MESHelper.cs 53 KB

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