frmRegion.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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.Base;
  5. using NXWMS.Client.Model.AppModels.Result;
  6. using NXWMS.Client.Model.AppModels.Result.Base;
  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.Base
  20. {
  21. public partial class frmRegion : 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. /// <summary>
  36. /// 仓库列表
  37. /// </summary>
  38. private List<WarehouseResult> _warehouseList;
  39. /// <summary>
  40. /// 区域列表
  41. /// </summary>
  42. private List<AreaResult> _areaList;
  43. private int _selectIndex;
  44. private int _selectId;
  45. public frmRegion()
  46. {
  47. InitializeComponent();
  48. _CrrentClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;
  49. InitData();
  50. InitControl();
  51. }
  52. protected override CreateParams CreateParams
  53. {
  54. get
  55. {
  56. CreateParams cp = base.CreateParams;
  57. cp.ExStyle |= 0x02000000;
  58. return cp;
  59. }
  60. }
  61. private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
  62. {
  63. e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1);
  64. }
  65. private void btnSearch_Click(object sender, EventArgs e)
  66. {
  67. _pageIndex = 1;
  68. var loadfrm = new frmLoading();
  69. loadfrm.Show();
  70. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  71. pageTool.DataCount = _totalCount;
  72. if (!string.IsNullOrWhiteSpace(message))
  73. {
  74. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  75. }
  76. }
  77. private int _pageSize;
  78. private int _pageIndex;
  79. private int _totalCount;
  80. private string LoadSearch(int pageIndex, int pageSize)
  81. {
  82. var result = BaseServices.regionService.GetList(new RegionSearchCondition
  83. {
  84. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  85. RegionCode = txtSearchRegionCode.Text,
  86. RegionName = txtSearchRegionName.Text,
  87. PageIndex = pageIndex,
  88. PageSize = pageSize,
  89. IsUsed = chkSearchUse.Checked,
  90. });
  91. if (result.Status == OperateStatus.Success)
  92. {
  93. _totalCount = result.Data.TotalCount;
  94. _pageIndex = pageIndex;
  95. _pageSize = pageSize;
  96. if (result.Data.RowData.Any())
  97. {
  98. dataGridView.Columns.Clear();
  99. dataGridView.DataSource = result.Data.RowData.ToList();
  100. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  101. }
  102. else
  103. {
  104. if (dataGridView.DataSource != null)
  105. {
  106. dataGridView.DataSource = new List<RegionResult>();
  107. }
  108. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  109. }
  110. return string.Empty;
  111. }
  112. else
  113. {
  114. return result.Message;
  115. }
  116. }
  117. /// <summary>
  118. /// 数据初始化
  119. /// </summary>
  120. private void InitData()
  121. {
  122. var areaResult = BaseServices.areaService.GetList(new AreaSearchCondition { IsUsed = true, ItemSQL = "AREA_CODE,AREA_NAME" });
  123. if (areaResult.Status == OperateStatus.Success)
  124. {
  125. _areaList = areaResult.Data.RowData.ToList();
  126. }
  127. var warehouseResult = BaseServices.warehouseService.GetList(new WarehouseSearchCondition { IsUsed = true, ItemSQL = "WAREHOUSE_CODE,WAREHOUSE_NAME" });
  128. if (warehouseResult.Status == OperateStatus.Success)
  129. {
  130. _warehouseList = warehouseResult.Data.RowData.ToList();
  131. }
  132. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  133. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "AREA_NAME", FieldDesc = "区域" });
  134. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "WAREHOUSE_NAME", FieldDesc = "仓库" });
  135. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "REGION_CODE", FieldDesc = "库区编码" });
  136. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  137. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  138. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  139. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  140. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  141. }
  142. /// <summary>
  143. /// 控件初始化
  144. /// </summary>
  145. private void InitControl()
  146. {
  147. CheckForIllegalCrossThreadCalls = false;
  148. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  149. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  150. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  151. //this.groupOperation.MouseDown += new System.Windows.Forms.MouseEventHandler(this.groupOperation_MouseDown);
  152. //this.groupOperation.MouseMove += new System.Windows.Forms.MouseEventHandler(this.groupOperation_MouseMove);
  153. //cmbAreaCode.DataSource = _areaList;
  154. //cmbAreaCode.DisplayMember = "AREA_NAME";
  155. //cmbAreaCode.ValueMember = "AREA_CODE";
  156. //cmbAreaCode.SelectedIndex = -1;
  157. //cmbWarehouse.DataSource = _warehouseList;
  158. //cmbWarehouse.DisplayMember = "WAREHOUSE_NAME";
  159. //cmbWarehouse.ValueMember = "WAREHOUSE_CODE";
  160. //cmbWarehouse.SelectedIndex = -1;
  161. _pageSize = 20;
  162. _pageIndex = 1;
  163. }
  164. private void groupOperation_GostFocus(object sender, EventArgs e)
  165. {
  166. //groupOperation.Values.Heading = _LastOperation.Display();
  167. ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
  168. //groupOperation.Text = $"{ _LastOperation.Display()}数据";
  169. //lbStatusMessage.Visible = true;
  170. }
  171. private void btnAdd_Click(object sender, EventArgs e)
  172. {
  173. var frm = new ChildFrm.FrmRegionEdit();
  174. frm.WarehouseList = this._warehouseList;
  175. frm.AreaList = this._areaList;
  176. frm.operation = EnumOperation.Add;
  177. frm.InitControl();
  178. if (frm.ShowDialog() == DialogResult.OK)
  179. {
  180. this.btnSearch_Click(null, null
  181. );
  182. }
  183. //if (!groupOperation.Visible)
  184. //{
  185. // tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  186. // richDescibe.Text = "";
  187. // _LastOperation = EnumOperation.Add;
  188. // txtRegionCode.Enabled = true;
  189. // groupOperation.Visible = true;
  190. // groupOperation.Focus();
  191. //}
  192. }
  193. private void btnEdit_Click(object sender, EventArgs e)
  194. {
  195. this.dataGridView_CellDoubleClick(null, null);
  196. //if (!groupOperation.Visible)
  197. //{
  198. // SelectInit();
  199. // if (_selectIndex >= 0)
  200. // {
  201. // var frm = new ChildFrm.FrmRegionEdit();
  202. // frm.WarehouseList = this._warehouseList;
  203. // frm.AreaList = this._areaList;
  204. // frm.operation = EnumOperation.Edit;
  205. // frm.Id = this._selectId;
  206. // frm.InitControl();
  207. // frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  208. // if (frm.ShowDialog() == DialogResult.OK)
  209. // {
  210. // this.btnSearch_Click(null, null);
  211. // }
  212. // //_LastOperation = EnumOperation.Edit;
  213. // //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  214. // // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  215. // //groupOperation.Visible = true;
  216. // //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  217. // //txtRegionCode.Enabled = false;
  218. // //groupOperation.Visible = true;
  219. // //groupOperation.Focus();
  220. // }
  221. //}
  222. }
  223. private void SelectInit()
  224. {
  225. _selectIndex = dataGridView.SelectedRows[0].Index;
  226. if (_selectIndex >= 0)
  227. {
  228. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  229. }
  230. }
  231. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  232. {
  233. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  234. {
  235. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  236. {
  237. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  238. {
  239. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  240. }
  241. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  242. }
  243. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  244. {
  245. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  246. {
  247. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  248. }
  249. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  250. }
  251. else
  252. {
  253. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  254. {
  255. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  256. }
  257. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  258. }
  259. }
  260. }
  261. /// <summary>
  262. /// 选择行主键列表
  263. /// </summary>
  264. private List<string> _CheckRowIdList = new List<string>();
  265. /// <summary>
  266. /// 当前页面操作的主键
  267. /// </summary>
  268. private string _PrimaryKey = "REGION_ID";
  269. private void btnRemove_Click(object sender, EventArgs e)
  270. {
  271. if (_CheckRowIdList.Count == 0)
  272. {
  273. return;
  274. }
  275. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  276. {
  277. _LastOperation = EnumOperation.Remove;
  278. var editResult = BaseServices.regionService.Deleted(new RegionCondition
  279. {
  280. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  281. Ids = string.Join(",", _CheckRowIdList)
  282. });
  283. if (editResult.Status == OperateStatus.Success)
  284. {
  285. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  286. //groupOperation.Visible = false;
  287. btnSearch_Click(null, null);
  288. }
  289. }
  290. }
  291. //private void btnSave_Click(object sender, EventArgs e)
  292. //{
  293. // if (string.IsNullOrWhiteSpace(cmbAreaCode.Text))
  294. // {
  295. // KryptonMessageBox.Show($"请选择区域!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  296. // return;
  297. // }
  298. // if (string.IsNullOrWhiteSpace(cmbWarehouse.Text))
  299. // {
  300. // KryptonMessageBox.Show($"请选择仓库!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  301. // return;
  302. // }
  303. // if (string.IsNullOrWhiteSpace(txtRegionCode.Text))
  304. // {
  305. // KryptonMessageBox.Show($"请输入库区编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  306. // return;
  307. // }
  308. // if (string.IsNullOrWhiteSpace(txtRegionName.Text))
  309. // {
  310. // KryptonMessageBox.Show($"请输入菜单名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  311. // return;
  312. // }
  313. // switch (_LastOperation)
  314. // {
  315. // case EnumOperation.Add:
  316. // var addResult = BaseServices.regionService.Add(new RegionCondition
  317. // {
  318. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  319. // IsUsed = chkUse.Checked,
  320. // RegionCode = txtRegionCode.Text,
  321. // RegionName = txtRegionName.Text,
  322. // AreaCode = cmbAreaCode.SelectedValue.GetObjectToString(),
  323. // Describe = richDescibe.Text,
  324. // WarehouseCode = cmbWarehouse.SelectedValue.GetObjectToString(),
  325. // });
  326. // if (addResult.Status == OperateStatus.Success)
  327. // {
  328. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  329. // InitControl();
  330. // groupOperation.Visible = false;
  331. // btnSearch_Click(null, null);
  332. // dataGridView.ClearSelection();
  333. // }
  334. // else
  335. // {
  336. // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  337. // }
  338. // break;
  339. // case EnumOperation.Edit:
  340. // var editResult = BaseServices.regionService.Edit(new RegionCondition
  341. // {
  342. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  343. // IsUsed = chkUse.Checked,
  344. // RegionCode = txtRegionCode.Text,
  345. // RegionName = txtRegionName.Text,
  346. // AreaCode = cmbAreaCode.SelectedValue == null ?
  347. // null : cmbAreaCode.SelectedValue.ToString(),
  348. // Describe = richDescibe.Text,
  349. // WarehouseCode = cmbWarehouse.SelectedValue == null ?
  350. // null : cmbWarehouse.SelectedValue.ToString(),
  351. // Id = _selectId
  352. // });
  353. // if (editResult.Status == OperateStatus.Success)
  354. // {
  355. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  356. // InitControl();
  357. // groupOperation.Visible = false;
  358. // btnSearch_Click(null, null);
  359. // dataGridView.ClearSelection();
  360. // }
  361. // else
  362. // {
  363. // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  364. // }
  365. // break;
  366. // }
  367. //}
  368. private void btnSearchExport_Click(object sender, EventArgs e)
  369. {
  370. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  371. }
  372. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  373. {
  374. SelectInit();
  375. if (_selectIndex >= 0)
  376. {
  377. var frm = new ChildFrm.FrmRegionEdit();
  378. frm.WarehouseList = this._warehouseList;
  379. frm.AreaList = this._areaList;
  380. frm.operation = EnumOperation.Edit;
  381. frm.Id = this._selectId;
  382. frm.InitControl();
  383. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  384. if (frm.ShowDialog() == DialogResult.OK)
  385. {
  386. this.btnSearch_Click(null, null);
  387. }
  388. //_LastOperation = EnumOperation.Edit;
  389. //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  390. // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  391. //groupOperation.Visible = true;
  392. //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  393. //txtRegionCode.Enabled = false;
  394. //groupOperation.Visible = true;
  395. //groupOperation.Focus();
  396. }
  397. //SelectInit();
  398. //if (_selectIndex >= 0)
  399. //{
  400. // _LastOperation = EnumOperation.Edit;
  401. // _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  402. // tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  403. // richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  404. // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  405. // txtRegionCode.Enabled = false;
  406. // groupOperation.Visible = true;
  407. // groupOperation.Focus();
  408. //}
  409. }
  410. private void btnExit_Click(object sender, EventArgs e)
  411. {
  412. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  413. {
  414. //groupOperation.Visible = false;
  415. }
  416. else
  417. {
  418. //groupOperation.Visible = true;
  419. //groupOperation.Focus();
  420. }
  421. }
  422. private Point mouse_offset;
  423. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  424. {
  425. mouse_offset = new Point(-e.X, -e.Y);
  426. }
  427. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  428. {
  429. ((Control)sender).Cursor = Cursors.Arrow;
  430. if (e.Button == MouseButtons.Left)
  431. {
  432. Point mousePos = MousePosition;
  433. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  434. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  435. Application.DoEvents();
  436. }
  437. }
  438. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  439. {
  440. this.btnSearch_Click(null, null);
  441. }
  442. }
  443. }