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

100 lines
3.4 KiB

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<ICSInStorageDetail> 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<string> rkcode,string conn)
{
FramDataContext frame = new FramDataContext(conn);
frame.Connection.Open();
frame.Transaction = frame.Connection.BeginTransaction();
try
{
IQueryable<ICSInStorage> instorage=frame.ICSInStorage.Where(a=>rkcode.Contains(a.RKCode));
List<ICSInStorageDetail> 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;
}
}
}
}