生成条码.cs 28 KB

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