锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

602 lines
23 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using ICSSoft.Frame.Data.BLL;
  13. using System.Data.SqlClient;
  14. using ICSSoft.Base.Config.AppConfig;
  15. using ICSSoft.Frame.Data.Entity;
  16. using ICSSoft.Base.Report.Filter;
  17. using ICSSoft.Base.Config.DBHelper;
  18. using ICSSoft.Base.UserControl.FormControl;
  19. using ICSSoft.Base.ReferForm.AppReferForm;
  20. using ICSSoft.Frame.APP;
  21. using ICSSoft.Base.Lable.PrintTool;
  22. namespace ICSSoft.Frame.APP
  23. {
  24. public partial class FormICSStack : DevExpress.XtraEditors.XtraForm
  25. {
  26. private string sqltxt = "";
  27. private string sqlconn = "";
  28. String guid = AppConfig.GetGuid();
  29. private DataTable dataSource = null;
  30. #region 构造函数
  31. public FormICSStack() {
  32. InitializeComponent();
  33. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  34. this.WindowState = FormWindowState.Maximized;
  35. }
  36. #endregion
  37. #region 移动窗体
  38. private const int WM_NCHITTEST = 0x84;
  39. private const int HTCLIENT = 0x1;
  40. private const int HTCAPTION = 0x2;
  41. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  42. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  43. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  44. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  45. //重写窗体,使窗体可以不通过自带标题栏实现移动
  46. protected override void WndProc(ref Message m)
  47. {
  48. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  49. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  50. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  51. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  52. switch (m.Msg)
  53. {
  54. case WM_NCHITTEST:
  55. base.WndProc(ref m);
  56. if ((int)m.Result == HTCLIENT)
  57. m.Result = (IntPtr)HTCAPTION;
  58. return;
  59. }
  60. //拦截双击标题栏、移动窗体的系统消息
  61. if (m.Msg != 0xA3)
  62. {
  63. base.WndProc(ref m);
  64. }
  65. }
  66. #endregion
  67. #region 操作权限
  68. /// <summary>
  69. /// 操作权限
  70. /// </summary>
  71. /// <returns></returns>
  72. public DataTable RightOfExute()
  73. {
  74. DataTable rData = new DataTable();
  75. rData.Columns.Add("BtnName");
  76. rData.Columns.Add("ActionName");
  77. //查看权限(必须有)
  78. DataRow seeRow = rData.NewRow();
  79. seeRow["BtnName"] = "see";
  80. seeRow["ActionName"] = "查看";
  81. rData.Rows.Add(seeRow);
  82. List<Control> ControlList = new List<Control>();
  83. //ControlList.Add(btnSelect);
  84. //ControlList.Add(btnCanSelect);
  85. ControlList.Add(btnAdd);
  86. //ControlList.Add(btnEdit);
  87. ControlList.Add(btnDelLable);
  88. ControlList.Add(btnPrint);
  89. ControlList.Add(btnOutPut);
  90. ControlList.Add(btnImportData);
  91. foreach (Control ctr in ControlList)
  92. {
  93. if (ctr.GetType() == typeof(SimpleButton))
  94. {
  95. DataRow dr = rData.NewRow();
  96. dr["BtnName"] = ctr.Name;
  97. dr["ActionName"] = ctr.Text;
  98. rData.Rows.Add(dr);
  99. }
  100. }
  101. rData.AcceptChanges();
  102. return rData;
  103. }
  104. /// <summary>
  105. /// 数据权限
  106. /// </summary>
  107. /// <returns></returns>
  108. public DataTable RightOfData()
  109. {
  110. DataTable rData = new DataTable();
  111. rData.Columns.Add("BodyName");
  112. rData.Columns.Add("ControlName");
  113. rData.Columns.Add("ControlCaption");
  114. rData.AcceptChanges();
  115. return rData;
  116. }
  117. #endregion
  118. #region 退出
  119. private void btnClose_Click(object sender, EventArgs e)
  120. {
  121. AppConfig.CloseFormShow(this.Text);
  122. this.Close();
  123. }
  124. private void btnExit_Click(object sender, EventArgs e)
  125. {
  126. AppConfig.CloseFormShow(this.Text);
  127. this.Close();
  128. }
  129. #endregion
  130. #region 过滤
  131. private string tempTableName = "";
  132. private void btnFilter_Click(object sender, EventArgs e)
  133. {
  134. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  135. filter.OldTempTableName = tempTableName;
  136. if (filter.ShowDialog() == DialogResult.OK)
  137. {
  138. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  139. try
  140. {
  141. _wait.Show();
  142. tempTableName = filter.NewTempTableName;
  143. sqltxt = filter.SqlText;
  144. sqlconn = filter.FilterConnectString;
  145. dataSource = filter.FilterData.Tables[0];
  146. grdDetail.DataSource = dataSource;
  147. grvDetail.BestFitColumns();
  148. rptPage.RecordNum = dataSource.Rows.Count;
  149. rptPage.PageSize = 499;
  150. rptPage.PageIndex = 1;
  151. rptPage.ReLoad();
  152. rptPage.PageSize = 500;
  153. rptPage.PageIndex = 1;
  154. rptPage.ReLoad();
  155. _wait.Close();
  156. }
  157. catch (Exception ex)
  158. {
  159. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  160. _wait.Close();
  161. }
  162. }
  163. }
  164. #endregion
  165. #region 分页
  166. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  167. {
  168. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  169. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  170. grdDetail.DataSource = data;
  171. }
  172. #endregion
  173. #region 绑定数据源
  174. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  175. {
  176. if (AppConfig.UserCode.ToLower() != "demo")
  177. {
  178. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  179. return;
  180. }
  181. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  182. fdata.ShowDialog();
  183. }
  184. #endregion
  185. #region 全选
  186. private void btnSelect_Click(object sender, EventArgs e)
  187. {
  188. for (int i = 0; i < grvDetail.RowCount; i++)
  189. {
  190. grvDetail.SetRowCellValue(i, colSelect, "Y");
  191. }
  192. }
  193. #endregion
  194. #region 全消
  195. private void btnCanSelect_Click(object sender, EventArgs e)
  196. {
  197. for (int i = 0; i < grvDetail.RowCount; i++)
  198. {
  199. grvDetail.SetRowCellValue(i, colSelect, "");
  200. }
  201. }
  202. #endregion
  203. #region 刷新
  204. private void btnFalsh_Click(object sender, EventArgs e)
  205. {
  206. if (sqlconn == null || sqlconn == "")
  207. {
  208. return;
  209. }
  210. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  211. try
  212. {
  213. _wait.Show();
  214. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  215. filter.OldTempTableName = tempTableName;
  216. //tempTableName = filter.NewTempTableName;
  217. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  218. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  219. grdDetail.DataSource = dataSource;
  220. rptPage.RecordNum = dataSource.Rows.Count;
  221. rptPage.PageIndex = 1;
  222. rptPage.ReLoad();
  223. _wait.Close();
  224. }
  225. catch (Exception ex)
  226. {
  227. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  228. _wait.Close();
  229. }
  230. }
  231. #endregion
  232. #region 列表
  233. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  234. {
  235. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  236. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  237. }
  238. #endregion
  239. #region 双击选择
  240. private void grvDetail_DoubleClick(object sender, EventArgs e)
  241. {
  242. if (grvDetail.FocusedRowHandle < 0)
  243. {
  244. return;
  245. }
  246. if (grvDetail.FocusedColumn == colSelect)
  247. {
  248. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colSelect).ToString() == "")
  249. {
  250. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colSelect, "Y");
  251. }
  252. else
  253. {
  254. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colSelect, "");
  255. }
  256. }
  257. }
  258. #endregion
  259. #region 删除
  260. private void btnDelete_Click(object sender, EventArgs e)//删除
  261. {
  262. grvDetail.PostEditor();
  263. this.Validate();
  264. if (grvDetail.RowCount == 0)
  265. return;
  266. SimpleButton btntemp = (SimpleButton)sender;
  267. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  268. {
  269. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  270. return;
  271. }
  272. List<string> guidList = new List<string>();
  273. for (int i = 0; i < grvDetail.RowCount; i++)
  274. {
  275. if (grvDetail.GetRowCellValue(i, colSelect).ToString() == "Y")
  276. {
  277. guidList.Add(grvDetail.GetRowCellValue(i, CoGuid).ToString());
  278. }
  279. }
  280. if (guidList.Count == 0)
  281. {
  282. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  283. return;
  284. }
  285. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该单据吗?单据删除后无法恢复,确定吗?") != DialogResult.OK)
  286. return;
  287. try
  288. {
  289. ICSStackBLL.delete(guidList);
  290. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  291. btnFalsh_Click(null, null);
  292. }
  293. catch (Exception ex)
  294. {
  295. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  296. return;
  297. }
  298. }
  299. #endregion
  300. #region 导出
  301. private void btnOutput_Click(object sender, EventArgs e)
  302. {
  303. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  304. foe.ShowDialog();
  305. }
  306. #endregion
  307. #region 新增
  308. private void btnAdd_Click(object sender, EventArgs e)
  309. {
  310. SimpleButton btntemp = (SimpleButton)sender;
  311. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  312. {
  313. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  314. return;
  315. }
  316. FormICSStackAdd add = new FormICSStackAdd();
  317. add.ShowDialog();
  318. btnFalsh_Click(null, null);
  319. }
  320. #endregion
  321. #region 编辑
  322. private void btnEdit_Click(object sender, EventArgs e)
  323. {
  324. String id = "";
  325. SimpleButton btntemp = (SimpleButton)sender;
  326. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  327. {
  328. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  329. return;
  330. }
  331. List<string> editList = new List<string>();
  332. for (int i = 0; i < grvDetail.RowCount; i++)
  333. {
  334. if (grvDetail.GetRowCellValue(i, colSelect).ToString() == "Y")
  335. {
  336. id = grvDetail.GetRowCellValue(i, CoGuid).ToString();
  337. editList.Add(id);
  338. }
  339. }
  340. if (editList.Count != 1)
  341. {
  342. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  343. return;
  344. }
  345. try
  346. {
  347. ICSStackBLL.select(id,AppConfig.AppConnectString);
  348. FormICSStackAdd add = new FormICSStackAdd(id);
  349. add.ShowDialog();
  350. btnFalsh_Click(null, null);
  351. }catch(Exception ex){
  352. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  353. }
  354. }
  355. #endregion
  356. #region 过滤方法
  357. private void FormICSStack_FormClosing(object sender, FormClosingEventArgs e)
  358. {
  359. AppConfig.DropTemTable(tempTableName);
  360. }
  361. #endregion
  362. private void FormICSStack_Load(object sender, EventArgs e)
  363. {
  364. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  365. if (filter.ShowDialog() == DialogResult.OK)
  366. {
  367. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  368. try
  369. {
  370. _wait.Show();
  371. sqltxt = filter.SqlText;
  372. sqlconn = filter.FilterConnectString;
  373. dataSource = filter.FilterData.Tables[0];
  374. grdDetail.DataSource = dataSource;
  375. grvDetail.BestFitColumns();
  376. rptPage.RecordNum = dataSource.Rows.Count;
  377. rptPage.PageSize = 499;
  378. rptPage.PageIndex = 1;
  379. rptPage.ReLoad();
  380. rptPage.PageSize = 500;
  381. rptPage.PageIndex = 1;
  382. rptPage.ReLoad();
  383. _wait.Close();
  384. }
  385. catch (Exception ex)
  386. {
  387. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  388. _wait.Close();
  389. }
  390. }
  391. }
  392. private void btnPrint_Click(object sender, EventArgs e)
  393. {
  394. SimpleButton btntemp = (SimpleButton)sender;
  395. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  396. {
  397. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  398. return;
  399. }
  400. if (grvDetail.FocusedRowHandle < 0)
  401. {
  402. return;
  403. }
  404. try
  405. {
  406. List<PrintPara> parasList = new List<PrintPara>();
  407. for (int i = 0; i < grvDetail.RowCount; i++)
  408. {
  409. if (grvDetail.GetRowCellValue(i, colSelect).ToString() == "Y")
  410. {
  411. //string barCode = grvDetail.GetRowCellValue(i, StackCode).ToString();
  412. PrintPara printInfo = new PrintPara();
  413. printInfo.PrintKey = "StackCode";
  414. printInfo.PrintValues = new object[] { grvDetail.GetRowCellValue(i, StackCode).ToString() };
  415. parasList.Add(printInfo);
  416. }
  417. }
  418. if (parasList.Count == 0)
  419. {
  420. ICSBaseSimpleCode.AppshowMessageBox("没有选择数据");
  421. return;
  422. }
  423. FormPrintDialog f = new FormPrintDialog("005", this.Text, parasList, false, null);
  424. f.ShowDialog();
  425. }
  426. catch (Exception ex)
  427. {
  428. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  429. }
  430. }
  431. #region 导入模板下载
  432. private void btnImportMould_Click(object sender, EventArgs e)
  433. {
  434. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  435. _wait.Hide();
  436. string anjianExcelFileName = Environment.CommandLine.Substring(1, Environment.CommandLine.LastIndexOf("\\")) + "Output\\";
  437. try
  438. {
  439. _wait.Show();
  440. _wait.Caption = "模板下载中......";
  441. SaveFileDialog dlgSaveFileDialog = new SaveFileDialog(); //弹框提示保存
  442. dlgSaveFileDialog.InitialDirectory = anjianExcelFileName; //默认打开目录
  443. dlgSaveFileDialog.FilterIndex = 1;
  444. dlgSaveFileDialog.RestoreDirectory = true;
  445. dlgSaveFileDialog.FileName = "库位资料导入模板.xlsx"; //默认保存名称
  446. dlgSaveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
  447. if (dlgSaveFileDialog.ShowDialog() == DialogResult.OK)
  448. {
  449. string fileName = dlgSaveFileDialog.FileName; //获取弹出框选择或填写的文件名称
  450. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  451. colNameList.Add(new FormReadExcelUIModelColumns("库房编码", true));
  452. colNameList.Add(new FormReadExcelUIModelColumns("货架", true));
  453. colNameList.Add(new FormReadExcelUIModelColumns("层", true));
  454. colNameList.Add(new FormReadExcelUIModelColumns("格", true));
  455. FileUtil.exportToExcelFile(fileName, colNameList);
  456. _wait.Close();
  457. ICSBaseSimpleCode.AppshowMessageBox("模板下载成功!");
  458. }
  459. _wait.Close();
  460. }
  461. catch (Exception ex)
  462. {
  463. _wait.Close();
  464. ICSBaseSimpleCode.AppshowMessageBox("模板下载失败:" + ex.Message);
  465. }
  466. }
  467. #endregion
  468. private void btnImportData_Click(object sender, EventArgs e)
  469. {
  470. SimpleButton btntemp = (SimpleButton)sender;
  471. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  472. {
  473. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  474. return;
  475. }
  476. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  477. _wait.Hide();
  478. try
  479. {
  480. FormReadExcel fre = new FormReadExcel();
  481. if (fre.ShowDialog() != DialogResult.OK)
  482. {
  483. return;
  484. }
  485. DataTable dataSource = fre._excelData;
  486. if (dataSource == null)
  487. {
  488. throw new Exception("excel数据取得失败");
  489. }
  490. _wait.Show();
  491. _wait.Caption = "判断模版是否正确......";
  492. #region 判断模版是否正确
  493. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  494. colNameList.Add(new FormReadExcelUIModelColumns("库房编码", true));
  495. //colNameList.Add(new FormReadExcelUIModelColumns("区", true));
  496. //colNameList.Add(new FormReadExcelUIModelColumns("排", true));
  497. colNameList.Add(new FormReadExcelUIModelColumns("货架", true));
  498. colNameList.Add(new FormReadExcelUIModelColumns("层", true));
  499. colNameList.Add(new FormReadExcelUIModelColumns("格", true));
  500. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  501. {
  502. if (!dataSource.Columns.Contains(columnsName.columnsName))
  503. {
  504. throw new Exception("模版不正确,缺少列" + columnsName.columnsName);
  505. }
  506. }
  507. #endregion
  508. _wait.Caption = "数据整理中......";
  509. List<ICSStack> InfoList = new List<ICSStack>();
  510. foreach (DataRow dr in dataSource.Rows)
  511. {
  512. ///判断必输项目是否为空
  513. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  514. {
  515. if (string.IsNullOrWhiteSpace(dr[columnsName.columnsName].ToString()) == true && columnsName.NotNull == true)
  516. {
  517. throw new Exception("列" + columnsName.columnsName + "没有输入值");
  518. }
  519. }
  520. ICSStorage storage = ICSStorageBLL.selectByCode(dr["库房编码"].ToString(), AppConfig.AppConnectString);
  521. if (storage == null)
  522. throw new Exception("仓库编码:" + dr["库房编码"].ToString() + " 不存在!");
  523. ICSStack Info = new ICSStack();
  524. Info.Serial = "";
  525. Info.StackCode = dr["货架"].ToString().ToUpper() + '-' + dr["层"].ToString() + '-' + dr["格"].ToString();
  526. Info.StackName = dr["货架"].ToString().ToUpper() + "货架" + dr["层"].ToString() + '层' + dr["格"].ToString() + '格';
  527. Info.Storage_Serial = storage.Serial;
  528. Info.Storage_Name = storage.StorageName;
  529. Info.MUSER = AppConfig.UserCode;
  530. Info.MUSERName = AppConfig.UserName;
  531. Info.EATTRIBUTE1 = "";
  532. InfoList.Add(Info);
  533. }
  534. _wait.Caption = "导入数据......";
  535. ICSStackBLL.AddAndEditList(InfoList, AppConfig.AppConnectString);
  536. _wait.Close();
  537. ICSBaseSimpleCode.AppshowMessageBox("导入成功!");
  538. btnFalsh_Click(null, null);
  539. }
  540. catch (Exception ex)
  541. {
  542. _wait.Close();
  543. ICSBaseSimpleCode.AppshowMessageBox("数据导入失败:" + ex.Message);
  544. }
  545. }
  546. }
  547. }