|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace GeBoShi.UI.User
- {
- public partial class UserListFrm : Form
- {
- UserService service = new UserService();
- private UserMgr _UserMgr;
- public UserListFrm(UserMgr userMgr)
- {
- InitializeComponent();
- this.uiTitel1.ShowContrlBox(false, false, true);
- this.uiTitel1.FatherForm = this;
-
- dataGridView1.AutoGenerateColumns = false;
- _UserMgr = userMgr;
- }
-
- private void initDataView()
- {
- var list = service.GetListNav();
- tsslCount.Text = $"共 {list.Count} 条记录";
- dataGridView1.DataSource = new BindingSource(list, null);
- }
-
- private void UserListFrm_Load(object sender, EventArgs e)
- {
- initDataView();
- }
-
- private void tsbtnAdd_Click(object sender, EventArgs e)
- {
- NewUserFrm frm = new NewUserFrm(_UserMgr.LoginUser);
- if (frm.ShowDialog() == DialogResult.OK)
- initDataView();
- }
-
- private void tsbtnDel_Click(object sender, EventArgs e)
- {
-
- }
-
- private void tsbtnEnable_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dataGridView1.CurrentRow == null)
- return;
-
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<User>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
- if (MessageBox.Show($"确认启用?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- list[liIndex].State = true;
- //只更新指定列
- if (!service.Update(it => new User() { State = list[liIndex].State }, it => it.Id == list[liIndex].Id))
- throw new Exception("启用失败!");
- MessageBox.Show("启用成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- initDataView();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- private void tsbtnDisable_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dataGridView1.CurrentRow == null)
- return;
-
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<User>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
- if (list[liIndex].Code == "admin")
- throw new Exception("管理员不可禁用!");
- if (MessageBox.Show($"确认禁用?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- list[liIndex].State = false;
- //只更新指定列
- if (!service.Update(it => new User() { State = list[liIndex].State }, it => it.Id == list[liIndex].Id))
- throw new Exception("禁用失败!");
- MessageBox.Show("禁用成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- initDataView();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- private void tsbtnResetPW_Click(object sender, EventArgs e)
- {
- if (this.dataGridView1.CurrentRow == null)
- return;
-
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<User>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
- if (MessageBox.Show($"确认重置密码?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- string szUserPw = "";
- list[liIndex].Password = szUserPw;
- //只更新指定列
- if (!service.Update(it => new User() { Password = list[liIndex].Password }, it => it.Id == list[liIndex].Id))
- throw new Exception("重置失败!");
- MessageBox.Show("重置成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- initDataView();
- }
- }
- private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<User>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
- NewUserFrm frm = new NewUserFrm(_UserMgr.LoginUser,list[liIndex]);
- frm.ShowDialog(this);
- initDataView();
- }
- private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
- {
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<User>;
- for (int i = 0; i < dataGridView1.Rows.Count; i++)
- {
- if (list[i].RoleInfo != null)
- dataGridView1.Rows[i].Cells["colRoleName"].Value = list[i].RoleInfo.Name;
-
- }
- }
-
- private void tsbtnChangePW_Click(object sender, EventArgs e)
- {
- var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<User>;
- int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
- ModifyPWFrm frm = new ModifyPWFrm(list[liIndex]);
- frm.ShowDialog();
- }
-
- private void toolStrip1_Paint(object sender, PaintEventArgs e)
- {
- Rectangle rect = new Rectangle(0, 0, this.toolStrip1.Width, this.toolStrip1.Height - 2);
- e.Graphics.SetClip(rect);
- }
- }
- }
|