using System; using System.Collections.Generic; using System.Linq; using System.Text; using ICSSoft.Frame.Data.Entity; using ICSSoft.Base.Config.AppConfig; using System.Data; using System.Data.Sql; using System.Data.Linq; namespace ICSSoft.Frame.Data.DAL { public class ICSINVInfoDAL { #region AddandEdit public static void AddandEdit(ICSINVInfo inventoryLot, string Appconstr) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { bool isNew = false; ICSINVInfo line = db.ICSINVInfo.SingleOrDefault(a => a.INVCODE == inventoryLot.INVCODE && a.WorkPoint == AppConfig.WorkPointCode); if (inventoryLot.ID == "")//新增 { if (line != null) { throw new Exception(inventoryLot.INVCODE + "物料编码已存在"); } isNew = true; line = new ICSINVInfo(); line.ID = AppConfig.GetGuid(); } line.INVCODE = inventoryLot.INVCODE; line.INVNAME = inventoryLot.INVNAME; line.EATTRIBUTE5 = inventoryLot.EATTRIBUTE5; //line.EATTRIBUTE6 = inventoryLot.EATTRIBUTE6; line.MUSER = inventoryLot.MUSER; line.MUSERName = inventoryLot.MUSERName; line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); line.WorkPoint = AppConfig.WorkPointCode; if (isNew) { db.ICSINVInfo.InsertOnSubmit(line); } db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw new Exception(ex.Message); } } #endregion #region 新增和修改List public static string AddList(List InfoList, List listLvL, string dsconn) { FramDataContext db = new FramDataContext(dsconn); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { string str = ""; foreach (ICSINVInfo info in InfoList) { var code = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.INVCODE && a.WorkPoint == AppConfig.WorkPointCode); if (code == null) { str += "存货编码:" + info.INVCODE + "不存在" + "\r\n"; continue; } if (!listLvL.Contains(info.EATTRIBUTE5)) { str += "存货编码:" + info.INVCODE + "不存在此产品等级" + info.EATTRIBUTE5 + "\r\n"; continue; } bool isNew = false; var line = db.ICSINVInfo.SingleOrDefault(a => a.INVCODE == info.INVCODE && a.WorkPoint == AppConfig.WorkPointCode); if (line == null) { isNew = true; line = new ICSINVInfo(); line.ID = AppConfig.GetGuid(); } line.INVCODE = info.INVCODE; line.INVNAME = info.INVNAME; line.EATTRIBUTE1 = info.EATTRIBUTE1; line.EATTRIBUTE5 = info.EATTRIBUTE5; line.EATTRIBUTE4 = info.EATTRIBUTE4; line.EATTRIBUTE6 = info.EATTRIBUTE6; line.MUSER = AppConfig.UserCode; line.MUSERName = AppConfig.UserName; line.MTIME = DateTime.Now; line.WorkPoint = AppConfig.WorkPointCode; if (isNew) db.ICSINVInfo.InsertOnSubmit(line); db.SubmitChanges(); } db.Transaction.Commit(); return str; } catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #endregion #region select public static ICSINVInfo select(String guid, String Appconstr) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); ICSINVENTORY entity = new ICSINVENTORY(); try { var line = db.ICSINVInfo.SingleOrDefault(a => a.ID == guid); return (ICSINVInfo)line; } catch (Exception ex) { throw new Exception(ex.Message); } } #endregion #region delete public static void delete(List guidList, List codeList) { FramDataContext db = new FramDataContext(AppConfig.AppConnectString); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { var lines = db.ICSINVInfo.Where(a => guidList.Contains(a.ID) && a.WorkPoint == AppConfig.WorkPointCode); db.ICSINVInfo.DeleteAllOnSubmit(lines); db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #endregion } }