private void btnDel_Click(object sender, EventArgs e)
 {
     try
     {
         var selectedRow = allUserInfo.Rows[allUserInfo.CurrentRow.Index];
         if (MessageBox.Show(string.Format("确定要删除{0}吗?此过程不可逆,请谨慎操作!", selectedRow.Cells[1].Value.ToString()), "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
         {
             using(IdentityCertifyDataContext conn=new IdentityCertifyDataContext())
             {
                 var res = conn.T_Users.Where(o => o.userID == selectedRow.Cells[0].Value.ToString()).FirstOrDefault();
                 conn.T_Users.DeleteOnSubmit(res);
                 conn.SubmitChanges();
                 MessageBox.Show("删除成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 UserManage_Load(null, null);
             }
         }
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         UserManage_Load(null, null);
         btnClr_Click(null, null);
     }
 }
 private void btnOk_Click(object sender, EventArgs e)
 {
     try
     {
         if (oldPwd.Text.Trim() != "" && newPwd.Text.Trim() != "" && newAgain.Text.Trim() != "")
         {
             if (oldPwd.Text.Trim() == EncryptAndDecrypt.DecryptDES(op.userPassword.Trim()))
             {
                 if (newPwd.Text.Trim() == newAgain.Text.Trim())
                 {
                     using (IdentityCertifyDataContext conn = new IdentityCertifyDataContext())
                     {
                         var res = conn.T_Users.Where(o => o.userID == op.userID).FirstOrDefault();
                         res.userPassword = EncryptAndDecrypt.EncryptDES(newAgain.Text.Trim());
                         conn.SubmitChanges();
                         MessageBox.Show("修改密码成功!从下次登录起请使用新密码进行身份认证!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                     }
                 }
                 else
                 {
                     MessageBox.Show("两次输入密码不一致,请重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("原密码错误,请重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show("请补全信息后重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
     }
     catch (Exception ee)
     {
         MessageBox.Show(ee.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         ChangePassword_Load(null, null);
     }
 }
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (operatorID.Text == "")
         {
             if (operatorName.Text != "" && operatorHlpMsg.Text != "" && operatorPwd.Text != "")
             {
                 using (IdentityCertifyDataContext conn = new IdentityCertifyDataContext())
                 {
                     T_Users table = new T_Users();
                     string uid = SerialGenerator.GenerateSerialNumber();
                     table.userID = uid;
                     table.userName = operatorName.Text;
                     table.hlpMsg = operatorHlpMsg.Text;
                     table.userPassword = EncryptAndDecrypt.EncryptDES(operatorPwd.Text);
                     table.roleType = operatorRoleType.SelectedIndex == 0 ? "1" : "2";
                     conn.T_Users.InsertOnSubmit(table);
                     conn.SubmitChanges();
                     MessageBox.Show(string.Format("添加操作员成功!\n用户身份:{0}\n用户姓名:{1}\n用户ID:{2}\n助记码:{3}\n可使用用户ID或助记码进行身份认证。"
                         , table.roleType == "1" ? "管理员" : "普通用户", table.userName, table.userID, table.hlpMsg), "添加成功",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
                     btnClr_Click(null, null);
                 }
             }
         }
         else
         {
             using(IdentityCertifyDataContext conn=new IdentityCertifyDataContext())
             {
                 var table = conn.T_Users.Where(o => o.userID == operatorID.Text).FirstOrDefault();
                 table.userName = operatorName.Text;
                 table.hlpMsg = operatorHlpMsg.Text;
                 table.userPassword = EncryptAndDecrypt.EncryptDES(operatorPwd.Text);
                 table.roleType = operatorRoleType.SelectedIndex == 0 ? "1" : "2";
                 conn.SubmitChanges();
                 MessageBox.Show(string.Format("修改操作员成功!\n用户身份:{0}\n用户姓名:{1}\n用户ID:{2}\n助记码:{3}\n可使用用户ID或助记码进行身份认证。"
                     , table.roleType == "1" ? "管理员" : "普通用户", table.userName, table.userID, table.hlpMsg), "添加成功",
                     MessageBoxButtons.OK, MessageBoxIcon.Information);
                 btnClr_Click(null, null);
             }
         }
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         UserManage_Load(null, null);
         btnClr_Click(null, null);
     }
 }
 private void UserManage_Load(object sender, EventArgs e)
 {
     using (IdentityCertifyDataContext ic=new IdentityCertifyDataContext())
     {
         var res = ic.T_Users;
         if (res != null)
         {
             allUserInfo.DataSource = res;
             SetAllUsersDataGridView();
             operatorRoleType.SelectedIndex = 0;
             operatorName.Focus();
         }
     }
 }