using ComponentFactory.Krypton.Toolkit; using NXWMS.Client.Code.Extends; using NXWMS.Client.Model.AppModels.Condition; using NXWMS.Client.Model.AppModels.Condition.SysSettings; using NXWMS.Client.Model.AppModels.Result; using NXWMS.Client.Model.AppModels.Result.SysSettings; using NXWMS.Client.Model.CoreModels; using NXWMS.Client.String.Enums; using NXWMS.Commons; using NXWMS.Services; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.ComboBox; namespace NXWMS.Forms.SysSettings { public partial class frmUser : KryptonForm { /// /// 界面最后执行操作 /// private EnumOperation _LastOperation; /// /// 窗体类名 /// private string _CrrentClassName; /// /// 客户端字段排序列表 /// private List _clientFieldOrderList; /// /// 角色列表 /// private List _roleList; public frmUser() { InitializeComponent(); _CrrentClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName; InitData(); InitControl(); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } /// /// ESC撤销此次编辑操作 /// /// /// /// protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { int WM_KEYDOWN = 256; int WM_SYSKEYDOWN = 260; if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN) { switch (keyData) { case Keys.Escape: //if (groupOperation.Visible) //{ // btnExit_Click(null, null); //} break; } } return false; } private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex == 0) { if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null) { if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any()) { _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1; } else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1") { if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any()) { _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0; } else { if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any()) { _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1; } } } /// /// 选择行主键列表 /// private List _CheckRowIdList = new List(); /// /// 当前页面操作的主键 /// private string _PrimaryKey = "USER_ID"; private void btnRemove_Click(object sender, EventArgs e) { if (_CheckRowIdList.Count == 0) { return; } if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { _LastOperation = EnumOperation.Remove; var editResult = SysSettingsServices.userService.Deleted(new UserCondition { OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, UserIds = string.Join(",", _CheckRowIdList) }); if (editResult.Status == OperateStatus.Success) { KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); //groupOperation.Visible = false; btnSearch_Click(null, null); } } } /// /// 控件初始化 /// private void InitControl() { CheckForIllegalCrossThreadCalls = false; //groupOperation.LostFocus += new EventHandler(groupOperation_LostFocus); //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus); dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick); dataGridView.BuildDataGridView(_clientFieldOrderList.GetFieldOrderDic(), false); var fieldValueList = (from x in _roleList select new FieldValue { Code = x.ROLE_CODE, Name = x.ROLE_NAME }).ToList(); //cmbRole.DataSource = fieldValueList.Where((x, i) => fieldValueList.FindIndex(z => z.Code == x.Code) == i).ToList(); //cmbRole.DisplayMember = "Name"; //cmbRole.ValueMember = "Code"; //cmbRole.SelectedIndex = -1; tableLayoutPanelSearch.SetFormPanelEnabled(AppConfig.CurrentMenu); tableLayoutPanelEdit.SetFormPanelEnabled(AppConfig.CurrentMenu); var fieldList = new List().Add(new FieldValue { Id = "", Name = "全部" }); cmbSearchRole.DataSource = fieldList.GetFieldValueIdList(_roleList, "ROLE_CODE", "ROLE_NAME"); cmbSearchRole.DisplayMember = "Name"; cmbSearchRole.ValueMember = "Code"; cmbSearchRole.SelectedIndex = -1; fieldList = new List().Add(new FieldValue { Id = "", Name = "全部" }); cmbSearchGender.DataSource = fieldList.GetFieldValueIdList(); cmbSearchGender.DisplayMember = "Name"; cmbSearchGender.ValueMember = "Id"; cmbSearchGender.SelectedIndex = -1; //cmbGender.DataSource = new List().GetFieldValueIdList(); //cmbGender.DisplayMember = "Name"; //cmbGender.ValueMember = "Id"; //cmbGender.SelectedIndex = -1; //暂时用代码限制长度,不用表配置之类做了.. txtSearchIphone.SetControlBase(20); txtSearchUserInfo.SetControlBase(200); txtSerachJob.SetControlBase(50); txtSerachMail.SetControlBase(100); //txtUserCode.SetControlBase(50); //txtUserName.SetControlBase(100); //txtNickName.SetControlBase(50); //txtIphoneNumber.SetControlBase(20); //txtJobTitle.SetControlBase(50); //txtEmail.SetControlBase(100); //txtAddress.SetControlBase(200); } /// /// 数据初始化 /// private void InitData() { //获取数据源配置 var result = ConfigServices.configService.GetDataViewOrderList(new ClientFieldOrderCondition { SourceCode = $"{_CrrentClassName}" }); if (result.Status == OperateStatus.Success) { _clientFieldOrderList = result.Data; } //获取角色 var roleResult = SysSettingsServices.roleService.GetList(new RoleSearchCondition { IsUsed = true, ItemSQL = "ROLE_CODE,ROLE_NAME" }); if (roleResult.Status == OperateStatus.Success) { _roleList = roleResult.Data.RowData.ToList(); } } private void groupOperation_LostFocus(object sender, EventArgs e) { } private void groupOperation_GostFocus(object sender, EventArgs e) { //groupOperation.Values.Heading = _LastOperation.Display(); //groupOperation.Text = $"正在{ _LastOperation.Display()}数据"; //lbStatusMessage.Visible = true; } private void btnAdd_Click(object sender, EventArgs e) { var frm = new ChildFrm.FrmUserEdit(); frm.Operation = EnumOperation.Add; frm.RoleList = this._roleList; frm.InitControl(); if (frm.ShowDialog() == DialogResult.OK) { this.btnSearch_Click(null, null); } //if (!groupOperation.Visible) //{ // tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView); // _LastOperation = EnumOperation.Add; // txtUserCode.Enabled = true; // groupOperation.Visible = true; // groupOperation.Focus(); //} } private void btnSearch_Click(object sender, EventArgs e) { var loadfrm = new frmLoading(); loadfrm.Show(); var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize); if (!string.IsNullOrWhiteSpace(message)) { KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private string LoadSearch(int pageIndex, int pageSize) { var result = SysSettingsServices.userService.GetList(new UserSearchCondition { Address = txtSerachAddress.Text, Email = txtSerachMail.Text, Gender = cmbSearchGender.SelectedValue.GetObjectToInt(), IphoneNumber = txtSearchIphone.Text, JobTitle = txtSerachJob.Text, UserInfo = txtSearchUserInfo.Text, PageIndex = pageIndex, PageSize = pageSize, IsUsed = chkSearchUse.Checked, }); if (result.Status == OperateStatus.Success) { this.pageTool.DataCount = result.Data.TotalCount; if (result.Data.RowData.Any()) { dataGridView.Columns.Clear(); dataGridView.DataSource = result.Data.RowData.ToList(); dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList)); } else { if (dataGridView.DataSource != null) { dataGridView.DataSource = new List(); } dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false); } return string.Empty; } else { return result.Message; } } private void btnExit_Click(object sender, EventArgs e) { if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //groupOperation.Visible = false; } else { //groupOperation.Visible = true; //groupOperation.Focus(); } } private Point mouse_offset; private void groupOperation_MouseDown(object sender, MouseEventArgs e) { mouse_offset = new Point(-e.X, -e.Y); } private void groupOperation_MouseMove(object sender, MouseEventArgs e) { ((Control)sender).Cursor = Cursors.Arrow; if (e.Button == MouseButtons.Left) { Point mousePos = MousePosition; mousePos.Offset(mouse_offset.X, mouse_offset.Y); ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos); Application.DoEvents(); } } private void btnEdit_Click(object sender, EventArgs e) { this.dataGridView_CellDoubleClick(null, null); //if (dataGridView.CurrentRow == null) //{ // return; //} //if (!groupOperation.Visible) //{ // _selectIndex = dataGridView.CurrentRow.Index; // if (_selectIndex >= 0) // { // _LastOperation = EnumOperation.Edit; // _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value); // tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]); // txtUserCode.Enabled = false; // groupOperation.Visible = true; // groupOperation.Focus(); // } //} } private string _selectRuleCode; private int _selectIndex; private int _selectId; //private void btnSave_Click(object sender, EventArgs e) //{ // if (string.IsNullOrWhiteSpace(txtUserCode.Text)) // { // KryptonMessageBox.Show($"请输入用户编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // if (string.IsNullOrWhiteSpace(txtUserName.Text)) // { // KryptonMessageBox.Show($"请输入用户名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // if (string.IsNullOrWhiteSpace(cmbGender.Text)) // { // KryptonMessageBox.Show($"请选择性别。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // switch (_LastOperation) // { // case EnumOperation.Add: // var addResult = SysSettingsServices.userService.Add(new UserCondition // { // JobTitle = txtJobTitle.Text, // NickName = txtNickName.Text, // Address = txtAddress.Text, // PhoneNumber = txtIphoneNumber.Text, // UserName = txtUserName.Text, // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, // Email = txtEmail.Text, // Gender = cmbGender.SelectedValue.GetObjectToInt().Value, // IsUsed = chkUse.Checked, // RoleCode = cmbRole.SelectedValue.GetObjectToString(), // UserCode = txtUserCode.Text, // }); // if (addResult.Status == OperateStatus.Success) // { // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // groupOperation.Visible = false; // btnSearch_Click(null, null); // dataGridView.ClearSelection(); // } // else // { // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // break; // case EnumOperation.Edit: // var editResult = SysSettingsServices.userService.Edit(new UserCondition // { // JobTitle = txtJobTitle.Text.Trim(), // NickName = txtNickName.Text, // Address = txtAddress.Text, // PhoneNumber = txtIphoneNumber.Text, // UserName = txtUserName.Text, // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, // Email = txtEmail.Text, // Gender = cmbGender.SelectedValue.GetObjectToInt().Value, // IsUsed = chkUse.Checked, // RoleCode = cmbRole.SelectedValue.GetObjectToString(), // UserId = _selectId, // }); // if (editResult.Status == OperateStatus.Success) // { // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // groupOperation.Visible = false; // btnSearch_Click(null, null); // dataGridView.ClearSelection(); // } // else // { // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // break; // } //} private void cmbRule_SelectedIndexChanged(object sender, EventArgs e) { //if (cmbRole.SelectedValue != null) //{ // _selectRuleCode = cmbRole.SelectedValue.ToString(); //} //else //{ // _selectRuleCode = ""; //} } private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e) { // e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1); } private void btnSearchExport_Click(object sender, EventArgs e) { this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault()}列表" + DateTime.Now.ToString("yyyyMMddHH")); } private void SelectInit() { _selectIndex = dataGridView.SelectedRows[0].Index; if (_selectIndex >= 0) { _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value); } } private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { SelectInit(); if (_selectIndex >= 0) { var frm = new ChildFrm.FrmUserEdit(); frm.Operation = EnumOperation.Edit; frm.SelectId= this._selectId; frm.RoleList = this._roleList; frm.InitControl(); frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]); if (frm.ShowDialog() == DialogResult.OK) { this.btnSearch_Click(null, null); } //_LastOperation = EnumOperation.Edit; //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]); ////richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" : //// dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString(); //txtUserCode.Enabled = false; //groupOperation.Visible = true; //groupOperation.Focus(); } } private void btnClear_Click(object sender, EventArgs e) { txtSearchUserInfo.Text = ""; txtSearchIphone.Text = ""; txtSerachAddress.Text = ""; txtSerachJob.Text = ""; txtSerachMail.Text = ""; cmbSearchGender.SelectedIndex = -1; cmbSearchRole.SelectedIndex = -1; } private void pageTool_OnPageChange(int PageIndex, int PageSzie) { this.btnSearch_Click(null, null); } } }