public static BG_ChangePwd AddBG_ChangePwd(BG_ChangePwd bG_ChangePwd)
        {
            string sql =
                "INSERT BG_ChangePwd (UserID, OldPwd, NewPwd, CrTime, UserName, DepName)" +
                "VALUES (@UserID, @OldPwd, @NewPwd, @CrTime, @UserName, @DepName)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@UserID", bG_ChangePwd.UserID),
                    new SqlParameter("@OldPwd", bG_ChangePwd.OldPwd),
                    new SqlParameter("@NewPwd", bG_ChangePwd.NewPwd),
                    new SqlParameter("@CrTime", bG_ChangePwd.CrTime),
                    new SqlParameter("@UserName", bG_ChangePwd.UserName),
                    new SqlParameter("@DepName", bG_ChangePwd.DepName)
                };

                string IdStr = DBUnity.ExecuteScalar(CommandType.Text, sql, para);
                int newId = Convert.ToInt32(IdStr);
                return GetBG_ChangePwdByPwdID(newId);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 public static bool ModifyBG_ChangePwd(BG_ChangePwd bG_ChangePwd)
 {
     return BG_ChangePwdService.ModifyBG_ChangePwd(bG_ChangePwd);
 }
 public static bool DeleteBG_ChangePwd(BG_ChangePwd bG_ChangePwd)
 {
     return BG_ChangePwdService.DeleteBG_ChangePwd(bG_ChangePwd);
 }
 public static BG_ChangePwd AddBG_ChangePwd(BG_ChangePwd bG_ChangePwd)
 {
     return BG_ChangePwdService.AddBG_ChangePwd(bG_ChangePwd);
 }
        public static BG_ChangePwd GetBG_ChangePwdByPwdID(int pwdID)
        {
            string sql = "SELECT * FROM BG_ChangePwd WHERE PwdID = @PwdID";

            try
            {
                SqlParameter para = new SqlParameter("@PwdID", pwdID);
                DataTable dt = DBUnity.AdapterToTab(sql, para);

                if(dt.Rows.Count > 0)
                {
                    BG_ChangePwd bG_ChangePwd = new BG_ChangePwd();

                    bG_ChangePwd.PwdID = dt.Rows[0]["PwdID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["PwdID"];
                    bG_ChangePwd.UserID = dt.Rows[0]["UserID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["UserID"];
                    bG_ChangePwd.OldPwd = dt.Rows[0]["OldPwd"] == DBNull.Value ? "" : (string)dt.Rows[0]["OldPwd"];
                    bG_ChangePwd.NewPwd = dt.Rows[0]["NewPwd"] == DBNull.Value ? "" : (string)dt.Rows[0]["NewPwd"];
                    bG_ChangePwd.CrTime = dt.Rows[0]["CrTime"] == DBNull.Value ? DateTime.MinValue : (DateTime)dt.Rows[0]["CrTime"];
                    bG_ChangePwd.UserName = dt.Rows[0]["UserName"] == DBNull.Value ? "" : (string)dt.Rows[0]["UserName"];
                    bG_ChangePwd.DepName = dt.Rows[0]["DepName"] == DBNull.Value ? "" : (string)dt.Rows[0]["DepName"];

                    return bG_ChangePwd;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 public static bool DeleteBG_ChangePwd(BG_ChangePwd bG_ChangePwd)
 {
     return DeleteBG_ChangePwdByPwdID( bG_ChangePwd.PwdID );
 }
        public static bool ModifyBG_ChangePwd(BG_ChangePwd bG_ChangePwd)
        {
            string sql =
                "UPDATE BG_ChangePwd " +
                "SET " +
                    "UserID = @UserID, " +
                    "OldPwd = @OldPwd, " +
                    "NewPwd = @NewPwd, " +
                    "CrTime = @CrTime, " +
                    "UserName = @UserName, " +
                    "DepName = @DepName " +
                "WHERE PwdID = @PwdID";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@PwdID", bG_ChangePwd.PwdID),
                    new SqlParameter("@UserID", bG_ChangePwd.UserID),
                    new SqlParameter("@OldPwd", bG_ChangePwd.OldPwd),
                    new SqlParameter("@NewPwd", bG_ChangePwd.NewPwd),
                    new SqlParameter("@CrTime", bG_ChangePwd.CrTime),
                    new SqlParameter("@UserName", bG_ChangePwd.UserName),
                    new SqlParameter("@DepName", bG_ChangePwd.DepName)
                };

                int t = DBUnity.ExecuteNonQuery(CommandType.Text, sql, para);
                if(t>0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 protected void btnsure_OnDirectClick(object sender, DirectEventArgs e)
 {
     if (!string.IsNullOrEmpty(PasswordField.Text.Trim()))
     {
         string pwd = "";
         BG_User bgUser = BG_UserManager.GetBG_UserByUserID(UserID);
         pwd = bgUser.UserPwd;
         if (bgUser.UserPwd == PasswordField.Text.Trim())
         {
             X.Msg.Alert("系统提示", "密码不能与原密码相同").Show();
             return;
         }
         bgUser.UserPwd = PasswordField.Text.Trim();
         if (BG_UserManager.ModifyBG_User(bgUser))
         {
             X.Msg.Alert("系统提示", "密码修改成功").Show();
             Window1.Close();
         }
         BG_ChangePwd bgChangePwd = new BG_ChangePwd();
         bgChangePwd.UserName = UserName;
         bgChangePwd.CrTime = DateTime.Now;
         bgChangePwd.DepName = DepName;
         bgChangePwd.NewPwd = bgUser.UserPwd;
         bgChangePwd.UserID = bgUser.UserID;
         bgChangePwd.OldPwd = pwd;
         BG_ChangePwdManager.AddBG_ChangePwd(bgChangePwd);
     }
 }