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.
359 lines
18 KiB
359 lines
18 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSAllocationDAL
|
|
{
|
|
|
|
public static void AddJiLu(FormICSITEMTransUIModel infomodel, FormICSITEMTransLotUIModel lotmodel, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
bool isNew = false;
|
|
string testid = "";
|
|
var info = db.ICSITEMTrans.SingleOrDefault(a => a.TransNO == infomodel.TransNO && a.TransLine == infomodel.TransLine);
|
|
if (info == null)
|
|
{
|
|
isNew = true;
|
|
info = new ICSITEMTrans();
|
|
info.ID = AppConfig.GetGuid();
|
|
testid = info.ID;
|
|
}
|
|
|
|
testid = info.ID;
|
|
info.TransNO = infomodel.TransNO;
|
|
info.TransLine = infomodel.TransLine;
|
|
info.ITEMCODE = infomodel.ITEMCODE;
|
|
info.FRMStorageCODE = infomodel.FRMStorageCODE;
|
|
info.FRMStackCODE = infomodel.FRMStackCODE;
|
|
info.TOStorageCODE = infomodel.TOStorageCODE;
|
|
info.TOStackCODE = infomodel.TOStackCODE;
|
|
//info.LotNO = infomodel.LotNO;
|
|
if (!isNew)
|
|
{
|
|
info.TransQTY += infomodel.TransQTY;
|
|
}
|
|
else
|
|
{
|
|
info.TransQTY = infomodel.TransQTY;
|
|
}
|
|
info.TransType = infomodel.TransType;
|
|
info.BusinessCode = infomodel.BusinessCode;
|
|
info.MUSER = AppConfig.UserId;
|
|
info.MUSERName = AppConfig.UserName;
|
|
info.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
info.WorkPoint = AppConfig.WorkPointCode;
|
|
if (isNew)
|
|
db.ICSITEMTrans.InsertOnSubmit(info);
|
|
db.SubmitChanges();
|
|
|
|
ICSITEMTransLot lotinfo = new ICSITEMTransLot();
|
|
lotinfo.ID = AppConfig.GetGuid();
|
|
lotinfo.ITEMTransID = testid;
|
|
lotinfo.LotNO = lotmodel.LotNO;
|
|
lotinfo.ITEMCODE = lotmodel.ITEMCODE;
|
|
lotinfo.TransQTY = lotmodel.TransQTY;
|
|
lotinfo.MUSER = AppConfig.UserId;
|
|
lotinfo.MUSERName = AppConfig.UserName;
|
|
lotinfo.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
lotinfo.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSITEMTransLot.InsertOnSubmit(lotinfo);
|
|
db.SubmitChanges();
|
|
//更新转移单详细表数量
|
|
var transdetail = db.ICSInvTransferDetail.SingleOrDefault(a => a.TransferNO == infomodel.TransNO && a.TransferLine == infomodel.TransLine);
|
|
if (transdetail != null)
|
|
transdetail.ACTQTY += infomodel.TransQTY;
|
|
db.SubmitChanges();
|
|
|
|
var linethree = db.ICSStorage.SingleOrDefault(a => a.StorageCode == infomodel.TOStorageCODE);
|
|
string whguid = linethree.Serial;
|
|
var linefour = db.ICSStack.SingleOrDefault(a => a.StackCode == infomodel.TOStackCODE);
|
|
string binguid = linefour.Serial;
|
|
var linefive = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == infomodel.ITEMCODE);
|
|
string invguid = linefive.ID;
|
|
// 更新库存信息
|
|
var WareHouseInfoF = db.ICSWareHouseInfo.SingleOrDefault(a => a.WHCode == infomodel.FRMStorageCODE && a.BinCode == infomodel.FRMStackCODE && a.INVCode == infomodel.ITEMCODE);
|
|
if (WareHouseInfoF != null)
|
|
{
|
|
WareHouseInfoF.QTY -= infomodel.TransQTY;
|
|
}
|
|
db.SubmitChanges();
|
|
var WareHouseInfoT = db.ICSWareHouseInfo.SingleOrDefault(a => a.WHCode == infomodel.TOStorageCODE && a.BinCode == infomodel.TOStackCODE && a.INVCode == infomodel.ITEMCODE);
|
|
if (WareHouseInfoT != null)
|
|
WareHouseInfoT.QTY += infomodel.TransQTY;
|
|
else
|
|
{
|
|
ICSWareHouseInfo infoF = new ICSWareHouseInfo();
|
|
infoF.WHGUID = whguid;
|
|
infoF.WHCode = infomodel.TOStorageCODE;
|
|
infoF.BinGUID = binguid;
|
|
infoF.BinCode = infomodel.TOStackCODE; ;
|
|
infoF.INVGUID = invguid; ;
|
|
infoF.INVCode = infomodel.ITEMCODE;
|
|
infoF.QTY = infomodel.TransQTY; ;
|
|
infoF.MUSER = AppConfig.UserCode;
|
|
infoF.MUSERName = AppConfig.UserName;
|
|
infoF.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
infoF.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSWareHouseInfo.InsertOnSubmit(infoF);
|
|
}
|
|
db.SubmitChanges();
|
|
|
|
var Lot = db.ICSWareHouseLotInfo.SingleOrDefault(a => a.LotNO == lotmodel.LotNO);
|
|
db.ICSWareHouseLotInfo.DeleteOnSubmit(Lot);
|
|
db.SubmitChanges();
|
|
ICSWareHouseLotInfo InfoLot = new ICSWareHouseLotInfo();
|
|
InfoLot.ID = AppConfig.GetGuid();
|
|
InfoLot.LotNO = lotmodel.LotNO;
|
|
InfoLot.WHGUID = whguid;
|
|
InfoLot.WHCode = infomodel.TOStorageCODE;
|
|
InfoLot.BinGUID = binguid;
|
|
InfoLot.BinCode = infomodel.TOStackCODE;
|
|
InfoLot.INVGUID = invguid;
|
|
InfoLot.INVCode = infomodel.ITEMCODE;
|
|
InfoLot.LotQty = infomodel.TransQTY;
|
|
InfoLot.ReceiveDate = DateTime.Now;
|
|
InfoLot.MUSER = AppConfig.UserCode;
|
|
InfoLot.MUSERName = AppConfig.UserName;
|
|
InfoLot.MTIME = DateTime.Now;
|
|
InfoLot.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSWareHouseLotInfo.InsertOnSubmit(InfoLot);
|
|
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void TransItem(List<FormICSITEMTransUIModel> translist, List<FormICSInvTransferDetailUIModel> transdetail, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
|
|
foreach (FormICSITEMTransUIModel trans in translist)
|
|
{
|
|
|
|
//批次
|
|
if (trans.Lot.lotdetail == null || trans.Lot.lotdetail.Count() == 0)
|
|
{
|
|
|
|
ICSITEMTrans transmodel = new ICSITEMTrans();
|
|
transmodel.ID = AppConfig.GetGuid();
|
|
transmodel.TransNO = trans.TransNO;
|
|
transmodel.TransLine = trans.TransLine;
|
|
transmodel.ITEMCODE = trans.ITEMCODE;
|
|
transmodel.FRMStorageCODE = trans.FRMStorageCODE;
|
|
transmodel.FRMStackCODE = trans.FRMStackCODE;
|
|
transmodel.TOStorageCODE = trans.TOStorageCODE;
|
|
transmodel.TOStackCODE = trans.TOStackCODE;
|
|
transmodel.TransQTY = trans.TransQTY;
|
|
transmodel.Memo = "";
|
|
transmodel.TransType = "发";
|
|
transmodel.BusinessCode = "";
|
|
transmodel.MUSER = AppConfig.UserId;
|
|
transmodel.MUSERName = AppConfig.UserName;
|
|
transmodel.MTIME = DateTime.Now;
|
|
transmodel.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSITEMTrans.InsertOnSubmit(transmodel);
|
|
|
|
ICSITEMTransLot lotmodel = new ICSITEMTransLot();
|
|
lotmodel.ID = AppConfig.GetGuid();
|
|
lotmodel.ITEMTransID = transmodel.ID;
|
|
lotmodel.LotNO = trans.Lot.LotNO;
|
|
lotmodel.ITEMCODE = trans.Lot.ITEMCODE;
|
|
lotmodel.TransQTY = trans.Lot.TransQTY;
|
|
lotmodel.Memo = "";
|
|
lotmodel.MUSER = AppConfig.UserId;
|
|
lotmodel.MUSERName = AppConfig.UserName;
|
|
lotmodel.MTIME = DateTime.Now;
|
|
lotmodel.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSITEMTransLot.InsertOnSubmit(lotmodel);
|
|
|
|
var lineone = db.ICSWareHouseLotInfo.SingleOrDefault(a => a.LotNO == trans.Lot.LotNO && a.WHCode == trans.FRMStorageCODE && a.BinCode == trans.FRMStackCODE && a.INVCode == trans.ITEMCODE);
|
|
string guid = lineone.ID;
|
|
//删除库存
|
|
var linetwo = db.ICSWareHouseLotInfo.Where(a => a.ID == guid);
|
|
db.ICSWareHouseLotInfo.DeleteAllOnSubmit(linetwo);
|
|
var linethree = db.ICSStorage.SingleOrDefault(a => a.StorageCode == trans.TOStorageCODE);
|
|
string whguid = linethree.Serial;
|
|
var linefour = db.ICSStack.SingleOrDefault(a => a.StackCode == trans.TOStackCODE);
|
|
string binguid = linefour.Serial;
|
|
var linefive = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == trans.ITEMCODE);
|
|
string invguid = linefive.ID;
|
|
//添加库存
|
|
ICSWareHouseLotInfo ware = new ICSWareHouseLotInfo();
|
|
ware.ID = guid;
|
|
ware.LotNO = trans.Lot.LotNO;
|
|
ware.WHGUID = whguid;
|
|
ware.WHCode = transmodel.TOStorageCODE;
|
|
ware.BinGUID = binguid;
|
|
ware.BinCode = transmodel.TOStackCODE;
|
|
ware.INVGUID = invguid;
|
|
ware.INVCode = transmodel.ITEMCODE;
|
|
ware.LotQty = transmodel.TransQTY;
|
|
ware.ReceiveDate = DateTime.Now;
|
|
ware.MUSER = AppConfig.UserId;
|
|
ware.MUSERName = AppConfig.UserName;
|
|
ware.MTIME = DateTime.Now;
|
|
ware.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSWareHouseLotInfo.InsertOnSubmit(ware);
|
|
}
|
|
else
|
|
{
|
|
|
|
ICSITEMTrans transmodel = new ICSITEMTrans();
|
|
transmodel.ID = AppConfig.GetGuid();
|
|
transmodel.TransNO = trans.TransNO;
|
|
transmodel.TransLine = trans.TransLine;
|
|
transmodel.ITEMCODE = trans.ITEMCODE;
|
|
transmodel.FRMStorageCODE = trans.FRMStorageCODE;
|
|
transmodel.FRMStackCODE = trans.FRMStackCODE;
|
|
transmodel.TOStorageCODE = trans.TOStorageCODE;
|
|
transmodel.TOStackCODE = trans.TOStackCODE;
|
|
transmodel.TransQTY = trans.TransQTY;
|
|
transmodel.Memo = "";
|
|
transmodel.TransType = "发";
|
|
transmodel.BusinessCode = "";
|
|
transmodel.MUSER = AppConfig.UserId;
|
|
transmodel.MUSERName = AppConfig.UserName;
|
|
transmodel.MTIME = DateTime.Now;
|
|
transmodel.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSITEMTrans.InsertOnSubmit(transmodel);
|
|
|
|
ICSITEMTransLot lotmodel = new ICSITEMTransLot();
|
|
lotmodel.ID = AppConfig.GetGuid();
|
|
lotmodel.ITEMTransID = transmodel.ID;
|
|
lotmodel.LotNO = trans.Lot.LotNO;
|
|
lotmodel.ITEMCODE = trans.Lot.ITEMCODE;
|
|
lotmodel.TransQTY = trans.Lot.TransQTY;
|
|
lotmodel.Memo = "";
|
|
lotmodel.MUSER = AppConfig.UserId;
|
|
lotmodel.MUSERName = AppConfig.UserName;
|
|
lotmodel.MTIME = DateTime.Now;
|
|
lotmodel.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSITEMTransLot.InsertOnSubmit(lotmodel);
|
|
|
|
foreach (FormICSITEMTransLotDetailUIModel details in trans.Lot.lotdetail)
|
|
{
|
|
ICSITEMTransLotDetail detailmodel = new ICSITEMTransLotDetail();
|
|
detailmodel.ID = AppConfig.GetGuid();
|
|
detailmodel.ITEMTransLotID = lotmodel.ID;
|
|
detailmodel.LotNO = details.LotNO;
|
|
detailmodel.ITEMCODE = details.ITEMCODE;
|
|
detailmodel.SERIALNO = details.SERIALNO;
|
|
detailmodel.MUSER = AppConfig.UserId;
|
|
detailmodel.MUSERName = AppConfig.UserName;
|
|
detailmodel.MTIME = DateTime.Now;
|
|
detailmodel.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSITEMTransLotDetail.InsertOnSubmit(detailmodel);
|
|
|
|
}
|
|
|
|
|
|
var lineone = db.ICSWareHouseLotInfo.SingleOrDefault(a => a.LotNO == trans.Lot.LotNO && a.WHCode == trans.FRMStorageCODE && a.BinCode == trans.FRMStackCODE && a.INVCode == trans.ITEMCODE);
|
|
if (lineone.LotQty > trans.TransQTY)
|
|
{
|
|
var linetwo = db.ICSStorage.SingleOrDefault(a => a.StorageCode == trans.TOStorageCODE);
|
|
string whguid = linetwo.Serial;
|
|
var linethree = db.ICSStack.SingleOrDefault(a => a.StackCode == trans.TOStackCODE);
|
|
string binguid = linethree.Serial;
|
|
|
|
string lotnoone = "LOT" + AppConfig.GetSeverDateTime("yyyy-MM-dd").ToString("yyyyMMdd");
|
|
lotnoone = AppConfig.GetSerialCode(AppConfig.FrameConnectString, AppConfig.WorkPointCode, "ICSWareHouseLotInfo", "LotNo", lotnoone, 4);
|
|
lineone.LotQty -= trans.TransQTY;
|
|
ICSWareHouseLotInfo lotinfomodel = new ICSWareHouseLotInfo();
|
|
lotinfomodel.ID = AppConfig.GetGuid();
|
|
lotinfomodel.LotNO = lotnoone;
|
|
lotinfomodel.WHGUID = whguid;
|
|
lotinfomodel.WHCode = trans.TOStorageCODE;
|
|
lotinfomodel.BinGUID = binguid;
|
|
lotinfomodel.BinCode = trans.TOStackCODE;
|
|
lotinfomodel.INVGUID = lineone.INVGUID;
|
|
lotinfomodel.INVCode = lineone.INVCode;
|
|
lotinfomodel.LotQty = trans.TransQTY;
|
|
lotinfomodel.ReceiveDate = DateTime.Now;
|
|
lotinfomodel.MUSER = AppConfig.UserId;
|
|
lotinfomodel.MUSERName = AppConfig.UserName;
|
|
lotinfomodel.MTIME = DateTime.Now;
|
|
lotinfomodel.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSWareHouseLotInfo.InsertOnSubmit(lotinfomodel);
|
|
}
|
|
else if (lineone.LotQty == trans.TransQTY)
|
|
{
|
|
string guid = lineone.ID;
|
|
//删除库存
|
|
var linefour = db.ICSWareHouseLotInfo.Where(a => a.ID == guid);
|
|
db.ICSWareHouseLotInfo.DeleteAllOnSubmit(linefour);
|
|
var linefive = db.ICSStorage.SingleOrDefault(a => a.StorageCode == trans.TOStorageCODE);
|
|
string whguid = linefive.Serial;
|
|
var linesix = db.ICSStack.SingleOrDefault(a => a.StackCode == trans.TOStackCODE);
|
|
string binguid = linesix.Serial;
|
|
var lineseven = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == trans.ITEMCODE);
|
|
string invguid = lineseven.ID;
|
|
//添加库存
|
|
ICSWareHouseLotInfo ware = new ICSWareHouseLotInfo();
|
|
ware.ID = guid;
|
|
ware.LotNO = trans.Lot.LotNO;
|
|
ware.WHGUID = whguid;
|
|
ware.WHCode = transmodel.TOStorageCODE;
|
|
ware.BinGUID = binguid;
|
|
ware.BinCode = transmodel.TOStackCODE;
|
|
ware.INVGUID = invguid;
|
|
ware.INVCode = transmodel.ITEMCODE;
|
|
ware.LotQty = transmodel.TransQTY;
|
|
ware.ReceiveDate = DateTime.Now;
|
|
ware.MUSER = AppConfig.UserId;
|
|
ware.MUSERName = AppConfig.UserName;
|
|
ware.MTIME = DateTime.Now;
|
|
ware.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSWareHouseLotInfo.InsertOnSubmit(ware);
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
foreach (FormICSInvTransferDetailUIModel transdet in transdetail)
|
|
{
|
|
var linesix = db.ICSInvTransferDetail.SingleOrDefault(a => a.TransferNO == transdet.TransferNO && a.TransferLine == transdet.TransferLine);
|
|
linesix.ACTQTY += transdet.ACTQTY;
|
|
linesix.TOStackCode = transdet.TOStackCode;
|
|
}
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|