private void btnLogin_Click(object sender, EventArgs e) { string usercode = this.tbUserCode.Text.Trim(); string pwd = this.txtPwd.Text.Trim(); DataRow drUserInfo; if (!String.IsNullOrEmpty(pwd) && !String.IsNullOrEmpty(usercode)) { ScanDataSet scanDataSet = new Business.UserInfo().GetUserByUserInfo(usercode, pwd); if (scanDataSet.UserInfo.Rows.Count < 1) { MessageBox.Show("用户名或密码错误!"); return; } //校验启用状态 drUserInfo = scanDataSet.UserInfo.Rows[0]; if (!drUserInfo["status"].ToString().Equals("1")) { MessageBox.Show("该用户未启用!"); return; } this.frcode = drUserInfo["frcode"].ToString(); } else if (String.IsNullOrEmpty(pwd)) { MessageBox.Show("密码不能为空!"); return; } else if (String.IsNullOrEmpty(usercode)) { MessageBox.Show("用户名不能为空!"); return; } else { MessageBox.Show("登录未知错误!"); return; } //记录业务模式 计入配置文件中 key: immode value:1,录入;2,修改 string immode = ""; if (this.InputRadioButton.Checked) { immode = "1"; } if (this.UpdateRadioButton.Checked) { immode = "2"; } Util.Util.WriteAppSetting("immode", immode, false); //通过用户对应信息 修改配置 this.UpdateConfigByUser(drUserInfo); this.DialogResult = DialogResult.OK; }
private void btnUpdate_Click(object sender, EventArgs e) { string oldUserCode = this.tbOldUserCode.Text.Trim(); string oldPwd = this.tbOldPwd.Text.Trim(); string newPwd = this.tbNewPwd.Text.Trim(); //if(String.IsNullOrEmpty(oldPwd)||String.IsNullOrEmpty(newPwd)) //{ // MessageBox.Show("密码不能为空!"); // return; //} //if (Util.Util.EncrptMd5(oldPwd).Equals(System.Configuration.ConfigurationManager.AppSettings["password"].ToString())) //{ // System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); // configuration.AppSettings.Settings["password"].Value = Util.Util.EncrptMd5(newPwd); // configuration.Save(); // this.DialogResult = DialogResult.OK; // MessageBox.Show("密码修改成功!"); //} try { ScanDataSet scanDataSet = new Business.UserInfo().GetUserByUserInfo(oldUserCode, oldPwd); if (scanDataSet.UserInfo.Rows.Count < 1) { MessageBox.Show("用户名或密码错误!"); return; } //获取用户信息通过 则更新密码 if (!String.IsNullOrEmpty(newPwd)) { DataTable dt = scanDataSet.UserInfo; dt.Rows[0]["password"] = newPwd; bool result = new Business.UserInfo().UpdateUser(dt); if (result) { MessageBox.Show("密码修改成功!"); //关闭窗口 this.Close(); return; } } else { MessageBox.Show("新密码不能为空!"); return; } } catch (Exception ex) { throw ex; } }
private void LoadUserInfo() { //如果是修改加载user信息 用户账号不允许修改 if (this.Owner is UserManager) { UserManager userManager = (UserManager)this.Owner; if (userManager.flag.Equals("2")) { ScanDataSet scandataset = new Business.UserInfo().GetUserByID(userManager.userID); if (scandataset.UserInfo.Rows.Count > 0) { this.tbUserCode.ReadOnly = true; userTable = scandataset.UserInfo; userRow = scandataset.UserInfo.Rows[0]; this.tbUserCode.Text = userRow["usercode"].ToString(); this.tbUserName.Text = userRow["username"].ToString(); this.tbUserPassWord.Text = userRow["password"].ToString(); this.tbSite.Text = userRow["site"].ToString(); string status = userRow["status"].ToString(); switch (status) { case "1": this.startRadioButton.Checked = true; break; case "0": this.forbidRadioButton.Checked = true; break; default: this.startRadioButton.Checked = true; break; } } else { MessageBox.Show("获取用户信息错误!"); return; } } } }
private void btnUpdateStatus_Click(object sender, EventArgs e) { //判断选中几行 try { int count = 0; bool result = false; for (int i = 0; i < this.dgvUserInfo.Rows.Count; i++) { if (this.dgvUserInfo.Rows[i].Cells[this.dgvUserInfo.Columns["SelectCheck"].Index].EditedFormattedValue.ToString() == "True") { count++; this.userID = this.dgvUserInfo.Rows[i].Cells["id"].Value.ToString(); string status = this.dgvUserInfo.Rows[i].Cells["status"].Value.ToString(); ScanDataSet scanDataSet = new Business.UserInfo().GetUserByID(this.userID); if (scanDataSet.UserInfo.Rows.Count > 0) { ScanDataSet.UserInfoDataTable dt = scanDataSet.UserInfo; dt.Rows[0]["status"] = status == "1" ? "0" : "1"; result = new Business.UserInfo().AddUser(dt); } } } if (count == 0) { MessageBox.Show("请选择要修改的行!"); return; } else if (count > 1) { MessageBox.Show("请选择一行修改记录!"); return; } if (result) { MessageBox.Show("更新成功!"); return; } } catch (Exception ex) { throw ex; } }
private void btnSearch_Click(object sender, EventArgs e) { //获取所选机构 GetOwnOrg(); //获取查询条件 string str = "and forgid='" + this.orgID + "'"; if (!String.IsNullOrEmpty(this.tbCondition.Text.Trim())) { str += " and (username like '%" + this.tbCondition.Text.Trim() + "%' or usercode like '%" + this.tbCondition.Text.Trim() + "%' )"; } ScanDataSet scanDataSet = new Business.UserInfo().GetUserByStr(str); if (scanDataSet.UserInfo.Rows.Count > 0) { dtInfo = scanDataSet.UserInfo; InitDataSet(); } }
private void btnSave_Click(object sender, EventArgs e) { try { //校验数据 CheckContent(); bool result; UserManager userManager; //判断是新增 or 修改 if (this.Owner is UserManager) { userManager = (UserManager)this.Owner; if (userManager.flag.Equals("1")) { userTable = new ScanDataSet.UserInfoDataTable(); userInfoRow = userTable.NewUserInfoRow(); userInfoRow.usercode = this.tbUserCode.Text.Trim(); userInfoRow.username = this.tbUserName.Text.Trim(); userInfoRow.password = this.tbUserPassWord.Text.Trim(); userInfoRow.forgid = ((UserManager)this.Owner).orgID; userInfoRow.frcode = ((UserManager)this.Owner).frcode; userInfoRow.site = this.tbSite.Text.Trim(); string status = ""; if (this.startRadioButton.Checked) { status = "1"; } if (this.forbidRadioButton.Checked) { status = "0"; } userInfoRow.status = status; userTable.AddUserInfoRow(userInfoRow); result = new Business.UserInfo().AddUser(userTable); } else if (userManager.flag.Equals("2")) { ScanDataSet scandataset = new Business.UserInfo().GetUserByID(userManager.userID); if (scandataset.UserInfo.Rows.Count > 0) { userTable = scandataset.UserInfo; userRow = scandataset.UserInfo.Rows[0]; userRow["usercode"] = this.tbUserCode.Text.Trim(); userRow["username"] = this.tbUserName.Text.Trim(); userRow["password"] = this.tbUserPassWord.Text.Trim(); userRow["forgid"] = ((UserManager)this.Owner).orgID; userRow["frcode"] = Util.Util.GetAppSetting("rcode").ToString(); userRow["site"] = this.tbSite.Text.Trim(); string status = ""; if (this.startRadioButton.Checked) { status = "1"; } if (this.forbidRadioButton.Checked) { status = "0"; } userRow["status"] = status; if (!String.IsNullOrEmpty(((UserManager)this.Owner).userID)) { userRow["id"] = ((UserManager)this.Owner).userID; } result = new Business.UserInfo().AddUser(userTable); } else { MessageBox.Show("获取用户信息错误!"); return; } } else { MessageBox.Show("获取业务标记错误!"); return; } } else { MessageBox.Show("获取父窗口错误!"); return; } if (result) { MessageBox.Show("保存成功!"); userManager.searchData(); this.Close(); return; } else { MessageBox.Show("保存失败!"); return; } } catch (Exception ex) { throw ex; } }