ReSetMaxNum.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Windows.Forms;
  10. using UAS_LabelMachine.Entity;
  11. namespace UAS_LabelMachine
  12. {
  13. public partial class ReSetMaxNum : Form
  14. {
  15. DataHelper dh = SystemInf.dh;
  16. string custcode;
  17. string inoutno;
  18. public ReSetMaxNum(string iCustCode,string iInoutno)
  19. {
  20. custcode = iCustCode;
  21. inoutno = iInoutno;
  22. InitializeComponent();
  23. }
  24. //前缀
  25. string Prefix = "";
  26. //后缀
  27. string Suffix = "";
  28. //编码规则编号
  29. string NrCode = "";
  30. string PrefixFixed = "";
  31. //流水号的索引
  32. int SerialNumIndex = 0;
  33. //流水长度
  34. int SerialNumLength = 0;
  35. //存放键值对
  36. int Radix = 10;
  37. //客户的流水号
  38. int custserialnum = 0;
  39. private void ReSetMaxNum_Load(object sender, EventArgs e)
  40. {
  41. 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");
  42. //如果没有则取公共规则
  43. if (Nr.Rows.Count == 0)
  44. 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");
  45. //用于过滤参数的正则表达式
  46. if (Nr.Rows.Count > 0)
  47. {
  48. NrCode = Nr.Rows[0]["nr_code"].ToString();
  49. }
  50. Regex match = new Regex("{\\w+}");
  51. //用于存放每一项的明细的数据
  52. string[] NrData = new string[Nr.Rows.Count];
  53. for (int m = 0; m < Nr.Rows.Count; m++)
  54. {
  55. switch (Nr.Rows[m]["nrd_type"].ToString())
  56. {
  57. //常量直接进行拼接
  58. case "常量":
  59. NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
  60. Prefix += NrData[m];
  61. Suffix += NrData[m];
  62. break;
  63. case "SQL":
  64. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  65. DataTable Temp;
  66. //如果不包含参数替换
  67. if (SQL.IndexOf("{") == 0)
  68. {
  69. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  70. }
  71. else
  72. {
  73. //替换参数后重新执行SQL
  74. foreach (Match mch in match.Matches(SQL))
  75. {
  76. SQL = SQL.Replace(mch.Value.Trim(), "'"+ inoutno + "'");
  77. }
  78. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  79. }
  80. if (Temp.Rows.Count > 0)
  81. {
  82. NrData[m] = Temp.Rows[0][0].ToString();
  83. Prefix += NrData[m];
  84. Suffix += NrData[m];
  85. }
  86. else
  87. {
  88. NrData[m] = "";
  89. Prefix += NrData[m];
  90. Suffix += NrData[m];
  91. }
  92. break;
  93. //流水需要通过MaxNumber去取
  94. case "流水":
  95. NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "'").ToString();
  96. Suffix = "";
  97. PrefixFixed = Prefix;
  98. //设置当前流水
  99. custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
  100. SerialNumIndex = m;
  101. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  102. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  109. if (maxnum == "")
  110. {
  111. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + NrCode + "','" + Prefix + "','1')", "insert");
  112. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  113. custserialnum = int.Parse(maxnum);
  114. }//如果流水号不为空则取当前流水
  115. else
  116. {
  117. custserialnum = int.Parse(maxnum);
  118. }
  119. Number.Text = custserialnum.ToString();
  120. }
  121. private void SingleLabelPrint_Click(object sender, EventArgs e)
  122. {
  123. int num = 0;
  124. if (int.TryParse(Number.Text, out num))
  125. {
  126. dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + num + "'", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
  127. MessageBox.Show("流水修改成功");
  128. Close();
  129. }
  130. else
  131. {
  132. MessageBox.Show("请填写正确的数字");
  133. }
  134. }
  135. }
  136. }