Program.cs 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  1. using Oracle.ManagedDataAccess.Client;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Text;
  7. namespace upload
  8. {
  9. class Program
  10. {
  11. //定义连接字符串
  12. //static string connString = "Server=192.168.83.231;DataBase=GW_DAS;Uid=oa3;Pwd=789123-gw";
  13. //static string connString = "server=192.168.11.253;database=gw_das;uid=oa3;pwd=789123-gw";
  14. //用于拼接SQL
  15. StringBuilder sql = new StringBuilder();
  16. //用于存放批量执行的SQL
  17. List<string> sqls = new List<string>();
  18. //系统默认的的连接字符串
  19. //static string ConnectionStrings = "Password=select!#%*(;User ID=LIANT;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=usoftchina.7766.org)(PORT=11644)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  20. static string ConnectionStrings = "Password=select!#%*(;User ID=LIANT;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.83.235)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  21. //static string ConnectionStrings = "Password=select!#%*(;User ID=LIANT;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.11.201)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  22. //用户选择的数据库的连接字符串
  23. static OracleConnection connection;
  24. //用户选择的数据库的连接字符串
  25. static OracleCommand command = null;
  26. static void Main(string[] args)
  27. {
  28. //int res = Chk_key("2GWTC116-2BK1Y21H000000");
  29. //Console.WriteLine(res);
  30. //string tests = "00";
  31. //if (string.IsNullOrWhiteSpace(tests))
  32. //{
  33. // Console.WriteLine("fail");
  34. //}
  35. //Console.ReadLine();
  36. if (args.Length < 2) {
  37. Console.WriteLine("please input parameter run!");
  38. System.Environment.Exit(1);
  39. }
  40. switch (args[0])
  41. {
  42. case "Chk_Station":
  43. Chk_parameter(3, args);
  44. System.Environment.Exit(Chk_Station(args[1],args[2]));
  45. break;
  46. case "Update_station":
  47. Chk_parameter(3, args);
  48. System.Environment.Exit(Update_station(args[1], args[2]));
  49. break;
  50. case "Chk_key":
  51. Chk_parameter(2, args);
  52. System.Environment.Exit(Chk_key(args[1]));
  53. break;
  54. case "Upload_key":
  55. Chk_parameter(6, args);
  56. System.Environment.Exit(Upload_key(args[1], args[2], args[3], args[4], args[5]));
  57. break;
  58. case "Upload_offlinekey":
  59. Chk_parameter(3, args);
  60. System.Environment.Exit(Upload_offlinekey(args[1], args[2]));
  61. break;
  62. case "Upload_cbr":
  63. Chk_parameter(5, args);
  64. System.Environment.Exit(Upload_cbr(args[1], args[2], args[3], args[4]));
  65. break;
  66. case "Upload_part":
  67. //Chk_parameter(7, args);
  68. if (args.Length == 7)
  69. System.Environment.Exit(Upload_part(args[1], args[2], args[3], args[4], args[5], args[6]));
  70. else
  71. System.Environment.Exit(Upload_part(args[1], args[2], args[3], args[4], args[5], args[6], args[7]));
  72. break;
  73. case "Upload_mdos":
  74. //Chk_parameter(7, args);
  75. if(args.Length==9)
  76. System.Environment.Exit(Upload_mdos(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]));
  77. else
  78. System.Environment.Exit(Upload_mdos(args[1], args[2], args[3], args[4], args[5], args[6], args[7]));
  79. break;
  80. case "Upload_pack":
  81. Chk_parameter(3, args);
  82. System.Environment.Exit(Upload_pack(args[1], args[2]));
  83. break;
  84. case "Get_SN":
  85. Chk_parameter(3, args);
  86. System.Environment.Exit(Get_SN(args[1], args[2]));
  87. break;
  88. case "Get_Hash":
  89. Chk_parameter(2, args);
  90. System.Environment.Exit(Get_Hash(args[1]));
  91. break;
  92. case "Upload_IMEI":
  93. Chk_parameter(3, args);
  94. System.Environment.Exit(Upload_IMEI(args[1], args[2]));
  95. break;
  96. case "Upload_Bs":
  97. Chk_parameter(3, args);
  98. System.Environment.Exit(Upload_Bs(args[1], args[2]));
  99. break;
  100. case "Get_Mes":
  101. Chk_parameter(2, args);
  102. System.Environment.Exit(Get_Mes(args[1]));
  103. break;
  104. case "Get_Key":
  105. Chk_parameter(2, args);
  106. System.Environment.Exit(Get_Key(args[1]));
  107. break;
  108. //case "Upload_par":
  109. // Chk_parameter(4, args);
  110. // System.Environment.Exit(Upload_par(args[1], args[2], args[3]));
  111. // break;
  112. default:
  113. Console.WriteLine("please input parameter run!");
  114. System.Environment.Exit(1);
  115. break;
  116. }
  117. //Console.ReadLine();
  118. }
  119. // 检查工站 返回0 是正确的
  120. public static void Chk_parameter(int loop ,string[] para) {
  121. //Console.WriteLine("aa");
  122. //if (para.Length < loop)
  123. //{
  124. // Console.WriteLine("please input parameter run, less");
  125. // System.Environment.Exit(1);
  126. //}
  127. //for (int i = 0; i < loop; i++)
  128. //{
  129. // if (string.IsNullOrWhiteSpace(para[i]))
  130. // {
  131. // Console.WriteLine("please input parameter run, null");
  132. // System.Environment.Exit(1);
  133. // }
  134. //}
  135. return;
  136. }
  137. public static int Chk_Station(string field, string ssn) {
  138. //int ret_code = 1;
  139. ////创建连接对象
  140. //SqlConnection conn = new SqlConnection(connString);
  141. ////string ssn = "2GWTC116-2BK1Y21H000000";
  142. //string sql = "select ["+field+"] from notebook_info where ssn='"+ssn+"'";
  143. //SqlCommand cmd = new SqlCommand(sql, conn);
  144. ////打开连接
  145. //conn.Open();
  146. ////执行查询方法,返回DataReader对象
  147. //SqlDataReader objRader = cmd.ExecuteReader();
  148. ////bool tmp_value = objRader.Read();
  149. ////if (tmp_value == true)
  150. ////{
  151. //// ret_code = 0;
  152. ////}
  153. //string res_tmp = "0";
  154. ////读取数据
  155. //while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
  156. //{
  157. // res_tmp = objRader[field].ToString();
  158. //}
  159. ////关闭读取器
  160. //objRader.Close();
  161. //conn.Close();
  162. //if (res_tmp.Equals("1")) {
  163. // ret_code = 0;
  164. //}
  165. //return ret_code;
  166. connection = new OracleConnection(ConnectionStrings);
  167. connection.Open();
  168. string oErrMessage;
  169. if (ssn == "")
  170. {
  171. oErrMessage = "SN不能为空";
  172. Console.WriteLine(oErrMessage);
  173. return 1;
  174. }
  175. oErrMessage = "";
  176. string[] param = new string[] { "", field, ssn, "", "", "", oErrMessage };
  177. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
  178. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  179. oErrMessage = param[6];
  180. DataTable dt = (DataTable)ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=( select max(ms_id) from makeserial where ms_sncode in ( select '" + ssn + "' from dual union select sn from makesnrelation where beforesn='" + ssn + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + ssn + "' and beforesn<>' '))", "select");
  181. string ms_status = "";
  182. string ms_stepcode = "";
  183. string ms_nextstepcode = "";
  184. if (dt.Rows.Count > 0)
  185. {
  186. ms_status = dt.Rows[0]["ms_status"].ToString();
  187. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  188. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  189. }
  190. string stepcode = GetStepCodeBySource(field);
  191. connection.Close();
  192. if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
  193. {
  194. oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
  195. Console.WriteLine(oErrMessage);
  196. return 1;
  197. }
  198. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" )
  199. {
  200. return 0;
  201. }
  202. else
  203. {
  204. Console.WriteLine(oErrMessage);
  205. return 1;
  206. }
  207. }
  208. // 更新工站 返回0 是过站成功
  209. public static int Update_station(string ssn, string stations)
  210. {
  211. connection = new OracleConnection(ConnectionStrings);
  212. connection.Open();
  213. //SqlConnection conn = new SqlConnection(connString);
  214. //conn.Open();
  215. //string sql = "update [notebook_info] set "+ stations + "='1' where ssn='" + ssn + "'";
  216. //SqlCommand command = new SqlCommand(sql, conn);
  217. //int num = 0;
  218. //num = command.ExecuteNonQuery();
  219. //conn.Close();
  220. //if (num == 1)
  221. //{
  222. // ret_code = 0;
  223. //}
  224. string oErrMessage = "";
  225. if (ssn == "")
  226. {
  227. oErrMessage = "SN不能为空";
  228. Console.WriteLine(oErrMessage);
  229. connection.Close();
  230. return 1;
  231. }
  232. oErrMessage = "";
  233. string oMakeCode = "";
  234. GetRcardMOInfo(ssn, out oMakeCode, out oErrMessage);
  235. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  236. {
  237. if(!SetStepFinish(oMakeCode, stations, ssn, "测试工具测试", "OK", "ZZCS", "", out oErrMessage))
  238. {
  239. Console.WriteLine(oErrMessage);
  240. connection.Close();
  241. return 1;
  242. }
  243. }
  244. else
  245. {
  246. Console.WriteLine(oErrMessage);
  247. connection.Close();
  248. return 1;
  249. }
  250. connection.Close();
  251. return 0;
  252. }
  253. // 检查key 返回0 证明不存在
  254. public static int Chk_key(string ssn)
  255. {
  256. int ret_code = 1;
  257. ////创建连接对象
  258. //SqlConnection conn = new SqlConnection(connString);
  259. ////string ssn = "2GWTC116-2BK1Y21H000000";
  260. //string sql = "select [SerialNumber] from OAkeyinfo where SerialNumber='" + ssn + "'";
  261. //string sqlfom = "select [StateID] from FactoryData where SN='" + ssn + "'";
  262. //SqlCommand cmd = new SqlCommand(sql, conn);
  263. ////打开连接
  264. //conn.Open();
  265. ////执行查询方法,返回DataReader对象
  266. //SqlDataReader objRader = cmd.ExecuteReader();
  267. //int oakey = 1;
  268. //int fomkey = 1;
  269. //bool tmp_value = true;
  270. //string res_tmp = "100";
  271. ////读取数据
  272. //tmp_value =objRader.Read();
  273. //if (tmp_value == false) {
  274. // oakey = 0;
  275. // }
  276. //objRader.Close();
  277. //conn.Close();
  278. //SqlCommand cmdfom = new SqlCommand(sqlfom, conn);
  279. //conn.Open();
  280. //SqlDataReader objfom = cmdfom.ExecuteReader();
  281. //while (objfom.Read()) {
  282. // res_tmp = objfom["StateID"].ToString();
  283. //}
  284. ////Console.WriteLine(res_tmp);
  285. //if (res_tmp.Equals("1") || res_tmp.Equals("100"))
  286. //{
  287. // fomkey = 0;
  288. //}
  289. //if (oakey == 0 && fomkey ==0)
  290. //{
  291. // ret_code = 0;
  292. //}
  293. //objfom.Close();
  294. //conn.Close();
  295. connection = new OracleConnection(ConnectionStrings);
  296. connection.Open();
  297. if (!CheckExist("makeserial", "ms_sncode = '" + ssn + "' and ms_key is not null"))
  298. ret_code = 0;
  299. connection.Close();
  300. return ret_code;
  301. }
  302. // 检查keyid 是否一致 返回 0 pass
  303. public static int Chk_keyid(string ssn, string keyid)
  304. {
  305. int ret_code = 1;
  306. //创建连接对象
  307. //SqlConnection conn = new SqlConnection(connString);
  308. ////string ssn = "2GWTC116-2BK1Y21H000000";
  309. //string sql = "select [ProductKeyID] from OAkeyinfo where SerialNumber='" + ssn + "'";
  310. //SqlCommand cmd = new SqlCommand(sql, conn);
  311. ////打开连接
  312. //conn.Open();
  313. ////执行查询方法,返回DataReader对象
  314. //SqlDataReader objRader = cmd.ExecuteReader();
  315. ////读取数据
  316. //string res_tmp = "0";
  317. ////读取数据
  318. //while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
  319. //{
  320. // res_tmp = objRader["ProductKeyID"].ToString();
  321. //}
  322. //if (res_tmp.Equals(keyid)) {
  323. // ret_code = 0;
  324. //}
  325. //objRader.Close();
  326. //conn.Close();
  327. connection = new OracleConnection(ConnectionStrings);
  328. connection.Open();
  329. if (CheckExist("makeserial", "ms_sncode = '" + ssn + "' and ms_keyid ='"+keyid+"'"))
  330. ret_code = 0;
  331. connection.Close();
  332. return ret_code;
  333. }
  334. public static int Chk_keyid(string keyid) {
  335. int ret_code = 1;
  336. ////创建连接对象
  337. //SqlConnection conn = new SqlConnection(connString);
  338. ////string ssn = "2GWTC116-2BK1Y21H000000";
  339. //string sql = "select [ProductKeyID] from OAkeyinfo where ProductKeyID='" + keyid + "'";
  340. //SqlCommand cmd = new SqlCommand(sql, conn);
  341. ////打开连接
  342. //conn.Open();
  343. ////执行查询方法,返回DataReader对象
  344. //SqlDataReader objRader = cmd.ExecuteReader();
  345. //bool tmp_value = true;
  346. ////读取数据
  347. //tmp_value = objRader.Read();
  348. //if (tmp_value == false)
  349. //{
  350. // ret_code = 0;
  351. //}
  352. //objRader.Close();
  353. //conn.Close();
  354. connection = new OracleConnection(ConnectionStrings);
  355. connection.Open();
  356. if (!CheckExist("makeserial", " ms_keyid ='" + keyid + "'"))
  357. ret_code = 0;
  358. connection.Close();
  359. return ret_code;
  360. }
  361. public static int Chk_uuid(string uuid)
  362. {
  363. int ret_code = 1;
  364. //connection = new OracleConnection(ConnectionStrings);
  365. //connection.Open();
  366. //if (uuid == "" || uuid == null)
  367. //{
  368. // ret_code = 2;
  369. //}
  370. //else if (CheckExist("makeserial", " ms_uuid ='" + uuid + "'"))
  371. //{
  372. // ret_code = 3;
  373. //}
  374. //connection.Close();
  375. return ret_code;
  376. }
  377. // 上传key 返回0 pass
  378. public static int Upload_key(string ssn, string dpk, string keyid, string stateid, string partnumber)
  379. {
  380. int res_code = 1;
  381. int res_keyid = Chk_keyid(keyid);
  382. if (res_keyid == 0)
  383. {
  384. int res_key = Chk_key(ssn);
  385. if (res_key == 0) {
  386. //SqlConnection conn = new SqlConnection(connString);
  387. //conn.Open();
  388. ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
  389. //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate)
  390. //string sql = "insert into OAkeyinfo(SerialNumber, ProductKey, ProductKeyID, ProductKeyStateID, ProductKeyPartNumber) values ('" + ssn+"','"+ dpk + "','"+keyid+"',"+stateid+ ",'" + partnumber + "')";
  391. //SqlCommand command = new SqlCommand(sql, conn);
  392. //int num = 0;
  393. //num = command.ExecuteNonQuery();
  394. //if (num == 1) {
  395. // res_code = 0;
  396. //}
  397. //conn.Close();
  398. connection = new OracleConnection(ConnectionStrings);
  399. connection.Open();
  400. ExecuteSql("update makeserial set ms_key = '"+dpk+"',ms_keyid = '"+keyid+ "',MS_KEYSTATEID ='"+stateid+ "',MS_KEYPARTNUMBER ='"+partnumber+"' where ms_sncode = '" + ssn + "' ","update");
  401. ExecuteSql(" insert into KEYLOG(KL_ID,KL_SN,KL_KEY,KL_INDATE) values(KEYLOG_SEQ.NEXTVAL,'"+ ssn + "','"+ dpk + "',sysdate) ", "insert");
  402. res_code = 0;
  403. connection.Close();
  404. }
  405. }
  406. else
  407. {
  408. Console.WriteLine("key is exist db");
  409. }
  410. return res_code;
  411. }
  412. // 上传key 返回0 pass
  413. public static int Upload_offlinekey(string ssn, string dpk)
  414. {
  415. //SqlConnection conn = new SqlConnection(connString);
  416. //conn.Open();
  417. ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
  418. //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate)
  419. //string sql = "insert into OAkeyinfo(SerialNumber, ProductKey, ProductKeyID, ProductKeyStateID, ProductKeyPartNumber) values ('" + ssn+"','"+ dpk + "','"+keyid+"',"+stateid+ ",'" + partnumber + "')";
  420. //SqlCommand command = new SqlCommand(sql, conn);
  421. //int num = 0;
  422. //num = command.ExecuteNonQuery();
  423. //if (num == 1) {
  424. // res_code = 0;
  425. //}
  426. //conn.Close();
  427. connection = new OracleConnection(ConnectionStrings);
  428. connection.Open();
  429. ExecuteSql("update makeserial set ms_key = '" + dpk + "' where ms_sncode = '" + ssn + "' ", "update");
  430. ExecuteSql(" insert into KEYLOG(KL_ID,KL_SN,KL_KEY,KL_INDATE) values(KEYLOG_SEQ.NEXTVAL,'" + ssn + "','" + dpk + "',sysdate) ", "insert");
  431. connection.Close();
  432. return 0;
  433. }
  434. // 上传 cbr 返回 0 pass
  435. public static int Upload_cbr(string ssn, string hardwreid, string stateid, string keyid)
  436. {
  437. int res_code = 1;
  438. int res_key = Chk_keyid(ssn, keyid);
  439. if (res_key == 0)
  440. {
  441. //SqlConnection conn = new SqlConnection(connString);
  442. //conn.Open();
  443. ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
  444. //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate) HardwreID
  445. //string sql = "update OAkeyinfo set HardwreID='"+ hardwreid + "',ProductKeyStateID="+ stateid + " where ProductKeyID='" + keyid + "'";
  446. //SqlCommand command = new SqlCommand(sql, conn);
  447. ////int num = 0;
  448. //int num = command.ExecuteNonQuery();
  449. ////Console.WriteLine(num);
  450. //if (num == 1 || num == 2)
  451. //{
  452. // res_code = 0;
  453. //}
  454. //conn.Close();
  455. connection = new OracleConnection(ConnectionStrings);
  456. connection.Open();
  457. ExecuteSql("update makeserial set MS_HARDWREID = '" + hardwreid + "',ms_keyid = '" + keyid + "',MS_KEYSTATEID ='" + stateid + "' where ms_sncode = '" + ssn + "' ", "update");
  458. res_code = 0;
  459. connection.Close();
  460. }
  461. return res_code;
  462. }
  463. // 返回 0 证明上传 包装数据pass
  464. public static int Upload_part(string ssn, string bt, string wifi, string bios, string ec, string uuid)
  465. {
  466. int res_code = 1;
  467. connection = new OracleConnection(ConnectionStrings);
  468. connection.Open();
  469. int res_uuid = Chk_uuid(uuid);
  470. if (res_uuid == 1)
  471. {
  472. if (bt.Length != 12)
  473. {
  474. Console.WriteLine("bt." + bt + ".bt length is"+bt.Length);
  475. connection.Close();
  476. return res_code;
  477. }
  478. if (wifi.Length != 12)
  479. {
  480. Console.WriteLine("wifi." + wifi + ".wifi length is"+wifi.Length);
  481. connection.Close();
  482. return res_code;
  483. }
  484. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
  485. {
  486. Console.WriteLine("bt." + bt + ".bt exist db");
  487. connection.Close();
  488. return res_code;
  489. }
  490. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
  491. {
  492. Console.WriteLine("wifi." + wifi + ".wifi exist db");
  493. connection.Close();
  494. return res_code;
  495. }
  496. if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
  497. {
  498. ExecuteSql("update makeserial set ms_bt = '" + bt + "',ms_mac = '" + wifi + "',MS_BIOS ='" + bios + "' ,MS_EC ='" + ec + "' ,MS_UUID ='" + uuid + "' where ms_sncode = '" + ssn + "' ", "update");
  499. res_code = 0;
  500. }
  501. }
  502. else
  503. {
  504. Console.WriteLine(uuid+"."+ res_uuid + ".uuid is null or exist db");
  505. }
  506. connection.Close();
  507. return res_code;
  508. }
  509. public static int Upload_part(string ssn, string bt, string wifi, string bios, string ec, string uuid,string lan)
  510. {
  511. int res_code = 1;
  512. connection = new OracleConnection(ConnectionStrings);
  513. connection.Open();
  514. int res_uuid = Chk_uuid(uuid);
  515. if (res_uuid == 1)
  516. {
  517. if (bt.Length != 12)
  518. {
  519. Console.WriteLine("bt." + bt + ".bt length is" + bt.Length);
  520. connection.Close();
  521. return res_code;
  522. }
  523. if (wifi.Length != 12)
  524. {
  525. Console.WriteLine("wifi." + wifi + ".wifi length is" + wifi.Length);
  526. connection.Close();
  527. return res_code;
  528. }
  529. if (lan.Length != 12)
  530. {
  531. Console.WriteLine("lan." + lan + ".lan length is" + lan.Length);
  532. connection.Close();
  533. return res_code;
  534. }
  535. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
  536. {
  537. Console.WriteLine("bt." + bt + ".bt exist db");
  538. connection.Close();
  539. return res_code;
  540. }
  541. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
  542. {
  543. Console.WriteLine("wifi." + wifi + ".wifi exist db");
  544. connection.Close();
  545. return res_code;
  546. }
  547. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_lan = '" + lan + "' and ms_lan is not null"))
  548. {
  549. Console.WriteLine("lan." + lan + ".lan exist db");
  550. connection.Close();
  551. return res_code;
  552. }
  553. if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
  554. {
  555. ExecuteSql("update makeserial set ms_bt = '" + bt + "',ms_mac = '" + wifi + "',MS_BIOS ='" + bios + "' ,MS_EC ='" + ec + "' ,MS_UUID ='" + uuid + "',ms_lan = '"+lan+"' where ms_sncode = '" + ssn + "' ", "update");
  556. res_code = 0;
  557. }
  558. }
  559. else
  560. {
  561. Console.WriteLine(uuid + "." + res_uuid + ".uuid is null or exist db");
  562. }
  563. connection.Close();
  564. return res_code;
  565. }
  566. // 返回 0 可以包装
  567. public static int Upload_pack(string ssn, string keyid)
  568. {
  569. int res_code = 1;
  570. //int res_key = Chk_keyid(ssn, keyid);
  571. //if (res_key == 0)
  572. //{
  573. // SqlConnection conn = new SqlConnection(connString);
  574. // conn.Open();
  575. // string selects = "select [orderid] from notebook_info where ssn='" + ssn + "'";
  576. // SqlCommand cmd = new SqlCommand(selects, conn);
  577. // //执行查询方法,返回DataReader对象
  578. // SqlDataReader objRader = cmd.ExecuteReader();
  579. // //bool tmp_value = objRader.Read();
  580. // //if (tmp_value == true)
  581. // //{
  582. // // ret_code = 0;
  583. // //}
  584. // int res_tmp = 0;
  585. // //读取数据
  586. // while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
  587. // {
  588. // res_tmp = objRader.GetInt32(objRader.GetOrdinal("orderid"));
  589. // //res_tmp = objRader["orderid"]
  590. // }
  591. // objRader.Close();
  592. // conn.Close();
  593. // conn.Open();
  594. // if (res_tmp != 0)
  595. // {
  596. // string updatesql = "update FactoryData set OrderID=" + res_tmp + " where SN='" + ssn + "'";
  597. // SqlCommand command = new SqlCommand(updatesql, conn);
  598. // int num = 0;
  599. // num = command.ExecuteNonQuery();
  600. // if (num == 1)
  601. // {
  602. // res_code = 0;
  603. // }
  604. // }
  605. // conn.Close();
  606. //}
  607. return 0;
  608. }
  609. // field 返回SN
  610. public static int Get_SN(string field, string code)
  611. {
  612. int ret_code = 1;
  613. ////创建连接对象
  614. //SqlConnection conn = new SqlConnection(connString);
  615. ////string ssn = "2GWTC116-2BK1Y21H000000";
  616. //string sql = "select [ssn] from notebook_info where "+field+"='" + code + "'";
  617. //SqlCommand cmd = new SqlCommand(sql, conn);
  618. ////打开连接
  619. //conn.Open();
  620. ////执行查询方法,返回DataReader对象
  621. //SqlDataReader objRader = cmd.ExecuteReader();
  622. ////bool tmp_value = objRader.Read();
  623. ////if (tmp_value == true)
  624. ////{
  625. //// ret_code = 0;
  626. ////}
  627. //string res_tmp = "0";
  628. ////读取数据
  629. ////Console.WriteLine(objRader.Read());
  630. //while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
  631. //{
  632. // Console.WriteLine("SET SSN="+objRader["ssn"].ToString());
  633. // res_tmp = "1";
  634. //}
  635. ////关闭读取器
  636. //objRader.Close();
  637. //conn.Close();
  638. //if (res_tmp.Equals("1"))
  639. //{
  640. // ret_code = 0;
  641. //}
  642. //return ret_code;
  643. connection = new OracleConnection(ConnectionStrings);
  644. connection.Open();
  645. string res_tmp = "0";
  646. if (CheckExist("craftmaterial","cm_barcode = '"+ code + "' and cm_status = 0"))//objRader.Read() 如果返回true就说明结果里面有数据
  647. {
  648. string sn = getFieldDataByCondition("craftmaterial", "cm_sncode", "cm_barcode = '" + code + "' and cm_status = 0").ToString();
  649. Console.WriteLine("SET SSN=" + sn);
  650. res_tmp = "1";
  651. }
  652. if (res_tmp.Equals("1"))
  653. {
  654. ret_code = 0;
  655. }
  656. connection.Close();
  657. return ret_code;
  658. }
  659. public static int Upload_mdos(string ssn, string bt, string wifi, string bios, string ec, string uuid, string disksn)
  660. {
  661. int res_code = 1;
  662. //SqlConnection conn = new SqlConnection(connString);
  663. //conn.Open();
  664. ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
  665. //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate) HardwreID
  666. //// string sql = "select ["+field+"] from notebook_info where ssn='"+ssn+"'";
  667. //string checksql = "select [StateID] from FactoryData where SN='" + ssn + "'";
  668. //string insertsql = "insert into FactoryData(SN, WIFI, BT, BIOS, EC, UUID, IMEI1, BS, StateID) values('" + ssn + "', '" + wifi + "', '" + bt + "', '" + bios + "','" + ec + "','" + uuid + "','" + imei + "','" + disksn + "',10)";
  669. //string updatesql = "update FactoryData set WIFI='" + wifi + "',BT='" + bt + "',BIOS='" + bios + "',EC='" + ec + "',UUID='" + uuid + "',IMEI1='"+ imei + "',BS='"+ disksn + "',StateID=10 where SN='" + ssn + "'";
  670. //SqlCommand chkcmd = new SqlCommand(checksql, conn);
  671. //SqlDataReader objRader = chkcmd.ExecuteReader();
  672. //int chk_res = 0;
  673. //bool check_data = objRader.Read();
  674. //if (check_data == true)
  675. //{
  676. // chk_res = 1;
  677. // string StateID = "0";
  678. // while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
  679. // {
  680. // StateID = objRader["StateID"].ToString();
  681. // }
  682. // if (StateID.Equals("60"))
  683. // {
  684. // chk_res = 2;
  685. // // 返回2 不能更新
  686. // }
  687. // objRader.Close();
  688. //}
  689. //conn.Close();
  690. //int sql_res = 0;
  691. //// 0 inser 1 update
  692. //conn.Open();
  693. //switch (chk_res)
  694. //{
  695. // case 0:
  696. // SqlCommand inertcmd = new SqlCommand(insertsql, conn);
  697. // sql_res = inertcmd.ExecuteNonQuery();
  698. // break;
  699. // case 1:
  700. // SqlCommand updatecmd = new SqlCommand(updatesql, conn);
  701. // sql_res = updatecmd.ExecuteNonQuery();
  702. // break;
  703. // default:
  704. // break;
  705. //}
  706. //if (sql_res == 1)
  707. //{
  708. // res_code = 0;
  709. //}
  710. ////SqlCommand command = new SqlCommand(checksql, conn);
  711. ////int num = 0;
  712. ////num = command.ExecuteNonQuery();
  713. ////if (num == 1)
  714. ////{
  715. //// res_code = 0;
  716. ////}
  717. //conn.Close();
  718. connection = new OracleConnection(ConnectionStrings);
  719. connection.Open();
  720. int res_uuid = Chk_uuid(uuid);
  721. if (res_uuid == 1)
  722. {
  723. if (bt.Length != 12)
  724. {
  725. Console.WriteLine("bt." + bt + ".bt length is" + bt.Length);
  726. connection.Close();
  727. return res_code;
  728. }
  729. if (wifi.Length != 12)
  730. {
  731. Console.WriteLine("wifi." + wifi + ".wifi length is" + wifi.Length);
  732. connection.Close();
  733. return res_code;
  734. }
  735. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
  736. {
  737. Console.WriteLine("bt." + bt + ".bt exist db");
  738. connection.Close();
  739. return res_code;
  740. }
  741. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
  742. {
  743. Console.WriteLine("wifi." + wifi + ".wifi exist db");
  744. connection.Close();
  745. return res_code;
  746. }
  747. if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
  748. {
  749. ExecuteSql("update makeserial set ms_bt = '" + bt + "',ms_mac = '" + wifi + "',MS_BIOS ='" + bios + "' ,MS_EC ='" + ec + "' ,MS_UUID ='" + uuid + "',MS_BS ='" + disksn + "' where ms_sncode = '" + ssn + "' ", "update");
  750. res_code = 0;
  751. }
  752. }
  753. else
  754. {
  755. Console.WriteLine(uuid + "." + res_uuid + ".uuid is null or exist db");
  756. }
  757. connection.Close();
  758. return res_code;
  759. }
  760. public static int Upload_mdos(string ssn, string bt, string wifi, string bios, string ec, string uuid, string imei, string disksn)
  761. {
  762. int res_code = 1;
  763. //SqlConnection conn = new SqlConnection(connString);
  764. //conn.Open();
  765. ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
  766. //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate) HardwreID
  767. //// string sql = "select ["+field+"] from notebook_info where ssn='"+ssn+"'";
  768. //string checksql = "select [StateID] from FactoryData where SN='" + ssn + "'";
  769. //string insertsql = "insert into FactoryData(SN, WIFI, BT, BIOS, EC, UUID, IMEI1, BS, StateID) values('" + ssn + "', '" + wifi + "', '" + bt + "', '" + bios + "','" + ec + "','" + uuid + "','" + imei + "','" + disksn + "',10)";
  770. //string updatesql = "update FactoryData set WIFI='" + wifi + "',BT='" + bt + "',BIOS='" + bios + "',EC='" + ec + "',UUID='" + uuid + "',IMEI1='"+ imei + "',BS='"+ disksn + "',StateID=10 where SN='" + ssn + "'";
  771. //SqlCommand chkcmd = new SqlCommand(checksql, conn);
  772. //SqlDataReader objRader = chkcmd.ExecuteReader();
  773. //int chk_res = 0;
  774. //bool check_data = objRader.Read();
  775. //if (check_data == true)
  776. //{
  777. // chk_res = 1;
  778. // string StateID = "0";
  779. // while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
  780. // {
  781. // StateID = objRader["StateID"].ToString();
  782. // }
  783. // if (StateID.Equals("60"))
  784. // {
  785. // chk_res = 2;
  786. // // 返回2 不能更新
  787. // }
  788. // objRader.Close();
  789. //}
  790. //conn.Close();
  791. //int sql_res = 0;
  792. //// 0 inser 1 update
  793. //conn.Open();
  794. //switch (chk_res)
  795. //{
  796. // case 0:
  797. // SqlCommand inertcmd = new SqlCommand(insertsql, conn);
  798. // sql_res = inertcmd.ExecuteNonQuery();
  799. // break;
  800. // case 1:
  801. // SqlCommand updatecmd = new SqlCommand(updatesql, conn);
  802. // sql_res = updatecmd.ExecuteNonQuery();
  803. // break;
  804. // default:
  805. // break;
  806. //}
  807. //if (sql_res == 1)
  808. //{
  809. // res_code = 0;
  810. //}
  811. ////SqlCommand command = new SqlCommand(checksql, conn);
  812. ////int num = 0;
  813. ////num = command.ExecuteNonQuery();
  814. ////if (num == 1)
  815. ////{
  816. //// res_code = 0;
  817. ////}
  818. //conn.Close();
  819. connection = new OracleConnection(ConnectionStrings);
  820. connection.Open();
  821. int res_uuid = Chk_uuid(uuid);
  822. if (res_uuid == 1)
  823. {
  824. if (bt.Length != 12)
  825. {
  826. Console.WriteLine("bt." + bt + ".bt length is" + bt.Length);
  827. connection.Close();
  828. return res_code;
  829. }
  830. if (wifi.Length != 12)
  831. {
  832. Console.WriteLine("wifi." + wifi + ".wifi length is" + wifi.Length);
  833. connection.Close();
  834. return res_code;
  835. }
  836. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
  837. {
  838. Console.WriteLine("bt." + bt + ".bt exist db");
  839. connection.Close();
  840. return res_code;
  841. }
  842. if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
  843. {
  844. Console.WriteLine("wifi." + wifi + ".wifi exist db");
  845. connection.Close();
  846. return res_code;
  847. }
  848. if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
  849. {
  850. ExecuteSql("update makeserial set ms_bt = '" + bt + "',ms_mac = '" + wifi + "',MS_BIOS ='" + bios + "' ,MS_EC ='" + ec + "' ,MS_UUID ='" + uuid + "',MS_IMEI ='" + imei + "',MS_BS ='" + disksn + "' where ms_sncode = '" + ssn + "' ", "update");
  851. res_code = 0;
  852. }
  853. }
  854. else
  855. {
  856. Console.WriteLine(uuid + "." + res_uuid + ".uuid is null or exist db");
  857. }
  858. connection.Close();
  859. return res_code;
  860. }
  861. public static int Get_Hash(string ssn)
  862. {
  863. int ret_code = 1;
  864. connection = new OracleConnection(ConnectionStrings);
  865. connection.Open();
  866. string hsid = "";
  867. if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
  868. {
  869. hsid = getFieldDataByCondition("makeserial", "MS_HARDWREID", " ms_sncode ='" + ssn + "'").ToString();
  870. if (hsid != "")
  871. {
  872. ret_code = 0;
  873. Console.WriteLine("SET HASH=" + hsid.Trim());
  874. }
  875. }
  876. connection.Close();
  877. return ret_code;
  878. }
  879. public static int Get_Mes(string ssn)
  880. {
  881. int ret_code = 1;
  882. connection = new OracleConnection(ConnectionStrings);
  883. connection.Open();
  884. string mainbord = "";
  885. string mac = "";
  886. string snmac = "";
  887. string snbt = "";
  888. if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
  889. {
  890. mainbord = getFieldDataByCondition("MES_CRAFTMATERIAL_VIEW", "主板", " ms_firstsn ='" + ssn + "'").ToString();
  891. mac = getFieldDataByCondition("MES_CRAFTMATERIAL_VIEW", "MAC贴纸", " ms_firstsn ='" + ssn + "'").ToString();
  892. snbt = getFieldDataByCondition("makeserial", "ms_bt", " ms_sncode ='" + ssn + "'").ToString(); ;
  893. snmac = getFieldDataByCondition("makeserial", "ms_mac", " ms_sncode ='" + ssn + "'").ToString(); ;
  894. ret_code = 0;
  895. Console.WriteLine("SET MES1=" + mainbord);
  896. Console.WriteLine("SET MES2=" + mac);
  897. Console.WriteLine("SET MES3=" + snbt);
  898. Console.WriteLine("SET MES4=" + snmac);
  899. }
  900. connection.Close();
  901. return ret_code;
  902. }
  903. public static int Get_Key(string ssn)
  904. {
  905. int ret_code = 1;
  906. connection = new OracleConnection(ConnectionStrings);
  907. connection.Open();
  908. string key = "";
  909. string keyid = "";
  910. if (CheckExist("makesnlist", " msl_sncode ='" + ssn + "'"))
  911. {
  912. key = getFieldDataByCondition("makesnlist", "nvl(msl_key,' ')", " msl_sncode ='" + ssn + "'").ToString();
  913. if (!key.Contains("-"))
  914. {
  915. byte[] data = Convert.FromBase64String(key);
  916. key = System.Text.Encoding.UTF8.GetString(data);
  917. }
  918. keyid = getFieldDataByCondition("makesnlist", "nvl(msl_keyid,' ')", " msl_sncode ='" + ssn + "'").ToString();
  919. ret_code = 0;
  920. Console.WriteLine("SET ProductKey=" + key);
  921. Console.WriteLine("SET ProductKeyID=" + keyid);
  922. }
  923. connection.Close();
  924. return ret_code;
  925. }
  926. public static int Upload_IMEI(string imeicode, string ssn)
  927. {
  928. int res_code = 1;
  929. connection = new OracleConnection(ConnectionStrings);
  930. connection.Open();
  931. if (!CheckExist("makeserial", " MS_IMEI ='" + imeicode + "'"))
  932. {
  933. ExecuteSql("update makeserial set MS_IMEI = '" + imeicode + "' where ms_sncode = '" + ssn + "' ", "update");
  934. Console.WriteLine("suucces");
  935. res_code = 0;
  936. }else
  937. {
  938. Console.WriteLine("IMEI is exist!");
  939. }
  940. connection.Close();
  941. return res_code;
  942. }
  943. public static int Upload_Bs(string ssn, string bs)
  944. {
  945. int res_code = 1;
  946. connection = new OracleConnection(ConnectionStrings);
  947. connection.Open();
  948. if (!CheckExist("makeserial", " ms_bs ='" + bs + "'"))
  949. {
  950. ExecuteSql("update makeserial set ms_bs = '" + bs + "' where ms_sncode = '" + ssn + "' ", "update");
  951. Console.WriteLine("suucces");
  952. res_code = 0;
  953. }
  954. else
  955. {
  956. Console.WriteLine("IMEI is exist!");
  957. }
  958. connection.Close();
  959. return res_code;
  960. }
  961. //// 上报 part
  962. //public static int Upload_par(string ssn, string K, string V)
  963. //{
  964. // int ret_code = 1;
  965. // SqlConnection conn = new SqlConnection(connString);
  966. // conn.Open();
  967. // string sql = "update [FactoryData] set " + K + "='" + V + "' where SN='" + ssn + "'";
  968. // SqlCommand command = new SqlCommand(sql, conn);
  969. // int num = 0;
  970. // num = command.ExecuteNonQuery();
  971. // conn.Close();
  972. // if (num == 1)
  973. // {
  974. // ret_code = 0;
  975. // }
  976. // return ret_code;
  977. //}
  978. /// <summary>
  979. /// 获取执行步骤代码,名称和线别
  980. /// </summary>
  981. /// <param name="Source"></param>
  982. /// <param name="StepCode"></param>
  983. /// <param name="StepName"></param>
  984. /// <param name="LineCode"></param>
  985. private static void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
  986. {
  987. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  988. if (dt.Rows.Count > 0)
  989. {
  990. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  991. StepName = dt.Rows[0]["sc_stepname"].ToString();
  992. LineCode = dt.Rows[0]["sc_linecode"].ToString();
  993. }
  994. }
  995. /// <summary>
  996. /// 获取步骤代码和名称
  997. /// </summary>
  998. /// <param name="Source"></param>
  999. /// <param name="StepCode"></param>
  1000. /// <param name="StepName"></param>
  1001. private static void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  1002. {
  1003. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  1004. if (dt.Rows.Count > 0)
  1005. {
  1006. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  1007. StepName = dt.Rows[0]["sc_stepname"].ToString();
  1008. }
  1009. }
  1010. /// <summary>
  1011. /// 获取步骤代码
  1012. /// </summary>
  1013. /// <param name="Source"></param>
  1014. /// <returns></returns>
  1015. private static string GetStepCodeBySource(string Source)
  1016. {
  1017. return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
  1018. }
  1019. /// <summary>
  1020. /// 获取步骤代码
  1021. /// </summary>
  1022. /// <param name="Source"></param>
  1023. /// <returns></returns>
  1024. private static string GetStepName(string st_code)
  1025. {
  1026. return getFieldDataByCondition("step", "st_name", "st_code='" + st_code + "'").ToString();
  1027. }
  1028. /// <summary>
  1029. /// 获取第一行第一列的信息
  1030. /// </summary>
  1031. private static object getFieldDataByCondition(string TableName, string Field, string Condition)
  1032. {
  1033. DataTable dt = new DataTable();
  1034. string sql = "select " + Field + " from " + TableName + " where " + Condition;
  1035. command = new OracleCommand(sql, connection);
  1036. Reconnect(command);
  1037. OracleDataAdapter ad = new OracleDataAdapter();
  1038. ad.SelectCommand = command;
  1039. try
  1040. {
  1041. ad.Fill(dt);
  1042. }
  1043. catch (Exception)
  1044. {
  1045. connection = new OracleConnection(ConnectionStrings);
  1046. connection.Open();
  1047. command = new OracleCommand(sql, connection);
  1048. ad = new OracleDataAdapter();
  1049. ad.SelectCommand = command;
  1050. ad.Fill(dt);
  1051. }
  1052. ad.Dispose();
  1053. command.Dispose();
  1054. if (dt.Rows.Count > 0)
  1055. {
  1056. return dt.Rows[0][0];
  1057. }
  1058. else
  1059. {
  1060. return "";
  1061. }
  1062. }
  1063. /// <summary>
  1064. /// 通过表名和获取单行的记录
  1065. /// </summary>
  1066. private static DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
  1067. {
  1068. DataTable dt = new DataTable();
  1069. string sql = "select ";
  1070. sql += AddField(Fields);
  1071. sql += " from " + TableName + " where " + Condition + " and rownum=1";
  1072. command = new OracleCommand(sql, connection);
  1073. Reconnect(command);
  1074. OracleDataAdapter ad = new OracleDataAdapter(command);
  1075. try
  1076. {
  1077. ad.Fill(dt);
  1078. }
  1079. catch (Exception)
  1080. {
  1081. connection = new OracleConnection(ConnectionStrings);
  1082. connection.Open();
  1083. command = new OracleCommand(sql, connection);
  1084. ad = new OracleDataAdapter();
  1085. ad.SelectCommand = command;
  1086. ad.Fill(dt);
  1087. }
  1088. ad.Dispose();
  1089. command.Dispose();
  1090. return dt;
  1091. }
  1092. /// <summary>
  1093. /// 通过表名,字段和条件获取DataTable类型的数据
  1094. /// </summary>
  1095. private static DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
  1096. {
  1097. DataTable dt = new DataTable();
  1098. string sql = "select ";
  1099. sql += AddField(Fields);
  1100. sql += " from " + TableName + " where " + Condition;
  1101. command = new OracleCommand(sql, connection);
  1102. Reconnect(command);
  1103. OracleDataAdapter ad = new OracleDataAdapter(command);
  1104. try
  1105. {
  1106. ad.Fill(dt);
  1107. }
  1108. catch (Exception)
  1109. {
  1110. connection = new OracleConnection(ConnectionStrings);
  1111. connection.Open();
  1112. command = new OracleCommand(sql, connection);
  1113. ad = new OracleDataAdapter();
  1114. ad.SelectCommand = command;
  1115. ad.Fill(dt);
  1116. }
  1117. ad.Dispose();
  1118. command.Dispose();
  1119. return dt;
  1120. }
  1121. /// <summary>
  1122. /// 通过表名,字段获取DataTable类型的数据
  1123. /// </summary>
  1124. private static DataTable getFieldsDatas(string TableName, string Fields)
  1125. {
  1126. DataTable dt = new DataTable();
  1127. string sql = "select ";
  1128. sql += Fields;
  1129. sql += " from " + TableName;
  1130. command = new OracleCommand(sql, connection);
  1131. Reconnect(command);
  1132. OracleDataAdapter ad = new OracleDataAdapter(command);
  1133. ad.SelectCommand = command;
  1134. try
  1135. {
  1136. ad.Fill(dt);
  1137. }
  1138. catch (Exception)
  1139. {
  1140. connection = new OracleConnection(ConnectionStrings);
  1141. connection.Open();
  1142. command = new OracleCommand(sql, connection);
  1143. ad = new OracleDataAdapter();
  1144. ad.SelectCommand = command;
  1145. ad.Fill(dt);
  1146. }
  1147. ad.Dispose();
  1148. command.Dispose();
  1149. return dt;
  1150. }
  1151. /// <summary>
  1152. /// 检测内容是否存在
  1153. /// </summary>
  1154. /// <param name="TableName"></param>
  1155. /// <param name="Condition"></param>
  1156. /// <returns></returns>
  1157. private static bool CheckExist(string TableName, string Condition)
  1158. {
  1159. string sql = "select count(1) from " + TableName + " where " + Condition;
  1160. command = new OracleCommand(sql, connection);
  1161. Reconnect(command);
  1162. OracleDataAdapter ad = new OracleDataAdapter(command);
  1163. DataTable dt = new DataTable();
  1164. ad.Fill(dt);
  1165. ad.Dispose();
  1166. command.Dispose();
  1167. return int.Parse(dt.Rows[0][0].ToString()) > 0;
  1168. }
  1169. /// <summary>
  1170. /// 直接执行SQL,同时传入SQL的类型
  1171. /// </summary>
  1172. /// <param name="SQL"></param>
  1173. /// <param name="Type"></param>
  1174. /// <returns></returns>
  1175. private static object ExecuteSql(string SQL, string Type, params object[] names)
  1176. {
  1177. object result = null;
  1178. command = new OracleCommand(SQL, connection);
  1179. Reconnect(command);
  1180. //用来拼接参数的
  1181. if (names.Length > 0)
  1182. {
  1183. string[] par = SQL.Split(':');
  1184. //用来存参数的数组
  1185. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  1186. for (int i = 0; i < par.Length - 1; i++)
  1187. {
  1188. //新建一个char类型的数组用来存储每个字节的变量
  1189. char[] c = par[i + 1].ToCharArray();
  1190. addpar[i] = new StringBuilder();
  1191. for (int j = 0; j < c.Length; j++)
  1192. {
  1193. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  1194. {
  1195. addpar[i].Append(c[j]);
  1196. }
  1197. else
  1198. {
  1199. break;
  1200. }
  1201. }
  1202. }
  1203. for (int i = 0; i < addpar.Length; i++)
  1204. {
  1205. command.Parameters.Add(new OracleParameter(addpar[i].ToString(), names[i]));
  1206. }
  1207. }
  1208. switch (Type.ToUpper())
  1209. {
  1210. case "SELECT":
  1211. OracleDataAdapter ad = new OracleDataAdapter(command);
  1212. result = new DataTable();
  1213. try
  1214. {
  1215. ad.Fill((DataTable)result);
  1216. }
  1217. catch (Exception)
  1218. {
  1219. connection = new OracleConnection(ConnectionStrings);
  1220. connection.Open();
  1221. command = new OracleCommand(SQL, connection);
  1222. ad = new OracleDataAdapter();
  1223. ad.SelectCommand = command;
  1224. ad.Fill((DataTable)result);
  1225. }
  1226. break;
  1227. case "DELETE":
  1228. try
  1229. {
  1230. result = command.ExecuteNonQuery();
  1231. }
  1232. catch (Exception)
  1233. {
  1234. command.Connection = new OracleConnection(ConnectionStrings);
  1235. command.Connection.Open();
  1236. result = command.ExecuteNonQuery();
  1237. }
  1238. break;
  1239. case "UPDATE":
  1240. try
  1241. {
  1242. result = command.ExecuteNonQuery();
  1243. }
  1244. catch (Exception)
  1245. {
  1246. command.Connection = new OracleConnection(ConnectionStrings);
  1247. command.Connection.Open();
  1248. result = command.ExecuteNonQuery();
  1249. }
  1250. break;
  1251. case "INSERT":
  1252. try
  1253. {
  1254. result = command.ExecuteNonQuery();
  1255. }
  1256. catch (Exception)
  1257. {
  1258. command.Connection = new OracleConnection(ConnectionStrings);
  1259. command.Connection.Open();
  1260. result = command.ExecuteNonQuery();
  1261. }
  1262. break;
  1263. }
  1264. command.Dispose();
  1265. return result;
  1266. }
  1267. /// <summary>
  1268. /// 出现异常进行回滚的执行方法
  1269. /// </summary>
  1270. /// <param name="SQL"></param>
  1271. private static void ExecuteSQLTran(params string[] SQL)
  1272. {
  1273. command = new OracleCommand();
  1274. command.Connection = new OracleConnection(ConnectionStrings);
  1275. command.Connection.Open();
  1276. Reconnect(command);
  1277. OracleTransaction tx = command.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
  1278. command.Transaction = tx;
  1279. try
  1280. {
  1281. foreach (string sql in SQL)
  1282. {
  1283. if (!string.IsNullOrEmpty(sql))
  1284. {
  1285. command.CommandText = sql;
  1286. command.ExecuteNonQuery();
  1287. }
  1288. }
  1289. tx.Commit();
  1290. }
  1291. catch (OracleException E)
  1292. {
  1293. tx.Rollback();
  1294. throw new Exception(E.Message);
  1295. }
  1296. command.Dispose();
  1297. }
  1298. private static string UpdateByCondition(string TableName, string update, string condition)
  1299. {
  1300. string sql = "update " + TableName + " set " + update + " where " + condition;
  1301. command = new OracleCommand(sql, connection);
  1302. Reconnect(command);
  1303. try
  1304. {
  1305. command.ExecuteNonQuery();
  1306. }
  1307. catch (Exception)
  1308. {
  1309. command.Connection = new OracleConnection(ConnectionStrings);
  1310. command.Connection.Open();
  1311. command.ExecuteNonQuery();
  1312. }
  1313. command.Dispose();
  1314. return sql;
  1315. }
  1316. private static void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
  1317. {
  1318. command = new OracleCommand(ProcedureName);
  1319. command.Connection = connection;
  1320. Reconnect(command);
  1321. command.CommandText = ProcedureName;
  1322. command.CommandType = CommandType.StoredProcedure;
  1323. for (int i = 0; i < param.Length; i++)
  1324. {
  1325. command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
  1326. //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
  1327. }
  1328. try
  1329. {
  1330. command.ExecuteNonQuery();
  1331. }
  1332. catch (Exception)
  1333. {
  1334. command.Connection = new OracleConnection(ConnectionStrings);
  1335. command.Connection.Open();
  1336. command.ExecuteNonQuery();
  1337. }
  1338. for (int i = 0; i < command.Parameters.Count; i++)
  1339. param[i] = command.Parameters[i].Value.ToString();
  1340. command.Dispose();
  1341. }
  1342. private static string AddField(string[] Fields)
  1343. {
  1344. string sql = " ";
  1345. foreach (string field in Fields)
  1346. {
  1347. sql += field + ",";
  1348. }
  1349. return sql.Substring(0, sql.Length - 1);
  1350. }
  1351. private static string[] GetField(string field)
  1352. {
  1353. string[] fields = field.Split(',');
  1354. for (int i = 0; i < fields.Length; i++)
  1355. {
  1356. fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
  1357. }
  1358. return fields;
  1359. }
  1360. private static void Reconnect(OracleCommand cmd)
  1361. {
  1362. if (cmd.Connection.State == ConnectionState.Closed)
  1363. {
  1364. cmd.Connection.Open();
  1365. }
  1366. }
  1367. private static bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage)
  1368. {
  1369. //取MakeProcess表中的执行记录ID最大的一个工单的号码
  1370. oMoCode = "";
  1371. if (iSN == "")
  1372. {
  1373. oErrMessage = "SN不能为空";
  1374. return false;
  1375. }
  1376. StringBuilder sql = new StringBuilder();
  1377. oErrMessage = "";
  1378. sql.Clear();
  1379. sql.Append("select max(ms_id) from makeserial where ms_sncode in (select '" + iSN + "' from dual union select sn from ");
  1380. sql.Append("makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' ')");
  1381. DataTable dt = (DataTable)ExecuteSql(sql.ToString(), "select");
  1382. string ms_id = dt.Rows[0][0].ToString();
  1383. oMoCode = getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_id='" + ms_id + "'").ToString();
  1384. if (oMoCode != "")
  1385. return true;
  1386. else
  1387. {
  1388. oErrMessage = "序列号:" + iSN + " 未归属工单";
  1389. return false;
  1390. }
  1391. }
  1392. private static bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrMessage)
  1393. {
  1394. if (iSN == "")
  1395. {
  1396. oErrMessage = "SN不能为空";
  1397. return false;
  1398. }
  1399. oErrMessage = "";
  1400. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
  1401. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
  1402. CallProcedure("CS_SETSTEPRESULT", ParamName, ref param);
  1403. oErrMessage = param[5];
  1404. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  1405. return true;
  1406. else
  1407. return false;
  1408. }
  1409. private static bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
  1410. {
  1411. StringBuilder sql = new StringBuilder();
  1412. if (iSN == "")
  1413. {
  1414. oErrMessage = "SN不能为空";
  1415. return false;
  1416. }
  1417. oErrMessage = "";
  1418. string StepCode = getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
  1419. string CurrentStep = GetStepCodeBySource(iSourceCode);
  1420. string BgCode = getFieldDataByCondition("step", "st_badgroupcode", "st_code='" + CurrentStep + "'").ToString();
  1421. switch (iResult)
  1422. {
  1423. case "OK":
  1424. break;
  1425. case "NG":
  1426. if (iErrCode == "")
  1427. {
  1428. oErrMessage = "测试结果为NG时必须传递不良代码";
  1429. return false;
  1430. }
  1431. else
  1432. {
  1433. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "' and mb_stepcode='" + CurrentStep + "' and mb_status=0");
  1434. string[] BadCode = iErrCode.Split(',');
  1435. sql.Length = 0;
  1436. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  1437. sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select makebad_seq.nextval");
  1438. sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
  1439. sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  1440. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  1441. List<string> InsertSQL = new List<string>();
  1442. for (int i = 0; i < BadCode.Length; i++)
  1443. {
  1444. InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + BadCode[i] + "'"));
  1445. }
  1446. ExecuteSQLTran(InsertSQL.ToArray());
  1447. //将不良的序列号的状态码设为3
  1448. ExecuteSql("update makeserial set ms_status='3' where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'", "update");
  1449. }
  1450. break;
  1451. default:
  1452. oErrMessage = "测试结果必须为NG或者OK";
  1453. return false;
  1454. }
  1455. //不良采集为良品是更新
  1456. if (StepCode == CurrentStep && iResult == "OK")
  1457. {
  1458. DataTable dt = getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_craftcode", "ms_prodcode" }, "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  1459. if (dt.Rows.Count > 0)
  1460. {
  1461. string ms_status = dt.Rows[0]["ms_status"].ToString();
  1462. string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  1463. string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  1464. if (ms_status == "3")
  1465. {
  1466. string nextstepcode = getFieldDataByCondition("craft left join craftdetail on cr_id=cd_crid ", "cd_nextstepcode", "cr_code='" + ms_craftcode + "' and cr_prodcode='" + ms_prodcode + "' and cd_stepcode='" + CurrentStep + "'").ToString();
  1467. UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  1468. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "'");
  1469. }
  1470. }
  1471. }
  1472. return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrMessage);
  1473. }
  1474. }
  1475. }