生成条码.cs 25 KB

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