frmMenu.cs 19 KB

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