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

248 lines
9.9 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 ICSStorageDAL
  12. {
  13. public static void AddAndEdit(ICSStorage Storage, 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.ICSStorage.SingleOrDefault(a => a.Serial == Storage.Serial);
  22. if(line==null){
  23. isNew = true;
  24. line = new ICSStorage();
  25. line.Serial = AppConfig.GetGuid();
  26. }
  27. var names = db.ICSStorage.Where(a => a.StorageName == Storage.StorageName && a.Serial != line.Serial);
  28. var codes = db.ICSStorage.Where(a => a.StorageCode == Storage.StorageCode && a.Serial != line.Serial);
  29. //var StorageLotInfoLog = db.ICSStorageLotInfoLog.SingleOrDefault(a => a.Stack_Serial == Storage.Serial);
  30. var SStack = db.ICSStack.SingleOrDefault(a => a.Storage_Serial == Storage.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 || SStack != null)
  40. //{
  41. // throw new Exception("库房正在使用中无法修改!!");
  42. //}
  43. line.StorageCode = Storage.StorageCode;
  44. line.StorageName = Storage.StorageName;
  45. line.MUSER=Storage.MUSER;
  46. line.MUSERName = Storage.MUSERName;
  47. line.WorkPoint = AppConfig.WorkPointCode;
  48. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  49. if (isNew) db.ICSStorage.InsertOnSubmit(line);
  50. db.SubmitChanges();
  51. db.Transaction.Commit();
  52. }
  53. catch (Exception ex)
  54. {
  55. db.Transaction.Rollback();
  56. throw new Exception(ex.Message);
  57. }
  58. }
  59. public static ICSStorage select(String guid, String Appconstr)
  60. {
  61. FramDataContext db = new FramDataContext(Appconstr);
  62. db.Connection.Open();
  63. db.Transaction = db.Connection.BeginTransaction();
  64. ICSStorage entity = new ICSStorage();
  65. try
  66. {
  67. var line = db.ICSStorage.SingleOrDefault(a => a.Serial == guid);
  68. //var StorageLotInfoLog = db.ICSStorageLotInfoLog.Where(a=>a.Storage_Serial==guid);
  69. var Stack = db.ICSStack.Where(a =>a.Storage_Serial==guid);
  70. //if (StorageLotInfoLog.ToList().Count > 0 || Stack.ToList().Count> 0)
  71. //{
  72. // throw new Exception("库房正在使用中无法修改");
  73. //}
  74. return (ICSStorage)line;
  75. }
  76. catch (Exception ex)
  77. {
  78. throw ex;
  79. }
  80. }
  81. public static ICSStorage selectByID(String guid, String con)
  82. {
  83. FramDataContext db = new FramDataContext(con);
  84. db.Connection.Open();
  85. db.Transaction = db.Connection.BeginTransaction();
  86. ICSStorage entity = new ICSStorage();
  87. try
  88. {
  89. var line = db.ICSStorage.SingleOrDefault(a => a.Serial == guid);
  90. return (ICSStorage)line;
  91. }
  92. catch (Exception ex)
  93. {
  94. throw ex;
  95. }
  96. }
  97. public static ICSStorage selectByCode(String storagecode, String Appconstr)
  98. {
  99. FramDataContext db = new FramDataContext(Appconstr);
  100. db.Connection.Open();
  101. db.Transaction = db.Connection.BeginTransaction();
  102. try
  103. {
  104. var line = db.ICSStorage.SingleOrDefault(a => a.StorageCode == storagecode);
  105. //entity.Serial = line.Serial;
  106. //entity.StorageCode = line.StorageCode;
  107. //entity.StorageName = line.StorageName;
  108. //entity.MUSER = line.MUSER;
  109. //entity.MTIME = line.MTIME;
  110. //entity.EATTRIBUTE1 = line.EATTRIBUTE1;
  111. return (ICSStorage)line;
  112. }
  113. catch (Exception ex)
  114. {
  115. throw new Exception(ex.Message);
  116. }
  117. }
  118. public static void delete(List<String> guidList) {
  119. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  120. db.Connection.Open();
  121. db.Transaction = db.Connection.BeginTransaction();
  122. try
  123. {
  124. //var line = db.ICSStorageLotInfoLog.Where(a => guidList.Contains(a.Storage_Serial));
  125. var line1 = db.ICSStack.Where(a => guidList.Contains(a.Storage_Serial));
  126. if (line1.Count() > 0)
  127. {
  128. throw new Exception("库房正在使用中无法删除!!");
  129. }
  130. var lines = db.ICSStorage.Where(a => guidList.Contains(a.Serial));
  131. db.ICSStorage.DeleteAllOnSubmit(lines);
  132. db.SubmitChanges();
  133. db.Transaction.Commit();
  134. }
  135. catch (Exception ex)
  136. {
  137. db.Transaction.Rollback();
  138. throw ex;
  139. }
  140. }
  141. public static void SelectERP(string ERPName)
  142. {
  143. string sql = @"UPDATE b SET b.StorageCode = a.cWhCode,
  144. b.StorageName = a.cWhName,b.EATTRIBUTE1 = CONVERT(NVARCHAR(50),a.dModifyDate,21)
  145. FROM (SELECT cWhCode,cWhName,a.dModifyDate,b.EATTRIBUTE1 FROM {1}.dbo.Warehouse a
  146. LEFT JOIN [dbo].[ICSStorage] b ON a.cWhCode = b.StorageCode
  147. AND a.dModifyDate = b.EATTRIBUTE1
  148. WHERE dWhEndDate IS NULL AND b.StorageCode IS NULL) a
  149. INNER JOIN [ICSStorage] b ON a.cWhCode = b.StorageCode
  150. INSERT INTO [dbo].[ICSStorage]
  151. SELECT NEWID(),cWhCode,cWhName,'',
  152. '',GETDATE(),a.dModifyDate,'{0}' FROM {1}.dbo.Warehouse a
  153. LEFT JOIN [dbo].[ICSStorage] b ON a.cWhCode = b.StorageCode
  154. WHERE dWhEndDate IS NULL AND b.StorageCode IS NULL";
  155. sql = string.Format(sql,AppConfig.WorkPointCode, ERPName);
  156. DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql);
  157. //return DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP]"), CommandType.Text, sql).Tables[0];
  158. }
  159. public static void SaveInfo(DataTable data, string Appconstr) {
  160. FramDataContext db = new FramDataContext(Appconstr);
  161. db.Connection.Open();
  162. db.Transaction = db.Connection.BeginTransaction();
  163. try
  164. {
  165. for (int i = 0; i < data.Rows.Count; i++)
  166. {
  167. var StorageCode=data.Rows[i]["库房编号"].ToString();
  168. var StorageName=data.Rows[i]["库房名称"].ToString();
  169. ICSStorage code = new ICSStorage();
  170. code.Serial = AppConfig.GetGuid();
  171. code.StorageCode = StorageCode;
  172. code.StorageName = StorageName;
  173. code.MUSER = AppConfig.UserId;
  174. code.MUSERName = AppConfig.UserName;
  175. code.WorkPoint = AppConfig.WorkPointCode;
  176. code.MTIME = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString());
  177. db.ICSStorage.InsertOnSubmit(code);
  178. }
  179. db.SubmitChanges();
  180. db.Transaction.Commit();
  181. }
  182. catch (Exception ex)
  183. {
  184. db.Transaction.Rollback();
  185. throw new Exception(ex.Message);
  186. }
  187. finally
  188. {
  189. db.Connection.Close();
  190. }
  191. }
  192. public static void SaveConnect(string Connecting,string StorageSerial1,Dictionary<string ,string> ConnList)
  193. {
  194. FramDataContext db = new FramDataContext(Connecting);
  195. db.Connection.Open();
  196. db.Transaction = db.Connection.BeginTransaction();
  197. try
  198. {
  199. List<string> SerialList = new List<string>();
  200. bool isNew = false;
  201. //foreach (string Serial in ConnList.Keys)
  202. //{
  203. // //var line = db.ICSStorage2Storage.SingleOrDefault(a => a.Serial == Serial);
  204. // //if (line == null)
  205. // //{
  206. // // isNew = true;
  207. // // line = new ICSStorage2Storage();
  208. // // line.Serial = Serial;
  209. // //}
  210. // line.Storage1Serial = StorageSerial1;
  211. // line.Storage2Serial = ConnList[Serial];
  212. // line.MTIME = DateTime.Now;
  213. // line.MUSER = AppConfig.UserId;
  214. // line.MUSERName = AppConfig.UserName;
  215. // SerialList.Add(Serial);
  216. // if (isNew) db.ICSStorage2Storage.InsertOnSubmit(line);
  217. //}
  218. //var lines = db.ICSStorage2Storage.Where(a => a.Storage1Serial == StorageSerial1 && !SerialList.Contains(a.Serial));
  219. //db.ICSStorage2Storage.DeleteAllOnSubmit(lines);
  220. db.SubmitChanges();
  221. db.Transaction.Commit();
  222. }
  223. catch (Exception ex)
  224. {
  225. throw ex;
  226. }
  227. }
  228. }
  229. }