using HZH_Controls.Controls; 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.Web; using System.Windows.Forms; using DB.Dto; using DB.Service; using HZH_Controls.Forms; namespace RfidWeb.Frm { public partial class FormAccount : UserControl { private UserService userService = new UserService(); private UserDto OlduserDto; public FormAccount() { InitializeComponent(); OlduserDto= UserManager.GetUser(); Init(); } private void Init() { this.dataGridView1.AutoGenerateColumns = false; ucPagerControl21.PageModel = PageModel.PageCount; ucPagerControl21.PageIndex = 1; ucPagerControl21.PageSize = 20; } private void ucPagerControl21_ShowSourceChanged(object currentSource) { string key = this.textBoxSel.Text.Trim(); var index = ucPagerControl21.PageIndex; List lsInts = new List(); if (OlduserDto != null) { switch (OlduserDto.RoleLevel) { case 1: lsInts.AddRange(new[] { 1, 2, 3 }); break; case 2: lsInts.AddRange(new[] { 2, 3 }); break; case 3: lsInts.Add(3); break; } } var page = userService.GetPagedList(index, ucPagerControl21.PageSize, key,lsInts); ucPagerControl21.PageCount = page.TotalPages; this.dataGridView1.DataSource = page.Items; } private void ucBtnSelect_BtnClick(object sender, EventArgs e) { Replace(); } private void ucBtnAdd_BtnClick(object sender, EventArgs e) { var user = UserManager.GetUser(); if (user != null) { FormRegister formRegis = new FormRegister(user); formRegis.StartPosition = FormStartPosition.CenterScreen; // 设置窗口显示在屏幕中央 formRegis.ShowDialog(); } else { FormLogin fromLogin=new FormLogin(); fromLogin.ShowDialog(); } } private void ucBtnDel_BtnClick(object sender, EventArgs e) { var dataGridViewRows = this.dataGridView1.SelectedRows; if (dataGridViewRows.Count == 0) { FrmDialog.ShowDialog(this, "请勾选相关信息", "警告窗体"); return; } List ls = new List(); foreach (DataGridViewRow dataGridViewRow in dataGridViewRows) { var obj = dataGridViewRow.DataBoundItem as UserDto; ls.Add(obj.Id); } if (ls.Any()) { userService.UpdateDel(ls); Replace(); } } private void ucBtnUpdate_BtnClick(object sender, EventArgs e) { var dataGridViewRows = this.dataGridView1.SelectedRows; if (dataGridViewRows.Count != 1) { FrmDialog.ShowDialog(this, "只能修改一条", "警告窗体"); return; } var dto = dataGridViewRows[0].DataBoundItem as UserDto; FormRegister formRegis = new FormRegister(dto.Id, OlduserDto); formRegis.StartPosition = FormStartPosition.CenterScreen; // 设置窗口显示在屏幕中央 formRegis.ShowDialog(); Replace(); } private void Replace() { ucPagerControl21.PageIndex = 1; ucPagerControl21_ShowSourceChanged(new object()); } private void FormAccount_Load(object sender, EventArgs e) { } } }