生成条码.cs 27 KB

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