frmUser.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Code.Extends;
  3. using NXWMS.Client.Model.AppModels.Condition;
  4. using NXWMS.Client.Model.AppModels.Condition.SysSettings;
  5. using NXWMS.Client.Model.AppModels.Result;
  6. using NXWMS.Client.Model.AppModels.Result.SysSettings;
  7. using NXWMS.Client.Model.CoreModels;
  8. using NXWMS.Client.String.Enums;
  9. using NXWMS.Commons;
  10. using NXWMS.Services;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Runtime.InteropServices;
  18. using System.Text;
  19. using System.Threading;
  20. using System.Threading.Tasks;
  21. using System.Windows.Forms;
  22. using static System.Windows.Forms.ComboBox;
  23. namespace NXWMS.Forms.SysSettings
  24. {
  25. public partial class frmUser : KryptonForm
  26. {
  27. /// <summary>
  28. /// 界面最后执行操作
  29. /// </summary>
  30. private EnumOperation _LastOperation;
  31. /// <summary>
  32. /// 窗体类名
  33. /// </summary>
  34. private string _CrrentClassName;
  35. /// <summary>
  36. /// 客户端字段排序列表
  37. /// </summary>
  38. private List<ClientFieldOrderResult> _clientFieldOrderList;
  39. /// <summary>
  40. /// 角色列表
  41. /// </summary>
  42. private List<RoleResult> _roleList;
  43. public frmUser()
  44. {
  45. InitializeComponent();
  46. _CrrentClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;
  47. InitData();
  48. InitControl();
  49. }
  50. protected override CreateParams CreateParams
  51. {
  52. get
  53. {
  54. CreateParams cp = base.CreateParams;
  55. cp.ExStyle |= 0x02000000;
  56. return cp;
  57. }
  58. }
  59. /// <summary>
  60. /// ESC撤销此次编辑操作
  61. /// </summary>
  62. /// <param name="msg"></param>
  63. /// <param name="keyData"></param>
  64. /// <returns></returns>
  65. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  66. {
  67. int WM_KEYDOWN = 256;
  68. int WM_SYSKEYDOWN = 260;
  69. if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
  70. {
  71. switch (keyData)
  72. {
  73. case Keys.Escape:
  74. //if (groupOperation.Visible)
  75. //{
  76. // btnExit_Click(null, null);
  77. //}
  78. break;
  79. }
  80. }
  81. return false;
  82. }
  83. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  84. {
  85. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  86. {
  87. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  88. {
  89. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  90. {
  91. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  92. }
  93. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  94. }
  95. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  96. {
  97. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  98. {
  99. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  100. }
  101. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  102. }
  103. else
  104. {
  105. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  106. {
  107. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  108. }
  109. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  110. }
  111. }
  112. }
  113. /// <summary>
  114. /// 选择行主键列表
  115. /// </summary>
  116. private List<string> _CheckRowIdList = new List<string>();
  117. /// <summary>
  118. /// 当前页面操作的主键
  119. /// </summary>
  120. private string _PrimaryKey = "USER_ID";
  121. private void btnRemove_Click(object sender, EventArgs e)
  122. {
  123. if (_CheckRowIdList.Count == 0)
  124. {
  125. return;
  126. }
  127. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  128. {
  129. _LastOperation = EnumOperation.Remove;
  130. var editResult = SysSettingsServices.userService.Deleted(new UserCondition
  131. {
  132. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  133. UserIds = string.Join(",", _CheckRowIdList)
  134. });
  135. if (editResult.Status == OperateStatus.Success)
  136. {
  137. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  138. //groupOperation.Visible = false;
  139. btnSearch_Click(null, null);
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// 控件初始化
  145. /// </summary>
  146. private void InitControl()
  147. {
  148. CheckForIllegalCrossThreadCalls = false;
  149. //groupOperation.LostFocus += new EventHandler(groupOperation_LostFocus);
  150. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  151. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  152. dataGridView.BuildDataGridView(_clientFieldOrderList.GetFieldOrderDic(), false);
  153. var fieldValueList = (from x in _roleList
  154. select new FieldValue
  155. {
  156. Code = x.ROLE_CODE,
  157. Name = x.ROLE_NAME
  158. }).ToList();
  159. //cmbRole.DataSource = fieldValueList.Where((x, i) => fieldValueList.FindIndex(z => z.Code == x.Code) == i).ToList();
  160. //cmbRole.DisplayMember = "Name";
  161. //cmbRole.ValueMember = "Code";
  162. //cmbRole.SelectedIndex = -1;
  163. tableLayoutPanelSearch.SetFormPanelEnabled(AppConfig.CurrentMenu);
  164. tableLayoutPanelEdit.SetFormPanelEnabled(AppConfig.CurrentMenu);
  165. var fieldList = new List<FieldValue>().Add<FieldValue>(new FieldValue { Id = "", Name = "全部" });
  166. cmbSearchRole.DataSource = fieldList.GetFieldValueIdList(_roleList, "ROLE_CODE", "ROLE_NAME");
  167. cmbSearchRole.DisplayMember = "Name";
  168. cmbSearchRole.ValueMember = "Code";
  169. cmbSearchRole.SelectedIndex = -1;
  170. fieldList = new List<FieldValue>().Add<FieldValue>(new FieldValue { Id = "", Name = "全部" });
  171. cmbSearchGender.DataSource = fieldList.GetFieldValueIdList<GenderType>();
  172. cmbSearchGender.DisplayMember = "Name";
  173. cmbSearchGender.ValueMember = "Id";
  174. cmbSearchGender.SelectedIndex = -1;
  175. //cmbGender.DataSource = new List<FieldValue>().GetFieldValueIdList<GenderType>();
  176. //cmbGender.DisplayMember = "Name";
  177. //cmbGender.ValueMember = "Id";
  178. //cmbGender.SelectedIndex = -1;
  179. //暂时用代码限制长度,不用表配置之类做了..
  180. txtSearchIphone.SetControlBase(20);
  181. txtSearchUserInfo.SetControlBase(200);
  182. txtSerachJob.SetControlBase(50);
  183. txtSerachMail.SetControlBase(100);
  184. //txtUserCode.SetControlBase(50);
  185. //txtUserName.SetControlBase(100);
  186. //txtNickName.SetControlBase(50);
  187. //txtIphoneNumber.SetControlBase(20);
  188. //txtJobTitle.SetControlBase(50);
  189. //txtEmail.SetControlBase(100);
  190. //txtAddress.SetControlBase(200);
  191. }
  192. /// <summary>
  193. /// 数据初始化
  194. /// </summary>
  195. private void InitData()
  196. {
  197. //获取数据源配置
  198. var result = ConfigServices.configService.GetDataViewOrderList(new ClientFieldOrderCondition { SourceCode = $"{_CrrentClassName}" });
  199. if (result.Status == OperateStatus.Success)
  200. {
  201. _clientFieldOrderList = result.Data;
  202. }
  203. //获取角色
  204. var roleResult = SysSettingsServices.roleService.GetList(new RoleSearchCondition { IsUsed = true, ItemSQL = "ROLE_CODE,ROLE_NAME" });
  205. if (roleResult.Status == OperateStatus.Success)
  206. {
  207. _roleList = roleResult.Data.RowData.ToList();
  208. }
  209. }
  210. private void groupOperation_LostFocus(object sender, EventArgs e)
  211. {
  212. }
  213. private void groupOperation_GostFocus(object sender, EventArgs e)
  214. {
  215. //groupOperation.Values.Heading = _LastOperation.Display();
  216. //groupOperation.Text = $"正在{ _LastOperation.Display()}数据";
  217. //lbStatusMessage.Visible = true;
  218. }
  219. private void btnAdd_Click(object sender, EventArgs e)
  220. {
  221. var frm = new ChildFrm.FrmUserEdit();
  222. frm.Operation = EnumOperation.Add;
  223. frm.RoleList = this._roleList;
  224. frm.InitControl();
  225. if (frm.ShowDialog() == DialogResult.OK)
  226. {
  227. this.btnSearch_Click(null, null);
  228. }
  229. //if (!groupOperation.Visible)
  230. //{
  231. // tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  232. // _LastOperation = EnumOperation.Add;
  233. // txtUserCode.Enabled = true;
  234. // groupOperation.Visible = true;
  235. // groupOperation.Focus();
  236. //}
  237. }
  238. private void btnSearch_Click(object sender, EventArgs e)
  239. {
  240. var loadfrm = new frmLoading();
  241. loadfrm.Show();
  242. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  243. if (!string.IsNullOrWhiteSpace(message))
  244. {
  245. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  246. }
  247. }
  248. private string LoadSearch(int pageIndex, int pageSize)
  249. {
  250. var result = SysSettingsServices.userService.GetList(new UserSearchCondition
  251. {
  252. Address = txtSerachAddress.Text,
  253. Email = txtSerachMail.Text,
  254. Gender = cmbSearchGender.SelectedValue.GetObjectToInt(),
  255. IphoneNumber = txtSearchIphone.Text,
  256. JobTitle = txtSerachJob.Text,
  257. UserInfo = txtSearchUserInfo.Text,
  258. PageIndex = pageIndex,
  259. PageSize = pageSize,
  260. IsUsed = chkSearchUse.Checked,
  261. });
  262. if (result.Status == OperateStatus.Success)
  263. {
  264. this.pageTool.DataCount = result.Data.TotalCount;
  265. if (result.Data.RowData.Any())
  266. {
  267. dataGridView.Columns.Clear();
  268. dataGridView.DataSource = result.Data.RowData.ToList();
  269. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  270. }
  271. else
  272. {
  273. if (dataGridView.DataSource != null)
  274. {
  275. dataGridView.DataSource = new List<UserResult>();
  276. }
  277. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  278. }
  279. return string.Empty;
  280. }
  281. else
  282. {
  283. return result.Message;
  284. }
  285. }
  286. private void btnExit_Click(object sender, EventArgs e)
  287. {
  288. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  289. {
  290. //groupOperation.Visible = false;
  291. }
  292. else
  293. {
  294. //groupOperation.Visible = true;
  295. //groupOperation.Focus();
  296. }
  297. }
  298. private Point mouse_offset;
  299. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  300. {
  301. mouse_offset = new Point(-e.X, -e.Y);
  302. }
  303. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  304. {
  305. ((Control)sender).Cursor = Cursors.Arrow;
  306. if (e.Button == MouseButtons.Left)
  307. {
  308. Point mousePos = MousePosition;
  309. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  310. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  311. Application.DoEvents();
  312. }
  313. }
  314. private void btnEdit_Click(object sender, EventArgs e)
  315. {
  316. this.dataGridView_CellDoubleClick(null, null);
  317. //if (dataGridView.CurrentRow == null)
  318. //{
  319. // return;
  320. //}
  321. //if (!groupOperation.Visible)
  322. //{
  323. // _selectIndex = dataGridView.CurrentRow.Index;
  324. // if (_selectIndex >= 0)
  325. // {
  326. // _LastOperation = EnumOperation.Edit;
  327. // _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  328. // tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  329. // txtUserCode.Enabled = false;
  330. // groupOperation.Visible = true;
  331. // groupOperation.Focus();
  332. // }
  333. //}
  334. }
  335. private string _selectRuleCode;
  336. private int _selectIndex;
  337. private int _selectId;
  338. //private void btnSave_Click(object sender, EventArgs e)
  339. //{
  340. // if (string.IsNullOrWhiteSpace(txtUserCode.Text))
  341. // {
  342. // KryptonMessageBox.Show($"请输入用户编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  343. // return;
  344. // }
  345. // if (string.IsNullOrWhiteSpace(txtUserName.Text))
  346. // {
  347. // KryptonMessageBox.Show($"请输入用户名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  348. // return;
  349. // }
  350. // if (string.IsNullOrWhiteSpace(cmbGender.Text))
  351. // {
  352. // KryptonMessageBox.Show($"请选择性别。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  353. // return;
  354. // }
  355. // switch (_LastOperation)
  356. // {
  357. // case EnumOperation.Add:
  358. // var addResult = SysSettingsServices.userService.Add(new UserCondition
  359. // {
  360. // JobTitle = txtJobTitle.Text,
  361. // NickName = txtNickName.Text,
  362. // Address = txtAddress.Text,
  363. // PhoneNumber = txtIphoneNumber.Text,
  364. // UserName = txtUserName.Text,
  365. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  366. // Email = txtEmail.Text,
  367. // Gender = cmbGender.SelectedValue.GetObjectToInt().Value,
  368. // IsUsed = chkUse.Checked,
  369. // RoleCode = cmbRole.SelectedValue.GetObjectToString(),
  370. // UserCode = txtUserCode.Text,
  371. // });
  372. // if (addResult.Status == OperateStatus.Success)
  373. // {
  374. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  375. // groupOperation.Visible = false;
  376. // btnSearch_Click(null, null);
  377. // dataGridView.ClearSelection();
  378. // }
  379. // else
  380. // {
  381. // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  382. // }
  383. // break;
  384. // case EnumOperation.Edit:
  385. // var editResult = SysSettingsServices.userService.Edit(new UserCondition
  386. // {
  387. // JobTitle = txtJobTitle.Text.Trim(),
  388. // NickName = txtNickName.Text,
  389. // Address = txtAddress.Text,
  390. // PhoneNumber = txtIphoneNumber.Text,
  391. // UserName = txtUserName.Text,
  392. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  393. // Email = txtEmail.Text,
  394. // Gender = cmbGender.SelectedValue.GetObjectToInt().Value,
  395. // IsUsed = chkUse.Checked,
  396. // RoleCode = cmbRole.SelectedValue.GetObjectToString(),
  397. // UserId = _selectId,
  398. // });
  399. // if (editResult.Status == OperateStatus.Success)
  400. // {
  401. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  402. // groupOperation.Visible = false;
  403. // btnSearch_Click(null, null);
  404. // dataGridView.ClearSelection();
  405. // }
  406. // else
  407. // {
  408. // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  409. // }
  410. // break;
  411. // }
  412. //}
  413. private void cmbRule_SelectedIndexChanged(object sender, EventArgs e)
  414. {
  415. //if (cmbRole.SelectedValue != null)
  416. //{
  417. // _selectRuleCode = cmbRole.SelectedValue.ToString();
  418. //}
  419. //else
  420. //{
  421. // _selectRuleCode = "";
  422. //}
  423. }
  424. private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
  425. {
  426. // e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1);
  427. }
  428. private void btnSearchExport_Click(object sender, EventArgs e)
  429. {
  430. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault()}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  431. }
  432. private void SelectInit()
  433. {
  434. _selectIndex = dataGridView.SelectedRows[0].Index;
  435. if (_selectIndex >= 0)
  436. {
  437. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  438. }
  439. }
  440. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  441. {
  442. SelectInit();
  443. if (_selectIndex >= 0)
  444. {
  445. var frm = new ChildFrm.FrmUserEdit();
  446. frm.Operation = EnumOperation.Edit;
  447. frm.SelectId= this._selectId;
  448. frm.RoleList = this._roleList;
  449. frm.InitControl();
  450. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  451. if (frm.ShowDialog() == DialogResult.OK)
  452. {
  453. this.btnSearch_Click(null, null);
  454. }
  455. //_LastOperation = EnumOperation.Edit;
  456. //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  457. ////richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  458. //// dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  459. //txtUserCode.Enabled = false;
  460. //groupOperation.Visible = true;
  461. //groupOperation.Focus();
  462. }
  463. }
  464. private void btnClear_Click(object sender, EventArgs e)
  465. {
  466. txtSearchUserInfo.Text = "";
  467. txtSearchIphone.Text = "";
  468. txtSerachAddress.Text = "";
  469. txtSerachJob.Text = "";
  470. txtSerachMail.Text = "";
  471. cmbSearchGender.SelectedIndex = -1;
  472. cmbSearchRole.SelectedIndex = -1;
  473. }
  474. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  475. {
  476. this.btnSearch_Click(null, null);
  477. }
  478. }
  479. }