/// <summary> /// 保存按钮单击事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnSave_Click(object sender, EventArgs e) { //检验用户名和密码框是否为空 if (string.IsNullOrEmpty(this.txtName.Text)) { MessageBox.Show("用户名不能为空!", "提交提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(this.txtPwd.Text)) { MessageBox.Show("密码不能为空!", "提交提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //实体对象赋值 user.UserName = this.txtName.Text.Trim(); user.Password = this.txtPwd.Text.Trim(); if (HotelUserManager.AddHotelUser(user)) { //刷新显示 this.dgvUser.DataSource = HotelUserManager.GetAllHotelUsers(); MessageBox.Show("保存成功"); } else { MessageBox.Show("用户已经存在"); } }
//private void dgvUser_CellClick(object sender, DataGridViewCellEventArgs e) //{ // //显示编辑区 // this.pnlUserContent.Visible = true; // //获取用户ID // userid = Convert.ToInt32(this.dgvUser.Rows[e.RowIndex].Cells["userID"].Value); // //调用业务逻辑层通过类型ID得到用户信息 // user = HotelUserManager.GetHotelUserByUserID(userid); // //回绑数据 // this.txtName.Text = user.UserName.ToString(); // this.txtPwd.Text = user.Password.ToString(); //} /// <summary> /// DataGridView控件的click事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvUser_CellClick_1(object sender, DataGridViewCellEventArgs e) { //显示编辑区 this.pnlUserContent.Visible = true; //获取用户ID userid = Convert.ToInt32(this.dgvUser.Rows[e.RowIndex].Cells["id"].Value); //调用业务逻辑层通过类型ID得到用户信息 user = HotelUserManager.GetHotelUserByUserID(userid); //回绑数据 this.txtName.Text = user.UserName.ToString(); this.txtPwd.Text = user.Password.ToString(); }
/// <summary> /// 修改用户信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnModify_Click(object sender, EventArgs e) { if (userid == 0) { MessageBox.Show("请选择修改项目"); return; } user.UserName = this.txtName.Text.Trim(); user.Password = this.txtPwd.Text.Trim(); user.UserID = userid; HotelUserManager.ModifyHotelUser(user);//调用业务层添加用户方法 this.dgvUser.DataSource = HotelUserManager.GetAllHotelUsers(); MessageBox.Show("修改成功"); }
/// <summary> /// 删除按钮单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteToolStripButton_Click(object sender, EventArgs e) { if (userid != 0) { //调用业务逻辑层用户信息删除功能 DialogResult result = MessageBox.Show("您确实要删除此信息吗?", "提交提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == DialogResult.OK) { HotelUserManager.DeleteHotelUserById(userid); //刷新用户信息列表 this.dgvUser.DataSource = HotelUserManager.GetAllHotelUsers(); MessageBox.Show("信息删除成功!", "提交提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("请选择要删除的信息!", "提交提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// 点击登录按钮时,设置用户名和登录类型 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogIn_Click(object sender, EventArgs e) { if (GetValidate()) { //根据用名得到用户实体,并和输入的密码进行比较 HotelUser user = HotelUserManager.GetHotelUser(this.txtLogInId.Text.Trim()); string userPwd = user.Password.ToString(); if (userPwd.Trim() == this.txtLogInPwd.Text.Trim()) { result = MessageBox.Show("登录成功", "登录提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("您的帐号或密码不正确!", "登录判断", MessageBoxButtons.YesNo, MessageBoxIcon.Information); } } else { MessageBox.Show("请填写正确的登录信息!", "登录判断", MessageBoxButtons.YesNo, MessageBoxIcon.Information); } }
/// <summary> /// 窗体载入时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UserManagerForm_Load(object sender, EventArgs e) { this.dgvUser.AutoGenerateColumns = false; this.dgvUser.DataSource = HotelUserManager.GetAllHotelUsers(); this.pnlUserContent.Visible = false; }