LogicHandler.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System.Collections.Generic;
  2. using System.Data;
  3. using System.Text;
  4. namespace UAS_AutoPass.ToolClass
  5. {
  6. class LogicHandler
  7. {
  8. public LogicHandler() { }
  9. public static DataHelper dh = new DataHelper();
  10. //用于拼接SQL
  11. static StringBuilder sql = new StringBuilder();
  12. //用于存放批量执行的SQL
  13. static List<string> sqls = new List<string>();
  14. public static bool CheckStepSNAndMacode(string iMakeCode, string iSourceCode, string iSN, string iUserCode, out string oMakeCode, out string oMsID, out string oErrorMessage)
  15. {
  16. oErrorMessage = "";
  17. oMakeCode = "";
  18. oMsID = "";
  19. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, oMakeCode, oMsID, oErrorMessage };
  20. dh.CallProcedure("CS_CHECKSTEPSNANDMACODE", ref param);
  21. oMakeCode = param[4];
  22. oMsID = param[5];
  23. oErrorMessage = param[6];
  24. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  25. return true;
  26. else
  27. return false;
  28. }
  29. public static void AutoPassLog(string iSN, string iSource, string iMakeCode, string iDate, string iStepCode, string iLineCode, string iFileName, string iIFNG, string iIFAutoSN, int iMiss, string iTestPart, string iNGPart)
  30. {
  31. sql.Clear();
  32. sql.Append("insert into AUTOSCANLOG(as_id,as_indate,as_testdate,as_sourcecode,as_stepcode,");
  33. sql.Append("as_linecode,as_makecode,as_sncode,as_filename,as_ifng,as_autosn,as_realng,as_testpart,as_ngpart)values(AUTOSCANLOG_seq.nextval,");
  34. sql.Append("sysdate,to_date('" + iDate + "','yyyymmddhh24miss'),'" + iSource + "','" + iStepCode + "','" + iLineCode + "','" + iMakeCode + "',");
  35. sql.Append("'" + iSN + "','" + iFileName + "','" + iIFNG + "','" + iIFAutoSN + "','" + iMiss + "','" + iTestPart + "','" + iNGPart + "')");
  36. dh.ExecuteSql(sql.ToString(), "select");
  37. }
  38. /// <summary>
  39. /// 获取工单的最近一条执行记录
  40. /// </summary>
  41. /// <param name="iSnCode"></param>
  42. /// <param name="oMakeCode"></param>
  43. /// <param name="oErrorMessage"></param>
  44. /// <returns></returns>
  45. public static bool GetMakeInfo(string iSnCode, out string oMakeCode, out string oStatus, out string oErrorMessage)
  46. {
  47. //取MakeProcess表中的执行记录ID最大的一个工单的号码
  48. oMakeCode = "";
  49. oErrorMessage = "";
  50. oStatus = "";
  51. DataTable dt = dh.getFieldsDataByCondition("MakeSerial", new string[] { "ms_makecode", "ms_status" }, "ms_id=(select max(ms_id) from makeserial where ms_sncode='" + iSnCode + "')");
  52. if (dt.Rows.Count > 0)
  53. {
  54. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  55. oStatus = dt.Rows[0]["ms_status"].ToString();
  56. }
  57. if (oMakeCode != "")
  58. return true;
  59. else
  60. {
  61. oErrorMessage = "序列号:" + iSnCode + " 未归属工单";
  62. return false;
  63. }
  64. }
  65. public static void AutoPassJudge(string iSN, string iMakeCode, string iSource, string iFileName, string iLineCode, string iCombine)
  66. {
  67. //插入不良判断记录
  68. sql.Clear();
  69. sql.Append("insert into AUTOSCAN_REJUDGE(asr_id,asr_indate,asr_filename,asr_combinecode,asr_sourcecode,");
  70. sql.Append("asr_linecode,asr_makecode,asr_sncode) values(AUTOSCAN_REJUDGE_seq.nextval,sysdate,");
  71. sql.Append("'" + iFileName + "','" + iCombine + "','" + iSource + "','" + iLineCode + "','" + iMakeCode + "','" + iSN + "')");
  72. dh.ExecuteSql(sql.ToString(), "insert");
  73. }
  74. public static bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
  75. {
  76. oErrorMessage = "";
  77. string SQL = "select em_code from employee where upper(em_code)=:UserName and em_password =:PassWord";
  78. DataTable dt;
  79. dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode.ToUpper(), iPassWord);
  80. if (dt.Rows.Count > 0)
  81. return true;
  82. else
  83. {
  84. oErrorMessage = "用户名或者密码不正确!";
  85. return false;
  86. }
  87. }
  88. public static bool SetTestNGDetail(string iSnCode, string iMakeCode, string iUserCode, string iSourceCode, string iResult, out string oErrorMessage)
  89. {
  90. oErrorMessage = "";
  91. string StepCode = "";
  92. string StepName = "";
  93. if (iResult == "" || iResult == null)
  94. iResult = "检查未通过";
  95. GetStepCodeAndNameBySource(iSourceCode, ref StepCode, ref StepName);
  96. //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
  97. //如果存在送检批号则进行删除
  98. if (dh.CheckExist("oqcbatchdetail", "obd_sncode='" + iSnCode + "'"))
  99. {
  100. string checkno = dh.getFieldDataByCondition("oqcbatchdetail", "obd_checkno", "obd_sncode='" + iSnCode + "'").ToString();
  101. dh.ExecuteSql("delete from oqcbatchdetail where obd_sncode='" + iSnCode + "'", "delete");
  102. dh.ExecuteSql("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + checkno + "'", "update");
  103. }
  104. //之前保存的不良就不再调用
  105. DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_stepcode", "nvl(ms_ifrework,0)ms_ifrework" }, "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  106. if (dt.Rows.Count > 0)
  107. {
  108. string ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  109. string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  110. if (ms_stepcode == StepCode)
  111. {
  112. if (ifrework == "0")
  113. dh.UpdateByCondition("makeserial", "ms_status=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  114. else
  115. dh.UpdateByCondition("makeserial", "ms_reworkstatus=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  116. }
  117. else
  118. {
  119. if (ifrework == "0")
  120. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_paststep = ms_paststep ||'," + StepCode + "',ms_status=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "' ");
  121. else
  122. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_paststep = ms_paststep ||'," + StepCode + "',ms_reworkstatus=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  123. SetStepResult(iMakeCode, iSourceCode, iSnCode, "不良采集", iResult, iUserCode, out oErrorMessage);
  124. }
  125. }
  126. return true;
  127. }
  128. /// <summary>
  129. /// 获取步骤代码和名称
  130. /// </summary>
  131. /// <param name="Source"></param>
  132. /// <param name="StepCode"></param>
  133. /// <param name="StepName"></param>
  134. private static void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  135. {
  136. DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  137. if (dt.Rows.Count > 0)
  138. {
  139. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  140. StepName = dt.Rows[0]["sc_stepname"].ToString();
  141. }
  142. }
  143. public static bool CheckUserAndResourcePassed(string iUserCode, string iSourceCode, out string oErrorMessage)
  144. {
  145. oErrorMessage = "";
  146. iUserCode = iUserCode.ToUpper();
  147. iSourceCode = iSourceCode.ToUpper();
  148. string SQL = "select em_code,em_type from employee where upper(em_code)=:UserName ";
  149. DataTable dt;
  150. dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode);
  151. if (dt.Rows.Count > 0)
  152. {
  153. string em_type = dt.Rows[0]["em_type"].ToString();
  154. if (iSourceCode == "")
  155. {
  156. oErrorMessage = "岗位资源不允许为空";
  157. return false;
  158. }
  159. if (em_type == "admin")
  160. {
  161. if (dh.CheckExist("Source", "upper(sc_code)='" + iSourceCode + "' and sc_statuscode='AUDITED'"))
  162. {
  163. return true;
  164. }
  165. else
  166. {
  167. oErrorMessage = "岗位资源编号错误或者未审核!";
  168. return false;
  169. }
  170. }
  171. else
  172. {
  173. dt = dh.getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "upper(ur_resourcecode) ur_resourcecode" }, "upper(eg_emcode)= '" + iUserCode + "' and sc_statuscode='AUDITED'");
  174. //如果存在该编号
  175. if (dt.Rows.Count > 0)
  176. {
  177. //判断如果多个岗位资源存在,用户输入的只要在其中就行
  178. for (int i = 0; i < dt.Rows.Count; i++)
  179. {
  180. if (dt.Rows[i]["ur_resourcecode"].ToString() == iSourceCode)
  181. return true;
  182. }
  183. oErrorMessage = "用户不处于当前资源所属分组!";
  184. }
  185. else
  186. oErrorMessage = "岗位资源编号错误或者未审核!";
  187. }
  188. }
  189. else
  190. oErrorMessage = "用户不存在!";
  191. return false;
  192. }
  193. public static bool SetStepResult(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
  194. {
  195. return CS_SetResult(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrorMessage);
  196. }
  197. public static bool CS_SetResult(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrorMessage)
  198. {
  199. oErrorMessage = "";
  200. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrorMessage };
  201. dh.CallProcedure("CS_SETSTEPRESULT", ref param);
  202. oErrorMessage = param[5];
  203. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  204. return true;
  205. else
  206. return false;
  207. }
  208. }
  209. }