frmParameter.cs 19 KB

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