LogicHandler.cs 12 KB

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