生成条码.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. using NPOI.SS.Util;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Windows.Forms;
  9. using UAS_LabelMachine.Entity;
  10. using UAS_LabelMachine.PublicMethod;
  11. namespace UAS_LabelMachine
  12. {
  13. public partial class 生成条码 : Form
  14. {
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataHelper dh;
  17. DataTable dt;
  18. StringBuilder sql = new StringBuilder();
  19. string pi_id;
  20. //用于提示超出数量的物料
  21. Dictionary<string, string> NotPass = new Dictionary<string, string>();
  22. //前缀条件
  23. string Prefix = "";
  24. string Suffix = "";
  25. //生成条码的流水号
  26. int serialnum = 0;
  27. //客户的流水号
  28. int custserialnum = 0;
  29. //是否生成过条码
  30. bool FirstCode = false;
  31. //客户编号
  32. string CustCode = "";
  33. //编码规则编号
  34. string NrCode = "";
  35. string DataType = "";
  36. public 生成条码(string PI_INOUTNO)
  37. {
  38. InitializeComponent();
  39. pi_inoutno.Text = PI_INOUTNO;
  40. }
  41. public 生成条码(string PI_INOUTNO, string type)
  42. {
  43. InitializeComponent();
  44. pi_inoutno.Text = PI_INOUTNO;
  45. DataType = type;
  46. }
  47. private void 生成条码_Load(object sender, EventArgs e)
  48. {
  49. dh = SystemInf.dh;
  50. ChooseAll.ChooseAll(ProdIoInfDGV);
  51. //如果传进了出入库单号则默认执行一次取数据
  52. if (pi_inoutno.Text != "")
  53. {
  54. bi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  55. }
  56. pr_kind.Text = "全部";
  57. asc.controllInitializeSize(this);
  58. Width = Width - 1;
  59. }
  60. private void bi_inoutno_KeyDown(object sender, KeyEventArgs e)
  61. {
  62. if (e.KeyCode == Keys.Enter)
  63. {
  64. LoadData();
  65. }
  66. }
  67. private void 生成条码_SizeChanged(object sender, EventArgs e)
  68. {
  69. asc.controlAutoSize(this);
  70. }
  71. /// <summary>
  72. /// 筛选按钮
  73. /// </summary>
  74. /// <param name="sender"></param>
  75. /// <param name="e"></param>
  76. private void Screen_Click(object sender, EventArgs e)
  77. {
  78. bi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  79. }
  80. /// <summary>
  81. /// 生成条码
  82. /// </summary>
  83. /// <param name="sender"></param>
  84. /// <param name="e"></param>
  85. private void GenerateBarCode_Click(object sender, EventArgs e)
  86. {
  87. try
  88. {
  89. //获取编码规则
  90. DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + CustCode + "' order by nrd_detno", "select");
  91. //如果没有则取公共规则
  92. if (Nr.Rows.Count == 0)
  93. Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
  94. //用于过滤参数的正则表达式
  95. if (Nr.Rows.Count > 0)
  96. {
  97. NrCode = Nr.Rows[0]["nr_code"].ToString();
  98. }
  99. Regex match = new Regex("{\\w+}");
  100. //用于存放每一项的明细的数据
  101. string[] NrData = new string[Nr.Rows.Count];
  102. //流水号的索引
  103. int SerialNumIndex = 0;
  104. //流水长度
  105. int SerialNumLength = 0;
  106. //存放键值对
  107. int Radix = 10;
  108. string PrefixFixed = "";
  109. for (int m = 0; m < Nr.Rows.Count; m++)
  110. {
  111. switch (Nr.Rows[m]["nrd_type"].ToString())
  112. {
  113. //常量直接进行拼接
  114. case "常量":
  115. NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
  116. Prefix += NrData[m];
  117. Suffix += NrData[m];
  118. break;
  119. case "SQL":
  120. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  121. DataTable Temp;
  122. //如果不包含参数替换
  123. if (SQL.IndexOf("{") == 0)
  124. {
  125. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  126. }
  127. else
  128. {
  129. //替换参数后重新执行SQL
  130. foreach (Match mch in match.Matches(SQL))
  131. {
  132. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  133. }
  134. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  135. }
  136. if (Temp.Rows.Count > 0)
  137. {
  138. NrData[m] = Temp.Rows[0][0].ToString();
  139. Prefix += NrData[m];
  140. Suffix += NrData[m];
  141. }
  142. else
  143. {
  144. NrData[m] = "";
  145. Prefix += NrData[m];
  146. Suffix += NrData[m];
  147. }
  148. break;
  149. //流水需要通过MaxNumber去取
  150. case "流水":
  151. NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "'").ToString();
  152. Suffix = "";
  153. PrefixFixed = Prefix;
  154. //设置当前流水
  155. custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
  156. SerialNumIndex = m;
  157. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  158. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  159. break;
  160. default:
  161. break;
  162. }
  163. }
  164. //获取最大的流水号
  165. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  166. //如果流水号为空则插入一条新记录,从1开始取
  167. if (maxnum == "")
  168. {
  169. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + NrCode + "','" + Prefix + "','1')", "insert");
  170. custserialnum = 1;
  171. }
  172. //如果流水号不为空则取当前流水
  173. else
  174. {
  175. custserialnum = int.Parse(maxnum);
  176. }
  177. //有错误需要提醒的内容
  178. int CheckedRowCount = 0;
  179. string ErrRowIndex = "";
  180. //遍历整个Grid,勾选的项目全部进行条码生成
  181. for (int i = 0; i < ProdIoInfDGV.RowCount; i++)
  182. {
  183. if (ProdIoInfDGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  184. {
  185. CheckedRowCount++;
  186. List<string> pib_inqty = new List<string>();
  187. string pd_id = ProdIoInfDGV.Rows[i].Cells["pd_id"].FormattedValue.ToString();
  188. string pd_prodcode = ProdIoInfDGV.Rows[i].Cells["pd_prodcode"].FormattedValue.ToString();
  189. string lotno = ProdIoInfDGV.Rows[i].Cells["BAR_VENDBARCODE"].FormattedValue.ToString();
  190. string dc = ProdIoInfDGV.Rows[i].Cells["BAR_MADE"].FormattedValue.ToString();
  191. string pr_id = ProdIoInfDGV.Rows[i].Cells["pr_id"].FormattedValue.ToString();
  192. string pd_ordercode = ProdIoInfDGV.Rows[i].Cells["pd_ordercode"].FormattedValue.ToString();
  193. string pd_pdno = ProdIoInfDGV.Rows[i].Cells["pd_pdno"].FormattedValue.ToString();
  194. string pd_orderdetno = ProdIoInfDGV.Rows[i].Cells["pd_orderdetno"].FormattedValue.ToString();
  195. string pr_brand = ProdIoInfDGV.Rows[i].Cells["pr_brand"].FormattedValue.ToString();
  196. //总数
  197. decimal pd_totalqty = decimal.Parse(ProdIoInfDGV.Rows[i].Cells["pd_totalqty"].FormattedValue.ToString());
  198. //本次数量
  199. decimal pd_qty = decimal.Parse(ProdIoInfDGV.Rows[i].Cells["pd_qty"].FormattedValue.ToString());
  200. //最小包装数
  201. decimal pr_zxbzs = decimal.Parse(ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].FormattedValue.ToString());
  202. //中盒容量
  203. int mid_qty;
  204. try
  205. {
  206. mid_qty = int.Parse(ProdIoInfDGV.Rows[i].Cells["mid_qty"].FormattedValue.ToString());
  207. }
  208. catch (Exception)
  209. {
  210. MessageBox.Show("请检查中盒容量");
  211. return;
  212. }
  213. //如果中盘盒数量为1且有尾数则表示一箱未装满
  214. int mid_num = int.Parse(ProdIoInfDGV.Rows[i].Cells["mid_num"].FormattedValue.ToString());
  215. //中盒尾数
  216. decimal mid_remain = decimal.Parse(ProdIoInfDGV.Rows[i].Cells["mid_remain"].FormattedValue.ToString());
  217. string pib_barcode = dh.getFieldDataByCondition("prodiobarcode", "max(pib_barcode)", "PIB_INOUTNO='" + pi_inoutno.Text + "'").ToString();
  218. //中盒数量*中盒容量=需要打印的单盘标签
  219. ArrayList<string> midcode = new ArrayList<string>();
  220. ArrayList<string> barcode = new ArrayList<string>();
  221. ArrayList<string> custbarcode = new ArrayList<string>();
  222. ArrayList<string> lotno1 = new ArrayList<string>();
  223. ArrayList<string> dc1 = new ArrayList<string>();
  224. decimal restqty1 = 0;
  225. if (ProdIoInfDGV.Rows[i].Cells["pib_restqty1"].Value != null && ProdIoInfDGV.Rows[i].Cells["pib_restqty1"].Value.ToString() != "")
  226. {
  227. string[] restqty = ProdIoInfDGV.Rows[i].Cells["pib_restqty1"].Value.ToString().Split(',');
  228. for (int k = 0; k < restqty.Length; k++)
  229. {
  230. string mid_code = dh.getFieldDataByCondition("PRODIOBARCODE", "nvl(max(to_number(PIB_OUTBOXCODE1)),0)+1", "PIB_INOUTNO='" + pi_inoutno.Text + "'").ToString();
  231. decimal.TryParse(restqty[k], out restqty1);
  232. barcode.Add(BarcodeMethod1(pd_id, pr_id, pib_barcode));
  233. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  234. midcode.Add(mid_code);
  235. lotno1.Add(lotno);
  236. dc1.Add(dc);
  237. pib_inqty.Add(restqty1.ToString());
  238. //剩余生成的数量需要减掉尾数
  239. }
  240. }
  241. //循环中盒号的个数,取当前出入库单最大 的中盒号+1
  242. for (int j = 0; j < mid_num; j++)
  243. {
  244. //获取中盘的编号
  245. string mid_code = dh.getFieldDataByCondition("PRODIOBARCODE", "nvl(max(to_number(PIB_OUTBOXCODE1)),0)+" + (j + 1), "PIB_INOUTNO='" + pi_inoutno.Text + "'").ToString();
  246. //如果尾数不为0,并且已经遍历到了最后一箱(未装满的箱)
  247. int count = 0;
  248. decimal AddNum = pr_zxbzs;
  249. if (mid_remain != 0 && j + 1 == mid_num)
  250. {
  251. //剩下的尾数刚好够整数的最小包或者加上一个未装满的最小包
  252. int num = 0;
  253. if (int.TryParse((mid_remain % pr_zxbzs).ToString(), out num))
  254. {
  255. //如果小于最小包装数就是一条尾数
  256. if (mid_remain > pr_zxbzs)
  257. {
  258. if (mid_remain % pr_zxbzs != 0)
  259. count = int.Parse(Math.Floor(mid_remain / pr_zxbzs).ToString()) + 1;
  260. else
  261. count = int.Parse(Math.Floor(mid_remain / pr_zxbzs).ToString());
  262. }
  263. else
  264. count = 1;
  265. }
  266. else
  267. {
  268. count = int.Parse(Math.Ceiling(mid_remain / pr_zxbzs).ToString());
  269. }
  270. }
  271. else
  272. {
  273. //循环中盒的箱内容量
  274. count = mid_qty;
  275. }
  276. for (int k = 0; k < count; k++)
  277. {
  278. //将箱号添加进List
  279. barcode.Add(BarcodeMethod1(pd_id, pr_id, pib_barcode));
  280. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  281. midcode.Add(mid_code);
  282. lotno1.Add(lotno);
  283. dc1.Add(dc);
  284. if (mid_remain % pr_zxbzs != 0 && k + 1 == count && j + 1 == mid_num)
  285. AddNum = mid_remain % pr_zxbzs;
  286. pib_inqty.Add(AddNum.ToString());
  287. }
  288. }
  289. if (barcode.Count > 0)
  290. {
  291. //插入条码
  292. sql.Clear();
  293. sql.Append("insert into prodiobarcode (PIB_ID,PIB_PRODCODE,pib_inman,PIB_INDATE,PIB_INOUTNO,PIB_PIID,pib_brand,PIB_BARCODE,PIB_CUSTBARCODE,PIB_PDNO,");
  294. sql.Append("PIB_PDID,PIB_PICLASS,PIB_QTY,PIB_PRODID,PIB_OUTBOXCODE1,PIB_IFPRINT,PIB_IFPICK,PIB_ORDERCODE,PIB_CUSTPO,pib_orderdetno,pib_lotno,pib_datecode)");
  295. sql.Append(" values (prodiobarcode_seq.nextval,'" + pd_prodcode + "','" + User.UserName + "',sysdate,'" + pi_inoutno.Text + "'," + pi_id + ",'" + pr_brand + "',:barcode,:custbarcode,'" + pd_pdno + "','" + pd_id + "',");
  296. sql.Append("'" + pi_class.Text + "',:pib_inqty,'" + pr_id + "',:midcode,0,0,'" + pd_ordercode + "','','" + pd_orderdetno + "',:lotno1,:dc1)");
  297. dh.BatchInsert(sql.ToString(), new string[] { "barcode", "custbarcode", "pib_inqty", "midcode","lotno1","dc1" }, barcode.ToArray(), custbarcode.ToArray(), pib_inqty.ToArray(), midcode.ToArray(),lotno1.ToArray(),dc1.ToArray());
  298. //更新最大流水号
  299. dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + custserialnum + "'", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
  300. }
  301. else
  302. {
  303. ErrRowIndex += (i + 1) + ",";
  304. }
  305. }
  306. }
  307. if (ErrRowIndex != "")
  308. {
  309. MessageBox.Show(ErrRowIndex + "行无可用条码,请检查本次数量");
  310. return;
  311. }
  312. if (CheckedRowCount > 0)
  313. {
  314. LoadData();
  315. MessageBox.Show("生成条码成功!");
  316. }
  317. else
  318. {
  319. MessageBox.Show("未勾选需要生成的明细!");
  320. }
  321. //如果含有内容不符合的选项,进行提示
  322. string str = "";
  323. foreach (string ss in NotPass.Values)
  324. {
  325. str += ss + "\n";
  326. }
  327. if (str != "")
  328. MessageBox.Show(str);
  329. }
  330. catch (Exception ex)
  331. {
  332. MessageBox.Show(ex.Message + ex.StackTrace);
  333. }
  334. }
  335. //生成唯一条码
  336. public string BarcodeMethod1(string pd_id, string pr_id, string pib_barcode)
  337. {
  338. if (pib_barcode != "")
  339. {
  340. if (FirstCode)
  341. {
  342. serialnum = serialnum + 1;
  343. }
  344. //第一次的时候去获取数据库查询出来的值
  345. else
  346. {
  347. serialnum = int.Parse(pib_barcode.Substring(pib_barcode.Length - 4)) + 1;
  348. FirstCode = true;
  349. }
  350. }
  351. else
  352. {
  353. serialnum = serialnum + 1;
  354. }
  355. string serialcode = serialnum.ToString();
  356. for (int i = serialnum.ToString().Length; i < 4; i++)
  357. {
  358. serialcode = "0" + serialcode;
  359. }
  360. return pd_id + "-" + pr_id + "-" + serialcode;
  361. }
  362. //生成客户条码
  363. public string BarcodeMethod1(string Prefix, string Suffix, int Index, int Length, int radix)
  364. {
  365. string str = Prefix;
  366. //如果是流水则需要在前面加0
  367. string serialcode = BaseUtil.DToAny(custserialnum, radix);
  368. for (int j = serialcode.ToString().Length; j < Length; j++)
  369. {
  370. serialcode = "0" + serialcode;
  371. }
  372. str += serialcode;
  373. str += Suffix;
  374. custserialnum = custserialnum + 1;
  375. return str;
  376. }
  377. private static string lpad(int length, string number)
  378. {
  379. while (number.Length < length)
  380. {
  381. number = "0" + number;
  382. }
  383. number = number.Substring(number.Length - length, length);
  384. return number;
  385. }
  386. /// <summary>
  387. /// 重绘指定列的背景色
  388. /// </summary>
  389. /// <param name="sender"></param>
  390. /// <param name="e"></param>
  391. private void ProdIoInfDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  392. {
  393. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  394. if (e.ColumnIndex > 0)
  395. if (ProdIoInfDGV.Columns[e.ColumnIndex].Name == "pr_zxbzs" || ProdIoInfDGV.Columns[e.ColumnIndex].Name == "pd_qty" || ProdIoInfDGV.Columns[e.ColumnIndex].Name == "mid_qty" || ProdIoInfDGV.Columns[e.ColumnIndex].Name == "pib_restqty1")
  396. {
  397. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  398. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  399. Rectangle border = e.CellBounds;
  400. border.Width -= 1;
  401. e.Graphics.DrawRectangle(Pens.White, border);
  402. e.PaintContent(e.CellBounds);
  403. e.Handled = true;
  404. }
  405. }
  406. /// <summary>
  407. /// 计算中盘尾数的方法
  408. /// </summary>
  409. /// <param name="sender"></param>
  410. /// <param name="e"></param>
  411. private void ProdIoInfDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  412. {
  413. object pr_zxbzs = ProdIoInfDGV.Rows[e.RowIndex].Cells["pr_zxbzs"].Value;
  414. object pd_qty = ProdIoInfDGV.Rows[e.RowIndex].Cells["pd_qty"].Value;
  415. object mid_qty = ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_qty"].Value;
  416. object pd_totalqty = ProdIoInfDGV.Rows[e.RowIndex].Cells["pd_totalqty"].Value;
  417. decimal restqty1 = 0;
  418. if (ProdIoInfDGV.Rows[e.RowIndex].Cells["pib_restqty1"].Value != null && ProdIoInfDGV.Rows[e.RowIndex].Cells["pib_restqty1"].Value.ToString() != "")
  419. {
  420. string[] restqty = ProdIoInfDGV.Rows[e.RowIndex].Cells["pib_restqty1"].Value.ToString().Split(',');
  421. for (int k = 0; k < restqty.Length; k++)
  422. {
  423. decimal qty = 0;
  424. decimal.TryParse(restqty[k], out qty);
  425. restqty1 += qty;
  426. }
  427. }
  428. //ProdIoInfDGV.Rows[e.RowIndex].Cells["pd_qty"].Value = decimal.Parse(pd_qty.ToString()) - restqty1;
  429. pd_qty = decimal.Parse(pd_qty.ToString()) - restqty1;
  430. if (pr_zxbzs != null && pd_qty != null && mid_qty != null)
  431. {
  432. decimal 最小包装量 = decimal.Parse(pr_zxbzs.ToString());
  433. decimal 中盘容量 = decimal.Parse(mid_qty.ToString());
  434. decimal 本次数量 = decimal.Parse(pd_qty.ToString());
  435. decimal 总数 = decimal.Parse(pd_totalqty.ToString());
  436. //计算中盘数量
  437. decimal mid_num = 本次数量 / (最小包装量 * 中盘容量);
  438. int num = 0;
  439. if (int.TryParse(mid_num.ToString(), out num))
  440. {
  441. ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_num"].Value = mid_num;
  442. ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_remain"].Value = 本次数量 - mid_num * 最小包装量 * 中盘容量;
  443. }
  444. else
  445. {
  446. ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_num"].Value = Math.Floor(mid_num) + 1;
  447. ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_remain"].Value = 本次数量 - Math.Floor(mid_num) * 最小包装量 * 中盘容量;
  448. }
  449. }
  450. }
  451. //设置全部中盒容量
  452. private void SetMidCapacity_Click(object sender, EventArgs e)
  453. {
  454. for (int i = 0; i < ProdIoInfDGV.Rows.Count; i++)
  455. {
  456. ProdIoInfDGV.Rows[i].Cells["mid_qty"].Value = MidCapacity.Text;
  457. decimal restqty1 = 0;
  458. if (ProdIoInfDGV.Rows[i].Cells["pib_restqty1"].Value != null && ProdIoInfDGV.Rows[i].Cells["pib_restqty1"].Value.ToString() != "")
  459. {
  460. string[] restqty = ProdIoInfDGV.Rows[i].Cells["pib_restqty1"].Value.ToString().Split(',');
  461. for (int k = 0; k < restqty.Length; k++)
  462. {
  463. decimal qty = 0;
  464. decimal.TryParse(restqty[k], out qty);
  465. restqty1 += qty;
  466. }
  467. }
  468. object pr_zxbzs = ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].Value;
  469. object pd_qty = ProdIoInfDGV.Rows[i].Cells["pd_qty"].Value;
  470. object mid_qty = ProdIoInfDGV.Rows[i].Cells["mid_qty"].Value;
  471. object pd_totalqty = ProdIoInfDGV.Rows[i].Cells["pd_totalqty"].Value;
  472. if (ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].Value.ToString() != "" && ProdIoInfDGV.Rows[i].Cells["pd_qty"].Value.ToString() != "" && ProdIoInfDGV.Rows[i].Cells["mid_qty"].Value.ToString() != "" && ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].Value.ToString() != "0")
  473. {
  474. decimal 最小包装量 = decimal.Parse(pr_zxbzs.ToString());
  475. decimal 中盘容量 = decimal.Parse(mid_qty.ToString());
  476. decimal 本次数量 = decimal.Parse(pd_qty.ToString());
  477. decimal 总数 = decimal.Parse(pd_totalqty.ToString());
  478. //计算中盘数量
  479. decimal mid_num = 本次数量 / (最小包装量 * 中盘容量);
  480. int num = 0;
  481. if (int.TryParse(mid_num.ToString(), out num))
  482. {
  483. ProdIoInfDGV.Rows[i].Cells["mid_num"].Value = mid_num;
  484. ProdIoInfDGV.Rows[i].Cells["mid_remain"].Value = 本次数量 - mid_num * 最小包装量 * 中盘容量;
  485. }
  486. else
  487. {
  488. ProdIoInfDGV.Rows[i].Cells["mid_num"].Value = Math.Floor(mid_num) + 1;
  489. ProdIoInfDGV.Rows[i].Cells["mid_remain"].Value = 本次数量 - Math.Floor(mid_num) * 最小包装量 * 中盘容量;
  490. }
  491. }
  492. }
  493. }
  494. private void LoadData()
  495. {
  496. //获取客户编号
  497. CustCode = dh.getFieldDataByCondition("ProdInOut", "pi_cardcode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString();
  498. //用于存放每一项的明细的数据
  499. dt = (DataTable)dh.ExecuteSql("select pi_class,pi_id from prodinout where pi_inoutno='" + pi_inoutno.Text + "'", "select");
  500. if (dt.Rows.Count > 0)
  501. {
  502. pi_id = dt.Rows[0]["pi_id"].ToString();
  503. BaseUtil.SetFormValue(this.Controls, dt);
  504. string outsql = "";
  505. switch (pi_class.Text)
  506. {
  507. case "出货单":
  508. LogicHandler.GenerateBarCode(pi_id, CustCode + "|" + DataType, out outsql);
  509. sql.Clear();
  510. sql.Append(outsql);
  511. break;
  512. case "完工入库单":
  513. sql.Clear();
  514. sql.Append("select pd_piid,pd_id,pr_id,pr_brand,pr_madein,pr_unit,pr_detail,pr_spec,pr_zxbzs,inqty pd_totalqty,pd_ordercode,pd_orderdetno,pd_pdno,pd_prodcode,");
  515. sql.Append("pd_piclass,pd_qty from (select pd_piid,pd_id,pr_id,pr_brand,pr_madein,pr_unit,pr_detail,pr_spec,pr_zxbzs,inqty,pd_ordercode,pd_orderdetno,pd_pdno,");
  516. sql.Append("pd_prodcode,pd_piclass,inqty-nvl((select sum(nvl(pib_qty,0)) from PRODIOBARCODE where PIB_PIID=pd_piid and pib_pdno=pd_pdno ),0)pd_qty ");
  517. sql.Append("from (select pd_piid,min(pd_id) pd_id,sum(pd_inqty)inqty,pd_ordercode,pd_orderdetno,pd_pdno,max(pd_prodcode)pd_prodcode,max(pd_piclass)pd_piclass ");
  518. sql.Append("from prodiodetail group by pd_piid,pd_ordercode, pd_orderdetno,pd_pdno)T left join product ");
  519. sql.Append("on pr_code=pd_prodcode ) where pd_piid='" + pi_id + "' order by pd_pdno");
  520. break;
  521. case "其它出库单":
  522. LogicHandler.GenerateBarCode(pi_id, CustCode + "|" + DataType, out outsql);
  523. sql.Clear();
  524. sql.Append(outsql);
  525. break;
  526. default:
  527. break;
  528. }
  529. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  530. BaseUtil.FillDgvWithDataTable(ProdIoInfDGV, dt);
  531. }
  532. else
  533. {
  534. MessageBox.Show("当前单据不存在");
  535. pi_inoutno.Text = "";
  536. }
  537. }
  538. private void ResetSerialNum_Click(object sender, EventArgs e)
  539. {
  540. dt = (DataTable)dh.ExecuteSql("select pi_class,pi_id from prodinout where pi_inoutno='" + pi_inoutno.Text + "'", "select");
  541. if (dt.Rows.Count > 0)
  542. {
  543. if (NrCode != "")
  544. {
  545. dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber=1", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
  546. MessageBox.Show("流水重置成功");
  547. }
  548. else
  549. MessageBox.Show("当前客户无对应条码规则");
  550. }
  551. else
  552. {
  553. MessageBox.Show("当前单据不存在");
  554. pi_inoutno.Text = "";
  555. }
  556. }
  557. }
  558. }