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