生成条码.cs 27 KB

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