frmPallet.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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.Forms.Base.ChildFrm;
  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 frmPallet : KryptonForm
  22. {
  23. /// 界面最后执行操作
  24. /// </summary>
  25. private EnumOperation _LastOperation;
  26. /// <summary>
  27. /// 客户端字段排序列表
  28. /// </summary>
  29. private List<ClientFieldOrderResult> _clientFieldOrderList;
  30. /// <summary>
  31. /// 托盘类型列表
  32. /// </summary>
  33. private List<PalletTypeResult> _palletTypeList;
  34. /// <summary>
  35. /// 模板地址
  36. /// </summary>
  37. private string _reportFolder = Application.StartupPath + "\\ReportMd\\";
  38. private int _selectIndex;
  39. private int _selectId;
  40. public frmPallet()
  41. {
  42. InitializeComponent();
  43. InitData();
  44. InitControl();
  45. }
  46. protected override CreateParams CreateParams
  47. {
  48. get
  49. {
  50. CreateParams cp = base.CreateParams;
  51. cp.ExStyle |= 0x02000000;
  52. return cp;
  53. }
  54. }
  55. /// <summary>
  56. /// 数据初始化
  57. /// </summary>
  58. private void InitData()
  59. {
  60. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  61. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PALLET_CODE", FieldDesc = "托盘编码" });
  62. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PALLET_NAME", FieldDesc = "托盘名称" });
  63. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PalletTypeName", FieldDesc = "托盘类型" });
  64. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  65. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DESCRIBE", FieldDesc = "描述" });
  66. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  67. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  68. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  69. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  70. //获取数据源配置
  71. var result = BaseServices.palletTypeService.GetList(new PalletTypeSearchCondition { IsUsed = true, ItemSQL = "PALLET_TYPE_CODE,PALLET_TYPE_NAME" });
  72. if (result.Status == OperateStatus.Success)
  73. {
  74. _palletTypeList = result.Data.RowData.ToList();
  75. }
  76. }
  77. /// <summary>
  78. /// 控件初始化
  79. /// </summary>
  80. private void InitControl()
  81. {
  82. CheckForIllegalCrossThreadCalls = false;
  83. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  84. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  85. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  86. //cmbPalletType.DataSource = _palletTypeList;
  87. //cmbPalletType.DisplayMember = "PALLET_TYPE_NAME";
  88. //cmbPalletType.ValueMember = "PALLET_TYPE_CODE";
  89. //cmbPalletType.SelectedIndex = -1;
  90. _pageIndex = 1;
  91. _pageSize = 20;
  92. }
  93. private void groupOperation_GostFocus(object sender, EventArgs e)
  94. {
  95. //groupOperation.Values.Heading = _LastOperation.Display();
  96. ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
  97. //groupOperation.Text = $"{ _LastOperation.Display()}数据";
  98. //lbStatusMessage.Visible = true;
  99. }
  100. private void btnSearch_Click(object sender, EventArgs e)
  101. {
  102. _pageIndex = 1;
  103. var loadfrm = new frmLoading();
  104. loadfrm.Show();
  105. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  106. pageTool.DataCount = _totalCount;
  107. if (!string.IsNullOrWhiteSpace(message))
  108. {
  109. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  110. }
  111. }
  112. private int _pageSize;
  113. private int _pageIndex;
  114. private int _totalCount;
  115. private string LoadSearch(int pageIndex, int pageSize)
  116. {
  117. var result = BaseServices.palletService.GetList(new PalletSearchCondition
  118. {
  119. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  120. PalletInfo = txtSearchPalletInfo.Text,
  121. IsUsed = chkSearchUse.Checked,
  122. PageIndex = pageIndex,
  123. PageSize = pageSize
  124. });
  125. if (result.Status == OperateStatus.Success)
  126. {
  127. _totalCount = result.Data.TotalCount;
  128. _pageIndex = pageIndex;
  129. _pageSize = pageSize;
  130. if (result.Data.RowData.Any())
  131. {
  132. dataGridView.Columns.Clear();
  133. dataGridView.DataSource = result.Data.RowData.ToList();
  134. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  135. }
  136. else
  137. {
  138. if (dataGridView.DataSource != null)
  139. {
  140. dataGridView.DataSource = new List<PalletResult>();
  141. }
  142. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  143. }
  144. return string.Empty;
  145. }
  146. else
  147. {
  148. return result.Message;
  149. }
  150. }
  151. private void btnAdd_Click(object sender, EventArgs e)
  152. {
  153. var frm = new ChildFrm.FrmPalletEdit();
  154. frm.operation = EnumOperation.Add;
  155. frm.PalletTypeList = this._palletTypeList;
  156. frm.InitControl();
  157. if (frm.ShowDialog() == DialogResult.OK)
  158. {
  159. this.btnSearch_Click(null, null);
  160. }
  161. //_selectId = 0;
  162. //tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  163. //richDescibe.Text = "";
  164. //_LastOperation = EnumOperation.Add;
  165. //txtPalletCode.Enabled = true;
  166. //groupOperation.Visible = true;
  167. //groupOperation.Focus();
  168. }
  169. private void SelectInit()
  170. {
  171. _selectIndex = dataGridView.SelectedRows[0].Index;
  172. if (_selectIndex >= 0)
  173. {
  174. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  175. }
  176. }
  177. private void btnEdit_Click(object sender, EventArgs e)
  178. {
  179. dataGridView_CellDoubleClick(null, null);
  180. }
  181. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  182. {
  183. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  184. {
  185. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  186. {
  187. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  188. {
  189. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  190. }
  191. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  192. }
  193. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  194. {
  195. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  196. {
  197. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  198. }
  199. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  200. }
  201. else
  202. {
  203. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  204. {
  205. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  206. }
  207. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  208. }
  209. }
  210. }
  211. /// <summary>
  212. /// 选择行主键列表
  213. /// </summary>
  214. private List<string> _CheckRowIdList = new List<string>();
  215. /// <summary>
  216. /// 当前页面操作的主键
  217. /// </summary>
  218. private string _PrimaryKey = "PALLET_ID";
  219. private void btnRemove_Click(object sender, EventArgs e)
  220. {
  221. if (_CheckRowIdList.Count == 0)
  222. {
  223. return;
  224. }
  225. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  226. {
  227. _LastOperation = EnumOperation.Remove;
  228. var editResult = BaseServices.palletService.Deleted(new PalletCondition
  229. {
  230. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  231. Ids = string.Join(",", _CheckRowIdList)
  232. });
  233. if (editResult.Status == OperateStatus.Success)
  234. {
  235. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  236. //groupOperation.Visible = false;
  237. btnSearch_Click(null, null);
  238. }
  239. }
  240. }
  241. //private void btnSave_Click(object sender, EventArgs e)
  242. //{
  243. // if (string.IsNullOrWhiteSpace(txtPalletCode.Text))
  244. // {
  245. // KryptonMessageBox.Show($"请输入托盘编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  246. // return;
  247. // }
  248. // if (string.IsNullOrWhiteSpace(txtPalletName.Text))
  249. // {
  250. // KryptonMessageBox.Show($"请输入托盘名称!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  251. // return;
  252. // }
  253. // if (string.IsNullOrWhiteSpace(cmbPalletType.Text))
  254. // {
  255. // KryptonMessageBox.Show($"请选择托盘类型!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  256. // return;
  257. // }
  258. // switch (_LastOperation)
  259. // {
  260. // case EnumOperation.Add:
  261. // var addResult = BaseServices.palletService.Add(new PalletCondition
  262. // {
  263. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  264. // IsUsed = chkUse.Checked,
  265. // Describe = richDescibe.Text,
  266. // PalletCode = txtPalletCode.Text,
  267. // PalletName = txtPalletName.Text,
  268. // PalletType = cmbPalletType.SelectedValue == null ? "" :
  269. // cmbPalletType.SelectedValue.ToString(),
  270. // }); ;
  271. // if (addResult.Status == OperateStatus.Success)
  272. // {
  273. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  274. // InitControl();
  275. // groupOperation.Visible = false;
  276. // btnSearch_Click(null, null);
  277. // dataGridView.ClearSelection();
  278. // }
  279. // else
  280. // {
  281. // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  282. // }
  283. // break;
  284. // case EnumOperation.Edit:
  285. // var editResult = BaseServices.palletService.Edit(new PalletCondition
  286. // {
  287. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  288. // IsUsed = chkUse.Checked,
  289. // Describe = richDescibe.Text,
  290. // PalletCode = txtPalletCode.Text,
  291. // PalletName = txtPalletName.Text,
  292. // PalletType = cmbPalletType.SelectedValue == null ? "" :
  293. // cmbPalletType.SelectedValue.ToString(),
  294. // Id = _selectId
  295. // });
  296. // if (editResult.Status == OperateStatus.Success)
  297. // {
  298. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  299. // InitControl();
  300. // groupOperation.Visible = false;
  301. // btnSearch_Click(null, null);
  302. // dataGridView.ClearSelection();
  303. // }
  304. // else
  305. // {
  306. // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  307. // }
  308. // break;
  309. // }
  310. //}
  311. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  312. {
  313. SelectInit();
  314. if (_selectIndex >= 0)
  315. {
  316. var frm = new ChildFrm.FrmPalletEdit();
  317. frm.operation = EnumOperation.Edit;
  318. frm.PalletTypeList = this._palletTypeList;
  319. frm.Id = this._selectId;
  320. frm.InitControl();
  321. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  322. if (frm.ShowDialog() == DialogResult.OK)
  323. {
  324. this.btnSearch_Click(null, null);
  325. }
  326. //_LastOperation = EnumOperation.Edit;
  327. //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  328. //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  329. // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  330. //txtPalletCode.Enabled = false;
  331. //groupOperation.Visible = true;
  332. //groupOperation.Focus();
  333. }
  334. }
  335. private Point mouse_offset;
  336. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  337. {
  338. mouse_offset = new Point(-e.X, -e.Y);
  339. }
  340. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  341. {
  342. ((Control)sender).Cursor = Cursors.Arrow;
  343. if (e.Button == MouseButtons.Left)
  344. {
  345. Point mousePos = MousePosition;
  346. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  347. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  348. Application.DoEvents();
  349. }
  350. }
  351. private void btnExit_Click(object sender, EventArgs e)
  352. {
  353. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  354. {
  355. //groupOperation.Visible = false;
  356. }
  357. else
  358. {
  359. //groupOperation.Visible = true;
  360. //groupOperation.Focus();
  361. }
  362. }
  363. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  364. {
  365. this.btnSearch_Click(null, null);
  366. }
  367. private void kryptonButton1_Click(object sender, EventArgs e)
  368. {
  369. kryptonButton1.Enabled = false;
  370. try
  371. {
  372. int ids = 0;
  373. DataTable dt = new DataTable();
  374. DataColumn dc = new DataColumn("Ids");
  375. dt.Columns.Add(dc);
  376. dc = new DataColumn("PalletCode");
  377. dt.Columns.Add(dc);
  378. foreach (DataGridViewRow item in dataGridView.Rows)
  379. {
  380. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)item.Cells[0];
  381. object obj = checkCell.EditedFormattedValue;
  382. if (Convert.ToBoolean(obj))
  383. {
  384. ids++;
  385. DataRow dr = dt.NewRow();
  386. dr["Ids"] = ids;
  387. dr["PalletCode"] = item.Cells["PALLET_CODE"].Value;
  388. dt.Rows.Add(dr);
  389. }
  390. }
  391. if (ids > 0)
  392. {
  393. DataSet dts = new DataSet();
  394. dts.Tables.Add(dt);
  395. FastReport.Report report = new FastReport.Report();
  396. string filename = _reportFolder + "托盘条码.frx";
  397. report.Load(filename);
  398. report.RegisterData(dts);
  399. report.Prepare();
  400. report.PrintSettings.ShowDialog = false;
  401. report.Print();
  402. report.Clear();
  403. KryptonMessageBox.Show("打印成功!");
  404. }
  405. else
  406. {
  407. KryptonMessageBox.Show("请勾选要打印的托盘数据行!");
  408. }
  409. }
  410. catch (Exception ex)
  411. {
  412. KryptonMessageBox.Show($"打印托盘条码发生异常:{ex.Message}");
  413. }
  414. kryptonButton1.Enabled = true;
  415. }
  416. private void kryptonButton2_Click(object sender, EventArgs e)
  417. {
  418. FrmBatchPrint frm = new FrmBatchPrint();
  419. frm.ShowDialog();
  420. }
  421. }
  422. }