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

367 lines
15 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.Base.Language.Tool;
  10. using ICSSoft.Base.UserControl.MessageControl;
  11. using ICSSoft.Base.Config.AppConfig;
  12. using ICSSoft.Base.Config.DBHelper;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.UserControl.FormControl;
  15. using ICSSoft.Base.ReferForm.AppReferForm;
  16. using System.Text.RegularExpressions;
  17. using ICSSoft.Frame.APP;
  18. using ICSSoft.Frame.Data.BLL;
  19. using ICSSoft.Frame.Data.Entity;
  20. using ICSSoft.Base.Lable.PrintTool;
  21. namespace ICSSoft.Frame.APP
  22. {
  23. public partial class FormStockBarCodeCreate : DevExpress.XtraEditors.XtraForm
  24. {
  25. List<Dictionary<string, object>> _Rows = new List<Dictionary<string, object>>();
  26. bool isCreateOK = false;
  27. decimal d = 0;
  28. public FormStockBarCodeCreate()
  29. {
  30. InitializeComponent();
  31. }
  32. public FormStockBarCodeCreate(List<Dictionary<string, object>> Rows)
  33. {
  34. InitializeComponent();
  35. _Rows = Rows;
  36. OnCreateControl();
  37. }
  38. #region 移动窗体
  39. private const int WM_NCHITTEST = 0x84;
  40. private const int HTCLIENT = 0x1;
  41. private const int HTCAPTION = 0x2;
  42. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  43. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  44. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  45. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  46. //重写窗体,使窗体可以不通过自带标题栏实现移动
  47. protected override void WndProc(ref Message m)
  48. {
  49. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  50. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  51. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  52. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  53. switch (m.Msg)
  54. {
  55. case WM_NCHITTEST:
  56. base.WndProc(ref m);
  57. if ((int)m.Result == HTCLIENT)
  58. m.Result = (IntPtr)HTCAPTION;
  59. return;
  60. }
  61. //拦截双击标题栏、移动窗体的系统消息
  62. if (m.Msg != 0xA3)
  63. {
  64. base.WndProc(ref m);
  65. }
  66. }
  67. #endregion
  68. protected override void OnCreateControl()
  69. {
  70. base.OnCreateControl();
  71. grdDetail.DataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FormStockBarCodeSelect.searchSQl() + "and 1=2").Tables[0];
  72. InsertIntoGrvDetail(_Rows);
  73. }
  74. private void btnClose_Click(object sender, EventArgs e)
  75. {
  76. this.DialogResult = DialogResult.Cancel;
  77. btnExit_Click(null, null);
  78. }
  79. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  80. {
  81. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  82. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  83. }
  84. private void btnDel_Click(object sender, EventArgs e)
  85. {
  86. }
  87. private void btnQuit_Click(object sender, EventArgs e)
  88. {
  89. if (grvDetail.RowCount > 0)
  90. {
  91. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("有待生成条码的数据,是否放弃") == System.Windows.Forms.DialogResult.OK)
  92. {
  93. grdDetail.DataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FormStockBarCodeSelect.searchSQl() + " and 1=2 ").Tables[0];
  94. }
  95. }
  96. }
  97. private void btnExit_Click(object sender, EventArgs e)
  98. {
  99. if (grvDetail.RowCount > 0)
  100. {
  101. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("有待生成条码的数据,是否退出") == System.Windows.Forms.DialogResult.OK)
  102. {
  103. this.Close();
  104. }
  105. }
  106. else
  107. {
  108. this.Close();
  109. }
  110. }
  111. #region 生成
  112. private void btnFilter_Click(object sender, EventArgs e)
  113. {
  114. grvDetail.PostEditor();
  115. this.Validate();
  116. decimal suming = 0;
  117. decimal PQty = 0;//批次数量
  118. if (grvDetail.RowCount == 0)
  119. {
  120. ICSBaseSimpleCode.AppshowMessageBox("没有数据,无法生成");
  121. return;
  122. }
  123. for (int i = 0; i < grvDetail.RowCount; i++)
  124. {
  125. if (Convert.ToInt32(grvDetail.GetRowCellValue(i, BarCodeCount)) == 0)
  126. {
  127. ICSBaseSimpleCode.AppshowMessageBox("条码个数不能为空!!");
  128. return;
  129. }
  130. if (Convert.ToInt32(grvDetail.GetRowCellValue(i, BarCodeqty)) == 0)
  131. {
  132. ICSBaseSimpleCode.AppshowMessageBox("条码规格不能为空!!");
  133. return;
  134. }
  135. //if (Convert.ToInt32(grvDetail.GetRowCellValue(i, BatchCode)) == 0)
  136. //{
  137. // ICSBaseSimpleCode.AppshowMessageBox("批次不能为空!!");
  138. // return;
  139. //}
  140. }
  141. try
  142. {
  143. string CartonNo = "";
  144. string PCode = "";
  145. string PRow = "0";
  146. String PID = "";
  147. List<PrintPara> parasList = new List<PrintPara>();
  148. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  149. List<ICSITEMLot> Listguid = new List<ICSITEMLot>();
  150. for (int i = 0; i < grvDetail.RowCount;i++ )
  151. {
  152. decimal BarQty = 0;//条码规格
  153. decimal packQty = 0;//已包装数量
  154. string PoCode = grvDetail.GetRowCellValue(i,Code).ToString();
  155. PCode = grvDetail.GetRowCellValue(i, cCode).ToString();
  156. //PRow = int.Parse(grvDetail.GetRowCellValue(i, row).ToString());
  157. PRow = grvDetail.GetRowCellValue(i, row).ToString();
  158. PID = grvDetail.GetRowCellValue(i, ERPAutoid).ToString();
  159. int BarCount = 0;//条码个数
  160. decimal.TryParse(grvDetail.GetRowCellValue(i, iQuantity).ToString(), out PQty);
  161. decimal.TryParse(grvDetail.GetRowCellValue(i, BarCodeqty).ToString(), out BarQty);
  162. decimal.TryParse(grvDetail.GetRowCellValue(i, PackQty).ToString(), out packQty);
  163. int.TryParse(grvDetail.GetRowCellValue(i, BarCodeCount).ToString(), out BarCount);
  164. suming += BarQty * BarCount;
  165. decimal sumQty = suming + packQty;
  166. if (sumQty > PQty)
  167. {
  168. ICSBaseSimpleCode.AppshowMessageBox("生成条码数量大于到货总数,");
  169. return;
  170. }
  171. for (int j = 0; j < BarCount; j++)
  172. {
  173. ICSITEMLot line = new ICSITEMLot();
  174. line.ID = AppConfig.GetGuid();
  175. CartonNo = AppConfig.GetSerialCode(AppConfig.FrameConnectString,AppConfig.WorkPointCode,
  176. "ICSITEMLot", "LotNO", PoCode, 5);
  177. line.LotNO = CartonNo;
  178. line.TransNO = PCode;
  179. line.TransLine = PRow;
  180. line.ItemCode = grvDetail.GetRowCellValue(i, cInvCode).ToString();
  181. line.PRODUCTDATE = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  182. line.LOTQTY = BarQty;
  183. line.ACTIVE = "Y";
  184. line.Exdate = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  185. line.TYPE = "原材料";
  186. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  187. line.MUSER = AppConfig.UserId;
  188. line.MUSERName = AppConfig.UserName;
  189. line.WorkPoint = AppConfig.WorkPointCode;
  190. Listguid.Add(line);
  191. PrintPara para = new PrintPara();
  192. para.PrintKey = "LOTNO";
  193. para.PrintValues = new object[] { CartonNo };
  194. parasList.Add(para);
  195. ICSITEMLot Info = new ICSITEMLot();
  196. Info.LotNO = CartonNo;
  197. Info.lastPrintUSERID = AppConfig.UserId;
  198. Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  199. Info.WorkPoint = AppConfig.WorkPointCode;
  200. InfoList.Add(Info);
  201. }
  202. }
  203. //ICSStockBarCodeBLL.CreatebarCode(Listguid, AppConfig.AppConnectString, PID, suming);
  204. grdDetail.DataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FormStockBarCodeSelect.searchSQl() + " and 1=2 ").Tables[0];
  205. grvDetail.BestFitColumns();
  206. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("保存成功,是否打印?") == DialogResult.OK)
  207. {
  208. FormPrintDialog f = new FormPrintDialog("006", this.Text, parasList, false, null);
  209. f.ShowDialog();
  210. //更新打印信息
  211. ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
  212. }
  213. isCreateOK = true;
  214. }
  215. catch(Exception ex)
  216. {
  217. ICSBaseSimpleCode.AppshowMessageBox(1, "保存失败\r\n" + ex.Message);
  218. }
  219. this.DialogResult = DialogResult.OK;
  220. }
  221. #endregion
  222. private void FormProductBarCodeCreate_FormClosing(object sender, FormClosingEventArgs e)
  223. {
  224. if (isCreateOK)
  225. {
  226. this.DialogResult = DialogResult.OK;
  227. }
  228. }
  229. private void btnAdd_Click(object sender, EventArgs e)
  230. {
  231. }
  232. private void InsertIntoGrvDetail(List<Dictionary<string, object>> Rows)
  233. {
  234. List<string> serialList = new List<string>();
  235. for (int i = 0; i < grvDetail.RowCount; i++)
  236. {
  237. serialList.Add(grvDetail.GetRowCellValue(i, ERPAutoid).ToString());
  238. }
  239. foreach (Dictionary<string, object> dr in Rows)
  240. {
  241. if (serialList.Contains(dr["ERPAutoid"].ToString()))
  242. {
  243. continue;
  244. }
  245. grvDetail.AddNewRow();
  246. for (int i = 0; i < grvDetail.Columns.Count; i++)
  247. {
  248. string FieldName = grvDetail.Columns[i].FieldName;
  249. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, FieldName, dr[FieldName]);
  250. }
  251. }
  252. grvDetail.AddNewRow();
  253. grvDetail.DeleteRow(grvDetail.FocusedRowHandle);
  254. //for (int j = 0; j < grvDetail.RowCount;j++ )
  255. //{
  256. // double PackingSpec = 0;
  257. // double.TryParse(grvDetail.GetRowCellValue(j, BQuantity).ToString(), out PackingSpec);
  258. // if(PackingSpec<=0)
  259. // {
  260. // ICSBaseSimpleCode.AppshowMessageBox(2,"包装规格(除数不能小于等于0!)");
  261. // return;
  262. // }
  263. // int Lotqty = 0;
  264. // int.TryParse(grvDetail.GetRowCellValue(j, PQuantity).ToString(), out Lotqty);
  265. // int count = (int)Math.Ceiling((double)Lotqty / (double)PackingSpec);
  266. // grvDetail.SetRowCellValue(j,BarCodeqty,count);
  267. //}
  268. }
  269. bool b = false;
  270. private void FormCartonProtectCreate_Load(object sender, EventArgs e)
  271. {
  272. LanguageConvert.ChangeLanguage(this, "1");
  273. Application.DoEvents();
  274. OnCreateControl();
  275. b = true;
  276. }
  277. private void grvDetail_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
  278. {
  279. if (e.Column.FieldName == "BQuantity" || e.Column.FieldName == "BarCodeqty")
  280. {
  281. e.Appearance.BackColor = Color.YellowGreen;
  282. }
  283. }
  284. private void btnAdd_Click_1(object sender, EventArgs e)
  285. {
  286. grvDetail.FocusedRowHandle = 0;
  287. decimal sum = decimal.Parse(grvDetail.GetRowCellValue(grvDetail.RowCount - 1, iQuantity).ToString() == "" ? "0" : grvDetail.GetRowCellValue(grvDetail.RowCount - 1, iQuantity).ToString());
  288. decimal count = decimal.Parse(grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeCount).ToString() == "" ? "0" : grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeCount).ToString());
  289. decimal Spec = decimal.Parse(grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeqty).ToString() == "" ? "0" : grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeqty).ToString());
  290. d = sum - (count * Spec);
  291. foreach (Dictionary<string, object> dr in _Rows)
  292. {
  293. grvDetail.AddNewRow();
  294. for (int j = 0; j < grvDetail.Columns.Count; j++)
  295. {
  296. string FieldName = grvDetail.Columns[j].FieldName;
  297. if (FieldName == "PQuantity")
  298. {
  299. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, FieldName, d);
  300. }
  301. else
  302. {
  303. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, FieldName, dr[FieldName]);
  304. }
  305. }
  306. }
  307. }
  308. private void btnDel_Click_1(object sender, EventArgs e)
  309. {
  310. grvDetail.PostEditor();
  311. this.Validate();
  312. if (grvDetail.FocusedRowHandle < 0)
  313. {
  314. return;
  315. }
  316. if (grvDetail.RowCount <= 1)
  317. {
  318. return;
  319. }
  320. grvDetail.DeleteRow(grvDetail.FocusedRowHandle);
  321. }
  322. }
  323. }