MesHelper.cs 58 KB

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