private void btn_Sure_Click(object sender, EventArgs e) { string _old = txt_Old.Text.Trim(); string _new = txt_New.Text.Trim(); if (_old == string.Empty || _new == string.Empty) { MessageBox.Show("不能为空!"); return; } User user = new User(); // 项目 Common 的 User 类 user.GetModel(Global.userName); if (user.UserPwd != _old) { MessageBox.Show("原密码错误!"); return; } else { user.UserPwd = _new; bool re = user.Update(); if (re) { MessageBox.Show("修改成功!"); this.Close(); } else { MessageBox.Show("修改失败!"); } } }
private void btn_Sure_Click(object sender, EventArgs e) { string _old = txt_Old.Text.Trim(); string _new = txt_New.Text.Trim(); if (_old == string.Empty || _new == string.Empty) { MessageBox.Show("不能为空!"); return; } User user = new User(); user.GetModel(Global.userName); if (user.UserPwd != _old) { MessageBox.Show("原密码错误!"); return; } else { user.UserPwd = _new; bool re = user.Update(); if (re) { MessageBox.Show("修改成功!"); this.Close(); } else { MessageBox.Show("修改失败!"); } } }
/// <summary> /// 单击单元格内容时发生 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == dataGridView1.Columns["cDel"].Index) { if (MessageBox.Show(this, "确定要删除吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes) { object v = dataGridView1.Rows[e.RowIndex].Cells["cUserName"].Value; if (v != null) { if (v.ToString() == "admin") { MessageBox.Show("不能删除系统管理员!"); return; } User no = new User(); no.UserName = v.ToString(); bool re = no.Delete(); if (re) { MessageBox.Show("删除成功!"); BindDGV(); } else { MessageBox.Show("删除失败!"); } } } } else if (e.ColumnIndex == dataGridView1.Columns["cModity"].Index) { object v = dataGridView1.Rows[e.RowIndex].Cells["cUserName"].Value; if (v != null) { if (v.ToString() == "admin") { MessageBox.Show("不能修改系统管理员!"); return; } User no = new User(); no.GetModel(v.ToString()); frmUserUpdate f = new frmUserUpdate(no); // 本项目的 frmUserUpdate 窗体 f.ShowDialog(); if (f._isTrue) { BindDGV(); // 自定义函数 } } } }
private void btn_Login_Click(object sender, EventArgs e) { try { // 客户端使用控制(当服务器时间大于 2015-6-1 时停止使用程序) //DateTime serverTime = CommonService.GetServerTime(); //if (serverTime >= DateTime.Parse("2015-6-1")) //{ // MessageBox.Show("系统异常,请联系开发人员!"); // Application.Exit(); // return; //} string _name = txt_UserName.Text.Trim(); // Trim() 去除前、后的空白字符 string _pwd = txt_UserPwd.Text.Trim(); User user = new User(); // 本项目的 Service 文件夹内的 User 类(属于 Model 层) if (user.Login(_name, _pwd)) { user.GetModel(_name); if (user.Position == "管理员" || user.Position == "系统管理员") { Global.IsAdmin = true; // 项目 Common 的 Global 类(作用:使用 Global 类内数据成员来保存本次程序的不变量) } Global.userName = _name; // 写入本次登录名 INIService ini = new INIService(); // 项目 Common 的 INIService 类 ini.IniWriteValue("LoginUser", "UserName", _name, Application.StartupPath + "\\LastLogin.ini"); // 跳转 frmIndex 窗体和隐藏本窗体 frmIndex f = new frmIndex(); this.Hide(); f.ShowDialog(); } else { MessageBox.Show("登录失败,用户名或者密码错误!"); return; } } catch (Exception ex) { MyLog.WriteLog(ex.Message); // 项目 Common 的 MyLog 类(作用:保存日志) MessageBox.Show("登录失败,请检查服务器是否正常运行!"); } }
private void btn_Login_Click(object sender, EventArgs e) { try { //DateTime serverTime = CommonService.GetServerTime(); //if (serverTime >= DateTime.Parse("2015-6-1")) //{ // MessageBox.Show("系统异常,请联系开发人员!"); // Application.Exit(); // return; //} string _name = txt_UserName.Text.Trim(); string _pwd = txt_UserPwd.Text.Trim(); User user = new User(); if (user.Login(_name, _pwd)) { user.GetModel(_name); if (user.Position == "管理员" || user.Position == "系统管理员") { Global.IsAdmin = true; } Global.userName = _name; //写入上次登录名 INIService ini = new INIService(); ini.IniWriteValue("LoginUser", "UserName", _name, Application.StartupPath + "\\LastLogin.ini"); frmIndex f = new frmIndex(); this.Hide(); f.ShowDialog(); } else { MessageBox.Show("登录失败,用户名或者密码错误!"); return; } } catch (Exception ex) { MyLog.WriteLog(ex.Message); MessageBox.Show("登录失败,请检查服务器是否正常运行!"); } }