using HighWayIot.Repository.domain; using HighWayIot.Repository.service; using HighWayIot.Winform.UserControlPages.SysConfigPages; 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 HighWayIot.Winform.UserControlPages.SysConfigPages { public partial class UserConfigPage : UserControl { /// /// 用户数据库业务实例 /// private SysUserInfoService sysUserInfoService = SysUserInfoService.Instance; /// /// 角色数据库业务实例 /// private SysUserRoleService sysUserRoleService = SysUserRoleService.Instance; /// /// 用户信息列表 /// private List List = new List(); /// /// 角色名称列表 /// private string[] RoleNames; public UserConfigPage() { InitializeComponent(); Init(); } private void Init() { UserInfoDataGridView.AutoGenerateColumns = false; List = sysUserInfoService.GetUserInfos(); RoleNames = sysUserRoleService.GetRoleInfos().Select(x => x.RoleName).ToArray(); Array.Resize(ref RoleNames, RoleNames.Length + 1); Array.Copy(RoleNames, 0, RoleNames, 1, RoleNames.Length - 1); RoleNames[0] = string.Empty; SelectUserLoginBeginTime.Value = DateTime.Now - TimeSpan.FromDays(3); this.SelectUserRole.DataSource = RoleNames; UserInfoDataGridView.DataSource = null; UserInfoDataGridView.DataSource = List; } private void UpdateUser_Click(object sender, EventArgs e) { SysUserEntity entity = new SysUserEntity(); int a = UserInfoDataGridView.CurrentRow.Index; int.TryParse(UserInfoDataGridView.Rows[a].Cells["Id"].Value.ToString(), out int id); entity.Id = id; entity.UserName = UserInfoDataGridView.Rows[a].Cells["UserName"].Value.ToString(); entity.UserRole = UserInfoDataGridView.Rows[a].Cells["UserRole"].Value.ToString(); entity.Password = UserInfoDataGridView.Rows[a].Cells["Password"].Value.ToString(); UserUpDateForm form = new UserUpDateForm(entity, RoleNames); form.ShowDialog(); List = sysUserInfoService.GetUserInfos(); UserInfoDataGridView.DataSource = null; UserInfoDataGridView.DataSource = List; } private void AddUser_Click(object sender, EventArgs e) { UserAddForm form = new UserAddForm(RoleNames); form.ShowDialog(); List = sysUserInfoService.GetUserInfos(); UserInfoDataGridView.DataSource = null; UserInfoDataGridView.DataSource = List; } private void DeleteUser_Click(object sender, EventArgs e) { int a = UserInfoDataGridView.CurrentRow.Index; if (MessageBox.Show($"确定要删除所选{List[a].UserName}行的数据?", "确认", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } int.TryParse(UserInfoDataGridView.Rows[a].Cells["Id"].Value.ToString(), out a); sysUserInfoService.DeleteUserInfoById(a); List = sysUserInfoService.GetUserInfos(); UserInfoDataGridView.DataSource = null; UserInfoDataGridView.DataSource = List; } private void SelectUser_Click(object sender, EventArgs e) { List = sysUserInfoService.GetUserInfos(SelectUserName.Text, SelectUserRole.Text, SelectUserLoginBeginTime.Value, SelectUserLoginEndTime.Value, IsCheckByLoginTime.Checked); UserInfoDataGridView.DataSource = null; UserInfoDataGridView.DataSource = List; } } }