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

196 lines
6.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. namespace ICSSoft.Frame.Data.DAL
  10. {
  11. public class ICSOPDAL
  12. {
  13. #region 新增和修改
  14. public static void Add(List<FormICSOPUIModel> tbInfoList, string dsconn)
  15. {
  16. FramDataContext db = new FramDataContext(dsconn);
  17. db.Connection.Open();
  18. db.Transaction = db.Connection.BeginTransaction();
  19. try
  20. {
  21. foreach (FormICSOPUIModel tbinfo in tbInfoList)
  22. {
  23. bool isNew = false;
  24. var line = db.ICSOP.SingleOrDefault(a => a.OPCODE == tbinfo.OPCODE);
  25. if (line == null)
  26. {
  27. isNew = true;
  28. line = new ICSOP();
  29. line.ID = AppConfig.GetGuid();
  30. line.OPCODE = tbinfo.OPCODE;
  31. }
  32. line.OPDESC = tbinfo.OPDESC;
  33. line.OPCOLLECTION = tbinfo.OPCOLLECTION;
  34. line.OPCONTROL = tbinfo.OPCONTROL;
  35. line.MUSER = AppConfig.UserId;
  36. line.MUSERName = AppConfig.UserName;
  37. line.MTIME = DateTime.Now;
  38. line.WorkPoint = AppConfig.WorkPointCode;
  39. line.CostCenter = tbinfo.CostCenter;
  40. line.OpFrom = tbinfo.OpFrom;
  41. if (isNew)
  42. db.ICSOP.InsertOnSubmit(line);
  43. db.SubmitChanges();
  44. }
  45. db.Transaction.Commit();
  46. }
  47. catch (Exception ex)
  48. {
  49. db.Transaction.Rollback();
  50. throw ex;
  51. }
  52. }
  53. #endregion
  54. #region 工序代码是否存在
  55. public static bool IsIncluding(string opCODE, string dsconn)
  56. {
  57. FramDataContext db = new FramDataContext(dsconn);
  58. db.Connection.Open();
  59. db.Transaction = db.Connection.BeginTransaction();
  60. try
  61. {
  62. var line = db.ICSOP.SingleOrDefault(a => a.OPCODE == opCODE);
  63. if (line == null)
  64. return true;
  65. else
  66. return false;
  67. }
  68. catch (Exception ex)
  69. {
  70. db.Transaction.Rollback();
  71. throw ex;
  72. }
  73. }
  74. #endregion
  75. #region 查询工序信息
  76. public static List<FormICSOPUIModel> SearchOPInfo(string opcode, string dsconn)
  77. {
  78. List<FormICSOPUIModel> returnOP = new List<FormICSOPUIModel>();
  79. string sql = @"select OPCODE,OPDESC,OPCOLLECTION,OPCONTROL,CostCenter from ICSOP where OPCODE='{0}'";
  80. sql = string.Format(sql, opcode);
  81. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  82. foreach (DataRow dr in dt.Rows)
  83. {
  84. FormICSOPUIModel returnInfo = new FormICSOPUIModel();
  85. returnInfo.OPCODE = dr["OPCODE"].ToString();
  86. returnInfo.OPDESC = dr["OPDESC"].ToString();
  87. returnInfo.OPCOLLECTION = dr["OPCOLLECTION"].ToString();
  88. returnInfo.OPCONTROL = dr["OPCONTROL"].ToString();
  89. returnInfo.CostCenter = dr["CostCenter"].ToString();
  90. returnOP.Add(returnInfo);
  91. }
  92. return returnOP;
  93. }
  94. #endregion
  95. #region 删除
  96. public static void deleteInfo(List<string> codeList, string dsconn)
  97. {
  98. FramDataContext db = new FramDataContext(dsconn);
  99. db.Connection.Open();
  100. db.Transaction = db.Connection.BeginTransaction();
  101. try
  102. {
  103. var lines = db.ICSOP.Where(a => codeList.Contains(a.OPCODE));
  104. db.ICSOP.DeleteAllOnSubmit(lines);
  105. db.SubmitChanges();
  106. db.Transaction.Commit();
  107. }
  108. catch (Exception ex)
  109. {
  110. db.Transaction.Rollback();
  111. throw ex;
  112. }
  113. }
  114. #endregion
  115. #region 判断是否在工序和资源的关系中
  116. public static bool Including2RES(List<string> idList, string dsconn)
  117. {
  118. FramDataContext db = new FramDataContext(dsconn);
  119. db.Connection.Open();
  120. db.Transaction = db.Connection.BeginTransaction();
  121. try
  122. {
  123. bool flag = false;
  124. var lines = db.ICSOP2RES.Where(a => idList.Contains(a.OPID));
  125. if (lines.Count() != 0)
  126. flag = true;
  127. return flag;
  128. }
  129. catch (Exception ex)
  130. {
  131. //db.Transaction.Rollback();
  132. throw ex;
  133. }
  134. }
  135. #endregion
  136. #region 判断是否在途程和工序的关系中
  137. public static bool IncludingROUTE2OP(List<string> idList, string dsconn)
  138. {
  139. FramDataContext db = new FramDataContext(dsconn);
  140. db.Connection.Open();
  141. db.Transaction = db.Connection.BeginTransaction();
  142. try
  143. {
  144. bool flag = false;
  145. var lines = db.ICSROUTE2OP.Where(a => idList.Contains(a.OPID));
  146. if (lines.Count() != 0)
  147. flag = true;
  148. return flag;
  149. }
  150. catch (Exception ex)
  151. {
  152. //db.Transaction.Rollback();
  153. throw ex;
  154. }
  155. }
  156. #endregion
  157. #region 获取成本中心
  158. public static DataTable SearchData(string dsconn)
  159. {
  160. try
  161. {
  162. string sql = @"SELECT EnumKey, EnumText FROM Sys_EnumValues WHERE 1=1 AND EnumKey = '00018' AND WorkPointCode = '{0}' ";
  163. sql = string.Format(sql, AppConfig.WorkPointCode);
  164. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  165. return dt;
  166. }
  167. catch (Exception ex)
  168. {
  169. throw ex;
  170. }
  171. }
  172. public static DataTable SearchData(string EnumText, string dsconn)
  173. {
  174. try
  175. {
  176. string sql = @"SELECT EnumKey, EnumText FROM Sys_EnumValues WHERE 1=1 AND EnumKey = '00018' AND EnumText = '{0}' AND WorkPointCode = '{1}' ";
  177. sql = string.Format(sql, EnumText, AppConfig.WorkPointCode);
  178. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  179. return dt;
  180. }
  181. catch (Exception ex)
  182. {
  183. throw ex;
  184. }
  185. }
  186. #endregion
  187. }
  188. }