MesHelper.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. using Oracle.ManagedDataAccess.Client;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Web.Script.Serialization;
  9. namespace UMESDLLService
  10. {
  11. [Guid("974DEAD2-9D4C-4728-87EA-2407752E300F")]
  12. [InterfaceType(ComInterfaceType.InterfaceIsDual)]
  13. public interface IMESHelper
  14. {
  15. [DispId(12)]
  16. bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage);
  17. bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage);
  18. bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage);
  19. bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage);
  20. bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
  21. bool SetTestDetail(string iSN, string iTestResult, string iResCode, string[,] iTestDetail, out string oErrMessage);
  22. bool GetMEIOrNetCodeRange(string iSnCode, string iIMEI1, string iNetCode, out string oInfo, out string oErrMessage);
  23. bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage);
  24. bool GetMobileAllInfo(string iSnCode, out string oInfo, out string oErrorMessage);
  25. bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperator, string iResult, string iErrCode, string flag, out string oErrorMessage);
  26. bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage);
  27. bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage);
  28. bool GetInfoByMaterial(string iPCBA, out string oSN, out string oErrMessage);
  29. }
  30. [Guid("5379A8F6-EB38-4A2B-9050-52AD9757E12D")]
  31. [ComSourceInterfaces(typeof(IMESHelper))]
  32. [ClassInterface(ClassInterfaceType.None)]
  33. [ProgId("UMES.DllService.MESHelper")]
  34. public class MESHelper : IMESHelper
  35. {
  36. //用于拼接SQL
  37. StringBuilder sql = new StringBuilder();
  38. //用于存放批量执行的SQL
  39. List<string> sqls = new List<string>();
  40. //系统默认的的连接字符串
  41. private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.101.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  42. //用户选择的数据库的连接字符串
  43. private OracleConnection connection;
  44. //用户选择的数据库的连接字符串
  45. private OracleCommand command = null;
  46. public MESHelper()
  47. {
  48. connection = new OracleConnection(ConnectionStrings);
  49. }
  50. public MESHelper(string IP)
  51. {
  52. connection = new OracleConnection("Data Source=" + IP + "/orcl;User ID=N_MES_T;PassWord=select!#%*(;");
  53. }
  54. public bool GetInfoByMaterial(string iPCBA, out string oSN, out string oErrMessage)
  55. {
  56. oSN = "";
  57. oErrMessage = "";
  58. if (iPCBA == "")
  59. {
  60. oErrMessage = "主板SN不能为空";
  61. }
  62. DataTable dt = (DataTable)ExecuteSql("select ms_firstsn,ms_sncode from CRAFTMATERIAL left join make on cm_makecode=ma_code " +
  63. "left join makeserial on ms_firstsn=cm_firstsn and cm_makecode=ms_makecode where cm_barcode='" + iPCBA + "' and nvl(cm_status,0)<>-1 order by cm_id desc", "select");
  64. if (dt.Rows.Count > 0)
  65. {
  66. oSN = dt.Rows[0]["ms_sncode"].ToString();
  67. }
  68. else
  69. {
  70. oErrMessage = "主板SN未查询到关联信息";
  71. }
  72. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  73. {
  74. return true;
  75. }
  76. else
  77. return false;
  78. }
  79. /// <summary>
  80. /// 检测当前的岗位资源对应的工序
  81. /// </summary>
  82. /// <param name="iSN"></param>
  83. /// <param name="iResCode"></param>
  84. /// <param name="oErrMessage"></param>
  85. /// <returns></returns>
  86. [Description("序列号对应工序检测")]
  87. public bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage)
  88. {
  89. if (iSN == "")
  90. {
  91. oErrMessage = "SN不能为空";
  92. return false;
  93. }
  94. oErrMessage = "";
  95. string[] param = new string[] { "", iResCode, iSN, "", "", "", oErrMessage };
  96. 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" };
  97. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  98. oErrMessage = param[6];
  99. 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 '" + iSN + "' from dual union select sn from makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' '))", "select");
  100. string ms_status = "";
  101. string ms_stepcode = "";
  102. string ms_nextstepcode = "";
  103. if (dt.Rows.Count > 0)
  104. {
  105. ms_status = dt.Rows[0]["ms_status"].ToString();
  106. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  107. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  108. }
  109. string stepcode = GetStepCodeBySource(iResCode);
  110. if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
  111. {
  112. oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
  113. return false;
  114. }
  115. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
  116. {
  117. if (ms_status == "3")
  118. {
  119. oErrMessage = "";
  120. }
  121. DataTable dt1 = (DataTable)ExecuteSql("select 1 from makebadcount where mbc_sncode='" + iSN + "' and mbc_stepcode='" + stepcode + "' and mbc_status=0", "select");
  122. int BadCount = dt1.Rows.Count;
  123. //测试不良3次不允许再测试,必须先维修
  124. if (BadCount == 3)
  125. {
  126. oErrMessage = stepcode + "连续三次测试不良,请进行维修";
  127. return false;
  128. }
  129. return true;
  130. }
  131. else
  132. return false;
  133. }
  134. /// <summary>
  135. /// 验证用户身份信息
  136. /// </summary>
  137. /// <param name="iUserCode"></param>
  138. /// <param name="oErrorMessage"></param>
  139. /// <returns></returns>
  140. private bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
  141. {
  142. oErrorMessage = "";
  143. string SQL = "select em_code from employee where em_code=:UserName and em_password =:PassWord";
  144. DataTable dt;
  145. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode, iPassWord);
  146. if (dt.Rows.Count > 0)
  147. return true;
  148. else
  149. {
  150. oErrorMessage = "用户名或者密码不正确!";
  151. return false;
  152. }
  153. }
  154. /// <summary>
  155. /// 验证用户身份信息和岗位资源
  156. /// </summary>
  157. /// <param name="iUserCode"></param>
  158. /// <param name="iResCode"></param>
  159. /// <param name="oErrMessage"></param>
  160. /// <returns></returns>
  161. [Description("验证身份信息")]
  162. public bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage)
  163. {
  164. oErrMessage = "";
  165. if (iUserCode == "" || iPassWord == "" || iResCode == "")
  166. {
  167. oErrMessage = "用户名,密码,岗位资源必须填写";
  168. return false;
  169. }
  170. if (CheckUserLogin(iUserCode, iPassWord, out oErrMessage))
  171. {
  172. string SQL = "select em_code,em_type,em_name from employee where em_code=:UserName ";
  173. DataTable dt;
  174. dt = (DataTable)ExecuteSql(SQL, "select", iUserCode);
  175. if (dt.Rows.Count > 0)
  176. {
  177. string em_name = dt.Rows[0]["em_name"].ToString();
  178. string em_type = dt.Rows[0]["em_type"].ToString();
  179. if (iResCode == "")
  180. {
  181. oErrMessage = "岗位资源不允许为空";
  182. return false;
  183. }
  184. if (em_type == "admin")
  185. {
  186. if (CheckExist("Source", "sc_code='" + iResCode + "' and sc_statuscode='AUDITED'"))
  187. {
  188. return true;
  189. }
  190. else
  191. {
  192. oErrMessage = "岗位资源编号错误或者未审核!";
  193. return false;
  194. }
  195. }
  196. else
  197. {
  198. dt = getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "ur_resourcecode" }, "eg_emcode = '" + iUserCode + "' and sc_statuscode='AUDITED'");
  199. //如果存在该编号
  200. if (dt.Rows.Count > 0)
  201. {
  202. //判断如果多个岗位资源存在,用户输入的只要在其中就行
  203. for (int i = 0; i < dt.Rows.Count; i++)
  204. {
  205. if (dt.Rows[i]["ur_resourcecode"].ToString() == iResCode)
  206. return true;
  207. }
  208. oErrMessage = "用户不处于当前资源所属分组!";
  209. }
  210. else
  211. oErrMessage = "岗位资源编号错误或者未审核!";
  212. }
  213. }
  214. else
  215. oErrMessage = "用户不存在!";
  216. }
  217. return false;
  218. }
  219. /// <summary>
  220. /// 分配Mac地址和BT地址
  221. /// </summary>
  222. /// <param name="iSN"></param>
  223. /// <param name="oWIFI"></param>
  224. /// <param name="oBT"></param>
  225. /// <param name="oCode1"></param>
  226. /// <param name="oCode2"></param>
  227. /// <param name="oCdoe3"></param>
  228. /// <param name="oErrMessage"></param>
  229. /// <returns></returns>
  230. [Description("分配MAC和BT信息")]
  231. public bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage)
  232. {
  233. oInfo = "";
  234. string oWIFI = "";
  235. string oBT = "";
  236. string oCode1 = "";
  237. string oCode2 = "";
  238. string oCdoe3 = "";
  239. if (iSN == "")
  240. {
  241. oErrMessage = "SN不能为空";
  242. return false;
  243. }
  244. oErrMessage = "";
  245. string omakeCode = "";
  246. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  247. string[] param = new string[] { iSN, omakeCode, oWIFI, oBT, oCode1, oCode2, oCdoe3, oErrMessage };
  248. string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_o_mac", "v_o_bt", "v_o_code1", "v_o_code2", "v_o_code3", "v_o_errmsg" };
  249. CallProcedure("CS_GETADDRESSBYMAKECODE", ParamName, ref param);
  250. oInfo += "MAC:"+param[2].ToString() + "^";
  251. oInfo += "BT:" + param[3].ToString() + "^";
  252. oInfo += "Code1:" + param[4].ToString() + "^";
  253. oInfo += "Code2:" + param[5].ToString() + "^";
  254. oInfo += "Code3:" + param[6].ToString() + "";
  255. oErrMessage = param[7];
  256. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  257. return true;
  258. else
  259. return false;
  260. }
  261. /// <summary>
  262. /// 输入的 SN 号查找在制品是否有 IMEI 信息存在,如果存在则将 IMEI 信息传出,如果没有则在该工单下未使用的 IMEI 中随机分配一组
  263. /// 如果iIMEI1、iNetCode不为空,则分别作为获取的附件加条件。
  264. /// </summary>
  265. /// <param name="iSN"></param>
  266. /// <param name="iIMEI1"></param>
  267. /// <param name="iNetCode"></param>
  268. /// <param name="oIMEI1"></param>
  269. /// <param name="oIMEI2"></param>
  270. /// <param name="oIMEI3"></param>
  271. /// <param name="oMEID"></param>
  272. /// <param name="oNetCode"></param>
  273. /// <param name="oPSN"></param>
  274. /// <param name="oID1"></param>
  275. /// <param name="oID2"></param>
  276. /// <param name="oID3"></param>
  277. /// <param name="oErrMessage"></param>
  278. /// <returns></returns>
  279. [Description("分配IMEI和NetCode信息")]
  280. public bool GetMEIOrNetCodeRange(string iSN, string iIMEI1, string iNetCode, out string oInfo, out string oErrMessage)
  281. {
  282. oInfo = "";
  283. string oIMEI1 = "";
  284. string oIMEI2 = "";
  285. string oMEID = "";
  286. string oNetCode = "";
  287. string oPSN = "";
  288. string oID1 = "";
  289. string oID2 = "";
  290. string oID3 = "";
  291. if (iSN == "")
  292. {
  293. oErrMessage = "SN不能为空";
  294. return false;
  295. }
  296. oErrMessage = "";
  297. string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, "", oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
  298. string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_i_imei", "v_i_netcode", "v_o_imei1", "v_o_imei2", "v_o_imei3", "v_o_meid", "v_o_netcode", "v_o_psn", "v_o_id1", "v_o_id2", "v_o_id3", "v_o_errmsg" };
  299. CallProcedure("CS_GETIMEIORNETCODERANGE", ParamName, ref param);
  300. oInfo += "IMEI1:" + param[4].ToString() + "^";
  301. oInfo += "IMEI2:" + param[5].ToString() + "^";
  302. oInfo += "MEID:" + param[7].ToString() + "^";
  303. oInfo += "NETCODE:" + param[8].ToString() + "^";
  304. oInfo += "PSN:" + param[9].ToString() + "";
  305. oInfo += "ID1:" + param[10].ToString() + "";
  306. oInfo += "ID2:" + param[11].ToString() + "";
  307. oInfo += "ID3:" + param[12].ToString() + "";
  308. oErrMessage = param[13];
  309. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  310. return true;
  311. else
  312. return false;
  313. }
  314. /// <summary>
  315. /// 获取工单的最近一条执行记录
  316. /// </summary>
  317. /// <param name="iSN"></param>
  318. /// <param name="oMoCode"></param>
  319. /// <param name="oErrMessage"></param>
  320. /// <returns></returns>
  321. [Description("获取序列号对应工单信息")]
  322. public bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage)
  323. {
  324. //取MakeProcess表中的执行记录ID最大的一个工单的号码
  325. oMoCode = "";
  326. if (iSN == "")
  327. {
  328. oErrMessage = "SN不能为空";
  329. return false;
  330. }
  331. oErrMessage = "";
  332. sql.Clear();
  333. sql.Append("select max(ms_id) from makeserial where ms_sncode in (select '" + iSN + "' from dual union select sn from ");
  334. sql.Append("makesnrelation where beforesn='" + iSN + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' ')");
  335. DataTable dt = (DataTable)ExecuteSql(sql.ToString(), "select");
  336. string ms_id = dt.Rows[0][0].ToString();
  337. oMoCode = getFieldDataByCondition("MakeSerial", "ms_makecode", "ms_id='" + ms_id + "'").ToString();
  338. if (oMoCode != "")
  339. return true;
  340. else
  341. {
  342. oErrMessage = "序列号:" + iSN + " 未归属工单";
  343. return false;
  344. }
  345. }
  346. /// <summary>
  347. /// 获取序列号的所有串号信息
  348. /// </summary>
  349. /// <param name="iSN"></param>
  350. /// <param name="oWIFI"></param>
  351. /// <param name="oBT"></param>
  352. /// <param name="oCode1"></param>
  353. /// <param name="oCode2"></param>
  354. /// <param name="oCode3"></param>
  355. /// <param name="oIMEI1"></param>
  356. /// <param name="oIMEI2"></param>
  357. /// <param name="oIMEI3"></param>
  358. /// <param name="oMEID"></param>
  359. /// <param name="oNetCode"></param>
  360. /// <param name="oPSN"></param>
  361. /// <param name="oID1"></param>
  362. /// <param name="oID2"></param>
  363. /// <param name="oID3"></param>
  364. /// <param name="oID4"></param>
  365. /// <param name="oID5"></param>
  366. /// <param name="oErrMessage"></param>
  367. /// <returns></returns>
  368. [Description("查询已分配的信息")]
  369. public bool GetMobileAllInfo(string iSN, out string oJson, out string oErrMessage)
  370. {
  371. JavaScriptSerializer jss = new JavaScriptSerializer();
  372. Dictionary<string, string> oInfo = new Dictionary<string, string>();
  373. oErrMessage = "";
  374. oJson = "";
  375. if (iSN == "")
  376. {
  377. oErrMessage = "SN不能为空";
  378. return false;
  379. }
  380. string MacInfo;
  381. if (!GetAddressRangeByMO(iSN, out MacInfo, out oErrMessage))
  382. {
  383. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  384. return true;
  385. else
  386. return false;
  387. }
  388. string MAC = MacInfo.Split('^')[0].Replace("MAC:", "");
  389. string BT = MacInfo.Split('^')[1].Replace("BT:", "");
  390. string TCode1 = MacInfo.Split('^')[2].Replace("Code1:", "");
  391. string TCode2 = MacInfo.Split('^')[3].Replace("Code2:", "");
  392. string TCode3 = MacInfo.Split('^')[4].Replace("Code3:", "");
  393. if (!SetAddressInfo(iSN, MAC == "null" ? "" : MAC, BT == "null" ? "" : BT, TCode1 == "null" ? "" :TCode1,TCode2 == "null" ? "" :TCode2,TCode3 == "null" ? "" :TCode3, out oErrMessage))
  394. {
  395. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  396. return true;
  397. else
  398. return false;
  399. }
  400. //通过序列号获取最近操作的工单号
  401. string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'").ToString();
  402. if (ms_id != "")
  403. {
  404. DataTable dt = getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_id='" + ms_id + "'");
  405. if (dt.Rows.Count > 0)
  406. {
  407. string Code1 = "";
  408. string Code2 = "";
  409. string Code3 = "";
  410. string Code4 = "";
  411. string Code5 = "";
  412. string Code6 = "";
  413. string Code7 = "";
  414. string Code8 = "";
  415. string Code9 = "";
  416. string Code10 = "";
  417. string Code11 = "";
  418. string Code12 = "";
  419. string Code13 = "";
  420. string Code14 = "";
  421. string Code15 = "";
  422. string Code16 = "";
  423. string Code17 = "";
  424. string Code18 = "";
  425. string Code19 = "";
  426. string Code20 = "";
  427. string Code21 = "";
  428. string Code22 = "";
  429. string Code23 = "";
  430. string Code24 = "";
  431. string Code25 = "";
  432. string[] param = new string[] { ms_id, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15, Code16, Code17, Code18, Code19, Code20, Code21, Code22, Code23, Code24, Code25 };
  433. string[] ParamName = new string[] { "v_ms_id", "v_i_code1", "v_i_code2", "v_i_code3", "v_i_code4", "v_i_code5", "v_i_code6", "v_i_code7", "v_i_code8", "v_i_code9", "v_i_code10", "v_i_code11", "v_i_code12", "v_i_code13", "v_i_code14", "v_i_code15", "v_i_code16", "v_i_code17", "v_i_code18", "v_i_code19", "v_i_code20", "v_i_code21", "v_i_code22", "v_i_code23", "v_i_code24", "v_i_code25" };
  434. CallProcedure("GetMobileAllInfo_NEW", ParamName, ref param);
  435. for (int i = 1; i < param.Length; i++)
  436. {
  437. //获取出来的参数使用^分割
  438. if (param[i] != "" && param[i] != "null" && param[i] != null)
  439. {
  440. oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
  441. }
  442. }
  443. oJson = jss.Serialize(oInfo);
  444. oErrMessage = "";
  445. return true;
  446. }
  447. else
  448. {
  449. oErrMessage = "序列号" + iSN + "不存在";
  450. return false;
  451. }
  452. }
  453. else
  454. {
  455. oErrMessage = "序列号" + iSN + "不存在";
  456. return false;
  457. }
  458. }
  459. /// <summary>
  460. /// 记录操作日志
  461. /// </summary>
  462. /// <param name="iSnCode"></param>
  463. /// <param name="iMakeCode"></param>
  464. /// <param name="iMPKind"></param>
  465. /// <param name="result"></param>
  466. /// <param name="iUserCode"></param>
  467. private void InsertMakeProcess(string iSnCode, string iMakeCode, string iSourceCode, string iMPKind, string result, string iUserCode)
  468. {
  469. string CurrentStep = "";
  470. string LineCode = "";
  471. string CurrentStepName = "";
  472. GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
  473. sql.Length = 0;
  474. sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,");
  475. sql.Append("mp_craftcode,mp_craftname,mp_kind,mp_result,mp_indate,mp_inman,mp_wccode,mp_linecode,mp_sourcecode,mp_snstatus,mp_sncheckno,mp_snoutboxcode)");
  476. sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,'" + CurrentStep + "','" + CurrentStepName + "',");
  477. sql.Append("ma_craftcode,ma_craftname,'" + iMPKind + "','" + result + "',sysdate,'" + iUserCode + "',ma_wccode,'" + LineCode + "','" + iSourceCode + "',");
  478. sql.Append("ms_status,ms_checkno,ms_outboxcode from make left join makeserial on ms_makecode=ma_code left join step on st_code=ms_stepcode ");
  479. sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "' and st_code='" + CurrentStep + "'");
  480. ExecuteSql(sql.ToString(), "insert");
  481. }
  482. /// <summary>
  483. /// 保存Mac地址和BT地址
  484. /// </summary>
  485. /// <param name="iSN"></param>
  486. /// <param name="iMac"></param>
  487. /// <param name="iBT"></param>
  488. /// <param name="iCode1"></param>
  489. /// <param name="iCode2"></param>
  490. /// <param name="iCode3"></param>
  491. /// <param name="oErrMessage"></param>
  492. /// <returns></returns>
  493. [Description("写入SN的Wifi,BT信息")]
  494. public bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrMessage)
  495. {
  496. if (iSN == "")
  497. {
  498. oErrMessage = "SN不能为空";
  499. return false;
  500. }
  501. oErrMessage = "";
  502. string[] param = new string[] { iSN, iMac, iBT, iCode1, iCode2, iCode3, oErrMessage };
  503. string[] ParamName = new string[] { "v_i_sncode", "v_i_mac", "v_i_bt", "v_i_code1", "v_i_code2", "v_i_code3", "v_o_errmsg" };
  504. CallProcedure("CS_SETADDRESSINFO", ParamName, ref param);
  505. oErrMessage = param[6];
  506. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  507. return true;
  508. else
  509. return false;
  510. }
  511. [Description("序列号跳到下一 步")]
  512. private bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
  513. {
  514. if (iSN == "")
  515. {
  516. oErrMessage = "SN不能为空";
  517. return false;
  518. }
  519. oErrMessage = "";
  520. string StepCode = getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
  521. string CurrentStep = GetStepCodeBySource(iSourceCode);
  522. string BgCode = getFieldDataByCondition("step", "st_badgroupcode", "st_code='" + CurrentStep + "'").ToString();
  523. switch (iResult)
  524. {
  525. case "OK":
  526. break;
  527. case "NG":
  528. if (iErrCode == "")
  529. {
  530. oErrMessage = "测试结果为NG时必须传递不良代码";
  531. return false;
  532. }
  533. else
  534. {
  535. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "' and mb_stepcode='" + CurrentStep + "' and mb_status=0");
  536. string[] BadCode = iErrCode.Split(',');
  537. sql.Length = 0;
  538. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  539. sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select makebad_seq.nextval");
  540. sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
  541. sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  542. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  543. List<string> InsertSQL = new List<string>();
  544. for (int i = 0; i < BadCode.Length; i++)
  545. {
  546. InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + BadCode[i] + "'"));
  547. }
  548. ExecuteSQLTran(InsertSQL.ToArray());
  549. //将不良的序列号的状态码设为3
  550. ExecuteSql("update makeserial set ms_status='3' where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'", "update");
  551. }
  552. break;
  553. default:
  554. oErrMessage = "测试结果必须为NG或者OK";
  555. return false;
  556. }
  557. //不良采集为良品是更新
  558. if (StepCode == CurrentStep && iResult == "OK")
  559. {
  560. DataTable dt = getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_craftcode", "ms_prodcode" }, "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  561. if (dt.Rows.Count > 0)
  562. {
  563. string ms_status = dt.Rows[0]["ms_status"].ToString();
  564. string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  565. string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  566. if (ms_status == "3")
  567. {
  568. 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();
  569. UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
  570. UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "'");
  571. }
  572. }
  573. }
  574. return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrMessage);
  575. }
  576. /// <summary>
  577. /// 设置测试结果
  578. /// </summary>
  579. /// <param name="iMakeCode"></param>
  580. /// <param name="iSourceCode"></param>
  581. /// <param name="iSN"></param>
  582. /// <param name="iOperater"></param>
  583. /// <param name="iResult"></param>
  584. /// <param name="iUserCode"></param>
  585. /// <param name="oErrorMessage"></param>
  586. /// <returns></returns>
  587. [Description("设置测试结果,结果必须为NG或者OK")]
  588. public bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperater, string iResult, string iErrCode, string flag, out string oErrorMessage)
  589. {
  590. oErrorMessage = "";
  591. if (iTSN == "") { oErrorMessage = "TSN不能为空"; return false; }
  592. if (iSN == "") { oErrorMessage = "SN不能为空"; return false; }
  593. string[] param = new string[] { iTSN, iSN, iSourceCode, iOperater, iResult, iErrCode, oErrorMessage };
  594. string[] ParamName = new string[] { "v_i_tsn", "v_i_sncode", "v_i_sourcecode", "v_i_usercode", "v_i_result", "v_i_errcode", "v_o_errmsg" };
  595. CallProcedure("CS_DLLSNCHANGE_TOOL", ParamName, ref param);
  596. oErrorMessage = param[6];
  597. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  598. return true;
  599. else
  600. return false;
  601. }
  602. private bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrMessage)
  603. {
  604. if (iSN == "")
  605. {
  606. oErrMessage = "SN不能为空";
  607. return false;
  608. }
  609. oErrMessage = "";
  610. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
  611. string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
  612. CallProcedure("CS_SETSTEPRESULT_TOOL", ParamName, ref param);
  613. oErrMessage = param[5];
  614. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  615. return true;
  616. else
  617. return false;
  618. }
  619. /// <summary>
  620. /// 方法说明:测试详细信息录入系统,针对一个SN多个测试项目结果可循环调用
  621. /// </summary>
  622. /// <param name="iSN">序列号</param>
  623. /// <param name="iClass"></param>
  624. /// <param name="iSubClass1"></param>
  625. /// <param name="iSubClass2"></param>
  626. /// <param name="iSubClass3"></param>
  627. /// <param name="iMaxValue"></param>
  628. /// <param name="iMinValue"></param>
  629. /// <param name="iActualValue"></param>
  630. /// <param name="iValue1"></param>
  631. /// <param name="iValue2"></param>
  632. /// <param name="iValue3"></param>
  633. /// <param name="iTestResult"></param>
  634. /// <param name="oErrMessage"></param>
  635. /// <returns></returns>
  636. [Description("设置测试结果")]
  637. public bool SetTestDetail(string iSN, string iClass, string iResCode, string[,] iTestDetail, out string oErrMessage)
  638. {
  639. if (iSN == "" || iSN == null)
  640. {
  641. oErrMessage = "SN不能为空";
  642. return false;
  643. }
  644. oErrMessage = "";
  645. string omakeCode = "";
  646. GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
  647. sql.Clear();
  648. sql.Append("begin ");
  649. bool needBreak = false;
  650. for (int i = 0; i < iTestDetail.Length / 200; i++)
  651. {
  652. string DataField = "Insert into MES_TEST(STD_ID,STD_SN,STD_MAKECODE,STD_CLASS,STD_TESTDATE,";
  653. string ValueField = ")values(MES_TEST_SEQ.nextval,'" + iSN + "','" + omakeCode + "','" + iClass + "',sysdate,";
  654. for (int j = 0; j < 200; j++)
  655. {
  656. if (j == 0)
  657. {
  658. DataField += "STD_ITEMNAME,";
  659. //如果传递的参数没有测试名称则中断插入
  660. if (iTestDetail[i, j] == "" || iTestDetail[i, j] == null)
  661. {
  662. //外层循环也需要中断
  663. needBreak = true;
  664. break;
  665. }
  666. }
  667. else
  668. {
  669. DataField += "STD_ITEM" + j + " ,";
  670. }
  671. ValueField += "'" + iTestDetail[i, j] + "',";
  672. }
  673. if (needBreak)
  674. break;
  675. sql.Append(DataField.Substring(0, DataField.Length - 1) + ValueField.Substring(0, ValueField.Length - 1) + ");");
  676. }
  677. sql.Append("end;");
  678. ExecuteSql(sql.ToString(), "insert");
  679. return true;
  680. }
  681. /// <summary>
  682. /// 作业调用该方法将确认接收SN对应的IMEI及附属信息。
  683. /// </summary>
  684. /// <param name="iSN"></param>
  685. /// <param name="iMO"></param>
  686. /// <param name="iIMEI1"></param>
  687. /// <param name="iIMEI2"></param>
  688. /// <param name="iIMEI3"></param>
  689. /// <param name="iMEID"></param>
  690. /// <param name="iNetCode"></param>
  691. /// <param name="iPSN"></param>
  692. /// <param name="iID1"></param>
  693. /// <param name="iBT"></param>
  694. /// <param name="iID1"></param>
  695. /// <param name="iID2"></param>
  696. /// <param name="iID3"></param>
  697. /// <param name="oErrorMessage"></param>
  698. /// <returns></returns>
  699. [Description("设置IMEI信息")]
  700. public bool SetIMEIInfo(string iSN, string iIMEI1,string iIMEI2,string iIMEI3,string iMEID,string iNETCODE,string iID1,string iID2,string iID3, out string oErrMessage)
  701. {
  702. if (iSN == "")
  703. {
  704. oErrMessage = "SN不能为空";
  705. return false;
  706. }
  707. oErrMessage = "";
  708. string[] param = new string[] { iSN, iIMEI1, iIMEI2, iIMEI3, iMEID, iNETCODE, "", iID1, iID2, iID3, oErrMessage };
  709. string[] ParamName = new string[] { "v_i_sncode", "v_i_imei1", "v_i_imei2", "v_i_imei3", "v_i_meid", "v_i_netcode", "v_i_psn", "v_i_id1", "v_i_id2", "v_i_id3", "v_o_errmsg" };
  710. CallProcedure("CS_SETIMEIINFO", ParamName, ref param);
  711. oErrMessage = param[10];
  712. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  713. return true;
  714. else
  715. return false;
  716. }
  717. /// <summary>
  718. ///
  719. /// </summary>
  720. /// <param name="iSN"></param>
  721. /// <param name="iResCode"></param>
  722. /// <param name="iOperator"></param>
  723. /// <param name="iResult"></param>
  724. /// <param name="iErrCode"></param>
  725. /// <param name="oErrMessage"></param>
  726. /// <returns></returns>
  727. [Description("设置测试结果")]
  728. public bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage)
  729. {
  730. if (iSN == "")
  731. {
  732. oErrMessage = "SN不能为空";
  733. return false;
  734. }
  735. oErrMessage = "";
  736. string oMakeCode = "";
  737. GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
  738. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
  739. return SetStepFinish(oMakeCode, iResCode, iSN, "", iResult, iOperator, iErrCode, out oErrMessage);
  740. else
  741. return false;
  742. }
  743. /// <summary>
  744. /// 序列号归属工单
  745. /// </summary>
  746. /// <param name="iMO"></param>
  747. /// <param name="iSN"></param>
  748. /// <param name="iResCode"></param>
  749. /// <param name="oErrMessage"></param>
  750. /// <returns></returns>
  751. [Description("序列号归属工单")]
  752. public bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage)
  753. {
  754. if (iSN == "")
  755. {
  756. oErrMessage = "SN不能为空";
  757. return false;
  758. }
  759. oErrMessage = "";
  760. string[] param = new string[] { iMO, iResCode, iSN, "", "", "", oErrMessage };
  761. 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" };
  762. CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
  763. oErrMessage = param[6];
  764. 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='" + iSN + "')", "select");
  765. string ms_status = "";
  766. string ms_stepcode = "";
  767. string ms_nextstepcode = "";
  768. if (dt.Rows.Count > 0)
  769. {
  770. ms_status = dt.Rows[0]["ms_status"].ToString();
  771. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  772. ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  773. }
  774. string stepcode = GetStepCodeBySource(iResCode);
  775. if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && ms_stepcode == stepcode))
  776. {
  777. if (ms_status == "3")
  778. {
  779. oErrMessage = "";
  780. }
  781. return true;
  782. }
  783. else
  784. return false;
  785. }
  786. /// <summary>
  787. /// 获取执行步骤代码,名称和线别
  788. /// </summary>
  789. /// <param name="Source"></param>
  790. /// <param name="StepCode"></param>
  791. /// <param name="StepName"></param>
  792. /// <param name="LineCode"></param>
  793. private void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
  794. {
  795. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  796. if (dt.Rows.Count > 0)
  797. {
  798. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  799. StepName = dt.Rows[0]["sc_stepname"].ToString();
  800. LineCode = dt.Rows[0]["sc_linecode"].ToString();
  801. }
  802. }
  803. /// <summary>
  804. /// 获取步骤代码和名称
  805. /// </summary>
  806. /// <param name="Source"></param>
  807. /// <param name="StepCode"></param>
  808. /// <param name="StepName"></param>
  809. private void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  810. {
  811. DataTable dt = getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  812. if (dt.Rows.Count > 0)
  813. {
  814. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  815. StepName = dt.Rows[0]["sc_stepname"].ToString();
  816. }
  817. }
  818. /// <summary>
  819. /// 获取步骤代码
  820. /// </summary>
  821. /// <param name="Source"></param>
  822. /// <returns></returns>
  823. private string GetStepCodeBySource(string Source)
  824. {
  825. return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
  826. }
  827. /// <summary>
  828. /// 获取步骤代码
  829. /// </summary>
  830. /// <param name="Source"></param>
  831. /// <returns></returns>
  832. private string GetStepName(string st_code)
  833. {
  834. return getFieldDataByCondition("step", "st_name", "st_code='" + st_code + "'").ToString();
  835. }
  836. /// <summary>
  837. /// 获取第一行第一列的信息
  838. /// </summary>
  839. private object getFieldDataByCondition(string TableName, string Field, string Condition)
  840. {
  841. DataTable dt = new DataTable();
  842. string sql = "select " + Field + " from " + TableName + " where " + Condition;
  843. command = new OracleCommand(sql, connection);
  844. Reconnect(command);
  845. OracleDataAdapter ad = new OracleDataAdapter();
  846. ad.SelectCommand = command;
  847. try
  848. {
  849. ad.Fill(dt);
  850. }
  851. catch (Exception)
  852. {
  853. connection = new OracleConnection(ConnectionStrings);
  854. connection.Open();
  855. command = new OracleCommand(sql, connection);
  856. ad = new OracleDataAdapter();
  857. ad.SelectCommand = command;
  858. ad.Fill(dt);
  859. }
  860. ad.Dispose();
  861. command.Dispose();
  862. if (dt.Rows.Count > 0)
  863. {
  864. return dt.Rows[0][0];
  865. }
  866. else
  867. {
  868. return "";
  869. }
  870. }
  871. /// <summary>
  872. /// 通过表名和获取单行的记录
  873. /// </summary>
  874. private DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
  875. {
  876. DataTable dt = new DataTable();
  877. string sql = "select ";
  878. sql += AddField(Fields);
  879. sql += " from " + TableName + " where " + Condition + " and rownum=1";
  880. command = new OracleCommand(sql, connection);
  881. Reconnect(command);
  882. OracleDataAdapter ad = new OracleDataAdapter(command);
  883. try
  884. {
  885. ad.Fill(dt);
  886. }
  887. catch (Exception)
  888. {
  889. connection = new OracleConnection(ConnectionStrings);
  890. connection.Open();
  891. command = new OracleCommand(sql, connection);
  892. ad = new OracleDataAdapter();
  893. ad.SelectCommand = command;
  894. ad.Fill(dt);
  895. }
  896. ad.Dispose();
  897. command.Dispose();
  898. return dt;
  899. }
  900. /// <summary>
  901. /// 通过表名,字段和条件获取DataTable类型的数据
  902. /// </summary>
  903. private DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
  904. {
  905. DataTable dt = new DataTable();
  906. string sql = "select ";
  907. sql += AddField(Fields);
  908. sql += " from " + TableName + " where " + Condition;
  909. command = new OracleCommand(sql, connection);
  910. Reconnect(command);
  911. OracleDataAdapter ad = new OracleDataAdapter(command);
  912. try
  913. {
  914. ad.Fill(dt);
  915. }
  916. catch (Exception)
  917. {
  918. connection = new OracleConnection(ConnectionStrings);
  919. connection.Open();
  920. command = new OracleCommand(sql, connection);
  921. ad = new OracleDataAdapter();
  922. ad.SelectCommand = command;
  923. ad.Fill(dt);
  924. }
  925. ad.Dispose();
  926. command.Dispose();
  927. return dt;
  928. }
  929. /// <summary>
  930. /// 通过表名,字段获取DataTable类型的数据
  931. /// </summary>
  932. private DataTable getFieldsDatas(string TableName, string Fields)
  933. {
  934. DataTable dt = new DataTable();
  935. string sql = "select ";
  936. sql += Fields;
  937. sql += " from " + TableName;
  938. command = new OracleCommand(sql, connection);
  939. Reconnect(command);
  940. OracleDataAdapter ad = new OracleDataAdapter(command);
  941. ad.SelectCommand = command;
  942. try
  943. {
  944. ad.Fill(dt);
  945. }
  946. catch (Exception)
  947. {
  948. connection = new OracleConnection(ConnectionStrings);
  949. connection.Open();
  950. command = new OracleCommand(sql, connection);
  951. ad = new OracleDataAdapter();
  952. ad.SelectCommand = command;
  953. ad.Fill(dt);
  954. }
  955. ad.Dispose();
  956. command.Dispose();
  957. return dt;
  958. }
  959. /// <summary>
  960. /// 检测内容是否存在
  961. /// </summary>
  962. /// <param name="TableName"></param>
  963. /// <param name="Condition"></param>
  964. /// <returns></returns>
  965. private bool CheckExist(string TableName, string Condition)
  966. {
  967. string sql = "select count(1) from " + TableName + " where " + Condition;
  968. command = new OracleCommand(sql, connection);
  969. Reconnect(command);
  970. OracleDataAdapter ad = new OracleDataAdapter(command);
  971. DataTable dt = new DataTable();
  972. ad.Fill(dt);
  973. ad.Dispose();
  974. command.Dispose();
  975. return int.Parse(dt.Rows[0][0].ToString()) > 0;
  976. }
  977. /// <summary>
  978. /// 直接执行SQL,同时传入SQL的类型
  979. /// </summary>
  980. /// <param name="SQL"></param>
  981. /// <param name="Type"></param>
  982. /// <returns></returns>
  983. private object ExecuteSql(string SQL, string Type, params object[] names)
  984. {
  985. object result = null;
  986. command = new OracleCommand(SQL, connection);
  987. Reconnect(command);
  988. //用来拼接参数的
  989. if (names.Length > 0)
  990. {
  991. string[] par = SQL.Split(':');
  992. //用来存参数的数组
  993. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  994. for (int i = 0; i < par.Length - 1; i++)
  995. {
  996. //新建一个char类型的数组用来存储每个字节的变量
  997. char[] c = par[i + 1].ToCharArray();
  998. addpar[i] = new StringBuilder();
  999. for (int j = 0; j < c.Length; j++)
  1000. {
  1001. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  1002. {
  1003. addpar[i].Append(c[j]);
  1004. }
  1005. else
  1006. {
  1007. break;
  1008. }
  1009. }
  1010. }
  1011. for (int i = 0; i < addpar.Length; i++)
  1012. {
  1013. command.Parameters.Add(new OracleParameter(addpar[i].ToString(), names[i]));
  1014. }
  1015. }
  1016. switch (Type.ToUpper())
  1017. {
  1018. case "SELECT":
  1019. OracleDataAdapter ad = new OracleDataAdapter(command);
  1020. result = new DataTable();
  1021. try
  1022. {
  1023. ad.Fill((DataTable)result);
  1024. }
  1025. catch (Exception)
  1026. {
  1027. connection = new OracleConnection(ConnectionStrings);
  1028. connection.Open();
  1029. command = new OracleCommand(SQL, connection);
  1030. ad = new OracleDataAdapter();
  1031. ad.SelectCommand = command;
  1032. ad.Fill((DataTable)result);
  1033. }
  1034. break;
  1035. case "DELETE":
  1036. try
  1037. {
  1038. result = command.ExecuteNonQuery();
  1039. }
  1040. catch (Exception)
  1041. {
  1042. command.Connection = new OracleConnection(ConnectionStrings);
  1043. command.Connection.Open();
  1044. result = command.ExecuteNonQuery();
  1045. }
  1046. break;
  1047. case "UPDATE":
  1048. try
  1049. {
  1050. result = command.ExecuteNonQuery();
  1051. }
  1052. catch (Exception)
  1053. {
  1054. command.Connection = new OracleConnection(ConnectionStrings);
  1055. command.Connection.Open();
  1056. result = command.ExecuteNonQuery();
  1057. }
  1058. break;
  1059. case "INSERT":
  1060. try
  1061. {
  1062. result = command.ExecuteNonQuery();
  1063. }
  1064. catch (Exception)
  1065. {
  1066. command.Connection = new OracleConnection(ConnectionStrings);
  1067. command.Connection.Open();
  1068. result = command.ExecuteNonQuery();
  1069. }
  1070. break;
  1071. }
  1072. command.Dispose();
  1073. return result;
  1074. }
  1075. /// <summary>
  1076. /// 出现异常进行回滚的执行方法
  1077. /// </summary>
  1078. /// <param name="SQL"></param>
  1079. private void ExecuteSQLTran(params string[] SQL)
  1080. {
  1081. command = new OracleCommand();
  1082. command.Connection = new OracleConnection(ConnectionStrings);
  1083. command.Connection.Open();
  1084. Reconnect(command);
  1085. OracleTransaction tx = command.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
  1086. command.Transaction = tx;
  1087. try
  1088. {
  1089. foreach (string sql in SQL)
  1090. {
  1091. if (!string.IsNullOrEmpty(sql))
  1092. {
  1093. command.CommandText = sql;
  1094. command.ExecuteNonQuery();
  1095. }
  1096. }
  1097. tx.Commit();
  1098. }
  1099. catch (OracleException E)
  1100. {
  1101. tx.Rollback();
  1102. throw new Exception(E.Message);
  1103. }
  1104. command.Dispose();
  1105. }
  1106. private string UpdateByCondition(string TableName, string update, string condition)
  1107. {
  1108. string sql = "update " + TableName + " set " + update + " where " + condition;
  1109. command = new OracleCommand(sql, connection);
  1110. Reconnect(command);
  1111. try
  1112. {
  1113. command.ExecuteNonQuery();
  1114. }
  1115. catch (Exception)
  1116. {
  1117. command.Connection = new OracleConnection(ConnectionStrings);
  1118. command.Connection.Open();
  1119. command.ExecuteNonQuery();
  1120. }
  1121. command.Dispose();
  1122. return sql;
  1123. }
  1124. private void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
  1125. {
  1126. command = new OracleCommand(ProcedureName);
  1127. command.Connection = connection;
  1128. Reconnect(command);
  1129. command.CommandText = ProcedureName;
  1130. command.CommandType = CommandType.StoredProcedure;
  1131. for (int i = 0; i < param.Length; i++)
  1132. {
  1133. command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
  1134. //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
  1135. }
  1136. try
  1137. {
  1138. command.ExecuteNonQuery();
  1139. }
  1140. catch (Exception)
  1141. {
  1142. command.Connection = new OracleConnection(ConnectionStrings);
  1143. command.Connection.Open();
  1144. command.ExecuteNonQuery();
  1145. }
  1146. for (int i = 0; i < command.Parameters.Count; i++)
  1147. param[i] = command.Parameters[i].Value.ToString();
  1148. command.Dispose();
  1149. }
  1150. private string AddField(string[] Fields)
  1151. {
  1152. string sql = " ";
  1153. foreach (string field in Fields)
  1154. {
  1155. sql += field + ",";
  1156. }
  1157. return sql.Substring(0, sql.Length - 1);
  1158. }
  1159. private string[] GetField(string field)
  1160. {
  1161. string[] fields = field.Split(',');
  1162. for (int i = 0; i < fields.Length; i++)
  1163. {
  1164. fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
  1165. }
  1166. return fields;
  1167. }
  1168. private void Reconnect(OracleCommand cmd)
  1169. {
  1170. if (cmd.Connection.State == ConnectionState.Closed)
  1171. {
  1172. cmd.Connection.Open();
  1173. }
  1174. }
  1175. }
  1176. }