From 192aff391dac6c3f69c3ea4be708a2e10c26817b Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Sat, 8 Sep 2018 16:16:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=AE=BE=E8=AE=A1=E6=8B=92=E7=BB=9D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0RejectUse?= =?UTF-8?q?rs=E6=95=B0=E6=8D=AE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess/User.cs | 12 ---------- Bootstrap.DataAccess/UserHelper.cs | 7 +++--- DatabaseScripts/Install.sql | 38 ++++++++++++++++++++++++++++++ DatabaseScripts/Procedures.sql | 37 +++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 16 deletions(-) diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index a8ca3be0..e54dce61 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -49,18 +49,6 @@ namespace Bootstrap.DataAccess /// public string Period { get; set; } /// - /// 获得/设置 拒绝人 - /// - public string RejectedBy { get; set; } - /// - /// 获得/设置 拒绝原因 - /// - public string RejectedReason { get; set; } - /// - /// 获得/设置 拒绝时刻 - /// - public string RejectedTime { get; set; } - /// /// 获得/设置 新密码 /// public string NewPassword { get; set; } diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs index c39c7b2d..bedf5cf2 100644 --- a/Bootstrap.DataAccess/UserHelper.cs +++ b/Bootstrap.DataAccess/UserHelper.cs @@ -60,7 +60,7 @@ namespace Bootstrap.DataAccess { return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => { - string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null and RejectedTime is null order by RegisterTime desc"; + string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc"; List users = new List(); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) @@ -153,13 +153,12 @@ namespace Bootstrap.DataAccess public static bool RejectUser(int id, string rejectBy) { var ret = false; - var sql = "update Users set RejectedTime = GETDATE(), RejectedBy = @rejectedBy, RejectedReason = @rejectedReason where ID = @id"; - using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) + using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers")) { cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedBy", rejectBy)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedReason", "未填写")); - ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1; + ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; } CacheCleanUtility.ClearCache(userIds: id.ToString()); return ret; diff --git a/DatabaseScripts/Install.sql b/DatabaseScripts/Install.sql index 12aa427d..b3127305 100644 --- a/DatabaseScripts/Install.sql +++ b/DatabaseScripts/Install.sql @@ -407,3 +407,41 @@ EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'完成进度' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分配时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Tasks', @level2type=N'COLUMN',@level2name=N'AssignTime' GO + +/****** Object: Table [dbo].[RejectUsers] Script Date: 09/08/2018 15:34:25 ******/ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + +SET ANSI_PADDING ON +GO + +CREATE TABLE [dbo].[RejectUsers]( + [ID] [int] IDENTITY(1,1) NOT NULL, + [UserName] [varchar](50) NOT NULL, + [DisplayName] [nvarchar](50) NOT NULL, + [RegisterTime] [datetime] NOT NULL, + [RejectedBy] [varchar](50) NULL, + [RejectedTime] [datetime] NULL, + [RejectedReason] [nvarchar](50) NULL, + CONSTRAINT [PK_RejectUsers] PRIMARY KEY CLUSTERED +( + [ID] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +) ON [PRIMARY] + +GO + +SET ANSI_PADDING OFF +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'用户名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RejectUsers', @level2type=N'COLUMN',@level2name=N'UserName' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'显示名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RejectUsers', @level2type=N'COLUMN',@level2name=N'DisplayName' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'注册时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'RejectUsers', @level2type=N'COLUMN',@level2name=N'RegisterTime' +GO \ No newline at end of file diff --git a/DatabaseScripts/Procedures.sql b/DatabaseScripts/Procedures.sql index 008c3f47..8f340f47 100644 --- a/DatabaseScripts/Procedures.sql +++ b/DatabaseScripts/Procedures.sql @@ -198,3 +198,40 @@ BEGIN end END GO + +Drop PROCEDURE Proc_RejectUsers +GO +-- ============================================= +-- Author: Argo +-- Create date: 2018-09-07 +-- Description: +-- ============================================= +CREATE PROCEDURE [dbo].[Proc_RejectUsers] + -- Add the parameters for the stored procedure here + @id int, + @rejectedBy varchar(50), + @rejectedReason nvarchar(50) + WITH ENCRYPTION +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + SET XACT_ABORT ON; + -- Insert statements for procedure here + begin + declare @registerTime datetime + declare @userName varchar(50) + declare @displayName nvarchar(50) + select @registerTime = Registertime, @userName = UserName, @displayName = DisplayName from Users where ID = @id + + if @userName is not null + begin + begin tran + insert into RejectUsers (UserName, DisplayName, RegisterTime, RejectedBy, RejectedTime, RejectedReason) values (@userName, @displayName, @registerTime, @rejectedBy, GETDATE(), @rejectedReason) + delete from users where ID = @id + commit tran + end + end +END +GO