华恒Mes鼎捷代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

569 lines
20 KiB

5 months ago
  1. using System;
  2. using System.Data.SqlTypes;
  3. using System.Collections;
  4. using System.Linq;
  5. using System.Data.Linq;
  6. using System.Xml;
  7. using System.IO;
  8. using ICSSoft.Base.Config.AppConfig;
  9. using System.Collections.Specialized;
  10. using ICSSoft.Frame.Helper;
  11. using ICSSoft.Frame.Data.Entity;
  12. using ICSSoft.Frame.DataConnect.Action;
  13. namespace ICSSoft.Frame.DataConnect
  14. {
  15. /// <summary>
  16. /// ReportHelper ��ժҪ˵����
  17. /// </summary>
  18. public class ReportHelper
  19. {
  20. private const string OutLineResource = "OUTLINERESOURCE";
  21. private FramDataContext _domainDataProvider = null;
  22. // public ReportHelper()
  23. // {
  24. // }
  25. public ReportHelper(FramDataContext domainDataProvider)
  26. {
  27. this._domainDataProvider = domainDataProvider;
  28. }
  29. public FramDataContext DataProvider
  30. {
  31. get
  32. {
  33. return _domainDataProvider;
  34. }
  35. }
  36. public int WeekOfYear(string Date)
  37. {
  38. int weekOfYear =0;
  39. String sqlWeek = "select datepart(week,'"+Date+"') ";
  40. var query = this.DataProvider.ExecuteQuery<int>(sqlWeek);
  41. weekOfYear = query.First<int>();
  42. if (weekOfYear > 0)
  43. {
  44. return weekOfYear;
  45. }
  46. else
  47. {
  48. weekOfYear = 1;
  49. }
  50. return weekOfYear;
  51. }
  52. private static void DecodeDateWeek(DateTime dt,out int year,out int weekOfYear,out int dayOfWeek)
  53. {
  54. int dayOfYear = dt.DayOfYear;
  55. int monthOfYear = dt.Month;
  56. year = dt.Year;
  57. dayOfWeek = (int)dt.DayOfWeek;
  58. DateTime startDate = new DateTime(dt.Year,1,1);
  59. System.DayOfWeek startDayOfWeek = startDate.DayOfWeek;
  60. System.DayOfWeek endDayOfWeek = dt.DayOfWeek;
  61. if((startDayOfWeek == DayOfWeek.Friday)||(startDayOfWeek==DayOfWeek.Saturday)||(startDayOfWeek==DayOfWeek.Sunday))
  62. {
  63. dayOfYear = dayOfYear - (7- (int)startDayOfWeek);
  64. }
  65. else
  66. {
  67. dayOfYear = dayOfYear + (int)startDayOfWeek;
  68. }
  69. //dayOfYear+startDayOfWeek <7 ��Ӧ��Ϊȥ������
  70. if(dayOfYear <0)
  71. {
  72. DecodeDateWeek(startDate.AddDays(-1),out year,out weekOfYear,out dayOfWeek);
  73. }
  74. weekOfYear = dayOfYear/7;
  75. if( SqlInt32.Mod(dayOfYear,7) != 0)
  76. {
  77. weekOfYear++;
  78. }
  79. if(weekOfYear > 52)
  80. {
  81. endDayOfWeek = startDayOfWeek;
  82. if(DateTime.IsLeapYear(dt.Year))
  83. {
  84. if((endDayOfWeek == DayOfWeek.Sunday)||(endDayOfWeek == DayOfWeek.Monday))
  85. {
  86. endDayOfWeek ++;
  87. }
  88. if((endDayOfWeek==DayOfWeek.Monday)||(endDayOfWeek==DayOfWeek.Tuesday)||(endDayOfWeek==DayOfWeek.Wednesday))
  89. {
  90. year ++;
  91. weekOfYear = 1;
  92. }
  93. }
  94. }
  95. }
  96. private bool IsLastOP(string moCode,string routeCode,string opCode)
  97. {
  98. if (routeCode==string.Empty)
  99. return false;
  100. DataCollectFacade dataCollectFacade = new DataCollectFacade(this.DataProvider);
  101. return dataCollectFacade.OPIsMORouteLastOP(moCode,routeCode,opCode);
  102. }
  103. private bool IsMidOutputOP(string itemCode,string routeCode,string opCode,ProductInfo product)
  104. {
  105. if (routeCode.Trim()==string.Empty)
  106. {
  107. //BaseModelFacade itemFacade = new BaseModelFacade(this.DataProvider);
  108. object obj = null;// itemFacade.GetOperation(opCode);
  109. if(obj == null)
  110. {
  111. /*Burn In ©ɨʱFTʾòƷѾ߱ʾҪ޸ģԱUSER֪ˣʾҪӵһվͶ
  112. ʾʱ򣬼ָòƷѾȲҪֱӱںټһ򣬲ϾǺܷܶĹǿų
  113. * */
  114. if(product.LastSimulation != null && product.LastSimulation.ISCOM == "1")
  115. {
  116. throw new Exception("$CS_PRODUCT_ALREADY_COMPLETE $CS_Param_OPCode =" + product.LastSimulation.OPCODE);
  117. }
  118. else
  119. {
  120. throw new Exception("$CS_Route_Failed_GetNotNextOP");
  121. }
  122. }
  123. return FormatHelper.StringToBoolean( ((ICSOP)obj).OPCONTROL,(int)OperationList.MidistOutput);
  124. }
  125. else
  126. {
  127. //ItemFacade itemFacade = new ItemFacade(this.DataProvider);
  128. object obj = null;
  129. if(product.CurrentItemRoute2OP != null)
  130. {
  131. obj = product.CurrentItemRoute2OP;
  132. }
  133. else
  134. {
  135. obj = null;// itemFacade.GetItemRoute2Operation(itemCode, routeCode, opCode);
  136. }
  137. return FormatHelper.StringToBoolean(((ICSITEMROUTE2OP)obj).OPCONTROL, (int)OperationList.MidistOutput);
  138. }
  139. }
  140. //���� �ж��Ƿ����м�Ͷ�빤��
  141. private bool IsMidInputOP(string itemCode,string routeCode,string opCode,ProductInfo product)
  142. {
  143. //return false;
  144. if (routeCode.Trim()==string.Empty)
  145. {
  146. //BaseModelFacade itemFacade = new BaseModelFacade(this.DataProvider);
  147. object obj = null;//itemFacade.GetOperation(opCode);
  148. if(obj == null)
  149. {
  150. /*Burn In ©ɨʱFTʾòƷѾ߱ʾҪ޸ģԱUSER֪ˣʾҪӵһվͶ
  151. ʾʱ򣬼ָòƷѾȲҪֱӱںټһ򣬲ϾǺܷܶĹǿų
  152. * */
  153. if(product.LastSimulation != null && product.LastSimulation.ISCOM == "1")
  154. {
  155. throw new Exception("$CS_PRODUCT_ALREADY_COMPLETE $CS_Param_OPCode =" + product.LastSimulation.OPCODE);
  156. }
  157. else
  158. {
  159. throw new Exception("$CS_Route_Failed_GetNotNextOP");
  160. }
  161. }
  162. return FormatHelper.StringToBoolean( ((ICSOP)obj).OPCONTROL,(int)OperationList.MidistInput);
  163. }
  164. else
  165. {
  166. //ItemFacade itemFacade = new ItemFacade(this.DataProvider);
  167. object obj = null;
  168. if(product.CurrentItemRoute2OP != null)
  169. {
  170. obj = product.CurrentItemRoute2OP;
  171. }
  172. else
  173. {
  174. obj = null;//itemFacade.GetItemRoute2Operation(itemCode,routeCode,opCode);
  175. }
  176. return FormatHelper.StringToBoolean( ((ICSITEM2ROUTE)obj).ROUTECODE,(int)OperationList.MidistInput);
  177. }
  178. }
  179. /// <summary>
  180. /// By Line ͳ�Ʋ�����NG��ֱͨ��
  181. /// ��������
  182. /// </summary>
  183. /// <param name="domainDataProvider"></param>
  184. /// <param name="actionType"></param>
  185. /// <param name="product"></param>
  186. /// <returns></returns>
  187. public Messages ReportLineQuanMaster(FramDataContext domainDataProvider, string actionType, ProductInfo product)
  188. {
  189. return ReportLineQuanMaster(domainDataProvider, actionType, product, null);
  190. }
  191. // ��չһ����ActionCheckStatus�����ķ���
  192. public Messages ReportLineQuanMaster(FramDataContext domainDataProvider, string actionType, ProductInfo product, ActionCheckStatus actionCheckStatus)
  193. {
  194. Messages messages=new Messages();
  195. ICSReport reportFacade = new ICSReport(domainDataProvider);
  196. //TSFacade tSFacade = new TSFacade(domainDataProvider);
  197. //MOFacade mOFacade = new MOFacade(domainDataProvider);
  198. int ngtimes = 0;
  199. int qty = 0;
  200. int allqty = 0;
  201. int inputQty = 0;
  202. int moInputQty = 0;
  203. int moAllGoodQty = 0;
  204. try
  205. {
  206. //QtyFlag��������
  207. string flag = String.Empty;
  208. bool midOP = false;
  209. bool midInputOP = false;
  210. if (actionCheckStatus == null || actionCheckStatus.IsMidOutputOP == string.Empty)
  211. {
  212. if(IsMidOutputOP(product.NowSimulationReport.ITEMCODE,product.NowSimulationReport.ROUTECODE,product.NowSimulationReport.OPCODE,product))
  213. {
  214. midOP = true;
  215. }
  216. if (actionCheckStatus != null)
  217. {
  218. actionCheckStatus.IsMidOutputOP = midOP.ToString();
  219. }
  220. }
  221. else
  222. {
  223. midOP = Convert.ToBoolean(actionCheckStatus.IsMidOutputOP);
  224. }
  225. if (actionCheckStatus == null || actionCheckStatus.IsMidInputOP == string.Empty)
  226. {
  227. //�м�Ͷ��
  228. if(IsMidInputOP(product.NowSimulationReport.ITEMCODE,product.NowSimulationReport.ROUTECODE,product.NowSimulationReport.OPCODE,product))
  229. {
  230. midInputOP = true;
  231. }
  232. if (actionCheckStatus != null)
  233. {
  234. actionCheckStatus.IsMidInputOP = midInputOP.ToString();
  235. }
  236. }
  237. else
  238. {
  239. midInputOP = Convert.ToBoolean(actionCheckStatus.IsMidInputOP);
  240. }
  241. //�Ƿ�Ϊ��������
  242. if (actionCheckStatus == null || actionCheckStatus.IsLastOP == string.Empty)
  243. {
  244. if (IsLastOP(product.NowSimulationReport.MOCODE,product.NowSimulationReport.ROUTECODE,product.NowSimulationReport.OPCODE))//�Ƿ�Ϊ��������
  245. flag = "Y";
  246. else
  247. flag = "N";
  248. if (actionCheckStatus != null)
  249. {
  250. actionCheckStatus.IsLastOP = flag;
  251. }
  252. }
  253. else
  254. {
  255. flag = actionCheckStatus.IsLastOP;
  256. }
  257. int iNGStart = 0;
  258. int iMoNGStart = 0;
  259. #region ��������
  260. //���м�Ͷ�빤��Ͷ���IJ�������Ʒ���Dz���Ʒ,����ΪͶ�����ļ���.�����ڼ���.
  261. if(midInputOP)
  262. {
  263. inputQty = Convert.ToInt32(1 * product.NowSimulation.IDMERGERULE);
  264. }
  265. if (product.NowSimulation.PRODUCTSTATUS == "GOOD" && product.NowSimulation.LACTION != ActionType.DataCollectAction_GoMO)
  266. {
  267. if (flag == "Y" || midOP)//�Ƿ�Ϊ�����������м����㹤��
  268. {
  269. if(product.NowSimulation != null)
  270. {
  271. //iNGStart = tSFacade.QueryTSCountByLine(
  272. // product.NowSimulationReport.RCARD
  273. // ,product.NowSimulationReport.SSCODE
  274. // ,Convert.ToInt32(product.NowSimulationReport.RCARDSEQ));
  275. //iMoNGStart = tSFacade.QueryTSCountByMo(
  276. // product.NowSimulation.RCARD
  277. // ,product.NowSimulation.MOCODE);
  278. }
  279. qty = Convert.ToInt32(1 * product.NowSimulation.IDMERGERULE);
  280. //ֱͨ������׼
  281. //if (
  282. // iNGStart == 0 && IDIsInRejectCount(product.NowSimulationReport.RCARD,product.NowSimulationReport.SSCODE)==0)
  283. //{
  284. // //reportRealtimeLineQty.AllGoodQty += 1 * product.NowSimulation.IDMERGERULE;
  285. // allqty = Convert.ToInt32(1 * product.NowSimulation.IDMERGERULE);
  286. //}
  287. //����ֱ̨ͨ��
  288. #region �йز�����Ͷ�����������ʡ�ֱͨ�ʵIJ���˵����
  289. /*3. ֱͨʣ
  290. (򷵹ͶĹδֹIJƷ̨)/ù򷵹ɵIJƷƷ̨
  291. ԲжֱͨƷʱһҪֹAֻжϸòƷкAעǹDzߣ мߣܸòƷкδֲǰIJֲǸмߵķֱͨƷǷ˲вΪֱͨƷʹòƷкֹԸôεӰֱ̨ͨļ
  292. ֱͨʲڿʱε.ֻҪڹֹ򲻻¼ΪֱͨƷûвͼ¼ΪֱͨƷȻʱΡ
  293. ùIJƷһֱͨƷ
  294. FQCΪ˵IJƷһֱͨƷ
  295. */
  296. #endregion
  297. //if (flag == "Y" && iMoNGStart == 0
  298. // && IDIsInRejectCountByMo(product.NowSimulationReport.RCARD,product.NowSimulationReport.MOCODE)==0
  299. // && product.NowSimulationReport.NGTIMES == 0)
  300. //{
  301. // moAllGoodQty = Convert.ToInt32(1 * product.NowSimulation.IDMERGERULE);
  302. //}
  303. }
  304. }
  305. else if (product.NowSimulation.PRODUCTSTATUS == "NG")
  306. {
  307. //reportRealtimeLineQty.NGTimes += 1;
  308. //Ͷ�����ļ���
  309. //��������TS�����Ҳ�Ʒǰһ��״̬�����ڵ�NG״̬����
  310. //����ǰһ��Action�����ڵ�Action����ͬһ������
  311. //�ɼ�NG��Ͷ����Ӧ�ü���
  312. //����ֱ�Ӳɼ�NG����Ͷ������bug
  313. //Eric ���м�Ͷ�빤��Ͷ���IJ�������Ʒ���Dz���Ʒ,����ΪͶ�����ļ���.�����ڼ���.
  314. ngtimes = 1;
  315. if (product.NowSimulation.OPCODE == product.LastSimulation.OPCODE
  316. && (product.LastSimulation.LACTION == ActionType.DataCollectAction_GOOD
  317. || product.LastSimulation.LACTION == ActionType.DataCollectAction_SMTGOOD
  318. || product.LastSimulation.LACTION == ActionType.DataCollectAction_OutLineGood
  319. || product.LastSimulation.LACTION == ActionType.DataCollectAction_OQCPass) )
  320. {
  321. if (flag == "Y" || midOP)//�Ƿ�Ϊ�����������м����㹤��
  322. {
  323. //��ǰվ�й�����,����ǰһ�β���״̬��GOOD�Ż�������
  324. qty = Convert.ToInt32(-1 * product.NowSimulation.IDMERGERULE);
  325. if(product.NowSimulation != null)
  326. {
  327. //iNGStart = tSFacade.QueryTSCountByLine(
  328. // product.NowSimulationReport.RCARD
  329. // ,product.NowSimulationReport.SSCODE
  330. // ,Convert.ToInt32(product.NowSimulationReport.RCARDSEQ));
  331. //iMoNGStart = tSFacade.QueryTSCountByMo(
  332. // product.NowSimulation.RCARD
  333. // ,product.NowSimulation.MOCODE);
  334. }
  335. //ֱͨ������׼
  336. //if ((IDIsInRejectCount(product.NowSimulationReport.RCARD,product.NowSimulationReport.SSCODE)==0)
  337. // && iNGStart == 0)//rejectlist
  338. //{
  339. // allqty = Convert.ToInt32(-1 * product.NowSimulation.IDMERGERULE);
  340. //}
  341. //����ֱ̨ͨ��
  342. #region �йز�����Ͷ�����������ʡ�ֱͨ�ʵIJ���˵����
  343. /*3. ֱͨʣ
  344. (򷵹ͶĹδֹIJƷ̨)/ù򷵹ɵIJƷƷ̨
  345. ԲжֱͨƷʱһҪֹAֻжϸòƷкAעǹDzߣ мߣܸòƷкδֲǰIJֲǸмߵķֱͨƷǷ˲вΪֱͨƷʹòƷкֹԸôεӰֱ̨ͨļ
  346. ֱͨʲڿʱε.ֻҪڹֹ򲻻¼ΪֱͨƷûвͼ¼ΪֱͨƷȻʱΡ
  347. ùIJƷһֱͨƷ
  348. FQCΪ˵IJƷһֱͨƷ
  349. */
  350. #endregion
  351. //if (flag == "Y" && iMoNGStart == 0
  352. // && IDIsInRejectCountByMo(product.NowSimulationReport.RCARD, product.NowSimulationReport.MOCODE) == 0
  353. // && product.NowSimulationReport.NGTIMES == 1)
  354. //{
  355. // moAllGoodQty = Convert.ToInt32(-1 * product.NowSimulation.IDMERGERULE);
  356. //}
  357. }
  358. }
  359. }
  360. else if (product.NowSimulation.PRODUCTSTATUS == "REJECT")
  361. {
  362. if (product.NowSimulation.RESCODE == product.LastSimulation.RESCODE
  363. && (product.LastSimulation.LACTION == ActionType.DataCollectAction_GOOD
  364. || product.LastSimulation.LACTION == ActionType.DataCollectAction_SMTGOOD
  365. || product.LastSimulation.LACTION == ActionType.DataCollectAction_OutLineGood
  366. || product.LastSimulation.LACTION == ActionType.DataCollectAction_OQCPass) )
  367. {
  368. if (flag == "Y" || midOP)//�Ƿ�Ϊ�����������м����㹤��
  369. {
  370. //reportRealtimeLineQty.OuputQty -= 1 * product.NowSimulation.IDMERGERULE;
  371. if(product.NowSimulationReport != null)
  372. {
  373. //iNGStart = tSFacade.QueryTSCountByLine(
  374. // product.NowSimulationReport.RCARD
  375. // ,product.NowSimulationReport.SSCODE
  376. // ,Convert.ToInt32(product.NowSimulationReport.RCARDSEQ));
  377. //iMoNGStart = tSFacade.QueryTSCountByMo(
  378. // product.NowSimulation.RCARD
  379. // ,product.NowSimulation.MOCODE);
  380. }
  381. //ֱͨ������׼
  382. qty = Convert.ToInt32(-1 * product.NowSimulation.IDMERGERULE);
  383. //if ((IDIsInRejectCount(product.NowSimulationReport.RCARD,product.NowSimulationReport.SSCODE)==1)
  384. // && iNGStart == 0)
  385. //{
  386. // allqty = Convert.ToInt32( -1 * product.NowSimulation.IDMERGERULE);
  387. //}
  388. //����ֱ̨ͨ��
  389. #region �йز�����Ͷ�����������ʡ�ֱͨ�ʵIJ���˵����
  390. ///<Comment>3. ����ֱͨ�ʣ�
  391. ///��(���������������򷵹���������Ͷ�뵽�����Ĺ�����δ�����ֹ������IJ�Ʒ̨��)/�ù��������������򷵹������������ɵIJ�Ʒ��Ʒ̨��
  392. ///�Բ����ж�ֱͨ��Ʒ����ʱ��һ��Ҫ�ֹ�������������������A������ֻ���жϸò�Ʒ���к���A������ע���ǹ����������Dz��ߣ������� �����м����ߣ����ܸò�Ʒ���к�������δ���ֲ���������ǰ���IJ����������ֲ��������Ǹ��м����ߵķ�ֱͨƷ���������������Ƿ������˲��������в�����Ϊ��ֱͨƷ����ʹ�ò�Ʒ���к������������������ֹ����������Ըôε�������Ӱ�쵽ֱ̨ͨ���ļ��㡣
  393. ///ֱͨ�ʲ����ڿ�ʱ�ε�����.ֻҪ�������ڹ����������ֹ��������򲻻���¼ΪֱͨƷ��û�в����ͼ�¼ΪֱͨƷ��Ȼ��������ʱ�Ρ�
  394. ///�ù��������IJ�Ʒһ������ֱͨƷ
  395. ///FQC����Ϊ�����������˵IJ�Ʒһ������ֱͨƷ
  396. ///</Comment>
  397. #endregion
  398. //if (flag == "Y" && iMoNGStart == 0
  399. // && IDIsInRejectCountByMo(product.NowSimulationReport.RCARD, product.NowSimulationReport.MOCODE) == 0
  400. // && product.NowSimulationReport.NGTIMES == 1)
  401. //{
  402. // moAllGoodQty = Convert.ToInt32(-1 * product.NowSimulation.IDMERGERULE);
  403. //}
  404. }
  405. }
  406. }
  407. #endregion
  408. if(product.NowSimulationReport.LACTION == ActionType.DataCollectAction_GoMO)
  409. {
  410. moInputQty = Convert.ToInt32(1 * product.NowSimulation.IDMERGERULE);
  411. }
  412. //������������
  413. //û�����֡��������빤��ʲô����������ʡϵͳ��Դ
  414. if(ngtimes != 0 || qty != 0 || allqty != 0 || inputQty != 0 || moInputQty != 0 || moAllGoodQty != 0
  415. || actionType == ActionType.DataCollectAction_OffMo/*���빤������*/)
  416. {
  417. //û������ʲô����������ʡϵͳ��Դ
  418. if(ngtimes != 0 || qty != 0 || allqty != 0 || inputQty != 0 || moInputQty != 0 || moAllGoodQty != 0)
  419. {
  420. #region ��ȡ����ʵ��
  421. #endregion
  422. }
  423. }
  424. if(product.NowSimulationReport.LACTION == ActionType.DataCollectAction_OffMo
  425. || product.NowSimulationReport.LACTION == ActionType.DataCollectAction_GoMO
  426. || flag == "Y")
  427. {
  428. //�������¹�������������
  429. //mOFacade.UpdateMOQty(product.NowSimulationReport.MOCODE
  430. // ,product.NowSimulationReport.LACTION
  431. // ,Convert.ToInt32(1 * product.NowSimulation.IDMERGERULE));
  432. }
  433. }
  434. catch (Exception e)
  435. {
  436. messages.Add(new Message(e));
  437. }
  438. return messages;
  439. }
  440. //Ӧ����û�п��ǵ��������ع�������
  441. //�����Ƿ��ڵ�ǰվ�Ѿ�����ͳ��
  442. private bool CheckNeedCountInthisResoure(ProductInfo product)
  443. {
  444. if (product.NowSimulation.RESCODE == product.LastSimulation.RESCODE
  445. && product.NowSimulation.OPCODE == product.LastSimulation.OPCODE
  446. &&
  447. (
  448. product.LastSimulation.LACTION == ActionType.DataCollectAction_GOOD
  449. || product.LastSimulation.LACTION == ActionType.DataCollectAction_SMTGOOD
  450. || product.LastSimulation.LACTION == ActionType.DataCollectAction_OutLineGood
  451. || product.LastSimulation.LACTION == ActionType.DataCollectAction_CollectKeyParts
  452. || product.LastSimulation.LACTION == ActionType.DataCollectAction_CollectINNO
  453. || product.LastSimulation.LACTION == ActionType.DataCollectAction_IDTran
  454. || product.LastSimulation.LACTION == ActionType.DataCollectAction_Split
  455. )
  456. )
  457. return true;
  458. else
  459. return false;
  460. }
  461. }
  462. /// <summary>
  463. /// �ܵļ���
  464. /// </summary>
  465. ///
  466. [Serializable]
  467. public class WeekObject
  468. {
  469. public int Week;
  470. }
  471. /// <summary>
  472. ///
  473. /// </summary>
  474. ///
  475. [Serializable]
  476. public struct ReportQtyHelper
  477. {
  478. public decimal OuputQty;
  479. public decimal AllGoodQty;
  480. public decimal MoAllGoodQty;
  481. public ReportQtyHelper(
  482. decimal ouputQty,
  483. decimal allGoodQty,
  484. decimal moAllGoodQty)
  485. {
  486. OuputQty = ouputQty ;
  487. AllGoodQty = allGoodQty ;
  488. MoAllGoodQty= moAllGoodQty ;
  489. }
  490. }
  491. }