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.
|
|
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 ICSMODELDAL { #region AddandEdit
public static void AddandEdit(ICSMODEL MODEL, string Appconstr) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { bool isNew = false; var line = db.ICSMODEL.SingleOrDefault(a => a.ID == MODEL.ID);
if (line == null) { isNew = true; line = new ICSMODEL(); line.ID = AppConfig.GetGuid(); }
var codes = db.ICSMODEL.Where(a => a.MODELCODE == MODEL.MODELCODE && a.ID != line.ID); if (codes.ToList().Count > 0) { throw new Exception("产品别代码已存在"); }
line.MODELCODE = MODEL.MODELCODE; line.MODELDESC = MODEL.MODELDESC; line.MUSER = MODEL.MUSER; line.MUSERName = MODEL.MUSERName; line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); line.WorkPoint = AppConfig.WorkPointCode;
if (isNew) db.ICSMODEL.InsertOnSubmit(line);
db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw new Exception(ex.Message); } } #endregion
#region AddandEdit
public static void AddandEdit(List<ICSINVOPPrice> inv, string Appconstr,String type) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (type != "导入") { foreach (var MODEL in inv) { bool isNew = false; var line = db.ICSINVOPPrice.SingleOrDefault(a => a.id == MODEL.id);
if (line == null) { isNew = true; line = new ICSINVOPPrice(); line.id = AppConfig.GetGuid(); } //判断存货编码和工序是否存在
var INV_Exists = db.ICSINVENTORY.Where(a => a.INVCODE == MODEL.invcode).FirstOrDefault(); if (INV_Exists == null) { throw new Exception("存货编码:" + MODEL.invcode + "不存在!"); } var OP_Exists = db.ICSOP.Where(a => a.OPCODE == MODEL.opcode).FirstOrDefault(); if (OP_Exists == null) { throw new Exception("工序编码:" + MODEL.opcode + "不存在!"); }
var codes = db.ICSINVOPPrice.Where(a => a.invcode == MODEL.invcode && a.id != line.id && a.opcode == MODEL.opcode); if (codes.ToList().Count > 0) { throw new Exception("存货编码:" + MODEL.invcode + ",对应的工序:" + MODEL.opcode + "已维护单价!"); }
line.invcode = MODEL.invcode; line.opcode = MODEL.opcode; line.Muser = MODEL.Muser; line.price = MODEL.price; line.Mtime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
if (isNew) db.ICSINVOPPrice.InsertOnSubmit(line);
} } else {
foreach (var MODEL in inv) { bool isNew = false; var line = db.ICSINVOPPrice.Where(a => a.invcode == MODEL.invcode && a.opcode == MODEL.opcode).FirstOrDefault();
if (line == null) { isNew = true; line = new ICSINVOPPrice(); line.id = AppConfig.GetGuid(); } //判断存货编码和工序是否存在
var INV_Exists = db.ICSINVENTORY.Where(a => a.INVCODE == MODEL.invcode).FirstOrDefault(); if (INV_Exists == null) { throw new Exception("存货编码:" + MODEL.invcode + "不存在!"); } var OP_Exists = db.ICSOP.Where(a => a.OPCODE == MODEL.opcode).FirstOrDefault(); if (OP_Exists == null) { throw new Exception("工序编码:" + MODEL.opcode + "不存在!"); }
line.invcode = MODEL.invcode; line.opcode = MODEL.opcode; line.Muser = MODEL.Muser; line.price = MODEL.price; line.Mtime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); if (isNew) db.ICSINVOPPrice.InsertOnSubmit(line);
}
} db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw new Exception(ex.Message); } } #endregion
#region select
public static ICSMODEL select(String guid, String Appconstr) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); ICSMODEL entity = new ICSMODEL(); try { var line = db.ICSMODEL.SingleOrDefault(a => a.ID == guid); return (ICSMODEL)line; } catch (Exception ex) { throw new Exception(ex.Message); } } #endregion
#region select
public static ICSINVOPPrice selectprice(String guid, String Appconstr) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); ICSINVOPPrice entity = new ICSINVOPPrice(); try { var line = db.ICSINVOPPrice.SingleOrDefault(a => a.id == guid); return (ICSINVOPPrice)line; } catch (Exception ex) { throw new Exception(ex.Message); } } #endregion
#region delete
public static void delete(List<String> guidList, List<String> codeList) { FramDataContext db = new FramDataContext(AppConfig.AppConnectString); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { var line = db.ICSINVENTORY.Where(a => codeList.Contains(a.INVCLASS)); if(line.Count()>0){ throw new Exception("产品别已经关联存货档案无法删除!!"); } var lines = db.ICSMODEL.Where(a => guidList.Contains(a.ID)); db.ICSMODEL.DeleteAllOnSubmit(lines);
db.SubmitChanges(); db.Transaction.Commit();
} catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #endregion
#region delete
public static void deleteprice(List<String> guidList) { FramDataContext db = new FramDataContext(AppConfig.AppConnectString); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { var lines = db.ICSINVOPPrice.Where(a => guidList.Contains(a.id)); db.ICSINVOPPrice.DeleteAllOnSubmit(lines);
db.SubmitChanges(); db.Transaction.Commit();
} catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #endregion
} }
|