LogicHandler.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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)
  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)values(AUTOSCANLOG_seq.nextval,");
  34. sql.Append("sysdate,to_date('" + iDate + "','yyyy-mm-dd,hh24:mi:ss'),'" + iSource + "','" + iStepCode + "','" + iLineCode + "','" + iMakeCode + "',");
  35. sql.Append("'" + iSN + "','" + iFileName + "','" + iIFNG + "')");
  36. dh.ExecuteSql(sql.ToString(), "select");
  37. }
  38. public static void AutoPassJudge(string iSN, string iMakeCode, string iSource, string iFileName, string iLineCode, string iCombine)
  39. {
  40. //插入不良判断记录
  41. sql.Clear();
  42. sql.Append("insert into AUTOSCAN_REJUDGE(asr_id,asr_indate,asr_filename,asr_combinecode,asr_sourcecode,");
  43. sql.Append("asr_linecode,asr_makecode,asr_sncode) values(AUTOSCAN_REJUDGE_seq.nextval,sysdate,");
  44. sql.Append("'" + iFileName + "','" + iCombine + "','" + iSource + "','" + iLineCode + "','" + iMakeCode + "','" + iSN + "')");
  45. dh.ExecuteSql(sql.ToString(), "insert");
  46. }
  47. public static bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
  48. {
  49. oErrorMessage = "";
  50. string SQL = "select em_code from employee where upper(em_code)=:UserName and em_password =:PassWord";
  51. DataTable dt;
  52. dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode.ToUpper(), iPassWord);
  53. if (dt.Rows.Count > 0)
  54. return true;
  55. else
  56. {
  57. oErrorMessage = "用户名或者密码不正确!";
  58. return false;
  59. }
  60. }
  61. public static bool SetTestNGDetail(string iSnCode, string iMakeCode, string iUserCode, string iSourceCode, string iResult, out string oErrorMessage)
  62. {
  63. oErrorMessage = "";
  64. string StepCode = "";
  65. string StepName = "";
  66. if (iResult == "" || iResult == null)
  67. iResult = "检查未通过";
  68. GetStepCodeAndNameBySource(iSourceCode, ref StepCode, ref StepName);
  69. //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
  70. //如果存在送检批号则进行删除
  71. if (dh.CheckExist("oqcbatchdetail", "obd_sncode='" + iSnCode + "'"))
  72. {
  73. string checkno = dh.getFieldDataByCondition("oqcbatchdetail", "obd_checkno", "obd_sncode='" + iSnCode + "'").ToString();
  74. dh.ExecuteSql("delete from oqcbatchdetail where obd_sncode='" + iSnCode + "'", "delete");
  75. dh.ExecuteSql("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + checkno + "'", "update");
  76. }
  77. //之前保存的不良就不再调用
  78. DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_stepcode", "nvl(ms_ifrework,0)ms_ifrework" }, "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  79. if (dt.Rows.Count > 0)
  80. {
  81. string ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  82. string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  83. if (ms_stepcode == StepCode)
  84. {
  85. if (ifrework == "0")
  86. dh.UpdateByCondition("makeserial", "ms_status=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  87. else
  88. dh.UpdateByCondition("makeserial", "ms_reworkstatus=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  89. }
  90. else
  91. {
  92. if (ifrework == "0")
  93. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_paststep = ms_paststep ||'," + StepCode + "',ms_status=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "' ");
  94. else
  95. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_paststep = ms_paststep ||'," + StepCode + "',ms_reworkstatus=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
  96. SetStepResult(iMakeCode, iSourceCode, iSnCode, "不良采集", iResult, iUserCode, out oErrorMessage);
  97. }
  98. }
  99. return true;
  100. }
  101. /// <summary>
  102. /// 获取步骤代码和名称
  103. /// </summary>
  104. /// <param name="Source"></param>
  105. /// <param name="StepCode"></param>
  106. /// <param name="StepName"></param>
  107. private static void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
  108. {
  109. DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
  110. if (dt.Rows.Count > 0)
  111. {
  112. StepCode = dt.Rows[0]["sc_stepcode"].ToString();
  113. StepName = dt.Rows[0]["sc_stepname"].ToString();
  114. }
  115. }
  116. public static bool CheckUserAndResourcePassed(string iUserCode, string iSourceCode, out string oErrorMessage)
  117. {
  118. oErrorMessage = "";
  119. iUserCode = iUserCode.ToUpper();
  120. iSourceCode = iSourceCode.ToUpper();
  121. string SQL = "select em_code,em_type from employee where upper(em_code)=:UserName ";
  122. DataTable dt;
  123. dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode);
  124. if (dt.Rows.Count > 0)
  125. {
  126. string em_type = dt.Rows[0]["em_type"].ToString();
  127. if (iSourceCode == "")
  128. {
  129. oErrorMessage = "岗位资源不允许为空";
  130. return false;
  131. }
  132. if (em_type == "admin")
  133. {
  134. if (dh.CheckExist("Source", "upper(sc_code)='" + iSourceCode + "' and sc_statuscode='AUDITED'"))
  135. {
  136. return true;
  137. }
  138. else
  139. {
  140. oErrorMessage = "岗位资源编号错误或者未审核!";
  141. return false;
  142. }
  143. }
  144. else
  145. {
  146. 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'");
  147. //如果存在该编号
  148. if (dt.Rows.Count > 0)
  149. {
  150. //判断如果多个岗位资源存在,用户输入的只要在其中就行
  151. for (int i = 0; i < dt.Rows.Count; i++)
  152. {
  153. if (dt.Rows[i]["ur_resourcecode"].ToString() == iSourceCode)
  154. return true;
  155. }
  156. oErrorMessage = "用户不处于当前资源所属分组!";
  157. }
  158. else
  159. oErrorMessage = "岗位资源编号错误或者未审核!";
  160. }
  161. }
  162. else
  163. oErrorMessage = "用户不存在!";
  164. return false;
  165. }
  166. public static bool SetStepResult(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
  167. {
  168. return CS_SetResult(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrorMessage);
  169. }
  170. public static bool CS_SetResult(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrorMessage)
  171. {
  172. oErrorMessage = "";
  173. string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrorMessage };
  174. dh.CallProcedure("CS_SETSTEPRESULT", ref param);
  175. oErrorMessage = param[5];
  176. if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
  177. return true;
  178. else
  179. return false;
  180. }
  181. }
  182. }