using ICSSoft.Common;
using ICSSoft.Entity;
using ICSSoft.Entity;
using Newtonsoft.Json;
using NFine.Code;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using static ICSSoft.Entity.LOTCreateIModel;
namespace ICSSoft.DataProject
{
///
/// WMS条码信息
///
public class WMSBarCoreService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
DataTable table = null;
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
string sql = string.Empty;
string sqlInfo = string.Empty;
VerificationMethod verification = new VerificationMethod();
#region 多语言
///
/// 多语言查询
///
///
///
public List Get(WMSBarCoreModel JsonData)
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
sql = @"select cnValue AS Name,Code from Sys_Language where 1=1";
if (!string.IsNullOrWhiteSpace(JsonData.Code))
{
sql += " and Code='{0}'";
}
sql = string.Format(sql, JsonData.Code);
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
List model = JsonConvert.DeserializeObject>(json);
cmd.Transaction.Commit();
return model;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 源头单据信息
///
/// 源头单据信息
///
///
///
public object DocumentGet(WMSSourceDocumentModel JsonData)
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
string jsonInfo = null;
int num = 0;
try
{
sql = @"select * from {0} ";
switch (JsonData.TransType )
{
case "送货单":
string sqlInfoList = @"select * from ICSASNDetail where ASNCode='{0}' and WorkPoint='{1}'";
sqlInfoList = string.Format(sqlInfoList, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfoList, cmd);
if (table.Rows.Count <= 0)
{
throw new Exception("源头单据不存在!");
}
else
{
sqlInfo += @" SELECT a.[ID],
b.TransCode as TransCode ,
c.ID as DetailID,
b.TransSequence as TransSequence,
c.InvCode as InvCode,
d.InvName as InvName,
d.InvStd as InvStd,
a.[Quantity] as Quantity,
d.InvUnit as InvUnit,
a.Amount as Amount,
d.AmountUnit as AmountUnit,
c.ExtensionID as BatchCode,
d.InvVersion as InvVersion,
d.InvBrand as InvBrand,
c.VenCode as cFree1,
c.DepCode as cFree2,
c.POCode as cFree3,
c.UnitPrice as cFree4,
c.Currency as cFree5,
c.DepCode as cFree6,
c.VenCode as cFree7,
a.LotNo,
a.ASNCode
FROM {0} a
left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
left join ICSPurchaseOrder c on b.TransCode = c.POCode and b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence
left join ICSInventory d on c.InvCode = d.InvCode and c.WorkPoint=d.WorkPoint where 1 = 1 and a.ASNCode='{1}' and a.WorkPoint='{2}'";
sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSASNDetail, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var modelInfo = JsonConvert.DeserializeObject(jsonInfo);
return modelInfo;
}
case "委外送货单":
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
b.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
a.OASNCode as TransCode,--来源单据
a.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10,
o.VenCode,
isnull((k.UnitPrice),0) as UnitPrice,
isnull((k.Currency), ' ') as Currency,
isnull((k.DepCode), ' ') as DepCode,
isnull(( k.PersonCode), ' ') asPersonCode
from ICSOASNDetail a
left join ICSInventoryLot b on A.LotNo =B.LotNo
LEFT JOIN ICSInventoryLotDetail c ON A.LotNo =c.LotNo
LEFT JOIN ICSExtension E ON E.ID=b.ExtensionID
LEFT JOIN ICSInventory F ON b.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
inner join ICSOASN O on o.OASNCode=a.OASNCode
LEFT JOIN ICSOutsourcingOrder k on k.OOCode=TransCode and c.TransSequence=k.Sequence
where 1 = 1 and a.OASNCode='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var ReceiveTransq = JsonConvert.DeserializeObject(jsonInfo);
return ReceiveTransq;
case "一步式调拨单":
string sqlkk = @"select * from ICSTransfer where TransferNO='{0}' and WorkPoint='{1}'";
sqlkk = string.Format(sqlkk, JsonData.TransCode, JsonData.WorkPoint);
DataTable dataDt = DBHelper.SQlReturnData(sqlkk, cmd);
if (dataDt.Rows.Count <= 0)
{
throw new Exception("调拨单不存在");
}
else
{
sqlInfo = @"select
a.ID as ID,
a.TransferNO as TransCode,
a.Sequence as TransSequence,
a.InvCode as InvCode,
c.InvName as InvName,
c.InvStd as InvStd,
a.Quantity as Quantity,
c.InvUnit as InvUnit,
a.Amount as Amount,
c.AmountUnit as AmountUnit,
a.ToWarehouseCode ,
a.FromWarehouseCode,
a.ToLocationCode as LocationCode,
--f.WarehouseName as WHName,
c.InvVersion as Version,
c.InvBrand as Brand,
a.TransferQuantity as IssueQuantity ,
a.MUSER as MUSER,
a.MTIME as MTime
from ICSTransfer a --主表
left join ICSExtension b on a.ExtensionID=b.id and a.WorkPoint=b.WorkPoint--条码
left join ICSInventory c on c.InvCode=a.InvCode and c.WorkPoint=b.WorkPoint--y源头单据
left join ICSWarehouse e on e.WarehouseCode =a.FromWarehouseCode and e.WorkPoint=a.WorkPoint
where a.TransferNO='{0}' and a.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var ReceiveTrans = JsonConvert.DeserializeObject(jsonInfo);
return ReceiveTrans;
}
case "委外订单备料表":
sqlInfo = @"select
a.ID as ID,
a.OODetailID as TransCode,
b.Sequence+'-'+a.Sequence as TransSequence,
a.InvCode as InvCode,
c.InvName as InvName,
c.InvStd as InvStd,
a.Quantity as Quantity,
c.InvUnit as InvUnit,
a.Amount as Amount,
c.AmountUnit as AmountUnit,
a.WHCode as WHCode,
d.WarehouseName as WHName,
c.InvVersion as Version,
c.InvBrand as Brand,
a.IssueQuantity ,
a.MUSER as MUSER,
a.MTIME as MTime
from ICSOOPick a --主表
left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
left join ICSInventory c on a.InvCode=c.InvCode AND a.WorkPoint=c.WorkPoint
left join ICSWarehouse d on d.WarehouseCode =a.WHCode AND d.WorkPoint=a.WorkPoint
where b.OOCode='{0}' and b.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var modelInfoList = JsonConvert.DeserializeObject(jsonInfo);
return modelInfoList;
case "委外领料申请单":
sqlInfo = @"select
a.ID as ID,
c.TransCode as TransCode,
c.TransSequence as TransSequence,
a.InvCode as InvCode,
e.InvName as InvName,
e.InvStd as InvStd,
a.Quantity as Quantity,
e.InvUnit as InvUnit,
a.Amount as Amount,
e.AmountUnit as AmountUnit,
a.WHCode as WHCode,
f.WarehouseName as WHName,
e.InvVersion as Version,
e.InvBrand as Brand,
a.IssueQuantity ,
a.MUSER as MUSER,
a.MTIME as MTime
from {0} a --主表
left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--条码
left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--料品
left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint--仓库
where 1=1 and a.Status='2'";
sqlInfo += " and a.ApplyCode='{1}' and a.WorkPoint='{2}'";
sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSMOApply, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Info = JsonConvert.DeserializeObject(jsonInfo);
return Info;
case "材料出库":
sql = @"select
a.ID as ID,
c.TransCode as TransCode,
c.TransSequence as TransSequence,
a.InvCode as InvCode,
e.InvName as InvName,
e.InvStd as InvStd,
a.Quantity as Quantity,
e.InvUnit as InvUnit,
a.Amount as Amount,
e.AmountUnit as AmountUnit,
a.WHCode as WHCode,
f.WarehouseName as WHName,
e.InvVersion as Version,
e.InvBrand as Brand,
a.IssueQuantity as IssueQuantity ,
a.MUSER as MUSER,
a.MTIME as MTime,
a.Status
from ICSMOIssue a --主表
left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--条码
left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--料品
left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint
where a.Status='2' and a.SDNCode='{1}' and a.WorkPoint='{2}'";
sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Issue = JsonConvert.DeserializeObject(jsonInfo);
return Issue;
case "销售发货":
sql = @"select
a.ID as ID,
a.SDNCode as TransCode,
b.ID as DetailID ,
a.Sequence as TransSequence,
b.InvCode as InvCode,
b.InvName as InvName,
b.InvStd as InvStd,
a.Quantity as Quantity,
b.InvUnit as InvUnit,
a.Amount as Amount,
a.SDNQuantity as IssueQuantity,
b.AmountUnit,
d.WarehouseCode as WHCode,
d.WarehouseName as WHName,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10,
a.Type,
a.MUSER,
a.MTIME as MTime
from ICSSDN a
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
left join ICSExtension c on c.ID=a.ExtensionID and c.WorkPoint=a.WorkPoint
left join ICSWarehouse d on d.WarehouseCode=a.WHCode and d.WorkPoint=a.WorkPoint
WHERE type ='1' ";
sql += " and a.SDNCode='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var ICSSDN = JsonConvert.DeserializeObject(jsonInfo);
return ICSSDN;
case "生产订单备料表":
sql = @"select
a.ID as ID,
d.MOCode as TransCode,
d.MODetailID as IDDetailID,
d.Sequence+'-'+a.Sequence as TransSequence,
a.InvCode as InvCode,
e.InvName as InvName,
e.InvStd as InvStd,
a.Quantity as Quantity,
e.InvUnit as InvUnit,
isnull((a.Amount),0)as Amount,
e.AmountUnit as AmountUnit,
a.WHCode as WHCode,
f.WarehouseName as WHName,
e.InvVersion as Version,
e.InvBrand as Brand,
isnull((a.IssueQuantity),0)as IssueQuantity,
a.MUSER as MUSER,
a.MTIME as MTime,
a.WorkPoint,
a.Sequence
from {0} a --主表
INNER JOIN ICSMO d on d.id=a.MODetailID and d.WorkPoint=a.WorkPoint-- 表体标识
INNER JOIN ICSInventory e on e.InvCode=d.InvCode and e.WorkPoint=a.WorkPoint--料品
LEFT JOIN ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint--仓库
where 1=1 ";
sql += " and d.MOCode='{1}' and a.WorkPoint='{2}'";
sql = string.Format(sql, TransTypeEnum.ICSMOPick, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var MOPic = JsonConvert.DeserializeObject(jsonInfo);
return MOPic;
case "委外材料出库":
sqlInfo = @"select
a.ID as ID,
c.TransCode as TransCode,
c.TransSequence as TransSequence,
a.InvCode as InvCode,
e.InvName as InvName,
e.InvStd as InvStd,
a.Quantity as Quantity,
e.InvUnit as InvUnit,
a.Amount as Amount,
e.AmountUnit as AmountUnit,
a.WHCode as WHCode,
f.WarehouseName as WHName,
e.InvVersion as Version,
e.InvBrand as Brand,
a.IssueQuantity ,
a.MUSER as MUSER,
a.MTIME as MTime
from {0} a --主表
left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--条码
left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--料品
left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint--仓库
where 1=1 and a.Status='2'";
sqlInfo += " and a.IssueCode='{1}' and a.WorkPoint='{2}'";
sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSOIssue, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
//sqlInfo = string.Format(sqlInfo, Type.ICSMOApply, JsonData.TransCode);
var ICSOIssue = JsonConvert.DeserializeObject(jsonInfo);
return ICSOIssue;
case "杂发单":
sql = @"select
a.ID as ID,
c.TransCode as TransCode,
c.TransSequence as TransSequence,
a.InvCode as InvCode,
e.InvName as InvName,
e.InvStd as InvStd,
a.Quantity as Quantity,
e.InvUnit as InvUnit,
a.Amount as Amount,
e.AmountUnit as AmountUnit,
a.WHCode as WHCode,
f.WarehouseName as WHName,
e.InvVersion as Version,
e.InvBrand as Brand,
a.OutQuantity as IssueQuantity ,
a.MUSER as MUSER,
a.MTIME as MTime
from ICSOtherOut a --主表
left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--条码
left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--料品
left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint
where a.Status='2' and a.OutCode='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
//sqlInfo = string.Format(sqlInfo, Type.ICSMOApply, JsonData.TransCode);
var ItherOut = JsonConvert.DeserializeObject(jsonInfo);
return ItherOut;
case "采购退货单":
sqlInfo += @"select a.ID,
a.InvCode,
C.InvName,
C.InvStd,
a.Quantity ,
C.InvUnit,
a.Amount AS AmountUnit,
--l.WarehouseCode,
--l.WarehouseName,
--j.LocationCode,
--j.LocationName,
a.RCVQuantity as IssueQuantity,
a.Sequence as TransSequence,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10
from ICSDeliveryNotice a
left join ICSExtension b on a.ExtensionID=b.ID
LEFT JOIN ICSInventory C ON A.InvCode =C.InvCode where 1 = 1 ";
sqlInfo += " and A.DNType='2' AND a.dncode='{0}' and A.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Receive = JsonConvert.DeserializeObject(jsonInfo);
return Receive;
case "委外红字入库单":
sql += " and a.RCVCode='{1}' and Type=2";
sql = string.Format(sql, TransTypeEnum.ICSOutsourcingReceive, JsonData.TransCode);
break;
case "销售退货":
sqlInfo = @"select
a.ID as ID,
a.SDNCode as TransCode,
b.ID as DetailID ,
a.Sequence as TransSequence,
b.InvCode as InvCode,
b.InvName as InvName,
b.InvStd as InvStd,
a.Quantity as Quantity,
b.InvUnit as InvUnit,
a.Amount as Amount,
a.SDNQuantity as IssueQuantity,
b.AmountUnit,
d.WarehouseCode as WHCode,
d.WarehouseName as WHName,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10,
a.Type,
a.MUSER,
a.MTIME as MTime
from {0} a
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
left join ICSExtension c on c.ID=a.ExtensionID and c.WorkPoint=a.WorkPoint
left join ICSWarehouse d on d.WarehouseCode=a.WHCode and d.WorkPoint=a.WorkPoint
WHERE type ='2' ";
sqlInfo += " and a.SDNCode='{1}' and a.WorkPoint='{2}'";
sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSSDN, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var ICSSDNInfo = JsonConvert.DeserializeObject(jsonInfo);
return ICSSDNInfo;
case "两步式调拨单":
sql = @"select
a.ID as ID,
c.TransCode as TransCode,
c.TransSequence as TransSequence,
a.InvCode as InvCode,
e.InvName as InvName,
e.InvStd as InvStd,
a.Quantity as Quantity,
e.InvUnit as InvUnit,
a.Amount as Amount,
e.AmountUnit as AmountUnit,
a.FromWarehouseCode as WHCode,
f.WarehouseName as WHName,
e.InvVersion as Version,
e.InvBrand as Brand,
a.TransferQuantity as IssueQuantity ,
a.MUSER as MUSER,
a.MTIME as MTime
from ICSTransfer a --主表
left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--条码
left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--料品
left join ICSWarehouse f on f.WarehouseCode =a.FromWarehouseCode and f.WorkPoint=a.WorkPoint";
sql += " and a.TransferNO='{0}' and Type=2 and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
break;
case "采购红字入库单":
sql = @"SELECT
a.[ID],
b.TransCode as TransCode ,
c.ID as DetailID,
b.TransSequence as TransSequence,
c.InvCode as InvCode,
d.InvName as InvName,
d.InvStd as InvStd,
a.[Quantity] as Quantity,
d.InvUnit as InvUnit,
a.Amount as Amount,
d.AmountUnit as AmountUnit,
c.ExtensionID as BatchCode,
d.InvVersion as InvVersion,
d.InvBrand as InvBrand,
c.VenCode as cFree1,
c.DepCode as cFree2,
c.POCode as cFree3,
c.UnitPrice as cFree4,
c.Currency as cFree5,
c.DepCode as cFree6,
c.VenCode as cFree7,
b.LotNo,a.RCVQuantity as IssueQuantity
FROM {0} a
left join ICSInventoryLotDetail b on a.SourceCode = b.TransCode and a.WorkPoint=b.WorkPoint
left join ICSPurchaseOrder c on b.TransCode = c.POCode and b.WorkPoint=c.WorkPoint
left join ICSInventory d on c.InvCode = d.InvCode and c.WorkPoint=d.WorkPoint where 1 = 1 and a.Status = '2' and a.type = '红字入库单'";
sql += " and a.RCVCode='{1}' and a.WorkPoint='{2}'";
sql = string.Format(sql, TransTypeEnum.ICSPurchaseReceive, JsonData.TransCode);
break;
case "委外退货单":
sqlInfo = @" SELECT
a.[ID],--表头唯一标识
a.ODNCode as TransCode ,--源头单据号
--c.ID as DetailID,--表体唯一标识
a.Sequence as TransSequence,--源头单据行号
a.InvCode as InvCode ,--料品编码
b.InvName as InvName,
b.InvStd as InvStd,
a.[Quantity] as Quantity,
b.InvUnit as InvUnit,
a.Amount as Amount,
b.AmountUnit as AmountUnit,
c.ProjectCode as ProjectCode,
c.BatchCode as BatchCode,
c.Version as Version,
c.Brand as Brand,
a.RCVQuantity as IssueQuantity,
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10
FROM ICSODeliveryNotice a --退货
LEFT JOIN ICSInventory B ON A.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--料品表
LEFT JOIN ICSExtension C ON A.ExtensionID=C.ID and a.WorkPoint=c.WorkPoint--源头单据
where a.ODNType='2' and a.ODNCode='{0}' and a.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Notice = JsonConvert.DeserializeObject(jsonInfo);
return Notice;
case "盘点":
bool ischeck = verification.isCheck(JsonData.TransCode, JsonData.WorkPoint);
if (ischeck == true)
{
sqlInfo = @"SELECT
a.[ID],--表头唯一标识
f.CheckCode as TransCode ,--源头单据号
--c.ID as DetailID,--表体唯一标识
e.TransCode as TransSequence,--源头单据行号
f.InvCode as InvCode ,--料品编码
b.InvName as InvName,
b.InvStd as InvStd,
a.[Quantity] as Quantity,
b.InvUnit as InvUnit,
f.Amount as Amount,
b.AmountUnit as AmountUnit,
d.ProjectCode as ProjectCode,
d.BatchCode as BatchCode,
d.Version as Version,
d.Brand as Brand,
f.ActualQuantity as IssueQuantity,
d.cFree2,
d.cFree3,
d.cFree4,
d.cFree5,
d.cFree6,
d.cFree7,
d.cFree8,
d.cFree9,
d.cFree10
FROM ICSWareHouseLotInfo a
left join ICSCheck f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--料品表
left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint--源头单据
left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
where f.CheckCode='{0}' and a.WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Noticec = JsonConvert.DeserializeObject(jsonInfo);
return Noticec;
}
return false;
case "其它出库":
bool ischecks = verification.IsOtherOut(JsonData.TransCode, JsonData.WorkPoint);
if (ischecks == true)
{
sqlInfo = @"SELECT
a.[ID],--表头唯一标识
f.OutCode as TransCode ,--源头单据号
--c.ID as DetailID,--表体唯一标识
f.Sequence as TransSequence,--源头单据行号
f.InvCode as InvCode ,--料品编码
b.InvName as InvName,
b.InvStd as InvStd,
a.[Quantity] as Quantity,
b.InvUnit as InvUnit,
f.Amount as Amount,
b.AmountUnit as AmountUnit,
d.ProjectCode as ProjectCode,
d.BatchCode as BatchCode,
d.Version as Version,
d.Brand as Brand,
f.OutQuantity as IssueQuantity,
d.cFree2,
d.cFree3,
d.cFree4,
d.cFree5,
d.cFree6,
d.cFree7,
d.cFree8,
d.cFree9,
d.cFree10
FROM ICSWareHouseLotInfo a
left join ICSOtherOut f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--料品表
left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint--源头单据
where f.OutCode='{0}' and a.WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var OtherOut = JsonConvert.DeserializeObject(jsonInfo);
return OtherOut;
}
return false;
case "拆卸单":
bool isDisassemblyDoc = verification.isBoolDisassemblyDoc(JsonData.TransCode, JsonData.WorkPoint);
if (isDisassemblyDoc == true)
{
sqlInfo = @"SELECT
a.[ID],--表头唯一标识
a.DABDOCCode as TransCode ,--源头单据号
a.Sequence as TransSequence,--源头单据行号
a.Quantity as Quantity,
a.Amount as Amount,
a.InvCode as InvCode ,
a.DABDOCQuantity as IssueQuantity,
b.InvName as InvName,--料品编码
b.InvStd as InvStd,
b.InvUnit as InvUnit,
b.AmountUnit as AmountUnit,
c.ProjectCode as ProjectCode,--自由项
c.BatchCode as BatchCode,
c.Version as Version,
c.Brand as Brand,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10
FROM ICSDisassemblyDoc a
left join ICSInventory b on b.InvCode=a.InvCode
LEFT JOIN ICSExtension c ON a.ExtensionID=c.id and a.WorkPoint=c.WorkPoint--自由项
where a.DABDOCCode='{0}' and a.WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Doc = JsonConvert.DeserializeObject(jsonInfo);
return Doc;
}
return null;
case "两步调入":
sqlInfo = @"SELECT
a.[ID],--表头唯一标识
f.InCode as TransCode ,--源头单据号
--c.ID as DetailID,--表体唯一标识
f.Sequence as TransSequence,--源头单据行号
f.InvCode as InvCode ,--料品编码
b.InvName as InvName,
b.InvStd as InvStd,
a.[Quantity] as Quantity,
b.InvUnit as InvUnit,
f.Amount as Amount,
b.AmountUnit as AmountUnit,
d.ProjectCode as ProjectCode,
d.BatchCode as BatchCode,
d.Version as Version,
d.Brand as Brand,
f.InQuantity as IssueQuantity,
d.cFree2,
d.cFree3,
d.cFree4,
d.cFree5,
d.cFree6,
d.cFree7,
d.cFree8,
d.cFree9,
d.cFree10,
F.WHCode
from ICSWareHouseLotInfo a
left join ICSOtherIn f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--料品表
left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint
where f.InCode='{0}' and f.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var OtherEnter = JsonConvert.DeserializeObject(jsonInfo);
return OtherEnter;
case "两步调出":
sqlInfo = @"SELECT
a.[ID],--表头唯一标识
f.OutCode as TransCode ,--源头单据号
--c.ID as DetailID,--表体唯一标识
f.Sequence as TransSequence,--源头单据行号
f.InvCode as InvCode ,--料品编码
b.InvName as InvName,
b.InvStd as InvStd,
a.[Quantity] as Quantity,
b.InvUnit as InvUnit,
f.Amount as Amount,
b.AmountUnit as AmountUnit,
d.ProjectCode as ProjectCode,
d.BatchCode as BatchCode,
d.Version as Version,
d.Brand as Brand,
f.OutQuantity as IssueQuantity,
d.cFree2,
d.cFree3,
d.cFree4,
d.cFree5,
d.cFree6,
d.cFree7,
d.cFree8,
d.cFree9,
d.cFree10
from ICSWareHouseLotInfo a
left join ICSOtherOut f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--料品表
left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint
where f.OutCode='{0}' and f.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Otheroutr = JsonConvert.DeserializeObject(jsonInfo);
return Otheroutr;
}
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
var model = JsonConvert.DeserializeObject(json);//>
cmd.Transaction.Commit();
return model;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 获取条码信息
///
/// 获取条码信息
///
///
///
public object BarCodeGet(BarCodeModel JsonData)
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
switch (JsonData.TransType)
{
#region 委外退料单
case "委外退料单":
verification.LotoOut(JsonData.Code, JsonData.WorkPoint);
double numLotoInfo = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
verification.HouseLotoOut(JsonData.Code, JsonData.WorkPoint);
if (numLotoInfo == 0.0)
{
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
l.OApplyNegCode as TransCode,--来源单据
l.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
inner join ICSOApplyNegDetail l on l.OApplyNegCode=b.TransCode and l.Sequence=b.TransSequence";
}
else
{
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
'{2}' as a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
l.OApplyNegCode as TransCode,--来源单据
l.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
inner join ICSOApplyNegDetail l on l.OApplyNegCode=b.TransCode and l.Sequence=b.TransSequence";
}
sql += " and a.LotNo='{0}' and a.WorkPoint='{1}' ";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint, numLotoInfo);
table = DBHelper.SQlReturnData(sql, cmd);
string jsonICSMOs = JsonConvert.SerializeObject(table);
var ICSMOa = JsonConvert.DeserializeObject(jsonICSMOs);
return ICSMOa;
#endregion
#region 委外订单
case "委外订单":
verification.LotoOut(JsonData.Code, JsonData.WorkPoint);
double numLoto = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
if (numLoto == 0.0)
{
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
l.OOCode as TransCode,--来源单据
l.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
left join ICSOutsourcingOrder l on l.OOCode=b.TransCode and l.Sequence=b.TransSequence where 1=1";
}
else
{
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
'{2}' as a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
l.OOCode as TransCode,--来源单据
l.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
left join ICSOutsourcingOrder l on l.OOCode=b.TransCode and l.Sequence=b.TransSequence where 1=1";
}
sql += " and a.LotNo='{0}' and a.WorkPoint='{1}' ";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint, numLoto);
table = DBHelper.SQlReturnData(sql, cmd);
string jsonNegReceive = JsonConvert.SerializeObject(table);
var ApplyNegjsonNegReceive = JsonConvert.DeserializeObject(jsonNegReceive);//>
return ApplyNegjsonNegReceive;
#endregion
#region 委外送货单
case "委外送货单 ":
sql += " and c.LotNo='{1}' and a.WorkPoint='{2}' ";
sql = string.Format(sql, TransTypeEnum.ICSODeliveryNotice, JsonData.Code, JsonData.WorkPoint);
break;
#endregion
#region 退料单
case "退料单":
sql = @"
select a.ID,
a.InvCode,
a.Quantity,
d.ProjectCode,
d.BatchCode,
d.Version,
d.Brand,
c.ApplyNegCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
a.LotNo,
d.cFree1,
d.cFree2,
d.cFree3,
d.cFree4,
d.cFree5,
d.cFree6,
d.cFree7,
d.cFree8,
d.cFree9,
d.cFree10
from ICSInventoryLot a
left join ICSInventoryLotDetail b on a.LotNo=b.LotNo
left join ICSMOApplyNegDetail c on c.ApplyNegCode=b.TransCode and c.Sequence=b.TransSequence
left join ICSExtension d on d.ID=a.ExtensionID
where 1=1 and a.LotNo='{1}' and a.WorkPoint='{2}'";
sql = string.Format(sql, TransTypeEnum.ICSMOApplyNegDetail, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
string jsonNeg = JsonConvert.SerializeObject(table);
var ApplyNeg = JsonConvert.DeserializeObject(jsonNeg);//>
cmd.Transaction.Commit();
return ApplyNeg;
#endregion
#region 生产订单
case "生产订单":
//verification.HouseLotInvCode();
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.MOCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSMO C ON B.TransCode=C.MOCode AND C.Sequence=B.TransSequence
LEFT JOIN ICSMOPick D ON C.MODetailID=D.ID
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID WHERE 1=1 ";
sql += " and A.LotNo='{1}' and a.WorkPoint='{2}' ";
sql = string.Format(sql, TransTypeEnum.ICSMO, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
string jsonICSMO = JsonConvert.SerializeObject(table);
var ICSMO = JsonConvert.DeserializeObject(jsonICSMO);//>
cmd.Transaction.Commit();
return ICSMO;
#endregion
case "销售退货":
string type = "退货";
bool veri = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);
if (veri == true)
{
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.SDNCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSSDN C ON a.InvCode=C.InvCode AND C.WorkPoint=a.WorkPoint
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where C.type='2' and A.LotNo='{0}' and A.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
}
break;
case "盘点":
sqlInfo = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
a.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10,
b.LotNo
from ICSWareHouseLotInfo a
left join ICSInventoryLot b on b.LotNo=a.LotNo and a.WorkPoint=b.WorkPoint
left join ICSExtension c on c.ID=B.ExtensionID and c.WorkPoint=b.WorkPoint
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint
left join ICSWareHouseLotInfo h on h.LotNo=a.LotNo and h.WorkPoint=a.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint
left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint where a.LotNo='{0}' and a.WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
string jsonInfo = JsonConvert.SerializeObject(table);
var modelInfo = JsonConvert.DeserializeObject(jsonInfo);//>
cmd.Transaction.Commit();
return modelInfo;
case "盘点单":
sqlInfo = @" SELECT
a.[ID],--表头唯一标识
a.CheckCode as TransCode ,--源头单据号
--c.ID as DetailID,--表体唯一标识
e.TransCode as TransSequence,--源头单据行号
f.InvCode as InvCode ,--料品编码
b.InvName as InvName,
b.InvStd as InvStd,
a.[Quantity] as Quantity,
b.InvUnit as InvUnit,
f.Amount as Amount,
b.AmountUnit as AmountUnit,
d.ProjectCode as ProjectCode,
d.BatchCode as BatchCode,
d.Version as Version,
d.Brand as Brand,
f.ActualQuantity as IssueQuantity,
d.cFree2,
d.cFree3,
d.cFree4,
d.cFree5,
d.cFree6,
d.cFree7,
d.cFree8,
d.cFree9,
d.cFree10,
c.LotNo
FROM ICSCheckDetail a --退货
left join ICSCheck f on f.CheckCode=a.CheckCode and a.WorkPoint=f.WorkPoint
LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--料品表
left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint--源头单据
left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
where f.Status='2' and c.lotno='{0}' and a.WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Noticec = JsonConvert.DeserializeObject(jsonInfo);
return Noticec;
case "采购到货单":
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.POCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSPurchaseOrder C ON b.TransCode=C.POCode AND C.Sequence=B.TransSequence
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where a.lotno='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var NoticecList = JsonConvert.DeserializeObject(jsonInfo);
return NoticecList;
case "采购订单":
bool SDN = verification.SNDetail(JsonData.Code, JsonData.WorkPoint);
bool oorder = verification.PurchaseOrder(JsonData.Code, JsonData.WorkPoint);
if (SDN == true && oorder == true)
{
double unm = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
if (unm == 0.0)
{
///条码数量
sqlInfo = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
j.DNQuantity as Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.POCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSPurchaseOrder C ON B.TransCode=C.POCode AND C.Sequence=B.TransSequence
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
left join ICSASNDetail j on j.lotno=a.lotno
where c.Status='2' and a.lotno='{0}' and a.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Purchase = JsonConvert.DeserializeObject(jsonInfo);
return Purchase;
}
else
{
//检验数量
sqlInfo = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
'{2}' as Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.POCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSPurchaseOrder C ON B.TransCode=C.POCode AND C.Sequence=B.TransSequence
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where c.Status='2' and a.lotno='{0}' and a.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint, unm);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Purchase = JsonConvert.DeserializeObject(jsonInfo);
return Purchase;
}
}
break;
case "一步式调拨单":
bool iSLocationCode = verification.iSLocationCode(JsonData.Code, JsonData.WorkPoint);
if (iSLocationCode == true)
{
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
a.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10,
b.LotNo
from ICSWareHouseLotInfo a
left join ICSInventoryLot b on b.LotNo=a.LotNo and a.WorkPoint=b.WorkPoint
left join ICSExtension c on c.ID=B.ExtensionID and c.WorkPoint=b.WorkPoint
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint
left join ICSWareHouseLotInfo h on h.LotNo=a.LotNo and h.WorkPoint=a.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint
left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint
left join ICSTransfer l on l.TransferNO=t.TransCode and t.TransSequence=l.Sequence
where a.lotno='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var Transfer = JsonConvert.DeserializeObject(jsonInfo);
return Transfer;
}
return null;
case "二部调拨":
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
a.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
a.TransferQuantity as hasQuantity,
a.FromWarehouseCode as fromWHCode,
a.ToWarehouseCode as toWHCode,
b.ProjectCode ,
a.ToLocationCode as binCode,
c.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10,
c.LotNo
from ICSTransfer a
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSContainerLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--条码
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint
where a.Type='2' and c.lotno='{0}' and a.WorkPoint'{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var TOTransfer = JsonConvert.DeserializeObject(jsonInfo);
return TOTransfer;
case "其它入库":
bool BoolOtherIn = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, JsonData.TransType);
if (BoolOtherIn == true)
{
double num = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
if (num == 0.0)
{
///条码数量
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.InCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSOtherIn C ON b.TransCode=C.InCode AND C.Sequence=B.TransSequence
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where a.lotno='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
}
else
{
///检验的数量
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
'{2}' as Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.InCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSOtherIn C ON b.TransCode=C.InCode AND C.Sequence=B.TransSequence
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where a.lotno='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint, num);
table = DBHelper.SQlReturnData(sql, cmd);
}
}
jsonInfo = JsonConvert.SerializeObject(table);
var OtherIn = JsonConvert.DeserializeObject(jsonInfo);
return OtherIn;
case "拆分":
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
d.TransCode as TransCode,--来源单据
d.TransSequence as TransSequence,--来源行号
A.LotNo,
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10
FROM ICSWareHouseLotInfo A
LEFT JOIN ICSInventoryLot B ON A.LotNo =B.LotNo
LEFT JOIN ICSExtension c ON c.ID=b.ExtensionID
left join ICSInventoryLotDetail d on b.LotNo=d.LotNo
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where a.lotno='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
jsonInfo = JsonConvert.SerializeObject(table);
var lotinfo = JsonConvert.DeserializeObject(jsonInfo);
return lotinfo;
case "两部调入":
sqlInfo = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.InCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSOtherIn C ON b.TransCode=C.InCode AND C.Sequence=B.TransSequence
left join ICSTransfer d on d.TransferNO =c.InCode and d.Sequence=c.Sequence
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where a.lotno ='{0}' and a.WorkPoint='{1}' and d.Type='2' ";
sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
if (table.Rows.Count > 0)
{
jsonInfo = JsonConvert.SerializeObject(table);
var loyout = JsonConvert.DeserializeObject(jsonInfo);
return loyout;
}
else
{
throw new Exception("调拨单不存在!");
}
}
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
var model = JsonConvert.DeserializeObject(json);//>
cmd.Transaction.Commit();
return model;
}
catch (Exception ex)
{
//cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 获取条码信息()
/// 入库
///
///
public object BarcodeWarehousing(BarCodeModel JsonData)
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
string type;
try
{
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10,
c.LotNo
from {0} a --委外出库
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--条码
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where 1=1 ";
switch (JsonData.TransType)
{
case "送货单":
verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);//库存条码验证
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
a.LotNo,
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10
from {0} a --送货单
left join ICSInventoryLot b on a.LotNo=b.LotNo and b.WorkPoint=a.WorkPoint--条码
left join ICSExtension c on b.ExtensionID=b.ID and b.WorkPoint=c.WorkPoint
left join ICSInventory d on b.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where 1=1 and a.LotNo='{1}' and a.WorkPoint='{2}' and a.ASNCode='{3}'";
sql = string.Format(sql, TransTypeEnum.ICSASNDetail, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
break;
case "委外送货单子表":
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
a.LotNo,
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10
from {0} a --送货单
left join ICSInventoryLot b on a.LotNo=b.LotNo and b.WorkPoint=a.WorkPoint--条码
left join ICSExtension c on b.ExtensionID=b.ID and b.WorkPoint=c.WorkPoint
left join ICSInventory d on b.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where 1=1 and a.LotNo='{1}' and a.WorkPoint='{2}'and a.OASNCode='{3}'";
sql = string.Format(sql, TransTypeEnum.ICSOASNDetail, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
break;
case "一步式调拨单":
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10,
c.LotNo
from {0} a --委外出库
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--条码
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where 1=1 and type='1' and c.lotno='{1}' and a.TransferNO='{2}'";
sql = string.Format(sql, TransTypeEnum.ICSTransfer, JsonData.Code, JsonData.TransCode);
break;
case "二步式调拨单":
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10,
c.LotNo
from {0} a --委外出库
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--条码
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where 1=1 and type='2' and c.lotno='{1}' and a.TransferNO='{2}' and a.WorkPoint='{3}'";
sql = string.Format(sql, TransTypeEnum.ICSTransfer, JsonData.Code, JsonData.TransCode, JsonData.WorkPoint);
break;
case "委外订单备料表":
type = "委外发料";
bool lotInfo = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);
if (lotInfo == true)
{
verification.Outsourcing(JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
sqlInfo = @"select a.ID,
b.InvCode,
o.InvName,
o.InvStd,
a.Quantity ,
o.InvUnit,
o.AmountUnit,
l.WarehouseCode,
l.WarehouseName,
j.LocationCode,
j.LocationName,
e.ProjectCode,
e.BatchCode,
e.Version,
e.Brand,
c.TransCode,--来源单据
c.TransSequence,--来源行号
a.LotNo,
e.cFree1,
e.cFree2,
e.cFree3,
e.cFree4,
e.cFree5,
e.cFree6,
e.cFree7,
e.cFree8,
e.cFree9,
e.cFree10 ,
b.Type
from ICSWareHouseLotInfo a
left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
left join ICSExtension e on e.id=b.ExtensionID
left join ICSContainerLot f on f.LotNo=b.LotNo
left join ICSContainer g on g.ContainerID=f.id
left join ICSLocation j on j.LocationCode=a.LocationCode
left join ICSWarehouse L ON L.ID=J.WHID
left join ICSInventory o on o.InvCode=b.InvCode
where a.LotNo='{0}' and a.WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
}
string jsonInfoT = JsonConvert.SerializeObject(table);
var PickT = JsonConvert.DeserializeObject(jsonInfoT); //>
cmd.Transaction.Commit();
return PickT;
case "委外领料申请单":
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10,
c.LotNo
from {0} a --委外出库
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--条码
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where c.LotNo='{1}' and a.WorkPoint='{2}' and a.OODetailID='{3}'";
sql = string.Format(sql, TransTypeEnum.ICSMOApply, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
break;
case "销售发货":
type = "发货";
bool LotInfo = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);
if (LotInfo == true)
{
sql = @"select
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
a.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10
from ICSInventoryLot a
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=a.LotNo and h.WorkPoint=a.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint--关联表
where 1=1";
sql += " and a.LotNo='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
if (table.Rows.Count <= 0)
{
throw new Exception("条码不存在!");
}
string jsonInfoInve = JsonConvert.SerializeObject(table);
var Inve = JsonConvert.DeserializeObject(jsonInfoInve); //>
cmd.Transaction.Commit();
return Inve;
}
break;
case "生产订单备料表":
type = "生产订单备料表";
bool nu = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);//库存条码验证
verification.HouseLotInvCode(JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
sqlInfo = @"select a.ID,
b.InvCode,
o.InvName,
o.InvStd,
a.Quantity ,
o.InvUnit,
o.AmountUnit,
l.WarehouseCode,
l.WarehouseName,
j.LocationCode,
j.LocationName,
e.ProjectCode,
e.BatchCode,
e.Version,
e.Brand,
c.TransCode,--来源单据
c.TransSequence,--来源行号
a.LotNo,
e.cFree1,
e.cFree2,
e.cFree3,
e.cFree4,
e.cFree5,
e.cFree6,
e.cFree7,
e.cFree8,
e.cFree9,
e.cFree10
from ICSWareHouseLotInfo a
left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
left join ICSExtension e on e.id=b.ExtensionID
left join ICSContainerLot f on f.LotNo=b.LotNo
left join ICSContainer g on g.ContainerID=f.id
left join ICSLocation j on j.LocationCode=a.LocationCode
left join ICSWarehouse L ON L.ID=J.WHID
left join ICSInventory o on o.InvCode=b.InvCode where a.LotNo='{0}' and a.WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
string jsonInfo = JsonConvert.SerializeObject(table);
var Pick = JsonConvert.DeserializeObject(jsonInfo); //>
cmd.Transaction.Commit();
return Pick;
case "委外材料出库":
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10,
c.LotNo
from {0} a --委外出库
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--条码
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where 1=1 and c.LotNo='{1}' and a.Status='2' and a.IssueCode='{2}'and a.WorkPoint='{3}'";
sql = string.Format(sql, TransTypeEnum.ICSOIssue, JsonData.Code, JsonData.TransCode, JsonData.WorkPoint);
break;
case "杂发单":
sql = @"select
a.ID,
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
h.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
c.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10,
c.LotNo
from {0} a --委外出库
left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--条码
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--关联表
where 1=1 and c.LotNo='{1}' and a.Status='2' and a.OutCode='{2}' and a.WorkPoint='{3}'";
sql = string.Format(sql, TransTypeEnum.ICSOtherOut, JsonData.Code, JsonData.TransCode, JsonData.WorkPoint);
break;
case "采购退货单":
sql = @"select a.ID,
b.InvCode,
o.InvName,
o.InvStd,
a.Quantity ,
o.InvUnit,
o.AmountUnit,
l.WarehouseCode,
l.WarehouseName,
j.LocationCode,
j.LocationName,
e.ProjectCode,
e.BatchCode,
e.Version,
e.Brand,
c.TransCode,--来源单据
c.TransSequence,--来源行号
a.LotNo,
e.cFree1,
e.cFree2,
e.cFree3,
e.cFree4,
e.cFree5,
e.cFree6,
e.cFree7,
e.cFree8,
e.cFree9,
e.cFree10
from ICSWareHouseLotInfo a
left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
left join ICSExtension e on e.id=b.ExtensionID
left join ICSContainerLot f on f.LotNo=b.LotNo
left join ICSContainer g on g.ContainerID=f.id
left join ICSLocation j on j.LocationCode=a.LocationCode
left join ICSWarehouse L ON L.ID=J.WHID
left join ICSInventory o on o.InvCode=b.InvCode where a.LotNo='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
string jsonNotice = JsonConvert.SerializeObject(table);
var PickNotice = JsonConvert.DeserializeObject(jsonNotice); //>
cmd.Transaction.Commit();
return PickNotice;
case "两部调出":
sql = @"select
a.ID,
H.ContainerCODE,
H.ContainerName,
A.InvCode,
F.InvName,
F.InvStd,
a.Quantity,
F.InvUnit,
F.AmountUnit,
E.ProjectCode,
E.BatchCode,
E.Version,
E.Brand,
c.OutCode as TransCode,--来源单据
c.Sequence as TransSequence,--来源行号
A.LotNo,
E.cFree1,
E.cFree2,
E.cFree3,
E.cFree4,
E.cFree5,
E.cFree6,
E.cFree7,
E.cFree8,
E.cFree9,
E.cFree10
FROM ICSInventoryLot A
LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
LEFT JOIN ICSOtherOut C ON b.TransCode=C.OutCode AND C.Sequence=B.TransSequence
left join ICSTransfer d on d.TransferNO =c.OutCode and d.Sequence=c.Sequence
LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
where a.lotno ='{0}' and a.WorkPoint='{1}' and d.Type='2'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
if (table.Rows.Count > 0)
{
string jsonCode = JsonConvert.SerializeObject(table);
var modelCode = JsonConvert.DeserializeObject(jsonCode);
return modelCode;
}
else
{
throw new Exception("调拨单不存在!");
}
case "委外退货单":
sql = @"select a.ID,
b.InvCode,
o.InvName,
o.InvStd,
a.Quantity ,
o.InvUnit,
o.AmountUnit,
l.WarehouseCode,
l.WarehouseName,
j.LocationCode,
j.LocationName,
e.ProjectCode,
e.BatchCode,
e.Version,
e.Brand,
c.TransCode,--来源单据
c.TransSequence,--来源行号
a.LotNo,
e.cFree1,
e.cFree2,
e.cFree3,
e.cFree4,
e.cFree5,
e.cFree6,
e.cFree7,
e.cFree8,
e.cFree9,
e.cFree10
from ICSWareHouseLotInfo a
left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
left join ICSExtension e on e.id=b.ExtensionID
left join ICSContainerLot f on f.LotNo=b.LotNo
left join ICSContainer g on g.ContainerID=f.id
left join ICSLocation j on j.LocationCode=a.LocationCode
left join ICSWarehouse L ON L.ID=J.WHID
left join ICSInventory o on o.InvCode=b.InvCode where a.LotNo='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
string jsonOrder = JsonConvert.SerializeObject(table);
var PickOrder = JsonConvert.DeserializeObject(jsonOrder); //>
cmd.Transaction.Commit();
return PickOrder;
case "其它出库":
bool Zero = verification.isStockZero(JsonData.Code, JsonData.WorkPoint);
if (Zero == true)
{
bool ZeroCode = verification.iSNullLocationCode(JsonData.Code, JsonData.WorkPoint);
if (ZeroCode == true)
{
sql = @"select
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
a.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
b.ProjectCode,
b.BatchCode,
b.Version,
b.Brand,
t.TransCode,--来源单据
t.TransSequence,--来源行号
a.LotNo,
b.cFree1,
b.cFree2,
b.cFree3,
b.cFree4,
b.cFree5,
b.cFree6,
b.cFree7,
b.cFree8,
b.cFree9,
b.cFree10
from ICSWareHouseLotInfo a
left join ICSInventoryLot h on a.LotNo=h.LotNo
left join ICSExtension b on h.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--料品表
left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint--包装关联表
left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--包装
left join ICSLocation q on q.LocationCode=a.LocationCode and q.WorkPoint=a.WorkPoint
left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint--仓库
left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint--关联表
where a.lotno='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
string jsonCode = JsonConvert.SerializeObject(table);
var modelCode = JsonConvert.DeserializeObject(jsonCode);
return modelCode;
}
}
break;
}
sql = string.Format(sql, JsonData.Code);
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
var model = JsonConvert.DeserializeObject(json); //>
cmd.Transaction.Commit();
return model;
}
catch (Exception ex)
{
// cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 上架
///
/// 上架查询
///
///
public object LOTStockUpGet(WMSTBarCodeModel JsonData)
{
//WMSTBarCodeModelInfo model = new WMSTBarCodeModelInfo();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
sql = @"SELECT
b.ID,
b.InvCode,
b.Quantity,
b.AmountRate,
a.TransCode,
a.TransSequence,
a.LotNo,
d.WarehouseCode,
d.WarehouseName,
e.LocationCode,
e.LocationName,
b.Type,
a.MUSER,
a.MTIME
from ICSInventoryLotDetail a
left join ICSInventoryLot b on a.LotNo=b.LotNo
left join ICSWareHouseLotInfo c on a.LotNo=c.LotNo
left join ICSWarehouse d on d.WarehouseCode=c.WarehouseCode
left join ICSLocation e on e.LocationCode=c.LocationCode where 1=1";
if (!string.IsNullOrEmpty(JsonData.TransCode))
{
sql += " and a.TransCode='{0}'";
sql = string.Format(sql, JsonData.TransCode);
}
if (!string.IsNullOrEmpty(JsonData.User))
{
sql += " and MUSER='{1}'";
sql = string.Format(sql, JsonData.User);
}
if (JsonData.MTime.ToString() != "0001/1/1 0:00:00")
{
sql += " and MTIME='{2}'";
sql = string.Format(sql, JsonData.MTime);
}
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
var model = JsonConvert.DeserializeObject(json);
//model = JsonConvert.DeserializeObject(json);//>
cmd.Transaction.Commit();
return model;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 上架增加
/// BusinessCode,TransType 两个类型
///
///
public List LOTStockCreate(List JsonData)
{
List model = new List();
List mddelInfo = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num = 0;
int numInfo = 0;
DataTable tableInfo = null;
string sqlERP = string.Empty;//ERP的表头
string sqlERPDetil = string.Empty;//ERP的表体
string jsonERP = string.Empty;///erpjson
string IstrErp = string.Empty;
string iresult = string.Empty;//接口调用
try
{
foreach (var item in JsonData)
{
foreach (var itemInfo in item.detail)
{
int i = 1;
switch (item.TransType)
{
case "委外退料单":
// string neg = verification.HouseLotoOut(itemInfo.LotNo, item.WorkPoint);
//if (neg == null)
//{
string numNegDetaill = @"select * from ICSOApplyNegDetail where OApplyNegCode='{0}'and Sequence='{1}' and WorkPoint='{2}' ";
numNegDetaill = string.Format(numNegDetaill, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
DataTable numNegDetailwl = DBHelper.SQlReturnData(numNegDetaill, cmd);
foreach (DataRow itemDetail in numNegDetailwl.Rows)
{
double Quantity = Convert.ToDouble(itemInfo.Quantity);///输入数量
double IssueNegQuantity = Convert.ToDouble(itemDetail["IssueNegQuantity"]);//已退数量
double NegQuantity = Quantity + IssueNegQuantity;//总数量(输入数量+已退数量)
double QuantityPla = Convert.ToDouble(itemDetail["Quantity"]);//计划数量
if (QuantityPla >= NegQuantity)
{
string NegDetailSql = @"update ICSOApplyNegDetail set IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{3}'
, MUSER='{4}' ,MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{2}'), MTIME=GETDATE()
where OApplyNegCode='{0}' and Sequence='{1}' and WorkPoint='{2}' ";
NegDetailSql = string.Format(NegDetailSql, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, itemInfo.Quantity, item.User);
if (!DBHelper.ExecuteNonQuery(NegDetailSql, cmd))
{
throw new Exception("委外退料单更新失败!");
}
///添加库存
string HouseLotSql = @" insert into ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
(select newid(),'{0}' ,a.WHCode,isnull((f.LocationCode),0) ,b.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{4}' ,'{5}' ,' '
from ICSOApplyNeg a --委外退料申请单
inner join ICSOApplyNegDetail b on a.OApplyNegCode=b.OApplyNegCode and a.WorkPoint=b.WorkPoint --委外退料申请单详情
left join ICSInventoryLotDetail c on b.OApplyNegCode=c.TransCode and c.TransSequence=b.Sequence AND b.WorkPoint=c.WorkPoint--条码关联
left join ICSInventoryLot d on c.LOTNO=d.LotNO and d.WorkPoint=c.WorkPoint --条码
left join ICSWarehouse e on e.WarehouseCode=a.WHCode and e.WorkPoint=a.WorkPoint--仓库
left join ICSLocation f on f.WHID=e.ID and f.WorkPoint=e.WorkPoint--库位
left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{5}' --用户
where a.OApplyNegCode='{6}' and a. WorkPoint='{5}')";
HouseLotSql = string.Format(HouseLotSql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
if (!DBHelper.ExecuteNonQuery(HouseLotSql, cmd))
{
throw new Exception("委外退料单库存更新失败!");
}
///添加日志
string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{0}','{1}','{2}',b.InvCode ,' ', ' ',a.WHCode,d.LocationCode,'{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
from ICSOApplyNeg a--主表
inner join ICSOApplyNegDetail b on a.OApplyNegCode=b.OApplyNegCode --明细
left join ICSWarehouse c on c.WarehouseCode=a.WHCode and c.WorkPoint=a.WorkPoint--仓库
left join ICSLocation d on d.WHID=c.ID and d.WorkPoint=c.WorkPoint--库位
left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
where a.OApplyNegCode='{0}' and a. WorkPoint='{6}')";
sqlLogInfo = string.Format(sqlLogInfo, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint);
cmd.CommandText = sqlLogInfo;
int numInfoLot = cmd.ExecuteNonQuery();
if (numInfoLot > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
throw new Exception("已退数量不能大于计划数量!");
}
}
#region ERP
string sqlERPOOPick = @" select DepCode,FromWarehouseCode,OOCode,a.MUSER , (getdate())as Mtime from ICSWareHouseLotInfoLog a
left join ICSOutsourcingOrder b on b.OOCode=a.TransCode and a.TransSequence=b.Sequence
left join ICSOOPick c on b.OODetailID=c.OODetailID
where OOCode='{0}' and b.WorkPoint='{1}'
group by DepCode,FromWarehouseCode,OOCode,a.MUSER ";
sqlERPOOPick = string.Format(sqlERPOOPick, itemInfo.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sqlERPOOPick, cmd);
string sqlERPPickList = @"select a.TransCode, a.TransSequence,a.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount,c.PickID from ICSWareHouseLotInfoLog a
left JOIN ICSOutsourcingOrder B on b.OOCode=a.TransCode and a.TransSequence=b.Sequence
left join ICSOOPick C on C.OODetailID=B.OODetailID and c.Sequence=a.TransSequence
where lotno='{0}' and a.Memo<>'1'
group by a.TransCode, a.TransSequence,a.InvCode,b.Amount ,c.PickID ";
sqlERPPickList = string.Format(sqlERPPickList, itemInfo.LotNo);
DataTable ERPOOPick = DBHelper.SQlReturnData(sqlERPPickList, cmd);
string jsonPickList = null;
List docPickmodel = new List();
foreach (DataRow dts in table.Rows)
{
IssueDoc doc = new IssueDoc();
doc.DepCode = dts["DepCode"].ToString();
doc.WHCode = dts["FromWarehouseCode"].ToString();
doc.SourceType = "委外退料";
doc.SourceCode = dts["OOCode"].ToString();
doc.User = dts["MUSER"].ToString();
doc.User = dts["Mtime"].ToString();
// doc.MTime = DateTime.Now;
List list = new List();
foreach (DataRow dtList in ERPOOPick.Rows)
{
IssueDocList docc = new IssueDocList();
docc.Sequence = dtList["TransSequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.SourceDetailID = dtList["PickID"].ToString();
list.Add(docc);
}
doc.details = list;
docPickmodel.Add(doc);
//jsonList = JsonConvert.SerializeObject(doc);
}
string IstrPick = JsonConvert.SerializeObject(docPickmodel);
string iresultPick = HttpPost("委外退料", ERPUrl.OutsourcingIssueDoNegativeURL, IstrPick);
Result OtherOutResultpick = new Result();
OtherOutResultpick = JsonConvert.DeserializeObject(iresultPick);
ERPJsonRetun m = new ERPJsonRetun();
if (OtherOutResultpick.Success == true)
{
string nn = OtherOutResultpick.Data.ToString();//LOTStockModel
m = JsonConvert.DeserializeObject(nn);
string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
where TransCode='{4}' and TransSequence ='{5}'";
ERPupdate = string.Format(ERPupdate, m.ID, m.DetailID, m.RCVNEGCode, m.Sequence, itemInfo.TransCode, itemInfo.TransSequence);
cmd.CommandText = ERPupdate;
num = cmd.ExecuteNonQuery();
if (num > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
cmd.Transaction.Rollback();
throw new Exception(OtherOutResultpick.Message);
}
#endregion
//}
return null;
case "采购入库":
//添加采购入库
sql = @"update ICSPurchaseOrder set RCVQuantity= RCVQuantity+(select Quantity from ICSInventoryLot where lontno='{0}' ,MTIME='{1}' where RCVCod='{2}' and InvCode=(select InvCode from ICSInventoryLot where lontno='{0}' ),and WorkPoint='{3}')";
sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
cmd.CommandText = sql;
int Purchase = cmd.ExecuteNonQuery();
cmd.Transaction.Commit();
//记录日志
if (Purchase > 0)
{
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{4}'
,''
,'{0}'
,(SELECT InvCode FROM ICSMO WHERE MOCode='{5}')
,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,''
,''
,(SELECT Quantity FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,''
,''
,'1'
,''
,''
,''
,''
,''
,'{1}'
,'{1}'
,'{2}'
,'{3}'
,'')";
sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
cmd.Transaction.Commit();
}
//生产erp订单
return null;
case "销售退货":
string Date = DateTime.Now.ToString("yy");
string Pre = "CHK" + i + Date;//库存盘点单号
#region 添加到库存表/日志表
///验证条码是否存在或者是否上架
sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (table.Rows.Count <= 0)
{
throw new Exception("条码不存在!");
}
string sqlll = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
sqlll = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlll;
DataTable dataTex = DBHelper.SQlReturnData(sqlll, cmd);//返回条数
if (dataTex.Rows.Count <= 0)
{
throw new Exception("条码已上架!");
}
sqlInfo = @"select * from ICSSDN where SDNCode='{0}' and Status='3' and Type='2'";
sqlInfo = string.Format(sqlInfo, itemInfo.TransCode);
cmd.CommandText = sqlInfo;
tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (tableInfo.Rows.Count > 0)
{
throw new Exception("销售订单已经关闭!或退货不存在");
}
else
{
sql = @"update ICSSDN set SDNQuantity= SDNQuantity + Quantity ,MTIME='{1}' where SDNCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint, itemInfo.Quantity);
cmd.CommandText = sql;
int ApplyNeg = cmd.ExecuteNonQuery();
// cmd.Transaction.Commit();
string sqlLotInfo = @" INSERT INTO[ICSWareHouseLotInfo]
([ID]
,[LotNo]
,[WarehouseCode]
,[LocationCode]
,[InvCode]
,[Quantity]
,[InDate]
,[LockQuantity]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
, '{0}'
, (select WarehouseCode from ICSWarehouse a left join ICSLocation b on a.ID = b.WHID WHERE LocationCode = '{1}')
,'{1}'
,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo = '{0}')
,'{6}'
,'{5}'
,0
,'{2}'
,'{2}'
,'{3}'
,'{4}'
,'')";
sqlLotInfo = string.Format(sqlLotInfo, itemInfo.LotNo, itemInfo.LocationCode, item.User, DateTime.Now, item.WorkPoint, item.MTime, itemInfo.Quantity);
DBHelper.CmdExecuteNonQuery(sqlLotInfo, cmd, "成功");
//cmd.Transaction.Commit();
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{4}'
,' '
,'{0}'
,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,''
,''
,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
,''
,''
,'21'
,''
,''
,''
,''
,''
,'{1}'
,'{1}'
,'{2}'
,'{3}'
,'')";
sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
cmd.Transaction.Commit();
#region ERP接口
string ERPSnd = @"select A.CusCode,A.SOCode ,B.MUSER,MAX(B.MTIME) AS MTIME,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode FROM ICSSDN a
inner join ICSWareHouseLotInfoLog b on a.SDNCode=b.TransCode and b.TransSequence=a.Sequence
where a.Type='2' and b.TransCode='{0}' and b.WorkPoint='{1}'
group by A.CusCode,A.SOCode ,B.MUSER,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode";
ERPSnd = string.Format(ERPSnd, itemInfo.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(ERPSnd, cmd);
string ERPSndList = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount ,b.SDNDetailID from ICSWareHouseLotInfoLog a
inner JOIN ICSSDN B ON b.SDNCode=a.TransCode and a.TransSequence=b.Sequence
where a.LotNo='{0}' and a.Memo<>'1' and b.WorkPoint='{1}' and b.Type='2'
group by a.TransSequence,b.InvCode, Amount ,b.SDNDetailID";
ERPSndList = string.Format(ERPSndList, itemInfo.LotNo, item.WorkPoint);
DataTable SDNNEG = DBHelper.SQlReturnData(ERPSndList, cmd);
List ERPSDNNEG = new List();
foreach (DataRow itemNotice in table.Rows)
{
ERPICSSDN noticeModel = new ERPICSSDN();
noticeModel.CusCode = itemNotice["CusCode"].ToString();
noticeModel.WHCode = itemNotice["FromWarehouseCode"].ToString();
noticeModel.SDNRTCode = itemNotice["SOCode"].ToString();
noticeModel.User = itemNotice["MUSER"].ToString();
noticeModel.MTime = itemNotice["MTIME"].ToString();
List noticeModelList = new List();
foreach (DataRow ERPNoticeList in SDNNEG.Rows)
{
ERPICSSDNList listInfo = new ERPICSSDNList();
listInfo.Sequence = ERPNoticeList["TransSequence"].ToString();
listInfo.InvCode = ERPNoticeList["InvCode"].ToString();
listInfo.Quantity = ERPNoticeList["Quantity"].ToString();
listInfo.Amount = ERPNoticeList["Amount"].ToString();
listInfo.SDNDetailID = ERPNoticeList["SDNDetailID"].ToString();
noticeModelList.Add(listInfo);
}
noticeModel.details = noticeModelList;
ERPSDNNEG.Add(noticeModel);
string ERPICSSDN = JsonConvert.SerializeObject(ERPSDNNEG);
string Emoiresultsdn = HttpPost("红字销售出库单", ERPUrl.SalesDeliveryNoticeURL, ERPICSSDN);
Result OtherOutI = new Result();
OtherOutI = JsonConvert.DeserializeObject(Emoiresultsdn);
if (OtherOutI.Message != "200")
{
throw new Exception(OtherOutI.Message);
}
else
{
//OtherOutResult.Data;
}
}
#endregion
}
#endregion
return null;
case "生产退库":
#region 添加到库存表/日志表
sqlInfo = @"select * from ICSLocation where LocationCode='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LocationCode);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);
if (table.Rows.Count <= 0)
{
throw new Exception("库位不存在!");
}
///验证条码是否存在或者是否上架
sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (table.Rows.Count <= 0)
{
throw new Exception("条码不存在!");
}
sqlInfo = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (tableInfo.Rows.Count > 0)
{
throw new Exception("条码已经上架!");
}
else
{
sql = @"update ICSMOApplyNegDetail set IssueNegQuantity= IssueNegQuantity + (select Quantity from ICSInventoryLot where lotno='{0}' ) ,MTIME='{1}' where ApplyNegCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
cmd.CommandText = sql;
int ApplyNeg = cmd.ExecuteNonQuery();
sql = @" INSERT INTO [ICSWareHouseLotInfo]
([ID]
,[LotNo]
,[WarehouseCode]
,[LocationCode]
,[InvCode]
,[Quantity]
,[InDate]
,[LockQuantity]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{0}'
,(select WarehouseCode from ICSWarehouse a left join ICSLocation b on a.ID =b.WHID WHERE LocationCode='{1}')
,'{1}'
,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
,'{5}'
,0
,'{2}'
,'{2}'
,'{3}'
,'{4}'
,'')";
sql = string.Format(sql, itemInfo.LotNo, itemInfo.LocationCode, item.User, item.MTime, item.WorkPoint, DateTime.Now);
cmd.CommandText = sql;
numInfo = cmd.ExecuteNonQuery();
//cmd.Transaction.Commit();
if (numInfo > 0)
{
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{4}'
,' '
,'{0}'
,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,''
,''
,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
,''
,''
,'21'
,''
,''
,''
,''
,''
,'{1}'
,'{1}'
,'{2}'
,'{3}'
,'')";
sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
cmd.Transaction.Commit();
}
}
#endregion
return null;
case "采购订单":
///验证订单是否关闭
string sqlTYPE = @"SELECT * FROM ICSPurchaseOrder WHERE POCode='{0}' AND WorkPoint='{1}' AND Status='3'";
sqlTYPE = string.Format(sqlTYPE, itemInfo.TransCode, item.WorkPoint);
DataTable dtType = DBHelper.SQlReturnData(sqlTYPE, cmd);
if (dtType.Rows.Count <= 0)
{
#region 添加到库存表/日志表
sqlInfo = @"select * from ICSLocation where LocationCode='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LocationCode);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);
if (table.Rows.Count <= 0)
{
throw new Exception("库位不存在!");
}
///验证条码是否存在或者是否上架
sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (table.Rows.Count <= 0)
{
throw new Exception("条码不存在!");
}
sqlInfo = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (tableInfo.Rows.Count > 0)
{
throw new Exception("条码已经上架!");
}
else
{
sql = @"update ICSPurchaseOrder set InQuantity= InQuantity + (select Quantity from ICSInventoryLot where lotno='{0}' ) ,MTIME='{1}' where POCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
cmd.CommandText = sql;
int PurchaseList = cmd.ExecuteNonQuery();
if (PurchaseList > 0)
{
sql = @" INSERT INTO [ICSWareHouseLotInfo]
([ID]
,[LotNo]
,[WarehouseCode]
,[LocationCode]
,[InvCode]
,[Quantity]
,[InDate]
,[LockQuantity]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{0}' ,e.WarehouseCode,isnull((f.LocationCode),0) ,a.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{4}' ,'{5}' ,' '
from ICSPurchaseOrder a
left join ICSLocation f on LocationCode='{8}'
left join ICSWarehouse e on e.id=(select WHID from ICSLocation where LocationCode='{8}')
left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{5}' --用户
where a.POCode='{6}' and a. WorkPoint='{5}' and a.Sequence='{7}')";
sql = string.Format(sql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LocationCode);
cmd.CommandText = sql;
numInfo = cmd.ExecuteNonQuery();
if (numInfo > 0)
{
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',c.WarehouseCode,'{7}','{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
from ICSPurchaseOrder a--主表
left join ICSWarehouse c on c.id=(select WHID from ICSLocation where LocationCode='{7}')
left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
where a.POCode='{0}' and a. WorkPoint='{6}')";
sqlLog = string.Format(sqlLog, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint, itemInfo.LocationCode);
cmd.CommandText = sqlLog;
numInfo = cmd.ExecuteNonQuery();
}
}
else
{
throw new Exception("数量不足!");
}
}
#endregion
#region ERP
sqlERP = @" select VenCode,POCode, ToWarehouseCode,a.MUSER,b.Sequence ,(getdate())as Mtime from ICSWareHouseLotInfoLog a
left join ICSPurchaseOrder b on a.TransCode=b.POCode and b.Sequence =a.transSequence
where b.POCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
group by VenCode,POCode, ToWarehouseCode,a.MUSER,b.Sequence ";
sqlERP = string.Format(sqlERP, itemInfo.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sqlERP, cmd);
sqlERPDetil = @"select b.Sequence,a.InvCode,sum (a.Quantity) as Quantity,isnull((b.Amount),0) as Amount,b.UnitPrice,b.Currency,b.PODetailID from ICSWareHouseLotInfoLog a
inner join ICSPurchaseOrder b on a.TransCode=b.POCode and b.Sequence =a.transSequence
where b.POCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
group by b.Sequence,a.InvCode,b.Amount,b.UnitPrice,b.Currency,b.PODetailID";
sqlERPDetil = string.Format(sqlERPDetil, itemInfo.TransCode, item.WorkPoint);
DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
List docmodel = new List();
foreach (DataRow dtIn in table.Rows)
{
ERPPurchaseOrder doc = new ERPPurchaseOrder();
doc.VenCode = dtIn["VenCode"].ToString();
doc.POCode = dtIn["POCode"].ToString();
doc.User = dtIn["MUSER"].ToString();
doc.MTime = dtIn["Mtime"].ToString();
doc.WHCode = dtIn["ToWarehouseCode"].ToString();
doc.DNCode = "";
List list = new List();
foreach (DataRow dtList in ERPtable.Rows)
{
ERPPurchaseOrderList docc = new ERPPurchaseOrderList();
docc.Sequence = dtList["Sequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.Currency = dtList["Currency"].ToString();
docc.UnitPrice = dtList["UnitPrice"].ToString();
docc.PODetailID = dtList["PODetailID"].ToString();
docc.DNDetailID = "";
list.Add(docc);
}
doc.details = list;
docmodel.Add(doc);
}
IstrErp = JsonConvert.SerializeObject(docmodel);
iresult = HttpPost("采购订单", ERPUrl.PurchaseOrderURL, IstrErp);
Result OtherOutResult = new Result();
OtherOutResult = JsonConvert.DeserializeObject(iresult);
List mm = new List();//json返回
if (OtherOutResult.Success == true)
{
string nn = OtherOutResult.Data.ToString();//LOTStockModel
mm = JsonConvert.DeserializeObject>(nn);
foreach (var items in mm)
{
string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',memo='1'
where TransCode='{4}' and TransSequence ='{5}'";
ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVTCode, items.Sequence, itemInfo.TransCode, itemInfo.TransSequence);
cmd.CommandText = ERPupdate;
numInfo = cmd.ExecuteNonQuery();
}
if (numInfo > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
cmd.Transaction.Rollback();
throw new Exception(OtherOutResult.Message);
}
#endregion
}
else
{
throw new Exception("采购订单已经关闭!");
}
return null;
case "成品入库":
#region 添加到库存表/日志表
sqlInfo = @"select * from ICSLocation where LocationCode='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LocationCode);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);
if (table.Rows.Count <= 0)
{
throw new Exception("库位不存在!");
}
///验证条码是否存在或者是否上架
sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (table.Rows.Count <= 0)
{
throw new Exception("条码不存在!");
}
sqlInfo = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (tableInfo.Rows.Count > 0)
{
throw new Exception("条码已经上架!");
}
else
{
sql = @"update ICSMO set RCVQuantity= RCVQuantity + (select Quantity from ICSInventoryLot where lotno='{0}' ) ,MTIME='{1}' where MOCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
cmd.CommandText = sql;
int ApplyNeg = cmd.ExecuteNonQuery();
sql = @" INSERT INTO [ICSWareHouseLotInfo]
([ID]
,[LotNo]
,[WarehouseCode]
,[LocationCode]
,[InvCode]
,[Quantity]
,[InDate]
,[LockQuantity]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{0}'
,(select WarehouseCode from ICSWarehouse a left join ICSLocation b on a.ID =b.WHID WHERE LocationCode='{1}')
,'{1}'
,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
,'{5}'
,0
,'{2}'
,'{2}'
,'{3}'
,'{4}'
,'')";
sql = string.Format(sql, itemInfo.LotNo, itemInfo.LocationCode, item.User, item.MTime, item.WorkPoint, DateTime.Now);
cmd.CommandText = sql;
numInfo = cmd.ExecuteNonQuery();
//cmd.Transaction.Commit();
if (numInfo > 0)
{
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{4}'
,' '
,'{0}'
,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,''
,''
,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
,''
,''
,'21'
,''
,''
,''
,''
,''
,'{1}'
,'{1}'
,'{2}'
,'{3}'
,'')";
sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
cmd.Transaction.Commit();
}
}
#endregion
return null;
case "委外订单"://(委外入库)
verification.HouseLotoOut(itemInfo.LotNo, item.WorkPoint);
string numNegDetail = @"select isnull((InQuantity),0) as InQuantity , Quantity from ICSOutsourcingOrder where OOCode='{0}'and Sequence='{1}' and WorkPoint='{2}' and Status <> '3' ";
numNegDetail = string.Format(numNegDetail, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
DataTable dataDetail = DBHelper.SQlReturnData(numNegDetail, cmd);
if (dataDetail.Rows.Count < 0)
{
throw new Exception("订单已关闭!");
}
else
{
foreach (DataRow itemDetail in dataDetail.Rows)
{
double Quantity = Convert.ToDouble(itemInfo.Quantity);///输入数量
double IssueNegQuantity = Convert.ToDouble(itemDetail["InQuantity"]);//已退数量
double NegQuantity = Quantity + IssueNegQuantity;//总数量(输入数量+已退数量)
double QuantityPla = Convert.ToDouble(itemDetail["Quantity"]);//计划数量
if (QuantityPla >= NegQuantity)
{
string NegDetailSql = @"update ICSOutsourcingOrder set Quantity=(select sum(Quantity) from ICSOutsourcingOrder where OOCode='{0}' and Sequence='{1}' and WorkPoint='{2}') +'{3}'
, MUSER='{4}' ,MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{2}'), MTIME='{5}'
where OOCode='{0}' and Sequence='{1}' and WorkPoint='{2}' ";
NegDetailSql = string.Format(NegDetailSql, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, itemInfo.Quantity, item.User, DateTime.Now);
cmd.CommandText = NegDetailSql;
numInfo = cmd.ExecuteNonQuery();
///添加库存
string HouseLotSql = @"
insert into ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
(select newid(),'{0}' ,e.WarehouseCode,isnull((d.LocationCode),0) as LocationCode ,a.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{2}' ,'{4}' ,' '
from ICSOutsourcingOrder a --委外退料申请单
left join ICSLocation d on d.LocationCode='{6}'
left join ICSWarehouse e on e.id=(select WHID from ICSLocation where LocationCode='{6}')
left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{4}' --用户
where a.OOCode='{5}' and a. WorkPoint='{4}')";
HouseLotSql = string.Format(HouseLotSql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, item.WorkPoint, itemInfo.TransCode, itemInfo.LocationCode);
cmd.CommandText = HouseLotSql;
num = cmd.ExecuteNonQuery();
///添加日志
string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',b.WarehouseCode,'{7}','{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
from ICSOutsourcingOrder a--主表
left join ICSWarehouse b on b.id=(select WHID from ICSLocation where LocationCode='{7}')
left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
where a.OOCode='{0}' and a. WorkPoint='{6}')";
sqlLogInfo = string.Format(sqlLogInfo, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint, itemInfo.LocationCode);
cmd.CommandText = sqlLogInfo;
int numInfoLot = cmd.ExecuteNonQuery();
#region ERP
sqlERP = @" select VenCode,OOCode, ToWarehouseCode,a.MUSER,b.Sequence ,(getdate())as Mtime from ICSWareHouseLotInfoLog a
left join ICSOutsourcingOrder b on a.TransCode=b.OOCode and b.Sequence =a.transSequence
where b.OOCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
group by VenCode,OOCode, ToWarehouseCode,a.MUSER,b.Sequence ";
sqlERP = string.Format(sqlERP, itemInfo.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sqlERP, cmd);
sqlERPDetil = @"select b.Sequence,a.InvCode,sum (a.Quantity) as Quantity,isnull((b.Amount),0) as Amount,isnull((b.UnitPrice),0) as UnitPrice,b.Currency,b.OODetailID from ICSWareHouseLotInfoLog a
inner join ICSOutsourcingOrder b on a.TransCode=b.OOCode and b.Sequence =a.transSequence
where b.OOCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
group by b.Sequence,a.InvCode,b.Amount,b.UnitPrice,b.Currency,b.OODetailID";
sqlERPDetil = string.Format(sqlERPDetil, itemInfo.TransCode, item.WorkPoint);
DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
List docmodel = new List();
foreach (DataRow dtIn in table.Rows)
{
ERPPurchaseOrder doc = new ERPPurchaseOrder();
doc.VenCode = dtIn["VenCode"].ToString();
//doc.OOCode = dtIn["OOCode"].ToString();
doc.User = dtIn["MUSER"].ToString();
doc.MTime = dtIn["Mtime"].ToString();
//doc.MTime = DateTime.Now;
doc.WHCode = dtIn["ToWarehouseCode"].ToString();
doc.ODNCode = "";
List list = new List();
foreach (DataRow dtList in ERPtable.Rows)
{
ERPPurchaseOrderList docc = new ERPPurchaseOrderList();
docc.Sequence = dtList["Sequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.Currency = dtList["Currency"].ToString();
docc.UnitPrice = dtList["UnitPrice"].ToString();
//docc.OODetailID = dtList["OODetailID"].ToString();
docc.DNDetailID = "";
list.Add(docc);
}
doc.details = list;
docmodel.Add(doc);
}
IstrErp = JsonConvert.SerializeObject(docmodel);
log.Info("委外入库ERPJSON" + IstrErp);
iresult = HttpPost("委外入库", ERPUrl.OutsourcingReceiveDocURL, IstrErp);
Result OtherOutResult = new Result();
OtherOutResult = JsonConvert.DeserializeObject(iresult);
List mm = new List();//json返回
if (OtherOutResult.Success == true)
{
string nn = OtherOutResult.Data.ToString();//LOTStockModel
mm = JsonConvert.DeserializeObject>(nn);
foreach (var items in mm)
{
string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',memo='1'
where TransCode='{4}' and TransSequence ='{5}'";
ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVTCode, items.Sequence, itemInfo.TransCode, itemInfo.TransSequence);
cmd.CommandText = ERPupdate;
numInfo = cmd.ExecuteNonQuery();
}
if (numInfo > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
cmd.Transaction.Rollback();
throw new Exception(OtherOutResult.Message);
}
#endregion
if (numInfoLot > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
}
}
return null;
case "其它入库":
string SOtherInDetail = @"select * from ICSOtherIn where InCode='{0}'and Sequence='{1}' and WorkPoint='{2}' ";
SOtherInDetail = string.Format(SOtherInDetail, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
DataTable dataDetailIn = DBHelper.SQlReturnData(SOtherInDetail, cmd);
if (dataDetailIn.Rows.Count > 0)
{
string sqlnn = @"select * from ICSOtherIn where InCode='{0}'and Sequence='{1}' and WorkPoint='{2}' and Status='3' ";
sqlnn = string.Format(sqlnn, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
DataTable dataDetailll = DBHelper.SQlReturnData(sqlnn, cmd);
if (dataDetailll.Rows.Count > 0)
{
throw new Exception("订单已关闭!");
}
else
{
foreach (DataRow itemDetail in dataDetailIn.Rows)
{
double Quantity = Convert.ToDouble(itemInfo.Quantity);///输入数量
double IssueNegQuantity = Convert.ToDouble(itemDetail["InQuantity"]);//已退数量
double NegQuantity = Quantity + IssueNegQuantity;//总数量(输入数量+已退数量)
double QuantityPla = Convert.ToDouble(itemDetail["Quantity"]);//计划数量
if (QuantityPla >= NegQuantity)
{
string NegDetailSql = @"update ICSOtherIn set InQuantity=(select sum(InQuantity) from ICSOtherIn where InCode='{0}' and Sequence='{1}' and WorkPoint='{2}') +'{3}'
, MUSER='{4}' ,MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{2}'), MTIME='{5}'
where InCode='{0}' and Sequence='{1}' and WorkPoint='{2}' ";
NegDetailSql = string.Format(NegDetailSql, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, itemInfo.Quantity, item.User, DateTime.Now);
cmd.CommandText = NegDetailSql;
numInfo = cmd.ExecuteNonQuery();
///添加库存
string HouseLotSql = @"
insert into ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
(select newid(),'{0}' ,a.WHCode,isnull((f.LocationCode),0) ,a.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{4}' ,'{5}' ,' '
from ICSOtherIn a --委外退料申请单
left join ICSInventoryLotDetail c on a.InCode=c.TransCode and c.TransSequence=a.Sequence --条码关联
left join ICSInventoryLot d on c.LOTNO=d.LotNO and d.WorkPoint=c.WorkPoint --条码
left join ICSLocation f on f.WHID=(select id from ICSWarehouse where WarehouseCode='{6}')
left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{5}' --用户
where a.InCode='{6}' and a. WorkPoint='{5}')";
HouseLotSql = string.Format(HouseLotSql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode, itemInfo.LocationCode);
cmd.CommandText = HouseLotSql;
num = cmd.ExecuteNonQuery();
///添加日志
string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',a.WHCode,d.LocationCode,'{3}',' ','0','2','12',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
from ICSOtherIn a--主表
left join ICSWarehouse c on c.WarehouseCode=a.WHCode and c.WorkPoint=a.WorkPoint--仓库
left join ICSLocation d on d.WHID=(select id from ICSWarehouse where WarehouseCode='{7}')--库位
left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
where a.InCode='{0}' and a. WorkPoint='{6}' AND A.Sequence='{1}' )";
sqlLogInfo = string.Format(sqlLogInfo, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint, itemInfo.LocationCode);
cmd.CommandText = sqlLogInfo;
int numInfoLot = cmd.ExecuteNonQuery();
if (numInfoLot > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
#region ERP
#endregion
}
else
{
throw new Exception("已入数量超过计划数量!");
}
}
}
}
else
{
throw new Exception("查无数据!");
}
return null;
}
}
}
return model;
}
catch (Exception ex)
{
//cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 上架删除
/// BusinessCode,TransType 两个类型
///
///
public List LOTStockDelete(LOTStockUpDeleteIModel JsonData)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
sql = @"";
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
model = JsonConvert.DeserializeObject>(json);//>
cmd.Transaction.Commit();
return model;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 下架
///
/// 下架增加
/// BusinessCode,TransType 两个类型
///
///
public int LOTStockDownCreate(List JsonData)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num;
string sqlERP = string.Empty;//ERP的表头
string sqlERPDetil = string.Empty;//ERP的表体
string jsonERP = string.Empty;///erpjson
string IstrErp = string.Empty;
string iresult = string.Empty;//接口调用
try
{
foreach (var item in JsonData)
{
foreach (var itemInfo in item.detail)
{
switch (item.TransType)
{
case "委外退货":
string sqlNotices = @"select * from ICSODeliveryNotice where ODNCode='{0}' and Sequence='{1}' and ODNType='2' and WorkPoint='{2}'";
sqlNotices = string.Format(sqlNotices, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
DataTable Notices = DBHelper.SQlReturnData(sqlNotices, cmd);
if (Notices.Rows.Count < 0)
{
throw new Exception("单据已经关闭!");
}
foreach (DataRow itemdata in Notices.Rows)
{
int IssueQuantity = Convert.ToInt32(itemdata["RCVQuantity"]);//入库数量
int Quantity = Convert.ToInt32(itemdata["Quantity"]);//数量
int CurrentQuantity = Convert.ToInt32(Convert.ToDouble(itemInfo.CurrentQuantity));
int numQuantity = IssueQuantity + CurrentQuantity;//总数量
if (numQuantity > Quantity)
{
throw new Exception("应退数量大于实际数量");
}
}
//修改退货表
sql = " update ICSODeliveryNotice set RCVQuantity = RCVQuantity + '{0}' where ODNCode= '{1}' and WorkPoint='{2}' and Sequence='{3}' ";
sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
//修改库存
sqlInfo = @"update ICSWareHouseLotInfo set Quantity= Quantity -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
cmd.CommandText = sqlInfo;
num = cmd.ExecuteNonQuery();
///添加日志表
#region 添加日志
string sqlLogw = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),A.ODNCode,A.Sequence,'{0}',a.InvCode ,' ', ' ',b.WarehouseCode,b.LocationCode,'{1}',' ','0','2','20',' ',' ',' ',' ','{2}',e.F_RealName,'{3}','{4}',' '
from ICSODeliveryNotice a--主表
left join ICSWareHouseLotInfo b on b.LotNo='{0}'
left join Sys_SRM_User e on e.F_Account='{2}' and e.F_Location='{4}'
where a.ODNCode='{5}' and a.WorkPoint='{4}' and Sequence='{6}')";
sqlLogw = string.Format(sqlLogw, itemInfo.LotNo, item.Quantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.TransSequence, itemInfo.Sequence);
cmd.CommandText = sqlLogw;
int numlogs = cmd.ExecuteNonQuery();
#endregion
#region ERP
sqlERP = @" select a.VenCode ,a.POID,b.ToWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.ODNCode ,(getdate())as Mtime from ICSODeliveryNotice a
inner join ICSWareHouseLotInfoLog b on a.ODNCode=b.TransCode and b.TransSequence=a.Sequence
where a.ODNType='2' and a.odncode='{0}' and b.WorkPoint='{1}' and b.Memo <> '1'
group by a.VenCode ,a.POID,b.ToWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.ODNCode";
sqlERP = string.Format(sqlERP, item.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sqlERP, cmd);
sqlERPDetil = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity, isnull((b.Amount), 0) as Amount ,Currency,ISNULL((UnitPrice),0) AS UnitPrice,b.ODNDetailID from ICSWareHouseLotInfoLog a
inner JOIN ICSODeliveryNotice B ON b.ODNCode = a.TransCode and a.TransSequence = b.Sequence
where b.ODNCode='{0}' and a.Memo <> '1' and a.WorkPoint='{1}'
group by a.TransSequence,b.InvCode,a.Quantity, Amount ,Currency,UnitPrice,b.ODNDetailID";
sqlERPDetil = string.Format(sqlERPDetil, item.TransCode, item.WorkPoint);
DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
List docmodel = new List();
foreach (DataRow dtIn in table.Rows)
{
ERPODNRT doc = new ERPODNRT();
doc.VenCode = dtIn["VenCode"].ToString();
//doc.POCode = dtIn["POID"].ToString();
doc.User = dtIn["MUSER"].ToString();
doc.MTime = dtIn["Mtime"].ToString();
doc.WHCode = dtIn["ToWarehouseCode"].ToString();
doc.ODNRTCode = dtIn["Odncode"].ToString();
List list = new List();
foreach (DataRow dtList in ERPtable.Rows)
{
ERPODNRTList docc = new ERPODNRTList();
docc.Sequence = dtList["TransSequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.Currency = dtList["Currency"].ToString();
docc.UnitPrice = dtList["UnitPrice"].ToString();
docc.ODNRTDetailID = dtList["ODNDetailID"].ToString();
list.Add(docc);
}
doc.details = list;
docmodel.Add(doc);
}
IstrErp = JsonConvert.SerializeObject(docmodel);
log.Info("委外退货ERPJSON" + IstrErp);
iresult = HttpPost("委外退货", ERPUrl.OutsourcingReturnBackURL, IstrErp);
Result OtherOutResult = new Result();
OtherOutResult = JsonConvert.DeserializeObject(iresult);
int numInfo = 0;
if (OtherOutResult.Success == false)
{
throw new Exception(OtherOutResult.Message);
}
else
{
List list = new List();
//string nn = OtherOutResult.Data.ToString();//LOTStockModel
list = JsonConvert.DeserializeObject>(OtherOutResult.Data.ToString());
foreach (var items in list)
{
string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
where TransCode='{4}' and TransSequence ='{5}'";
ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVNEGCode, items.Sequence, item.TransCode, itemInfo.TransSequence);
cmd.CommandText = ERPupdate;
numInfo = cmd.ExecuteNonQuery();
}
if (numInfo > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
#endregion
if (numlogs <= 0)
{
cmd.Transaction.Rollback();
}
else
{
cmd.Transaction.Commit();
}
return 0;
case "材料出库":
string sqlMOPick = @"SELECT IssueQuantity,Quantity,* from ICSMOPick
where MODetailID= (SELECT ID FROM ICSMO WHERE MOCode='{0}') and InvCode=(select InvCode from ICSInventoryLot where LotNo='{1}' AND WorkPoint='{2}')";
sqlMOPick = string.Format(sqlMOPick, item.TransCode, itemInfo.LotNo, item.WorkPoint);
//cmd.CommandText = sqlMOPick;
DataTable data = DBHelper.SQlReturnData(sqlMOPick, cmd);
foreach (DataRow itemdata in data.Rows)
{
int IssueQuantity = Convert.ToInt32(itemdata["IssueQuantity"]);
int Quantity = Convert.ToInt32(itemdata["Quantity"]);
int CurrentQuantity = Convert.ToInt32(Convert.ToDouble(itemInfo.CurrentQuantity));
int numQuantity = IssueQuantity + CurrentQuantity;
if (numQuantity > Quantity)
{
throw new Exception("应退数量大于实际数量");
}
}
sql = " update ICSMOPick set IssueQuantity= IssueQuantity + '{0}' where MODetailID= (SELECT ID FROM ICSMO WHERE MOCode='{1}') and WorkPoint='{2}' and InvCode=(select InvCode from ICSInventoryLot where LotNo='{3}' )";
sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.LotNo);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
if (num <= 0)
{
throw new Exception("条码不存在!");
}
else
{
string sqlVerification = @"select * from ICSWareHouseLotInfo where lotno='{0}' and '{2}'<= Quantity and WorkPoint='{1}'";
sqlVerification = string.Format(sqlVerification, itemInfo.LotNo, item.WorkPoint, itemInfo.CurrentQuantity);
DataTable dataTableNum = DBHelper.SQlReturnData(sqlVerification, cmd);
if (dataTableNum.Rows.Count <= 0)
{
throw new Exception("输入数量大于库存数量");
}
else
{
sqlInfo = @"update ICSWareHouseLotInfo set Quantity= Quantity -'{0}' where lotno='{1}' ";
sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
cmd.CommandText = sqlInfo;
num = cmd.ExecuteNonQuery();
//DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
//cmd.Transaction.Commit();
log.Info("材料出库" + sql);
}
///添加日志表
#region 添加日志
string sqlLogs = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{5}','{6}','{0}',b.InvCode ,' ', ' ',b.WarehouseCode,b.LocationCode,'{1}',' ','0','2','21',' ',' ',' ',' ','{2}',e.F_RealName,'{3}','{4}',' '
from
ICSWareHouseLotInfo b
left join Sys_SRM_User e on e.F_Account='{2}' and e.F_Location='{4}'
where b.LotNo='{0}' and b.WorkPoint='{4}' )";
sqlLogs = string.Format(sqlLogs, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.TransSequence, itemInfo.Sequence);
cmd.CommandText = sqlLogs;
num = cmd.ExecuteNonQuery();
if (num <= 0)
{
cmd.Transaction.Rollback();
}
else
{
cmd.Transaction.Commit();
}
#endregion
#region ERP
sqlERP = @"select DepCode,FromWarehouseCode,MOCode,Sequence,a.MUSER ,(getdate())as Mtime,b.TransType from ICSMO a
left join ICSWareHouseLotInfoLog b on a.MOCode=b.TransCode and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
where MOCode='{0}' and a.WorkPoint='{1}' ";
sqlERP = string.Format(sqlERP, item.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sqlERP, cmd);
sqlERPDetil = @"select a.TransSequence,b.InvCode,a.Quantity, isnull((b.Amount),0)as Amount ,PickID from ICSWareHouseLotInfoLog a
LEFT JOIN ICSMO B ON B.MOCode=A.TransCode
left join ICSMOPick C on C.MODetailID=B.ID where LotNo='{0}' and c.Sequence=a.TransSequence and a.EATTRIBUTE1=b.Sequence and a.Memo<>'1'";
sqlERPDetil = string.Format(sqlERPDetil, itemInfo.LotNo);
DataTable ERPtabless = DBHelper.SQlReturnData(sqlERPDetil, cmd);
List docmodelss = new List();
foreach (DataRow dt in table.Rows)
{
IssueDoc doc = new IssueDoc();
doc.DepCode = dt["DepCode"].ToString();
doc.WHCode = dt["FromWarehouseCode"].ToString();
doc.SourceType = dt["MOCode"].ToString();
doc.SourceCode = "生产订单";
doc.User = dt["MUSER"].ToString();
doc.MTime = dt["Mtime"].ToString();
List list = new List();
foreach (DataRow dtList in ERPtabless.Rows)
{
IssueDocList docc = new IssueDocList();
docc.Sequence = dtList["TransSequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.SourceDetailID = dtList["PickID"].ToString();
list.Add(docc);
}
doc.details = list;
docmodelss.Add(doc);
}
IstrErp = JsonConvert.SerializeObject(docmodelss);
iresult = HttpPost("材料出库", ERPUrl.MOIssueDocURL, IstrErp);
Result OtherOutResultss = new Result();
OtherOutResultss = JsonConvert.DeserializeObject(iresult);
if (OtherOutResultss.Success == false)
{
throw new Exception(OtherOutResultss.Message);
}
else
{
//OtherOutResult.Data;
}
#endregion
}
return 0;
case "生产退料":
sql = @"update ICSMOApplyNegDetail set Quantity='{0}',Amount='{1}',IssueNegQuantity =((select sum(IssueNegQuantity) from ICSODelICSMOApplyNegDetailiveryNotice where ApplyNegCode='{2}') - '{0}'), MUSER='{3}',MTIME='{4}' where ApplyNegCode='{2}' and WorkPoint='{5}'";
sql = string.Format(sql, item.Quantity, item.Amount, item.TransCode, item.User, item.MTime, item.WorkPoint);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
return num;
case "产品入库":
sql = @"update ICSODeliveryNotice set Quantity='{0}',Amount='{1}'RCVQuantity =((select sum(RCVQuantity) from ICSODeliveryNotice where ODNCode='{2}') - '{0}') ,MUSER='{3}',MTIME='{4}' where ODNCode='{2}' and WorkPoint='{5}'";
sql = string.Format(sql, itemInfo.CurrentQuantity, itemInfo.CurrentAmount, item.TransCode, item.User, item.MTime, item.WorkPoint);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
if (num > 0)
{
//添加到日志表
}
return num;
case "销售发货":
#region 添加到库存表/日志表
///验证条码是否存在或者是否上架
sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
cmd.CommandText = sqlInfo;
table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (table.Rows.Count <= 0)
{
throw new Exception("条码不存在!");
}
///查询销售订单是否已经关闭
sqlInfo = @"select * from ICSSDN where SDNCode='{0}' and Sequence='{1}' and Status='3' and Type='1' and WorkPoint='{2}'";
sqlInfo = string.Format(sqlInfo, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
cmd.CommandText = sqlInfo;
DataTable tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
if (tableInfo.Rows.Count > 0)
{
throw new Exception("销售订单已经关闭!");
}
else
{
string sqlVerification = @"select * from ICSWareHouseLotInfo where lotno='{0}' and '{2}'<= Quantity and WorkPoint='{1}'";
sqlVerification = string.Format(sqlVerification, itemInfo.LotNo, item.WorkPoint, itemInfo.CurrentQuantity);
DataTable dataTablel = DBHelper.SQlReturnData(sqlVerification, cmd);
if (dataTablel.Rows.Count <= 0)
{
throw new Exception("输入数量大于库存数量");
}
else
{
///修改销售订单表已发数量
sql = @"update ICSSDN set SDNQuantity= SDNQuantity + '{4}' ,MTIME='{1}' where SDNCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, item.TransCode, item.WorkPoint, itemInfo.CurrentQuantity);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
//修改库存表的数量
sql = @" update ICSWareHouseLotInfo set Quantity=Quantity -'{4}',MTIME='{1}' where lotno ='{0}' and InvCode in (select InvCode from ICSInventoryLot where lotno='{0}' and WorkPoint ='{3}') and WorkPoint='{3}' ";
sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, item.TransCode, item.WorkPoint, itemInfo.CurrentQuantity);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
// cmd.Transaction.Commit();
#region 添加日志
if (num > 0)
{
string sqlLogInfoInf = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{4}'
,' '
,'{0}'
,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,''
,''
,'{5}'
,''
,''
,'21'
,''
,''
,''
,''
,''
,'{1}'
,'{1}'
,'{2}'
,'{3}'
,'')";
sqlLogInfoInf = string.Format(sqlLogInfoInf, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.CurrentQuantity);
cmd.CommandText = sqlLogInfoInf;
num = cmd.ExecuteNonQuery();
//cmd.Transaction.Commit();
}
#endregion
#region ERP接口
string ERPSnd = @"select A.CusCode,A.SDNCode ,B.MUSER,MAX(B.MTIME) AS MTIME,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode FROM ICSSDN a
inner join ICSWareHouseLotInfoLog b on a.SDNCode=b.TransCode and b.TransSequence=a.Sequence
where a.Type='1' and b.TransCode='{0}' and b.TransSequence='{1}' and b.WorkPoint='{2}'
group by A.CusCode,A.SDNCode ,B.MUSER,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode";
ERPSnd = string.Format(ERPSnd, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
table = DBHelper.SQlReturnData(ERPSnd, cmd);
string ERPSndList = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount ,b.SDNDetailID from ICSWareHouseLotInfoLog a
inner JOIN ICSSDN B ON b.SDNCode=a.TransCode and a.TransSequence=b.Sequence
where a.LotNo='{0}' and a.Memo<>'1' and b.WorkPoint='{1}' and b.Type='1'
group by a.TransSequence,b.InvCode, Amount ,b.SDNDetailID";
ERPSndList = string.Format(ERPSndList, itemInfo.LotNo, item.WorkPoint);
DataTable ERPtbSndList = DBHelper.SQlReturnData(ERPSndList, cmd);
List ERPemo = new List();
foreach (DataRow itemNotice in table.Rows)
{
ERPICSSDN noticeModel = new ERPICSSDN();
noticeModel.CusCode = itemNotice["CusCode"].ToString();
noticeModel.WHCode = itemNotice["FromWarehouseCode"].ToString();
noticeModel.SDNRTCode = itemNotice["SDNCode"].ToString();
noticeModel.User = itemNotice["MUSER"].ToString();
noticeModel.MTime = itemNotice["MTIME"].ToString();
List noticeModelList = new List();
foreach (DataRow ERPNoticeList in ERPtbSndList.Rows)
{
ERPICSSDNList listInfo = new ERPICSSDNList();
listInfo.Sequence = ERPNoticeList["TransSequence"].ToString();
listInfo.InvCode = ERPNoticeList["InvCode"].ToString();
listInfo.Quantity = ERPNoticeList["Quantity"].ToString();
listInfo.Amount = ERPNoticeList["Amount"].ToString();
listInfo.SDNRTDetailID = ERPNoticeList["SDNDetailID"].ToString();
noticeModelList.Add(listInfo);
}
noticeModel.details = noticeModelList;
ERPemo.Add(noticeModel);
string ERPICSSDN = JsonConvert.SerializeObject(ERPemo);
string Emoiresultsdn = HttpPost("销售出库单", ERPUrl.SalesDeliveryNoticeURL, ERPICSSDN);
Result OtherOutI = new Result();
OtherOutI = JsonConvert.DeserializeObject(Emoiresultsdn);
if (OtherOutI.Message != "200")
{
throw new Exception(OtherOutI.Message);
}
else
{
//OtherOutResult.Data;
}
}
#endregion
}
}
return 0;
#endregion
case "采购退货":
string sqlNotice = @"select * from ICSDeliveryNotice where DNCode='{0}' and Sequence='{1}' and DNType='2' and Status='3' and WorkPoint='{2}'";
sqlNotice = string.Format(sqlNotice, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
DataTable Notice = DBHelper.SQlReturnData(sqlNotice, cmd);
if (Notice.Rows.Count > 0)
{
throw new Exception("单据已经关闭!");
}
foreach (DataRow itemdata in Notice.Rows)
{
int IssueQuantity = Convert.ToInt32(itemdata["RCVQuantity"]);//入库数量
int Quantity = Convert.ToInt32(itemdata["Quantity"]);//数量
int CurrentQuantity = Convert.ToInt32(Convert.ToDouble(itemInfo.CurrentQuantity));
int numQuantity = IssueQuantity + CurrentQuantity;//总数量
if (numQuantity > IssueQuantity)
{
throw new Exception("应退数量大于实际数量");
}
}
//修改退货表
sql = " update ICSDeliveryNotice set RCVQuantity = RCVQuantity + '{0}' where DNCode= '{1}' and WorkPoint='{2}' and Sequence='{3}' ";
sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
//修改库存
sqlInfo = @"update ICSWareHouseLotInfo set Quantity= Quantity -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
cmd.CommandText = sqlInfo;
num = cmd.ExecuteNonQuery();
///添加日志表
#region 添加日志
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
( select newid(),'{5}' ,'{6}' ,'{0}',b.InvCode,b.WarehouseCode,b.LocationCode,'','','{1}' ,'','','2' ,'' ,'' ,'' ,'','' ,'{2}' ,c.F_RealName,'{3}' ,'{4}' ,'{7}'
from ICSWareHouseLotInfo b
left join Sys_SRM_User c on c.F_Account='{2}' and c.F_Location='{4}'
where b.LotNo='{0}' and b.WorkPoint='{4}')";
sqlLog = string.Format(sqlLog, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.TransSequence, itemInfo.Sequence);
cmd.CommandText = sqlLog;
int numlog = cmd.ExecuteNonQuery();
#endregion
#region ERP
sqlERP = @" select a.VenCode ,a.POID,b.FromWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.dncode,(getdate())as Mtime from ICSDeliveryNotice a
inner join ICSWareHouseLotInfoLog b on a.DNCode=b.TransCode and b.TransSequence=a.Sequence
where a.DNType='2' and b.TransCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
group by a.VenCode ,a.POID,b.FromWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.dncode";
sqlERP = string.Format(sqlERP, item.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sqlERP, cmd);
sqlERPDetil = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity, isnull((b.Amount), 0) as Amount ,Currency,UnitPrice,b.DNDetailID from ICSWareHouseLotInfoLog a
inner JOIN ICSDeliveryNotice B ON b.DNCode = a.TransCode and a.TransSequence = b.Sequence
where LotNo = '{0}' and a.Memo <> '1' and a.WorkPoint='{1}'
group by a.TransSequence,b.InvCode,a.Quantity, Amount ,Currency,UnitPrice,b.DNDetailID";
sqlERPDetil = string.Format(sqlERPDetil, itemInfo.LotNo, item.WorkPoint);
DataTable ERPtables = DBHelper.SQlReturnData(sqlERPDetil, cmd);
List docmodels = new List();
foreach (DataRow dtIn in table.Rows)
{
ERPPurchaseOrder doc = new ERPPurchaseOrder();
doc.VenCode = dtIn["VenCode"].ToString();
doc.POCode = dtIn["POID"].ToString();
doc.User = dtIn["MUSER"].ToString();
doc.MTime = dtIn["Mtime"].ToString();
doc.WHCode = dtIn["FromWarehouseCode"].ToString();
doc.DNCode = dtIn["dncode"].ToString();
List list = new List();
foreach (DataRow dtList in ERPtables.Rows)
{
ERPPurchaseOrderList docc = new ERPPurchaseOrderList();
docc.Sequence = dtList["TransSequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.Currency = dtList["Currency"].ToString();
docc.UnitPrice = dtList["UnitPrice"].ToString();
docc.DNDetailID = dtList["DNDetailID"].ToString();
list.Add(docc);
}
doc.details = list;
docmodels.Add(doc);
}
IstrErp = JsonConvert.SerializeObject(docmodels);
iresult = HttpPost("采购退货", ERPUrl.PurchaseReturnBackURL, IstrErp);
Result OtherOutResults = new Result();
OtherOutResult = JsonConvert.DeserializeObject(iresult);
int numInfos = 0;
if (OtherOutResult.Success == false)
{
throw new Exception(OtherOutResult.Message);
}
else
{
List list = new List();
//string nn = OtherOutResult.Data.ToString();//LOTStockModel
list = JsonConvert.DeserializeObject>(OtherOutResult.Data.ToString());
foreach (var items in list)
{
string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
where TransCode='{4}' and TransSequence ='{5}'";
ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVNEGCode, items.Sequence, item.TransCode, itemInfo.TransSequence);
cmd.CommandText = ERPupdate;
numInfos = cmd.ExecuteNonQuery();
}
if (numInfos > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
//string sqlupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
// where DNCode='{4}'";
//sqlupdate = string.Format(sqlupdate);
}
#endregion
return 0;
case "委外发料":
string str = itemInfo.TransSequence;
string[] arrStr = str.Split(',');
string BSequence = arrStr[0].ToString();
string ASequence = arrStr[1].ToString();
string sqlverification = @"select * from ICSOOPick where OODetailID = (select OODetailID from ICSOutsourcingOrder where OOCode='{0}' and Sequence='{2}' and WorkPoint='{1}') and WorkPoint='{1}' AND Sequence='{3}'";
sqlverification = string.Format(sqlverification, item.TransCode, item.WorkPoint, BSequence, ASequence);
DataTable tabletion = DBHelper.SQlReturnData(sqlverification, cmd);
if (tabletion.Rows.Count <= 0)
{
throw new Exception("发料单不存在!");
}
sql = @"update ICSOOPick set IssueQuantity= (select IssueQuantity from ICSOOPick where OODetailID = (select OODetailID from ICSOutsourcingOrder where OOCode='{1}' and Sequence='{3}' and WorkPoint='{2}') and WorkPoint='{2}' AND Sequence='{4}' ) + '{0}' where OODetailID = (select OODetailID from ICSOutsourcingOrder where OOCode='{1}' and Sequence='{3}' and WorkPoint='{2}') and WorkPoint='{2}' AND Sequence='{4}' ";
sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, BSequence, ASequence);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
sqlInfo = @"update ICSWareHouseLotInfo set Quantity= (select Quantity from ICSWareHouseLotInfo where lotno='{1}' and WorkPoint='{2}' ) -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
cmd.CommandText = sqlInfo;
num = cmd.ExecuteNonQuery();
#region 添加日志
string sqlPickLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
( select newid(),'{5}' ,'{6}' ,'{0}',b.InvCode,b.WarehouseCode,b.LocationCode,'','','{1}' ,'','','7' ,'' ,'' ,'' ,'','' ,'{2}' ,c.F_RealName,'{3}' ,'{4}' ,'{7}'
from ICSWareHouseLotInfo b
left join Sys_SRM_User c on c.F_Account='{2}' and c.F_Location='{4}'
where b.LotNo='{0}' and b.WorkPoint='{4}')";
sqlPickLog = string.Format(sqlPickLog, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, BSequence, itemInfo.TransSequence);
cmd.CommandText = sqlPickLog;
num = cmd.ExecuteNonQuery();
//if (numPicklog <= 0)
//{
// cmd.Transaction.Rollback();
//}
//else
//{
// cmd.Transaction.Commit();
//}
#endregion
#region ERP
string sqlERPOOPick = @" select b.DepCode,FromWarehouseCode,b.OOCode,a.MUSER ,(getdate())as Mtime from ICSWareHouseLotInfoLog a
left join ICSOutsourcingOrder b ON A.TransCode=B.OOCode and b.Sequence=a.TransSequence
left join ICSOOPick C on b.OODetailID=c.OODetailID and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
where b.OOCode='{0}' and a.WorkPoint='{1}' and a.memo<>'1'";
sqlERPOOPick = string.Format(sqlERPOOPick, item.TransCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sqlERPOOPick, cmd);
string sqlERPPickList = @"select a.TransCode, a.TransSequence,a.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount,c.PickID from ICSWareHouseLotInfoLog a
left JOIN ICSOutsourcingOrder B ON B.OOCode=A.TransCode and a.TransSequence=b.Sequence
left join ICSOOPick C on C.OODetailID=B.OODetailID and c.Sequence=a.TransSequence
where LotNo='{0}' and a.Memo<>'1'
group by a.TransCode, a.TransSequence,a.InvCode,b.Amount ,c.PickID ";
sqlERPPickList = string.Format(sqlERPPickList, itemInfo.LotNo);
DataTable ERPOOPick = DBHelper.SQlReturnData(sqlERPPickList, cmd);
string jsonPickList = null;
List docPickmodel = new List();
foreach (DataRow dt in table.Rows)
{
IssueDoc doc = new IssueDoc();
doc.DepCode = dt["DepCode"].ToString();
doc.WHCode = dt["FromWarehouseCode"].ToString();
doc.SourceType = dt["OOCode"].ToString();
doc.SourceCode = "委外发料";
doc.User = dt["MUSER"].ToString();
doc.MTime = dt["Mtime"].ToString();
List list = new List();
foreach (DataRow dtList in ERPOOPick.Rows)
{
IssueDocList docc = new IssueDocList();
docc.Sequence = dtList["TransSequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.SourceDetailID = dtList["PickID"].ToString();
list.Add(docc);
}
doc.details = list;
docPickmodel.Add(doc);
//jsonList = JsonConvert.SerializeObject(doc);
}
string IstrPick = JsonConvert.SerializeObject(docPickmodel);
log.Info("委外发料ERP传入的json" + IstrPick);
string iresultPick = HttpPost("委外发料", ERPUrl.OutsourcingIssueDocURL, IstrPick);
Result OtherOutResultpick = new Result();
OtherOutResultpick = JsonConvert.DeserializeObject(iresultPick);
List m = new List();
if (OtherOutResultpick.Success == true)
{
string nn = OtherOutResultpick.Data.ToString();//LOTStockModel
m = JsonConvert.DeserializeObject>(nn);
foreach (var items in m)
{
string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
where TransCode='{4}' and TransSequence ='{5}'";
ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.IssueCode, items.Sequence, item.TransCode, BSequence);
cmd.CommandText = ERPupdate;
num = cmd.ExecuteNonQuery();
}
if (num > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
cmd.Transaction.Rollback();
throw new Exception(OtherOutResultpick.Message);
}
#endregion
return 0;
case "其它出库":
string sqlOtherOut = @"select * from ICSOtherOut where OutCode = '{0}' and WorkPoint='{1}' AND Sequence='{2}'";
sqlOtherOut = string.Format(sqlOtherOut, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
DataTable tabletionIn = DBHelper.SQlReturnData(sqlOtherOut, cmd);
if (tabletionIn.Rows.Count <= 0)
{
throw new Exception("杂发单不存在!");
}
string sqlVerificationNum = @"select * from ICSWareHouseLotInfo where lotno='{0}' and '{2}'<= Quantity and WorkPoint='{1}'";
sqlVerificationNum = string.Format(sqlVerificationNum, itemInfo.LotNo, item.WorkPoint, itemInfo.CurrentQuantity);
DataTable dataTable = DBHelper.SQlReturnData(sqlVerificationNum, cmd);
if (dataTable.Rows.Count <= 0)
{
throw new Exception("输入数量大于库存数量");
}
//修改出库表
sql = @"update ICSOtherOut set OutQuantity= (select sum(OutQuantity) from ICSOtherOut where OutCode = '{1}')+'{0}' where OutCode = '{1}' and WorkPoint='{2}' AND Sequence='{3}' ";
sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
//修改库存
sqlInfo = @"update ICSWareHouseLotInfo set Quantity= (select sum(Quantity) from ICSWareHouseLotInfo where lotno='{1}' and WorkPoint='{2}' ) -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
cmd.CommandText = sqlInfo;
num = cmd.ExecuteNonQuery();
///添加日志
string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',b.WarehouseCode,b.LocationCode,'{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
from ICSOtherOut a--主表
left join ICSWareHouseLotInfo b on b.LotNo='{2}'
left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
where a.mocode='{0}' and a.WorkPoint='{6}' and Sequence='{1}')";
sqlLogInfo = string.Format(sqlLogInfo, item.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint);
//left join ICSWarehouse c on c.WarehouseCode = a.WHCode and c.WorkPoint = a.WorkPoint--仓库
// left join ICSLocation d on d.WHID = c.ID and d.WorkPoint = c.WorkPoint--库位
cmd.CommandText = sqlLogInfo;
int numInfoLot = cmd.ExecuteNonQuery();
if (numInfoLot > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
return 0;
}
}
}
return 0;
}
catch (Exception ex)
{
// cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 合并
///
/// 合并 查询
///
///
///
public List LOTMergeGet(WMSTBarCodeModel JsonData)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
sql = @"SELECT
a.[ID] --唯一标识
,[TransCode] --源头单据号
,[TransSequence]--源头单据行号
,a.[LotNo] --条码
,a.[InvCode] --料品编码
,a.[Quantity] --数量
,c.WarehouseCode as WHCode --仓库编码
,c.WarehouseName as WHName --仓库名称
,d.LocationCode as LocationCode --库位代码
,d.LocationName as LocationName --库位名称
,e.name as BusinessCode
,a.MUSER --操作人
,a.[MTIME] --操作时间
FROM [ICSWMS_Base].[dbo].[ICSWareHouseLotInfoLog] a --主表出入库
left join ICSWareHouseLotInfo b on a.LotNo=b.LotNo and b.InvCode=a.InvCode and a.WorkPoint=b.WorkPoint --库存
left join ICSWarehouse c on c.WarehouseCode=b.WarehouseCode and c.WorkPoint=b.WorkPoint-- 仓库
left join ICSLocation d on b.LocationCode=d.LocationCode and b.WorkPoint=d.WorkPoint--库位
left join ICSType e on a.BusinessCode=e.ColumnCode and e.Code=a.BusinessCode and e.WorkPoint=a.WorkPoint --类型
where 1=1 ";
if (!string.IsNullOrEmpty(JsonData.TransCode))
{
sql += " and TransCode='{0}'";
sql = string.Format(sql, JsonData.TransCode);
}
if (!string.IsNullOrEmpty(JsonData.User))
{
sql += " and MUSER='{1}'";
sql = string.Format(sql, JsonData.User);
}
if (JsonData.MTime.ToString() != "0001/1/1 0:00:00")
{
sql += " and MTIME='{2}'";
sql = string.Format(sql, JsonData.MTime);
}
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
model = JsonConvert.DeserializeObject>(json);//>
cmd.Transaction.Commit();
return model;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 合并Create
///
///
/// ,
public List LOTMergeCreate(List JsonData)
{
List model = new List();
var lotNo = string.Empty;
var CoreNo = string.Empty;//合并的条码
decimal num = 0;//合并的数量
var cnum = string.Empty;
string str = string.Empty;
string WorkPoint = null;
string UserName = string.Empty;
string TransNos = "";
int numInfo = 0;
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
List list = new List();
///第一个条码的数量
foreach (var item in JsonData)
{
lotNo = item.LotNo;//条码
UserName = item.User;
foreach (var itemInfo in item.detail)
{
CoreNo = itemInfo.CurrentLotNo;//合并的条码
num += Convert.ToDecimal(itemInfo.CurrentQuantity);//合并的数量
WorkPoint = itemInfo.WorkPoint;
list.Add(CoreNo);
}
}
//str = string.Join(",", list.ToArray());
///主表条码
//int UpdatenumInfo = 0;
foreach (var item in list.ToArray())
{
str = item.ToString();
string sql = @"update ICSWareHouseLotInfo set Quantity='0' where LotNo = '{0}' and WorkPoint='{1}'";
sql = string.Format(sql, str, WorkPoint);
cmd.CommandText = sql;
numInfo = cmd.ExecuteNonQuery();
}
string updateSql = @"update ICSWareHouseLotInfo set Quantity=(select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{2}')+'{0}' where LotNo='{1}' and WorkPoint='{2}'";
updateSql = string.Format(updateSql, num, lotNo, WorkPoint);
cmd.CommandText = updateSql;
numInfo = cmd.ExecuteNonQuery();
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','',a.Quantity,' ','0','5','18',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
from ICSWareHouseLotInfo a--主表
left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
where a.LotNo='{0}' and a.WorkPoint='{3}' )";
sqlLog = string.Format(sqlLog, lotNo, UserName, DateTime.Now, WorkPoint);
cmd.CommandText = sqlLog;
int numLog = cmd.ExecuteNonQuery();
if (numLog > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
return null;
}
catch (Exception ex)
{
//cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 拆分
///
///
///
public List LOTSplitCreates(List JsonData)
{
//List model = new List();
var lotNo = string.Empty;
var CoreNo = string.Empty;//拆分的条码
int num = 0;//拆分的数量
var cnum = string.Empty;//拆分总数量
string str = string.Empty;
string WorkPoint = string.Empty;//站点
string UserName = string.Empty;
int numInfo = 0;
Decimal numm = 0;
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
List list = new List();
///第一个条码的数量
foreach (var item in JsonData)
{
lotNo = item.LotNo;//条码
UserName = item.User;
WorkPoint = item.WorkPoint;
foreach (var itemInfo in item.detail)
{
LOTCreateIModelInfo modelInfo = new LOTCreateIModelInfo();
modelInfo.CurrentLotNo = itemInfo.CurrentLotNo;//拆分的条码
modelInfo.CurrentQuantity = itemInfo.CurrentQuantity;//拆分的数量
modelInfo.WorkPoint = itemInfo.WorkPoint;
numm += Convert.ToDecimal(itemInfo.CurrentQuantity);
list.Add(modelInfo);
}
}
//拆分之前记录日志
//string sqlFront = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}'";
//sqlFront = string.Format(sqlFront,lotNo, WorkPoint);
string primaryLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','',a.Quantity,' ','0','4','16',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
from ICSWareHouseLotInfo a--主表
left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
where a.LotNo='{0}' and a.WorkPoint='{3}')";
primaryLog = string.Format(primaryLog, lotNo, UserName, DateTime.Now, WorkPoint);
cmd.CommandText = primaryLog;
int primarynumLog = cmd.ExecuteNonQuery();
///拆分后的条码数量
foreach (var item in list.ToArray())
{
CoreNo = item.CurrentLotNo;//条码
num = Convert.ToInt32(item.CurrentQuantity);//数量
WorkPoint = item.WorkPoint;//站点
//拆分条码
string sql = @"INSERT INTO [dbo].[ICSWareHouseLotInfo]
([ID]
,[LotNo]
,[WarehouseCode]
,[LocationCode]
,[InvCode]
,[Quantity]
,[InDate]
,[LockQuantity]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
select newid()
,'{0}'
,WarehouseCode
,LocationCode
,InvCode
,'{1}'
,InDate
,LockQuantity
,'{2}'
,b.F_RealName
,'{3}'
,'{4}'
,EATTRIBUTE1
from ICSWareHouseLotInfo
left join Sys_SRM_User b on b.F_Account='{2}' and b.F_Location='{4}' ";
sql = string.Format(sql, CoreNo, num, UserName, DateTime.Now, WorkPoint);
cmd.CommandText = sql;
numInfo = cmd.ExecuteNonQuery();
if (numInfo == 0)
{
throw new Exception("已经拆分过,请无重复拆分," + "拆分的条码:" + CoreNo);
}
}
///拆分日志
foreach (var item in list.ToArray())
{
CoreNo = item.CurrentLotNo;//条码
num = Convert.ToInt32(item.CurrentQuantity);//数量
WorkPoint = item.WorkPoint;//站点
//拆分 日志
string sqlLogs = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','','{4}',' ','0','4','15',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
from ICSWareHouseLotInfo a--主表
left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
where a.LotNo='{0}' and a.WorkPoint='{3}' )";
sqlLogs = string.Format(sqlLogs, CoreNo, UserName, DateTime.Now, WorkPoint, num);
cmd.CommandText = sqlLogs;
numInfo = cmd.ExecuteNonQuery();
}
//修改拆分总数量
string updateSql = @"update ICSWareHouseLotInfo set Quantity=(select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{2}')-'{0}' where LotNo='{1}' and WorkPoint='{2}'";
updateSql = string.Format(updateSql, numm, lotNo, WorkPoint);
cmd.CommandText = updateSql;
numInfo = cmd.ExecuteNonQuery();
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','',a.Quantity,' ','0','4','15',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
from ICSWareHouseLotInfo a--主表
left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
where a.LotNo='{0}' and a.WorkPoint='{3}' )";
sqlLog = string.Format(sqlLog, lotNo, UserName, DateTime.Now, WorkPoint);
cmd.CommandText = sqlLog;
int numLog = cmd.ExecuteNonQuery();
if (numLog > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
return null;
}
catch (Exception ex)
{
//cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 更新
///
public string LOTReviseUpdate(LOTReviseUpdateIModel JsonData)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
int result = 0;
string resultInfo = "数量为0";
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
#region 更新ICSWareHouseInfo表
sql = @"update ICSWareHouseLotInfo
set Quantity=Quantity - {0},MTIME='{1}'
where INVCode='{2}' and WorkPoint='{3}'
update ICSWareHouseLotInfoLog
set Quantity=Quantity + {0},MTIME='{1}'
where INVCode='{2}' and WorkPoint='{4}'";
sql = string.Format(sql, JsonData.Quantityl, DateTime.Now, JsonData.LotNo, JsonData.WorkPoint);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();//返回条数
#endregion
if (result > 0)
{
return result.ToString();
}
return resultInfo;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 盘点
///
/// 盘点
///
///
///
public List LOTCheckGet(List JsonData)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
int result = 0;
string resultInfo = null;
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
foreach (var item in JsonData)
{
if (item.CheckCode == null)
{
resultInfo = "盘点单号不能为空!";
}
#region 查询该盘点号是否有数据
sql = @"select count(CheckCode) from ICSCheck
where CheckCode={0}";
sql = string.Format(sql, item.CheckCode);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();//返回条数
if (result > 0)
{
sql = @"select
a.ID,
a.CheckCode,
a.WHCode,
B.WarehouseName,
a.InvCode,
a.Quantity,
a.ActualQuantity,
a.MUSER,
a.MTIME,
c.id,
c.LotNo,
c.ActualQuantity,
c.Quantity
from ICSCheck a
left join ICSWarehouse b on a.WHCode=B.WarehouseCode and a.WorkPoint=b.WorkPoint
left join ICSCheckDetail c on c.CheckCode=a.CheckCode and c.WorkPoint=a.WorkPoint
where 1=1 and a.CheckCode='{0}'";
sql = string.Format(sql, item.CheckCode, item.MTime, item.User);
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
model = JsonConvert.DeserializeObject>(json);//>
cmd.Transaction.Commit();
return model;
}
else
{
resultInfo = "没有数据!";
}
}
#endregion
return null;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 盘点添加
///
///
///
public string LOTCheckCreate(List infoModel)
{
List model = new List();
DataTable dt = null;
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
string result = null;
int resultInfo = 0;
int Status = 1;
try
{
//根据条码查询库存数量
foreach (var item in infoModel)
{
foreach (var itemInfo in item.detail)
{
sql = @"select * from ICSWareHouseLotInfo where LotNo='{0}' ";
sql = string.Format(sql, itemInfo.LotNo);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 0)
{
sql = @"INSERT INTO [dbo].[ICSCheck]
([ID]
,[CheckCode]
,[WHCode]
,[InvCode]
,[Status]
,[Quantity]
,[MUSER]
,[MTIME]
,MUSERName
,[WorkPoint])
VALUES
( NEWID(),
'{0}',
(select WarehouseCode from ICSWareHouseLotInfo where LotNo='{4}' ),
(select InvCode from ICSWareHouseLotInfo where LotNo='{4}'),
'1',
(select Quantity from ICSWareHouseLotInfo where LotNo='{4}'),
'{1}',
'{2}',
'{1}',
'{3}' )";
sql = string.Format(sql, item.CheckCode, item.User, item.MTime, item.WorkPoint, itemInfo.LotNo);
cmd.CommandText = sql;
DBHelper.CmdExecuteNonQuery(sql, cmd, "成功");
resultInfo = cmd.ExecuteNonQuery();//返回条数
sqlInfo = @" INSERT INTO [dbo].[ICSCheckDetail]
([ID]
,[CheckCode]
,[LotNo]
,[Quantity]
,[ActualQuantity]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint])
VALUES(
newid(),'{0}','{1}',
(select Quantity from ICSWareHouseLotInfo where LotNo='{1}'),
'{4}',
'{2}','{2}','{3}')";
sqlInfo = string.Format(sqlInfo, item.CheckCode, itemInfo.LotNo, item.User, item.MTime, itemInfo.ActualQuantity);
cmd.CommandText = sqlInfo;
DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
resultInfo = cmd.ExecuteNonQuery();//返回条数
}
else
{
throw new Exception("条码没有查询到数据");
}
}
}
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
return resultInfo.ToString();
}
///
/// 删除盘点数据
///
///
///
public string LOTCheckDelete(List infoModel)
{
List model = new List();
DataTable dt = null;
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int resultInfo = 0;
try
{
foreach (var item in infoModel)
{
foreach (var itemInfo in item.detail)
{
///先删除主表在删除子表
sql = @"DELETE FROM ICSCheck where CheckCode=(select CheckCode from ICSCheckDetail where LotNo='{0}')
DELETE FROM ICSCheckDetail where LotNo='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
cmd.CommandText = sql;
resultInfo = cmd.ExecuteNonQuery();//返回条数
}
}
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
return resultInfo.ToString();
}
#endregion
#region 审核
///
/// 审核
///
///
///
public string MOIssueDocNegativeApplyApprove(List infoModel)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int resultInfo = 0;
string num = "审核成功!";
try
{
foreach (var item in infoModel)
{
foreach (var itemInfo in item.detail)
{
//先查询是否已经审核过
sql = @"select * from ICSMOApplyNeg where status='2' and id='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, item.ID, itemInfo.WorkPoint);
DataTable dataTable = DBHelper.SQlReturnData(sql, cmd);
if (dataTable.Rows.Count > 0)
{
throw new Exception("已经审核过,请重复审核");
}
else
{
string sqlInfo = @"update ICSMOApplyNeg set status ='1' where id='{0}' and WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, item.ID, itemInfo.WorkPoint);
DataTable data = DBHelper.SQlReturnData(sqlInfo, cmd);
if (data.Rows.Count > 0)
{
return num;
}
}
}
}
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
return num;
}
#endregion
#region 生产退料
///
/// 查询
///
///
///
public List MOIssueDocNegativeApplyGet(ICSMOApplyNeg infoModel)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int resultInfo = 0;
try
{
sql = @"select
a.id,
a.ApplyNegCode,
c.WarehouseCode,
c.WarehouseName,
a.MUSER,
a.MUSERName,
a.MTIME,
a.WorkPoint,
a.Sequence,
a.InvCode,
a.Quantity,
a.Amount,
a.SourceDetailID,
b.ID
from ICSMOApplyNegDetail a
left join ICSMOApplyNeg b on b.ApplyNegCode = a.ApplyNegCode and a.WorkPoint=b.WorkPoint
left join ICSWarehouse c on b.WHCode = c.WarehouseCode and b.WorkPoint=c.WorkPoint
where a.ApplyNegCode='{0}' and a.MUSER='{1}' and a.MTIME='{2}'";
sql = string.Format(sql, infoModel.MOApplyNegCode, infoModel.User, infoModel.MTime);
table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
model = JsonConvert.DeserializeObject>(json);//>
cmd.Transaction.Commit();
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
return model;
}
///
/// 添加
///
///
///
public string MOIssueDocNegativeApplyCreate(List infoModel)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int resultInfo = 0;
int resultInfowater = 0;
string Pre;
string water = "001";
try
{
Random Rdm = new Random();
foreach (var item in infoModel)
{
foreach (var itemInfo in item.detail)
{
string Date = DateTime.Now.ToString("yy");
Pre = "MOISSUENEGAPPLY" + item.WHCode + Rdm.Next(0, 100) + Date;
Pre += 1;
sql = @"INSERT INTO ICSMOApplyNeg ([ID],[ApplyNegCode],[WHCode],[Status],[MUSER],[MTIME],[WorkPoint],type,CreatePerson,MUSERName,CreateDateTime)
VALUES (newid(),'{0}','{1}','新建','{2}','{3}','{4}','生产','{2}','{2}','{3}')";
sql = string.Format(sql, Pre, item.WHCode, item.User, item.MTime, itemInfo.WorkPoint);
cmd.CommandText = sql;
resultInfo = cmd.ExecuteNonQuery();//返回条数
//cmd.Transaction.Commit();
if (resultInfo <= 0)
{
throw new Exception("添加主表失败");
}
sqlInfo = @" INSERT INTO ICSMOApplyNegDetail ([ID],[ApplyNegCode],[Sequence],[SourceDetailID],[InvCode],[Quantity],[Amount],[ExtensionID],[MUSER],MUSERName,[MTIME],[WorkPoint],[EATTRIBUTE])
VALUES( newid(),'{0}','{1}','{2}','{3}',{4},{5},'0','{6}','{6}','{7}','{8}','0') ";
if (itemInfo.Amount == "")
{
itemInfo.Amount = "0";
}
sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, item.User, item.MTime, itemInfo.WorkPoint);
cmd.CommandText = sqlInfo;
resultInfo = cmd.ExecuteNonQuery();//返回条数
cmd.Transaction.Commit();
}
}
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
return resultInfo.ToString();
}
///
/// 修改
///
///
///
public int MOIssueDocNegativeApplyUpdate(List infoModel)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int resultInfo = 0;
int ApplyNeg = 0;
string Pre;
try
{
foreach (var item in infoModel)
{
foreach (var itemInfo in item.detail)
{
//当id不为空的时候执行修改,当id为空的时候执行添加
sql = @"select * from ICSMOApplyNeg where id='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, item.ID, itemInfo.WorkPoint);
cmd.CommandText = sql;
cmd.Transaction.Commit();
resultInfo = cmd.ExecuteNonQuery();
if (resultInfo > 0)
{
sql = @"update ICSMOApplyNeg set WHCode='{0}',MUSER='{1}' ,MUSERName='{2}' where id='{3}' and WorkPoint='{4}'";
sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, itemInfo.WorkPoint);
cmd.CommandText = sql;
ApplyNeg = cmd.ExecuteNonQuery();
cmd.Transaction.Commit();
if (ApplyNeg > 0)
{
//修改子表
sqlInfo = @"update ICSMOApplyNegDetail set InvCode='{0}' Quantity={1} Amount={2} where id='{3}' and WorkPoint='{4}'";
if (itemInfo.Amount == "")
{
itemInfo.Amount = "0";
}
sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.DetailID, itemInfo.WorkPoint);
cmd.CommandText = sql;
ApplyNeg = cmd.ExecuteNonQuery();
cmd.Transaction.Commit();
}
}
else
{
MOIssueDocNegativeApplyCreate(infoModel);
}
}
}
return ApplyNeg + resultInfo;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 删除
///
///
///
public int MOIssueDocNegativeApplyDelete(List infoModel)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int resultInfo = 0;
try
{
foreach (var item in infoModel)
{
foreach (var itemInfo in item.detail)
{
//删除子表
sql = @"delete ICSMOApplyNegDetail where ID='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, itemInfo.DetailID, itemInfo.WorkPoint);
cmd.CommandText = sql;
cmd.Transaction.Commit();
resultInfo = cmd.ExecuteNonQuery();//返回条数
if (resultInfo <= 0)
{
throw new Exception("删除失败");
}
sqlInfo = @"delete ICSMOApplyNeg where ID='{0}'and WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, item.ID, itemInfo.WorkPoint);
cmd.CommandText = sqlInfo;
resultInfo = cmd.ExecuteNonQuery();//返回条数
}
}
}
catch (Exception ex)
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
return resultInfo;
}
#endregion
#region 采购到货单/拒收
///
/// 到货单添加
///
///
///
public string DeliveryNoticeCreate(List infoModel, string DNType)
{
DataTable dt = null;
DataTable dtInfo = null;
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num = 0;
int numInfo = 0;
string sqlDetail;
string json;
double numtable = 0;
double numASN = 0;
///ERP
string sqlERP = string.Empty;//ERP的表头
string sqlERPDetil = string.Empty;//ERP的表体
string jsonERP = string.Empty;///erpjson
string IstrErp = string.Empty;
string iresult = string.Empty;//接口调用
string ASNCode = string.Empty;
string WorkPoint = string.Empty;
string Sequences = string.Empty;
try
{
if (infoModel.Count <= 0)
{
throw new Exception("传送数据为空!");
}
List model = new List();
foreach (var item in infoModel)
{
ASNCode = item.ASNCode;
WorkPoint = item.WorkPoint;
string Pre;
int i = 0;
Random Rdm = new Random();
int iRdm = Rdm.Next(0, 100);
if (DNType == "到货")
{
string Date = DateTime.Now.ToString("yy");
Pre = "DN" + item.VenCode + iRdm + Date;
if (!string.IsNullOrEmpty(item.ASNCode))
{
sql = @"select * from ICSASN a inner join ICSASNDetail b on a.ASNCode=b.ASNCode where a.ASNCode='{0}' and a.Status='2' and a.WorkPoint='{1}'";
sql = string.Format(sql, item.ASNCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
}
else
{
throw new Exception("送货单号为空!");
}
#region 验证送货单数据是否存在
//是否送货单是否存在是否已经审核
if (table.Rows.Count <= 0)
{
throw new Exception("该送货单单没有审核或没有该单据请核对!");
}
#endregion
#region 验证送货单数据是否存在
//是否送货单是否存在是否已经审核
else
{
#region 修改子表的信息
foreach (var itemInfo in item.detail)
{
//WorkPoint = itemInfo.WorkPoint;
Sequences = itemInfo.Sequence;
///修改送货单子表信息
sqlDetail = @" update ICSASNDetail set DNQuantity='{2}' where ASNCode='{0}' and WorkPoint='{1}' and LotNo='{3}'";
sqlDetail = string.Format(sqlDetail, item.ASNCode, item.WorkPoint, itemInfo.Quantity, itemInfo.LotNo);
//DBHelper.CmdExecuteNonQuery(sqlDetail, cmd, "成功");
cmd.CommandText = sqlDetail;
int numInfoL = cmd.ExecuteNonQuery();
#endregion
#region Add到货单
string sqlnum = @"select * from ICSDeliveryNotice where WorkPoint='{0}' and ASNCode='{1}' and DNType='1' ";
sqlnum = string.Format(sqlnum, item.WorkPoint, item.ASNCode);
DataTable data = DBHelper.SQlReturnData(sqlnum, cmd);
if (data.Rows.Count > 0)
{
throw new Exception("已到货,不能重复到货!");
}
else
{
string sqlasn = @"select isnull(Quantity,0) as Quantity from ICSASN a inner join ICSASNDetail b on a.ASNCode=b.ASNCode where b.LotNo='{0}' and a.Status='2' and a.WorkPoint='{1}'";
sqlasn = string.Format(sqlasn, itemInfo.LotNo, item.WorkPoint);
DataTable dasn = DBHelper.SQlReturnData(sqlasn, cmd);
numASN = Convert.ToDouble(dasn.Rows[0][0]);
if (Convert.ToDouble(itemInfo.Quantity) > numASN)
{
throw new Exception("到货数量大于送货数量,请查看数量!");
}
}
}
//添加到到货单新数据
sqlInfo = @"INSERT INTO [ICSDeliveryNotice]
([ID]
,[DNCode]
,[Sequence]
,[VenCode]
,[DepCode]
,[DNType]
,[InvCode]
,[Quantity]
,[Amount]
,[RCVQuantity]
,[UnitPrice]
,[Currency]
,[Status]
,[CreatePerson]
,[CreateDateTime]
,[POID]
,[PODetailID]
,[DNID]
,[DNDetailID]
,[ExtensionID]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1]
,[ASNCode])
(SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,'1',b.InvCode,SUM(a.DNQuantity),'0','0',d.UnitPrice,d.Currency,'2'
,'{1}',GETDATE(),d.POID,d.PODetailID,'0','0',b.ExtensionID,'{1}',e.F_RealName,GETDATE(),'{2}','',a.ASNCode
FROM ICSASNDetail a
INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.ASNCode,e.F_RealName)";
sqlInfo = string.Format(sqlInfo, Pre, item.User, item.WorkPoint, item.ASNCode);
cmd.CommandText = sqlInfo;
num = cmd.ExecuteNonQuery();
#endregion
}
#endregion
}
else
{
///拒收
Random RdmInfo = new Random();
int iRdmInfo = Rdm.Next(0, 100);
string Date = DateTime.Now.ToString("yy");
Pre = "RJT" + item.VenCode + iRdmInfo + Date;
if (!string.IsNullOrEmpty(item.DNCode))
{
sql = @"select count(DNCode) from ICSDeliveryNotice where DNCode='{0}' and Status='2' and DNType='1' and WorkPoint='{1}'";
sql = string.Format(sql, item.DNCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
}
else
{
throw new Exception("送货单号为空!");
}
#region 验证送货单数据是否存在
//是否送货单是否存在是否已经审核
if (table.Rows.Count > 0)
{
#region Add拒收单
foreach (var itemInfo in item.detail)
{
int Sequence = i++;
//添加拒收新数据
sqlInfo = @" IF EXISTS(
select EATTRIBUTE1 from ICSDeliveryNotice
where EATTRIBUTE1 = '{14}' and DNType = '3' and WorkPoint = '{13}')
RAISERROR('条码:{14},该条码已拒收!', 16, 1)
INSERT INTO [ICSDeliveryNotice]
([ID]
,[DNCode]
,[Sequence]
,[VenCode]
,[DepCode]
,[DNType]
,[InvCode]
,[Quantity]
,[Amount]
,[RCVQuantity]
,[UnitPrice]
,[Currency]
,[Status]
,[CreatePerson]
,[CreateDateTime]
,[POID]
,[PODetailID]
,[DNID]
,[DNDetailID]
,[ExtensionID]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1]
,[ASNCode])
select newid(),'{0}', '{1}', '{2}', '{3}', '3', '{4}', '{5}', '{6}', 0, '{7}', '{8}' , '2', '{9}', '{10}', '{11}', '{12}', '0','0', b.ExtensionID, '{9}',a.F_RealName, '{10}', '{13}', '{14} ',' '
from Sys_SRM_User a
left join ICSDeliveryNotice b on b.DNCode='{15}'and b.DNType=1
where F_Account='{9}' and F_Location='{13}' ";
if (itemInfo.Amount == "")
{
int numInfoList = 0;
sqlInfo = string.Format(sqlInfo, Pre, Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, numInfoList, itemInfo.UnitPrice, itemInfo.Currency, item.User, DateTime.Now, item.ID, itemInfo.DNDetailID, itemInfo.WorkPoint, itemInfo.LotNo, item.DNCode);
cmd.CommandText = sqlInfo;
}
// DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
num = cmd.ExecuteNonQuery();
}
#endregion
}
else
{
throw new Exception("该送货单单没有审核或没有该单据请核对!");
}
#endregion
}
}
if (num > 0)
{
string numm = "成功";
#region ERP
sqlERP = @"select VenCode,DepCode,POID,MUSER,(getdate())as Mtime from ICSDeliveryNotice
where ASNCode='{0}' and WorkPoint='{1}' ";
sqlERP = string.Format(sqlERP, ASNCode, WorkPoint);
table = DBHelper.SQlReturnData(sqlERP, cmd);
sqlERPDetil = @"select Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID, cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from ICSDeliveryNotice A
LEFT JOIN ICSExtension B ON A.ASNCode=B.ID where A.ASNCode='{0}' and A.WorkPoint='{1}' ";
sqlERPDetil = string.Format(sqlERPDetil, ASNCode, WorkPoint);
DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
List docmodel = new List();
foreach (DataRow dtIn in table.Rows)
{
ERPDeliveryNotice doc = new ERPDeliveryNotice();
doc.VenCode = dtIn["VenCode"].ToString();
doc.DepCode = dtIn["DepCode"].ToString();
doc.POCode = dtIn["POID"].ToString();
doc.User = dtIn["MUSER"].ToString();
doc.MTime = dtIn["Mtime"].ToString();
List list = new List();
foreach (DataRow dtList in ERPtable.Rows)
{
ERPDeliveryNoticeList docc = new ERPDeliveryNoticeList();
docc.Sequence = dtList["Sequence"].ToString();
docc.InvCode = dtList["InvCode"].ToString();
docc.Quantity = dtList["Quantity"].ToString();
docc.Amount = dtList["Amount"].ToString();
docc.Currency = dtList["Currency"].ToString();
docc.UnitPrice = dtList["UnitPrice"].ToString();
docc.PODetailID = dtList["PODetailID"].ToString();
docc.cFree1 = dtList["cFree1"].ToString();
docc.cFree2 = dtList["cFree2"].ToString();
docc.cFree3 = dtList["cFree3"].ToString();
docc.cFree4 = dtList["cFree4"].ToString();
docc.cFree5 = dtList["cFree5"].ToString();
docc.cFree6 = dtList["cFree6"].ToString();
docc.cFree7 = dtList["cFree7"].ToString();
docc.cFree8 = dtList["cFree8"].ToString();
docc.cFree9 = dtList["cFree9"].ToString();
docc.cFree10 = dtList["cFree10"].ToString();
list.Add(docc);
}
doc.details = list;
docmodel.Add(doc);
}
IstrErp = JsonConvert.SerializeObject(docmodel);
iresult = HttpPost("采购到货", ERPUrl.CreatePOArrivURL, IstrErp);
Result OtherOutResult = new Result();
OtherOutResult = JsonConvert.DeserializeObject(iresult);
if (OtherOutResult.Success == false)
{
throw new Exception(OtherOutResult.Message);
}
else
{
List list = new List();
//string nn = OtherOutResult.Data.ToString();//LOTStockModel
list = JsonConvert.DeserializeObject>(OtherOutResult.Data.ToString());
foreach (var items in list)
{
string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}',DNType='1'
where ASNCode='{4}' and Sequence ='{5}'";
ERPupdate = string.Format(ERPupdate, items.DNCode, items.Sequence, items.ID, items.DetailID, ASNCode, Sequences);
cmd.CommandText = ERPupdate;
num = cmd.ExecuteNonQuery();
}
}
#endregion
cmd.Transaction.Commit();
//提交成功之后传ERP
return numm;
}
else
{
cmd.Transaction.Rollback();
}
return null;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 到货单查询
///
///
///
public string DeliveryNoticeGet(List infoModel, string DNType)
{
DataTable dt = null;
DataTable dtInfo = null;
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num = 0;
int numInfo = 0;
string sqlDetail;
string json;
try
{
return null;
}
catch (Exception ex)
{
// cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 委外到货/拒收
public string DeliveryNoticeODNCreate(List infoModel, string DNType)
{
Random Rdm = new Random();
int iRdm = Rdm.Next(0, 100);
DataTable dt = null;
DataTable dtInfo = null;
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num = 0;
int numInfo = 0;
string sqlDetail;
string json;
string TYPE;
try
{
if (infoModel.Count <= 0)
{
throw new Exception("传送数据为空!");
}
List model = new List();
int i = 1;
foreach (var item in infoModel)
{
string Pre;
if (DNType == "到货")
{
string Date = DateTime.Now.ToString("yy");
Pre = "ODN" + item.VenCode + iRdm + Date;
TYPE = "1";
#region 验证送货单数据是否存在
if (!string.IsNullOrEmpty(item.ASNCode))
{
sql = @"select * from ICSOASN where OASNCode='{0}' and Status='2' and WorkPoint='{1}'";
sql = string.Format(sql, item.ASNCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
}
else
{
return json = "委外送货单号为空!";
}
// 是否送货单是否存在是否已经审核
if (table.Rows.Count <= 0)
{
return json = "该送货单单没有审核或没有该单据请核对!";
}
#endregion
#region Add到货单
foreach (var itemInfo in item.detail)
{
//添加到到货单新数据
sqlInfo = @"INSERT INTO [ICSODeliveryNotice]
([ID]
,[ODNCode]
,[Sequence]
,[VenCode]
,[DepCode]
,[ODNType]
,[InvCode]
,[Quantity]
,[Amount]
,[RCVQuantity]
,[UnitPrice]
,[Currency]
,[Status]
,[CreatePerson]
,[CreateDateTime]
,[POID]
,[PODetailID]
,[ODNID]
,[ODNDetailID]
,[ExtensionID]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1]
)
(SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,'1',b.InvCode,SUM(a.ODNQuantity),'0','0',d.UnitPrice,d.Currency,'2'
,'{1}',GETDATE(),d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,'{1}',e.F_RealName,GETDATE(),'{2}','',a.OASNCode
FROM ICSOASNDetail a
INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.OASNCode,e.F_RealName)";
if (itemInfo.RCVQuantity == null)
{
int VQuantity = 0;
int Price = 0;
sqlInfo = string.Format(sqlInfo, Pre, item.User, item.WorkPoint, item.OASNCode);
//sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, VQuantity, Price, itemInfo.Currency, item.User, item.MTime, itemInfo.PODetailID, itemInfo.LotNo, item.WorkPoint, TYPE);
cmd.CommandText = sqlInfo;
}
else
{
sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.RCVQuantity, itemInfo.UnitPrice, itemInfo.Currency, item.User, item.MTime, itemInfo.PODetailID, itemInfo.LotNo, item.WorkPoint, TYPE);
cmd.CommandText = sqlInfo;
}
}
num = cmd.ExecuteNonQuery();//返回条数
#endregion
if (num <= 0)
{
return json = "添加失败";
}
else
{
#region 修改子表的信息
foreach (var itemInfo in item.detail)
{
///修改送货单子表信息
sqlDetail = @"
update ICSASNDetail set DNQuantity=((select SUM(DNQuantity) from ICSASNDetail where LotNo='{0}' and WorkPoint='{1}') +(select SUM(Quantity) from ICSDeliveryNotice where DNCode='{2}' and DNType='2' and WorkPoint='{1}' ))
where LotNo='{0}' and WorkPoint='{1}'";
sqlDetail = string.Format(sqlDetail, itemInfo.LotNo, item.WorkPoint, Pre);
cmd.CommandText = sqlDetail;
numInfo = cmd.ExecuteNonQuery();//返回条数
}
if (numInfo <= 0)
{
return json = "修改送货单失败";
}
#endregion
}
}
else
{
///拒收
Random RdmInfo = new Random();
int iRdmInfo = Rdm.Next(0, 100);
string Date = DateTime.Now.ToString("yy");
Pre = "ORJT" + item.VenCode + iRdm + Date;
if (!string.IsNullOrEmpty(item.ODNCode))
{
sql = @"select count(ODNCode) from ICSODeliveryNotice where ODNCode='{0}' and Status='2' and ODNType='1' and WorkPoint='{1}'";
sql = string.Format(sql, item.ODNCode, item.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
}
else
{
throw new Exception("到货单不存在!");
}
#region 验证送货单数据是否存在
//是否送货单是否存在是否已经审核
if (table.Rows.Count > 0)
{
#region Add拒收单
foreach (var itemInfo in item.detail)
{
int Sequence = i++;
//添加拒收新数据
sqlInfo = @"IF EXISTS(
select EATTRIBUTE1 from ICSODeliveryNotice
where EATTRIBUTE1 = '{14}' and ODNType = '3' and WorkPoint = '{13}')
RAISERROR('条码:{14},该条码已拒收!', 16, 1)
INSERT INTO [ICSODeliveryNotice]
([ID]
,[ODNCode]
,[Sequence]
,[VenCode]
,[DepCode]
,[ODNType]
,[InvCode]
,[Quantity]
,[Amount]
,[RCVQuantity]
,[UnitPrice]
,[Currency]
,[Status]
,[CreatePerson]
,[CreateDateTime]
,[POID]
,[PODetailID]
,[ODNID]
,[ODNDetailID]
,[ExtensionID]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1]
,[OASNCode])
select newid(),'{0}', '{1}', '{2}', '{3}', '3', '{4}', '{5}', '{6}', 0, '{7}', '{8}' , '2', '{9}', '{10}', '{11}', '{12}', '0', '0', a.ExtensionID, '{9}',c.F_RealName, '{10}', '{13}', '{14} ',' '
from ICSODeliveryNotice a
left join ICSOASNDetail b on a.OASNCode=b.OASNCode
LEFT JOIN Sys_SRM_User c ON c.F_Account='{9}' and c.F_Location='{13}'
where a.odncode='{15}' and B.LOTNO='{14}' ";
if (itemInfo.Amount == "")
{
int numInfoList = 0;
sqlInfo = string.Format(sqlInfo, Pre, Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, numInfoList, itemInfo.UnitPrice, itemInfo.Currency, item.User, DateTime.Now, item.ID, itemInfo.ODNDetailID, itemInfo.WorkPoint, itemInfo.LotNo, item.ODNCode);
cmd.CommandText = sqlInfo;
}
// DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
num = cmd.ExecuteNonQuery();
}
#endregion
}
else
{
throw new Exception("该送货单单没有审核或没有该单据请核对!");
}
#endregion
}
}
if (num > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
return num.ToString();
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 仓库/库位
///
/// 仓库/库位
///
///
///
public List LocationGet(ICSLocation JsonData)
{
List model = new List();
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
sqlInfo = @"SELECT
LocationCode,
LocationName ,
WarehouseCode,
WarehouseName
FROM ICSLocation a
left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' and b.Enable='0'";
sqlInfo = string.Format(sqlInfo, JsonData.LocationCode);
table = DBHelper.SQlReturnData(sqlInfo, cmd);
if (table.Rows.Count > 0)
{
throw new Exception("仓库不存在!");
}
else
{
sql = @"SELECT
LocationCode,
LocationName ,
WarehouseCode,
WarehouseName
FROM ICSLocation a
left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' and b.Enable='1'";
sql = string.Format(sql, JsonData.LocationCode);
table = DBHelper.SQlReturnData(sql, cmd);
if (table.Rows.Count <= 0)
{
throw new Exception("仓库未启用,请先启用仓库!");
}
string json = JsonConvert.SerializeObject(table);
model = JsonConvert.DeserializeObject>(json);//>
cmd.Transaction.Commit();
return model;
}
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 委外退料 /OutsourcingIssueDoNegativeApply
public ICSOApplyNegModel OutsourcingIssueDoNegativeApplyGet(ICSOApplyNeg JsonData)
{
List deliveryNotrModel = new List();
ICSOApplyNegModel model = new ICSOApplyNegModel();
DataTable dt = null;
DataTable dtInfo = null;
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = string.Empty;
string sqlInfo = string.Empty;
//foreach (var item in deliveryNotrModel)
//{
sql = @"select
a.ID as ID,
a.OApplyNegCode as OApplyNegCode,
a.WHCode as WHCode,
c.WarehouseName as WHName,
a.MUSER as MUSER,
a.MTIME as MTime
from ICSOApplyNeg a
left join ICSWarehouse c on c.WarehouseCode=a.WHCode and a.WorkPoint=b.WorkPoint
where 1=1";
if (!string.IsNullOrWhiteSpace(JsonData.OApplyNegCode))
{
sql += " and a.OApplyNegCode='{0}'";
}
if (!string.IsNullOrWhiteSpace(JsonData.User))
{
sql += " and a.MUSER='{1}'";
}
if (!string.IsNullOrWhiteSpace(JsonData.MTime))
{
sql += " and a.MTIME='{2}'";
}
sql = string.Format(sql, JsonData.OApplyNegCode, JsonData.User, JsonData.MTime);
sqlInfo = @"select
ID as DetailID,
Sequence as Sequence ,
InvCode as InvCode,
Quantity as Quantity,
Amount as Amount,
SourceDetailID as SourceDetailID
from ICSOApplyNegDetail
where OApplyNegCode=(select OApplyNegCode from ICSOApplyNeg where OApplyNegCode='{0}' and WorkPoint='{1}')";
sqlInfo = string.Format(sqlInfo, JsonData.OApplyNegCode, JsonData.WorkPoint);
//}
dt = DBHelper.SQlReturnData(sql, cmd);
dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
string json = JsonConvert.SerializeObject(dt);
string jsonInfo = JsonConvert.SerializeObject(dtInfo);
string jsonlist = null;
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
ICSOApplyNegModel main = new ICSOApplyNegModel();
main.ID = dr["ID"].ToString();
main.OApplyNegCode = dr["OApplyNegCode"].ToString();
main.WHCode = dr["WHCode"].ToString();
main.WHName = dr["WHName"].ToString();
main.User = dr["MUSER"].ToString();
main.MTime = dr["MTime"].ToString();
List list = new List();
foreach (DataRow info in dtInfo.Rows)
{
ICSOApplyNegModelInfo detail = new ICSOApplyNegModelInfo();
detail.DetailID = info["DetailID"].ToString();
detail.Sequence = info["Sequence"].ToString();
detail.InvCode = info["InvCode"].ToString();
detail.Quantity = info["Quantity"].ToString();
detail.Amount = info["Amount"].ToString();
detail.SourceDetailID = info["SourceDetailID"].ToString();
list.Add(detail);
}
main.detail = list;
jsonlist = JsonConvert.SerializeObject(main);
}
var deliveryNotrModelInfo = JsonConvert.DeserializeObject(jsonlist);
cmd.Transaction.Commit();
return deliveryNotrModelInfo;
}
else
{
throw new Exception("数据为空");
}
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 委外退料 新建
///
///
///
public int OutsourcingIssueDoNegativeApplyCreate(List JsonData)
{
Random Rdm = new Random();
int iRdm = Rdm.Next(0, 100);
List deliveryNotrModel = new List();
ICSOApplyNegModel model = new ICSOApplyNegModel();
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num = 0;
int numInfo = 0;
try
{
string sql = string.Empty;
string sqlInfo = string.Empty;
string Pre = "";
foreach (var item in JsonData)
{
foreach (var itemInfo in item.detail)
{
//主表新建数据
string Date = DateTime.Now.ToString("yy");
Pre = "OOISSUENEGAPPLY" + item.WHCode + iRdm + Date;//新的委外退料申请号
sql = @"INSERT INTO ICSOApplyNeg
([ID]
,[OApplyNegCode]
,[WHCode]
,[Status]
,[Type]
,[Memo]
,[CreatePerson]
,[CreateDateTime]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid(),'{0}','{1}','开立','委外',' ','{2}','{3}','{2}','{2}','{3}','{4}',' ')";
sql = string.Format(sql, Pre, item.WHCode, item.User, item.MTime, itemInfo.WorkPoint);
cmd.CommandText = sql;
//cmd.Transaction.Commit();
num = cmd.ExecuteNonQuery();//返回条数
sqlInfo = @"INSERT INTO [ICSOApplyNegDetail]
([ID]
,[OApplyNegCode]
,[Sequence]
,[SourceDetailID]
,[InvCode]
,[Quantity]
,[Amount]
,[IssueNegQuantity]
,[ExtensionID]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE])
VALUES
(newid(),'{0}'
,'{1}','{2}','{3}',{4},{5},0,'','{6}','{6}','{7}','{8}','')";
sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, item.User, item.MTime, itemInfo.WorkPoint);
cmd.CommandText = sqlInfo;
//cmd.Transaction.Commit();
numInfo = cmd.ExecuteNonQuery();//返回条数
}
cmd.Transaction.Commit();
}
if (num > 0 && numInfo > 0)
{
return num + numInfo;
}
return num;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 委外退料 修改
///
///
///
public int OutsourcingIssueDoNegativeApplyUpdate(List JsonData)
{
List deliveryNotrModel = new List();
ICSOApplyNegModel model = new ICSOApplyNegModel();
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num = 0;
int numInfo = 0;
try
{
string sql = string.Empty;
string sqlInfo = string.Empty;
string Pre = "";
foreach (var item in JsonData)
{
//主表修改
sql = @"update ICSOApplyNeg set WHCode='{0}' ,MUSER='{1}',MTIME='{2}'where ID='{3}' and WorkPoint='{4}' ";
sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
cmd.CommandText = sql;
cmd.Transaction.Commit();
num = cmd.ExecuteNonQuery();
foreach (var itemInfo in item.detail)
{
sql = @"update ICSOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}' where ID='{3}'and SourceDetailID='{4}' and WorkPoint='{5}'";
sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.DetailID, itemInfo.SourceDetailID, itemInfo.WorkPoint);
cmd.CommandText = sql;
//cmd.Transaction.Commit();
numInfo = cmd.ExecuteNonQuery();
}
}
if (num > 0 && numInfo > 0)
{
return numInfo + num;
}
return num + numInfo;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 委外退料 删除
///
///
///
public int OutsourcingIssueDoNegativeApplyDelete(List JsonData)
{
List deliveryNotrModel = new List();
ICSOApplyNegModel model = new ICSOApplyNegModel();
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num = 0;
int numInfo = 0;
try
{
string sql = string.Empty;
string sqlInfo = string.Empty;
string Pre = "";
foreach (var item in JsonData)
{
foreach (var itemInfo in item.detail)
{
sqlInfo = @"DELETE FROM ICSOApplyNegDetail where ID='{0}' and WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, itemInfo.DetailID, itemInfo.WorkPoint);
cmd.CommandText = sqlInfo;
cmd.Transaction.Commit();
numInfo = cmd.ExecuteNonQuery();
}
if (numInfo > 0)
{
//主表删除
sql = @"DELETE FROM [ICSOApplyNeg] where ID='{0}' and WorkPoint='{3}'";
if (!string.IsNullOrEmpty(item.User))
{
sql = "and MUSER = '{1}' ";
}
if (!string.IsNullOrEmpty(item.MTime))
{
sql = " and MTIME = '{2}'";
}
sql = string.Format(sql, item.id, item.User, item.MTime, item.WorkPoint);
cmd.CommandText = sql;
// cmd.Transaction.Commit();
num = cmd.ExecuteNonQuery();
}
}
if (num > 0 && numInfo > 0)
{
return numInfo + num;
}
return num + numInfo;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 库存盘点单
public object CheckGet(ICSCheck JsonData)
{
List deliveryNotrModel = new List();
ICSCheck model = new ICSCheck();
DataTable dt = null;
DataTable dtInfo = null;
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = string.Empty;
string sqlInfo = string.Empty;
string sqlList = string.Empty;
//foreach (var item in JsonData)
//{
sqlList = @" select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}'";
sql = string.Format(sqlList, JsonData.CheckCode, JsonData.WorkPoint);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 0)
{
sql = @"select
a.ID as ID,
a.CheckCode as CheckCode,
a.WHCode as WHCode,
b.WarehouseName as WHName,
a.InvCode as InvCode,
a.Quantity as Quantity,
a.ActualQuantity as ActualQuantity,
a.MUSER as MUSER,
a.MTIME as MTime
from ICSCheck a
left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
where 1=1 and Status='2'";
if (!string.IsNullOrWhiteSpace(JsonData.CheckCode))
{
sql += "and a.CheckCode='{0}'";
}
if (!string.IsNullOrWhiteSpace(JsonData.User))
{
sql += " and a.MUSER='{1}'";
}
if (!string.IsNullOrWhiteSpace(JsonData.MTime))
{
sql += " and a.MTIME='{2}'";
}
sql = string.Format(sql, JsonData.CheckCode, JsonData.User, JsonData.MTime);
sqlInfo = @" select
a.ID as DetailID ,
c.TransSequence as Sequence,
a.LotNo as LotNo,
a.Quantity as LotQuantity,
a.ActualQuantity as LotActualQuantity
from ICSCheckDetail a
left join ICSCheck b on a.CheckCode=b.CheckCode and a.WorkPoint=b.WorkPoint
left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and c.WorkPoint=a.WorkPoint
where 1=1 and a.CheckCode='{0}' ";
sqlInfo = string.Format(sqlInfo, JsonData.CheckCode);
//}
dt = DBHelper.SQlReturnData(sql, cmd);
dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
//string json = JsonConvert.SerializeObject(dt);
//string jsonInfo = JsonConvert.SerializeObject(dtInfo);
string jsonlist = null;
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
ICSCheckInfo main = new ICSCheckInfo();
main.ID = dr["ID"].ToString();
main.CheckCode = dr["CheckCode"].ToString();
main.WHCode = dr["WHCode"].ToString();
main.WHName = dr["WHName"].ToString();
main.InvCode = dr["InvCode"].ToString();
main.Quantity = dr["Quantity"].ToString();
main.ActualQuantity = dr["ActualQuantity"].ToString();
main.User = dr["MUSER"].ToString();
main.MTime = dr["MTime"].ToString();
List list = new List();
foreach (DataRow info in dtInfo.Rows)
{
ICSCheckInfoModel detail = new ICSCheckInfoModel();
detail.DetailID = info["DetailID"].ToString();
detail.Sequence = info["Sequence"].ToString();
detail.LotNo = info["LotNo"].ToString();
detail.LotQuantity = info["LotQuantity"].ToString();
detail.LotActualQuantity = info["LotActualQuantity"].ToString();
//detail.SourceDetailID = info["SourceDetailID"].ToString();
list.Add(detail);
}
main.detail = list;
jsonlist = JsonConvert.SerializeObject(main);
}
var deliveryNotrModelInfo = JsonConvert.DeserializeObject(jsonlist);
cmd.Transaction.Commit();
return deliveryNotrModelInfo;
}
else
{
throw new Exception("数据未审核,请先审核");
}
}
else
{
throw new Exception("单据不存在");
}
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 库存盘点
///
///
///
public object CheckCreate(List JsonData, string type)
{
List deliveryNotrModel = new List();
List iCs = new List();
ICSCheck model = new ICSCheck();
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
DataTable dt;
int num = 0;
Random Rdm = new Random();
int iRdm = Rdm.Next(0, 100);
try
{
string Pre = "";
string sql = string.Empty;
string sqlInfo = string.Empty;
foreach (var item in JsonData)
{
foreach (var itemInfo in item.detail)
{
if (type == "库存盘点")
{
string Date = DateTime.Now.ToString("yy");
Pre = "CHK" + itemInfo.WHCode + iRdm + Date;//库存盘点单号
sqlInfo = @"select * from ICSWarehouse a
left join ICSWareHouseLotInfo b on a.WarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
where a.Enable=1 and a.WarehouseCode='{0}' and a.WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, itemInfo.WHCode, itemInfo.WorkPoint);
cmd.CommandText = sqlInfo;
dt = DBHelper.SQlReturnData(sqlInfo, cmd);
if (dt.Rows.Count > 0)
{
sql = @"INSERT INTO [ICSCheck]
([ID]
,[CheckCode]
,[WHCode]
,[InvCode]
,[Status]
,[Quantity]
,[MUSER]
,[MTIME]
,MUSERName
,[WorkPoint])
(SELECT newid(),'{0}','{1}',a.InvCode,'1',SUM(a.Quantity),'{2}','{3}',b.F_RealName,'{4}'
FROM ICSWareHouseLotInfo a
INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{4}'
where WarehouseCode='{1}' and WorkPoint='{4}'
GROUP BY InvCode ,b.F_RealName)";
sql = string.Format(sql, Pre, itemInfo.WHCode, item.User, DateTime.Now, itemInfo.WorkPoint);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();//返回条数
if (num > 0)
{
string sqlCheck = @"select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}'";
sqlCheck = string.Format(sqlCheck, Pre, itemInfo.WorkPoint);
DataTable data = DBHelper.SQlReturnData(sqlCheck, cmd);
string json = JsonConvert.SerializeObject(data);
iCs = JsonConvert.DeserializeObject>(json);
//List docmodel = new List();
//foreach (DataRow row in data.Rows)
//{
// ICSCheckInfo doc = new ICSCheckInfo();
// doc.ID = row["ID"].ToString();
// doc.CheckCode = row["CheckCode"].ToString();
// doc.WHCode = row["WHCode"].ToString();
// doc.WHName = "";
// doc.InvCode = row["InvCode"].ToString();
// doc.Quantity = row["Quantity"].ToString();
// doc.ActualQuantity = row["ActualQuantity"].ToString();
// doc.User = row["User"].ToString();
// doc.MTime = row["MTime"].ToString();
// docmodel.Add(doc);
//}
//List list = new List();
//foreach (DataRow dtList in ERPtable.Rows)
//{
// IssueDocList docc = new IssueDocList();
// docc.Sequence = dtList["TransSequence"].ToString();
// docc.InvCode = dtList["InvCode"].ToString();
// docc.Quantity = dtList["Quantity"].ToString();
// docc.Amount = dtList["Amount"].ToString();
// docc.SourceDetailID = dtList["PickID"].ToString();
// list.Add(docc);
//}
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
throw new Exception("仓库未启用或仓库不存在!");
}
}
else if (type == "条码库存")
{
string Date = DateTime.Now.ToString("yy");
Pre = "LOTCHKdsk" + item.WHCode + Date;//条码盘点
sqlInfo = @"select * from ICSWarehouse a
left join ICSWareHouseLotInfo b on a.WarehouseCode=b.WarehouseCode
where a.Enable=1 and b.LotNo='{0}' and WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, itemInfo.WHCode, item.WorkPoint);
DataTable dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
if (dtInfo.Rows.Count > 0)
{
sql = @"INSERT INTO [ICSCheckDetail]
([ID]
,[CheckCode]
,[LotNo]
,[Quantity]
,[ActualQuantity]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint])
VALUES
(newid(),'{0}','{1}', (select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{4}' ),
(select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{4}' ),'{2}','{2}','{3}','{4}' )";
sql = string.Format(sql, Pre, itemInfo.WHCode, item.User, item.MTime, item.WorkPoint);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();//返回条数
if (num > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
throw new Exception("仓库未启用或仓库不存在!");
}
}
}
}
return iCs;
}
catch (Exception ex)
{
//cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// 盘点单审核
///
///
///
public bool CreateApprove(ICSCheck JsonData)
{
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
DataTable dt;
int num = 0;
Random Rdm = new Random();
int iRdm = Rdm.Next(0, 100);
try
{
sql = @"select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}' ";
sql = string.Format(sql, JsonData.CheckCode, JsonData.WorkPoint);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count <= 0)
{
throw new Exception("盘点单不存在!");
}
else
{
string sqlInfo = @"upadte ICSCheck set Status='2' ,MUSER ='{2}', MUSERName=(select F_RealName from Sys_SRM_User where F_Account ='{2}' and F_Location='{1}' ) , MTIME='{3}' where CheckCode='{0}' and WorkPoint='{1}'";
sqlInfo = string.Format(sqlInfo, JsonData.CheckCode, JsonData.WorkPoint, JsonData.User, DateTime.Now);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();//返回条数
if (num > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
return true;
}
catch (Exception ex)
{
//cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
///
/// PDA库存盘点
///
///
///
public int PDACheckCreate(List JsonData, string type)
{
List deliveryNotrModel = new List();
ICSCheck model = new ICSCheck();
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
DataTable dt;
int num = 0;
try
{
string Pre = "";
string sql = string.Empty;
string sqlInfo = string.Empty;
foreach (var item in JsonData)
{
foreach (var itemInfo in item.detail)
{
if (item.isChecked == "1")
{
string sqlICSCheck = @"update ICSCheck set Quantity=(select SUM(Quantity) from ICSCheck WHERE InvCode='{5}' AND WHCode='{6}') + '{0}' ,MUSER='{1}'
,MUSERName=(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}' and F_Location='{3}')
,MTIME='{2}' where WorkPoint='{3}' and CheckCode='{4}' and InvCode='{5}' AND WHCode='{6}'";
sqlICSCheck = string.Format(sqlICSCheck, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint, item.CheckCode, item.InvCode, item.WHCode);
cmd.CommandText = sqlICSCheck;
num = cmd.ExecuteNonQuery();
string SQLDetail = @" SELECT * FROM ICSCheckDetail WHERE LotNo='{0}' and WorkPoint='{1}'";
SQLDetail = string.Format(SQLDetail, itemInfo.LotNo, item.WorkPoint);
DataTable data = DBHelper.SQlReturnData(SQLDetail, cmd);
if (data.Rows.Count <= 0)
{
string SQLInertDetail = @"insert into ICSCheckDetail( ID,CheckCode,LotNo,Quantity,ActualQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
(select newid(),'{0}','{1}' ,a.Quantity,'{2}','{3}',b.F_RealName,'{4}','{5}',''
from ICSWareHouseLotInfo a
left join Sys_SRM_User b on F_Account='{3}' and F_Location='{5}'
where a.LotNo='{1}' and a.WorkPoint='{5}')";
SQLInertDetail = string.Format(SQLInertDetail, item.CheckCode, itemInfo.LotNo, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint);
cmd.CommandText = SQLInertDetail;
num = cmd.ExecuteNonQuery();
}
else
{
sql = @"update ICSCheckDetail set ActualQuantity=(select ActualQuantity from ICSCheckDetail where CheckCode='{2}' and LotNo='{3}') +'{0}',MUSER='{4}'
,MUSERName=(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{4}' and F_Location='{1}')
,MTIME='{5}'
where WorkPoint='{1}' and CheckCode='{2}' and LotNo='{3}'";
sql = string.Format(sql, itemInfo.ActualQuantity, item.WorkPoint, item.CheckCode, itemInfo.LotNo, item.User, DateTime.Now);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
}
string LotInfo = @"update ICSWareHouseLotInfo set Quantity= (select sum(Quantity) from ICSWareHouseLotInfo where LotNo='{3}'and WorkPoint='{4}')+'{0}',MUSER='{1}',
MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}') ,MTIME='{2}' where LotNo='{3}' and WorkPoint='{4}'";
LotInfo = string.Format(LotInfo, itemInfo.ActualQuantity, item.User, DateTime.Now, itemInfo.LotNo, item.WorkPoint);
cmd.CommandText = LotInfo;
num = cmd.ExecuteNonQuery();
string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{5}'
,''
,'{0}'
,'{6}'
,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
,''
,''
,'{1}'
,''
,''
,'19'
,''
,''
,''
,''
,''
,'{2}'
,(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}')
,'{3}'
,'{4}'
,'')";
sqlLog = string.Format(sqlLog, itemInfo.LotNo, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint, item.CheckCode, item.InvCode);
cmd.CommandText = sqlLog;
num = cmd.ExecuteNonQuery();
if (num > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
else
{
string SQLDetail = @" SELECT * FROM ICSCheckDetail WHERE LotNo='{0}' and WorkPoint='{1}'";
SQLDetail = string.Format(SQLDetail, itemInfo.LotNo, item.WorkPoint);
DataTable data = DBHelper.SQlReturnData(SQLDetail, cmd);
if (data.Rows.Count <= 0)
{
string SQLInertDetail = @"insert into ICSCheckDetail( ID,CheckCode,LotNo,Quantity,ActualQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
(select newid(),'{0}','{1}' ,a.Quantity,'{2}','{3}',b.F_RealName,'{4}','{5}',''
from ICSWareHouseLotInfo a
left join Sys_SRM_User b on F_Account='{3}' and F_Location='{5}'
where a.LotNo='{1}' and a.WorkPoint='{5}')";
SQLInertDetail = string.Format(SQLInertDetail, item.CheckCode, itemInfo.LotNo, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint);
cmd.CommandText = SQLInertDetail;
num = cmd.ExecuteNonQuery();
}
else
{
sql = @"update ICSCheckDetail set ActualQuantity=(select ActualQuantity from ICSCheckDetail where CheckCode='{2}' and LotNo='{3}') +'{0}',MUSER='{4}'
,MUSERName=(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{4}' and F_Location='{1}')
,MTIME='{5}'
where WorkPoint='{1}' and CheckCode='{2}' and LotNo='{3}'";
sql = string.Format(sql, itemInfo.ActualQuantity, item.WorkPoint, item.CheckCode, itemInfo.LotNo, item.User, DateTime.Now);
cmd.CommandText = sql;
num = cmd.ExecuteNonQuery();
}
if (num > 0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
}
}
return num;
}
catch (Exception ex)
{
//cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 调拨单
public string TransferDocupdte(TransferDoc JsonData)
{
List deliveryNotrModel = new List();
ICSCheck model = new ICSCheck();
DataTable dt = null;
DataTable dtInfo = null;
DataTable dtInfoModel = null;
string sqlInsert;
string sqlNum;
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
int num;
try
{
string sql = string.Empty;
string sqlInfo = string.Empty;
string sqlList = string.Empty;
//验证数量是否大于调拨数量
sql = @"select Quantity from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, JsonData.Lotno, JsonData.WorkPoint);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count <= 0)
{
throw new Exception("查无数据!");
}
foreach (DataRow dr in dt.Rows)
{
TransferDoc main = new TransferDoc();
main.Quantity = Convert.ToInt32(dr["Quantity"]);
if (main.Quantity < JsonData.Quantity)
{
throw new Exception("输入数量小于库存数量不能调拨!");
}
}
///查询调拨的库位是否存在
sqlInfo = @"select * from ICSLocation where LocationCode='{0}' and WorkPoint='{1}' ";
sqlInfo = string.Format(sqlInfo, JsonData.LocationCode, JsonData.WorkPoint);
dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
if (dtInfo.Rows.Count <= 0)
{
throw new Exception("目标库位不存在,请输入正确的目标库位!");
}
sqlNum = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}' ";
sqlNum = string.Format(sqlNum, JsonData.Lotno, JsonData.WorkPoint);
dtInfoModel = DBHelper.SQlReturnData(sqlNum, cmd);
if (dtInfoModel.Rows.Count < 0)
{
throw new Exception("条码不存在!");
}
bool isTransfer = verification.isTransfer(JsonData.TransCode, JsonData.TransSequence, JsonData.Quantity, JsonData.Lotno, JsonData.WarehouseCode, JsonData.LocationCode, JsonData.WorkPoint);
if (isTransfer == true)
{
string updateSql = @"update ICSTransfer set TransferQuantity ='{0}' where TransferNO='{1}' and Sequence='{2}' and WorkPoint='{3}'";
updateSql = string.Format(updateSql, JsonData.Quantity, JsonData.TransCode, JsonData.TransSequence, JsonData.WorkPoint);
cmd.CommandText = updateSql;
num = cmd.ExecuteNonQuery();
string HouseSql = @" update ICSWareHouseLotInfo set WarehouseCode='{0}',LocationCode='{1}' where LotNo='{2}' and WorkPoint='{3}' ";
HouseSql = string.Format(HouseSql, JsonData.WarehouseCode, JsonData.LocationCode, JsonData.Lotno, JsonData.WorkPoint);
cmd.CommandText = HouseSql;
num = cmd.ExecuteNonQuery();
sqlInsert = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
VALUES
(newid()
,'{0}'--TransCode
,'null'
,'{1}'
,(select InvCode from ICSWareHouseLotInfo where LotNo='{1}' )
,(select WarehouseCode from ICSWareHouseLotInfo where LotNo='{1}')
,(select LocationCode from ICSWareHouseLotInfo where LotNo='{1}')
,'null'--LocationCode
,'{2}'--LocationCode
,'{3}'--Quantity
,'null'
,0
,6
,'13'
,'null'
,'null'
,'null'
,'null'
,'{4}'
,'{4}'
,'{5}'
,'{6}'
,'null')";
sqlInsert = string.Format(sqlInsert, JsonData.TransCode, JsonData.Lotno, JsonData.LocationCode, JsonData.Quantity, JsonData.User, DateTime.Now, JsonData.WorkPoint);
cmd.CommandText = sqlInsert;
num = cmd.ExecuteNonQuery();
if (num > 0)
{
//throw new Exception("");
cmd.Transaction.Commit();
string ing = "成功 ";
return ing;
}
else
{
cmd.Transaction.Rollback();
}
}
return null;
}
catch (Exception ex)
{
// cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
#endregion
#region 接口调用
public static string HttpPost(string apiName, string url, string body)
{
try
{
Encoding encoding = Encoding.UTF8;
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.Method = "POST";
request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
// request.ContentType = "text/html, application/xhtml+xml";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
{
return reader.ReadToEnd();
}
}
catch (System.Net.WebException ex)
{
throw new Exception(apiName + "调用失败," + ex.Message);
}
}
#endregion
#region logIn
public object CheckLogin(Sys_SRM_User userModel)
{
List userLogOnEntity = new List();
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
DataTable dt;
try
{
sql = @"select * from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 0)//查询的数据不为空
{
sqlInfo = @" select a.[F_Id] as UserId
,[F_Account] as userCode
,[F_RealName] as UserName
,[F_NickName]
,b.F_UserPassword
,b.F_UserSecretkey
,[F_HeadIcon]
,[F_Gender]
,[F_Birthday]
,[F_MobilePhone]
,[F_Email]
,[F_WeChat]
,[F_ManagerId]
,[F_SecurityLevel]
,[F_Signature]
,[F_OrganizeId]
,[F_DepartmentId]
,[F_RoleId]
,[F_DutyId]
,[F_IsAdministrator]
,[F_SortCode]
,[F_DeleteMark]
,[F_EnabledMark]
,[F_Description]
,[F_CreatorTime]
,[F_CreatorUserId]
,[F_LastModifyTime]
,[F_LastModifyUserId]
,[F_DeleteTime]
,[F_DeleteUserId]
,[F_Location] as WorkPoint
,[F_VenCode]
from Sys_SRM_User a
left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
sqlInfo = string.Format(sqlInfo, userModel.UserCode, userModel.WorkPoint);
dt = DBHelper.SQlReturnData(sqlInfo, cmd);
IList users = DBHelper.ModelConvertHelper.ConvertToModel(dt);
// string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
foreach (var item in users)
{
//string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
if (dbPassword == item.F_UserPassword)
{
string json = JsonConvert.SerializeObject(dt);
userLogOnEntity = JsonConvert.DeserializeObject>(json);
return userLogOnEntity;
}
else
{
throw new Exception("密码不正确,请重新输入");
}
}
}
else
{
throw new Exception("用户名不存在,请重新输入!");
}
//cmd.CommandText = sql;
//int num = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
return null;
}
#endregion
}
}