| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674 |
- using Oracle.ManagedDataAccess.Client;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Text;
- namespace upload
- {
- class Program
- {
- //定义连接字符串
- //static string connString = "Server=192.168.83.231;DataBase=GW_DAS;Uid=oa3;Pwd=789123-gw";
- //static string connString = "server=192.168.11.253;database=gw_das;uid=oa3;pwd=789123-gw";
- //用于拼接SQL
- StringBuilder sql = new StringBuilder();
- //用于存放批量执行的SQL
- List<string> sqls = new List<string>();
- //系统默认的的连接字符串
- //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)));";
- 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)));";
- //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)));";
- //用户选择的数据库的连接字符串
- static OracleConnection connection;
- //用户选择的数据库的连接字符串
- static OracleCommand command = null;
- static void Main(string[] args)
- {
- //int res = Chk_key("2GWTC116-2BK1Y21H000000");
- //Console.WriteLine(res);
- //string tests = "00";
- //if (string.IsNullOrWhiteSpace(tests))
- //{
- // Console.WriteLine("fail");
- //}
- //Console.ReadLine();
-
- if (args.Length < 2) {
- Console.WriteLine("please input parameter run!");
- System.Environment.Exit(1);
- }
- switch (args[0])
- {
- case "Chk_Station":
- Chk_parameter(3, args);
- System.Environment.Exit(Chk_Station(args[1],args[2]));
- break;
- case "Update_station":
- Chk_parameter(3, args);
- System.Environment.Exit(Update_station(args[1], args[2]));
- break;
- case "Chk_key":
- Chk_parameter(2, args);
- System.Environment.Exit(Chk_key(args[1]));
- break;
- case "Upload_key":
- Chk_parameter(6, args);
- System.Environment.Exit(Upload_key(args[1], args[2], args[3], args[4], args[5]));
- break;
- case "Upload_offlinekey":
- Chk_parameter(3, args);
- System.Environment.Exit(Upload_offlinekey(args[1], args[2]));
- break;
- case "Upload_cbr":
- Chk_parameter(5, args);
- System.Environment.Exit(Upload_cbr(args[1], args[2], args[3], args[4]));
- break;
- case "Upload_part":
- //Chk_parameter(7, args);
- if (args.Length == 7)
- System.Environment.Exit(Upload_part(args[1], args[2], args[3], args[4], args[5], args[6]));
- else
- System.Environment.Exit(Upload_part(args[1], args[2], args[3], args[4], args[5], args[6], args[7]));
- break;
- case "Upload_mdos":
- //Chk_parameter(7, args);
- if(args.Length==9)
- System.Environment.Exit(Upload_mdos(args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]));
- else
- System.Environment.Exit(Upload_mdos(args[1], args[2], args[3], args[4], args[5], args[6], args[7]));
- break;
- case "Upload_pack":
- Chk_parameter(3, args);
- System.Environment.Exit(Upload_pack(args[1], args[2]));
- break;
- case "Get_SN":
- Chk_parameter(3, args);
- System.Environment.Exit(Get_SN(args[1], args[2]));
- break;
- case "Get_Hash":
- Chk_parameter(2, args);
- System.Environment.Exit(Get_Hash(args[1]));
- break;
- case "Upload_IMEI":
- Chk_parameter(3, args);
- System.Environment.Exit(Upload_IMEI(args[1], args[2]));
- break;
- case "Upload_Bs":
- Chk_parameter(3, args);
- System.Environment.Exit(Upload_Bs(args[1], args[2]));
- break;
- case "Get_Mes":
- Chk_parameter(2, args);
- System.Environment.Exit(Get_Mes(args[1]));
- break;
- case "Get_Key":
- Chk_parameter(2, args);
- System.Environment.Exit(Get_Key(args[1]));
- break;
- //case "Upload_par":
- // Chk_parameter(4, args);
- // System.Environment.Exit(Upload_par(args[1], args[2], args[3]));
- // break;
- default:
- Console.WriteLine("please input parameter run!");
- System.Environment.Exit(1);
- break;
- }
- //Console.ReadLine();
- }
- // 检查工站 返回0 是正确的
- public static void Chk_parameter(int loop ,string[] para) {
- //Console.WriteLine("aa");
- //if (para.Length < loop)
- //{
- // Console.WriteLine("please input parameter run, less");
- // System.Environment.Exit(1);
- //}
- //for (int i = 0; i < loop; i++)
- //{
- // if (string.IsNullOrWhiteSpace(para[i]))
- // {
- // Console.WriteLine("please input parameter run, null");
- // System.Environment.Exit(1);
- // }
- //}
- return;
- }
- public static int Chk_Station(string field, string ssn) {
- //int ret_code = 1;
- ////创建连接对象
- //SqlConnection conn = new SqlConnection(connString);
- ////string ssn = "2GWTC116-2BK1Y21H000000";
- //string sql = "select ["+field+"] from notebook_info where ssn='"+ssn+"'";
- //SqlCommand cmd = new SqlCommand(sql, conn);
- ////打开连接
- //conn.Open();
- ////执行查询方法,返回DataReader对象
- //SqlDataReader objRader = cmd.ExecuteReader();
- ////bool tmp_value = objRader.Read();
- ////if (tmp_value == true)
- ////{
- //// ret_code = 0;
- ////}
- //string res_tmp = "0";
- ////读取数据
- //while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
- //{
- // res_tmp = objRader[field].ToString();
- //}
- ////关闭读取器
- //objRader.Close();
- //conn.Close();
- //if (res_tmp.Equals("1")) {
- // ret_code = 0;
- //}
- //return ret_code;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- string oErrMessage;
- if (ssn == "")
- {
- oErrMessage = "SN不能为空";
- Console.WriteLine(oErrMessage);
- return 1;
- }
- oErrMessage = "";
- string[] param = new string[] { "", field, ssn, "", "", "", oErrMessage };
- 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" };
- CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
- oErrMessage = param[6];
- 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");
- string ms_status = "";
- string ms_stepcode = "";
- string ms_nextstepcode = "";
- if (dt.Rows.Count > 0)
- {
- ms_status = dt.Rows[0]["ms_status"].ToString();
- ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
- ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
- }
- string stepcode = GetStepCodeBySource(field);
- connection.Close();
- if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
- {
- oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
- Console.WriteLine(oErrMessage);
- return 1;
- }
- if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" )
- {
- return 0;
- }
- else
- {
- Console.WriteLine(oErrMessage);
- return 1;
- }
- }
- // 更新工站 返回0 是过站成功
- public static int Update_station(string ssn, string stations)
- {
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- //SqlConnection conn = new SqlConnection(connString);
- //conn.Open();
- //string sql = "update [notebook_info] set "+ stations + "='1' where ssn='" + ssn + "'";
- //SqlCommand command = new SqlCommand(sql, conn);
- //int num = 0;
- //num = command.ExecuteNonQuery();
- //conn.Close();
- //if (num == 1)
- //{
- // ret_code = 0;
- //}
- string oErrMessage = "";
- if (ssn == "")
- {
- oErrMessage = "SN不能为空";
- Console.WriteLine(oErrMessage);
- connection.Close();
- return 1;
- }
- oErrMessage = "";
- string oMakeCode = "";
- GetRcardMOInfo(ssn, out oMakeCode, out oErrMessage);
- if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
- {
- if(!SetStepFinish(oMakeCode, stations, ssn, "测试工具测试", "OK", "ZZCS", "", out oErrMessage))
- {
- Console.WriteLine(oErrMessage);
- connection.Close();
- return 1;
- }
- }
- else
- {
- Console.WriteLine(oErrMessage);
- connection.Close();
- return 1;
- }
- connection.Close();
- return 0;
- }
- // 检查key 返回0 证明不存在
- public static int Chk_key(string ssn)
- {
- int ret_code = 1;
- ////创建连接对象
- //SqlConnection conn = new SqlConnection(connString);
- ////string ssn = "2GWTC116-2BK1Y21H000000";
- //string sql = "select [SerialNumber] from OAkeyinfo where SerialNumber='" + ssn + "'";
- //string sqlfom = "select [StateID] from FactoryData where SN='" + ssn + "'";
- //SqlCommand cmd = new SqlCommand(sql, conn);
- ////打开连接
- //conn.Open();
- ////执行查询方法,返回DataReader对象
- //SqlDataReader objRader = cmd.ExecuteReader();
- //int oakey = 1;
- //int fomkey = 1;
- //bool tmp_value = true;
- //string res_tmp = "100";
- ////读取数据
- //tmp_value =objRader.Read();
- //if (tmp_value == false) {
- // oakey = 0;
- // }
- //objRader.Close();
- //conn.Close();
- //SqlCommand cmdfom = new SqlCommand(sqlfom, conn);
- //conn.Open();
- //SqlDataReader objfom = cmdfom.ExecuteReader();
- //while (objfom.Read()) {
- // res_tmp = objfom["StateID"].ToString();
- //}
- ////Console.WriteLine(res_tmp);
- //if (res_tmp.Equals("1") || res_tmp.Equals("100"))
- //{
- // fomkey = 0;
- //}
- //if (oakey == 0 && fomkey ==0)
- //{
- // ret_code = 0;
- //}
- //objfom.Close();
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- if (!CheckExist("makeserial", "ms_sncode = '" + ssn + "' and ms_key is not null"))
- ret_code = 0;
- connection.Close();
- return ret_code;
- }
- // 检查keyid 是否一致 返回 0 pass
- public static int Chk_keyid(string ssn, string keyid)
- {
- int ret_code = 1;
- //创建连接对象
- //SqlConnection conn = new SqlConnection(connString);
- ////string ssn = "2GWTC116-2BK1Y21H000000";
- //string sql = "select [ProductKeyID] from OAkeyinfo where SerialNumber='" + ssn + "'";
- //SqlCommand cmd = new SqlCommand(sql, conn);
- ////打开连接
- //conn.Open();
- ////执行查询方法,返回DataReader对象
- //SqlDataReader objRader = cmd.ExecuteReader();
- ////读取数据
- //string res_tmp = "0";
- ////读取数据
- //while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
- //{
- // res_tmp = objRader["ProductKeyID"].ToString();
- //}
- //if (res_tmp.Equals(keyid)) {
- // ret_code = 0;
- //}
- //objRader.Close();
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- if (CheckExist("makeserial", "ms_sncode = '" + ssn + "' and ms_keyid ='"+keyid+"'"))
- ret_code = 0;
- connection.Close();
- return ret_code;
- }
- public static int Chk_keyid(string keyid) {
- int ret_code = 1;
- ////创建连接对象
- //SqlConnection conn = new SqlConnection(connString);
- ////string ssn = "2GWTC116-2BK1Y21H000000";
- //string sql = "select [ProductKeyID] from OAkeyinfo where ProductKeyID='" + keyid + "'";
- //SqlCommand cmd = new SqlCommand(sql, conn);
- ////打开连接
- //conn.Open();
- ////执行查询方法,返回DataReader对象
- //SqlDataReader objRader = cmd.ExecuteReader();
- //bool tmp_value = true;
- ////读取数据
- //tmp_value = objRader.Read();
- //if (tmp_value == false)
- //{
- // ret_code = 0;
- //}
- //objRader.Close();
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
-
- if (!CheckExist("makeserial", " ms_keyid ='" + keyid + "'"))
- ret_code = 0;
- connection.Close();
- return ret_code;
- }
- public static int Chk_uuid(string uuid)
- {
- int ret_code = 1;
-
- //connection = new OracleConnection(ConnectionStrings);
- //connection.Open();
- //if (uuid == "" || uuid == null)
- //{
- // ret_code = 2;
- //}
- //else if (CheckExist("makeserial", " ms_uuid ='" + uuid + "'"))
- //{
- // ret_code = 3;
- //}
- //connection.Close();
- return ret_code;
- }
- // 上传key 返回0 pass
- public static int Upload_key(string ssn, string dpk, string keyid, string stateid, string partnumber)
- {
- int res_code = 1;
- int res_keyid = Chk_keyid(keyid);
- if (res_keyid == 0)
- {
- int res_key = Chk_key(ssn);
- if (res_key == 0) {
- //SqlConnection conn = new SqlConnection(connString);
- //conn.Open();
-
- ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
- //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate)
- //string sql = "insert into OAkeyinfo(SerialNumber, ProductKey, ProductKeyID, ProductKeyStateID, ProductKeyPartNumber) values ('" + ssn+"','"+ dpk + "','"+keyid+"',"+stateid+ ",'" + partnumber + "')";
- //SqlCommand command = new SqlCommand(sql, conn);
- //int num = 0;
- //num = command.ExecuteNonQuery();
- //if (num == 1) {
- // res_code = 0;
- //}
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- ExecuteSql("update makeserial set ms_key = '"+dpk+"',ms_keyid = '"+keyid+ "',MS_KEYSTATEID ='"+stateid+ "',MS_KEYPARTNUMBER ='"+partnumber+"' where ms_sncode = '" + ssn + "' ","update");
- ExecuteSql(" insert into KEYLOG(KL_ID,KL_SN,KL_KEY,KL_INDATE) values(KEYLOG_SEQ.NEXTVAL,'"+ ssn + "','"+ dpk + "',sysdate) ", "insert");
- res_code = 0;
- connection.Close();
- }
- }
- else
- {
- Console.WriteLine("key is exist db");
- }
- return res_code;
- }
- // 上传key 返回0 pass
- public static int Upload_offlinekey(string ssn, string dpk)
- {
- //SqlConnection conn = new SqlConnection(connString);
- //conn.Open();
- ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
- //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate)
- //string sql = "insert into OAkeyinfo(SerialNumber, ProductKey, ProductKeyID, ProductKeyStateID, ProductKeyPartNumber) values ('" + ssn+"','"+ dpk + "','"+keyid+"',"+stateid+ ",'" + partnumber + "')";
- //SqlCommand command = new SqlCommand(sql, conn);
- //int num = 0;
- //num = command.ExecuteNonQuery();
- //if (num == 1) {
- // res_code = 0;
- //}
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- ExecuteSql("update makeserial set ms_key = '" + dpk + "' where ms_sncode = '" + ssn + "' ", "update");
- ExecuteSql(" insert into KEYLOG(KL_ID,KL_SN,KL_KEY,KL_INDATE) values(KEYLOG_SEQ.NEXTVAL,'" + ssn + "','" + dpk + "',sysdate) ", "insert");
- connection.Close();
-
- return 0;
- }
- // 上传 cbr 返回 0 pass
- public static int Upload_cbr(string ssn, string hardwreid, string stateid, string keyid)
- {
- int res_code = 1;
- int res_key = Chk_keyid(ssn, keyid);
- if (res_key == 0)
- {
- //SqlConnection conn = new SqlConnection(connString);
- //conn.Open();
- ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
- //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate) HardwreID
- //string sql = "update OAkeyinfo set HardwreID='"+ hardwreid + "',ProductKeyStateID="+ stateid + " where ProductKeyID='" + keyid + "'";
- //SqlCommand command = new SqlCommand(sql, conn);
- ////int num = 0;
- //int num = command.ExecuteNonQuery();
- ////Console.WriteLine(num);
- //if (num == 1 || num == 2)
- //{
- // res_code = 0;
- //}
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- ExecuteSql("update makeserial set MS_HARDWREID = '" + hardwreid + "',ms_keyid = '" + keyid + "',MS_KEYSTATEID ='" + stateid + "' where ms_sncode = '" + ssn + "' ", "update");
- res_code = 0;
- connection.Close();
- }
-
- return res_code;
- }
- // 返回 0 证明上传 包装数据pass
- public static int Upload_part(string ssn, string bt, string wifi, string bios, string ec, string uuid)
- {
- int res_code = 1;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- int res_uuid = Chk_uuid(uuid);
- if (res_uuid == 1)
- {
- if (bt.Length != 12)
- {
- Console.WriteLine("bt." + bt + ".bt length is"+bt.Length);
- connection.Close();
- return res_code;
- }
- if (wifi.Length != 12)
- {
- Console.WriteLine("wifi." + wifi + ".wifi length is"+wifi.Length);
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
- {
- Console.WriteLine("bt." + bt + ".bt exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
- {
- Console.WriteLine("wifi." + wifi + ".wifi exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
- {
- ExecuteSql("update makeserial set ms_bt = '" + bt + "',ms_mac = '" + wifi + "',MS_BIOS ='" + bios + "' ,MS_EC ='" + ec + "' ,MS_UUID ='" + uuid + "' where ms_sncode = '" + ssn + "' ", "update");
- res_code = 0;
- }
- }
- else
- {
- Console.WriteLine(uuid+"."+ res_uuid + ".uuid is null or exist db");
- }
- connection.Close();
- return res_code;
- }
- public static int Upload_part(string ssn, string bt, string wifi, string bios, string ec, string uuid,string lan)
- {
- int res_code = 1;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- int res_uuid = Chk_uuid(uuid);
- if (res_uuid == 1)
- {
- if (bt.Length != 12)
- {
- Console.WriteLine("bt." + bt + ".bt length is" + bt.Length);
- connection.Close();
- return res_code;
- }
- if (wifi.Length != 12)
- {
- Console.WriteLine("wifi." + wifi + ".wifi length is" + wifi.Length);
- connection.Close();
- return res_code;
- }
- if (lan.Length != 12)
- {
- Console.WriteLine("lan." + lan + ".lan length is" + lan.Length);
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
- {
- Console.WriteLine("bt." + bt + ".bt exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
- {
- Console.WriteLine("wifi." + wifi + ".wifi exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_lan = '" + lan + "' and ms_lan is not null"))
- {
- Console.WriteLine("lan." + lan + ".lan exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
- {
- 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");
- res_code = 0;
- }
- }
- else
- {
- Console.WriteLine(uuid + "." + res_uuid + ".uuid is null or exist db");
- }
- connection.Close();
- return res_code;
- }
- // 返回 0 可以包装
- public static int Upload_pack(string ssn, string keyid)
- {
- int res_code = 1;
- //int res_key = Chk_keyid(ssn, keyid);
- //if (res_key == 0)
- //{
- // SqlConnection conn = new SqlConnection(connString);
- // conn.Open();
- // string selects = "select [orderid] from notebook_info where ssn='" + ssn + "'";
- // SqlCommand cmd = new SqlCommand(selects, conn);
- // //执行查询方法,返回DataReader对象
- // SqlDataReader objRader = cmd.ExecuteReader();
- // //bool tmp_value = objRader.Read();
- // //if (tmp_value == true)
- // //{
- // // ret_code = 0;
- // //}
- // int res_tmp = 0;
- // //读取数据
- // while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
- // {
- // res_tmp = objRader.GetInt32(objRader.GetOrdinal("orderid"));
- // //res_tmp = objRader["orderid"]
- // }
- // objRader.Close();
- // conn.Close();
- // conn.Open();
- // if (res_tmp != 0)
- // {
- // string updatesql = "update FactoryData set OrderID=" + res_tmp + " where SN='" + ssn + "'";
- // SqlCommand command = new SqlCommand(updatesql, conn);
- // int num = 0;
- // num = command.ExecuteNonQuery();
- // if (num == 1)
- // {
- // res_code = 0;
- // }
- // }
- // conn.Close();
- //}
- return 0;
- }
- // field 返回SN
- public static int Get_SN(string field, string code)
- {
- int ret_code = 1;
- ////创建连接对象
- //SqlConnection conn = new SqlConnection(connString);
- ////string ssn = "2GWTC116-2BK1Y21H000000";
- //string sql = "select [ssn] from notebook_info where "+field+"='" + code + "'";
- //SqlCommand cmd = new SqlCommand(sql, conn);
- ////打开连接
- //conn.Open();
- ////执行查询方法,返回DataReader对象
- //SqlDataReader objRader = cmd.ExecuteReader();
- ////bool tmp_value = objRader.Read();
- ////if (tmp_value == true)
- ////{
- //// ret_code = 0;
- ////}
- //string res_tmp = "0";
- ////读取数据
- ////Console.WriteLine(objRader.Read());
- //while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
- //{
- // Console.WriteLine("SET SSN="+objRader["ssn"].ToString());
- // res_tmp = "1";
- //}
- ////关闭读取器
- //objRader.Close();
- //conn.Close();
- //if (res_tmp.Equals("1"))
- //{
- // ret_code = 0;
- //}
- //return ret_code;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- string res_tmp = "0";
- if (CheckExist("craftmaterial","cm_barcode = '"+ code + "' and cm_status = 0"))//objRader.Read() 如果返回true就说明结果里面有数据
- {
- string sn = getFieldDataByCondition("craftmaterial", "cm_sncode", "cm_barcode = '" + code + "' and cm_status = 0").ToString();
- Console.WriteLine("SET SSN=" + sn);
- res_tmp = "1";
- }
- if (res_tmp.Equals("1"))
- {
- ret_code = 0;
- }
- connection.Close();
- return ret_code;
- }
- public static int Upload_mdos(string ssn, string bt, string wifi, string bios, string ec, string uuid, string disksn)
- {
- int res_code = 1;
- //SqlConnection conn = new SqlConnection(connString);
- //conn.Open();
- ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
- //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate) HardwreID
- //// string sql = "select ["+field+"] from notebook_info where ssn='"+ssn+"'";
- //string checksql = "select [StateID] from FactoryData where SN='" + ssn + "'";
- //string insertsql = "insert into FactoryData(SN, WIFI, BT, BIOS, EC, UUID, IMEI1, BS, StateID) values('" + ssn + "', '" + wifi + "', '" + bt + "', '" + bios + "','" + ec + "','" + uuid + "','" + imei + "','" + disksn + "',10)";
- //string updatesql = "update FactoryData set WIFI='" + wifi + "',BT='" + bt + "',BIOS='" + bios + "',EC='" + ec + "',UUID='" + uuid + "',IMEI1='"+ imei + "',BS='"+ disksn + "',StateID=10 where SN='" + ssn + "'";
- //SqlCommand chkcmd = new SqlCommand(checksql, conn);
- //SqlDataReader objRader = chkcmd.ExecuteReader();
- //int chk_res = 0;
- //bool check_data = objRader.Read();
- //if (check_data == true)
- //{
- // chk_res = 1;
- // string StateID = "0";
- // while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
- // {
- // StateID = objRader["StateID"].ToString();
- // }
- // if (StateID.Equals("60"))
- // {
- // chk_res = 2;
- // // 返回2 不能更新
- // }
- // objRader.Close();
- //}
- //conn.Close();
- //int sql_res = 0;
- //// 0 inser 1 update
- //conn.Open();
- //switch (chk_res)
- //{
- // case 0:
- // SqlCommand inertcmd = new SqlCommand(insertsql, conn);
- // sql_res = inertcmd.ExecuteNonQuery();
- // break;
- // case 1:
- // SqlCommand updatecmd = new SqlCommand(updatesql, conn);
- // sql_res = updatecmd.ExecuteNonQuery();
- // break;
- // default:
- // break;
- //}
- //if (sql_res == 1)
- //{
- // res_code = 0;
- //}
- ////SqlCommand command = new SqlCommand(checksql, conn);
- ////int num = 0;
- ////num = command.ExecuteNonQuery();
- ////if (num == 1)
- ////{
- //// res_code = 0;
- ////}
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- int res_uuid = Chk_uuid(uuid);
- if (res_uuid == 1)
- {
- if (bt.Length != 12)
- {
- Console.WriteLine("bt." + bt + ".bt length is" + bt.Length);
- connection.Close();
- return res_code;
- }
- if (wifi.Length != 12)
- {
- Console.WriteLine("wifi." + wifi + ".wifi length is" + wifi.Length);
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
- {
- Console.WriteLine("bt." + bt + ".bt exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
- {
- Console.WriteLine("wifi." + wifi + ".wifi exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
- {
- 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");
- res_code = 0;
- }
- }
- else
- {
- Console.WriteLine(uuid + "." + res_uuid + ".uuid is null or exist db");
- }
- connection.Close();
- return res_code;
- }
- public static int Upload_mdos(string ssn, string bt, string wifi, string bios, string ec, string uuid, string imei, string disksn)
- {
- int res_code = 1;
- //SqlConnection conn = new SqlConnection(connString);
- //conn.Open();
- ////string sql = "update [notebook_info] set mb_sn='" + mb_sn + "',batt_sn='" + batt_sn + "' where pre_sn='" + scan_sn + "' ";
- //// insert into OAkeyinfo(SerialNumber,ProductKey,ProductKeyID,ProductKeyStateID) values (@SSN,@key,@keyid,@keystate) HardwreID
- //// string sql = "select ["+field+"] from notebook_info where ssn='"+ssn+"'";
- //string checksql = "select [StateID] from FactoryData where SN='" + ssn + "'";
- //string insertsql = "insert into FactoryData(SN, WIFI, BT, BIOS, EC, UUID, IMEI1, BS, StateID) values('" + ssn + "', '" + wifi + "', '" + bt + "', '" + bios + "','" + ec + "','" + uuid + "','" + imei + "','" + disksn + "',10)";
- //string updatesql = "update FactoryData set WIFI='" + wifi + "',BT='" + bt + "',BIOS='" + bios + "',EC='" + ec + "',UUID='" + uuid + "',IMEI1='"+ imei + "',BS='"+ disksn + "',StateID=10 where SN='" + ssn + "'";
- //SqlCommand chkcmd = new SqlCommand(checksql, conn);
- //SqlDataReader objRader = chkcmd.ExecuteReader();
- //int chk_res = 0;
- //bool check_data = objRader.Read();
- //if (check_data == true)
- //{
- // chk_res = 1;
- // string StateID = "0";
- // while (objRader.Read())//objRader.Read() 如果返回true就说明结果里面有数据
- // {
- // StateID = objRader["StateID"].ToString();
- // }
- // if (StateID.Equals("60"))
- // {
- // chk_res = 2;
- // // 返回2 不能更新
- // }
- // objRader.Close();
- //}
- //conn.Close();
- //int sql_res = 0;
- //// 0 inser 1 update
- //conn.Open();
- //switch (chk_res)
- //{
- // case 0:
- // SqlCommand inertcmd = new SqlCommand(insertsql, conn);
- // sql_res = inertcmd.ExecuteNonQuery();
- // break;
- // case 1:
- // SqlCommand updatecmd = new SqlCommand(updatesql, conn);
- // sql_res = updatecmd.ExecuteNonQuery();
- // break;
- // default:
- // break;
- //}
- //if (sql_res == 1)
- //{
- // res_code = 0;
- //}
- ////SqlCommand command = new SqlCommand(checksql, conn);
- ////int num = 0;
- ////num = command.ExecuteNonQuery();
- ////if (num == 1)
- ////{
- //// res_code = 0;
- ////}
- //conn.Close();
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- int res_uuid = Chk_uuid(uuid);
- if (res_uuid == 1)
- {
- if (bt.Length != 12)
- {
- Console.WriteLine("bt." + bt + ".bt length is" + bt.Length);
- connection.Close();
- return res_code;
- }
- if (wifi.Length != 12)
- {
- Console.WriteLine("wifi." + wifi + ".wifi length is" + wifi.Length);
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_bt = '" + bt + "' and ms_bt is not null"))
- {
- Console.WriteLine("bt." + bt + ".bt exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode <>'" + ssn + "' and ms_mac = '" + wifi + "' and ms_mac is not null"))
- {
- Console.WriteLine("wifi." + wifi + ".wifi exist db");
- connection.Close();
- return res_code;
- }
- if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
- {
- 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");
- res_code = 0;
- }
- }
- else
- {
- Console.WriteLine(uuid + "." + res_uuid + ".uuid is null or exist db");
- }
- connection.Close();
- return res_code;
- }
- public static int Get_Hash(string ssn)
- {
- int ret_code = 1;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- string hsid = "";
- if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
- {
- hsid = getFieldDataByCondition("makeserial", "MS_HARDWREID", " ms_sncode ='" + ssn + "'").ToString();
- if (hsid != "")
- {
- ret_code = 0;
- Console.WriteLine("SET HASH=" + hsid.Trim());
- }
-
- }
- connection.Close();
- return ret_code;
- }
- public static int Get_Mes(string ssn)
- {
- int ret_code = 1;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- string mainbord = "";
- string mac = "";
- string snmac = "";
- string snbt = "";
- if (CheckExist("makeserial", " ms_sncode ='" + ssn + "'"))
- {
- mainbord = getFieldDataByCondition("MES_CRAFTMATERIAL_VIEW", "主板", " ms_firstsn ='" + ssn + "'").ToString();
- mac = getFieldDataByCondition("MES_CRAFTMATERIAL_VIEW", "MAC贴纸", " ms_firstsn ='" + ssn + "'").ToString();
- snbt = getFieldDataByCondition("makeserial", "ms_bt", " ms_sncode ='" + ssn + "'").ToString(); ;
- snmac = getFieldDataByCondition("makeserial", "ms_mac", " ms_sncode ='" + ssn + "'").ToString(); ;
-
- ret_code = 0;
- Console.WriteLine("SET MES1=" + mainbord);
- Console.WriteLine("SET MES2=" + mac);
- Console.WriteLine("SET MES3=" + snbt);
- Console.WriteLine("SET MES4=" + snmac);
- }
- connection.Close();
- return ret_code;
- }
- public static int Get_Key(string ssn)
- {
- int ret_code = 1;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- string key = "";
- string keyid = "";
- if (CheckExist("makesnlist", " msl_sncode ='" + ssn + "'"))
- {
- key = getFieldDataByCondition("makesnlist", "nvl(msl_key,' ')", " msl_sncode ='" + ssn + "'").ToString();
- if (!key.Contains("-"))
- {
- byte[] data = Convert.FromBase64String(key);
- key = System.Text.Encoding.UTF8.GetString(data);
- }
- keyid = getFieldDataByCondition("makesnlist", "nvl(msl_keyid,' ')", " msl_sncode ='" + ssn + "'").ToString();
- ret_code = 0;
- Console.WriteLine("SET ProductKey=" + key);
- Console.WriteLine("SET ProductKeyID=" + keyid);
- }
- connection.Close();
- return ret_code;
- }
- public static int Upload_IMEI(string imeicode, string ssn)
- {
- int res_code = 1;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- if (!CheckExist("makeserial", " MS_IMEI ='" + imeicode + "'"))
- {
- ExecuteSql("update makeserial set MS_IMEI = '" + imeicode + "' where ms_sncode = '" + ssn + "' ", "update");
- Console.WriteLine("suucces");
- res_code = 0;
- }else
- {
- Console.WriteLine("IMEI is exist!");
- }
- connection.Close();
- return res_code;
- }
- public static int Upload_Bs(string ssn, string bs)
- {
- int res_code = 1;
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- if (!CheckExist("makeserial", " ms_bs ='" + bs + "'"))
- {
- ExecuteSql("update makeserial set ms_bs = '" + bs + "' where ms_sncode = '" + ssn + "' ", "update");
- Console.WriteLine("suucces");
- res_code = 0;
- }
- else
- {
- Console.WriteLine("IMEI is exist!");
- }
- connection.Close();
- return res_code;
- }
- //// 上报 part
- //public static int Upload_par(string ssn, string K, string V)
- //{
- // int ret_code = 1;
- // SqlConnection conn = new SqlConnection(connString);
- // conn.Open();
- // string sql = "update [FactoryData] set " + K + "='" + V + "' where SN='" + ssn + "'";
- // SqlCommand command = new SqlCommand(sql, conn);
- // int num = 0;
- // num = command.ExecuteNonQuery();
- // conn.Close();
- // if (num == 1)
- // {
- // ret_code = 0;
- // }
- // return ret_code;
- //}
- /// <summary>
- /// 获取执行步骤代码,名称和线别
- /// </summary>
- /// <param name="Source"></param>
- /// <param name="StepCode"></param>
- /// <param name="StepName"></param>
- /// <param name="LineCode"></param>
- private static void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
- {
- DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
- if (dt.Rows.Count > 0)
- {
- StepCode = dt.Rows[0]["sc_stepcode"].ToString();
- StepName = dt.Rows[0]["sc_stepname"].ToString();
- LineCode = dt.Rows[0]["sc_linecode"].ToString();
- }
- }
- /// <summary>
- /// 获取步骤代码和名称
- /// </summary>
- /// <param name="Source"></param>
- /// <param name="StepCode"></param>
- /// <param name="StepName"></param>
- private static void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
- {
- DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
- if (dt.Rows.Count > 0)
- {
- StepCode = dt.Rows[0]["sc_stepcode"].ToString();
- StepName = dt.Rows[0]["sc_stepname"].ToString();
- }
- }
- /// <summary>
- /// 获取步骤代码
- /// </summary>
- /// <param name="Source"></param>
- /// <returns></returns>
- private static string GetStepCodeBySource(string Source)
- {
- return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
- }
- /// <summary>
- /// 获取步骤代码
- /// </summary>
- /// <param name="Source"></param>
- /// <returns></returns>
- private static string GetStepName(string st_code)
- {
- return getFieldDataByCondition("step", "st_name", "st_code='" + st_code + "'").ToString();
- }
- /// <summary>
- /// 获取第一行第一列的信息
- /// </summary>
- private static object getFieldDataByCondition(string TableName, string Field, string Condition)
- {
- DataTable dt = new DataTable();
- string sql = "select " + Field + " from " + TableName + " where " + Condition;
- command = new OracleCommand(sql, connection);
- Reconnect(command);
- OracleDataAdapter ad = new OracleDataAdapter();
- ad.SelectCommand = command;
- try
- {
- ad.Fill(dt);
- }
- catch (Exception)
- {
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- command = new OracleCommand(sql, connection);
- ad = new OracleDataAdapter();
- ad.SelectCommand = command;
- ad.Fill(dt);
- }
- ad.Dispose();
- command.Dispose();
- if (dt.Rows.Count > 0)
- {
- return dt.Rows[0][0];
- }
- else
- {
- return "";
- }
- }
- /// <summary>
- /// 通过表名和获取单行的记录
- /// </summary>
- private static DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
- {
- DataTable dt = new DataTable();
- string sql = "select ";
- sql += AddField(Fields);
- sql += " from " + TableName + " where " + Condition + " and rownum=1";
- command = new OracleCommand(sql, connection);
- Reconnect(command);
- OracleDataAdapter ad = new OracleDataAdapter(command);
- try
- {
- ad.Fill(dt);
- }
- catch (Exception)
- {
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- command = new OracleCommand(sql, connection);
- ad = new OracleDataAdapter();
- ad.SelectCommand = command;
- ad.Fill(dt);
- }
- ad.Dispose();
- command.Dispose();
- return dt;
- }
- /// <summary>
- /// 通过表名,字段和条件获取DataTable类型的数据
- /// </summary>
- private static DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
- {
- DataTable dt = new DataTable();
- string sql = "select ";
- sql += AddField(Fields);
- sql += " from " + TableName + " where " + Condition;
- command = new OracleCommand(sql, connection);
- Reconnect(command);
- OracleDataAdapter ad = new OracleDataAdapter(command);
- try
- {
- ad.Fill(dt);
- }
- catch (Exception)
- {
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- command = new OracleCommand(sql, connection);
- ad = new OracleDataAdapter();
- ad.SelectCommand = command;
- ad.Fill(dt);
- }
- ad.Dispose();
- command.Dispose();
- return dt;
- }
- /// <summary>
- /// 通过表名,字段获取DataTable类型的数据
- /// </summary>
- private static DataTable getFieldsDatas(string TableName, string Fields)
- {
- DataTable dt = new DataTable();
- string sql = "select ";
- sql += Fields;
- sql += " from " + TableName;
- command = new OracleCommand(sql, connection);
- Reconnect(command);
- OracleDataAdapter ad = new OracleDataAdapter(command);
- ad.SelectCommand = command;
- try
- {
- ad.Fill(dt);
- }
- catch (Exception)
- {
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- command = new OracleCommand(sql, connection);
- ad = new OracleDataAdapter();
- ad.SelectCommand = command;
- ad.Fill(dt);
- }
- ad.Dispose();
- command.Dispose();
- return dt;
- }
- /// <summary>
- /// 检测内容是否存在
- /// </summary>
- /// <param name="TableName"></param>
- /// <param name="Condition"></param>
- /// <returns></returns>
- private static bool CheckExist(string TableName, string Condition)
- {
- string sql = "select count(1) from " + TableName + " where " + Condition;
- command = new OracleCommand(sql, connection);
- Reconnect(command);
- OracleDataAdapter ad = new OracleDataAdapter(command);
- DataTable dt = new DataTable();
- ad.Fill(dt);
- ad.Dispose();
- command.Dispose();
- return int.Parse(dt.Rows[0][0].ToString()) > 0;
- }
- /// <summary>
- /// 直接执行SQL,同时传入SQL的类型
- /// </summary>
- /// <param name="SQL"></param>
- /// <param name="Type"></param>
- /// <returns></returns>
- private static object ExecuteSql(string SQL, string Type, params object[] names)
- {
- object result = null;
- command = new OracleCommand(SQL, connection);
- Reconnect(command);
- //用来拼接参数的
- if (names.Length > 0)
- {
- string[] par = SQL.Split(':');
- //用来存参数的数组
- StringBuilder[] addpar = new StringBuilder[par.Length - 1];
- for (int i = 0; i < par.Length - 1; i++)
- {
- //新建一个char类型的数组用来存储每个字节的变量
- char[] c = par[i + 1].ToCharArray();
- addpar[i] = new StringBuilder();
- for (int j = 0; j < c.Length; j++)
- {
- if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
- {
- addpar[i].Append(c[j]);
- }
- else
- {
- break;
- }
- }
- }
- for (int i = 0; i < addpar.Length; i++)
- {
- command.Parameters.Add(new OracleParameter(addpar[i].ToString(), names[i]));
- }
- }
- switch (Type.ToUpper())
- {
- case "SELECT":
- OracleDataAdapter ad = new OracleDataAdapter(command);
- result = new DataTable();
- try
- {
- ad.Fill((DataTable)result);
- }
- catch (Exception)
- {
- connection = new OracleConnection(ConnectionStrings);
- connection.Open();
- command = new OracleCommand(SQL, connection);
- ad = new OracleDataAdapter();
- ad.SelectCommand = command;
- ad.Fill((DataTable)result);
- }
- break;
- case "DELETE":
- try
- {
- result = command.ExecuteNonQuery();
- }
- catch (Exception)
- {
- command.Connection = new OracleConnection(ConnectionStrings);
- command.Connection.Open();
- result = command.ExecuteNonQuery();
- }
- break;
- case "UPDATE":
- try
- {
- result = command.ExecuteNonQuery();
- }
- catch (Exception)
- {
- command.Connection = new OracleConnection(ConnectionStrings);
- command.Connection.Open();
- result = command.ExecuteNonQuery();
- }
- break;
- case "INSERT":
- try
- {
- result = command.ExecuteNonQuery();
- }
- catch (Exception)
- {
- command.Connection = new OracleConnection(ConnectionStrings);
- command.Connection.Open();
- result = command.ExecuteNonQuery();
- }
- break;
- }
- command.Dispose();
- return result;
- }
- /// <summary>
- /// 出现异常进行回滚的执行方法
- /// </summary>
- /// <param name="SQL"></param>
- private static void ExecuteSQLTran(params string[] SQL)
- {
- command = new OracleCommand();
- command.Connection = new OracleConnection(ConnectionStrings);
- command.Connection.Open();
- Reconnect(command);
- OracleTransaction tx = command.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
- command.Transaction = tx;
- try
- {
- foreach (string sql in SQL)
- {
- if (!string.IsNullOrEmpty(sql))
- {
- command.CommandText = sql;
- command.ExecuteNonQuery();
- }
- }
- tx.Commit();
- }
- catch (OracleException E)
- {
- tx.Rollback();
- throw new Exception(E.Message);
- }
- command.Dispose();
- }
- private static string UpdateByCondition(string TableName, string update, string condition)
- {
- string sql = "update " + TableName + " set " + update + " where " + condition;
- command = new OracleCommand(sql, connection);
- Reconnect(command);
- try
- {
- command.ExecuteNonQuery();
- }
- catch (Exception)
- {
- command.Connection = new OracleConnection(ConnectionStrings);
- command.Connection.Open();
- command.ExecuteNonQuery();
- }
- command.Dispose();
- return sql;
- }
- private static void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
- {
- command = new OracleCommand(ProcedureName);
- command.Connection = connection;
- Reconnect(command);
- command.CommandText = ProcedureName;
- command.CommandType = CommandType.StoredProcedure;
- for (int i = 0; i < param.Length; i++)
- {
- command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
- //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
- }
- try
- {
- command.ExecuteNonQuery();
- }
- catch (Exception)
- {
- command.Connection = new OracleConnection(ConnectionStrings);
- command.Connection.Open();
- command.ExecuteNonQuery();
- }
- for (int i = 0; i < command.Parameters.Count; i++)
- param[i] = command.Parameters[i].Value.ToString();
- command.Dispose();
- }
- private static string AddField(string[] Fields)
- {
- string sql = " ";
- foreach (string field in Fields)
- {
- sql += field + ",";
- }
- return sql.Substring(0, sql.Length - 1);
- }
- private static string[] GetField(string field)
- {
- string[] fields = field.Split(',');
- for (int i = 0; i < fields.Length; i++)
- {
- fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
- }
- return fields;
- }
- private static void Reconnect(OracleCommand cmd)
- {
- if (cmd.Connection.State == ConnectionState.Closed)
- {
- cmd.Connection.Open();
- }
- }
- private static bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage)
- {
- //取MakeProcess表中的执行记录ID最大的一个工单的号码
- oMoCode = "";
- if (iSN == "")
- {
- oErrMessage = "SN不能为空";
- return false;
- }
- StringBuilder sql = new StringBuilder();
- oErrMessage = "";
- sql.Clear();
- sql.Append("select max(ms_id) from makeserial where ms_sncode in (select '" + iSN + "' from dual union select sn from ");
- sql.Append("makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' ')");
- DataTable dt = (DataTable)ExecuteSql(sql.ToString(), "select");
- string ms_id = dt.Rows[0][0].ToString();
- oMoCode = getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_id='" + ms_id + "'").ToString();
- if (oMoCode != "")
- return true;
- else
- {
- oErrMessage = "序列号:" + iSN + " 未归属工单";
- return false;
- }
- }
- private static bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrMessage)
- {
- if (iSN == "")
- {
- oErrMessage = "SN不能为空";
- return false;
- }
- oErrMessage = "";
- string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
- string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
- CallProcedure("CS_SETSTEPRESULT", ParamName, ref param);
- oErrMessage = param[5];
- if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
- return true;
- else
- return false;
- }
- private static bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
- {
- StringBuilder sql = new StringBuilder();
- if (iSN == "")
- {
- oErrMessage = "SN不能为空";
- return false;
- }
- oErrMessage = "";
- string StepCode = getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
- string CurrentStep = GetStepCodeBySource(iSourceCode);
- string BgCode = getFieldDataByCondition("step", "st_badgroupcode", "st_code='" + CurrentStep + "'").ToString();
- switch (iResult)
- {
- case "OK":
- break;
- case "NG":
- if (iErrCode == "")
- {
- oErrMessage = "测试结果为NG时必须传递不良代码";
- return false;
- }
- else
- {
- UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "' and mb_stepcode='" + CurrentStep + "' and mb_status=0");
- string[] BadCode = iErrCode.Split(',');
- sql.Length = 0;
- sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
- sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select makebad_seq.nextval");
- sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
- sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
- sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
- List<string> InsertSQL = new List<string>();
- for (int i = 0; i < BadCode.Length; i++)
- {
- InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + BadCode[i] + "'"));
- }
- ExecuteSQLTran(InsertSQL.ToArray());
- //将不良的序列号的状态码设为3
- ExecuteSql("update makeserial set ms_status='3' where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'", "update");
- }
- break;
- default:
- oErrMessage = "测试结果必须为NG或者OK";
- return false;
- }
- //不良采集为良品是更新
- if (StepCode == CurrentStep && iResult == "OK")
- {
- DataTable dt = getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_craftcode", "ms_prodcode" }, "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
- if (dt.Rows.Count > 0)
- {
- string ms_status = dt.Rows[0]["ms_status"].ToString();
- string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
- string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
- if (ms_status == "3")
- {
- 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();
- UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
- UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "'");
- }
- }
- }
- return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrMessage);
- }
- }
- }
|