using System; using System.Collections.Generic; using System.Linq; using System.Text; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.Data.DAL { public class ICSInstorageDAL { public static void Insert(ICSInStorage storage, List detail, string conn) { FramDataContext frame = new FramDataContext(conn); frame.Connection.Open(); frame.Transaction = frame.Connection.BeginTransaction(); try { ICSInStorage isexists = frame.ICSInStorage.FirstOrDefault(a => a.RKCode == storage.RKCode); if (isexists != null) { throw new Exception("入库单号:" + storage.RKCode + "已存在!"); } foreach (ICSInStorageDetail a in detail) { ICSITEMLot lot = frame.ICSITEMLot.Where(b => b.LotNO == a.Lotno).SingleOrDefault(); if (lot != null) { if (!string.IsNullOrEmpty(lot.EATTRIBUTE6)) { throw new Exception("条码:" + a.Lotno + "已产生入库单,请勿重复生成!"); } lot.RKcode =storage.RKCode; } else { throw new Exception("获取条码:" + a.Lotno + "信息失败!"); } } frame.SubmitChanges(); frame.ICSInStorage.InsertOnSubmit(storage); frame.SubmitChanges(); frame.ICSInStorageDetail.InsertAllOnSubmit(detail); frame.SubmitChanges(); frame.Transaction.Commit(); } catch (Exception ex) { frame.Transaction.Rollback(); throw ex; } } public static void Delete(List rkcode,string conn) { FramDataContext frame = new FramDataContext(conn); frame.Connection.Open(); frame.Transaction = frame.Connection.BeginTransaction(); try { IQueryable instorage=frame.ICSInStorage.Where(a=>rkcode.Contains(a.RKCode)); List detail = frame.ICSInStorageDetail.Where(a => rkcode.Contains(a.RKCode)).Select(b=>b).ToList(); foreach (ICSInStorageDetail d in detail) { ICSITEMLot lot=frame.ICSITEMLot.Where(a => a.LotNO == d.Lotno).SingleOrDefault(); if (lot != null) { if (!string.IsNullOrEmpty(lot.ISCOM)) { throw new Exception("条码:"+lot.LotNO+"已入库无法删除!"); } lot.RKcode = null; } } frame.SubmitChanges(); frame.ICSInStorageDetail.DeleteAllOnSubmit(detail); frame.SubmitChanges(); frame.ICSInStorage.DeleteAllOnSubmit(instorage); frame.SubmitChanges(); frame.Transaction.Commit(); } catch (Exception ex) { frame.Transaction.Rollback(); throw ex; } } } }