Make_UpdateCollectCode.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using UAS_MES.DataOperate;
  11. using UAS_MES.Entity;
  12. using UAS_MES.PublicMethod;
  13. namespace UAS_MES.FunctionCode.Make
  14. {
  15. public partial class Make_UpdateCollectCode : Form
  16. {
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataHelper dh;
  20. DataTable dt;
  21. DataTable info;
  22. int step = 0;
  23. List<CheckBox> list = new List<CheckBox>();//记录勾选的控件
  24. string ms_id = "";
  25. StringBuilder sb ;
  26. string sncode = "";
  27. public Make_UpdateCollectCode()
  28. {
  29. InitializeComponent();
  30. }
  31. private void Make_UpdateCollectCode_Load(object sender, EventArgs e)
  32. {
  33. asc.controllInitializeSize(this);
  34. dt = new DataTable();
  35. OperateResult.AppendText(">>请先勾选需要更新的项,通过采集栏输入SN,更新项具体数据\n", Color.Black);
  36. }
  37. private void Make_UpdateCollectCode_FormClosing(object sender, FormClosingEventArgs e)
  38. {
  39. }
  40. private void Make_UpdateCollectCode_SizeChanged(object sender, EventArgs e)
  41. {
  42. asc.controlAutoSize(this);
  43. }
  44. private void inputValue_KeyDown(object sender, KeyEventArgs e)
  45. {
  46. if (e.KeyCode==Keys.Enter)
  47. {
  48. //输入不能为空
  49. if (inputValue.Text=="")
  50. {
  51. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  52. return;
  53. }
  54. if (step == 0)
  55. {
  56. //判断是否有已勾选的项次
  57. foreach (Control ctl in collects.Controls)
  58. {
  59. if ((ctl as CheckBox).Checked)
  60. {
  61. list.Add((ctl as CheckBox));
  62. }
  63. }
  64. if (list.Count>0)
  65. {
  66. //无勾选的内容
  67. OperateResult.AppendText("<<请先勾选需要更新的信息\n", Color.Red);
  68. return;
  69. }
  70. //判断TSN或者SN是否存在
  71. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode ='" + inputValue.Text + "' or exists (select 1 from makesnrelation where beforesn='" + inputValue.Text + "' and ms_makecode=makecode)").ToString();
  72. sncode = inputValue.Text;
  73. if (ms_id == "")
  74. {
  75. OperateResult.AppendText("<<SN错误,不存在\n", Color.Red, inputValue);
  76. return;
  77. }
  78. //查询序列号状态
  79. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_makecode from makeserial where ms_id='"+ms_id+"'", "select");
  80. //序列号状态码必须是3
  81. if (dt.Rows[0]["ms_status"].ToString()!="3")
  82. {
  83. OperateResult.AppendText("<<序列号必须是待维修状态\n", Color.Red, inputValue);
  84. return;
  85. }
  86. sql.Clear();
  87. sql.Append("select * from (select rownum rn, ms_prodcode,ms_makecode,ms_salecode,");
  88. sql.Append("ms_mac,ms_imei1,ms_bt,ms_netcode,ms_imei2,ms_imei3 from makeserial ");
  89. sql.Append("where ms_firstsn=(select ms_firstsn from makeserial where ms_id='"+ms_id+"')");
  90. sql.Append(" and (nvl(ms_mac,' ')<>' ' or nvl(ms_bt,' ')<>' ' or nvl(ms_imei1,' ')<>' ' ) order by ms_id asc)where rn=1;");
  91. dt = (DataTable)dh.ExecuteSql(sql.GetString(),"select");
  92. //无值则提示没有需要更新的信息
  93. if (dt.Rows.Count == 0)
  94. {
  95. OperateResult.AppendText("<<序列号" + inputValue.Text + "没有需要更新的信息\n", Color.Red, inputValue);
  96. return;
  97. }
  98. else
  99. {
  100. info = (DataTable)dh.ExecuteSql("select psr_type,psr_prefix,psr_length from productsnrule where psr_prodcode='"+dt.Rows[0]["ms_prodcode"].ToString() +"'", "select");
  101. //查询规则显示
  102. collectCodeRules.DataSource = info;
  103. }
  104. step = 1;
  105. OperateResult.AppendText("<<请输入"+((CheckBox)list[0]).Text+"\n", Color.Green, inputValue);
  106. sb = new StringBuilder();
  107. }
  108. else
  109. //采集的关联采集信息
  110. {
  111. //从第一个开始
  112. switch (((CheckBox)list[step-1]).Text)
  113. {
  114. case "MAC/WIFI":
  115. case "BT":
  116. if (dh.CheckExist("makeserial", "ms_" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + " ='" + inputValue.Text + "' and ms_id='" + ms_id + "'"))
  117. {
  118. //如果一样提示用户“MAC 不允许与原来的值一致”,“请采集MAC”;
  119. OperateResult.AppendText("<<" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + "不允许与原来的值一致\n", Color.Red);
  120. }
  121. else
  122. {
  123. //判断是否有合同号MAC范围
  124. if (dh.CheckExist("SaleMacBTRange", "sr_sacode='"+dt.Rows[0]["ms_salecode"].ToString()+"' and sr_type='"+ ((CheckBox)list[step - 1]).Text.Split('/')[0] + "'"))
  125. {
  126. //有范围的情况下看是否在范围内
  127. if (!dh.CheckExist("SaleMacBTRange", "sr_sacode='" + dt.Rows[0]["ms_salecode"].ToString() + "' and sr_type='" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + "' AND '" + inputValue.Text + "' between sr_startcode and sr_endcode"))
  128. {
  129. OperateResult.AppendText("<<" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + ":" + inputValue.Text + "错误,不在合同防呆范围内\n", Color.Red, inputValue);
  130. OperateResult.AppendText(">>请采集" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + "\n", Color.Black);
  131. return;
  132. }
  133. }
  134. //验证长度前缀
  135. if (!checkPrefixAndLength()) {
  136. return;
  137. }
  138. //验证长度前缀通过,验证数据库
  139. if (dh.CheckExist("makeserial", "ms_status in (1,2,3) and nvl(ms_nextmacode,' ')<>' ' and ms_'"+ ((CheckBox)list[step - 1]).Text.Split('/')[0] + "'='"+inputValue.Text+"'"))
  140. {
  141. OperateResult.AppendText("<<" + ((CheckBox)list[step - 1]).Text + ":" + inputValue.Text + "错误,已被使用\n", Color.Red, inputValue);
  142. return;
  143. }
  144. //通过校验
  145. sb.Append("ms_"+((CheckBox)list[step - 1]).Text.Split('/')[0]+" = '"+inputValue.Text+"',");
  146. }
  147. break;
  148. case "网标":
  149. case "IMEI1":
  150. case "IMEI2":
  151. case "IMEI3":
  152. //验证长度前缀
  153. if (!checkPrefixAndLength()) {
  154. return;
  155. }
  156. //验证长度前缀通过,验证数据库
  157. if (dh.CheckExist("makeserial", "ms_status in (1,2,3) and nvl(ms_nextmacode,' ')<>' ' and ms_'" + ((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text + "'='" + inputValue.Text + "'"))
  158. {
  159. OperateResult.AppendText("<<" + ((CheckBox)list[step - 1]).Text + ":" + inputValue.Text + "错误,已被使用\n", Color.Red, inputValue);
  160. return;
  161. }
  162. //通过校验
  163. sb.Append("ms_" + ((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text+" = '"+inputValue.Text+"',");
  164. break;
  165. }
  166. //判断是否是最后一个
  167. if (step == list.Count)
  168. {
  169. //更新数据库
  170. sql.Clear();
  171. sql.Append("update makeserial set ");
  172. sql.Append(sb.ToString().Substring(0,sb.ToString().Length-1));
  173. sql.Append(" where ms_id='"+ms_id+"'");
  174. dh.ExecuteSql(sql.GetString(),"update");
  175. //提示烧录成功
  176. OperateResult.AppendText(">>烧录成功\n", Color.Green);
  177. //记录日志
  178. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, dt.Rows[0]["ms_makecode"].ToString(), User.UserLineCode, User.UserSourceCode, "更新烧录", "转换成功", sncode,"");
  179. step = 0;
  180. //清除规则
  181. dt = null;
  182. //聚焦,提示
  183. inputValue.Focus();
  184. OperateResult.AppendText("<<请采集SN\n", Color.Black);
  185. //清除LIST
  186. list.Clear();
  187. }
  188. else
  189. {
  190. step++;
  191. //请输入下一个
  192. OperateResult.AppendText(">>请采集" + ((CheckBox)list[step-1]).Text.Split('/')[0] + "\n", Color.Black);
  193. }
  194. }
  195. }
  196. }
  197. private bool checkPrefixAndLength()
  198. {
  199. //找到对应的规则
  200. for(int i=0;i<info.Rows.Count;i++)
  201. {
  202. if ((((CheckBox)list[step - 1]).Text.Split('/')[0]=="网标"?"NETCODE": ((CheckBox)list[step - 1]).Text.Split('/')[0])==info.Rows[i]["psr_type"].ToString())
  203. {
  204. //校验长度
  205. if ((info.Rows[i]["psr_length"].ToString() == "" ? true : inputValue.Text.Length != int.Parse(info.Rows[i]["psr_length"].ToString())))
  206. {
  207. OperateResult.AppendText(">>" + info.Rows[i]["psr_type"] + "长度校验不通过,请重新输入\n", Color.Red);
  208. OperateResult.AppendText(">>请重新输入" + info.Rows[i]["psr_type"] + "\n", Color.Black, inputValue);
  209. break;
  210. return false;
  211. }
  212. //校验前缀
  213. //以|符号分割前缀
  214. string[] preFixs = info.Rows[i]["psr_prefix"].ToString().Split('|');
  215. //只要满足其中一个前缀条件即可
  216. bool isfit = false;
  217. for (int j = 0; j < preFixs.Length; j++)
  218. {
  219. if (preFixs[j] == "" ? true : inputValue.Text.StartsWith(preFixs[j]))
  220. {
  221. //满足其中一条即可
  222. isfit = true;
  223. break;
  224. }
  225. }
  226. if (!isfit)
  227. {
  228. OperateResult.AppendText(">>" + info.Rows[i]["psr_type"] + "前缀校验不通过,请重新输入\n", Color.Red);
  229. OperateResult.AppendText(">>请重新输入" + info.Rows[i]["psr_type"] + "\n", Color.Black, inputValue);
  230. break;
  231. return false;
  232. }
  233. break;
  234. return true;
  235. }
  236. }
  237. OperateResult.AppendText(">>无对应规则\n", Color.Red, inputValue);
  238. return false;
  239. }
  240. }
  241. }