Make_UpdateCollectCode.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicMethod;
  13. namespace UAS_MES_NEW.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. DataTable macRange;
  23. int step = 0;
  24. List<CheckBox> list = new List<CheckBox>();//记录勾选的控件
  25. string ms_id = "";
  26. StringBuilder sb;//存更新makeserial表的数据
  27. StringBuilder toSi;//存储更新sninfo的数据
  28. StringBuilder insertSninfoFields;
  29. StringBuilder insertSninfoValues;
  30. string sncode = "";
  31. StringBuilder oldData;
  32. //记录新数据
  33. StringBuilder newData;
  34. public Make_UpdateCollectCode()
  35. {
  36. InitializeComponent();
  37. }
  38. private void Make_UpdateCollectCode_Load(object sender, EventArgs e)
  39. {
  40. asc.controllInitializeSize(this);
  41. dh = SystemInf.dh;
  42. OperateResult.AppendText(">>请先勾选需要更新的项,通过采集栏输入SN,更新项具体数据\n", Color.Black);
  43. inputValue.Focus();
  44. }
  45. private void Make_UpdateCollectCode_FormClosing(object sender, FormClosingEventArgs e)
  46. {
  47. }
  48. private void Make_UpdateCollectCode_SizeChanged(object sender, EventArgs e)
  49. {
  50. asc.controlAutoSize(this);
  51. }
  52. private void inputValue_KeyDown(object sender, KeyEventArgs e)
  53. {
  54. if (e.KeyCode == Keys.Enter)
  55. {
  56. //输入不能为空
  57. if (inputValue.Text == "")
  58. {
  59. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  60. return;
  61. }
  62. OperateResult.AppendText(">>" + inputValue.Text + "\n", Color.Black);
  63. if (step == 0)
  64. {
  65. //避免第一步出错的时候添加不需要的数据
  66. if (list.Count!=0)
  67. {
  68. list.Clear();
  69. }
  70. //判断是否有已勾选的项次
  71. foreach (Control ctl in collects.Controls)
  72. {
  73. if ((ctl as CheckBox).Checked)
  74. {
  75. list.Add((ctl as CheckBox));
  76. }
  77. }
  78. if (list.Count == 0)
  79. {
  80. //无勾选的内容
  81. OperateResult.AppendText("<<请先勾选需要更新的信息\n", Color.Red, inputValue);
  82. return;
  83. }
  84. //判断TSN或者SN是否存在
  85. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode ='" + inputValue.Text + "'").ToString();
  86. sncode = inputValue.Text;
  87. if (ms_id == "")
  88. {
  89. OperateResult.AppendText("<<SN错误,不存在\n", Color.Red, inputValue);
  90. return;
  91. }
  92. //查询序列号状态
  93. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_makecode from makeserial where ms_id='" + ms_id + "'", "select");
  94. //序列号状态码必须是3
  95. //if (dt.Rows[0]["ms_status"].ToString() != "3")
  96. //{
  97. // OperateResult.AppendText("<<序列号必须是待维修状态\n", Color.Red, inputValue);
  98. // return;
  99. //}
  100. sql.Clear();
  101. sql.Append("select * from (select rownum rn, ms_prodcode,ms_makecode,ms_salecode,");
  102. sql.Append("ms_mac,ms_imei1,ms_bt,ms_netcode,ms_imei2,ms_imei3 from makeserial ");
  103. sql.Append("where ms_firstsn=(select ms_firstsn from makeserial where ms_id='" + ms_id + "')");
  104. sql.Append("order by ms_id asc)where rn=1");
  105. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  106. //无值则提示没有需要更新的信息
  107. if (dt.Rows.Count == 0)
  108. {
  109. OperateResult.AppendText("<<序列号" + inputValue.Text + "没有需要更新的信息\n", Color.Red, inputValue);
  110. return;
  111. }
  112. else
  113. {
  114. info = (DataTable)dh.ExecuteSql("select psr_type,psr_prefix,psr_length from productsnrelation where psr_prodcode='" + dt.Rows[0]["ms_prodcode"].ToString() + "'", "select");
  115. //查询规则显示
  116. collectCodeRules.DataSource = info;
  117. }
  118. step = 1;
  119. OperateResult.AppendText("<<请输入" + ((CheckBox)list[0]).Text + "\n", Color.Green, inputValue);
  120. sb = new StringBuilder();
  121. toSi = new StringBuilder();//初始化以备更新sninfo表
  122. oldData = new StringBuilder();
  123. newData = new StringBuilder();
  124. insertSninfoFields = new StringBuilder();
  125. insertSninfoValues = new StringBuilder();
  126. }
  127. else
  128. //采集的关联采集信息
  129. {
  130. //从第一个开始
  131. switch (((CheckBox)list[step - 1]).Text)
  132. {
  133. case "MAC/WIFI":
  134. case "BT":
  135. if (dh.CheckExist("makeserial", "ms_" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + " ='" + inputValue.Text.Replace(":", "").Replace("-", "") + "' and ms_id='" + ms_id + "'"))
  136. {
  137. //如果一样提示用户“MAC 不允许与原来的值一致”,“请采集MAC”;
  138. OperateResult.AppendText("<<" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + "不允许与原来的值一致\n", Color.Red);
  139. OperateResult.AppendText(">>请采集" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + "\n", Color.Black, inputValue);
  140. return;
  141. }
  142. else
  143. {
  144. //验证长度前缀
  145. if (!checkPrefixAndLength())
  146. {
  147. return;
  148. }
  149. //验证MAC和BT合同合同防呆
  150. if (!LogicHandler.checkMacOrBtRange(ms_id, inputValue.Text.Replace(":", "").Replace("-", ""), ((CheckBox)list[step - 1]).Text.Split('/')[0]))
  151. {
  152. OperateResult.AppendText("<<" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + ":" + inputValue.Text + "错误,不在合同防呆范围内\n", Color.Red, inputValue);
  153. OperateResult.AppendText(">>请采集" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + "\n", Color.Black);
  154. return;
  155. }
  156. //验证长度前缀通过,验证数据库
  157. if (dh.CheckExist("makeserial", "ms_status in (0,1,2,3) and ms_" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + " ='" + inputValue.Text.Replace(":", "").Replace("-", "") + "'"))
  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.Split('/')[0] + " = '" + inputValue.Text.Replace(":", "").Replace("-", "") + "',");
  164. toSi.Append("si_" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + " = '" + inputValue.Text.Replace(":", "").Replace("-", "") + "',");
  165. insertSninfoFields.Append("si_" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + ",");
  166. insertSninfoValues.Append("'"+inputValue.Text.Replace(":", "").Replace("-", "") + "',");
  167. oldData.Append("ms_" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + ":" + dt.Rows[0]["ms_" + ((CheckBox)list[step - 1]).Text.Split('/')[0]].ToString() + ",");
  168. newData.Append("ms_" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + ":" + inputValue.Text.Replace(":", "").Replace("-", "") + ",");
  169. }
  170. break;
  171. case "网标":
  172. case "IMEI1":
  173. case "IMEI2":
  174. case "IMEI3":
  175. //验证长度前缀
  176. if (!checkPrefixAndLength())
  177. {
  178. return;
  179. }
  180. //验证长度前缀通过,验证数据库
  181. if (dh.CheckExist("makeserial", "ms_status in (0,1,2,3) and ms_" + (((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text) + " ='" + inputValue.Text + "' and ms_id <>'"+ms_id+"'"))
  182. {
  183. OperateResult.AppendText("<<" + ((CheckBox)list[step - 1]).Text + ":" + inputValue.Text + "错误,已被使用\n", Color.Red, inputValue);
  184. return;
  185. }
  186. //通过校验
  187. sb.Append("ms_" + (((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text) + " = '" + inputValue.Text + "',");
  188. toSi.Append("si_" + (((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text) + " = '" + inputValue.Text + "',");
  189. insertSninfoFields.Append("si_" + (((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text) + ",");
  190. insertSninfoValues.Append("'"+inputValue.Text+"',");
  191. oldData.Append("ms_" + (((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text) + ":" + dt.Rows[0]["ms_" + (((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text)].ToString() + ",");
  192. newData.Append("ms_" + (((CheckBox)list[step - 1]).Text == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text) + ":" + inputValue.Text + ",");
  193. break;
  194. }
  195. //判断是否是最后一个
  196. if (step == list.Count)
  197. {
  198. //更新数据库
  199. sql.Clear();
  200. sql.Append("update makeserial set ");
  201. sql.Append(sb.ToString().Substring(0, sb.ToString().Length - 1));
  202. sql.Append(" where ms_id='" + ms_id + "'");
  203. dh.ExecuteSql(sql.GetString(), "update");
  204. //提示烧录成功
  205. OperateResult.AppendText(">>烧录成功\n", Color.Green);
  206. //更新sninfo表
  207. insert2Sninfo(sncode);
  208. //记录日志
  209. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, dt.Rows[0]["ms_makecode"].ToString(), User.UserLineCode, User.UserSourceCode, "更新烧录","原:"+oldData.ToString()+",新:" + newData.ToString(), sncode, "");
  210. step = 0;
  211. //清除规则
  212. BaseUtil.CleanDataTableData(info);
  213. //聚焦,提示
  214. inputValue.Focus();
  215. OperateResult.AppendText("<<请采集SN\n", Color.Black, inputValue);
  216. //清除LIST
  217. list.Clear();
  218. }
  219. else
  220. {
  221. step++;
  222. //请输入下一个
  223. OperateResult.AppendText(">>请输入" + ((CheckBox)list[step - 1]).Text.Split('/')[0] + "\n", Color.Green, inputValue);
  224. }
  225. }
  226. }
  227. }
  228. private bool checkPrefixAndLength()
  229. {
  230. //找到对应的规则
  231. for (int i = 0; i < info.Rows.Count; i++)
  232. {
  233. if ((((CheckBox)list[step - 1]).Text.Split('/')[0] == "网标" ? "NETCODE" : ((CheckBox)list[step - 1]).Text.Split('/')[0]) == info.Rows[i]["psr_type"].ToString())
  234. {
  235. //校验长度
  236. if ((info.Rows[i]["psr_length"].ToString() == "0" ? false : inputValue.Text.Length != int.Parse(info.Rows[i]["psr_length"].ToString())))
  237. {
  238. OperateResult.AppendText(">>" + info.Rows[i]["psr_type"] + "长度校验不通过,请重新输入\n", Color.Red);
  239. OperateResult.AppendText(">>请重新输入" + info.Rows[i]["psr_type"] + "\n", Color.Black, inputValue);
  240. return false;
  241. }
  242. //校验前缀
  243. //以|符号分割前缀
  244. string[] preFixs = info.Rows[i]["psr_prefix"].ToString().Split('|');
  245. //只要满足其中一个前缀条件即可
  246. bool isfit = false;
  247. for (int j = 0; j < preFixs.Length; j++)
  248. {
  249. if (preFixs[j] == "" ? true : inputValue.Text.StartsWith(preFixs[j]))
  250. {
  251. //满足其中一条即可
  252. isfit = true;
  253. break;
  254. }
  255. }
  256. if (!isfit)
  257. {
  258. OperateResult.AppendText(">>" + info.Rows[i]["psr_type"] + "前缀校验不通过,请重新输入\n", Color.Red);
  259. OperateResult.AppendText(">>请重新输入" + info.Rows[i]["psr_type"] + "\n", Color.Black, inputValue);
  260. return false;
  261. }
  262. return true;
  263. }
  264. }
  265. return true;
  266. }
  267. private void Mac_CheckedChanged(object sender, EventArgs e)
  268. {
  269. //当有checkBox状态改变的时候
  270. if (step != 0)
  271. {
  272. //步骤码归零
  273. step = 0;
  274. //清除list,信息栏
  275. list.Clear();
  276. BaseUtil.CleanDataTableData(info);
  277. //聚焦,提示
  278. inputValue.Focus();
  279. OperateResult.AppendText(">>请采集SN\n", Color.Black);
  280. }
  281. }
  282. private void insert2Sninfo(string sn)
  283. {
  284. //查询是否有记录
  285. string siid = dh.getFieldDataByCondition("sninfo", "max(si_id) si_id", "si_sn='"+sn+"'").ToString();
  286. //是否为空
  287. if (siid == "")
  288. {
  289. //插入新的数据
  290. sql.Clear();
  291. sql.Append("insert into sninfo(si_id,si_sn,"+ insertSninfoFields.ToString().Substring(0, insertSninfoFields.ToString().Length - 1) + ") values ");
  292. sql.Append("(sninfo_seq.nextval,'"+sn+"',"+ insertSninfoValues.ToString().Substring(0, insertSninfoValues.ToString().Length - 1) + ")");
  293. dh.ExecuteSql(sql.GetString(),"insert");
  294. }
  295. else
  296. {
  297. //更新sninfo
  298. sql.Clear();
  299. sql.Append("update sninfo set ");
  300. sql.Append(toSi.ToString().Substring(0, toSi.ToString().Length - 1));
  301. sql.Append(" where si_id='" + siid + "'");
  302. dh.ExecuteSql(sql.GetString(), "update");
  303. }
  304. }
  305. }
  306. }