锐腾搅拌上料功能
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.

224 lines
8.6 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 );
  37. if (line == null)
  38. {
  39. isNew = true;
  40. line = new ICSOPBOM();
  41. line.ITEMCODE = tbinfo.ITEMCODE;
  42. line.OBCODE = tbinfo.OBCODE;
  43. line.OPBOMVER = tbinfo.OPBOMVER;
  44. }
  45. line.WorkPoint = tbinfo.WorkPoint;
  46. line.ITEMID = tbinfo.ITEMID;
  47. line.OBROUTE = tbinfo.OBROUTE;
  48. line.OPDESC = tbinfo.OPDESC;
  49. line.MUSER = tbinfo.MUSER;
  50. line.MUSERName = tbinfo.MUSERName;
  51. line.MTIME = tbinfo.MTIME;
  52. line.EATTRIBUTE1 = tbinfo.EATTRIBUTE1;
  53. line.AVIALABLE = tbinfo.AVIALABLE;
  54. if (isNew)
  55. db.ICSOPBOM.InsertOnSubmit(line);
  56. db.SubmitChanges();
  57. }
  58. db.Transaction.Commit();
  59. }
  60. catch (Exception ex)
  61. {
  62. db.Transaction.Rollback();
  63. throw ex;
  64. }
  65. }
  66. #endregion
  67. public ICSOPBOM GetOPBOMByRouteCode(string itemCode, string routeCode, string bomVersion)
  68. {
  69. string sql = "select * from ICSOPBOM where 1=1 {0}";
  70. string tmpString = string.Empty;
  71. if ((itemCode != string.Empty) && (itemCode.Trim() != string.Empty))
  72. {
  73. tmpString += " and itemcode ='" + itemCode.Trim() + "'";
  74. }
  75. if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty))
  76. {
  77. tmpString += " and obroute ='" + routeCode.Trim() + "'";
  78. }
  79. if ((bomVersion != string.Empty) && (bomVersion.Trim() != string.Empty))
  80. {
  81. tmpString += " and opbomver ='" + bomVersion.Trim() + "'";
  82. }
  83. tmpString += " and WorkPoint='"+AppConfig.WorkPointCode+"'" ;
  84. //工单途程是否有上料工序
  85. bool IsComponetLoading = this.CheckItemRouteIsContainComponetLoading(itemCode, routeCode);
  86. List<ICSITEMROUTE2OP> objsOp = this.GetItemRouteIsContainComponetLoading(itemCode, routeCode);
  87. List<ICSOPBOM> objs = this._domainDataProvider.ExecuteQuery<ICSOPBOM>(String.Format(sql, tmpString)).ToList();
  88. //检查工单途程是否有上料工序,如果有则OPBOM不允许为空并抛出异常,否则则新增一个OPBOM插入数据库,并返回这个OPBOM,不再抛出异常
  89. if (objs == null)
  90. {
  91. if (IsComponetLoading)
  92. {
  93. throw new Exception("$Error_OPBOMNotExist1"+string.Format("[$ItemCode='{0}',$RouteCode='{1}']", itemCode, routeCode));
  94. }
  95. else
  96. {
  97. ICSOPBOM opBOM = CreateNewOPBOM();
  98. opBOM.ITEMCODE = itemCode;
  99. opBOM.OBROUTE = routeCode;
  100. opBOM.MUSER = AppConfig.UserCode;
  101. opBOM.MUSERName = AppConfig.UserName;
  102. opBOM.OBCODE = routeCode;
  103. opBOM.WorkPoint = AppConfig.WorkPointCode;
  104. opBOM.OPBOMVER = bomVersion;
  105. this.AddOPBOM(opBOM);
  106. return opBOM;
  107. }
  108. }
  109. else
  110. {
  111. if (IsComponetLoading)
  112. {
  113. foreach (ICSITEMROUTE2OP opbom in objsOp)
  114. {
  115. string selectSql = "select count(*) from ICSopbomdetail where 1= 1 {0} and WorkPoint='" +AppConfig.WorkPointCode+ "'";
  116. string tmpString2 = " and itemcode ='" + itemCode.Trim() + "' ";
  117. tmpString2 += " and opcode='" + opbom.OPCODE.Trim() + "'";
  118. string opcodesSelect = string.Format(" AND obcode = '" + ((ICSOPBOM)objs[0]).OBCODE.Trim() + "' ");
  119. tmpString2 += opcodesSelect;
  120. int result = _domainDataProvider.ExecuteQuery<int>(String.Format(selectSql, tmpString2)).First<int>();
  121. if (!(result > 0))
  122. {
  123. throw new Exception("$Error_OPBOMNotExist1"+string.Format("[$ItemCode='{0}',$RouteCode='{1}',$OpCode='{2}']", itemCode, routeCode, opbom.OPCODE), null);
  124. }
  125. }
  126. }
  127. }
  128. return objs[0];
  129. }
  130. #region 检查产品途程是否包含上料工序
  131. public bool CheckItemRouteIsContainComponetLoading(string itemcode, string routecode)
  132. {
  133. bool returnbool = false;
  134. string sql = string.Format("select * from ICSITEMRoute2OP WHERE itemcode = '{0}' AND routecode = '{1}' AND WorkPoint='{2}'", itemcode, routecode, AppConfig.WorkPointCode);
  135. List<ICSITEMROUTE2OP> itemroute2ops = this._domainDataProvider.ExecuteQuery<ICSITEMROUTE2OP>(sql).ToList();
  136. if (itemroute2ops != null)
  137. {
  138. foreach (object _item2op in itemroute2ops)
  139. {
  140. if (IsComponentLoadingOperation(((ICSITEMROUTE2OP)_item2op).OPCONTROL))
  141. {
  142. returnbool = true;
  143. break;
  144. }
  145. }
  146. }
  147. return returnbool;
  148. }
  149. public List<ICSITEMROUTE2OP> GetItemRouteIsContainComponetLoading(string itemcode, string routecode)
  150. {
  151. List<ICSITEMROUTE2OP> objList = new List<ICSITEMROUTE2OP>();
  152. string sql = string.Format("select * from ICSITEMRoute2OP WHERE itemcode = '{0}' AND routecode = '{1}' AND WorkPoint='{2}'", itemcode, routecode, AppConfig.WorkPointCode);
  153. List<ICSITEMROUTE2OP> itemroute2ops = this._domainDataProvider.ExecuteQuery<ICSITEMROUTE2OP>(sql).ToList();
  154. if (itemroute2ops != null && itemroute2ops.Count>0)
  155. {
  156. foreach (ICSITEMROUTE2OP _item2op in itemroute2ops)
  157. {
  158. if (IsComponentLoadingOperation((_item2op).OPCONTROL))
  159. {
  160. objList.Add(_item2op);
  161. }
  162. }
  163. }
  164. if (objList.Count > 0)
  165. {
  166. return objList;
  167. }
  168. return null;
  169. }
  170. private bool IsComponentLoadingOperation(string opControl)
  171. {
  172. return FormatHelper.StringToBoolean(opControl, 0);
  173. }
  174. /// <summary>
  175. ///
  176. /// </summary>
  177. /// <returns></returns>
  178. public ICSOPBOM CreateNewOPBOM()
  179. {
  180. return new ICSOPBOM();
  181. }
  182. /// <summary>
  183. /// item下BOMCode,暂时不考虑版本版本为1
  184. /// 不考虑版本的升级
  185. /// </summary>
  186. /// <param name="opBOM"></param>
  187. public void AddOPBOM(ICSOPBOM opBOM)
  188. {
  189. if (opBOM.OPBOMVER.Trim().Length == 0)
  190. opBOM.OPBOMVER = OPBOMVERSION_DEFAULT;
  191. this._domainDataProvider.ICSOPBOM.InsertOnSubmit(opBOM);
  192. }
  193. #endregion
  194. }
  195. }