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

281 lines
15 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 ICSLLDisposeInFoDAL
  12. {
  13. #region AddandEditList
  14. // public static void AddandEditList(List<ICSLLDisposeInFo> ItemLotList, string Appconstr)
  15. // {
  16. // FramDataContext db = new FramDataContext(Appconstr);
  17. // db.Connection.Open();
  18. // db.Transaction = db.Connection.BeginTransaction();
  19. // try
  20. // {
  21. // foreach (ICSLLDisposeInFo lineNew in ItemLotList)
  22. // {
  23. // bool isNew = false;
  24. // var line = db.ICSLLDisposeInFo.SingleOrDefault(a => a.LOTNO == lineNew.LOTNO && a.ItemCode == lineNew.ItemCode && a.DocNo == lineNew.DocNo && a.LineNo == lineNew.LineNo);
  25. // if (line == null)
  26. // {
  27. // isNew = true;
  28. // line = new ICSLLDisposeInFo();
  29. // line.ID = AppConfig.GetGuid();
  30. // }
  31. // line.LOTNO = lineNew.LOTNO;
  32. // line.ItemCode = lineNew.ItemCode;
  33. // line.ItemName = lineNew.ItemName;
  34. // line.BarCodeQty = lineNew.BarCodeQty;
  35. // line.DisposeInQty = lineNew.DisposeInQty;
  36. // line.SupplierName = lineNew.SupplierName;
  37. // line.DocNo = lineNew.DocNo;
  38. // line.LineNo = lineNew.LineNo;
  39. // line.LineNo = lineNew.LineNo;
  40. // line.CompleteInformation = lineNew.CompleteInformation;
  41. // line.ReleaseStatus = lineNew.ReleaseStatus;
  42. // line.MUSER = lineNew.MUSER;
  43. // line.MUSERName = lineNew.MUSERName;
  44. // line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  45. // line.WorkPoint = lineNew.WorkPoint;
  46. // if (isNew) db.ICSLLDisposeInFo.InsertOnSubmit(line);
  47. // db.SubmitChanges();
  48. // }
  49. // db.Transaction.Commit();
  50. // UpdatePoLine(ItemLotList, Appconstr);
  51. // }
  52. // catch (Exception ex)
  53. // {
  54. // db.Transaction.Rollback();
  55. // throw new Exception(ex.Message);
  56. // }
  57. // }
  58. // public static void UpdatePoLine(List<ICSLLDisposeInFo> ItemLotList, string dsconn)
  59. // {
  60. // try
  61. // {
  62. // foreach (ICSLLDisposeInFo lineNew in ItemLotList)
  63. // {
  64. // //根据物料条码和RCV行获取U8采购单行和RCV实际到货数量
  65. // string sql = @"SELECT a.BarCodeNo ,--条码
  66. // b.RcvDocNo ,--收货单号
  67. // b.RcvLineNo ,--行号
  68. // b.RcvLineStoreQty ,--实到数量
  69. // b.RcvLineSrcPOSrcDocNo ,--源采购单号
  70. // b.RcvLineSrcPOSrcDocLineNo --源采购单行
  71. // FROM WM_BarCode a inner JOIN dbo.WM_RCVShip b ON a.RCVShipguid = b.guid
  72. // and a.SrcType = 'WM_RCVShip'
  73. // where 1=1
  74. // AND b.RcvDocNo='{0}' AND b.RcvLineNo='{1}'";
  75. // sql = string.Format(sql, lineNew.DocNo, lineNew.LineNo);
  76. // DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  77. // if (dt != null && dt.Rows.Count > 0)
  78. // {
  79. // //判断 到货数量 等于(ReleaseStatus=1 and Completelnformation=1)的数量之和 + ReleaseStatus=0 的数量之和
  80. // //回写 U9 PO行上 DescFlexSegments_PrivateDescSeg20=1
  81. // //判断 到货数量 大于(ReleaseStatus=1 and Completelnformation=1)的数量之和 + ReleaseStatus=0 的数量之和
  82. // //回写 U9 PO行上 DescFlexSegments_PrivateDescSeg20=0
  83. // string sql1 = @"select SUM(ISNULL(DisposeInQty,0)) DisposeInQty, DocNo , [LineNo] from ICSLLDisposeInFo
  84. // where DocNo = '{0}' AND [LineNo] = '{1}'
  85. // AND ((ReleaseStatus=1 and CompleteInformation=1) OR ReleaseStatus=0)
  86. // GROUP BY DocNo , [LineNo]";
  87. // sql1 = string.Format(sql1, lineNew.DocNo, lineNew.LineNo);
  88. // DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql1).Tables[0];
  89. // if (dt1 != null && dt1.Rows.Count > 0)
  90. // {
  91. // if (Convert.ToDecimal(dt.Rows[0]["RcvLineStoreQty"].ToString()) == Convert.ToDecimal(dt1.Rows[0]["DisposeInQty"].ToString()))
  92. // {
  93. // string sql2 = @"UPDATE a SET a.DescFlexSegments_PrivateDescSeg20=1
  94. // FROM dbo.PM_POLine a
  95. // LEFT JOIN dbo.PM_PurchaseOrder b ON a.PurchaseOrder=b.ID
  96. // WHERE b.DocNo='{0}' AND a.DocLineNo='{1}'";
  97. // sql2 = string.Format(sql2, dt.Rows[0]["RcvLineSrcPOSrcDocNo"].ToString(), dt.Rows[0]["RcvLineSrcPOSrcDocLineNo"].ToString());
  98. // DBHelper.ExecuteNonQuery(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP]"), CommandType.Text, sql2);
  99. // }
  100. // else if (Convert.ToDecimal(dt.Rows[0]["RcvLineStoreQty"].ToString()) > Convert.ToDecimal(dt1.Rows[0]["DisposeInQty"].ToString()))
  101. // {
  102. // string sql2 = @"UPDATE a SET a.DescFlexSegments_PrivateDescSeg20=0
  103. // FROM dbo.PM_POLine a
  104. // LEFT JOIN dbo.PM_PurchaseOrder b ON a.PurchaseOrder=b.ID
  105. // WHERE b.DocNo='{0}' AND a.DocLineNo='{1}'";
  106. // sql2 = string.Format(sql2, dt.Rows[0]["RcvLineSrcPOSrcDocNo"].ToString(), dt.Rows[0]["RcvLineSrcPOSrcDocLineNo"].ToString());
  107. // DBHelper.ExecuteNonQuery(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP]"), CommandType.Text, sql2);
  108. // }
  109. // }
  110. // else//查询不到数据默认到货数量大,回写0
  111. // {
  112. // string sql2 = @"UPDATE a SET a.DescFlexSegments_PrivateDescSeg20=0
  113. // FROM dbo.PM_POLine a
  114. // LEFT JOIN dbo.PM_PurchaseOrder b ON a.PurchaseOrder=b.ID
  115. // WHERE b.DocNo='{0}' AND a.DocLineNo='{1}'";
  116. // sql2 = string.Format(sql2, dt.Rows[0]["RcvLineSrcPOSrcDocNo"].ToString(), dt.Rows[0]["RcvLineSrcPOSrcDocLineNo"].ToString());
  117. // DBHelper.ExecuteNonQuery(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP]"), CommandType.Text, sql2);
  118. // }
  119. // }
  120. // }
  121. // }
  122. // catch (Exception ex)
  123. // {
  124. // throw ex;
  125. // }
  126. // }
  127. // private static DataTable SQlReturnData(SqlCommand cmd)
  128. // {
  129. // DataTable dt = new DataTable();
  130. // SqlDataAdapter dr = new System.Data.SqlClient.SqlDataAdapter();
  131. // dr.SelectCommand = cmd;
  132. // dr.Fill(dt);
  133. // return dt;
  134. // }
  135. #endregion
  136. //public static void EditCompleteInformation(ICSLLDisposeInFo ItemLot, string Appconstr)
  137. //{
  138. // FramDataContext db = new FramDataContext(Appconstr);
  139. // db.Connection.Open();
  140. // db.Transaction = db.Connection.BeginTransaction();
  141. // try
  142. // {
  143. // bool isNew = false;
  144. // var line = db.ICSLLDisposeInFo.SingleOrDefault(a => a.LOTNO == ItemLot.LOTNO && a.ItemCode == ItemLot.ItemCode && a.DocNo == ItemLot.DocNo && a.LineNo == ItemLot.LineNo);
  145. // if (line == null)
  146. // {
  147. // isNew = true;
  148. // line = new ICSLLDisposeInFo();
  149. // line.ID = AppConfig.GetGuid();
  150. // }
  151. // line.CompleteInformation = ItemLot.CompleteInformation;
  152. // line.MUSER = ItemLot.MUSER;
  153. // line.MUSERName = ItemLot.MUSERName;
  154. // line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  155. // if (isNew) db.ICSLLDisposeInFo.InsertOnSubmit(line);
  156. // db.SubmitChanges();
  157. // db.Transaction.Commit();
  158. // }
  159. // catch (Exception ex)
  160. // {
  161. // db.Transaction.Rollback();
  162. // throw new Exception(ex.Message);
  163. // }
  164. //}
  165. //public static void LLDisposeAgainEdit(List<ICSLLDisposeInFoAgain> ItemLotList, string Appconstr)
  166. //{
  167. // FramDataContext db = new FramDataContext(Appconstr);
  168. // db.Connection.Open();
  169. // db.Transaction = db.Connection.BeginTransaction();
  170. // try
  171. // {
  172. // foreach (ICSLLDisposeInFoAgain lineNew in ItemLotList)
  173. // {
  174. // bool isNew = false;
  175. // var line = db.ICSLLDisposeInFoAgain.SingleOrDefault(a => a.LOTNO == lineNew.LOTNO && a.ItemCode == lineNew.ItemCode);
  176. // if (line == null)
  177. // {
  178. // isNew = true;
  179. // line = new ICSLLDisposeInFoAgain();
  180. // line.ID = AppConfig.GetGuid();
  181. // }
  182. // line.LOTNO = lineNew.LOTNO;
  183. // line.ItemCode = lineNew.ItemCode;
  184. // line.ItemName = lineNew.ItemName;
  185. // line.BarCodeQty = lineNew.BarCodeQty;
  186. // line.DisposeInQty = lineNew.DisposeInQty;
  187. // line.SupplierName = lineNew.SupplierName;
  188. // line.DocNo = lineNew.DocNo;
  189. // line.LineNo = lineNew.LineNo;
  190. // line.MUSER = lineNew.MUSER;
  191. // line.MUSERName = lineNew.MUSERName;
  192. // line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  193. // line.WorkPoint = lineNew.WorkPoint;
  194. // line.EATTRIBUTE1 = lineNew.EATTRIBUTE1;
  195. // if (isNew) db.ICSLLDisposeInFoAgain.InsertOnSubmit(line);
  196. // db.SubmitChanges();
  197. // }
  198. // db.Transaction.Commit();
  199. // }
  200. // catch (Exception ex)
  201. // {
  202. // db.Transaction.Rollback();
  203. // throw new Exception(ex.Message);
  204. // }
  205. //}
  206. public static void LLDisposeAgainEditByLOTNO(List<ICSLLDisposeInFoAgain> ItemLotList, string Appconstr)
  207. {
  208. FramDataContext db = new FramDataContext(Appconstr);
  209. db.Connection.Open();
  210. db.Transaction = db.Connection.BeginTransaction();
  211. try
  212. {
  213. foreach (ICSLLDisposeInFoAgain lineNew in ItemLotList)
  214. {
  215. //判断是否存在自定义档案,不存在则自动生成一条确认数据
  216. //if (!GetUserCodeIsTrue(lineNew.LOTNO, Appconstr))
  217. //{
  218. bool isNew = false;
  219. var line = db.ICSLLDisposeInFoAgain.SingleOrDefault(a => a.LOTNO == lineNew.LOTNO && a.ItemCode == lineNew.ItemCode);
  220. if (line == null)
  221. {
  222. isNew = true;
  223. line = new ICSLLDisposeInFoAgain();
  224. line.ID = AppConfig.GetGuid();
  225. }
  226. line.LOTNO = lineNew.LOTNO;
  227. line.ItemCode = lineNew.ItemCode;
  228. line.ItemName = lineNew.ItemName;
  229. line.BarCodeQty = lineNew.BarCodeQty;
  230. line.DisposeInQty = lineNew.DisposeInQty;
  231. line.SupplierName = lineNew.SupplierName;
  232. line.DocNo = lineNew.DocNo;
  233. line.LineNo = lineNew.LineNo;
  234. line.MUSER = lineNew.MUSER;
  235. line.MUSERName = lineNew.MUSERName;
  236. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  237. line.WorkPoint = lineNew.WorkPoint;
  238. line.EATTRIBUTE1 = lineNew.EATTRIBUTE1;
  239. if (isNew) db.ICSLLDisposeInFoAgain.InsertOnSubmit(line);
  240. db.SubmitChanges();
  241. //}
  242. }
  243. db.Transaction.Commit();
  244. }
  245. catch (Exception ex)
  246. {
  247. db.Transaction.Rollback();
  248. throw new Exception(ex.Message);
  249. }
  250. }
  251. private static bool GetUserCodeIsTrue(string LotNo, string Appconstr)
  252. {
  253. bool isTrue = false;
  254. string sql = string.Format(@"SELECT *
  255. FROM Sys_EnumValues
  256. WHERE EnumKey='080'
  257. AND EnumValue=(SELECT MUSERCode FROM WM_RCVShip
  258. WHERE guid =(SELECT RCVShipguid FROM WM_BarCode WHERE BarCodeNo='{0}'))", LotNo);
  259. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  260. if (dt != null && dt.Rows.Count > 0)
  261. {
  262. isTrue = true;
  263. }
  264. return isTrue;
  265. }
  266. }
  267. }