示例#1
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     CanClose = false;
     try
     {
         if (NewPasswordTextBox.Text == "")
         {
             MessageBox.Show("新密碼不可空白!", "錯誤",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
             NewPasswordTextBox.Focus();
             return;
         }
         if (NewPasswordTextBox.Text != ConfirmPasswordTextBox.Text)
         {
             MessageBox.Show("新密碼與確認新密碼不一致!", "錯誤",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
             NewPasswordTextBox.Focus();
             return;
         }
         using (var context = new XINEntities())
         {
             var qry = (from U in context.XINUsers
                        where U.EmployeeNo == fmMain.FEmployeeNo &&
                        U.PasswordCode == OrignalPasswordTextBox.Text
                        select U).FirstOrDefault();
             if (qry == null)
             {
                 MessageBox.Show("原來的密碼輸入錯誤!", "錯誤",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
                 OrignalPasswordTextBox.Focus();
                 return;
             }
             //開始更新使用者的密碼
             qry.PasswordCode = NewPasswordTextBox.Text;
             context.SaveChanges();
             MessageBox.Show("密碼變更完成", "變更密碼",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
     //成功完成密碼變更,允許關閉視窗
     CanClose = true;
 }
示例#2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //開始密碼變更,禁止關閉視窗
            CanClose = false;

            //驗證程序
            try
            {
                if (NewPasswordTextBox.Text == "")
                {
                    MessageBox.Show("新密碼不可空白!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NewPasswordTextBox.Focus();
                    return;
                }
                if (NewPasswordTextBox.Text != ConfirmPasswordTextBox.Text)
                {
                    MessageBox.Show("新密碼與確認密碼不一致!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NewPasswordTextBox.Focus();
                    return;
                }
                using (var SSEntities = new SmartShoppingEntities())
                {
                    var qry = (from U in SSEntities.SSUsers
                               where U.Employee_ID == frmMain.FUserID && U.Password == OrignalPasswordTextBox.Text
                               select U).FirstOrDefault();
                    if (qry == null)
                    {
                        MessageBox.Show("原來密碼錯誤!", "錯誤",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        OrignalPasswordTextBox.Focus();
                        return;
                    }

                    //開始更新使用者的密碼
                    qry.Password = NewPasswordTextBox.Text;
                    SSEntities.SaveChanges();
                    MessageBox.Show("密碼變更完成,下次登入請使用新密碼", "變更密碼", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //完成密碼變更,允許關閉視窗
            CanClose = true;
        }
示例#3
0
 private void fmDtnPassword_Shown(object sender, EventArgs e)
 {
     OrignalPasswordTextBox.Focus();
 }