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

146 lines
4.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.DBHelper;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using ICSSoft.Base.Config.AppConfig;
  10. using ICSSoft.Frame.APP.Entity;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSItemOPPriceDAL
  14. {
  15. #region 新增和修改
  16. public static void Add(List<ICSItemOPPrice> InfoList, string dsconn)
  17. {
  18. FramDataContext db = new FramDataContext(dsconn);
  19. db.Connection.Open();
  20. db.Transaction = db.Connection.BeginTransaction();
  21. try
  22. {
  23. foreach (ICSItemOPPrice info in InfoList)
  24. {
  25. bool isNew = false;
  26. var line = db.ICSItemOPPrice.SingleOrDefault(a => a.ID == info.ID);
  27. if (line == null)
  28. {
  29. isNew = true;
  30. line = new ICSItemOPPrice();
  31. }
  32. //var codes = db.ICSItemOPPrice.Where(a => a.ITEMCODE == info.ITEMCODE && a.OPCODE == info.OPCODE && a.ID != info.ID);
  33. //if (codes.ToList().Count > 0)
  34. //{
  35. // throw new Exception("已存在相同产品工序的价格");
  36. //}
  37. line.ID = info.ID;
  38. //var line = db.ICSItemOPPrice.SingleOrDefault(a => a.ITEMCODE == info.ITEMCODE && a.OPCODE == info.OPCODE);
  39. //if (line == null)
  40. //{
  41. // isNew = true;
  42. // line = new ICSItemOPPrice();
  43. // line.ID = AppConfig.GetGuid();
  44. //}
  45. line.ITEMCODE = info.ITEMCODE;
  46. line.OPCODE = info.OPCODE;
  47. line.Price = Convert.ToDecimal(info.Price);
  48. line.MUSER = AppConfig.UserId;
  49. line.MUSERName = AppConfig.UserName;
  50. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss") ;
  51. line.WorkPoint = AppConfig.WorkPointCode;
  52. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  53. if (isNew)
  54. db.ICSItemOPPrice.InsertOnSubmit(line);
  55. db.SubmitChanges();
  56. }
  57. db.Transaction.Commit();
  58. }
  59. catch (Exception ex)
  60. {
  61. db.Transaction.Rollback();
  62. throw ex;
  63. }
  64. }
  65. #endregion
  66. #region 通过ID查询
  67. public static DataTable searchInfoByID(string ID, string dsconn)
  68. {
  69. string sql = @"SELECT
  70. b.INVNAME AS ItemName,
  71. c.OPDESC,
  72. a.ID,
  73. a.ITEMCODE,
  74. a.OPCODE,
  75. a.Price,
  76. a.WorkPoint,
  77. a.MUSER,
  78. a.MUSERName,
  79. a.MTIME,
  80. a.EATTRIBUTE1
  81. FROM ICSItemOPPrice a
  82. left join ICSINVENTORY b on a.ITEMCODE=b.INVCODE
  83. left join ICSOP c on a.OPCODE=C.OPCODE
  84. where a.ID='{0}'";
  85. sql = string.Format(sql, ID);
  86. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  87. return dt;
  88. }
  89. #endregion
  90. #region 是否存在
  91. public static bool IsIncluding(string ItemCode, string OPCode, string eqptype, string dsconn)
  92. {
  93. FramDataContext db = new FramDataContext(dsconn);
  94. db.Connection.Open();
  95. db.Transaction = db.Connection.BeginTransaction();
  96. try
  97. {
  98. var line = db.ICSItemOPPrice.SingleOrDefault(a => a.ITEMCODE == ItemCode && a.OPCODE == OPCode);
  99. if (line == null)
  100. return true;
  101. else
  102. return false;
  103. }
  104. catch (Exception ex)
  105. {
  106. db.Transaction.Rollback();
  107. throw ex;
  108. }
  109. }
  110. #endregion
  111. #region 删除
  112. public static void deleteInfo(List<string> codeList, string dsconn)
  113. {
  114. FramDataContext db = new FramDataContext(dsconn);
  115. db.Connection.Open();
  116. db.Transaction = db.Connection.BeginTransaction();
  117. try
  118. {
  119. var lines = db.ICSItemOPPrice.Where(a => codeList.Contains(a.ID));
  120. db.ICSItemOPPrice.DeleteAllOnSubmit(lines);
  121. db.SubmitChanges();
  122. db.Transaction.Commit();
  123. }
  124. catch (Exception ex)
  125. {
  126. db.Transaction.Rollback();
  127. throw ex;
  128. }
  129. }
  130. #endregion
  131. }
  132. }