锐腾搅拌上料功能
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.

578 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.Data.Linq;
  6. using System.Linq;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.BandedGrid;
  12. using DevExpress.XtraGrid.Columns;
  13. using DevExpress.XtraGrid;
  14. using System.IO;
  15. using System.Threading;
  16. using ICSSoft.Base.Language.Tool;
  17. using ICSSoft.Base.Config.AppConfig;
  18. using ICSSoft.Base.UserControl.MessageControl;
  19. using ICSSoft.Base.Config.DBHelper;
  20. using ICSSoft.Base.Report.Filter;
  21. using ICSSoft.Base.UserControl.FormControl;
  22. using ICSSoft.Base.Report.GridReport;
  23. using ICSSoft.Base.ReferForm.AppReferForm;
  24. using ICSSoft.Frame.Data.BLL;
  25. using DevExpress.XtraPrinting;
  26. using ICSSoft.Frame.Data.Entity;
  27. using ICSSoft.Base.Lable.PrintTool;
  28. using System.Data.SqlClient;
  29. namespace ICSSoft.Frame.APP
  30. {
  31. public partial class FormICSTuiKu_Out : DevExpress.XtraEditors.XtraForm
  32. {
  33. private string sqltxt = "";
  34. private string sqlconn = "";
  35. public string MinTime = "";
  36. public int status = 1;
  37. String guid = AppConfig.GetGuid();
  38. private DataTable dataSource = null;
  39. #region 构造函数
  40. public FormICSTuiKu_Out()
  41. {
  42. InitializeComponent();
  43. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  44. this.WindowState = FormWindowState.Maximized;
  45. }
  46. #endregion
  47. #region 操作权限
  48. public DataTable RightOfExute()
  49. {
  50. DataTable rData = new DataTable();
  51. rData.Columns.Add("BtnName");
  52. rData.Columns.Add("ActionName");
  53. //查看权限(必须有)
  54. DataRow seeRow = rData.NewRow();
  55. seeRow["BtnName"] = "see";
  56. seeRow["ActionName"] = "查看";
  57. rData.Rows.Add(seeRow);
  58. List<Control> ControlList = new List<Control>();
  59. ControlList.Add(btnModify);
  60. ControlList.Add(save);
  61. ControlList.Add(btnRefresh);
  62. ControlList.Add(btnPrint);
  63. foreach (Control ctr in ControlList)
  64. {
  65. if (ctr.GetType() == typeof(SimpleButton))
  66. {
  67. DataRow dr = rData.NewRow();
  68. dr["BtnName"] = ctr.Name;
  69. dr["ActionName"] = ctr.Text;
  70. rData.Rows.Add(dr);
  71. }
  72. }
  73. rData.AcceptChanges();
  74. return rData;
  75. }
  76. public DataTable RightOfData()// 数据权限
  77. {
  78. DataTable rData = new DataTable();
  79. rData.Columns.Add("BodyName");
  80. rData.Columns.Add("ControlName");
  81. rData.Columns.Add("ControlCaption");
  82. rData.AcceptChanges();
  83. return rData;
  84. }
  85. #endregion
  86. #region 退出
  87. private void btnClose_Click(object sender, EventArgs e)
  88. {
  89. AppConfig.CloseFormShow(this.Text);
  90. this.Close();
  91. }
  92. private void btnExit_Click(object sender, EventArgs e)
  93. {
  94. AppConfig.CloseFormShow(this.Text);
  95. this.Close();
  96. }
  97. #endregion
  98. #region 移动窗体
  99. private const int WM_NCHITTEST = 0x84;
  100. private const int HTCLIENT = 0x1;
  101. private const int HTCAPTION = 0x2;
  102. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  103. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  104. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  105. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  106. //重写窗体,使窗体可以不通过自带标题栏实现移动
  107. protected override void WndProc(ref Message m)
  108. {
  109. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  110. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  111. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  112. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  113. switch (m.Msg)
  114. {
  115. case WM_NCHITTEST:
  116. base.WndProc(ref m);
  117. if ((int)m.Result == HTCLIENT)
  118. m.Result = (IntPtr)HTCAPTION;
  119. return;
  120. }
  121. //拦截双击标题栏、移动窗体的系统消息
  122. if (m.Msg != 0xA3)
  123. {
  124. base.WndProc(ref m);
  125. }
  126. }
  127. #endregion
  128. #region 列表
  129. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  130. {
  131. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  132. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  133. }
  134. #endregion
  135. #region 过滤
  136. private string tempTableName = "";
  137. private void btnFilter_Click(object sender, EventArgs e)
  138. {
  139. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  140. filter.OldTempTableName = tempTableName;
  141. if (filter.ShowDialog() == DialogResult.OK)
  142. {
  143. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  144. try
  145. {
  146. _wait.Show();
  147. tempTableName = filter.NewTempTableName;
  148. sqltxt = filter.SqlText;
  149. sqlconn = filter.FilterConnectString;
  150. dataSource = filter.FilterData.Tables[0];
  151. grdDetail.DataSource = dataSource;
  152. grvDetail.BestFitColumns();
  153. rptPage.RecordNum = dataSource.Rows.Count;
  154. rptPage.PageSize = 499;
  155. rptPage.PageIndex = 1;
  156. rptPage.ReLoad();
  157. rptPage.PageSize = 500;
  158. rptPage.PageIndex = 1;
  159. rptPage.ReLoad();
  160. _wait.Close();
  161. }
  162. catch (Exception ex)
  163. {
  164. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  165. _wait.Close();
  166. }
  167. }
  168. }
  169. #endregion
  170. #region 绑定数据源
  171. private void btnConfig_Click(object sender, EventArgs e)
  172. {
  173. if (AppConfig.UserCode.ToLower() != "demo")
  174. {
  175. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  176. return;
  177. }
  178. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  179. fdata.ShowDialog();
  180. }
  181. #endregion
  182. #region 分页
  183. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  184. {
  185. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  186. grdDetail.DataSource = data;
  187. }
  188. #endregion
  189. #region 过滤方法
  190. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  191. {
  192. AppConfig.DropTemTable(tempTableName);
  193. }
  194. #endregion
  195. #region 全选
  196. private void btnSelectAll_Click(object sender, EventArgs e)
  197. {
  198. grvDetail.PostEditor();
  199. this.Validate();
  200. for (int i = 0; i < grvDetail.RowCount; i++)
  201. {
  202. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  203. }
  204. }
  205. #endregion
  206. #region 全消
  207. private void btnCancelAll_Click(object sender, EventArgs e)
  208. {
  209. grvDetail.PostEditor();
  210. this.Validate();
  211. for (int i = 0; i < grvDetail.RowCount; i++)
  212. {
  213. grvDetail.SetRowCellValue(i, colisSelect, "");
  214. }
  215. }
  216. #endregion
  217. #region 双击
  218. private void grvDetail_DoubleClick(object sender, EventArgs e)
  219. {
  220. if (grvDetail.FocusedRowHandle < 0)
  221. {
  222. return;
  223. }
  224. if (grvDetail.FocusedColumn == colisSelect)
  225. {
  226. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  227. {
  228. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  229. }
  230. else
  231. {
  232. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  233. }
  234. }
  235. }
  236. #endregion
  237. #region 刷新
  238. private void btnRefresh_Click(object sender, EventArgs e)
  239. {
  240. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  241. try
  242. {
  243. _wait.Show();
  244. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  245. filter.OldTempTableName = tempTableName;
  246. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  247. grdDetail.DataSource = dataSource;
  248. grvDetail.BestFitColumns();
  249. rptPage.RecordNum = dataSource.Rows.Count;
  250. rptPage.PageIndex = 1;
  251. rptPage.ReLoad();
  252. _wait.Close();
  253. }
  254. catch (Exception ex)
  255. {
  256. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  257. _wait.Close();
  258. }
  259. }
  260. #endregion
  261. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  262. {
  263. AppConfig.DropTemTable(tempTableName);
  264. }
  265. private void FormICSChuKu_Out_Load(object sender, EventArgs e)
  266. {
  267. btnFilter_Click(sender, e);
  268. }
  269. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  270. {
  271. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  272. {
  273. e.CellValue = "cccc";
  274. }
  275. }
  276. private void btnModify_Click(object sender, EventArgs e)
  277. {
  278. SimpleButton btntemp = (SimpleButton)sender;
  279. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  280. {
  281. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  282. return;
  283. }
  284. int count = 0;
  285. for (int i = 0; i < grvDetail.RowCount; i++)
  286. {
  287. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  288. {
  289. count++;
  290. }
  291. }
  292. if (count != 1)
  293. {
  294. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  295. return;
  296. }
  297. try
  298. {
  299. for (int i = 0; i < grvDetail.RowCount; i++)
  300. {
  301. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  302. {
  303. //FormICSTuiKuAdd add = new FormICSTuiKuAdd(grvDetail.GetRowCellValue(i, colTransferNO).ToString(), grvDetail.GetRowCellValue(i, colTransLine).ToString(), grvDetail.GetRowCellValue(i, colINVCode).ToString(), grvDetail.GetRowCellValue(i, colINVName).ToString(), grvDetail.GetRowCellValue(i, colQTY).ToString(), grvDetail.GetRowCellValue(i, colMUSER).ToString());
  304. //add.ShowDialog();
  305. }
  306. }
  307. btnRefresh_Click(null, null);
  308. }
  309. catch (Exception ex)
  310. {
  311. //throw ex;
  312. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  313. }
  314. }
  315. private void save_Click(object sender, EventArgs e)
  316. {
  317. int Count = 0;
  318. SimpleButton btntemp = (SimpleButton)sender;
  319. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  320. {
  321. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  322. return;
  323. }
  324. for (int i = 0; i < grvDetail.RowCount; i++)
  325. {
  326. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  327. {
  328. Count++;
  329. }
  330. }
  331. if (Count == 0)
  332. {
  333. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  334. return;
  335. }
  336. try
  337. {
  338. for (int i = 0; i < grvDetail.RowCount; i++)
  339. {
  340. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  341. {
  342. //FormICSTuiKuAdd add = new FormICSTuiKuAdd(grvDetail.GetRowCellValue(i, colTransferNO).ToString(), grvDetail.GetRowCellValue(i, colTransLine).ToString(), grvDetail.GetRowCellValue(i, colINVCode).ToString(), grvDetail.GetRowCellValue(i, colINVName).ToString(), status);
  343. }
  344. }
  345. ICSBaseSimpleCode.AppshowMessageBox(0, "审核成功");
  346. btnRefresh_Click(null, null);
  347. }
  348. catch (Exception ex)
  349. {
  350. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  351. return;
  352. }
  353. }
  354. private void btnDel_Click(object sender, EventArgs e)
  355. {
  356. string status = "";
  357. int Count = 0;
  358. SimpleButton btntemp = (SimpleButton)sender;
  359. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  360. {
  361. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  362. return;
  363. }
  364. for (int i = 0; i < grvDetail.RowCount; i++)
  365. {
  366. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  367. {
  368. Count++;
  369. }
  370. }
  371. if (Count == 0)
  372. {
  373. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  374. return;
  375. }
  376. try
  377. {
  378. for (int i = 0; i < grvDetail.RowCount; i++)
  379. {
  380. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  381. {
  382. if (grvDetail.GetRowCellValue(i, colStatusX).ToString() == "已退库")
  383. {
  384. status = "err";
  385. break;
  386. }
  387. }
  388. }
  389. if (status == "err")
  390. {
  391. ICSBaseSimpleCode.AppshowMessageBox("已经退库的退料单无法反审核!");
  392. return;
  393. }
  394. else
  395. {
  396. for (int i = 0; i < grvDetail.RowCount; i++)
  397. {
  398. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  399. {
  400. //FormICSTuiKuAdd add = new FormICSTuiKuAdd(grvDetail.GetRowCellValue(i, colTransferNO).ToString(), grvDetail.GetRowCellValue(i, colTransLine).ToString(), grvDetail.GetRowCellValue(i, colINVCode).ToString(), grvDetail.GetRowCellValue(i, colINVName).ToString(), 2);
  401. }
  402. }
  403. ICSBaseSimpleCode.AppshowMessageBox(0, "反审核成功");
  404. btnRefresh_Click(null, null);
  405. }
  406. }
  407. catch (Exception ex)
  408. {
  409. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  410. return;
  411. }
  412. }
  413. private void btnPrint_Click(object sender, EventArgs e)
  414. {
  415. string LotNO = "";
  416. int Count = 0, Sum = 0;
  417. SimpleButton btntemp = (SimpleButton)sender;
  418. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  419. {
  420. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  421. return;
  422. }
  423. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  424. List<PrintPara> parasList = new List<PrintPara>();
  425. for (int i = 0; i < grvDetail.RowCount; i++)
  426. {
  427. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  428. {
  429. if (grvDetail.GetRowCellValue(i, colLotNO).ToString() == "")
  430. {
  431. Count++;
  432. }
  433. else
  434. {
  435. Sum++;
  436. }
  437. }
  438. }
  439. if (Sum > 0)
  440. {
  441. if (Count == 0)
  442. {
  443. for (int i = 0; i < grvDetail.RowCount; i++)
  444. {
  445. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  446. {
  447. if (!(grvDetail.GetRowCellValue(i, colLotNO).ToString() == ""))
  448. {
  449. ICSITEMLot Info = new ICSITEMLot();
  450. Info.LotNO = grvDetail.GetRowCellValue(i, colLotNO).ToString();
  451. InfoList.Add(Info);
  452. PrintPara para = new PrintPara();
  453. para.PrintKey = "LotNO";
  454. para.PrintValues = new object[] { grvDetail.GetRowCellValue(i, colLotNO).ToString() };
  455. parasList.Add(para);
  456. ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
  457. }
  458. }
  459. }
  460. FormPrintDialog f = new FormPrintDialog("007", this.Text, parasList, false, null);
  461. f.ShowDialog();
  462. btnRefresh_Click(null, null);
  463. return;
  464. }
  465. else
  466. {
  467. ICSBaseSimpleCode.AppshowMessageBox("不能同时选择已经生成条码和未生成条码的退料单");
  468. return;
  469. }
  470. }
  471. if (Count == 0)
  472. {
  473. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  474. return;
  475. }
  476. for (int i = 0; i < grvDetail.RowCount; i++)
  477. {
  478. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  479. {
  480. SqlConnection conn = new System.Data.SqlClient.SqlConnection(AppConfig.AppConnectString);
  481. conn.Open();
  482. SqlTransaction sqlTran = conn.BeginTransaction();
  483. SqlCommand cmd = new SqlCommand();
  484. cmd.Transaction = sqlTran;
  485. cmd.Connection = conn;
  486. try
  487. {
  488. DateTime time = DateTime.Now;
  489. string timeStr = "T" + time.ToString("yyMMdd");
  490. int m = 0;
  491. string sql = @"SELECT MAX(A.LotNO) AS LOTNO FROM ICSITEMLot A WHERE A.LotNO LIKE '{0}%' AND LEN(a.LotNO) = 10";
  492. sql = string.Format(sql, timeStr);
  493. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  494. if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["LotNO"].ToString()))
  495. {
  496. LotNO = dt.Rows[0]["LOTNO"].ToString();
  497. m = int.Parse(LotNO.Substring(7, 3));
  498. }
  499. ICSITEMLot Info = new ICSITEMLot();
  500. Info.ID = "";
  501. Info.LOTQTY = Decimal.Parse(grvDetail.GetRowCellValue(i, colQTY).ToString());
  502. string add = "";
  503. if (m + i + 1 < 9)
  504. {
  505. add = "00" + (m + i + 1).ToString();
  506. }
  507. else if (m + i + 1 < 99)
  508. {
  509. add = "0" + (m + i + 1).ToString();
  510. }
  511. else
  512. {
  513. add = (m + i + 1).ToString();
  514. }
  515. Info.LotNO = timeStr + add;
  516. Info.ItemCode = grvDetail.GetRowCellValue(i, colINVCode).ToString();
  517. Info.TransNO = grvDetail.GetRowCellValue(i, colTransferNO).ToString();
  518. Info.TransLine = grvDetail.GetRowCellValue(i, colTransLine).ToString();
  519. Info.VenderLotNO = Info.LotNO + (m + 1).ToString().PadLeft(4, '0');
  520. Info.PRODUCTDATE = time;
  521. Info.ACTIVE = "Y";
  522. Info.Exdate = Convert.ToDateTime("2999-12-31");
  523. Info.TYPE = "退料";
  524. string sqlText = @"UPDATE ICSTransferNOBack SET LotNO = '{0}' WHERE TransferNO = '" + Info.TransNO + "' AND TransLine = '" + Info.TransLine + "'";
  525. sqlText = string.Format(sqlText, Info.LotNO);
  526. cmd.CommandText = sqlText;
  527. cmd.ExecuteNonQuery();
  528. cmd.Transaction.Commit();
  529. #region
  530. Info.lastPrintUSERID = AppConfig.UserId;
  531. Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  532. Info.WorkPoint = AppConfig.WorkPointCode;
  533. InfoList.Add(Info);
  534. PrintPara para = new PrintPara();
  535. para.PrintKey = "LotNO";
  536. para.PrintValues = new object[] { Info.LotNO };
  537. parasList.Add(para);
  538. #endregion
  539. }
  540. catch
  541. {
  542. cmd.Transaction.Rollback();
  543. }
  544. }
  545. }
  546. ICSRdrecord2LOTBLL.Add(InfoList, AppConfig.AppConnectString);
  547. FormPrintDialog x = new FormPrintDialog("007", this.Text, parasList, false, null);
  548. x.ShowDialog();
  549. ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
  550. btnRefresh_Click(null, null);
  551. }
  552. }
  553. }