frmBin.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Code.Extends;
  3. using NXWMS.Client.Model.AppModels.Condition.Base;
  4. using NXWMS.Client.Model.AppModels.Result;
  5. using NXWMS.Client.Model.AppModels.Result.Base;
  6. using NXWMS.Client.Model.CoreModels;
  7. using NXWMS.Client.String.Enums;
  8. using NXWMS.Commons;
  9. using NXWMS.Services;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Drawing;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Windows.Forms;
  18. namespace NXWMS.Forms.Base
  19. {
  20. public partial class frmBin : KryptonForm
  21. {
  22. /// <summary>
  23. /// 界面最后执行操作
  24. /// </summary>
  25. private EnumOperation _LastOperation;
  26. /// <summary>
  27. /// 窗体类名
  28. /// </summary>
  29. private string _CrrentClassName;
  30. /// <summary>
  31. /// 客户端字段排序列表
  32. /// </summary>
  33. private List<ClientFieldOrderResult> _clientFieldOrderList;
  34. /// <summary>
  35. /// 库区列表
  36. /// </summary>
  37. private List<RegionResult> _regionList;
  38. /// <summary>
  39. /// 仓库列表
  40. /// </summary>
  41. private List<WarehouseResult> _warehouseList;
  42. /// <summary>
  43. /// 区域列表
  44. /// </summary>
  45. private List<AreaResult> _areaList;
  46. //private int _pageSize;
  47. //private int _pageIndex;
  48. //private int _totalCount;
  49. private int _selectIndex;
  50. private int _selectId;
  51. private string _selectWarehouseCode;
  52. private string _selectAreaCode;
  53. private string _selectRegionCode;
  54. protected override CreateParams CreateParams
  55. {
  56. get
  57. {
  58. CreateParams cp = base.CreateParams;
  59. cp.ExStyle |= 0x02000000;
  60. return cp;
  61. }
  62. }
  63. public frmBin()
  64. {
  65. InitializeComponent();
  66. _CrrentClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;
  67. InitData();
  68. InitControl();
  69. }
  70. //private void cmbRegionCode_SelectedIndexChanged(object sender, EventArgs e)
  71. //{
  72. // if (cmbRegionCode.SelectedValue != null)
  73. // {
  74. // var regionInfo = _regionList.Where(s => s.REGION_CODE == cmbRegionCode.SelectedValue.ToString()).FirstOrDefault();
  75. // if (regionInfo != null)
  76. // {
  77. // _selectAreaCode = regionInfo.AREA_CODE;
  78. // _selectWarehouseCode = regionInfo.WAREHOUSE_CODE;
  79. // lbWarehouse.Text = regionInfo.AREA_NAME;
  80. // _selectRegionCode = regionInfo.REGION_CODE;
  81. // lbRegion.Text = regionInfo.AREA_NAME;
  82. // }
  83. // }
  84. //}
  85. /// <summary>
  86. /// 数据初始化
  87. /// </summary>
  88. private void InitData()
  89. {
  90. var regionResult = BaseServices.regionService.GetList(new RegionSearchCondition { IsUsed = true, ItemSQL = "REGION_CODE,REGION_NAME,AREA_NAME,AREA_CODE,WAREHOUSE_CODE,WAREHOUSE_NAME" });
  91. if (regionResult.Status == OperateStatus.Success)
  92. {
  93. _regionList = regionResult.Data.RowData.ToList();
  94. }
  95. var warehouseResult = BaseServices.warehouseService.GetList(new WarehouseSearchCondition { IsUsed = true, ItemSQL = "WAREHOUSE_CODE,WAREHOUSE_NAME" });
  96. if (warehouseResult.Status == OperateStatus.Success)
  97. {
  98. _warehouseList = warehouseResult.Data.RowData.ToList();
  99. }
  100. var areaResult = BaseServices.areaService.GetList(new AreaSearchCondition { IsUsed = true, ItemSQL = "AREA_CODE,AREA_NAME" });
  101. if (areaResult.Status == OperateStatus.Success)
  102. {
  103. _areaList = areaResult.Data.RowData.ToList();
  104. }
  105. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  106. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "AREA_NAME", FieldDesc = "区域" });
  107. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "WAREHOUSE_NAME", FieldDesc = "仓库" });
  108. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "REGION_NAME", FieldDesc = "库区" });
  109. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "TUNNEL", FieldDesc = "巷道" });
  110. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_CODE", FieldDesc = "库位编码" });
  111. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BinTypeName", FieldDesc = "库位类型" });
  112. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_ROW", FieldDesc = "排" });
  113. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_COLUMN", FieldDesc = "列" });
  114. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BIN_LAYER", FieldDesc = "层" });
  115. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "LENGTH", FieldDesc = "长(M)" });
  116. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "WIDE", FieldDesc = "宽(M)" });
  117. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "HEIGHT", FieldDesc = "高(M)" });
  118. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PUT_SHELF_ORDER", FieldDesc = "上架顺序" });
  119. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DOWN_SHELF_ORDER", FieldDesc = "下架顺序" });
  120. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "VOLUME_LIMIT", FieldDesc = "体积限制" });
  121. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "WEIGHT_LIMIT", FieldDesc = "重量限制(KG)" });
  122. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "NUMBER_LIMIT", FieldDesc = "数量限制" });
  123. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "TRAR_LIMIT", FieldDesc = "托盘限制" });
  124. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BLEND_PRODUCT_FLAG", FieldDesc = "允许混放产品" });
  125. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "BLEND_BATCH_FLAG", FieldDesc = "允许混放批次" });
  126. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  127. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  128. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  129. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  130. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  131. }
  132. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  133. {
  134. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  135. {
  136. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  137. {
  138. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  139. {
  140. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  141. }
  142. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  143. }
  144. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  145. {
  146. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  147. {
  148. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  149. }
  150. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  151. }
  152. else
  153. {
  154. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  155. {
  156. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  157. }
  158. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  159. }
  160. }
  161. }
  162. /// <summary>
  163. /// 选择行主键列表
  164. /// </summary>
  165. private List<string> _CheckRowIdList = new List<string>();
  166. /// <summary>
  167. /// 当前页面操作的主键
  168. /// </summary>
  169. private string _PrimaryKey = "BIN_ID";
  170. private void btnRemove_Click(object sender, EventArgs e)
  171. {
  172. if (_CheckRowIdList.Count == 0)
  173. {
  174. return;
  175. }
  176. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  177. {
  178. _LastOperation = EnumOperation.Remove;
  179. var editResult = BaseServices.binService.Deleted(new BinCondition
  180. {
  181. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  182. Ids = string.Join(",", _CheckRowIdList)
  183. });
  184. if (editResult.Status == OperateStatus.Success)
  185. {
  186. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  187. //groupOperation.Visible = false;
  188. btnSearch_Click(null, null);
  189. }
  190. }
  191. }
  192. /// <summary>
  193. /// 控件初始化
  194. /// </summary>
  195. private void InitControl()
  196. {
  197. CheckForIllegalCrossThreadCalls = false;
  198. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  199. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  200. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  201. //cmbRegionCode.DataSource = _regionList;
  202. //cmbRegionCode.DisplayMember = "REGION_NAME";
  203. //cmbRegionCode.ValueMember = "REGION_CODE";
  204. //cmbRegionCode.SelectedIndex = -1;
  205. cmbSearchRegionCode.DataSource = _regionList;
  206. cmbSearchRegionCode.DisplayMember = "REGION_NAME";
  207. cmbSearchRegionCode.ValueMember = "REGION_CODE";
  208. cmbSearchRegionCode.SelectedIndex = -1;
  209. var fieldList = new List<FieldValue>().GetFieldValueCodeList<BinType>();
  210. cmbSearchBinType.DataSource = fieldList;
  211. cmbSearchBinType.DisplayMember = "Name";
  212. cmbSearchBinType.ValueMember = "Code";
  213. cmbSearchBinType.SelectedIndex = -1;
  214. //cmbBinType.DataSource = fieldList;
  215. //cmbBinType.DisplayMember = "Name";
  216. //cmbBinType.ValueMember = "Code";
  217. //cmbBinType.SelectedIndex = -1;
  218. ////TODO 这是一个字典表,需要改
  219. //fieldList = new List<FieldValue>();
  220. //fieldList.Add(new FieldValue { Code = "Common", Name = "临时货架排" });
  221. //cmbShelf.DataSource = fieldList;
  222. //cmbShelf.DisplayMember = "Name";
  223. //cmbShelf.ValueMember = "Code";
  224. //cmbShelf.SelectedIndex = -1;
  225. //_pageIndex = 1;
  226. //_pageSize = 20;
  227. }
  228. private void groupOperation_GostFocus(object sender, EventArgs e)
  229. {
  230. //groupOperation.Values.Heading = _LastOperation.Display();
  231. ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
  232. //groupOperation.Text = $"{ _LastOperation.Display()}数据";
  233. //lbStatusMessage.Visible = true;
  234. }
  235. private void btnSearch_Click(object sender, EventArgs e)
  236. {
  237. // _pageIndex = 1;
  238. var loadfrm = new frmLoading();
  239. loadfrm.Show();
  240. // pageTool.Initialize(LoadSearch, 0, _pageSize);
  241. var message = loadfrm.EventCalExec(LoadSearch, pageTool.PageIndex, pageTool.PageSize);
  242. if (!string.IsNullOrWhiteSpace(message))
  243. {
  244. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  245. }
  246. }
  247. private string LoadSearch(int pageIndex, int pageSize)
  248. {
  249. var result = BaseServices.binService.GetList(new BinSearchCondition
  250. {
  251. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  252. BinCode = txtSearchBinCode.Text,
  253. RegionCode = cmbSearchRegionCode.SelectedValue.GetObjectToString(),
  254. BinColumn = Convert.ToInt32(numSearchBinColumn.Value),
  255. BinRow = Convert.ToInt32(numSearchBinRow.Value),
  256. BinType = cmbSearchBinType.SelectedValue.GetObjectToString(),
  257. IsUsed = chkSearchUse.Checked,
  258. PageIndex = pageIndex,
  259. PageSize = pageSize
  260. });
  261. if (result.Status == OperateStatus.Success)
  262. {
  263. pageTool.DataCount = result.Data.TotalCount;
  264. if (result.Data.RowData.Any())
  265. {
  266. dataGridView.Columns.Clear();
  267. dataGridView.DataSource = result.Data.RowData.ToList();
  268. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  269. }
  270. else
  271. {
  272. if (dataGridView.DataSource != null)
  273. {
  274. dataGridView.DataSource = new List<BinResult>();
  275. }
  276. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  277. }
  278. return string.Empty;
  279. }
  280. else
  281. {
  282. return result.Message;
  283. }
  284. }
  285. private void btnAdd_Click(object sender, EventArgs e)
  286. {
  287. var frm = new ChildFrm.FrmBinEdit();
  288. frm.RegionList = this._regionList;
  289. frm.Operation = EnumOperation.Add;
  290. frm.InitControl();
  291. if (frm.ShowDialog() == DialogResult.OK)
  292. {
  293. btnSearch_Click(null, null);
  294. dataGridView.ClearSelection();
  295. }
  296. //if (!groupOperation.Visible)
  297. //{
  298. // _selectId = 0;
  299. // _selectRegionCode = "";
  300. // _selectWarehouseCode = "";
  301. // _selectAreaCode = "";
  302. // lbWarehouse.Text = ".";
  303. // lbRegion.Text = ".";
  304. // tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  305. // richDescibe.Text = "";
  306. // _LastOperation = EnumOperation.Add;
  307. // txtBinCode.Enabled = true;
  308. // groupOperation.Visible = true;
  309. // groupOperation.Focus();
  310. //}
  311. }
  312. private void btnEdit_Click(object sender, EventArgs e)
  313. {
  314. dataGridView_CellDoubleClick(null, null);
  315. }
  316. private void SelectInit()
  317. {
  318. _selectIndex = dataGridView.SelectedRows.Count > 0 ? dataGridView.SelectedRows[0].Index : -1;
  319. if (_selectIndex >= 0)
  320. {
  321. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  322. }
  323. }
  324. private void btnSearchExport_Click(object sender, EventArgs e)
  325. {
  326. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  327. }
  328. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  329. {
  330. SelectInit();
  331. if (_selectIndex >= 0)
  332. {
  333. var frm = new ChildFrm.FrmBinEdit();
  334. frm.Operation = EnumOperation.Edit;
  335. frm.RegionList = this._regionList;
  336. frm.Id = this._selectId;
  337. frm.InitControl();
  338. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  339. if (frm.ShowDialog() == DialogResult.OK)
  340. {
  341. this.btnSearch_Click(null, null);
  342. dataGridView.ClearSelection();
  343. }
  344. //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  345. // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  346. //txtBinCode.Enabled = false;
  347. //groupOperation.Visible = true;
  348. //groupOperation.Focus();
  349. }
  350. }
  351. private Point mouse_offset;
  352. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  353. {
  354. mouse_offset = new Point(-e.X, -e.Y);
  355. }
  356. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  357. {
  358. ((Control)sender).Cursor = Cursors.Arrow;
  359. if (e.Button == MouseButtons.Left)
  360. {
  361. Point mousePos = MousePosition;
  362. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  363. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  364. Application.DoEvents();
  365. }
  366. }
  367. private void btnExit_Click(object sender, EventArgs e)
  368. {
  369. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  370. {
  371. //groupOperation.Visible = false;
  372. }
  373. else
  374. {
  375. //groupOperation.Visible = true;
  376. //groupOperation.Focus();
  377. }
  378. }
  379. private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
  380. {
  381. e.Row.HeaderCell.Value = string.Format("{0}", (this.pageTool.PageIndex - 1) * this.pageTool.PageSize + e.Row.Index + 1);
  382. }
  383. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  384. {
  385. this.btnSearch_Click(null, null);
  386. }
  387. private void chkSearchUse_CheckedChanged(object sender, EventArgs e)
  388. {
  389. }
  390. private void btnSearchImport_Click(object sender, EventArgs e)
  391. {
  392. var SyncResult = BaseServices.binService.SyncERP();
  393. if (SyncResult.Status == OperateStatus.Success)
  394. {
  395. this.btnSearch_Click(null, null);
  396. }
  397. else
  398. {
  399. KryptonMessageBox.Show($"操作失败!\r\n{SyncResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  400. }
  401. }
  402. }
  403. }