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

204 lines
7.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 ICSStackDAL
  12. {
  13. public static void AddAndEdit(ICSStack Stack, string Appconstr)
  14. {
  15. FramDataContext db = new FramDataContext(Appconstr);
  16. db.Connection.Open();
  17. db.Transaction = db.Connection.BeginTransaction();
  18. try
  19. {
  20. bool isNew = false;
  21. var line = db.ICSStack.SingleOrDefault(a => a.Serial == Stack.Serial);
  22. if (line == null)
  23. {
  24. isNew = true;
  25. line = new ICSStack();
  26. line.Serial = AppConfig.GetGuid();
  27. }
  28. var codes = db.ICSStack.Where(a => a.StackCode == Stack.StackCode && a.Serial != line.Serial);
  29. var names = db.ICSStack.Where(a => a.StackName == Stack.StackName && a.Serial != line.Serial);
  30. //var StorageLotInfoLog = db.ICSStorageLotInfoLog.SingleOrDefault(a => a.Stack_Serial == Stack.Serial);
  31. if (names.Count() > 0)
  32. {
  33. throw new Exception("库位名称已存在");
  34. }
  35. if (codes.Count() > 0)
  36. {
  37. throw new Exception("库位编号已存在");
  38. }
  39. //if (StorageLotInfoLog != null)
  40. //{
  41. // throw new Exception("库位正在使用中无法修改!!");
  42. //}
  43. line.StackCode = Stack.StackCode;
  44. line.StackName = Stack.StackName;
  45. line.Storage_Serial = Stack.Storage_Serial;
  46. line.Storage_Name = Stack.Storage_Name;
  47. line.MUSER = Stack.MUSER;
  48. line.MUSERName = Stack.MUSERName;
  49. line.WorkPoint = AppConfig.WorkPointCode;
  50. line.MTIME = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString());
  51. if (isNew) db.ICSStack.InsertOnSubmit(line);
  52. db.SubmitChanges();
  53. db.Transaction.Commit();
  54. }
  55. catch (Exception ex)
  56. {
  57. db.Transaction.Rollback();
  58. throw new Exception(ex.Message);
  59. }
  60. }
  61. public static void AddAndEditList(List<ICSStack> StackList, string Appconstr)
  62. {
  63. FramDataContext db = new FramDataContext(Appconstr);
  64. db.Connection.Open();
  65. db.Transaction = db.Connection.BeginTransaction();
  66. try
  67. {
  68. foreach (var Stack in StackList)
  69. {
  70. bool isNew = false;
  71. var line = db.ICSStack.SingleOrDefault(a => a.Serial == Stack.Serial);
  72. if (line == null)
  73. {
  74. isNew = true;
  75. line = new ICSStack();
  76. line.Serial = AppConfig.GetGuid();
  77. }
  78. var codes = db.ICSStack.Where(a => a.StackCode == Stack.StackCode && a.Serial != line.Serial);
  79. var names = db.ICSStack.Where(a => a.StackName == Stack.StackName && a.Serial != line.Serial);
  80. if (names.Count() > 0)
  81. {
  82. throw new Exception("库位名称已存在");
  83. }
  84. if (codes.Count() > 0)
  85. {
  86. throw new Exception("库位编号已存在");
  87. }
  88. line.StackCode = Stack.StackCode;
  89. line.StackName = Stack.StackName;
  90. line.Storage_Serial = Stack.Storage_Serial;
  91. line.Storage_Name = Stack.Storage_Name;
  92. line.MUSER = Stack.MUSER;
  93. line.MUSERName = Stack.MUSERName;
  94. line.WorkPoint = AppConfig.WorkPointCode;
  95. line.MTIME = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString());
  96. if (isNew) db.ICSStack.InsertOnSubmit(line);
  97. }
  98. db.SubmitChanges();
  99. db.Transaction.Commit();
  100. }
  101. catch (Exception ex)
  102. {
  103. db.Transaction.Rollback();
  104. throw new Exception(ex.Message);
  105. }
  106. }
  107. public static ICSStack select(String guid, String Appconstr)
  108. {
  109. FramDataContext db = new FramDataContext(Appconstr);
  110. db.Connection.Open();
  111. db.Transaction = db.Connection.BeginTransaction();
  112. try
  113. {
  114. //var StorageLotInfoLog = db.ICSStorageLotInfoLog.Where(a=>a.Stack_Serial==guid);
  115. //if (StorageLotInfoLog.ToList().Count>0)
  116. //{
  117. // throw new Exception("库位正在使用中无法修改!!");
  118. //}
  119. var line = db.ICSStack.SingleOrDefault(a => a.Serial == guid);
  120. return (ICSStack)line;
  121. }
  122. catch (Exception ex)
  123. {
  124. throw ex;
  125. }
  126. }
  127. public static ICSStack selectByCode(String stackcode, String Appconstr)
  128. {
  129. FramDataContext db = new FramDataContext(Appconstr);
  130. db.Connection.Open();
  131. db.Transaction = db.Connection.BeginTransaction();
  132. ICSStack entity = new ICSStack();
  133. try
  134. {
  135. var line = db.ICSStack.SingleOrDefault(a => a.StackCode == stackcode);
  136. //entity.Serial = line.Serial;
  137. //entity.StackCode = line.StackCode;
  138. //entity.StackName = line.StackName;
  139. //entity.Storage_Serial = line.Storage_Serial;
  140. //entity.MUSER = line.MUSER;
  141. //entity.MTIME = line.MTIME;
  142. //entity.EATTRIBUTE1 = line.EATTRIBUTE1;
  143. return (ICSStack)line;
  144. }
  145. catch (Exception ex)
  146. {
  147. throw new Exception(ex.Message);
  148. }
  149. }
  150. public static void delete(List<String> guidList) {
  151. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  152. db.Connection.Open();
  153. db.Transaction = db.Connection.BeginTransaction();
  154. try
  155. {
  156. //var line = db.ICSStorageLotInfoLog.Where(a => guidList.Contains(a.Stack_Serial));
  157. //if (line.ToList().Count > 0)
  158. //{
  159. // throw new Exception("库位正在使用中无法删除!!");
  160. //}
  161. var lines = db.ICSStack.Where(a => guidList.Contains(a.Serial));
  162. db.ICSStack.DeleteAllOnSubmit(lines);
  163. db.SubmitChanges();
  164. db.Transaction.Commit();
  165. }
  166. catch (Exception ex)
  167. {
  168. db.Transaction.Rollback();
  169. throw ex;
  170. }
  171. }
  172. public static DataTable SelectData() {
  173. String WorkPoint = AppConfig.WorkPointCode;
  174. string sql = @"SELECT [StorageCode] as '库房编号'
  175. ,[StorageName] as ''
  176. FROM ICSStorage where WorkPoint='" + WorkPoint + "'";
  177. object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetMainConnectString", new object[] { });
  178. if (obj == null)
  179. {
  180. throw new Exception("ERP数据库连接失败!");
  181. }
  182. return DBHelper.ExecuteDataset(obj.ToString(), CommandType.Text, sql).Tables[0];
  183. }
  184. }
  185. }