华恒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.

1919 lines
75 KiB

5 months ago
  1. using System;
  2. using System.Runtime.Remoting;
  3. using System.Collections;
  4. using System.Reflection;
  5. using System.Runtime.Remoting;
  6. using System.Text.RegularExpressions;
  7. using System.Linq;
  8. using System.Data.Linq;
  9. using System.Xml;
  10. using System.IO;
  11. using ICSSoft.Base.Config.AppConfig;
  12. using System.Collections.Specialized;
  13. using ICSSoft.Frame.Data.Entity;
  14. using ICSSoft.Frame.DataConnect.Action;
  15. using System.Data;
  16. using ICSSoft.Frame.Helper;
  17. using ICSSoft.Frame.Data.Entity;
  18. using ICSSoft.Base.Config.DBHelper;
  19. using System.Collections.Generic;
  20. using System.Data.SqlClient;
  21. namespace ICSSoft.Frame.DataConnect
  22. {
  23. /// <summary>
  24. /// BaseModel ��ժҪ˵����
  25. /// ���: BaseModel.cs
  26. /// �� ��: ����ģ��ά����̨
  27. /// �� ��:
  28. /// </summary>
  29. public class ICSBaseModel
  30. {
  31. FramDataContext domainDataProvider = new Data.Entity.FramDataContext();
  32. private FramDataContext _domainDataProvider = null;
  33. private const string TS_Operation = "TS";
  34. public ICSBaseModel(FramDataContext domainDataProvider)
  35. {
  36. this._domainDataProvider = domainDataProvider;
  37. }
  38. public ICSBaseModel()
  39. {
  40. }
  41. public FramDataContext DataProvider
  42. {
  43. get
  44. {
  45. return _domainDataProvider;
  46. }
  47. }
  48. #region Segment
  49. /// <summary>
  50. /// ** ��������: ��SegmentCode����Segment
  51. /// ** �� ��:
  52. /// ** �� ��:
  53. /// ** �汾
  54. /// </summary>
  55. /// <param name="segmentCode"></param>
  56. /// <returns></returns>
  57. public object GetSegment(string segmentCode)
  58. {
  59. return this.DataProvider.ICSSEG.SingleOrDefault(a => a.SEGCODE == segmentCode && a.WorkPoint == AppConfig.WorkPointCode);
  60. }
  61. #endregion
  62. #region ICSSS
  63. public object GetStepSequence(string stepSequenceCode)
  64. {
  65. return this.DataProvider.ICSSS.SingleOrDefault(a => a.SSCODE == stepSequenceCode && a.WorkPoint == AppConfig.WorkPointCode);
  66. }
  67. /// <summary>
  68. /// ** ��������: ��ѯICSSS��������
  69. ///
  70. /// </summary>
  71. /// <param name="stepSequenceCode">StepSequenceCode��ģ����ѯ</param>
  72. /// <param name="segmentCode">SegmentCode��ģ����ѯ</param>
  73. /// <returns>ICSSS���ܼ�¼��</returns>
  74. public int QueryStepSequenceCount(string stepSequenceCode, string segmentCode, string BigStepSequenceCode)
  75. {
  76. var ssline = from a in DataProvider.ICSSS
  77. join b in DataProvider.ICSSEG on a.SEGID equals b.ID
  78. where a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
  79. select new
  80. {
  81. a,
  82. b
  83. };
  84. if (stepSequenceCode != null && stepSequenceCode.Length != 0)
  85. {
  86. ssline = ssline.Where(p=>p.a.SSCODE==stepSequenceCode);
  87. }
  88. if (segmentCode != null && segmentCode.Length != 0)
  89. {
  90. if (segmentCode.IndexOf(",") >= 0)
  91. {
  92. ssline = ssline.Where(p => segmentCode.Contains(p.b.SEGCODE));
  93. }
  94. else
  95. {
  96. ssline = ssline.Where(p=>p.b.SEGCODE.StartsWith(segmentCode));
  97. }
  98. }
  99. if (ssline != null)
  100. {
  101. return ssline.ToList().Count;
  102. }
  103. else
  104. {
  105. return 0;
  106. }
  107. }
  108. /// <summary>
  109. /// ** ��������: ��ҳ��ѯICSSS
  110. /// </summary>
  111. /// <param name="stepSequenceCode">StepSequenceCode��ģ����ѯ</param>
  112. /// <param name="segmentCode">SegmentCode��ģ����ѯ</param>
  113. /// <param name="inclusive">��ʼ����</param>
  114. /// <param name="exclusive">��������</param>
  115. /// <returns></returns>
  116. public object[] QueryStepSequence(string stepSequenceCode, string segmentCode)
  117. {
  118. try
  119. {
  120. var ssline = from a in DataProvider.ICSSS
  121. join b in DataProvider.ICSSEG on a.SEGID equals b.ID
  122. where a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
  123. orderby a.SSCODE
  124. select new
  125. {
  126. a,
  127. b
  128. };
  129. if (stepSequenceCode != null && stepSequenceCode.Length != 0)
  130. {
  131. ssline = ssline.Where(p=>p.a.SSCODE.StartsWith(stepSequenceCode));
  132. }
  133. if (segmentCode != null && segmentCode.Length != 0)
  134. {
  135. if (segmentCode.IndexOf(",") >= 0)
  136. {
  137. ssline = ssline.Where(p => segmentCode.Contains(p.b.SEGCODE));
  138. }
  139. else
  140. {
  141. ssline = ssline.Where(p => p.b.SEGCODE.StartsWith(segmentCode));
  142. }
  143. }
  144. return ssline.ToArray();
  145. }
  146. catch (Exception ex)
  147. {
  148. throw new Exception(ex.Message);
  149. }
  150. // return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format( "select * from TBLSS where 1=1 {0} order by SSSEQ", condition )));
  151. //return this.DataProvider.CustomQuery(typeof(ICSSS), new PagerCondition(string.Format(, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)), condition), "SEGCODE"));
  152. }
  153. /// <summary>
  154. /// ** ��������: �������е�ICSSS
  155. /// </summary>
  156. /// <returns>���е�ICSSS</returns>
  157. public object[] GetAllStepSequence()
  158. {
  159. try
  160. {
  161. var line = DataProvider.ICSSS.Where(p => p.WorkPoint == AppConfig.WorkPointCode);
  162. return line.ToArray();
  163. }
  164. catch (Exception ex)
  165. {
  166. throw new Exception(ex.Message);
  167. }
  168. // return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format("select {0} from TBLSS where 1=1 " + " and WorkPoint ='"+AppConfig.WorkPointCode+"'" + " order by SSCODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)))));
  169. }
  170. /// <summary>
  171. /// ** ��������: ����Segment�����е�ICSSS
  172. /// </summary>
  173. /// <returns>Segment�����е�ICSSS</returns>
  174. public object[] GetStepSequenceBySegmentCode(string segmentCode)
  175. {
  176. try
  177. {
  178. var ssline = from a in DataProvider.ICSSS
  179. join b in DataProvider.ICSSEG on a.SEGID equals b.ID
  180. where a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode && b.SEGCODE==segmentCode
  181. orderby a.SSCODE
  182. select new
  183. {
  184. a,
  185. b
  186. };
  187. return ssline.ToArray();
  188. }
  189. catch (Exception ex)
  190. {
  191. throw new Exception(ex.Message);
  192. }
  193. //return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format("select {0} from TBLSS where 1=1 " + " and WorkPoint ='"+AppConfig.WorkPointCode+"'" + " and SEGCODE='{1}' order by SSCODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)), segmentCode)));
  194. }
  195. #endregion
  196. #region ICSRES
  197. //������Դ��Ӧ�����Ƿ���;�̵ĵ�һ������
  198. private void CheckResource(ICSRES resource)
  199. {
  200. var resline = from a in DataProvider.ICSOP2RES
  201. join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
  202. join c in DataProvider.ICSROUTE on b.ROUTECODE equals c.ROUTECODE
  203. where a.RESCODE == resource.RESCODE && c.ROUTETYPE == "Rework" && a.WorkPoint == AppConfig.WorkPointCode && b.WORKPOINT == AppConfig.WorkPointCode && c.WorkPoint == AppConfig.WorkPointCode
  204. select new {
  205. b.ROUTECODE
  206. };
  207. if (resource.ID != null && resline != null)
  208. {
  209. ICSOP2RES op = this.GetOperationByResource(resource.RESCODE);
  210. if (op == null)
  211. {
  212. throw new Exception("$Error_Res_not_belong_To_Op");
  213. }
  214. object op2 = GetFirstOperationOfRoute(resline.ToList()[0].ToString()) as ICSOP;
  215. if (op2 == null)
  216. {
  217. throw new Exception("$error_route_no_op");
  218. }
  219. if (((ICSOP)op2).OPCODE != op.OPCODE)
  220. {
  221. throw new Exception("$error_res_not_first_op");
  222. }
  223. }
  224. }
  225. public object GetResource(string resourceCode)
  226. {
  227. try
  228. {
  229. var line = DataProvider.ICSRES.SingleOrDefault(a => a.RESCODE == resourceCode);
  230. return line;
  231. }
  232. catch (Exception ex)
  233. {
  234. throw new Exception(ex.Message);
  235. }
  236. }
  237. /// <summary>
  238. /// ** ��������: ��ѯICSRES��������
  239. /// </summary>
  240. /// <param name="resourceCode">ResourceCode��ģ����ѯ</param>
  241. /// <returns> ICSRES���ܼ�¼��</returns>
  242. public int QueryResourceCount(string resourceCode, string stepSequenceCode, string crewCode)
  243. {
  244. var resline = from a in DataProvider.ICSRES
  245. join b in DataProvider.ICSSS on a.SSID equals b.ID
  246. where a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode && b.WorkPoint==AppConfig.WorkPointCode
  247. select new
  248. {
  249. a,
  250. b
  251. };
  252. if (stepSequenceCode != "")
  253. {
  254. if (stepSequenceCode.IndexOf(",") >= 0)
  255. {
  256. resline= resline.Where(p=>stepSequenceCode.Contains(p.b.SSCODE));
  257. }
  258. else
  259. {
  260. resline = resline.Where(p => p.b.SSCODE.StartsWith(stepSequenceCode));
  261. }
  262. }
  263. if (crewCode != "")
  264. {
  265. resline = resline.Where(p => p.a.CREWCODE.StartsWith(crewCode));
  266. }
  267. return resline.ToList().Count;
  268. }
  269. public object[] CheckResource(string ssCode)
  270. {
  271. try
  272. {
  273. var resline = from a in DataProvider.ICSSS
  274. where ssCode.ToUpper().StartsWith(a.SSCODE) && a.WorkPoint == AppConfig.WorkPointCode
  275. select a;
  276. return resline.ToArray();
  277. }
  278. catch (Exception ex)
  279. {
  280. throw new Exception(ex.Message);
  281. }
  282. //return this.DataProvider.CustomQuery(typeof(ICSSS), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSSS)), ssCode)));
  283. }
  284. /// <summary>
  285. /// ** ��������: ��ҳ��ѯICSRES
  286. /// </summary>
  287. /// <param name="resourceCode">ResourceCode��ģ����ѯ</param>
  288. /// <param name="inclusive">��ʼ����</param>
  289. /// <param name="exclusive">��������</param>
  290. /// <returns> ICSRES����</returns>
  291. public object[] QueryResource(string resourceCode, string stepSequenceCode, string crewCode)
  292. {
  293. try
  294. {
  295. var resline = from a in DataProvider.ICSRES
  296. join b in DataProvider.ICSSS on a.SSID equals b.ID
  297. where a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode && b.WorkPoint==AppConfig.WorkPointCode
  298. select new
  299. {
  300. a,
  301. b
  302. };
  303. if (stepSequenceCode != "")
  304. {
  305. if (stepSequenceCode.IndexOf(",") >= 0)
  306. {
  307. resline = resline.Where(p => stepSequenceCode.Contains(p.b.SSCODE));
  308. }
  309. else
  310. {
  311. resline = resline.Where(p => p.b.SSCODE.StartsWith(stepSequenceCode));
  312. }
  313. } //stepSequenceCode�����ݿ�������Ϊ��,
  314. if (crewCode != "")
  315. {
  316. resline = resline.Where(p => p.a.CREWCODE.StartsWith(crewCode));
  317. }
  318. return resline.ToArray();
  319. }
  320. catch (Exception ex)
  321. {
  322. throw new Exception(ex.Message);
  323. }
  324. //return this.DataProvider.CustomQuery(typeof(ICSRES), new PagerCondition(qSql, "RESCODE", inclusive, exclusive));
  325. }
  326. /// <summary>
  327. /// ** ��������: �������е�ICSRES
  328. /// </summary>
  329. /// <returns>ICSRES���ܼ�¼��</returns>
  330. public object[] GetAllResource()
  331. {
  332. try
  333. {
  334. var resline = from a in DataProvider.ICSRES
  335. where a.WorkPoint == AppConfig.WorkPointCode
  336. orderby a.RESCODE
  337. select a;
  338. return resline.ToArray();
  339. }
  340. catch (Exception ex)
  341. {
  342. throw new Exception(ex.Message);
  343. }
  344. //return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)))));
  345. }
  346. /// <summary>
  347. /// ** ��������: ����ShiftTypeCode�õ�ICSRESʵ��
  348. /// </summary>
  349. /// <param name="segmentCode">SegmentCode</param>
  350. /// <returns>ICSRES����</returns>
  351. public object[] QueryResourceBySegmentCode(string segmentCode)
  352. {
  353. try
  354. {
  355. var resline = from a in DataProvider.ICSRES
  356. join b in DataProvider.ICSSEG on a.SEGID equals b.ID
  357. where b.SEGCODE == segmentCode && a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
  358. select new {
  359. a,
  360. b
  361. };
  362. return resline.ToArray();
  363. }
  364. catch (Exception ex)
  365. {
  366. throw new Exception(ex.Message);
  367. }
  368. // End Added
  369. // return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), segmentCode)));
  370. }
  371. #endregion
  372. #region ICSOP
  373. public object GetOperation(string opCode)
  374. {
  375. try
  376. {
  377. var opline = from a in DataProvider.ICSOP
  378. where a.OPCODE == opCode && a.WorkPoint == AppConfig.WorkPointCode
  379. select a;
  380. return opline;
  381. }
  382. catch (Exception ex)
  383. {
  384. throw new Exception(ex.Message);
  385. }
  386. //return this.DataProvider.CustomSearch(typeof(ICSOP), new object[] { opCode });
  387. }
  388. /// <summary>
  389. /// ** ��������: ��ѯICSOP��������
  390. /// </summary>
  391. /// <param name="oPCode">OPCODE��ģ����ѯ</param>
  392. /// <returns> ICSOP���ܼ�¼��</returns>
  393. public int QueryOperationCount(string oPCode)
  394. {
  395. var resline = from a in DataProvider.ICSOP
  396. where oPCode.StartsWith(oPCode) && a.WorkPoint == AppConfig.WorkPointCode
  397. select a;
  398. return resline.ToList().Count;
  399. //return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLOP where 1=1 and OPCODE like '{0}%'", oPCode)));
  400. }
  401. /// <summary>
  402. /// ** ��������: ��ѯICSOP
  403. /// </summary>
  404. /// <param name="oPCode">OPCODE��ģ����ѯ</param>
  405. /// <param name="inclusive">��ʼ����</param>
  406. /// <param name="exclusive">��������</param>
  407. /// <returns> ICSOP����</returns>
  408. public object[] QueryOperation(string oPCode)
  409. {
  410. try
  411. {
  412. var resline = from a in DataProvider.ICSOP
  413. where a.OPCODE.StartsWith(oPCode) && a.WorkPoint==AppConfig.WorkPointCode
  414. select a;
  415. return resline.ToArray();
  416. }
  417. catch (Exception ex)
  418. {
  419. throw new Exception(ex.Message);
  420. }
  421. //return this.DataProvider.CustomQuery(typeof(ICSOP), new PagerCondition(string.Format("select {0} from TBLOP where 1=1 and OPCODE like '{1}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), oPCode), "OPCODE", inclusive, exclusive));
  422. }
  423. public object[] QueryOperation()
  424. {
  425. try
  426. {
  427. var resline = DataProvider.ICSOP.Where(p => p.WorkPoint == AppConfig.WorkPointCode);
  428. return resline.ToArray();
  429. }
  430. catch (Exception ex)
  431. {
  432. throw new Exception(ex.Message);
  433. }
  434. // return this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition("select distinct opcode from TBLOP ORDER BY opcode"));
  435. }
  436. /// <summary>
  437. /// ** ��������: �������е�ICSOP
  438. /// </summary>
  439. /// <returns>ICSOP���ܼ�¼��</returns>
  440. public object[] GetAllOperation()
  441. {
  442. try
  443. {
  444. var resline = from a in DataProvider.ICSOP
  445. where a.WorkPoint == AppConfig.WorkPointCode
  446. select a;
  447. return resline.ToArray();
  448. }
  449. catch (Exception ex)
  450. {
  451. throw new Exception(ex.Message);
  452. }
  453. //return this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format("select {0} from TBLOP order by OPCODE ", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)))));
  454. }
  455. public bool IsOperationInRoute(string routeCode, string opCode)
  456. {
  457. var resline = DataProvider.ICSROUTE2OP.Where(p=>p.ROUTECODE==routeCode&&p.OPCODE==opCode&&p.WORKPOINT==AppConfig.WorkPointCode);
  458. if (resline != null)
  459. {
  460. return true;
  461. }
  462. else
  463. {
  464. return false;
  465. }
  466. }
  467. #endregion
  468. #region ICSROUTE
  469. /// <summary>
  470. /// ** ��������: ��ѯICSROUTE��������
  471. /// </summary>
  472. /// <param name="routeCode">RouteCode��ģ����ѯ</param>
  473. /// <returns> ICSROUTE���ܼ�¼��</returns>
  474. public int QueryRouteCount(string routeCode)
  475. {
  476. var resline = DataProvider.ICSROUTE.Where(p=>p.ROUTECODE.StartsWith(routeCode));
  477. return resline.ToList().Count;
  478. //return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLROUTE where 1=1 and ROUTECODE like '{0}%' ", routeCode)));
  479. }
  480. /// <summary>
  481. /// ** ��������: ��ҳ��ѯICSROUTE
  482. /// </summary>
  483. /// <param name="routeCode">RouteCode��ģ����ѯ</param>
  484. /// <param name="inclusive">��ʼ����</param>
  485. /// <param name="exclusive">��������</param>
  486. /// <returns> ICSROUTE����</returns>
  487. public object[] QueryRoute(string routeCode)
  488. {
  489. try
  490. {
  491. var resline = DataProvider.ICSROUTE.Where(p => p.ROUTECODE.StartsWith(routeCode)&&p.WorkPoint==AppConfig.WorkPointCode);
  492. return resline.ToArray();
  493. }
  494. catch (Exception ex)
  495. {
  496. throw new Exception(ex.Message);
  497. }
  498. // return this.DataProvider.CustomQuery(typeof(ICSROUTE), new PagerCondition(string.Format("select {0} from TBLROUTE where 1=1 and ROUTECODE like '{1}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE)), routeCode), "ROUTECODE ", inclusive, exclusive));
  499. }
  500. /// <summary>
  501. /// ** ��������: ��ҳ��ѯICSROUTE
  502. /// </summary>
  503. /// <param name="routeCode">RouteCode��ģ����ѯ</param>
  504. /// <param name="inclusive">��ʼ����</param>
  505. /// <param name="exclusive">��������</param>
  506. /// <returns> ICSROUTE����</returns>
  507. public object[] QueryICSITEM2ROUTE(string itemCode)
  508. {
  509. try
  510. {
  511. var resline = DataProvider.ICSITEM2ROUTE.Where(p=>p.ITEMCODE==itemCode && p.WorkPoint==AppConfig.WorkPointCode);
  512. return resline.ToArray();
  513. }
  514. catch (Exception ex)
  515. {
  516. throw new Exception(ex.Message);
  517. }
  518. //return this.DataProvider.CustomQuery(typeof(ICSITEM2ROUTE),
  519. // new PagerCondition(string.Format("select {0} from TBLICSITEM2ROUTE where ITEMCODE = '{1}'"
  520. // + " and WorkPoint ='"+AppConfig.WorkPointCode+"'",
  521. // DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSITEM2ROUTE)), itemCode),
  522. // "ITEMCODE ", inclusive, exclusive));
  523. }
  524. /// <summary>
  525. /// ** ��������: ��ҳ��ѯICSROUTE
  526. /// </summary>
  527. /// <param name="routeCode">RouteCode��ģ����ѯ</param>
  528. /// <param name="inclusive">��ʼ����</param>
  529. /// <param name="exclusive">��������</param>
  530. /// <returns> ICSROUTE����</returns>
  531. public int GetICSITEM2ROUTECount(string itemCode)
  532. {
  533. try
  534. {
  535. var resline = DataProvider.ICSITEM2ROUTE.Where(p => p.ITEMCODE == itemCode && p.WorkPoint == AppConfig.WorkPointCode);
  536. return resline.ToList().Count;
  537. }
  538. catch (Exception)
  539. {
  540. throw;
  541. }
  542. }
  543. /// <summary>
  544. /// ** ��������: �������е�ICSROUTE
  545. /// </summary>
  546. /// <returns>ICSROUTE���ܼ�¼��</returns>
  547. public object[] GetAllRoute()
  548. {
  549. try
  550. {
  551. var resline = DataProvider.ICSROUTE.Where(p=>p.WorkPoint==AppConfig.WorkPointCode);
  552. return resline.ToArray();
  553. }
  554. catch (Exception ex)
  555. {
  556. throw new Exception(ex.Message);
  557. }
  558. //return this.DataProvider.CustomQuery(typeof(ICSROUTE), new SQLCondition(string.Format("select {0} from TBLROUTE order by ROUTECODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE)))));
  559. }
  560. /// <summary>
  561. /// ** ��������: �������е�ICSROUTE
  562. /// </summary>
  563. /// <returns>ICSROUTE���ܼ�¼��</returns>
  564. public object[] GetAllRouteEnabled()
  565. {
  566. try
  567. {
  568. var resline = DataProvider.ICSROUTE.Where(p=>p.WorkPoint==AppConfig.WorkPointCode&&p.ENABLED=="��Ч"&&p.WorkPoint==AppConfig.WorkPointCode);
  569. return resline.ToArray();
  570. }
  571. catch (Exception ex)
  572. {
  573. throw new Exception(ex.Message);
  574. }
  575. // return this.DataProvider.CustomQuery(typeof(ICSROUTE), new SQLCondition(string.Format("select {0} from TBLROUTE where enabled='1' order by ROUTECODE", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE)))));
  576. }
  577. public object GetOPFromRoute2OP(string routeCode, string resourceCode)
  578. {
  579. try
  580. {
  581. var resline = from a in DataProvider.ICSROUTE2OP
  582. join b in DataProvider.ICSOP2RES on a.OPCODE equals b.OPCODE
  583. select new {
  584. a,
  585. b
  586. };
  587. if (routeCode.Trim() != string.Empty)
  588. {
  589. resline = resline.Where(p=>p.a.ROUTECODE==routeCode.Trim().ToUpper());
  590. }
  591. if (resourceCode.Trim() != string.Empty)
  592. {
  593. resline = resline.Where(p => p.b.RESCODE == resourceCode.Trim().ToUpper());
  594. }
  595. return resline.ToArray() ;
  596. }
  597. catch (Exception ex)
  598. {
  599. throw new Exception(ex.Message);
  600. }
  601. //object[] returnObjects = this.DataProvider.CustomQuery(typeof(ICSROUTE2OP), new SQLCondition(sql));
  602. //if (returnObjects != null)
  603. //{
  604. // return returnObjects[0];
  605. //}
  606. //return null;
  607. }
  608. /// <summary>
  609. /// ** ��������: �������е�ICSROUTE
  610. /// </summary>
  611. /// <param name="routeCode"></param>
  612. /// <returns></returns>
  613. public bool IsRouteRef(string routeCode)
  614. {
  615. var resline = DataProvider.ICSITEM2ROUTE.Where(p=>p.ISREF=="��" && p.ROUTECODE==routeCode && p.WorkPoint==AppConfig.WorkPointCode);
  616. if (resline!=null)
  617. {
  618. return true;
  619. }
  620. else
  621. {
  622. return false;
  623. }
  624. //return (this.DataProvider.GetCount(new SQLCondition(string.Format(" select count(*) from ICSITEM2ROUTE where ISREF='��' AND ROUTECODE='{0}' ", routeCode))) > 0);
  625. }
  626. #endregion
  627. public void AddOrEdit(string Type)
  628. {
  629. System.Type type = System.Type.GetType(Type);
  630. }
  631. #region ICSROUTE2OP
  632. public ICSROUTE2OP CreateNewRoute2Operation()
  633. {
  634. return new ICSROUTE2OP();
  635. }
  636. public void AddAndUpdateRoute2Operation(ICSROUTE2OP route2Operation)
  637. {
  638. try
  639. {
  640. bool isNew = false;
  641. var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.ROUTEID == route2Operation.ROUTEID && a.OPID == route2Operation.OPID);
  642. if (line == null)
  643. {
  644. isNew = true;
  645. line = new ICSROUTE2OP();
  646. line.OPID = route2Operation.OPID;
  647. line.ROUTEID = route2Operation.ROUTEID;
  648. }
  649. line.ROUTECODE = route2Operation.ROUTECODE;
  650. line.OPCODE = route2Operation.OPCODE;
  651. line.OPSEQ = route2Operation.OPSEQ;
  652. line.OPCONTROL = route2Operation.OPCONTROL;
  653. line.MUSER = route2Operation.MUSER;
  654. line.MUSERName = route2Operation.MUSERName;
  655. line.MTIME = route2Operation.MTIME;
  656. line.WORKPOINT = route2Operation.WORKPOINT;
  657. line.EATTRIBUTE1 = route2Operation.EATTRIBUTE1;
  658. if (isNew) DataProvider.ICSROUTE2OP.InsertOnSubmit(line);
  659. DataProvider.SubmitChanges();
  660. }
  661. catch (Exception ex)
  662. {
  663. throw new Exception(ex.Message);
  664. }
  665. }
  666. public void AddRoute2Operation(ICSROUTE2OP[] route2Operations)
  667. {
  668. try
  669. {
  670. foreach (ICSROUTE2OP route2Operation in route2Operations)
  671. {
  672. bool isNew = false;
  673. var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.ROUTEID == route2Operation.ROUTEID && a.OPID == route2Operation.OPID);
  674. if (line == null)
  675. {
  676. isNew = true;
  677. line = new ICSROUTE2OP();
  678. line.OPID = route2Operation.OPID;
  679. line.ROUTEID = route2Operation.ROUTEID;
  680. }
  681. line.ROUTECODE = route2Operation.ROUTECODE;
  682. line.OPCODE = route2Operation.OPCODE;
  683. line.OPSEQ = route2Operation.OPSEQ;
  684. line.OPCONTROL = route2Operation.OPCONTROL;
  685. line.MUSER = route2Operation.MUSER;
  686. line.MUSERName = route2Operation.MUSERName;
  687. line.MTIME = route2Operation.MTIME;
  688. line.WORKPOINT = route2Operation.WORKPOINT;
  689. line.EATTRIBUTE1 = route2Operation.EATTRIBUTE1;
  690. if (isNew) DataProvider.ICSROUTE2OP.InsertOnSubmit(line);
  691. }
  692. DataProvider.SubmitChanges();
  693. }
  694. catch (Exception ex)
  695. {
  696. throw new Exception(ex.Message);
  697. }
  698. }
  699. public void UpdateRoute2Operation(ICSROUTE2OP route2Operation)
  700. {
  701. UpdateRoute2Operation(route2Operation, true);
  702. }
  703. public void UpdateRoute2Operation(ICSROUTE2OP route2Operation, bool checkSeq)
  704. {
  705. if (checkSeq)
  706. {
  707. var resline = DataProvider.ICSROUTE2OP.Where(p => p.ROUTECODE == route2Operation.ROUTECODE);
  708. //object[] route2Ops = this.DataProvider.CustomQuery(typeof(ICSROUTE2OP),
  709. // new SQLCondition(string.Format("select {0} from tblroute2op where routecode = '{1}'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSROUTE2OP)), route2Operation.RouteCode)));
  710. if (resline != null)
  711. {
  712. foreach (ICSROUTE2OP route2Op in resline)
  713. {
  714. if (route2Op.OPSEQ== route2Operation.OPSEQ
  715. && route2Op.OPCODE != route2Operation.OPCODE)
  716. {
  717. throw new Exception("$Error_Route2Operation_Sequence_Cannot_Repeat");
  718. }
  719. }
  720. }
  721. }
  722. AddAndUpdateRoute2Operation(route2Operation);
  723. }
  724. /// <summary>
  725. /// sammer kong 2005/05/21 route in usage
  726. /// </summary>
  727. /// <param name="route2Operation"></param>
  728. public void DeleteRoute2Operation(ICSROUTE2OP route2Operation)
  729. {
  730. try
  731. {
  732. var lines = DataProvider.ICSROUTE2OP.Where(a => a.OPID == route2Operation.OPID && a.ROUTEID == route2Operation.ROUTEID);
  733. DataProvider.ICSROUTE2OP.DeleteAllOnSubmit(lines);
  734. DataProvider.SubmitChanges();
  735. }
  736. catch (Exception ex)
  737. {
  738. throw ex;
  739. }
  740. }
  741. public void DeleteRoute2Operation(ICSROUTE2OP[] route2Operations)
  742. {
  743. try
  744. {
  745. foreach (ICSROUTE2OP route2Operation in route2Operations)
  746. {
  747. var lines = DataProvider.ICSROUTE2OP.Where(a => a.OPID == route2Operation.OPID && a.ROUTEID == route2Operation.ROUTEID);
  748. DataProvider.ICSROUTE2OP.DeleteAllOnSubmit(lines);
  749. }
  750. DataProvider.SubmitChanges();
  751. }
  752. catch (Exception ex)
  753. {
  754. throw ex;
  755. }
  756. }
  757. public bool IsRouteOperationInUsage(string routeCode, string opCode)
  758. {
  759. object obj = this.GetRoute2Operation(routeCode, opCode);
  760. if (obj != null && obj is ICSROUTE2OP)
  761. {
  762. //_standardRouteInUsage usageCheck = new _standardRouteInUsage(obj as ICSROUTE2OP, this.DataProvider);
  763. //return !usageCheck.Check();
  764. }
  765. else
  766. {
  767. //ExceptionManager.Raise(this.GetType(), "Error_Argument_Null");
  768. }
  769. return false;
  770. }
  771. public object GetRoute2Operation(string routeCode, string opCode)
  772. {
  773. try
  774. {
  775. var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.OPID == opCode && a.ROUTEID == routeCode);
  776. return line;
  777. }
  778. catch (Exception ex)
  779. {
  780. throw new Exception(ex.Message);
  781. }
  782. //return this.DataProvider.CustomSearch(typeof(ICSROUTE2OP), new object[] { routeCode, opCode });
  783. }
  784. //���ݲ�Ʒ;�̹���������ȡ����
  785. public object[] QueryCurrentRoute2Operation(string itemCode, string routeCode, string opCode)
  786. {
  787. try
  788. {
  789. var resline = DataProvider.ICSITEMROUTE2OP.Where(p=>p.ITEMCODE==itemCode&&p.ROUTECODE==routeCode&&p.OPCODE==opCode);
  790. return resline.ToArray();
  791. }
  792. catch (Exception ex)
  793. {
  794. throw new Exception(ex.Message);
  795. }
  796. //return this.DataProvider.CustomQuery(
  797. // typeof(ICSITEM2ROUTE),
  798. // new SQLCondition(
  799. // string.Format(" select {0} from TBLITEMROUTE2OP where itemcode = '{1}' and routecode = '{2}' and opcode = '{3}'" + " and WorkPoint ='" + AppConfig.WorkPointCode + "'",
  800. // DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSITEM2ROUTE)), itemCode, routeCode, opCode)));
  801. }
  802. #region ICSROUTE --> ICSOP
  803. /// <summary>
  804. /// ** ��������: ��RouteCode����ICSOP
  805. /// </summary>
  806. /// <param name="routeCode">RouteCode,��ȷ��ѯ</param>
  807. /// <returns>ICSOP����</returns>
  808. public object[] GetOperationByRouteCode(string routeCode)
  809. {
  810. string sql = string.Format("select * from ICSOP where OPCODE in ( select OPCODE from ICSROUTE2OP where ROUTECODE='{0}')", routeCode);
  811. DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
  812. ICSOP[] entity = new ICSOP[dt.Rows.Count];
  813. try
  814. {
  815. int i = 0;
  816. foreach (DataRow dr in dt.Rows)
  817. {
  818. var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["ID"].ToString() );
  819. entity[i] = line;
  820. i++;
  821. }
  822. return entity;
  823. }
  824. catch (Exception ex)
  825. {
  826. throw new Exception(ex.Message);
  827. }
  828. // return this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format("select {0} from TBLOP where OPCODE in ( select OPCODE from TBLROUTE2OP where ROUTECODE='{1}')", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), routeCode)));
  829. }
  830. /// <summary>
  831. /// ** ��������: ��RouteCode��������ICSROUTE��ICSOP������
  832. /// </summary>
  833. /// <param name="routeCode">RouteCode,��ȷ��ѯ</param>
  834. /// <param name="oPCode">OPCODE,ģ����ѯ</param>
  835. /// <returns>ICSOP������</returns>
  836. public int GetSelectedOperationByRouteCodeCount(string routeCode, string oPCode)
  837. {
  838. string sql = string.Format("select * from ICSROUTE2OP where ROUTECODE ='{0}' and OPCODE like '{1}%'", routeCode, oPCode);
  839. DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
  840. ICSROUTE2OP[] entity = new ICSROUTE2OP[dt.Rows.Count];
  841. try
  842. {
  843. int i = 0;
  844. foreach (DataRow dr in dt.Rows)
  845. {
  846. var line = DataProvider.ICSROUTE2OP.SingleOrDefault(a => a.ROUTEID == dr["ROUTEID"].ToString() && a.OPID == dr["OPID"].ToString());
  847. entity[i] = line;
  848. i++;
  849. }
  850. return entity.Length;
  851. }
  852. catch (Exception ex)
  853. {
  854. throw new Exception(ex.Message);
  855. }
  856. // return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLROUTE2OP where ROUTECODE ='{0}' and OPCODE like '{1}%'", routeCode, oPCode)));
  857. }
  858. /// <summary>
  859. /// ** ��������: ��RouteCode��������ICSROUTE��ICSOP����ҳ
  860. /// </summary>
  861. /// <param name="routeCode">RouteCode,��ȷ��ѯ</param>
  862. /// <param name="oPCode">OPCODE,ģ����ѯ</param>
  863. /// <param name="inclusive">��ʼ����</param>
  864. /// <param name="exclusive">��������</param>
  865. /// <returns>ICSOP����</returns>
  866. public object[] GetSelectedOperationByRouteCode(string routeCode, string oPCode)
  867. {
  868. string sql = string.Format("select * from ICSOP where OPCODE in ( select OPCODE from ICSROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode);
  869. DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
  870. ICSOP[] entity = new ICSOP[dt.Rows.Count];
  871. try
  872. {
  873. int i = 0;
  874. foreach (DataRow dr in dt.Rows)
  875. {
  876. var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["OPID"].ToString());
  877. entity[i] = line;
  878. i++;
  879. }
  880. return entity;
  881. }
  882. catch (Exception ex)
  883. {
  884. throw new Exception(ex.Message);
  885. }
  886. //return this.DataProvider.CustomQuery(typeof(ICSOP),
  887. // new PagerCondition(string.Format("select {0} from TBLOP where OPCODE in ( select OPCODE from TBLROUTE2OP where ROUTECODE ='{1}') and OPCODE like '{2}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), routeCode, oPCode), "OPCODE", inclusive, exclusive));
  888. }
  889. /// <summary>
  890. /// ** ��������: ��RouteCode������ICSROUTE��ICSOP������
  891. /// </summary>
  892. /// <param name="routeCode">RouteCode,��ȷ��ѯ</param>
  893. /// <param name="oPCode">OPCODE,ģ����ѯ</param>
  894. /// <returns>ICSOP������</returns>
  895. public int GetUnselectedOperationByRouteCodeCount(string routeCode, string oPCode)
  896. {
  897. string sql = string.Format("select * from ICSOP where OPCODE not in ( select OPCODE from ICSROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode);
  898. DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
  899. ICSOP[] entity = new ICSOP[dt.Rows.Count];
  900. try
  901. {
  902. int i = 0;
  903. foreach (DataRow dr in dt.Rows)
  904. {
  905. var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["OPID"].ToString());
  906. entity[i] = line;
  907. i++;
  908. }
  909. return entity.Length;
  910. }
  911. catch (Exception ex)
  912. {
  913. throw new Exception(ex.Message);
  914. }
  915. // return this.DataProvider.GetCount(new SQLCondition(string.Format("select count(*) from TBLOP where OPCODE not in ( select OPCODE from TBLROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode)));
  916. }
  917. /// <summary>
  918. /// ** ��������: ��RouteCode���ò�����ICSROUTE��ICSOP����ҳ
  919. /// </summary>
  920. /// <param name="routeCode">RouteCode,��ȷ��ѯ</param>
  921. /// <param name="oPCode">OPCODE,ģ����ѯ</param>
  922. /// <param name="inclusive">��ʼ����</param>
  923. /// <param name="exclusive">��������</param>
  924. /// <returns>ICSOP����</returns>
  925. public object[] GetUnselectedOperationByRouteCode(string routeCode, string oPCode, int inclusive, int exclusive)
  926. {
  927. string sql = string.Format("select * from ICSOP where OPCODE not in ( select OPCODE from ICSROUTE2OP where ROUTECODE ='{0}') and OPCODE like '{1}%'", routeCode, oPCode);
  928. DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
  929. ICSOP[] entity = new ICSOP[dt.Rows.Count];
  930. try
  931. {
  932. int i = 0;
  933. foreach (DataRow dr in dt.Rows)
  934. {
  935. var line = DataProvider.ICSOP.SingleOrDefault(a => a.ID == dr["OPID"].ToString());
  936. entity[i] = line;
  937. i++;
  938. }
  939. return entity;
  940. }
  941. catch (Exception ex)
  942. {
  943. throw new Exception(ex.Message);
  944. }
  945. // return this.DataProvider.CustomQuery(typeof(ICSOP),
  946. //new PagerCondition(string.Format("select {0} from TBLOP where OPCODE not in ( select OPCODE from TBLROUTE2OP where ROUTECODE ='{1}') and OPCODE like '{2}%'", DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSOP)), routeCode, oPCode), "OPCODE", inclusive, exclusive));
  947. }
  948. /// <summary>
  949. /// ** ��������: ��RouteCode��������ICSROUTE��OperationOfRoute����ҳ
  950. /// </summary>
  951. /// <param name="routeCode">RouteCode,��ȷ��ѯ</param>
  952. /// <param name="oPCode">OPCODE,ģ����ѯ</param>
  953. /// <param name="inclusive">��ʼ����</param>
  954. /// <param name="exclusive">��������</param>
  955. /// <returns>OperationOfRoute����</returns>
  956. public object[] GetSelectedOperationOfRouteByRouteCode(string routeCode, string opCode)
  957. {
  958. string sql = string.Format("select {0}, ICSROUTE2OP.OPSEQ, ICSROUTE2OP.ROUTECODE from ICSOP a,ICSROUTE2OP b where ICSOP.OPCODE = ICSROUTE2OP.OPCODE and ICSROUTE2OP.ROUTECODE='{1}' and a.WORKPOINT='" + AppConfig.WorkPointCode + "' and b.WORKPOINT='" + AppConfig.WorkPointCode + "' and ICSROUTE2OP.OPCODE like '{2}%'", "ICSROUTE2OP.OPCODE,ICSOP.OPDESC,ICSOP.OPCOLLECTION,ICSROUTE2OP.OPCONTROL,ICSROUTE2OP.MUSERName,ICSROUTE2OP.MTIME,ICSROUTE2OP.EAttribute1", routeCode, opCode);
  959. DataTable dt = DBHelper.ExecuteDataset(sql, CommandType.Text, AppConfig.AppConnectString).Tables[0];
  960. Object[] entity = new Object[dt.Rows.Count];
  961. try
  962. {
  963. int i = 0;
  964. foreach (DataRow dr in dt.Rows)
  965. {
  966. Object[] obj = new Object[dt.Columns.Count];
  967. for (int m = 0; m < dt.Columns.Count; m++)
  968. {
  969. obj[m] = dr[m];
  970. }
  971. entity[i]=obj;
  972. i++;
  973. }
  974. return entity;
  975. }
  976. catch (Exception ex)
  977. {
  978. throw new Exception(ex.Message);
  979. }
  980. //return this.DataProvider.CustomQuery(typeof(FormOperationOfRouteModel), new PagerCondition(string.Format("select {0}, TBLROUTE2OP.OPSEQ, TBLROUTE2OP.ROUTECODE from TBLOP,TBLROUTE2OP where TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' and TBLROUTE2OP.OPCODE like '{2}%'", "TBLROUTE2OP.OPCODE,TBLOP.OPDESC,TBLOP.OPCOLLECTION,TBLROUTE2OP.OPCONTROL,TBLROUTE2OP.MUSER,TBLROUTE2OP.MDATE,TBLROUTE2OP.MTIME,TBLROUTE2OP.EAttribute1", routeCode, opCode), "TBLROUTE2OP.OPSEQ", inclusive, exclusive));
  981. }
  982. #endregion
  983. #endregion
  984. #region ICSOP2RES
  985. public ICSOP2RES CreateNewOperation2Resource()
  986. {
  987. return new ICSOP2RES();
  988. }
  989. public void AddAndUpdateOperation2Resource(ICSOP2RES operation2Resource)
  990. {
  991. try
  992. {
  993. bool isNew = false;
  994. var line = DataProvider.ICSOP2RES.SingleOrDefault(a => a.RESID == operation2Resource.RESID && a.OPID == operation2Resource.OPID);
  995. if (line == null)
  996. {
  997. isNew = true;
  998. line = new ICSOP2RES();
  999. line.OPID = operation2Resource.OPID;
  1000. line.RESID = operation2Resource.RESID;
  1001. }
  1002. line.RESCODE = operation2Resource.RESCODE;
  1003. line.OPCODE = operation2Resource.OPCODE;
  1004. line.RESSEQ = operation2Resource.RESSEQ;
  1005. line.MUSER = operation2Resource.MUSER;
  1006. line.MUSERName = operation2Resource.MUSERName;
  1007. line.MTIME = operation2Resource.MTIME;
  1008. line.WorkPoint = operation2Resource.WorkPoint;
  1009. line.EATTRIBUTE1 = operation2Resource.EATTRIBUTE1;
  1010. if (isNew) DataProvider.ICSOP2RES.InsertOnSubmit(line);
  1011. DataProvider.SubmitChanges();
  1012. }
  1013. catch (Exception ex)
  1014. {
  1015. throw new Exception(ex.Message);
  1016. }
  1017. //this._helper.AddDomainObject(operation2Resource);
  1018. }
  1019. public void AddOperation2Resource(ICSOP2RES[] operation2Resources)
  1020. {
  1021. try
  1022. {
  1023. foreach (ICSOP2RES operation2Res in operation2Resources)
  1024. {
  1025. bool isNew = false;
  1026. var line = DataProvider.ICSOP2RES.SingleOrDefault(a => a.RESID == operation2Res.RESID && a.OPID == operation2Res.OPID);
  1027. if (line == null)
  1028. {
  1029. isNew = true;
  1030. line = new ICSOP2RES();
  1031. line.OPID = operation2Res.OPID;
  1032. line.RESID = operation2Res.RESID;
  1033. }
  1034. line.RESCODE = operation2Res.RESCODE;
  1035. line.OPCODE = operation2Res.OPCODE;
  1036. line.RESSEQ = operation2Res.RESSEQ;
  1037. line.MUSER = operation2Res.MUSER;
  1038. line.MUSERName = operation2Res.MUSERName;
  1039. line.MTIME = operation2Res.MTIME;
  1040. line.WorkPoint = operation2Res.WorkPoint;
  1041. line.EATTRIBUTE1 = operation2Res.EATTRIBUTE1;
  1042. if (isNew) DataProvider.ICSOP2RES.InsertOnSubmit(line);
  1043. }
  1044. DataProvider.SubmitChanges();
  1045. }
  1046. catch (Exception ex)
  1047. {
  1048. throw new Exception(ex.Message);
  1049. }
  1050. //this._helper.AddDomainObject(operation2Resources);
  1051. }
  1052. //public void UpdateOperation2Resource(ICSOP2RES operation2Resource)
  1053. //{
  1054. // this._helper.UpdateDomainObject(operation2Resource);
  1055. //}
  1056. public void DeleteOperation2Resource(ICSOP2RES operation2Resource)
  1057. {
  1058. try
  1059. {
  1060. var lines = DataProvider.ICSOP2RES.Where(a => a.OPID == operation2Resource.OPID && a.RESID == operation2Resource.RESID);
  1061. DataProvider.ICSOP2RES.DeleteAllOnSubmit(lines);
  1062. DataProvider.SubmitChanges();
  1063. }
  1064. catch (Exception ex)
  1065. {
  1066. throw ex;
  1067. }
  1068. //this._helper.DeleteDomainObject(operation2Resource);
  1069. }
  1070. public void DeleteOperation2Resource(ICSOP2RES[] operation2Resources)
  1071. {
  1072. try
  1073. {
  1074. for (int i = 0; i < operation2Resources.Length;i++ )
  1075. {
  1076. var lines = DataProvider.ICSOP2RES.Where(a => a.OPID == operation2Resources[i].OPID && a.RESID == operation2Resources[i].RESID);
  1077. DataProvider.ICSOP2RES.DeleteAllOnSubmit(lines);
  1078. }
  1079. DataProvider.SubmitChanges();
  1080. }
  1081. catch (Exception ex)
  1082. {
  1083. throw ex;
  1084. }
  1085. }
  1086. public object GetOperation2Resource(string operationCode, string resourceCode)
  1087. {
  1088. try
  1089. {
  1090. var resline = DataProvider.ICSOP2RES.SingleOrDefault(p => p.OPCODE == operationCode && p.RESCODE == resourceCode && p.WorkPoint == AppConfig.WorkPointCode);
  1091. return resline;
  1092. }
  1093. catch (Exception ex)
  1094. {
  1095. throw new Exception(ex.Message);
  1096. }
  1097. }
  1098. #region ICSOP --> ICSRES
  1099. /// <summary>
  1100. /// ** ��������: ��OPCODE����ICSRES
  1101. /// </summary>
  1102. /// <param name="oPCode">OPCODE,��ȷ��ѯ</param>
  1103. /// <returns>ICSRES����</returns>
  1104. public object[] GetResourceByOperationCode(string oPCode)
  1105. {
  1106. try
  1107. {
  1108. var opline=from a in DataProvider.ICSRES
  1109. where (from b in DataProvider.ICSOP2RES
  1110. where b.OPCODE==oPCode && b.WorkPoint==AppConfig.WorkPointCode
  1111. select b.RESCODE).Contains(a.RESCODE) && a.WorkPoint==AppConfig.WorkPointCode
  1112. select a;
  1113. return opline.ToArray();
  1114. }
  1115. catch (Exception ex)
  1116. {
  1117. throw new Exception(ex.Message);
  1118. }
  1119. //return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), oPCode)));
  1120. }
  1121. public ICSOP2RES GetOperationByResource(string rescode)
  1122. {
  1123. try
  1124. {
  1125. var opline = from a in DataProvider.ICSOP2RES
  1126. where a.RESCODE == rescode && a.WorkPoint == AppConfig.WorkPointCode
  1127. select a;
  1128. return opline.ToList()[0];
  1129. }
  1130. catch (Exception ex)
  1131. {
  1132. throw new Exception(ex.Message);
  1133. }
  1134. }
  1135. /// <summary>
  1136. /// ** ������������ICSSS����ICSRES
  1137. /// </summary>
  1138. /// <param name="ICSSS">ICSSS,��ȷ��ѯ</param>
  1139. /// <returns>ICSRES ����</returns>
  1140. public object[] GetResourceByStepSequenceCode(string StepSequenceCode)
  1141. {
  1142. try
  1143. {
  1144. var opline = from a in DataProvider.ICSRES
  1145. where (from b in DataProvider.ICSSS
  1146. where b.SSCODE == StepSequenceCode && b.WorkPoint == AppConfig.WorkPointCode
  1147. select b.ID).Contains(a.SSID) && a.WorkPoint == AppConfig.WorkPointCode
  1148. select a;
  1149. return opline.ToArray();
  1150. }
  1151. catch (Exception ex)
  1152. {
  1153. throw new Exception(ex.Message);
  1154. }
  1155. //return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), StepSequenceCode)));
  1156. }
  1157. /// <summary>
  1158. /// ** ��������: ��OPCODE��������ICSOP��ICSRES������
  1159. /// </summary>
  1160. /// <param name="oPCode">OPCODE,��ȷ��ѯ</param>
  1161. /// <param name="resourceCode">ResourceCode,ģ����ѯ</param>
  1162. /// <returns>ICSRES������</returns>
  1163. public int GetSelectedResourceByOperationCodeCount(string oPCode, string resourceCode)
  1164. {
  1165. var opline = from a in DataProvider.ICSOP2RES
  1166. join b in DataProvider.ICSRES on a.RESCODE equals b.RESCODE
  1167. where a.OPCODE == oPCode && b.RESCODE.StartsWith(resourceCode)
  1168. && a.WorkPoint == AppConfig.WorkPointCode
  1169. select new { a, b };
  1170. return opline.ToList().Count;
  1171. //return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, oPCode, resourceCode)));
  1172. }
  1173. public int GetResourceByOpCodeAndDctCodeCount(string oPCode, string dctCode)
  1174. {
  1175. var opline = from a in DataProvider.ICSOP2RES
  1176. join b in DataProvider.ICSRES on a.RESCODE equals b.RESCODE
  1177. where a.OPCODE == oPCode && b.DCTCODE.StartsWith(dctCode) && a.WorkPoint == AppConfig.WorkPointCode
  1178. select new { a, b };
  1179. return opline.ToList().Count;
  1180. //return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, oPCode, dctCode)));
  1181. }
  1182. /// <summary>
  1183. /// ** ��������: ��OPCODE��������ICSOP��ICSRES����ҳ
  1184. /// </summary>
  1185. /// <param name="oPCode">OPCODE,��ȷ��ѯ</param>
  1186. /// <param name="resourceCode">ResourceCode,ģ����ѯ</param>
  1187. /// <param name="inclusive">��ʼ����</param>
  1188. /// <param name="exclusive">��������</param>
  1189. /// <returns>ICSRES����</returns>
  1190. public object[] GetSelectedResourceByOperationCode(string oPCode, string resourceCode)
  1191. {
  1192. try
  1193. {
  1194. var opline = from a in DataProvider.ICSRES
  1195. where (from b in DataProvider.ICSOP2RES
  1196. where b.OPCODE == oPCode && b.WorkPoint == AppConfig.WorkPointCode
  1197. select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint == AppConfig.WorkPointCode
  1198. select a;
  1199. return opline.ToArray();
  1200. }
  1201. catch (Exception ex)
  1202. {
  1203. throw new Exception(ex.Message);
  1204. }
  1205. //return this.DataProvider.CustomQuery(typeof(ICSRES),
  1206. // new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), oPCode, resourceCode), "RESCODE", inclusive, exclusive));
  1207. }
  1208. public object[] GetResourceByDCTCode(string dctCode)
  1209. {
  1210. try
  1211. {
  1212. var opline = from a in DataProvider.ICSRES
  1213. where a.DCTCODE==dctCode && a.WorkPoint == AppConfig.WorkPointCode
  1214. select a;
  1215. return opline.ToArray();
  1216. }
  1217. catch (Exception ex)
  1218. {
  1219. throw new Exception(ex.Message);
  1220. }
  1221. //return this.DataProvider.CustomQuery(typeof(ICSRES),
  1222. //new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), dctCode), "dctcode", inclusive, exclusive));
  1223. }
  1224. /// <summary>
  1225. /// ** ��������: ��OPCODE������ICSOP��ICSRES������
  1226. /// </summary>
  1227. /// <param name="oPCode">OPCODE,��ȷ��ѯ</param>
  1228. /// <param name="resourceCode">ResourceCode,ģ����ѯ</param>
  1229. /// <returns>ICSRES������</returns>
  1230. public int GetUnselectedResourceByOperationCodeCount(string oPCode, string resourceCode)
  1231. {
  1232. try
  1233. {
  1234. var opline = from a in DataProvider.ICSRES
  1235. where !(from b in DataProvider.ICSOP2RES
  1236. where 1 == 1 && b.WorkPoint == AppConfig.WorkPointCode
  1237. select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(oPCode) && a.WorkPoint == AppConfig.WorkPointCode
  1238. select a;
  1239. return opline.ToList().Count;
  1240. }
  1241. catch (Exception ex)
  1242. {
  1243. throw new Exception(ex.Message);
  1244. }
  1245. //return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, oPCode, resourceCode)));
  1246. }
  1247. public int GetUnselectedResourceByDCTCodeCount(string dctCode, string resourceCode)
  1248. {
  1249. try
  1250. {
  1251. var opline = from a in DataProvider.ICSRES
  1252. where !a.DCTCODE.ToUpper().StartsWith(dctCode) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint == AppConfig.WorkPointCode
  1253. select a;
  1254. return opline.ToList().Count;
  1255. }
  1256. catch (Exception ex)
  1257. {
  1258. throw new Exception(ex.Message);
  1259. }
  1260. //return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, dctCode, resourceCode)));
  1261. }
  1262. public int GetResourceByresAndDCTCodeCount(string resourceCode, string dctCode)
  1263. {
  1264. try
  1265. {
  1266. var opline = from a in DataProvider.ICSRES
  1267. where a.DCTCODE == resourceCode && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint == AppConfig.WorkPointCode
  1268. select a;
  1269. return opline.ToList().Count;
  1270. }
  1271. catch (Exception ex)
  1272. {
  1273. throw new Exception(ex.Message);
  1274. }
  1275. //return this.DataProvider.GetCount(new SQLCondition(string.Format(sql, dctCode, resourceCode)));
  1276. }
  1277. /// <summary>
  1278. /// ** ��������: ��OPCODE���ò�����ICSOP��ICSRES����ҳ
  1279. /// </summary>
  1280. /// <param name="oPCode">OPCODE,��ȷ��ѯ</param>
  1281. /// <param name="resourceCode">ResourceCode,ģ����ѯ</param>
  1282. /// <param name="inclusive">��ʼ����</param>
  1283. /// <param name="exclusive">��������</param>
  1284. /// <returns>ICSRES����</returns>
  1285. public object[] GetUnselectedResourceByOperationCode(string oPCode, string resourceCode)
  1286. {
  1287. try
  1288. {
  1289. var opline = from a in DataProvider.ICSRES
  1290. where !(from b in DataProvider.ICSOP2RES
  1291. where b.RESCODE.ToUpper().StartsWith(resourceCode)&& b.OPCODE==oPCode && b.WorkPoint==AppConfig.WorkPointCode
  1292. select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode
  1293. select a;
  1294. return opline.ToArray();
  1295. }
  1296. catch (Exception ex)
  1297. {
  1298. throw new Exception(ex.Message);
  1299. }
  1300. // return this.DataProvider.CustomQuery(typeof(ICSRES),
  1301. // new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), oPCode, resourceCode), "RESCODE", inclusive, exclusive));
  1302. }
  1303. public object[] GetUnselectedResourceByDCTCode(string dctCode, string resourceCode)
  1304. {
  1305. try
  1306. {
  1307. var opline = from a in DataProvider.ICSRES
  1308. where !(from b in DataProvider.ICSRES
  1309. where b.DCTCODE.ToUpper().StartsWith(dctCode) && b.WorkPoint==AppConfig.WorkPointCode
  1310. select b.RESCODE).Contains(a.RESCODE) && a.RESCODE.StartsWith(resourceCode) && a.WorkPoint==AppConfig.WorkPointCode
  1311. select a;
  1312. return opline.ToArray();
  1313. }
  1314. catch (Exception ex)
  1315. {
  1316. throw new Exception(ex.Message);
  1317. }
  1318. //return this.DataProvider.CustomQuery(typeof(ICSRES),
  1319. // new PagerCondition(string.Format(sql, DomainObjectUtility.GetDomainObjectFieldsString(typeof(ICSRES)), dctCode, resourceCode), "RESCODE", inclusive, exclusive));
  1320. }
  1321. /// <summary>
  1322. /// ** ��������: ��OPCODE��������ICSOP��ResourceOfOperation����ҳ
  1323. /// </summary>
  1324. /// <param name="oPCode">OPCODE,��ȷ��ѯ</param>
  1325. /// <param name="resourceCode">ResourceCode,ģ����ѯ</param>
  1326. /// <param name="inclusive">��ʼ����</param>
  1327. /// <param name="exclusive">��������</param>
  1328. /// <returns>ResourceOfOperation����</returns>
  1329. public object[] GetSelectedResourceOfOperationByOperationCode(string opCode, string resCode, int inclusive, int exclusive)
  1330. {
  1331. try
  1332. {
  1333. var opline = from a in DataProvider.ICSOP2RES
  1334. join b in DataProvider.ICSRES on a.RESCODE equals b.RESCODE
  1335. where a.OPCODE == opCode && b.RESCODE.StartsWith(resCode) //&& a.WorkPoint == AppConfig.WorkPointCode && b.WorkPoint == AppConfig.WorkPointCode
  1336. select new {b};
  1337. DataProvider.Connection.Close();
  1338. return opline.ToArray();
  1339. }
  1340. catch (Exception ex)
  1341. {
  1342. throw new Exception(ex.Message);
  1343. }
  1344. // return this.DataProvider.CustomQuery(typeof(ResourceOfOperation), new PagerCondition(string.Format(sql,
  1345. // DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSRES)), opCode, resCode), "TBLOP2RES.RESSEQ", inclusive, exclusive));
  1346. }
  1347. /// <summary>
  1348. /// ** ������������moCode����ICSRES
  1349. /// </summary>
  1350. /// <param name="MOCode">moCode,��ȷ��ѯ</param>
  1351. /// <returns>ICSRES ����</returns>
  1352. public object[] GetResourceByMoCode(string MOCode)
  1353. {
  1354. try
  1355. {
  1356. var opline = from a in DataProvider.ICSRES
  1357. join b in DataProvider.ICSOP2RES on a.RESCODE equals b.RESCODE
  1358. join c in DataProvider.ICSOP on b.OPCODE equals c.OPCODE
  1359. join d in DataProvider.ICSROUTE2OP on c.OPCODE equals d.OPCODE
  1360. join e in DataProvider.ICSROUTE on d.ROUTECODE equals e.ROUTECODE
  1361. join f in DataProvider.ICSMO2ROUTE on e.ROUTECODE equals f.ROUTECODE
  1362. join g in DataProvider.ICSMO on f.MOCODE equals g.MOCODE
  1363. where g.MOCODE == MOCode && a.WorkPoint == AppConfig.WorkPointCode &&
  1364. b.WorkPoint == AppConfig.WorkPointCode && c.WorkPoint == AppConfig.WorkPointCode &&
  1365. d.WORKPOINT == AppConfig.WorkPointCode && f.WorkPoint == AppConfig.WorkPointCode && g.WorkPoint == AppConfig.WorkPointCode
  1366. orderby a.RESCODE
  1367. select new { a,b,c,d,e,f,g};
  1368. return opline.ToArray();
  1369. }
  1370. catch (Exception ex)
  1371. {
  1372. throw new Exception(ex.Message);
  1373. }
  1374. //if (GlobalVariables.CurrentOrganizations.GetSQLConditionWithoutColumnName().Length > 0)
  1375. //{
  1376. // sql += " and TBLRES.ORGID in (" + GlobalVariables.CurrentOrganizations.GetSQLConditionWithoutColumnName() + ")";
  1377. //}
  1378. //return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, MOCode)));
  1379. }
  1380. /// <summary>
  1381. /// ** ������������moCode����SMTResource
  1382. /// </summary>
  1383. /// <param name="MOCode">moCode,��ȷ��ѯ</param>
  1384. /// <returns>ICSRES ����</returns>
  1385. //public object[] GetSMTResourceByMoCode(string MOCode)
  1386. //{
  1387. //
  1388. // string sql = "";
  1389. // sql += "select ICSRES.* from ICSRES where RESCODE IN (select RESCODE from ICSSMTRESBOM where MOCODE = '{0}') ";
  1390. // sql += " and WorkPoint ='" + AppConfig.WorkPointCode + "'";
  1391. // sql += " ORDER BY TBLRES.rescode ";
  1392. // // End Added
  1393. // return this.DataProvider.CustomQuery(typeof(ICSRES), new SQLCondition(string.Format(sql, MOCode)));
  1394. //}
  1395. #endregion
  1396. #endregion
  1397. #region ICSROUTE --> ICSOP --> ICSRES
  1398. /// <summary>
  1399. /// ** ��������: ��ICSROUTE��ICSRES����ICSOP
  1400. /// </summary>
  1401. /// <param name="routeCode">RouteCode</param>
  1402. /// <param name="resourceCode">ResourceCode</param>
  1403. /// <returns></returns>
  1404. public object GetOperationByRouteAndResource(string routeCode, string resourceCode)
  1405. {
  1406. try
  1407. {
  1408. var resline = from a in DataProvider.ICSOP
  1409. join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
  1410. join c in DataProvider.ICSOP2RES on a.OPCODE equals c.OPCODE
  1411. where b.ROUTECODE == routeCode && c.RESCODE == resourceCode
  1412. select a;
  1413. return resline.ToList()[0] ;
  1414. }
  1415. catch (Exception ex)
  1416. {
  1417. throw new Exception(ex.Message);
  1418. }
  1419. // object[] objs = this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format(@"select {0} from TBLOP,TBLROUTE2OP,TBLOP2RES where TBLOP.OPCODE = TBLOP2RES.OPCODE and
  1420. // TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' and TBLOP2RES.RESCODE='{2}'",
  1421. // DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSOP)), routeCode, resourceCode)));
  1422. //if (objs != null && objs.Length > 0)
  1423. //{
  1424. // return objs[0];
  1425. //}
  1426. //return null;
  1427. }
  1428. /// <summary>
  1429. /// ** ��������: ����ICSROUTE�ĵ�һ��ICSOP
  1430. /// </summary>
  1431. /// <param name="routeCode">RouteCode</param>
  1432. /// <returns></returns>
  1433. public object GetFirstOperationOfRoute(string routeCode)
  1434. {
  1435. var resline = from a in DataProvider.ICSOP
  1436. join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
  1437. where b.ROUTECODE == routeCode && a.WorkPoint == AppConfig.WorkPointCode && b.WORKPOINT == AppConfig.WorkPointCode
  1438. orderby b.OPSEQ
  1439. select a.OPCODE;
  1440. try
  1441. {
  1442. if (resline != null && resline.ToList().Count > 0)
  1443. {
  1444. return resline.ToList()[0];
  1445. }
  1446. else
  1447. {
  1448. return null;
  1449. }
  1450. }
  1451. catch (Exception ex)
  1452. {
  1453. throw new Exception(ex.Message);
  1454. }
  1455. //object[] objs = this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format(@"select routeCode from TBLOP,TBLROUTE2OP where TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' order by TBLROUTE2OP.OPSEQ",
  1456. // DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSOP)), routeCode)));
  1457. }
  1458. /// <summary>
  1459. /// ** ��������: ����ICSROUTE����һ��ICSOP
  1460. /// </summary>
  1461. /// <param name="routeCode">RouteCode</param>
  1462. /// <param name="currentOperationCode">��ǰOP</param>
  1463. /// <returns></returns>
  1464. public object GetNextOperationOfRoute(string routeCode, string currentOperationCode)
  1465. {
  1466. try
  1467. {
  1468. var opline = from a in DataProvider.ICSOP
  1469. join b in DataProvider.ICSROUTE2OP on a.OPCODE equals b.OPCODE
  1470. where b.ROUTECODE == routeCode && (from c in DataProvider.ICSROUTE2OP
  1471. where c.ROUTECODE == routeCode && c.OPCODE == currentOperationCode && c.WORKPOINT == AppConfig.WorkPointCode
  1472. select c.OPSEQ).Equals(b.OPSEQ-1) && a.OPCODE == currentOperationCode && a.WorkPoint == AppConfig.WorkPointCode
  1473. select new {
  1474. a
  1475. };
  1476. if (opline != null && opline.ToList().Count > 0)
  1477. {
  1478. return opline.ToList()[0];
  1479. }
  1480. else
  1481. {
  1482. return null;
  1483. }
  1484. }
  1485. catch (Exception ex)
  1486. {
  1487. throw new Exception(ex.Message);
  1488. }
  1489. //operations = this.DataProvider.CustomQuery(typeof(ICSOP), new SQLCondition(string.Format("select {0} from TBLOP,TBLROUTE2OP where TBLOP.OPCODE = TBLROUTE2OP.OPCODE and TBLROUTE2OP.ROUTECODE='{1}' and TBLROUTE2OP.OPSEQ > {2} order by TBLROUTE2OP.OPSEQ",
  1490. // DomainObjectUtility.GetDomainObjectFieldsStringWithTableName(typeof(ICSOP)), routeCode, ((ICSROUTE2OP)relation).OPSEQ)));
  1491. }
  1492. #region this is for cs
  1493. public ICSITEMROUTE2OP GetMORouteFirstOperation(string moCode, string routeCode)
  1494. {
  1495. ICSMO mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode );
  1496. string selectSql = " select * "
  1497. + " from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' and "
  1498. + " opseq = (select min(opseq) from ICSITEMROUTE2OP"
  1499. + " where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' And workpoint = '" + AppConfig.WorkPointCode + "')";
  1500. List<ICSITEMROUTE2OP> list = this.DataProvider.ExecuteQuery<ICSITEMROUTE2OP>(selectSql).ToList();
  1501. if (list == null || list.Count ==1)
  1502. {
  1503. throw new Exception("$Error_ItemRoute_NotExist" + String.Format("[$Itemcode='{0}',$routecode='{1}']", mo.ITEMCODE, routeCode));
  1504. }
  1505. return (ICSITEMROUTE2OP)list[0];
  1506. }
  1507. public ICSITEMROUTE2OP GetMORouteNextOperation(string moCode, string routeCode, string opCode)
  1508. {
  1509. ICSMO mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode);
  1510. if (mo == null)
  1511. {
  1512. throw new Exception("$Error_MONotExisted");
  1513. }
  1514. string selectSql = " select * "
  1515. + " from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' "
  1516. + " and workpoint = '"+AppConfig.WorkPointCode+"'"
  1517. + " and opseq > (select opseq from ICSITEMROUTE2OP"
  1518. + " where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' and opcode='" + opCode + "' and workpoint = '" + AppConfig.WorkPointCode + "' order by opseq";
  1519. List<ICSITEMROUTE2OP> list = this.DataProvider.ExecuteQuery<ICSITEMROUTE2OP>(selectSql).ToList();
  1520. if (list == null || list.Count == 1)
  1521. {
  1522. throw new Exception("$Error_ItemRoute_NotExist" + String.Format("[$Itemcode='{0}',$routecode='{1}']", mo.ITEMCODE, routeCode));
  1523. }
  1524. return (ICSITEMROUTE2OP)list[0];
  1525. }
  1526. public bool OperationIsRouteLastOperation(string moCode, string routeCode, string OpCode)
  1527. {
  1528. ICSMO mo = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == moCode && a.WorkPoint == AppConfig.WorkPointCode);
  1529. if (mo == null)
  1530. {
  1531. throw new Exception("$Error_MONotExisted");
  1532. }
  1533. string selectSql = " select count(*) "
  1534. + " from ICSITEMROUTE2OP where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' And workpoint = '"+AppConfig.WorkPointCode+"'"
  1535. + " and opseq = (select max(opseq) from ICSITEMROUTE2OP"
  1536. + " where itemcode = '" + mo.ITEMCODE + "' and routecode = '" + routeCode + "' And workpoint = '" + AppConfig.WorkPointCode + "') and opcode='" + OpCode + "'";
  1537. var query = this.DataProvider.ExecuteQuery<int>(selectSql);
  1538. int iCount = query.First<int>();
  1539. if (iCount > 0)
  1540. {
  1541. return true;
  1542. }
  1543. return false;
  1544. }
  1545. #endregion
  1546. #endregion
  1547. #region Time Period
  1548. /// <summary>
  1549. /// ** ��������: ����Shift�����е�TimePeriod
  1550. /// ** �� ��:
  1551. /// ** �� ��:
  1552. /// </summary>
  1553. /// <param name="shiftCode">ShiftCode</param>
  1554. /// <returns>TimePeriod����</returns>
  1555. public List<ICSTP> GetTimePeriodByShiftCode(string shiftCode)
  1556. {
  1557. string sqlStr = "select * from ICSLTP where SHIFTCODE='"+shiftCode+"' order by TPSEQ";
  1558. return this.DataProvider.ExecuteQuery<ICSTP>(sqlStr).ToList();
  1559. }
  1560. public object GetTimePeriod(string timePeriodCode)
  1561. {
  1562. return this.DataProvider.ICSTP.SingleOrDefault(a => a.TPCODE == timePeriodCode && a.WorkPoint == AppConfig.WorkPointCode);
  1563. }
  1564. /// <summary>
  1565. /// ��ȡTimePeriod��ʼʱ��
  1566. /// </summary>
  1567. /// <param name="timePeriodCode"></param>
  1568. /// <returns></returns>
  1569. public int GetTimePeriodBeginTime(string timePeriodCode)
  1570. {
  1571. return this.DataProvider.ICSTP.SingleOrDefault(a => a.TPCODE == timePeriodCode && a.WorkPoint == AppConfig.WorkPointCode).TPBTIME;
  1572. }
  1573. /// <summary>
  1574. /// ��ȡTimePeriod����ʱ��
  1575. /// </summary>
  1576. /// <param name="timePeriodCode"></param>
  1577. /// <returns></returns>
  1578. public int GetTimePeriodEndTime(string timePeriodCode)
  1579. {
  1580. return this.DataProvider.ICSTP.SingleOrDefault(a => a.TPCODE == timePeriodCode && a.WorkPoint == AppConfig.WorkPointCode).TPETIME;
  1581. }
  1582. public int GetShiftDay(ICSTP currentTimePeriod, DateTime currentDateTime)
  1583. {
  1584. int shiftDay = FormatHelper.TODateInt(currentDateTime);
  1585. if (currentTimePeriod != null)
  1586. {
  1587. if (currentTimePeriod.ISOVERDATE == FormatHelper.TRUE_STRING)
  1588. {
  1589. if (currentTimePeriod.TPBTIME < currentTimePeriod.TPETIME)
  1590. {
  1591. shiftDay = FormatHelper.TODateInt(currentDateTime.AddDays(-1));
  1592. }
  1593. else if (FormatHelper.TOTimeInt(currentDateTime) < currentTimePeriod.TPBTIME)
  1594. {
  1595. shiftDay = FormatHelper.TODateInt(currentDateTime.AddDays(-1));
  1596. }
  1597. }
  1598. }
  1599. return shiftDay;
  1600. }
  1601. public int GetShiftDayBySS(ICSSS stepSequence, DateTime currentDateTime)
  1602. {
  1603. int returnValue = FormatHelper.TODateInt(currentDateTime);
  1604. if (stepSequence != null)
  1605. {
  1606. ICSTP tp = (ICSTP)GetTimePeriod(stepSequence.SHIFTTYPEID, FormatHelper.TOTimeInt(currentDateTime));
  1607. if (tp != null)
  1608. {
  1609. returnValue = GetShiftDay(tp, currentDateTime);
  1610. }
  1611. }
  1612. return returnValue;
  1613. }
  1614. public ICSSHIFT GetShift(string shiftTypeId, int time)
  1615. {
  1616. ICSSHIFT returnValue = null;
  1617. ICSTP tp = (ICSTP)GetTimePeriod(shiftTypeId, time);
  1618. if (tp != null)
  1619. {
  1620. returnValue = this.DataProvider.ICSSHIFT.SingleOrDefault(a => a.ID == tp.SHIFTID);
  1621. }
  1622. return returnValue;
  1623. }
  1624. /// <summary>
  1625. /// ** ��������: ���ݸ���ʱ�估ShiftType ����Ψһ�� TimePeriod
  1626. /// ** �� ��: Jane Shu
  1627. /// ** �� ��: 2005-03-08
  1628. /// ** �� ��: Jane Shu
  1629. /// ** �� ��: 2005-07-25
  1630. /// </summary>
  1631. /// <param name="shiftTypeCode"></param>
  1632. /// <param name="time"></param>
  1633. /// <returns></returns>
  1634. public object GetTimePeriod(string shiftTypeId, int time)
  1635. {
  1636. string sqlStr = @"select * from icstp where shifttypeid= '"+shiftTypeId+@"' and (
  1637. (tpbtime < tpetime and " +time+@" between tpbtime and tpetime )
  1638. or (tpbtime > tpetime and " + time + @" < tpbtime and " + time + @" + 240000 between tpbtime and tpetime + 240000)
  1639. or (tpbtime > tpetime and " + time + @" > tpbtime and " + time + @" between tpbtime and tpetime + 240000) )";
  1640. List < ICSTP > list = this.DataProvider.ExecuteQuery<ICSTP>(sqlStr).ToList();
  1641. if (list != null && list.Count > 0)
  1642. {
  1643. return list[0];
  1644. }
  1645. return null;
  1646. }
  1647. #endregion
  1648. }
  1649. }