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

227 lines
8.8 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Frame.Data.Entity;
  6. using ICSSoft.Base.Config.AppConfig;
  7. using System.Data;
  8. using ICSSoft.Base.Config.DBHelper;
  9. using ICSSoft.Frame.Helper;
  10. using System.Collections;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSOPBOMDAL
  14. {
  15. public static readonly string OPBOMITEMTYPE_DEFAULT = "lot";
  16. public static readonly string OPBOMVERSION_DEFAULT = "1";
  17. public static readonly string OPBOMISItemCheckValue_DEFAULT = "0";
  18. public static readonly string OPBOMItemCheckValue_DEFAULT = "0000000";
  19. public static readonly string OPBOMItemUOM_DEFAULT = "OPBOMItemUOM";
  20. private FramDataContext _domainDataProvider = null;
  21. public ICSOPBOMDAL(FramDataContext domainDataProvider)
  22. {
  23. this._domainDataProvider = domainDataProvider;
  24. }
  25. #region 新增和修改
  26. public static void Add(List<ICSOPBOM> tbInfoList, string dsconn)
  27. {
  28. FramDataContext db = new FramDataContext(dsconn);
  29. db.Connection.Open();
  30. db.Transaction = db.Connection.BeginTransaction();
  31. try
  32. {
  33. foreach (ICSOPBOM tbinfo in tbInfoList)
  34. {
  35. bool isNew = false;
  36. var line = db.ICSOPBOM.SingleOrDefault(a => a.ITEMCODE == tbinfo.ITEMCODE && a.OBCODE == tbinfo.OBCODE && a.OPBOMVER == tbinfo.OPBOMVER &&a.WorkPoint== tbinfo.WorkPoint);
  37. if (line == null)
  38. {
  39. isNew = true;
  40. line = new ICSOPBOM();
  41. line.ID = AppConfig.GetGuid();
  42. line.ITEMCODE = tbinfo.ITEMCODE;
  43. line.OBCODE = tbinfo.OBCODE;
  44. line.OPBOMVER = tbinfo.OPBOMVER;
  45. }
  46. line.WorkPoint = tbinfo.WorkPoint;
  47. line.ITEMID = tbinfo.ITEMID;
  48. line.OBROUTE = tbinfo.OBROUTE;
  49. line.OPDESC = tbinfo.OPDESC;
  50. line.MUSER = tbinfo.MUSER;
  51. line.MUSERName = tbinfo.MUSERName;
  52. line.MTIME = tbinfo.MTIME;
  53. line.EATTRIBUTE1 = tbinfo.EATTRIBUTE1;
  54. line.EATTRIBUTE2 = tbinfo.EATTRIBUTE2;
  55. line.EATTRIBUTE3 = tbinfo.EATTRIBUTE3;
  56. line.AVIALABLE = tbinfo.AVIALABLE;
  57. if (isNew)
  58. db.ICSOPBOM.InsertOnSubmit(line);
  59. db.SubmitChanges();
  60. }
  61. db.Transaction.Commit();
  62. }
  63. catch (Exception ex)
  64. {
  65. db.Transaction.Rollback();
  66. throw ex;
  67. }
  68. }
  69. #endregion
  70. public ICSOPBOM GetOPBOMByRouteCode(string itemCode, string routeCode, string bomVersion)
  71. {
  72. string sql = "select * from ICSOPBOM where 1=1 {0}";
  73. string tmpString = string.Empty;
  74. if ((itemCode != string.Empty) && (itemCode.Trim() != string.Empty))
  75. {
  76. tmpString += " and itemcode ='" + itemCode.Trim() + "'";
  77. }
  78. if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty))
  79. {
  80. tmpString += " and obroute ='" + routeCode.Trim() + "'";
  81. }
  82. if ((bomVersion != string.Empty) && (bomVersion.Trim() != string.Empty))
  83. {
  84. tmpString += " and opbomver ='" + bomVersion.Trim() + "'";
  85. }
  86. tmpString += " and WorkPoint='"+AppConfig.WorkPointCode+"'" ;
  87. //工单途程是否有上料工序
  88. bool IsComponetLoading = this.CheckItemRouteIsContainComponetLoading(itemCode, routeCode);
  89. List<ICSITEMROUTE2OP> objsOp = this.GetItemRouteIsContainComponetLoading(itemCode, routeCode);
  90. List<ICSOPBOM> objs = this._domainDataProvider.ExecuteQuery<ICSOPBOM>(String.Format(sql, tmpString)).ToList();
  91. //检查工单途程是否有上料工序,如果有则OPBOM不允许为空并抛出异常,否则则新增一个OPBOM插入数据库,并返回这个OPBOM,不再抛出异常
  92. if (objs == null)
  93. {
  94. if (IsComponetLoading)
  95. {
  96. throw new Exception("$Error_OPBOMNotExist1"+string.Format("[$ItemCode='{0}',$RouteCode='{1}']", itemCode, routeCode));
  97. }
  98. else
  99. {
  100. ICSOPBOM opBOM = CreateNewOPBOM();
  101. opBOM.ITEMCODE = itemCode;
  102. opBOM.OBROUTE = routeCode;
  103. opBOM.MUSER = AppConfig.UserCode;
  104. opBOM.MUSERName = AppConfig.UserName;
  105. opBOM.OBCODE = routeCode;
  106. opBOM.WorkPoint = AppConfig.WorkPointCode;
  107. opBOM.OPBOMVER = bomVersion;
  108. this.AddOPBOM(opBOM);
  109. return opBOM;
  110. }
  111. }
  112. else
  113. {
  114. if (IsComponetLoading)
  115. {
  116. foreach (ICSITEMROUTE2OP opbom in objsOp)
  117. {
  118. string selectSql = "select count(*) from ICSopbomdetail where 1= 1 {0} and WorkPoint='" +AppConfig.WorkPointCode+ "'";
  119. string tmpString2 = " and itemcode ='" + itemCode.Trim() + "' ";
  120. tmpString2 += " and opcode='" + opbom.OPCODE.Trim() + "'";
  121. string opcodesSelect = string.Format(" AND obcode = '" + ((ICSOPBOM)objs[0]).OBCODE.Trim() + "' ");
  122. tmpString2 += opcodesSelect;
  123. int result = _domainDataProvider.ExecuteQuery<int>(String.Format(selectSql, tmpString2)).First<int>();
  124. if (!(result > 0))
  125. {
  126. throw new Exception("$Error_OPBOMNotExist1"+string.Format("[$ItemCode='{0}',$RouteCode='{1}',$OpCode='{2}']", itemCode, routeCode, opbom.OPCODE), null);
  127. }
  128. }
  129. }
  130. }
  131. return objs[0];
  132. }
  133. #region 检查产品途程是否包含上料工序
  134. public bool CheckItemRouteIsContainComponetLoading(string itemcode, string routecode)
  135. {
  136. bool returnbool = false;
  137. string sql = string.Format("select * from ICSITEMRoute2OP WHERE itemcode = '{0}' AND routecode = '{1}' AND WorkPoint='{2}'", itemcode, routecode, AppConfig.WorkPointCode);
  138. List<ICSITEMROUTE2OP> itemroute2ops = this._domainDataProvider.ExecuteQuery<ICSITEMROUTE2OP>(sql).ToList();
  139. if (itemroute2ops != null)
  140. {
  141. foreach (object _item2op in itemroute2ops)
  142. {
  143. if (IsComponentLoadingOperation(((ICSITEMROUTE2OP)_item2op).OPCONTROL))
  144. {
  145. returnbool = true;
  146. break;
  147. }
  148. }
  149. }
  150. return returnbool;
  151. }
  152. public List<ICSITEMROUTE2OP> GetItemRouteIsContainComponetLoading(string itemcode, string routecode)
  153. {
  154. List<ICSITEMROUTE2OP> objList = new List<ICSITEMROUTE2OP>();
  155. string sql = string.Format("select * from ICSITEMRoute2OP WHERE itemcode = '{0}' AND routecode = '{1}' AND WorkPoint='{2}'", itemcode, routecode, AppConfig.WorkPointCode);
  156. List<ICSITEMROUTE2OP> itemroute2ops = this._domainDataProvider.ExecuteQuery<ICSITEMROUTE2OP>(sql).ToList();
  157. if (itemroute2ops != null && itemroute2ops.Count>0)
  158. {
  159. foreach (ICSITEMROUTE2OP _item2op in itemroute2ops)
  160. {
  161. if (IsComponentLoadingOperation((_item2op).OPCONTROL))
  162. {
  163. objList.Add(_item2op);
  164. }
  165. }
  166. }
  167. if (objList.Count > 0)
  168. {
  169. return objList;
  170. }
  171. return null;
  172. }
  173. private bool IsComponentLoadingOperation(string opControl)
  174. {
  175. return FormatHelper.StringToBoolean(opControl, 0);
  176. }
  177. /// <summary>
  178. ///
  179. /// </summary>
  180. /// <returns></returns>
  181. public ICSOPBOM CreateNewOPBOM()
  182. {
  183. return new ICSOPBOM();
  184. }
  185. /// <summary>
  186. /// item下BOMCode,暂时不考虑版本版本为1
  187. /// 不考虑版本的升级
  188. /// </summary>
  189. /// <param name="opBOM"></param>
  190. public void AddOPBOM(ICSOPBOM opBOM)
  191. {
  192. if (opBOM.OPBOMVER.Trim().Length == 0)
  193. opBOM.OPBOMVER = OPBOMVERSION_DEFAULT;
  194. this._domainDataProvider.ICSOPBOM.InsertOnSubmit(opBOM);
  195. }
  196. #endregion
  197. }
  198. }