private void btnOk_Click(object sender, EventArgs e) { lblError1.Visible = false; lblError2.Visible = false; String username = txtName.Text.Trim(); string realname = txtRealName.Text.Trim(); String phone = txtPhone.Text.Trim(); String sex = rdbMan.Checked ? "男" : "女"; int enable = ckbDisable.Checked ? 0 : 1; if (string.IsNullOrEmpty(username)) { lblError1.Text = "请输入用户名!"; lblError1.Visible = true; this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if( _user ==null) { _user = new Bean.UserBean(); _user.createman = Bean.Variable.User.username; _user.password = "******"; } _user.username = username; _user.realname = realname; _user.sex = sex; _user.enable = enable; _user.phone = phone; _user.modifyman = Bean.Variable.User.username; _user.modifytime = DateTime.Now; _user.roletype = rdbNormal.Checked ? Bean.Constant.Role_User : Bean.Constant.Role_Admin; HttpUtilWrapper wrapper = new HttpUtilWrapper(); Bean.UserResult result; if (_user.userid == 0) { result = wrapper.AddUser(_user); } else { result = wrapper.EditUser(_user); } if (result != null && result.Code == (int)Bean.Constant.ResultCodeEnum.Success) { MessageBox.Show(result.Message); this.DialogResult = System.Windows.Forms.DialogResult.OK; if (OnRefresh != null) { OnRefresh(this, EventArgs.Empty); } } else { String msg= result==null ?"操作失败":result.Message; MessageBox.Show(msg); this.DialogResult = System.Windows.Forms.DialogResult.None; } }
public FormUser( Bean.UserBean bean) { InitializeComponent(); _user = bean; if (_user != null) { txtName.Text = _user.username; txtPhone.Text = _user.phone; txtRealName.Text = _user.realname; rdbMan.Checked = _user.sex.Equals("男"); ckbDisable.Checked = _user.enable == 1 ? false : true; rdbNormal.Checked = _user.roletype.Equals(Bean.Constant.Role_User) ? true : false; rdbDB.Checked = _user.roletype.Equals(Bean.Constant.Role_Admin) ? true : false; } }
private void btnOk_Click(object sender, EventArgs e) { lblTipInfo.Visible = lblTipPwd.Visible = lblTipUser.Visible = false; bool isOk = true; if( string.IsNullOrEmpty( txtUserName.Text )) { lblTipUser.Text = "请输入用户名"; lblTipUser.Visible = true; isOk = false; txtUserName.Focus(); } if( string.IsNullOrEmpty( txtPassword.Text )) { lblTipPwd.Text = "请输入密码"; lblTipPwd.Visible = true; isOk = false; txtPassword.Focus(); } if( isOk == false ) { this.DialogResult = System.Windows.Forms.DialogResult.None; return; } string username = txtUserName.Text.Trim (); string password = txtPassword.Text; string pwdMD5 = DesEncryptUtil.EncryptMD5( password ); if (backgroundWorker1.IsBusy) return; lblLoadingText.Text = "正在登录,请稍等..."; panelLoading.Visible = true; panelLoading.Location = new Point((this.Width / 2 - this.panelLoading.Width / 2), this.Height / 2 - this.panelLoading.Height - 20); UserBean user = new UserBean(); user.username = username; user.password = password; backgroundWorker1.RunWorkerAsync(user); this.DialogResult = System.Windows.Forms.DialogResult.None; return; UserResult entity = new HttpUtilWrapper().Login<UserResult>(username, password); if (entity == null) { this.DialogResult = System.Windows.Forms.DialogResult.None; lblTipInfo.Text = "登录失败,用户名或密码错误"; lblTipInfo.Visible = true; return; } else if (entity.Code == (int)Constant.ResultCodeEnum.Error) { this.DialogResult = System.Windows.Forms.DialogResult.None; lblTipInfo.Text = entity.Message; // "登录失败,用户名或密码错误"; lblTipInfo.Visible = true; return; } Variable.User = entity.Data; SaveUser(Variable.User); }
protected void SaveUser( UserBean user ) { if (tcCheckBox1.Checked) { UserManager.SaveUser(user); } else { UserManager.Delete(user); } }