生成条码.cs 26 KB

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