LogicHandler.cs 11 KB

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