华恒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.

512 lines
20 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 System.Data.SqlClient;
  13. using ICSSoft.Base.Config.AppConfig;
  14. using ICSSoft.Base.Report.Filter;
  15. using ICSSoft.Base.Config.DBHelper;
  16. using ICSSoft.Base.UserControl.FormControl;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Base.Lable.PrintTool;
  19. using ICSSoft.Frame.Data.BLL;
  20. using ICSSoft.Frame.Data.Entity;
  21. using System.Collections;
  22. namespace ICSSoft.Frame.APP
  23. {
  24. public partial class FormICSPOArriveLOTCreate : DevExpress.XtraEditors.XtraForm
  25. {
  26. private FormICSRdrecord2LOTUIModelX RecInfo;
  27. private string cCode;
  28. private string irowno;
  29. private string cInvCode;
  30. private string Batch;
  31. private bool isVenBatch = false;//判断是否要有供应商炉批号
  32. private bool isBatch = false;//判断是否要有批次号
  33. private bool isCheck = false;//判断是否需要检验
  34. public string[] Codes = { "4101", "4102", "4701", "4301", "4302", "4702", "4703", "111301", "4201", "4202", "43", "46" };
  35. #region 构造函数
  36. public FormICSPOArriveLOTCreate()
  37. {
  38. InitializeComponent();
  39. }
  40. public FormICSPOArriveLOTCreate(string _cCode, string _irowno, string _cInvCode, string _Batch)
  41. {
  42. InitializeComponent();
  43. chkBtnAll.Checked = false;
  44. chkBtnAll.Checked = true;
  45. cCode = _cCode;
  46. irowno = _irowno;
  47. cInvCode = _cInvCode;
  48. Batch = _Batch;
  49. if (Batch != "")
  50. {
  51. txtBatch.Text = Batch;
  52. }
  53. CheckData();
  54. GetRecInfo();
  55. if (RecInfo == null)
  56. {
  57. throw new Exception("到货单信息取得失败");
  58. }
  59. }
  60. #endregion
  61. #region 移动窗体
  62. private const int WM_NCHITTEST = 0x84;
  63. private const int HTCLIENT = 0x1;
  64. private const int HTCAPTION = 0x2;
  65. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  66. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  67. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  68. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  69. //重写窗体,使窗体可以不通过自带标题栏实现移动
  70. protected override void WndProc(ref Message m)
  71. {
  72. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  73. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  74. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  75. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  76. switch (m.Msg)
  77. {
  78. case WM_NCHITTEST:
  79. base.WndProc(ref m);
  80. if ((int)m.Result == HTCLIENT)
  81. m.Result = (IntPtr)HTCAPTION;
  82. return;
  83. }
  84. //拦截双击标题栏、移动窗体的系统消息
  85. if (m.Msg != 0xA3)
  86. {
  87. base.WndProc(ref m);
  88. }
  89. }
  90. #endregion
  91. #region 退出
  92. private void btnClose_Click(object sender, EventArgs e)
  93. {
  94. this.Close();
  95. }
  96. private void btnExit_Click(object sender, EventArgs e)
  97. {
  98. this.Close();
  99. }
  100. #endregion
  101. private void CheckData()
  102. {
  103. #region 判断是否要有批次号
  104. DataTable dt = ICSPOArriveBLL.GetBatch(cInvCode, AppConfig.WorkPointCode, AppConfig.AppConnectString);
  105. if (dt != null && dt.Rows.Count > 0)
  106. {
  107. if (dt.Rows[0]["INVCONTROLTYPE"].ToString().Trim().ToUpper() == "TRUE")
  108. {
  109. isBatch = true;
  110. }
  111. }
  112. else
  113. {
  114. throw new Exception("物料存货信息取得失败");
  115. }
  116. #endregion
  117. #region 判断是否要有供应商炉批号
  118. dt = ICSPOArriveBLL.GetVen(cInvCode, AppConfig.WorkPointCode, AppConfig.AppConnectString);
  119. if (dt != null && dt.Rows.Count > 0)
  120. {
  121. isVenBatch = true;
  122. }
  123. else
  124. {
  125. isVenBatch = false;
  126. }
  127. #endregion
  128. #region //判断是否需要检验
  129. dt = ICSPOArriveBLL.GetCheck(cInvCode, AppConfig.WorkPointCode, AppConfig.AppConnectString);
  130. if (dt != null && dt.Rows.Count > 0)
  131. {
  132. isCheck = true;
  133. }
  134. #region 测试时屏蔽
  135. //else
  136. //{
  137. // throw new Exception("U8物料存货信息取得失败");
  138. // this.Close();
  139. //}
  140. #endregion
  141. #endregion
  142. }
  143. private void GetRecInfo()
  144. {
  145. RecInfo = ICSPOArriveBLL.Search_Info(cCode, irowno.ToString(), AppConfig.AppConnectString);
  146. init();
  147. }
  148. private void init()
  149. {
  150. txtVenBatch.Text = RecInfo.Arr.cBatchProperty6;
  151. txtSumNo.Text = "";
  152. txtNowNo.Text = "";
  153. txtNowQty.Text = "";
  154. txtSumQty.Text = "";
  155. txtAllQty.Text = "";
  156. btnLabelCreate.Enabled = true;
  157. if (RecInfo == null)
  158. {
  159. return;
  160. }
  161. chkBtnAll.Enabled = true;
  162. chkBtnNo.Enabled = true;
  163. chkBtnPack.Enabled = true;
  164. txtSumQty.Text = RecInfo.SumQty.ToString();
  165. txtSumNo.Text = RecInfo.SumNo.ToString();
  166. try
  167. {
  168. string sql = @"SELECT COUNT(C.MCODE) AS NUM, C.MCODE, C.LOTQTY FROM ICSPOArrive A
  169. LEFT JOIN ICSITEMLot C ON A.cInvCode = C.MCODE AND A.cCode = C.TransNO AND A.irowno = CONVERT(int, C.TransLine)
  170. LEFT JOIN ICSWareHouseLotInfo D ON C.LotNO = D.LotNO WHERE A.cCode = '{0}' AND A.irowno = '{1}' AND C.MCODE = '{2}'
  171. GROUP BY C.MCODE, C.LOTQTY ";
  172. sql = string.Format(sql, cCode, irowno, RecInfo.Arr.cInvCode);
  173. DataTable ds = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  174. if (ds.Rows.Count == 0 || ds == null)
  175. {
  176. txtNowQty.Text = RecInfo.SumQty.ToString();
  177. txtNowPackQty.Text = RecInfo.SumQty.ToString();
  178. }
  179. else
  180. {
  181. foreach (DataRow dr in ds.Rows)
  182. {
  183. RecInfo.SumQty = RecInfo.SumQty - Decimal.Parse(dr["NUM"].ToString()) * Decimal.Parse(dr["LOTQTY"].ToString());
  184. //txtNowQty.Text = (RecInfo.SumQty - Decimal.Parse(dr["NUM"].ToString()) * Decimal.Parse(dr["LOTQTY"].ToString())).ToString();
  185. }
  186. txtNowQty.Text = RecInfo.SumQty.ToString();
  187. txtNowPackQty.Text = RecInfo.SumQty.ToString();
  188. }
  189. }
  190. catch (Exception ex)
  191. {
  192. throw ex;
  193. }
  194. //txtNowPackQty.Text = "1";
  195. if (txtNowPackQty.Text == "0")
  196. {
  197. txtNowNo.Text = "0";
  198. }
  199. else
  200. {
  201. txtNowNo.Text = (Math.Ceiling(decimal.Parse(txtNowQty.Text)) / Math.Ceiling(decimal.Parse(txtNowPackQty.Text))).ToString();
  202. }
  203. txtAllQty.Text = (decimal.Parse(txtSumQty.Text) + decimal.Parse(txtNowQty.Text)).ToString();
  204. txtAllNo.Text = (decimal.Parse(txtSumNo.Text) + decimal.Parse(txtNowNo.Text)).ToString();
  205. }
  206. private void btnLabelCreate_Click(object sender, EventArgs e)
  207. {
  208. if (isVenBatch)
  209. {
  210. if (txtVenBatch.Text.ToString().Trim() == "")
  211. {
  212. ICSBaseSimpleCode.AppshowMessageBox("存货分类4101和4701,请输入供应商炉批号");
  213. return;
  214. }
  215. }
  216. string LotNO = "";
  217. if (RecInfo == null)
  218. {
  219. ICSBaseSimpleCode.AppshowMessageBox("到货单信息取得失败");
  220. return;
  221. }
  222. if (string.IsNullOrWhiteSpace(cCode) || string.IsNullOrWhiteSpace(irowno.ToString()))
  223. {
  224. ICSBaseSimpleCode.AppshowMessageBox("到货单号或到货单行号不能为空!");
  225. return;
  226. }
  227. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在生成条码……");
  228. try
  229. {
  230. _wait.Show();
  231. Decimal totalQty = decimal.Parse(txtNowQty.Text);
  232. decimal pieceQty = decimal.Parse(txtNowPackQty.Text);
  233. int Num = int.Parse(txtNowNo.Text);
  234. if (pieceQty * Num < totalQty || pieceQty * (Num - 1) >= totalQty)
  235. {
  236. throw new Exception("条码数量计算出错,请重新计算");
  237. }
  238. decimal Qty = decimal.Parse(txtNowPackQty.Text);
  239. if (Num <= 0)
  240. {
  241. throw new Exception("条码张数不能为0");
  242. }
  243. if (Qty <= 0)
  244. {
  245. throw new Exception("条码数量不能为0");
  246. }
  247. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  248. int count = Convert.ToInt32(RecInfo.MaxNo);
  249. DateTime time = DateTime.Now;
  250. string timeStr = time.ToString("yyMMdd");
  251. int NO = 0;
  252. string subTime = "7" + time.ToString("yyyyMMdd");
  253. string sql = @"SELECT MAX(A.LotNO) AS LOTNO FROM ICSITEMLot A WHERE 1=1 AND A.LotNO LIKE '{0}%' ";
  254. sql = string.Format(sql, subTime);
  255. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  256. if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["LotNO"].ToString()))
  257. {
  258. LotNO = dt.Rows[0]["LOTNO"].ToString();
  259. NO = int.Parse(LotNO.Substring(LotNO.Length - 4, 4));
  260. }
  261. for (int i = 0; i < Num; i++)
  262. {
  263. //int b = NO + i + 1;
  264. _wait.Caption = "正在生成条码……" + " " + i.ToString() + "/" + Num.ToString();
  265. _wait.Refresh();
  266. ICSITEMLot Info = new ICSITEMLot();
  267. Info.ID = "";
  268. if (Qty < totalQty - Qty * i)
  269. {
  270. Info.LOTQTY = Qty;
  271. }
  272. else
  273. {
  274. Info.LOTQTY = totalQty - Qty * i;
  275. }
  276. Info.LotNO = subTime + (NO + i + 1).ToString().PadLeft(4, '0');
  277. Info.MCODE = RecInfo.Arr.cInvCode;
  278. if (RecInfo.icsitems == null)
  279. {
  280. Info.TransNO = RecInfo.Arr.cCode;
  281. }
  282. else
  283. {
  284. Info.TransNO = RecInfo.icsitems.TransNO;
  285. }
  286. if (RecInfo.icsitems == null)
  287. {
  288. Info.TransLine = RecInfo.Arr.irowno.ToString();
  289. }
  290. else
  291. {
  292. Info.TransLine = RecInfo.icsitems.TransLine;
  293. }
  294. if (isBatch)
  295. {
  296. if (txtBatch.Text.ToString().Trim() == "")
  297. {
  298. _wait.Close();
  299. ICSBaseSimpleCode.AppshowMessageBox("物料启用了批次管理,请输入批次号");
  300. return;
  301. }
  302. sql = @"SELECT * FROM Sys_EnumValues A INNER JOIN ICSINVENTORY B ON A.EnumText = B.INVCLASS
  303. WHERE 1=1 AND A.EnumKey = '00012' AND B.INVCODE = '{0}' ";
  304. sql = string.Format(sql, RecInfo.Arr.cInvCode);
  305. DataTable dts = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  306. if (dts.Rows.Count > 0 && dts != null)
  307. {
  308. sql = @"SELECT * FROM ICSITEMLot WHERE 1=1 AND VenderLotNO = '{0}' AND type = '到货' ";
  309. sql = string.Format(sql, txtBatch.Text.Trim());
  310. dts = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  311. if (dts.Rows.Count > 0 && dts != null)
  312. {
  313. _wait.Close();
  314. throw new Exception("此零件号重复,请确认");
  315. }
  316. //Info.VenderLotNO = timeStr.Substring(timeStr.Length - 6) + (RecInfo.TodayMOCount + 1).ToString().PadLeft(3, '0'); //生产批号,每个工单一个
  317. Info.VenderLotNO = txtBatch.Text.Trim(); //批号
  318. }
  319. else
  320. {
  321. Info.VenderLotNO = txtBatch.Text.Trim(); //批号
  322. }
  323. }
  324. else
  325. {
  326. if (txtBatch.Text.ToString().Trim() != "")
  327. {
  328. _wait.Close();
  329. ICSBaseSimpleCode.AppshowMessageBox("物料未启用批次管理,请不要输入批次号");
  330. return;
  331. }
  332. Info.VenderLotNO = RecInfo.VenderLotNO;
  333. }
  334. Info.PRODUCTDATE = time;
  335. Info.ACTIVE = "Y";
  336. Info.Exdate = Convert.ToDateTime("2999-12-31");
  337. Info.TYPE = "到货";
  338. Info.VenBatch = txtVenBatch.Text.Trim();
  339. if (isCheck)
  340. {
  341. Info.EATTRIBUTE2 = "合格";
  342. Info.EATTRIBUTE5 = "已检";
  343. }
  344. else
  345. {
  346. Info.EATTRIBUTE2 = "";
  347. }
  348. if (RecInfo.Arr.iNum == 0)
  349. {
  350. Info.EATTRIBUTE3 = 0;
  351. }
  352. else
  353. {
  354. Info.EATTRIBUTE3 = RecInfo.Arr.iNum / RecInfo.Arr.iQuantity;
  355. }
  356. InfoList.Add(Info);
  357. }
  358. _wait.Caption = "条码生成成功,正在上传数据";
  359. _wait.Refresh();
  360. ICSPOArriveBLL.Add(InfoList, AppConfig.AppConnectString);
  361. _wait.Close();
  362. this.Close();
  363. }
  364. catch (Exception ex)
  365. {
  366. _wait.Close();
  367. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  368. }
  369. }
  370. private void chkBtnAll_CheckedChanged(object sender, EventArgs e)
  371. {
  372. if (chkBtnAll.Checked == true)
  373. {
  374. chkBtnAll.Checked = true;
  375. chkBtnNo.Checked = false;
  376. chkBtnPack.Checked = false;
  377. chkBtnCheckedCharge();
  378. }
  379. }
  380. private void chkBtnNo_CheckedChanged(object sender, EventArgs e)
  381. {
  382. if (chkBtnNo.Checked == true)
  383. {
  384. chkBtnAll.Checked = false;
  385. chkBtnNo.Checked = true;
  386. chkBtnPack.Checked = false;
  387. chkBtnCheckedCharge();
  388. }
  389. }
  390. private void chkBtnPack_CheckedChanged(object sender, EventArgs e)
  391. {
  392. if (chkBtnPack.Checked == true)
  393. {
  394. chkBtnAll.Checked = false;
  395. chkBtnNo.Checked = false;
  396. chkBtnPack.Checked = true;
  397. chkBtnCheckedCharge();
  398. }
  399. }
  400. private void chkBtnCheckedCharge()
  401. {
  402. if (chkBtnAll.Checked == true)
  403. {
  404. chkBtnAll.Checked = true;
  405. chkBtnNo.Checked = false;
  406. chkBtnPack.Checked = false;
  407. this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
  408. this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  409. this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  410. }
  411. else if (chkBtnNo.Checked == true)
  412. {
  413. chkBtnAll.Checked = false;
  414. chkBtnNo.Checked = true;
  415. chkBtnPack.Checked = false;
  416. this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  417. this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
  418. this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  419. }
  420. else if (chkBtnPack.Checked == true)
  421. {
  422. chkBtnAll.Checked = false;
  423. chkBtnNo.Checked = false;
  424. chkBtnPack.Checked = true;
  425. this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  426. this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  427. this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
  428. }
  429. }
  430. private void txtNowPackQty_KeyDown(object sender, KeyEventArgs e)
  431. {
  432. if (e.KeyCode == Keys.Enter)
  433. {
  434. if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
  435. {
  436. ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
  437. return;
  438. }
  439. txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
  440. }
  441. }
  442. private void txtNowQty_KeyDown(object sender, KeyEventArgs e)
  443. {
  444. if (e.KeyCode == Keys.Enter)
  445. {
  446. if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
  447. {
  448. ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
  449. return;
  450. }
  451. txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
  452. }
  453. }
  454. private void txtNowPackQty_TextChanged(object sender, EventArgs e)
  455. {
  456. if (txtNowQty.Text == "")
  457. {
  458. return;
  459. }
  460. if (txtNowPackQty.Text == "")
  461. {
  462. return;
  463. }
  464. if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
  465. {
  466. ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
  467. return;
  468. }
  469. txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
  470. }
  471. private void txtNowQty_TextChanged(object sender, EventArgs e)
  472. {
  473. if (txtNowQty.Text == "")
  474. {
  475. return;
  476. }
  477. if (txtNowPackQty.Text == "")
  478. {
  479. return;
  480. }
  481. if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
  482. {
  483. ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
  484. return;
  485. }
  486. txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
  487. }
  488. }
  489. }