/// <summary> /// 修改密码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (txtNew.Text.Trim() == "" || txtOld.Text.Trim() == "" || txtReNew.Text.Trim() == "") { MessageBox.Show("密码为空,请检查"); return; } if (txtNew.Text.Trim() != txtReNew.Text.Trim()) { MessageBox.Show("两次新密码不一致,请检查"); return; } var u = db.USER_INFOs.Where(a => a.UI_ID == SysUtil.CurrentUserID() && a.UI_PASSWORD == MD5Util.GetHash(txtOld.Text)).SingleOrDefault(); if (u != null) { u.UI_PASSWORD = MD5Util.GetHash(txtReNew.Text.Trim()); db.SubmitChanges(); MessageBox.Show("密码修改成功"); } else { MessageBox.Show("原密码有误,请检查"); return; } }
private void btnConnection_Click(object sender, EventArgs e) { if (TestConnection()) { try { UserName = txtName.Text.Trim(); string password = MD5Util.GetHash(txtPassword.Text.Trim()); //password HASH USER_INFO ui = db.USER_INFOs.SingleOrDefault(u => u.UI_NAME == UserName && u.UI_PASSWORD == password); if (ui == null) { MessageBox.Show("用户名或密码错误!"); } else { SysUtil.setCurrentUserID(ui.UI_ID); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { MessageBox.Show("Error to load schema.\n" + ex.Message, "Error to load schema", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// 新建或更改用户信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { if (!isInputValid()) { MessageBox.Show("请检查输入项!"); return; } var gi = from g in db.GROUP_INFOs where g.GI_NAME == cbxRoles.SelectedItem.ToString() select g; if (txtUserName.ReadOnly == false) //新建 { USER_INFO u = new USER_INFO { UI_ISVALID = cbxIsValid.Checked, UI_MAIL = txtMail.Text.Trim(), UI_NAME = txtUserName.Text.Trim(), UI_TEL = txtTel.Text.Trim(), UI_PASSWORD = MD5Util.GetHash("123456"), //txtUserName.Text.Trim() UI_TRUENAME = txtTrueName.Text.Trim(), UI_GIID = gi.First().GI_ID }; db.USER_INFOs.InsertOnSubmit(u); } else //更改 { var user = db.USER_INFOs.Where(u => u.UI_NAME == txtUserName.Text).SingleOrDefault(); user.UI_GIID = gi.First().GI_ID; user.UI_ISVALID = cbxIsValid.Checked; user.UI_MAIL = txtMail.Text.Trim(); user.UI_TEL = txtTel.Text.Trim(); user.UI_TRUENAME = txtTrueName.Text.Trim(); } db.SubmitChanges(); MessageBox.Show("数据提交成功!"); loadUsers(); txtUserName.ReadOnly = true; }