纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

700 lines
37 KiB

using NFine.Data.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NFine.Code;
using NFine.Repository;
using System.Data.Common;
using NFine.Domain._03_Entity.SRM;
using ICS.Application.Entity;
using Newtonsoft.Json;
using System.Configuration;
using System.Data.SqlClient;
using ICS.Data;
using Newtonsoft.Json.Linq;
using NFine.Domain._03_Entity.WMS;
using System.Net;
using System.IO;
namespace NFine.Application.WMS
{
public class ICSRCVIQCsApp:RepositoryFactory<ICSVendor>
{
/// <summary>
/// 采购
/// </summary>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetICSInspection(ref Pagination jqgridparam, string queryJson)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @" select
a.ID as DHID,
d.ID ,
h.ID as JYID,
a.DNCode ,
a.Sequence ,
a.ASNCode ,
l.POCode,
c.InvCode ,
c.InvName ,
c.INVSTD ,
c.ClassName,
CAST(b.DNQuantity as decimal(18,4)) as AllNumber,
CAST(ISNULL(h.QualifiedQuantity, b.DNQuantity)as decimal(18,4))as YLOTQTY ,
CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
c.InvUnit ,
b.LotNo ,
g.BadReasonDesc as BadReasonDesc ,
g.BadReasonCode as BRCodeValue,
j.BadCode as BCCodeValue,
j.BadDesc as BadDesc,
k.ContainerID,
isnull(h.MUSERName,'开发者') MUSERName,
CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
CONVERT(VARCHAR(100),a.CreateDateTime,23) as CreateDateTime,
CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState,
a.VenCode,
m.VenName,
isnull(h.MUSER,'') as Surveyor,
h.MUSERName as ProvingTime
,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
FROM ICSDeliveryNotice a
inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND d.WorkPoint=l.WorkPoint
left join ICSExtension f on l.ExtensionID=f.ID and l.WorkPoint=f.WorkPoint
left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
where b.LotNo is not null and a.DNType='1' {0}
";
#region 无srm逻辑
// sql = @"UNION all
//select
// a.ID as DHID,
// d.ID ,
// h.ID as JYID,
// a.DNCode ,
// a.Sequence ,
// a.ASNCode ,
// c.InvCode ,
// c.InvName ,
// c.INVSTD ,
// c.ClassName,
// f.BatchCode ,
// CAST(d.Quantity as decimal(18,4)) as AllNumber,
// CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY ,
// CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
// CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
// c.InvUnit ,
// d.LotNo ,
// g.BadReasonDesc as BadReasonDesc ,
// g.BadReasonCode as BRCodeValue,
// j.BadCode as BCCodeValue,
// j.BadDesc as BadDesc,
// k.ContainerID,
// isnull(h.MUSERName,'开发者') MUSERName,
// CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
// CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
// CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState
// FROM ICSDeliveryNotice a
// inner join ICSInventoryLotDetail e on e.TransCode =a.DNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
// inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
// LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
// LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
// left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
// left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
// LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
// left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
// where a.DNType='1' {0}";
#endregion
string wheresql = "";
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
{
wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
{
wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
{
wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
{
wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
{
wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
{
wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
{
wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
{
wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
{
string ReleaseState = queryParam["ReleaseState"].ToString();
if (ReleaseState == "1")
wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
else if (ReleaseState == "0")
wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
}
}
sql = string.Format(sql, wheresql);
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
//委外
public DataTable GetICSInspection2(ref Pagination jqgridparam, string queryJson)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @" select
a.ID as DHID,
d.ID ,
h.ID as JYID,
a.ODNCode as DNCode ,
a.Sequence ,
a.OASNCode ,
l.OOCode,
c.InvCode ,
c.InvName ,
c.INVSTD ,
c.ClassName,
f.BatchCode ,
CAST(b.ODNQuantity as NUMERIC(10,4)) as AllNumber,
CAST(ISNULL(h.QualifiedQuantity, b.ODNQuantity)as NUMERIC(10,4))as YLOTQTY ,
CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
c.InvUnit ,
b.LotNo ,
g.BadReasonDesc as BadReasonDesc ,
g.BadReasonCode as BRCodeValue,
j.BadCode as BCCodeValue,
j.BadDesc as BadDesc,
k.ContainerID,
isnull(h.MUSERName,'开发者') MUSERName,
CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
CONVERT(VARCHAR(100),a.CreateDateTime,23) as CreateDateTime,
CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState,
a.VenCode,
m.VenName,
isnull(h.MUSER,'') as Surveyor,
h.MUSERName as ProvingTime
FROM ICSODeliveryNotice a
LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
left join ICSExtension f on l.ExtensionID=f.ID and l.WorkPoint=f.WorkPoint
left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! ='' AND ISNULL(b.ODNQuantity, 0)<>0 {0}
";
#region 无SRM逻辑
// sql = @"UNION all
//select
// a.ID as DHID,
// d.ID ,
// h.ID as JYID,
// a.ODNCode as DNCode ,
// a.Sequence ,
// a.OASNCode ,
// c.InvCode ,
// c.InvName ,
// c.INVSTD ,
// c.ClassName,
// f.BatchCode ,
// CAST(d.Quantity as NUMERIC(10,4)) as AllNumber,
// CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY ,
// CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
// CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
// c.InvUnit ,
// d.LotNo ,
// g.BadReasonDesc as BadReasonDesc ,
// g.BadReasonCode as BRCodeValue,
// j.BadCode as BCCodeValue,
// j.BadDesc as BadDesc,
// k.ContainerID,
// isnull(h.MUSERName,'开发者') MUSERName,
// CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
// CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
// CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState
// FROM ICSODeliveryNotice a
// inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
// inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
// LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
// LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
// left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
// left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
// LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
// left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
// where 1=1 {0}";
#endregion
string wheresql = "";
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
{
wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
{
wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
{
wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
{
wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
{
wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
{
wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
{
wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
{
wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
{
string ReleaseState = queryParam["ReleaseState"].ToString();
if (ReleaseState == "1")
wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
else if (ReleaseState == "0")
wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
}
}
sql = string.Format(sql, wheresql);
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
//工单
public DataTable GetICSInspection3(ref Pagination jqgridparam, string queryJson)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @"select
a.ID as GDID,
e.ID ,
a.MOCode as DNCode,
a.Sequence ,
h.ID as JYID,
c.InvCode ,
c.InvName ,
c.INVSTD ,
c.ClassName,
f.BatchCode ,
e.Quantity as AllNumber,
CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
c.InvUnit ,
e.LotNo ,
g.BadReasonDesc as BadReasonDesc ,
g.BadReasonCode as BRCodeValue,
j.BadCode as BCCodeValue,
j.BadDesc as BadDesc,
i.ContainerID,
isnull(h.MUSERName,'开发者') MUSERName,
CONVERT(VARCHAR(100),e.ProductDate,23) as ProductTime,
CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState,
isnull(h.MUSER,'') as Surveyor,
h.MUSERName as ProvingTime
from ICSMO a
left JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint
left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
LEFT JOIN dbo.ICSInspection h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint
left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
where e.LotNO is not null {0} ";
string wheresql = "";
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
{
wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
{
wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
{
wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
{
wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
{
string ReleaseState = queryParam["ReleaseState"].ToString();
if (ReleaseState == "1")
wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
else if (ReleaseState == "0")
wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
}
}
sql = string.Format(sql, wheresql);
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
//获取不良原因
public DataTable Select_ICSBadReason(string InvCode)
{
string sql = string.Empty;
DataTable dt = null;
sql = @"select '' as BadReasonCode,'' as BadReasonDesc from ICSBadReason a left join
ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
union
select a.BadReasonCode,a.BadReasonDesc from ICSBadReason a left join
ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
where b.InvCode='{0}'";
sql = string.Format(sql, InvCode);
dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
//获取不良代码
public DataTable GetSelectICSBadCode(string InvCode)
{
string sql = string.Empty;
DataTable dt = null;
sql = @"
select '' as BadCode ,'' as BadDesc
from dbo.ICSBadCode a left join
ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
union
select BadCode,BadDesc from dbo.ICSBadCode a left join
ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID where b.InvCode='{0}'";
// sql = @"select BadCode,BadDesc from dbo.ICSBadCode a left join
//ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
//where b.InvCode='{0}'";
sql = string.Format(sql, InvCode);
dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
/// <summary>
/// 新增检验
/// </summary>
/// <param name="queryJson"></param>
/// <returns></returns>
public string CreateICSInspection(string keyValue, string ICSInspections)
{
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string msg = "";
string sql = string.Empty;
JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
foreach (var item in res)
{
JObject jo = (JObject)item;
if (jo["TestState"].ToString()=="已检验")
{
sql += @"UPDATE dbo.ICSInspection set QualifiedQuantity='{0}',UnqualifiedQuantity='{1}',WaiveQuantity='{2}',BCCode='{3}',BRCode='{4}',MTIME=GETDATE(),MUSER='{5}',MUSERName='{6}',WorkPoint='{7}' WHERE ID='{8}'";
sql = string.Format(sql, jo["YLOTQTY"].ToString(), jo["NLOTQTY"].ToString(), jo["SpecialQTY"].ToString(), jo["BCCode"].ToString(), jo["BRCode"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["JYID"].ToString());
}
else
{
sql += @"INSERT INTO dbo.ICSInspection
( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint )
Values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}')
";
sql = string.Format(sql, jo["LotNo"].ToString(), jo["InvCode"].ToString(), jo["AllNumber"].ToString(), jo["YLOTQTY"].ToString(), jo["NLOTQTY"].ToString(), jo["SpecialQTY"].ToString(), jo["BCCode"].ToString(), jo["BRCode"].ToString(), jo["Type"].ToString(), MUSER, MUSERNAME, WorkPoint);
}
}
try
{
if (SqlHelper.ExecuteNonQuery(sql) > 0)
{
}
else
{
msg = "新增失败";
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return msg;
}
//生成采购拒收单
public string CreateRejection(string keyValue)
{
string msg = "";
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a
inner join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")";
DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo
from ICSDeliveryNotice a
left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
List<RejectionHead> asn = new List<RejectionHead>();
for (int i = 0; i < dt.Rows.Count; i++)
{
RejectionHead ass = new RejectionHead();
ass.VenCode = dt.Rows[i]["VenCode"].ToString();
ass.ID = dt.Rows[i]["DNID"].ToString();
ass.DepCode = dt.Rows[i]["DepCode"].ToString();
ass.DNCode = dt.Rows[i]["DNCode"].ToString();
ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
ass.MTIME = System.DateTime.Now.ToString("s");
ass.WorkPoint = WorkPoint;
DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'");
for (int j = 0; j < drs.Length; j++)
{
RejectionBody DetailList = new RejectionBody();
DetailList.Sequence = (j+1).ToString();
DetailList.InvCode = drs[j]["InvCode"].ToString();
DetailList.Quantity = drs[j]["Quantity"].ToString();
DetailList.Amount = drs[j]["Amount"].ToString();
DetailList.Currency = drs[j]["Currency"].ToString();
DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
DetailList.DNDetailID = drs[j]["DNDetailID"].ToString();
DetailList.LotNo = drs[j]["LotNo"].ToString();
ass.detail.Add(DetailList);
}
asn.Add(ass);
}
string input = JsonConvert.SerializeObject(asn);
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString+ "PurchaseRejectDoc/Create";
string result = HttpPost(APIURL, input);
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString();
string Success = Obj["Success"].ToString();
if (Success.ToUpper() == "FALSE")
{
msg = MessAge;
}
return msg;
}
//生成委外拒收单
public string CreateWWRejection(string keyValue)
{
string msg = "";
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a
left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ")";
DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,ODNDetailID,ODNID,b.LotNo
from ICSODeliveryNotice a
inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint
inner join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
List<WWRejectionHead> asn = new List<WWRejectionHead>();
for (int i = 0; i < dt.Rows.Count; i++)
{
WWRejectionHead ass = new WWRejectionHead();
ass.VenCode = dt.Rows[i]["VenCode"].ToString();
ass.ID = dt.Rows[i]["ODNID"].ToString();
ass.DepCode = dt.Rows[i]["DepCode"].ToString();
ass.ODNCode = dt.Rows[i]["ODNCode"].ToString();
ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
ass.MTIME = System.DateTime.Now.ToString("s");
ass.WorkPoint = WorkPoint;
DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'");
for (int j = 0; j < drs.Length; j++)
{
WWRejectionBody DetailList = new WWRejectionBody();
DetailList.Sequence = (j + 1).ToString();
DetailList.InvCode = drs[j]["InvCode"].ToString();
DetailList.Quantity = drs[j]["Quantity"].ToString();
DetailList.Amount = drs[j]["Amount"].ToString();
DetailList.Currency = drs[j]["Currency"].ToString();
DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString();
DetailList.LotNo = drs[j]["LotNo"].ToString();
ass.detail.Add(DetailList);
}
asn.Add(ass);
}
string input = JsonConvert.SerializeObject(asn);
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDoc/Create";
string result = HttpPost(APIURL, input);
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString();
string Success = Obj["Success"].ToString();
if (Success.ToUpper() == "FALSE")
{
msg = MessAge;
}
return msg;
}
public static string HttpPost(string url, string body)
{
try
{
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
{
return reader.ReadToEnd();
}
}
catch (WebException ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 删除拒收单
/// </summary>
/// <param name="keyValue">传入ID</param>
/// <returns></returns>
public string DelectRejection(string keyValue)
{
//站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string msg = "";
keyValue = keyValue.Substring(1, keyValue.Length - 2);
string sql = string.Empty;
sql = string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
try
{
SqlHelper.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return msg;
}
/// <summary>
/// 删除委外拒收单
/// </summary>
/// <param name="keyValue">传入ID</param>
/// <returns></returns>
public string DelectWWRejection(string keyValue)
{
//站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string msg = "";
keyValue = keyValue.Substring(1, keyValue.Length - 2);
string sql = string.Empty;
sql = string.Format(@"DELETE FROM dbo.ICSODeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
try
{
SqlHelper.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return msg;
}
}
}