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

529 lines
19 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. namespace ICSSoft.Frame.APP
  22. {
  23. public partial class FormStockBarCodeCreates : DevExpress.XtraEditors.XtraForm
  24. {
  25. private FormICSBarCodeModel BarCodeInfo;
  26. private string AutoID;
  27. private string Code;
  28. #region 构造函数
  29. public FormStockBarCodeCreates(string ID,string cCode)
  30. {
  31. InitializeComponent();
  32. chkBtnAll.Checked = false;
  33. chkBtnAll.Checked = true;
  34. AutoID = ID;
  35. Code = cCode;
  36. GetRecInfo();
  37. if (BarCodeInfo == null)
  38. {
  39. throw new Exception("入库单信息取得失败");
  40. }
  41. //if (RecInfo.item.ItemCtrType == null || RecInfo.item.ItemCtrType.ItemCtrTypeCode == "")
  42. //{
  43. // throw new Exception("入库单对应料品的控管类型为空,无法生成条码");
  44. //}
  45. }
  46. #endregion
  47. #region 移动窗体
  48. private const int WM_NCHITTEST = 0x84;
  49. private const int HTCLIENT = 0x1;
  50. private const int HTCAPTION = 0x2;
  51. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  52. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  53. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  54. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  55. //重写窗体,使窗体可以不通过自带标题栏实现移动
  56. protected override void WndProc(ref Message m)
  57. {
  58. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  59. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  60. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  61. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  62. switch (m.Msg)
  63. {
  64. case WM_NCHITTEST:
  65. base.WndProc(ref m);
  66. if ((int)m.Result == HTCLIENT)
  67. m.Result = (IntPtr)HTCAPTION;
  68. return;
  69. }
  70. //拦截双击标题栏、移动窗体的系统消息
  71. if (m.Msg != 0xA3)
  72. {
  73. base.WndProc(ref m);
  74. }
  75. }
  76. #endregion
  77. #region 退出
  78. private void btnClose_Click(object sender, EventArgs e)
  79. {
  80. AppConfig.CloseFormShow(this.Text);
  81. this.Close();
  82. }
  83. private void btnExit_Click(object sender, EventArgs e)
  84. {
  85. AppConfig.CloseFormShow(this.Text);
  86. this.Close();
  87. }
  88. #endregion
  89. private void GetRecInfo()
  90. {
  91. DataTable dt = ICSStockBarCodeBLL.FindDataByID(AutoID,Code, AppConfig.AppConnectString);
  92. if (dt != null && dt.Rows.Count > 0)
  93. {
  94. BarCodeInfo = new FormICSBarCodeModel();
  95. BarCodeInfo.Qty = dt.Rows[0]["INVCARTONQTY"].ToString();
  96. BarCodeInfo.sumQty = dt.Rows[0]["sumQty"].ToString();
  97. BarCodeInfo.packCount = dt.Rows[0]["cont"].ToString();
  98. BarCodeInfo.packQty = dt.Rows[0]["PackQty"].ToString();
  99. BarCodeInfo.maxLot = int.Parse(dt.Rows[0]["maxLot"].ToString() == "" ? "0" : dt.Rows[0]["maxLot"].ToString());
  100. BarCodeInfo.Free1 = dt.Rows[0]["Free1"].ToString();
  101. BarCodeInfo.Free2 = dt.Rows[0]["Free2"].ToString();
  102. BarCodeInfo.Free3 = dt.Rows[0]["Free3"].ToString();
  103. BarCodeInfo.cCode = dt.Rows[0]["cCode"].ToString();
  104. BarCodeInfo.cInvCode = dt.Rows[0]["cInvCode"].ToString();
  105. BarCodeInfo.count = dt.Rows[0]["INVCARTONQTY"].ToString();
  106. }
  107. init();
  108. }
  109. private void init()
  110. {
  111. txtSumNo.Text = "";
  112. txtNowNo.Text = "";
  113. txtNowQty.Text = "";
  114. txtSumQty.Text = "";
  115. txtAllQty.Text = "";
  116. btnLabelCreate.Enabled = true;
  117. if (BarCodeInfo == null)
  118. {
  119. return;
  120. }
  121. //if (RecInfo.item != null)
  122. //{
  123. // if (RecInfo.item.ItemCtrType == null)
  124. // {
  125. // btnLabelCreate.Enabled = false;
  126. // }
  127. //if (RecInfo.item.ItemCtrType.ItemCtrTypeCode == ATVControlParam.ItemCtrlEnum.PieceCtrl.Code)
  128. //{
  129. // txtNowPackQty.Text = "1";
  130. // txtNowPackQty.Properties.ReadOnly = true;
  131. // chkBtnPack.Checked = false;
  132. // chkBtnPack.Checked = true;
  133. // chkBtnAll.Enabled = false;
  134. // chkBtnNo.Enabled = false;
  135. // chkBtnPack.Enabled = false;
  136. //}
  137. //else
  138. //{
  139. txtNowPackQty.Text = BarCodeInfo.count == "0" ? BarCodeInfo.sumQty : BarCodeInfo.count;
  140. txtNowPackQty.Properties.ReadOnly = false;
  141. //chkBtnPack.Checked = false;
  142. //chkBtnPack.Checked = true;
  143. chkBtnAll.Enabled = true;
  144. chkBtnNo.Enabled = true;
  145. chkBtnPack.Enabled = true;
  146. //}
  147. //}
  148. txtSumQty.Text = BarCodeInfo.packQty.ToString();
  149. txtSumNo.Text = BarCodeInfo.packCount.ToString() == "" ? "0" : BarCodeInfo.packCount.ToString();
  150. txtNowQty.Text = BarCodeInfo.sumQty;
  151. txtNowNo.Text = (decimal.Parse(txtNowQty.Text.Trim()) / decimal.Parse(txtNowPackQty.Text.Trim())).ToString();
  152. txtAllQty.Text = (decimal.Parse(txtSumQty.Text) + decimal.Parse(txtNowQty.Text)).ToString();
  153. txtAllNo.Text = (decimal.Parse(txtSumNo.Text) + decimal.Parse(txtNowNo.Text)).ToString();
  154. }
  155. private void btnLabelCreate_Click(object sender, EventArgs e)
  156. {
  157. if (BarCodeInfo == null)
  158. {
  159. ICSBaseSimpleCode.AppshowMessageBox("入库单信息取得失败");
  160. return;
  161. }
  162. if (string.IsNullOrWhiteSpace(BarCodeInfo.cCode) || string.IsNullOrWhiteSpace(BarCodeInfo.Free1))
  163. {
  164. ICSBaseSimpleCode.AppshowMessageBox("订单号或订单行号不能为空!");
  165. return;
  166. }
  167. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在生成条码……");
  168. try
  169. {
  170. _wait.Show();
  171. Decimal totalQty = decimal.Parse(txtNowQty.Text);
  172. decimal pieceQty = decimal.Parse(txtNowPackQty.Text);
  173. int Num = int.Parse(txtNowNo.Text);
  174. if (pieceQty * Num < totalQty || pieceQty * (Num - 1) >= totalQty)
  175. {
  176. throw new Exception("条码数量计算出错,请重新计算");
  177. }
  178. decimal Qty = decimal.Parse(txtNowPackQty.Text);
  179. if (Num <= 0)
  180. {
  181. throw new Exception("条码张数不能为0");
  182. }
  183. if (Qty <= 0)
  184. {
  185. throw new Exception("条码数量不能为0");
  186. }
  187. List<PrintPara> parasList = new List<PrintPara>();
  188. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  189. List<ICSITEMLot> InfoLists = new List<ICSITEMLot>();
  190. int count = Convert.ToInt32(BarCodeInfo.maxLot);
  191. DateTime time = AppConfig.GetSeverDateTime("yyyy-MM-dd");
  192. string timeStr=time.ToString("yyMMdd");
  193. for (int i = 0; i < Num; i++)
  194. {
  195. _wait.Caption = "正在生成条码……" + " " + i.ToString() + "/" + Num.ToString();
  196. _wait.Refresh();
  197. ICSITEMLot Info = new ICSITEMLot();
  198. Info.ID = "";
  199. if (Qty < totalQty - Qty * i)
  200. {
  201. Info.LOTQTY = Qty;
  202. }
  203. else
  204. {
  205. Info.LOTQTY = totalQty - Qty * i;
  206. }
  207. Info.LotNO = BarCodeInfo.cCode + BarCodeInfo.Free1 + (count + i + 1).ToString().PadLeft(5, '0');
  208. Info.ID = AppConfig.GetGuid();
  209. Info.ItemCode = BarCodeInfo.cInvCode;
  210. Info.TransNO = BarCodeInfo.Free2;
  211. //Info.TransLine = int.Parse(BarCodeInfo.Free3);
  212. Info.TransLine = BarCodeInfo.Free3;
  213. Info.PRODUCTDATE = time;
  214. Info.ACTIVE = "Y";
  215. Info.Exdate = Convert.ToDateTime("2999-12-31");
  216. Info.TYPE = "原材料";
  217. Info.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  218. InfoLists.Add(Info);
  219. PrintPara para = new PrintPara();
  220. para.PrintKey = "LOTNO";
  221. para.PrintValues = new object[] { Info.LotNO };
  222. parasList.Add(para);
  223. ICSITEMLot Infos = new ICSITEMLot();
  224. Infos.LotNO = Info.LotNO;
  225. Infos.lastPrintUSERID = AppConfig.UserId;
  226. Infos.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  227. Infos.WorkPoint = AppConfig.WorkPointCode;
  228. InfoList.Add(Infos);
  229. }
  230. _wait.Caption = "条码生成成功,正在上传数据";
  231. _wait.Refresh();
  232. ICSStockBarCodeBLL.CreatebarCode(InfoLists, AppConfig.AppConnectString);
  233. _wait.Close();
  234. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("保存成功,是否打印?") == DialogResult.OK)
  235. {
  236. FormPrintDialog f = new FormPrintDialog("006", this.Text, parasList, false, null);
  237. f.ShowDialog();
  238. //更新打印信息
  239. ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
  240. }
  241. //_wait.Caption = "数据上传完成,正在打开条码打印";
  242. //_wait.Refresh();
  243. //GetRecInfo();
  244. this.Close();
  245. }
  246. catch (Exception ex)
  247. {
  248. _wait.Close();
  249. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  250. }
  251. }
  252. private void chkBtnAll_CheckedChanged(object sender, EventArgs e)
  253. {
  254. if (chkBtnAll.Checked == true)
  255. {
  256. chkBtnAll.Checked = true;
  257. chkBtnNo.Checked = false;
  258. chkBtnPack.Checked = false;
  259. chkBtnCheckedCharge();
  260. }
  261. }
  262. private void chkBtnNo_CheckedChanged(object sender, EventArgs e)
  263. {
  264. if (chkBtnNo.Checked == true)
  265. {
  266. chkBtnAll.Checked = false;
  267. chkBtnNo.Checked = true;
  268. chkBtnPack.Checked = false;
  269. chkBtnCheckedCharge();
  270. }
  271. }
  272. private void chkBtnPack_CheckedChanged(object sender, EventArgs e)
  273. {
  274. if (chkBtnPack.Checked == true)
  275. {
  276. chkBtnAll.Checked = false;
  277. chkBtnNo.Checked = false;
  278. chkBtnPack.Checked = true;
  279. chkBtnCheckedCharge();
  280. }
  281. }
  282. private void chkBtnCheckedCharge()
  283. {
  284. if (chkBtnAll.Checked == true)
  285. {
  286. chkBtnAll.Checked = true;
  287. chkBtnNo.Checked = false;
  288. chkBtnPack.Checked = false;
  289. this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
  290. this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  291. this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  292. txtNowQty.Properties.ReadOnly = true;
  293. txtNowNo.Properties.ReadOnly = false;
  294. txtNowPackQty.Properties.ReadOnly = false;
  295. }
  296. else if (chkBtnNo.Checked == true)
  297. {
  298. chkBtnAll.Checked = false;
  299. chkBtnNo.Checked = true;
  300. chkBtnPack.Checked = false;
  301. this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  302. this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
  303. this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  304. txtNowQty.Properties.ReadOnly = false;
  305. txtNowNo.Properties.ReadOnly = true;
  306. txtNowPackQty.Properties.ReadOnly = false;
  307. }
  308. else if (chkBtnPack.Checked == true)
  309. {
  310. chkBtnAll.Checked = false;
  311. chkBtnNo.Checked = false;
  312. chkBtnPack.Checked = true;
  313. this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  314. this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
  315. this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
  316. txtNowQty.Properties.ReadOnly = false;
  317. txtNowNo.Properties.ReadOnly = false;
  318. txtNowPackQty.Properties.ReadOnly = true;
  319. }
  320. }
  321. private void txtNowPackQty_TextChanged(object sender, EventArgs e)
  322. {
  323. }
  324. private void txtDocOrg_EditValueChanged(object sender, EventArgs e)
  325. {
  326. }
  327. private void txtNowPackQty_EditValueChanged(object sender, EventArgs e)
  328. {
  329. bool isOK = false;
  330. if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox))
  331. {
  332. DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox;
  333. if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name)
  334. {
  335. isOK = true;
  336. }
  337. }
  338. if (!isOK)
  339. {
  340. return;
  341. }
  342. decimal No = 0;
  343. decimal Qty = 0;
  344. decimal Pack = 0;
  345. decimal.TryParse(txtNowNo.Text, out No);
  346. decimal.TryParse(txtNowQty.Text, out Qty);
  347. decimal.TryParse(txtNowPackQty.Text, out Pack);
  348. if (txtNowNo.Properties.ReadOnly == true)
  349. {
  350. Qty = No * Pack;
  351. txtNowQty.Text = Qty.ToString();
  352. }
  353. if (txtNowQty.Properties.ReadOnly == true)
  354. {
  355. if (Pack != 0)
  356. {
  357. No = Math.Ceiling(Qty / Pack);
  358. txtNowNo.Text = No.ToString();
  359. }
  360. else
  361. {
  362. No = 0;
  363. }
  364. }
  365. }
  366. private void txtNowNo_EditValueChanged(object sender, EventArgs e)
  367. {
  368. bool isOK = false;
  369. if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox))
  370. {
  371. DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox;
  372. if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name)
  373. {
  374. isOK = true;
  375. }
  376. }
  377. if (!isOK)
  378. {
  379. return;
  380. }
  381. decimal No;
  382. decimal Qty;
  383. decimal Pack;
  384. decimal.TryParse(txtNowNo.Text, out No);
  385. decimal.TryParse(txtNowQty.Text, out Qty);
  386. decimal.TryParse(txtNowPackQty.Text, out Pack);
  387. if (txtNowPackQty.Properties.ReadOnly == true)
  388. {
  389. Qty = No * Pack;
  390. txtNowQty.Text = Qty.ToString();
  391. }
  392. if (txtNowQty.Properties.ReadOnly == true)
  393. {
  394. if (No != 0)
  395. {
  396. Pack = Math.Ceiling(Qty / No);
  397. txtNowPackQty.Text = Pack.ToString();
  398. }
  399. else
  400. {
  401. Pack = 0;
  402. }
  403. }
  404. }
  405. private void txtNowQty_EditValueChanged(object sender, EventArgs e)
  406. {
  407. bool isOK = false;
  408. if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox))
  409. {
  410. DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox;
  411. if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name)
  412. {
  413. isOK = true;
  414. }
  415. }
  416. if (!isOK)
  417. {
  418. return;
  419. }
  420. decimal No = 0;
  421. decimal Qty = 0;
  422. decimal Pack = 0;
  423. decimal.TryParse(txtNowNo.Text, out No);
  424. decimal.TryParse(txtNowQty.Text, out Qty);
  425. decimal.TryParse(txtNowPackQty.Text, out Pack);
  426. if (txtNowPackQty.Properties.ReadOnly == true)
  427. {
  428. if (Pack != 0)
  429. {
  430. No = Math.Ceiling(Qty / Pack);
  431. txtNowNo.Text = No.ToString();
  432. }
  433. }
  434. if (txtNowNo.Properties.ReadOnly == true)
  435. {
  436. if (No != 0)
  437. {
  438. Pack = Math.Ceiling(Qty / No);
  439. txtNowPackQty.Text = Pack.ToString();
  440. }
  441. }
  442. }
  443. }
  444. }