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

100 lines
3.4 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. namespace ICSSoft.Frame.Data.DAL
  7. {
  8. public class ICSInstorageDAL
  9. {
  10. public static void Insert(ICSInStorage storage, List<ICSInStorageDetail> detail, string conn)
  11. {
  12. FramDataContext frame = new FramDataContext(conn);
  13. frame.Connection.Open();
  14. frame.Transaction = frame.Connection.BeginTransaction();
  15. try
  16. {
  17. ICSInStorage isexists = frame.ICSInStorage.FirstOrDefault(a => a.RKCode == storage.RKCode);
  18. if (isexists != null)
  19. {
  20. throw new Exception("入库单号:" + storage.RKCode + "已存在!");
  21. }
  22. foreach (ICSInStorageDetail a in detail)
  23. {
  24. ICSITEMLot lot = frame.ICSITEMLot.Where(b => b.LotNO == a.Lotno).SingleOrDefault();
  25. if (lot != null)
  26. {
  27. if (!string.IsNullOrEmpty(lot.EATTRIBUTE6))
  28. {
  29. throw new Exception("条码:" + a.Lotno + "已产生入库单,请勿重复生成!");
  30. }
  31. lot.RKcode =storage.RKCode;
  32. }
  33. else
  34. {
  35. throw new Exception("获取条码:" + a.Lotno + "信息失败!");
  36. }
  37. }
  38. frame.SubmitChanges();
  39. frame.ICSInStorage.InsertOnSubmit(storage);
  40. frame.SubmitChanges();
  41. frame.ICSInStorageDetail.InsertAllOnSubmit(detail);
  42. frame.SubmitChanges();
  43. frame.Transaction.Commit();
  44. }
  45. catch (Exception ex)
  46. {
  47. frame.Transaction.Rollback();
  48. throw ex;
  49. }
  50. }
  51. public static void Delete(List<string> rkcode,string conn)
  52. {
  53. FramDataContext frame = new FramDataContext(conn);
  54. frame.Connection.Open();
  55. frame.Transaction = frame.Connection.BeginTransaction();
  56. try
  57. {
  58. IQueryable<ICSInStorage> instorage=frame.ICSInStorage.Where(a=>rkcode.Contains(a.RKCode));
  59. List<ICSInStorageDetail> detail = frame.ICSInStorageDetail.Where(a => rkcode.Contains(a.RKCode)).Select(b=>b).ToList();
  60. foreach (ICSInStorageDetail d in detail) {
  61. ICSITEMLot lot=frame.ICSITEMLot.Where(a => a.LotNO == d.Lotno).SingleOrDefault();
  62. if (lot != null)
  63. {
  64. if (!string.IsNullOrEmpty(lot.ISCOM)) {
  65. throw new Exception("条码:"+lot.LotNO+"已入库无法删除!");
  66. }
  67. lot.RKcode = null;
  68. }
  69. }
  70. frame.SubmitChanges();
  71. frame.ICSInStorageDetail.DeleteAllOnSubmit(detail);
  72. frame.SubmitChanges();
  73. frame.ICSInStorage.DeleteAllOnSubmit(instorage);
  74. frame.SubmitChanges();
  75. frame.Transaction.Commit();
  76. }
  77. catch (Exception ex)
  78. {
  79. frame.Transaction.Rollback();
  80. throw ex;
  81. }
  82. }
  83. }
  84. }