华恒Mes鼎捷代码
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.

1342 lines
61 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 ICSSoft.Frame.Data.Entity;
  26. using ICSSoft.Base.Log;
  27. using ICSSoft.Frame.Common;
  28. namespace ICSSoft.Frame.APP
  29. {
  30. public partial class FormICSDataCollectForWW : DevExpress.XtraEditors.XtraForm
  31. {
  32. private string sqltxt = "";
  33. private string sqlconn = "";
  34. String guid = AppConfig.GetGuid();
  35. private DataTable dataSource = null;
  36. private DataTable grvdt = new DataTable();
  37. List<ICSPO_PoMain> polist = new List<ICSPO_PoMain>();
  38. List<ICSWareHouseLotInfoLog> loglist = new List<ICSWareHouseLotInfoLog>();
  39. #region 构造函数
  40. public FormICSDataCollectForWW()
  41. {
  42. InitializeComponent();
  43. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  44. this.WindowState = FormWindowState.Maximized;
  45. grvDetail.Columns[0].Visible = false;
  46. }
  47. #endregion
  48. #region 操作权限
  49. public DataTable RightOfExute()
  50. {
  51. DataTable rData = new DataTable();
  52. rData.Columns.Add("BtnName");
  53. rData.Columns.Add("ActionName");
  54. //查看权限(必须有)
  55. DataRow seeRow = rData.NewRow();
  56. seeRow["BtnName"] = "see";
  57. seeRow["ActionName"] = "查看";
  58. rData.Rows.Add(seeRow);
  59. List<Control> ControlList = new List<Control>();
  60. ControlList.Add(btnWWSubmit);
  61. foreach (Control ctr in ControlList)
  62. {
  63. if (ctr.GetType() == typeof(SimpleButton))
  64. {
  65. DataRow dr = rData.NewRow();
  66. dr["BtnName"] = ctr.Name;
  67. dr["ActionName"] = ctr.Text;
  68. rData.Rows.Add(dr);
  69. }
  70. }
  71. rData.AcceptChanges();
  72. return rData;
  73. }
  74. public DataTable RightOfData()// 数据权限
  75. {
  76. DataTable rData = new DataTable();
  77. rData.Columns.Add("BodyName");
  78. rData.Columns.Add("ControlName");
  79. rData.Columns.Add("ControlCaption");
  80. rData.AcceptChanges();
  81. return rData;
  82. }
  83. #endregion
  84. #region 退出
  85. private void btnClose_Click(object sender, EventArgs e)
  86. {
  87. AppConfig.CloseFormShow(this.Text);
  88. this.Close();
  89. }
  90. private void btnExit_Click(object sender, EventArgs e)
  91. {
  92. AppConfig.CloseFormShow(this.Text);
  93. this.Close();
  94. }
  95. #endregion
  96. #region 移动窗体
  97. private const int WM_NCHITTEST = 0x84;
  98. private const int HTCLIENT = 0x1;
  99. private const int HTCAPTION = 0x2;
  100. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  101. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  102. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  103. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  104. //重写窗体,使窗体可以不通过自带标题栏实现移动
  105. protected override void WndProc(ref Message m)
  106. {
  107. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  108. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  109. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  110. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  111. switch (m.Msg)
  112. {
  113. case WM_NCHITTEST:
  114. base.WndProc(ref m);
  115. if ((int)m.Result == HTCLIENT)
  116. m.Result = (IntPtr)HTCAPTION;
  117. return;
  118. }
  119. //拦截双击标题栏、移动窗体的系统消息
  120. if (m.Msg != 0xA3)
  121. {
  122. base.WndProc(ref m);
  123. }
  124. }
  125. #endregion
  126. #region 列表
  127. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  128. {
  129. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  130. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  131. }
  132. #endregion
  133. #region 分页
  134. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  135. {
  136. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  137. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  138. grdDetail.DataSource = data;
  139. }
  140. #endregion
  141. #region 全选
  142. private void btnSelectAll_Click(object sender, EventArgs e)
  143. {
  144. grvDetail.PostEditor();
  145. this.Validate();
  146. for (int i = 0; i < grvDetail.RowCount; i++)
  147. {
  148. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  149. }
  150. }
  151. #endregion
  152. #region 全消
  153. private void btnCancelAll_Click(object sender, EventArgs e)
  154. {
  155. grvDetail.PostEditor();
  156. this.Validate();
  157. for (int i = 0; i < grvDetail.RowCount; i++)
  158. {
  159. grvDetail.SetRowCellValue(i, colisSelect, "");
  160. }
  161. }
  162. #endregion
  163. #region 双击
  164. private void grvDetail_DoubleClick(object sender, EventArgs e)
  165. {
  166. if (grvDetail.FocusedRowHandle < 0)
  167. {
  168. return;
  169. }
  170. if (grvDetail.FocusedColumn == colisSelect)
  171. {
  172. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  173. {
  174. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  175. }
  176. else
  177. {
  178. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  179. }
  180. }
  181. }
  182. #endregion
  183. #region 新增
  184. private void btnCreate_Click(object sender, EventArgs e)
  185. {
  186. //SimpleButton btntemp = (SimpleButton)sender;
  187. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  188. //{
  189. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  190. // return;
  191. //}
  192. //FormICSONWIPCheckAdd add = new FormICSONWIPCheckAdd();
  193. //add.ShowDialog();
  194. //btnRefresh_Click(null, null);
  195. }
  196. #endregion
  197. private void FormICSCREW_Load(object sender, EventArgs e)
  198. {
  199. }
  200. private void btnSearch_Click(object sender, EventArgs e)
  201. {
  202. //if (SendType.Checked == true)
  203. //{
  204. // if (txtPOCode.Text != "")
  205. // {
  206. // GetSendGrvDT("MOCODE");
  207. // }
  208. // if (txtLotNo.Text != "")
  209. // {
  210. // GetSendGrvDT("LOTNO");
  211. // }
  212. //}
  213. //else
  214. //{
  215. // if (txtPOCode.Text != "")
  216. // {
  217. // GetReceiveDT("MOCODE");
  218. // }
  219. // if (txtLotNo.Text != "")
  220. // {
  221. // GetReceiveDT("LOTNO");
  222. // }
  223. //}
  224. }
  225. private void GetSendGrvDT(string CodeType)
  226. {
  227. string sql = @" select '' as isSelected
  228. ,A.LOTNO AS LOTNO
  229. ,B.MCODE AS INVCODE
  230. ,C.INVNAME AS INVNAME
  231. ,C.INVSTD AS INVSTD
  232. ,ISNULL(B.LOTQTY,0) AS LOTQTY
  233. ,C.INVUOM AS INVUOM
  234. ,Convert(decimal(18,2),ISNULL(B.LOTQTY,0))*Convert(decimal(18,2),ISNULL(B.EATTRIBUTE3,0)) AS AssQTY
  235. ,C.INVEXPORTIMPORT AS INVAssUOM
  236. ,D.ROUTECODE AS ROUTECODE
  237. ,D.OPSEQ AS OPSEQ
  238. ,D.OPCODE AS OPCODE
  239. ,E.OPDESC AS OPDESC
  240. ,G.TypeCODE AS TypeCode
  241. ,G.TypeDESC AS TypeDESC
  242. ,A.EQPCode AS EQPCode
  243. ,A.PRLineID AS LOTPRID
  244. ,'' AS LotPOCode
  245. ,'' AS LotPORow
  246. ,B.VenderLotNO
  247. from ICSMO2User A
  248. LEFT JOIN ICSITEMLot B
  249. ON B.LotNO=A.LOTNO
  250. LEFT JOIN ICSINVENTORY C
  251. ON C.INVCODE=B.MCODE
  252. LEFT JOIN ICSITEMROUTE2OPLot D
  253. ON D.LotNo=A.LOTNO AND D.OPCODE=A.OPCODE
  254. LEFT JOIN ICSOP E
  255. ON E.OPCODE=D.OPCODE
  256. LEFT JOIN ICSEquipment F
  257. ON F.EQPCode=A.EQPCode
  258. LEFT JOIN ICSEquipmentType G
  259. ON G.TypeCODE=F.Type
  260. where A.LOTNO = '{0}'
  261. AND A.EATTRIBUTE1='1'
  262. AND A.WorkPoint='{1}'
  263. AND A.LOTNO+A.OPCODE NOT IN
  264. (SELECT LotNO+OPCODE FROM ICSLOTONWIP WHERE LOTNO='{0}')
  265. ORDER BY A.LOTNO,D.OPSEQ";
  266. sql = string.Format(sql, txtLotNo.Text, AppConfig.WorkPointCode);
  267. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  268. //新增判断是否已发料
  269. if (dt.Rows.Count <= 0) {
  270. ICSBaseSimpleCode.AppshowMessageBox("未获取到该流转单未发料的委外工序!");
  271. return;
  272. }
  273. int chkCount = 0;
  274. bool canSend = false;
  275. for (int i = 0; i < dt.Rows.Count; i++)
  276. {
  277. for (int j = 0; j < gridViewCG.RowCount; j++)
  278. {
  279. if (dt.Rows[i]["LOTPRID"].ToString() == gridViewCG.GetRowCellValue(j, PRID).ToString())
  280. {
  281. chkCount++;
  282. }
  283. }
  284. }
  285. if (chkCount <= gridViewCG.RowCount)
  286. {
  287. canSend = true;
  288. }
  289. for (int i = dt.Rows.Count - 1; i >= 0; i--)
  290. {
  291. sql = @"select * from ICSITEMROUTE2OPLot
  292. where LotNo='{0}' AND OPSEQ<'{1}'";
  293. sql = string.Format(sql, dt.Rows[i]["LOTNO"].ToString(), dt.Rows[i]["OPSEQ"].ToString());
  294. DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  295. if (chkdt.Rows.Count != 0)
  296. {
  297. sql = @"SELECT * FROM ICSLOTONWIPCheck A
  298. INNER JOIN ICSLOTONWIP B
  299. ON B.ID=A.ONWIPID
  300. INNER JOIN ICSLOTSIMULATION C
  301. ON C.LOTNO=B.LOTNO AND C.SEQ=B.SEQ
  302. WHERE C.LOTNO='{0}' AND C.OPCODE=
  303. (SELECT TOP 1 OPCODE FROM ICSITEMROUTE2OPLot
  304. WHERE LOTNO='{0}' AND OPSEQ<'{1}'
  305. ORDER BY OPSEQ DESC) ";
  306. sql = string.Format(sql, dt.Rows[i]["LOTNO"].ToString(), dt.Rows[i]["OPSEQ"].ToString());
  307. chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  308. if (chkdt.Rows.Count == 0)
  309. {
  310. dt.Rows.Remove(dt.Rows[i]);
  311. }
  312. else
  313. {
  314. if ((chkdt.Rows[0]["Result"].ToString() == "不合格" && chkdt.Rows[0]["TResult"].ToString() == "报废")
  315. || (chkdt.Rows[0]["Result"].ToString() == "不合格" && chkdt.Rows[0]["TResult"] == null))
  316. {
  317. dt.Rows.Remove(dt.Rows[i]);
  318. }
  319. }
  320. }
  321. }
  322. if (dt.Rows.Count == 0)
  323. {
  324. ICSBaseSimpleCode.AppshowMessageBox("上一道工序未检验或检验不合格,无法委外发料,请确认!");
  325. return;
  326. }
  327. for (int i = dt.Rows.Count - 1; i >= 0; i--)
  328. {
  329. bool isexsist = false;
  330. for (int j = 0; j < gridViewCG.RowCount; j++)
  331. {
  332. if (dt.Rows[i]["LOTPRID"].ToString() == gridViewCG.GetRowCellValue(j, PRID).ToString())
  333. {
  334. isexsist = true;
  335. }
  336. }
  337. if (isexsist == false)
  338. {
  339. dt.Rows.Remove(dt.Rows[i]);
  340. }
  341. }
  342. if (dt.Rows.Count == 0)
  343. {
  344. ICSBaseSimpleCode.AppshowMessageBox("生成的请购单PR号和ERP内不一致或该PR单行对应采购订单行未生成,无法委外发料,请确认!");
  345. return;
  346. }
  347. if (canSend == false)
  348. {
  349. ICSBaseSimpleCode.AppshowMessageBox("MES连续委外道数(" + chkCount + ")和ERP内的采购订单(" + gridViewCG.RowCount + ")不一致,请确认!");
  350. return;
  351. }
  352. if (grvdt == null || grvdt.Rows.Count == 0)
  353. {
  354. decimal POTotalQTY = 0;
  355. decimal LotTotalQTY = 0;
  356. for (int i = 0; i < gridViewCG.RowCount; i++)
  357. {
  358. string POInvCode = gridViewCG.GetRowCellValue(i, ITEMCODE).ToString();
  359. decimal POPlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY));
  360. decimal POSendQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY));
  361. decimal POCurrentQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY));
  362. string PRLineID = gridViewCG.GetRowCellValue(i, PRID).ToString();
  363. for (int j = 0; j < dt.Rows.Count; j++)
  364. {
  365. if (POInvCode == dt.Rows[j]["INVCODE"].ToString() + "_" + dt.Rows[j]["OPCODE"].ToString() && PRLineID == dt.Rows[j]["LOTPRID"].ToString())
  366. {
  367. POTotalQTY = POTotalQTY + (POPlanQTY - POSendQTY - POCurrentQTY);
  368. }
  369. }
  370. }
  371. for (int i = 0; i < dt.Rows.Count; i++)
  372. {
  373. LotTotalQTY = LotTotalQTY + Convert.ToDecimal(dt.Rows[i]["LOTQTY"]);
  374. }
  375. if (POTotalQTY < LotTotalQTY)
  376. {
  377. ICSBaseSimpleCode.AppshowMessageBox("发料数量不能超过采购订单行数量!!");
  378. return;
  379. }
  380. grvdt = dt.Copy();
  381. }
  382. else
  383. {
  384. if (dt.Rows.Count != 0)
  385. {
  386. grvdt = GetGrvDTADD(grvdt, dt);
  387. }
  388. }
  389. if (grvdt.Rows.Count != 0)
  390. {
  391. if (grvdt.Rows.Count > 1)
  392. {
  393. for (int i = 0; i < grvdt.Rows.Count; i++)
  394. {
  395. if (grvdt.Rows[i]["LOTNO"].ToString() == txtLotNo.Text.Trim())
  396. {
  397. DataRow dr = grvdt.Select("LOTNO='" + txtLotNo.Text.Trim() + "'")[0];
  398. DataRow newdr = grvdt.NewRow();
  399. newdr.ItemArray = dr.ItemArray;
  400. grvdt.Rows.Remove(dr);
  401. grvdt.Rows.InsertAt(newdr, 0);
  402. }
  403. }
  404. }
  405. grdDetail.DataSource = grvdt;
  406. }
  407. }
  408. private void GetReceiveDT(string CodeType)
  409. {
  410. DataTable tempdt = new DataTable();
  411. string FLLotNo = "";
  412. string FLOPCode = "";
  413. string FLItemCode = "";
  414. tempdt.TableName = "IcsItemLotANDOP";
  415. tempdt.Columns.Add("LotNo", typeof(string));
  416. tempdt.Columns.Add("OPCode", typeof(string));
  417. tempdt.Columns.Add("ItemCode", typeof(string));
  418. string sql = @" select A.LOTNO AS LOTNO
  419. ,D.OPSEQ AS OPSEQ
  420. ,D.OPCODE AS OPCODE
  421. from ICSMO2User A
  422. LEFT JOIN ICSITEMROUTE2OPLot D
  423. ON D.LotNo=A.LOTNO AND D.OPCODE=A.OPCODE";
  424. if (CodeType == "LOTNO")
  425. {
  426. sql += @" WHERE A.LOTNO = '{0}'";
  427. }
  428. else
  429. {
  430. sql += @" WHERE A.MOCODE = '{0}'";
  431. }
  432. sql += @"AND A.EATTRIBUTE1='1'
  433. AND A.WorkPoint='{1}'
  434. AND A.LOTNO+A.OPCODE IN
  435. (SELECT LotNO+OPCODE FROM ICSLOTSIMULATION
  436. WHERE CollectStatus='COLLECT_BEGIN')
  437. ORDER BY A.LOTNO,D.OPSEQ";
  438. if (CodeType == "LOTNO")
  439. {
  440. sql = string.Format(sql, txtLotNo.Text, AppConfig.WorkPointCode);
  441. }
  442. else
  443. {
  444. sql = string.Format(sql, txtPOCode.Text, AppConfig.WorkPointCode);
  445. }
  446. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  447. for (int i = 0; i < dt.Rows.Count; i++)
  448. {
  449. sql = @"SELECT
  450. a.LotNo AS LOTNO
  451. ,a.ITEMCODE
  452. ,a.OPSEQ AS OPSEQ
  453. ,a.OPCODE AS OPCODE
  454. ,c.EATTRIBUTE1 AS ISWW
  455. ,b.OPSEQ AS NOPSEQ
  456. ,b.OPCODE AS NOPCODE
  457. ,d.EATTRIBUTE1 AS NISWW
  458. FROM ICSITEMROUTE2OPLot a
  459. LEFT JOIN ICSITEMROUTE2OPLot b ON a.LotNo=b.LotNo AND b.OPSEQ=(SELECT MIN(OPSEQ) FROM ICSITEMROUTE2OPLot WHERE LotNo=a.LotNo AND OPSEQ>a.OPSEQ)
  460. LEFT JOIN ICSMO2User c ON a.LotNo=c.LOTNO AND a.OPCODE=c.OPCODE
  461. LEFT JOIN ICSMO2User d ON b.LotNo=d.LOTNO AND b.OPCODE=d.OPCODE
  462. WHERE c.LotNo = '{0}'
  463. AND a.OPSEQ>='{1}'
  464. ORDER BY a.LotNo,a.OPSEQ";
  465. sql = string.Format(sql, dt.Rows[i]["LOTNO"].ToString(), dt.Rows[i]["OPSEQ"].ToString());
  466. DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  467. FLLotNo = chkdt.Rows[0]["LotNo"].ToString();
  468. FLOPCode = chkdt.Rows[0]["OPCODE"].ToString();
  469. FLItemCode = chkdt.Rows[0]["ITEMCODE"].ToString();
  470. for (int j = 0; j < chkdt.Rows.Count; j++)
  471. {
  472. if (chkdt.Rows[j]["ISWW"].ToString() == "1")
  473. {
  474. DataRow dr = tempdt.NewRow();
  475. dr["LotNo"] = chkdt.Rows[j]["LOTNO"].ToString();
  476. dr["OPCode"] = chkdt.Rows[j]["OPCODE"].ToString();
  477. dr["ItemCode"] = chkdt.Rows[j]["ITEMCODE"].ToString();
  478. tempdt.Rows.Add(dr);
  479. }
  480. if (chkdt.Rows[j]["NISWW"].ToString() != "1")
  481. {
  482. break;
  483. }
  484. }
  485. }
  486. string FLSql = @"select POCode,PORow,InvCode
  487. from ICSPO_PoMain A
  488. LEFT JOIN ICSWareHouseLotInfoLog B
  489. ON B.TransNO=A.POCode and a.PORow=b.TransLine
  490. where LotNO='{0}' AND BusinessCode=''
  491. AND TransType='发' and a.POCode=(select pocode from ICSWareHouseLotInfoLog where Lotno='{0}' and memo='{1}')
  492. --AND Memo='{1}'
  493. AND B.WorkPoint='{2}'";
  494. FLSql = string.Format(FLSql, FLLotNo, FLOPCode, AppConfig.WorkPointCode);
  495. DataTable fldt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FLSql).Tables[0];
  496. for (int i = tempdt.Rows.Count - 1; i >= 0; i--)
  497. {
  498. bool needReceive = false;
  499. for (int j = 0; j < fldt.Rows.Count; j++)
  500. {
  501. if (fldt.Rows[j]["InvCode"].ToString() ==
  502. tempdt.Rows[i]["ITEMCODE"].ToString() + "_" + tempdt.Rows[i]["OPCODE"].ToString())
  503. {
  504. needReceive = true;
  505. }
  506. }
  507. if (needReceive == false)
  508. {
  509. tempdt.Rows.Remove(tempdt.Rows[i]);
  510. }
  511. }
  512. //留下最后一道委外工序进行批量收料
  513. for (int i = tempdt.Rows.Count - 1; i >= 0; i--)
  514. {
  515. if (i != tempdt.Rows.Count - 1)
  516. {
  517. tempdt.Rows.Remove(tempdt.Rows[i]);
  518. }
  519. }
  520. for (int i = 0; i < tempdt.Rows.Count; i++)
  521. {
  522. string receivesql = @"select '' as isSelected
  523. ,A.LOTNO AS LOTNO
  524. ,B.MCODE AS INVCODE
  525. ,C.INVNAME AS INVNAME
  526. ,C.INVSTD AS INVSTD
  527. ,ISNULL(B.LOTQTY,0) AS LOTQTY
  528. ,C.INVUOM AS INVUOM
  529. ,Convert(decimal(18,2),ISNULL(B.LOTQTY,0))*Convert(decimal(18,2),ISNULL(B.EATTRIBUTE3,0)) AS AssQTY
  530. ,C.INVEXPORTIMPORT AS INVAssUOM
  531. ,D.ROUTECODE AS ROUTECODE
  532. ,D.OPSEQ AS OPSEQ
  533. ,D.OPCODE AS OPCODE
  534. ,E.OPDESC AS OPDESC
  535. ,G.TypeCODE AS TypeCode
  536. ,G.TypeDESC AS TypeDESC
  537. ,A.EQPCode AS EQPCode
  538. ,B.VenderLotNO
  539. from ICSMO2User A
  540. LEFT JOIN ICSITEMLot B
  541. ON B.LotNO=A.LOTNO
  542. LEFT JOIN ICSINVENTORY C
  543. ON C.INVCODE=B.MCODE
  544. LEFT JOIN ICSITEMROUTE2OPLot D
  545. ON D.LotNo=A.LOTNO AND D.OPCODE=A.OPCODE
  546. LEFT JOIN ICSOP E
  547. ON E.OPCODE=D.OPCODE
  548. LEFT JOIN ICSEquipment F
  549. ON F.EQPCode=A.EQPCode
  550. LEFT JOIN ICSEquipmentType G
  551. ON G.TypeCODE=F.Type
  552. where A.LOTNO='{0}'
  553. AND A.OPCODE='{1}'";
  554. receivesql = string.Format(receivesql, tempdt.Rows[i]["LotNo"].ToString()
  555. , tempdt.Rows[i]["OPCode"].ToString());
  556. DataTable receivedt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, receivesql).Tables[0];
  557. if (grvdt == null || grvdt.Rows.Count == 0)
  558. {
  559. grvdt = receivedt.Copy();
  560. }
  561. else
  562. {
  563. grvdt = GetGrvDTADD(grvdt, receivedt);
  564. }
  565. }
  566. if (grvdt.Rows.Count != 0)
  567. {
  568. if (grvdt.Rows.Count > 1)
  569. {
  570. for (int i = 0; i < grvdt.Rows.Count; i++)
  571. {
  572. if (grvdt.Rows[i]["LOTNO"].ToString() == txtLotNo.Text.Trim())
  573. {
  574. DataRow dr = grvdt.Select("LOTNO='" + txtLotNo.Text.Trim() + "'")[0];
  575. DataRow newdr = grvdt.NewRow();
  576. newdr.ItemArray = dr.ItemArray;
  577. grvdt.Rows.Remove(dr);
  578. grvdt.Rows.InsertAt(newdr, 0);
  579. }
  580. }
  581. }
  582. grdDetail.DataSource = grvdt;
  583. }
  584. else
  585. {
  586. ICSBaseSimpleCode.AppshowMessageBox("工单或条码下不存在符合收料条件的工序!!");
  587. return;
  588. }
  589. }
  590. private DataTable GetGrvDTADD(DataTable GRVDT, DataTable DT)
  591. {
  592. if (SendType.Checked == true)
  593. {
  594. decimal POTotalQTY = 0;
  595. decimal LotTotalQTY = 0;
  596. for (int i = 0; i < gridViewCG.RowCount; i++)
  597. {
  598. string POInvCode = gridViewCG.GetRowCellValue(i, ITEMCODE).ToString();
  599. decimal POPlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY));
  600. decimal POSendQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY));
  601. decimal POCurrentQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY));
  602. string PRLineID = gridViewCG.GetRowCellValue(i, PRID).ToString();
  603. for (int j = 0; j < DT.Rows.Count; j++)
  604. {
  605. if (POInvCode == DT.Rows[j]["INVCODE"].ToString() + "_" + DT.Rows[j]["OPCODE"].ToString() && PRLineID == DT.Rows[j]["LOTPRID"].ToString())
  606. {
  607. POTotalQTY = POTotalQTY + (POPlanQTY - POSendQTY - POCurrentQTY);
  608. }
  609. }
  610. }
  611. for (int i = 0; i < DT.Rows.Count; i++)
  612. {
  613. LotTotalQTY = LotTotalQTY + Convert.ToDecimal(DT.Rows[i]["LOTQTY"]);
  614. }
  615. if (POTotalQTY < LotTotalQTY)
  616. {
  617. ICSBaseSimpleCode.AppshowMessageBox("发料数量不能超过采购订单行数量!!");
  618. return GRVDT;
  619. }
  620. }
  621. for (int i = 0; i < DT.Rows.Count; i++)
  622. {
  623. bool isexsist = false;
  624. for (int j = 0; j < GRVDT.Rows.Count; j++)
  625. {
  626. if (DT.Rows[i]["LOTNO"].ToString() == GRVDT.Rows[j]["LOTNO"].ToString())
  627. {
  628. isexsist = true;
  629. }
  630. }
  631. if (isexsist == false)
  632. {
  633. if (SendType.Checked == true)
  634. {
  635. DataRow dr = GRVDT.NewRow();
  636. dr["isSelected"] = DT.Rows[i]["isSelected"].ToString();
  637. dr["VenderLotNO"] = DT.Rows[i]["VenderLotNO"].ToString();
  638. dr["LOTNO"] = DT.Rows[i]["LOTNO"].ToString();
  639. dr["INVCODE"] = DT.Rows[i]["INVCODE"].ToString();
  640. dr["INVNAME"] = DT.Rows[i]["INVNAME"].ToString();
  641. dr["INVSTD"] = DT.Rows[i]["INVSTD"].ToString();
  642. dr["LOTQTY"] = Convert.ToDecimal(DT.Rows[i]["LOTQTY"]);
  643. dr["INVUOM"] = DT.Rows[i]["INVUOM"].ToString();
  644. dr["AssQTY"] = Convert.ToDecimal(DT.Rows[i]["AssQTY"]);
  645. dr["INVAssUOM"] = DT.Rows[i]["INVAssUOM"].ToString();
  646. dr["ROUTECODE"] = DT.Rows[i]["ROUTECODE"].ToString();
  647. dr["OPSEQ"] = Convert.ToDecimal(DT.Rows[i]["OPSEQ"]);
  648. dr["OPCODE"] = DT.Rows[i]["OPCODE"].ToString();
  649. dr["OPDESC"] = DT.Rows[i]["OPDESC"].ToString();
  650. dr["EQPCode"] = DT.Rows[i]["EQPCode"].ToString();
  651. dr["TypeCode"] = DT.Rows[i]["TypeCode"].ToString();
  652. dr["TypeDESC"] = DT.Rows[i]["TypeDESC"].ToString();
  653. dr["LOTPRID"] = DT.Rows[i]["LOTPRID"].ToString();
  654. dr["LotPOCode"] = DT.Rows[i]["LotPOCode"].ToString();
  655. dr["LotPORow"] = DT.Rows[i]["LotPORow"].ToString();
  656. GRVDT.Rows.Add(dr);
  657. }
  658. else
  659. {
  660. DataRow dr = GRVDT.NewRow();
  661. dr["isSelected"] = DT.Rows[i]["isSelected"].ToString();
  662. dr["VenderLotNO"] = DT.Rows[i]["VenderLotNO"].ToString();
  663. dr["LOTNO"] = DT.Rows[i]["LOTNO"].ToString();
  664. dr["INVCODE"] = DT.Rows[i]["INVCODE"].ToString();
  665. dr["INVNAME"] = DT.Rows[i]["INVNAME"].ToString();
  666. dr["INVSTD"] = DT.Rows[i]["INVSTD"].ToString();
  667. dr["LOTQTY"] = Convert.ToDecimal(DT.Rows[i]["LOTQTY"]);
  668. dr["INVUOM"] = DT.Rows[i]["INVUOM"].ToString();
  669. dr["AssQTY"] = Convert.ToDecimal(DT.Rows[i]["AssQTY"]);
  670. dr["INVAssUOM"] = DT.Rows[i]["INVAssUOM"].ToString();
  671. dr["ROUTECODE"] = DT.Rows[i]["ROUTECODE"].ToString();
  672. dr["OPSEQ"] = Convert.ToDecimal(DT.Rows[i]["OPSEQ"]);
  673. dr["OPCODE"] = DT.Rows[i]["OPCODE"].ToString();
  674. dr["OPDESC"] = DT.Rows[i]["OPDESC"].ToString();
  675. dr["EQPCode"] = DT.Rows[i]["EQPCode"].ToString();
  676. dr["TypeCode"] = DT.Rows[i]["TypeCode"].ToString();
  677. dr["TypeDESC"] = DT.Rows[i]["TypeDESC"].ToString();
  678. GRVDT.Rows.Add(dr);
  679. }
  680. }
  681. }
  682. return GRVDT;
  683. }
  684. #region 全选
  685. private void btnSelectAll_Click_1(object sender, EventArgs e)
  686. {
  687. for (int i = 0; i < grvDetail.RowCount; i++)
  688. {
  689. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  690. }
  691. }
  692. #endregion
  693. #region 全消
  694. private void btnCancelAll_Click_1(object sender, EventArgs e)
  695. {
  696. for (int i = 0; i < grvDetail.RowCount; i++)
  697. {
  698. grvDetail.SetRowCellValue(i, colisSelect, "");
  699. }
  700. }
  701. #endregion
  702. private void btnClear_Click(object sender, EventArgs e)
  703. {
  704. txtPOCode.Text = "";
  705. txtLotNo.Text = "";
  706. grvdt.Clear();
  707. grdDetail.DataSource = null;
  708. gridControlCG.DataSource = null;
  709. loglist.Clear();
  710. polist.Clear();
  711. }
  712. private void SendType_CheckedChanged(object sender, EventArgs e)
  713. {
  714. if (SendType.Checked == true)
  715. {
  716. btnWWSubmit.Text = "委外发料";
  717. txtPOCode.Enabled = true;
  718. grvDetail.Columns[0].Visible = false;
  719. txtPOCode.Text = "";
  720. txtLotNo.Text = "";
  721. grvdt.Clear();
  722. grdDetail.DataSource = null;
  723. gridControlCG.DataSource = null;
  724. loglist.Clear();
  725. polist.Clear();
  726. }
  727. }
  728. private void ReceiveType_CheckedChanged(object sender, EventArgs e)
  729. {
  730. if (ReceiveType.Checked == true)
  731. {
  732. btnWWSubmit.Text = "委外收料";
  733. txtPOCode.Enabled = false;
  734. grvDetail.Columns[0].Visible = true;
  735. gridControlCG.DataSource = null;
  736. txtPOCode.Text = "";
  737. txtLotNo.Text = "";
  738. grvdt.Clear();
  739. grdDetail.DataSource = null;
  740. gridControlCG.DataSource = null;
  741. loglist.Clear();
  742. polist.Clear();
  743. }
  744. }
  745. private void btnWWSubmit_Click(object sender, EventArgs e)
  746. {
  747. List<ICSLOTSIMULATION> infolist = new List<ICSLOTSIMULATION>();
  748. if (SendType.Checked == true)
  749. {
  750. if (txtPOCode.Text == "" && txtLotNo.Text == "")
  751. {
  752. return;
  753. }
  754. for (int i = 0; i < gridViewCG.RowCount; i++)
  755. {
  756. decimal PlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY));
  757. decimal OutQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY));
  758. decimal NowQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY));
  759. if (PlanQTY < OutQTY + NowQTY)
  760. {
  761. ICSBaseSimpleCode.AppshowMessageBox("发料数量不能超出采购订单行数量!!");
  762. return;
  763. }
  764. }
  765. for (int i = 0; i < grvDetail.RowCount; i++)
  766. {
  767. ICSLOTSIMULATION simulation = new ICSLOTSIMULATION();
  768. simulation.MUSER = AppConfig.UserCode;
  769. simulation.LOTNO = grvDetail.GetRowCellValue(i, LOTNO).ToString();
  770. simulation.OPCODE = grvDetail.GetRowCellValue(i, OPCODE).ToString();
  771. simulation.EQPCODE = grvDetail.GetRowCellValue(i, EQPCode).ToString();
  772. simulation.EATTRIBUTE1 = "COLLECT_BEGIN";
  773. simulation.CHECKLOTNO = "WW";
  774. infolist.Add(simulation);
  775. }
  776. if (infolist.Count <= 0) {
  777. ICSBaseSimpleCode.AppshowMessageBox("请先输入产品跟踪单号!");
  778. return;
  779. }
  780. string errormessage = ICSCollectBLL.SaveList(AppConfig.AppConnectString, infolist, polist, loglist);
  781. if (errormessage != "")
  782. {
  783. MessageBox.Show(errormessage);
  784. }
  785. else
  786. {
  787. ICSBaseSimpleCode.AppshowMessageBox("发料成功!!");
  788. btnClear_Click(null, null);
  789. }
  790. }
  791. else
  792. {
  793. if (txtLotNo.Text == "")
  794. {
  795. return;
  796. }
  797. int count = 0;
  798. for (int i = 0; i < grvDetail.RowCount; i++)
  799. {
  800. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  801. {
  802. count++;
  803. }
  804. }
  805. if (count == 0)
  806. {
  807. ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行操作!!");
  808. return;
  809. }
  810. for (int i = 0; i < grvDetail.RowCount; i++)
  811. {
  812. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  813. {
  814. bool opisallend = false;
  815. string EndLotNo = grvDetail.GetRowCellValue(i, LOTNO).ToString();
  816. #region 判断当前收料工序是否是最后一道工序
  817. string chksql = @"select Top 1 OPCODE from ICSITEMROUTE2OPLot
  818. where LotNo='{0}' AND WorkPoint='{1}'
  819. order by OPSEQ DESC";
  820. chksql = string.Format(chksql, EndLotNo, AppConfig.WorkPointCode);
  821. DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0];
  822. if (chkdt.Rows.Count != 0)
  823. {
  824. if (chkdt.Rows[0]["OPCODE"].ToString() == grvDetail.GetRowCellValue(i, OPCODE).ToString())
  825. {
  826. opisallend = true;
  827. }
  828. }
  829. #endregion
  830. ICSLOTSIMULATION simulation = new ICSLOTSIMULATION();
  831. simulation.MUSER = AppConfig.UserCode;
  832. simulation.LOTNO = grvDetail.GetRowCellValue(i, LOTNO).ToString();
  833. simulation.OPCODE = grvDetail.GetRowCellValue(i, OPCODE).ToString();
  834. simulation.EQPCODE = grvDetail.GetRowCellValue(i, EQPCode).ToString();
  835. simulation.ITEMCODE = grvDetail.GetRowCellValue(i, INVCODE).ToString();
  836. simulation.EATTRIBUTE1 = "COLLECT_END";
  837. if (opisallend == true)
  838. {
  839. simulation.ISCOM = "1";
  840. simulation.EndTime = DateTime.Now;
  841. }
  842. else
  843. {
  844. simulation.ISCOM = "";
  845. simulation.EndTime = null;
  846. }
  847. infolist.Add(simulation);
  848. }
  849. }
  850. ICSCollectBLL.SaveListEnd(AppConfig.AppConnectString, infolist);
  851. ICSCollectBLL.CheckListEnd(AppConfig.AppConnectString, infolist);//验证该条码所有发料未收料的工序,进行收料处理,下道工序收料了,上面没有收料的都收料
  852. StringBuilder errores =new StringBuilder("");
  853. foreach (var Lot in infolist)
  854. {
  855. if (ICSAGVBLL.IsCanToAGV(Lot.LOTNO, Lot.OPCODE, "AGV是否开启", AppConfig.AppConnectString, AppConfig.WorkPointCode))
  856. {
  857. try
  858. {
  859. ICSAGVTASKLOG Log = new ICSAGVTASKLOG();
  860. Log.ID = AppConfig.GetGuid();
  861. Log.Lotno = Lot.LOTNO;
  862. Log.Opcode = Lot.OPCODE;
  863. bool Islastop = ICSAGVBLL.IsLastOP(Log.Lotno, Log.Opcode, AppConfig.AppConnectString, AppConfig.WorkPointCode);
  864. bool NextOpIsWW = ICSAGVBLL.NextOPisWW(Log.Lotno, Log.Opcode, AppConfig.AppConnectString, AppConfig.WorkPointCode);
  865. bool NextOpIsWG = ICSAGVBLL.NextOPisWG(Log.Lotno, Log.Opcode, AppConfig.AppConnectString, AppConfig.WorkPointCode);
  866. string Area = ICSAGVBLL.GetAreaCode("00088", "8", AppConfig.AppConnectString, AppConfig.WorkPointCode);
  867. Log.TaskType = "委外收料";
  868. string BeginArea = Area.Split('@')[0].Split(':')[0];
  869. string EndArea = Area.Split('@')[1].Split(':')[0];
  870. AgvAreaToAreaModel Model = new AgvAreaToAreaModel();
  871. Model.trackingNumber =Lot.LOTNO;
  872. Model.area = EndArea;
  873. Log.Area = BeginArea;
  874. Log.EndArea = EndArea;
  875. Log.Mtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  876. Log.MuserName = AppConfig.UserName;
  877. ICSAGVBLL.AgvAreaToArea(Model, Log, AppConfig.AppConnectString, AppConfig.WorkPointCode);
  878. }
  879. catch (Exception ex)
  880. {
  881. errores.Append("AGV任务异常:" + ex.Message + "已跳过\r\n");
  882. continue;
  883. }
  884. }
  885. }
  886. ICSBaseSimpleCode.AppshowMessageBox("收料成功!!");
  887. btnClear_Click(null, null);
  888. }
  889. }
  890. private void txtPOCode_KeyDown(object sender, KeyEventArgs e)
  891. {
  892. if (e.KeyCode == Keys.Enter)
  893. {
  894. grvdt.Clear();
  895. grdDetail.DataSource = null;
  896. gridControlCG.DataSource = null;
  897. loglist.Clear();
  898. polist.Clear();
  899. string POCode = txtPOCode.Text.Trim().ToString();
  900. string sql = @"select ROW_NUMBER() OVER(ORDER BY A.ID) SEQ,
  901. POCode AS POCODE,
  902. PORow AS POROW,
  903. A.InvCode AS ITEMCODE,
  904. B.INVNAME AS ITEMNAME,
  905. ISNULL(Quantity,0) AS QTY,
  906. ISNULL(qty,0) AS SendQTY,
  907. 0 AS CurrentQTY,
  908. Free1 AS PRID
  909. from ICSPO_PoMain A
  910. left join ICSINVENTORY B
  911. ON B.INVCODE=A.InvCode
  912. left join (select sum(TransQTY) as qty,TransNO,TransLine from ICSWareHouseLotInfoLog where TransType='发' and BusinessCode='' group by TransNO,TransLine)c
  913. on c.TransNO=a.POCode and c.TransLine=a.PORow
  914. where A.POCode='{0}'
  915. AND A.WorkPoint='{1}'";
  916. sql = string.Format(sql, POCode, AppConfig.WorkPointCode);
  917. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  918. if (dt.Rows.Count == 0)
  919. {
  920. ICSBaseSimpleCode.AppshowMessageBox("输入的采购条码不存在!!");
  921. return;
  922. }
  923. else
  924. {
  925. gridControlCG.DataSource = dt;
  926. }
  927. }
  928. }
  929. private void txtLotNo_KeyDown(object sender, KeyEventArgs e)
  930. {
  931. if (e.KeyCode == Keys.Enter)
  932. {
  933. for (int i = 0; i < grvDetail.RowCount; i++)
  934. {
  935. if (txtLotNo.Text == grvDetail.GetRowCellValue(i, LOTNO).ToString())
  936. {
  937. ICSBaseSimpleCode.AppshowMessageBox("扫描的产品产品跟踪单号已存在!!");
  938. txtLotNo.SelectAll();
  939. return;
  940. }
  941. }
  942. if (SendType.Checked == true)
  943. {
  944. if (gridControlCG.DataSource == null)
  945. {
  946. ICSBaseSimpleCode.AppshowMessageBox("请先扫描采购订单号!!");
  947. return;
  948. }
  949. else
  950. {
  951. #region 20210125新增判断(判断条码上一道工序是否检验合格)
  952. string chksql = @"select TOP 1 ID from ICSLOTONWIP
  953. where LOTNO='{0}' and WorkPoint='{1}'
  954. order by MTIME DESC";
  955. chksql = string.Format(chksql, txtLotNo.Text.Trim(), AppConfig.WorkPointCode);
  956. DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0];
  957. if (chkdt.Rows.Count != 0)
  958. {
  959. string ONWIPID = chkdt.Rows[0]["ID"].ToString();
  960. chksql = @"select Result,ISNULL(TResult,'') AS TResult from ICSLOTONWIPCheck
  961. where ONWIPID='{0}' AND WorkPoint='{1}'";
  962. chksql = string.Format(chksql, ONWIPID, AppConfig.WorkPointCode);
  963. chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0];
  964. if (chkdt.Rows.Count != 0)
  965. {
  966. if (chkdt.Rows[0]["Result"].ToString() == "不合格"
  967. && (chkdt.Rows[0]["TResult"].ToString() == "" || chkdt.Rows[0]["TResult"].ToString() == "报废"))
  968. {
  969. ICSBaseSimpleCode.AppshowMessageBox("跟踪单:" + txtLotNo.Text.Trim() + ",上道工序不合格且不是让步或返工状态,不能开始该工序!\n\r");
  970. return;
  971. }
  972. }
  973. }
  974. #endregion
  975. #region 20200820新增防呆
  976. //20210709卡控拿掉
  977. // string sql = @"select ISNULL(EATTRIBUTE6,'') AS EATTRIBUTE6 from ICSITEMLot
  978. // where LotNO='{0}' AND WorkPoint='{1}'";
  979. // sql = string.Format(sql, txtLotNo.Text.Trim(), AppConfig.WorkPointCode);
  980. // DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  981. // if (dt.Rows.Count == 0)
  982. // {
  983. // ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号不存在!!");
  984. // return;
  985. // }
  986. //else
  987. //{
  988. // if (dt.Rows[0]["EATTRIBUTE6"].ToString() == "")
  989. // {
  990. // ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号未绑定零件号,请先绑定再发料!!");
  991. // return;
  992. // }
  993. //}
  994. #endregion
  995. //右侧跟踪单详情显示的方法
  996. GetSendGrvDT("LOTNO");
  997. //左侧采购订单本次数量计算的方法
  998. GetSendQTY(txtLotNo.Text.Trim().ToString());
  999. }
  1000. }
  1001. else
  1002. {
  1003. GetReceiveDT("LOTNO");
  1004. }
  1005. txtLotNo.SelectAll();
  1006. }
  1007. }
  1008. public void GetSendQTY(string PRLotNo)
  1009. {
  1010. string PRINVCODE = "";
  1011. string PROPCODE = "";
  1012. decimal PRLOTQTY = 0;
  1013. string PRLotOP = "";
  1014. string LotPRID = "";
  1015. decimal TotalSendQTY = 0;
  1016. for (int i = 0; i < grvDetail.RowCount; i++)
  1017. {
  1018. if (PRLotNo == grvDetail.GetRowCellValue(i, LOTNO).ToString())
  1019. {
  1020. PRINVCODE = grvDetail.GetRowCellValue(i, INVCODE).ToString();
  1021. PROPCODE = grvDetail.GetRowCellValue(i, OPCODE).ToString();
  1022. PRLOTQTY = Convert.ToDecimal(grvDetail.GetRowCellValue(i, LOTQTY).ToString());
  1023. PRLotOP = grvDetail.GetRowCellValue(i, OPCODE).ToString();
  1024. LotPRID = grvDetail.GetRowCellValue(i, LOTPRID).ToString();
  1025. }
  1026. }
  1027. for (int i = 0; i < gridViewCG.RowCount; i++)
  1028. {
  1029. string PRITEMCode = gridViewCG.GetRowCellValue(i, ITEMCODE).ToString();
  1030. decimal PRPlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY).ToString());
  1031. decimal PRSendQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY).ToString());
  1032. decimal PRCurrentQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY).ToString());
  1033. string PRCODE = gridViewCG.GetRowCellValue(i, POCODE).ToString();
  1034. string PRROW = gridViewCG.GetRowCellValue(i, POROW).ToString();
  1035. string POPRID = gridViewCG.GetRowCellValue(i, PRID).ToString();
  1036. if (PRITEMCode == PRINVCODE + "_" + PROPCODE && PRLOTQTY != 0 && PRPlanQTY - PRSendQTY - PRCurrentQTY != 0
  1037. && LotPRID == POPRID)
  1038. {
  1039. #region 获取连续委外的后续工序
  1040. DataTable dt = GetNextWWInfo(PRLotNo, PRLotOP);
  1041. #endregion
  1042. if (PRPlanQTY - PRSendQTY - PRCurrentQTY >= PRLOTQTY)
  1043. {
  1044. grvDetail.SetRowCellValue(i, LotPOCode, PRCODE);
  1045. grvDetail.SetRowCellValue(i, LotPORow, PRROW);
  1046. gridViewCG.SetRowCellValue(i, CurrentQTY, PRLOTQTY + PRCurrentQTY);
  1047. ICSPO_PoMain poinfo = new ICSPO_PoMain();
  1048. poinfo.POCode = PRCODE;
  1049. poinfo.PORow = PRROW;
  1050. poinfo.INQty = PRLOTQTY;
  1051. polist.Add(poinfo);
  1052. foreach (DataRow dr in dt.Rows)
  1053. {
  1054. if (dr["ISWW"].ToString() == "1")
  1055. {
  1056. bool lotisexsist = false;
  1057. for (int k = 0; k < gridViewCG.RowCount; k++)
  1058. {
  1059. if (gridViewCG.GetRowCellValue(k, ITEMCODE).ToString() ==
  1060. dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString())
  1061. {
  1062. lotisexsist = true;
  1063. }
  1064. }
  1065. if (lotisexsist == true)
  1066. {
  1067. ICSWareHouseLotInfoLog loginfo = new ICSWareHouseLotInfoLog();
  1068. loginfo.ID = AppConfig.GetGuid();
  1069. loginfo.TransNO = PRCODE;
  1070. loginfo.TransLine = dr["PORow"].ToString();
  1071. loginfo.ITEMCODE = dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString();
  1072. loginfo.LotNO = PRLotNo;
  1073. loginfo.TransQTY = PRLOTQTY;
  1074. loginfo.TransType = "发";
  1075. loginfo.BusinessCode = "委外发料";
  1076. loginfo.Memo = dr["OPCODE"].ToString();
  1077. loginfo.MUSER = AppConfig.UserCode;
  1078. loginfo.MUSERName = AppConfig.UserName;
  1079. loginfo.MTIME = DateTime.Now;
  1080. loginfo.WorkPoint = AppConfig.WorkPointCode;
  1081. if (loginfo.TransLine == "")
  1082. {
  1083. ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号未关联到对应采购订单行,请联系开发人员!!");
  1084. btnClear_Click(null, null);
  1085. return;
  1086. }
  1087. loglist.Add(loginfo);
  1088. }
  1089. }
  1090. if (dr["NISWW"].ToString() == "0")
  1091. {
  1092. break;
  1093. }
  1094. }
  1095. PRLOTQTY = 0;
  1096. }
  1097. else
  1098. {
  1099. grvDetail.SetRowCellValue(i, LotPOCode, PRCODE);
  1100. grvDetail.SetRowCellValue(i, LotPORow, PRROW);
  1101. gridViewCG.SetRowCellValue(i, CurrentQTY, PRPlanQTY - PRSendQTY - PRCurrentQTY);
  1102. ICSPO_PoMain poinfo = new ICSPO_PoMain();
  1103. poinfo.POCode = PRCODE;
  1104. poinfo.PORow = PRROW;
  1105. poinfo.INQty = PRPlanQTY - PRSendQTY - PRCurrentQTY;
  1106. polist.Add(poinfo);
  1107. foreach (DataRow dr in dt.Rows)
  1108. {
  1109. if (dr["ISWW"].ToString() == "1")
  1110. {
  1111. bool lotisexsist = false;
  1112. for (int k = 0; k < gridViewCG.RowCount; k++)
  1113. {
  1114. if (gridViewCG.GetRowCellValue(k, ITEMCODE).ToString() ==
  1115. dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString())
  1116. {
  1117. lotisexsist = true;
  1118. }
  1119. }
  1120. if (lotisexsist == true)
  1121. {
  1122. ICSWareHouseLotInfoLog loginfo = new ICSWareHouseLotInfoLog();
  1123. loginfo.ID = AppConfig.GetGuid();
  1124. loginfo.TransNO = PRCODE;
  1125. loginfo.TransLine = dr["PORow"].ToString();
  1126. loginfo.ITEMCODE = dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString(); ;
  1127. loginfo.LotNO = PRLotNo;
  1128. loginfo.TransQTY = PRPlanQTY - PRSendQTY - PRCurrentQTY;
  1129. loginfo.TransType = "发";
  1130. loginfo.BusinessCode = "委外发料";
  1131. loginfo.Memo = dr["OPCODE"].ToString();
  1132. loginfo.MUSER = AppConfig.UserCode;
  1133. loginfo.MUSERName = AppConfig.UserName;
  1134. loginfo.MTIME = DateTime.Now;
  1135. loginfo.WorkPoint = AppConfig.WorkPointCode;
  1136. if (loginfo.TransLine == "")
  1137. {
  1138. ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号未关联到对应采购订单行,请联系开发人员!!");
  1139. btnClear_Click(null, null);
  1140. return;
  1141. }
  1142. loglist.Add(loginfo);
  1143. }
  1144. }
  1145. if (dr["NISWW"].ToString() == "0")
  1146. {
  1147. break;
  1148. }
  1149. }
  1150. PRLOTQTY = PRLOTQTY - (PRPlanQTY - PRSendQTY - PRCurrentQTY);
  1151. }
  1152. }
  1153. }
  1154. }
  1155. private void btnDelete_Click(object sender, EventArgs e)
  1156. {
  1157. int count = 0;
  1158. for (int i = 0; i < grvDetail.RowCount; i++)
  1159. {
  1160. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1161. {
  1162. count++;
  1163. }
  1164. }
  1165. if (count == 0)
  1166. {
  1167. ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行删除!!");
  1168. return;
  1169. }
  1170. for (int i = grvDetail.RowCount - 1; i >= 0; i--)
  1171. {
  1172. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1173. {
  1174. string pocode = grvDetail.GetRowCellValue(i, LotPOCode).ToString();
  1175. string porow = grvDetail.GetRowCellValue(i, LotPORow).ToString();
  1176. decimal poqty = Convert.ToDecimal(grvDetail.GetRowCellValue(i, LOTQTY));
  1177. string lotno = grvDetail.GetRowCellValue(i, LOTNO).ToString();
  1178. #region 左侧采购订单列表中的本次数量扣减
  1179. for (int j = 0; j < gridViewCG.RowCount; j++)
  1180. {
  1181. if (gridViewCG.GetRowCellValue(j, POCODE).ToString() == pocode
  1182. && gridViewCG.GetRowCellValue(j, POROW).ToString() == porow && poqty > 0)
  1183. {
  1184. if (poqty >= Convert.ToDecimal(gridViewCG.GetRowCellValue(j, CurrentQTY)))
  1185. {
  1186. poqty = poqty - Convert.ToDecimal(gridViewCG.GetRowCellValue(j, CurrentQTY));
  1187. gridViewCG.SetRowCellValue(j, CurrentQTY, 0);
  1188. }
  1189. else
  1190. {
  1191. gridViewCG.SetRowCellValue(j, CurrentQTY, Convert.ToDecimal(gridViewCG.GetRowCellValue(j, CurrentQTY)) - poqty);
  1192. poqty = 0;
  1193. }
  1194. }
  1195. }
  1196. #endregion
  1197. #region PO_PoMain实体对象中的本次数量扣减
  1198. poqty = Convert.ToDecimal(grvDetail.GetRowCellValue(i, LOTQTY));
  1199. foreach (ICSPO_PoMain info in polist)
  1200. {
  1201. if (info.POCode == pocode && info.PORow == porow && poqty > 0)
  1202. {
  1203. if (poqty > info.INQty)
  1204. {
  1205. poqty = poqty - Convert.ToDecimal(info.INQty);
  1206. info.INQty = 0;
  1207. }
  1208. else
  1209. {
  1210. info.INQty = Convert.ToDecimal(info.INQty) - poqty;
  1211. poqty = 0;
  1212. }
  1213. }
  1214. }
  1215. #endregion
  1216. #region ICSWareHouseInfoLog实体对象中的对象删除
  1217. foreach (ICSWareHouseLotInfoLog info in loglist)
  1218. {
  1219. if (lotno == info.LotNO)
  1220. {
  1221. loglist.Remove(info);
  1222. }
  1223. }
  1224. #endregion
  1225. grvDetail.DeleteRow(i);
  1226. }
  1227. }
  1228. }
  1229. //获取连续委外后续工序的信息
  1230. private DataTable GetNextWWInfo(string LotNO, string OPCode)
  1231. {
  1232. string sql = @"SELECT e.POCode,e.PORow,
  1233. a.LotNo AS LOTNO
  1234. ,a.ITEMCODE
  1235. ,a.OPSEQ AS OPSEQ
  1236. ,a.OPCODE AS OPCODE
  1237. ,c.EATTRIBUTE1 AS ISWW
  1238. ,b.OPSEQ AS NOPSEQ
  1239. ,b.OPCODE AS NOPCODE
  1240. ,d.EATTRIBUTE1 AS NISWW
  1241. FROM ICSITEMROUTE2OPLot a
  1242. LEFT JOIN ICSITEMROUTE2OPLot b ON a.LotNo=b.LotNo AND b.OPSEQ=(SELECT MIN(OPSEQ) FROM ICSITEMROUTE2OPLot WHERE LotNo=a.LotNo AND OPSEQ>a.OPSEQ)
  1243. LEFT JOIN ICSMO2User c ON a.LotNo=c.LOTNO AND a.OPCODE=c.OPCODE
  1244. LEFT JOIN ICSMO2User d ON b.LotNo=d.LOTNO AND b.OPCODE=d.OPCODE
  1245. inner JOIN ICSPO_PoMain e ON e.InvCode=a.ITEMCODE+'_'+a.OPCODE AND e.POCode='{2}' AND e.Free1=c.PRLineID AND Quantity!=ISNULL(INQty,0)
  1246. WHERE c.LotNo = '{0}'
  1247. AND a.OPSEQ>=(select OPSEQ from ICSITEMROUTE2OPLot
  1248. where ROUTECODE=(
  1249. select TOP 1 RouteCode from ICSMO2User
  1250. where LOTNO='{0}')
  1251. AND OPCODE='{1}' AND LOTNO='{0}')
  1252. ORDER BY a.LotNo,a.OPSEQ";
  1253. sql = string.Format(sql, LotNO, OPCode, txtPOCode.Text.ToString());
  1254. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  1255. dt.AcceptChanges();
  1256. string NextOpseq = "";
  1257. //排除不是连续的工序
  1258. for (int i = 0; i < dt.Rows.Count; i++)
  1259. {
  1260. if (NextOpseq != dt.Rows[i]["OPSEQ"].ToString() && NextOpseq != "") {
  1261. dt.Rows[i].Delete();
  1262. //删除剩余所有不连续的工序
  1263. if (i < dt.Rows.Count - 1) {
  1264. for (int j = i + 1; j <= dt.Rows.Count - 1; j++) {
  1265. dt.Rows[j].Delete();
  1266. }
  1267. }
  1268. break;
  1269. }
  1270. sql = "select top 1 opseq from ICSITEMROUTE2OPLot where lotno='" + LotNO + "' and opseq>"+dt.Rows[i]["OPSEQ"].ToString()+" order by opseq";
  1271. DataTable optable = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  1272. if (optable.Rows.Count > 0) {
  1273. NextOpseq=optable.Rows[0]["opseq"].ToString();
  1274. }
  1275. }
  1276. dt.AcceptChanges();
  1277. return dt;
  1278. }
  1279. }
  1280. }