Make_UpdateCollectCode.cs 18 KB

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