生成条码.cs 25 KB

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