纽威
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.
 
 
 
 
 

316 lines
15 KiB

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NFine.Code;
using NFine.Data.Extensions;
using NFine.Domain._03_Entity.SRM;
using NFine.Domain.Entity.ProductManage;
using NFine.Domain.IRepository.ProductManage;
using NFine.Repository;
using NFine.Repository.ProductManage;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
namespace NFine.Application
{
public class POMaintenanceApp : RepositoryFactory<ICSPO_PoMain>
{
public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @" SELECT DISTINCT a.ID, a.POCode,CONVERT(NVARCHAR(15),CreateDateTime,23) AS PODate,ExtensionID,a.VenCode,d.VenName,ReleaseState,a.WorkPoint,c.WorkPointName,b.PlanArriveDate
FROM dbo.ICSPurchaseOrder a
LEFT JOIN (SELECT POCode,PlanArriveDate,WorkPoint FROM dbo.ICSPurchaseOrder) b ON a.POCode=b.POCode and a.WorkPoint=b.WorkPoint
LEFT JOIN Sys_WorkPoint c on a.WorkPoint=c.WorkPointCode
left join ICSVendor d on a.VenCode=d.VenCode and a.WorkPoint=d.WorkPoint
WHERE 1=1 and ReleaseState='1'";
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["ORDERNO"].ToString()))
{
sql += " and a.ExtensionID like '%" + queryParam["ORDERNO"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
{
sql += " and a.POCode like '%" + queryParam["POCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["BeginDate"].ToString()))
{
sql += " and a.PODate >='" + queryParam["BeginDate"].ToString() + "' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
{
sql += " and a.PODate <='" + queryParam["EndDate"].ToString() + "'";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
{
sql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
{
sql += " and a.VenName like '%" + queryParam["VenName"].ToString() + "%'";
}
if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
{
string POStatus = queryParam["POStatus"].ToString();
if (POStatus == "1")
{
sql += " AND a.ArriveDate IS not NULL";
}
else if(POStatus=="2")
{
sql += " AND a.ArriveDate IS NULL";
}
}
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
{
sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode != "admin")
{
//已改多站点
sql += " and WorkPoint in (" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + ")";
}
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetGridJsonWeiWai(string queryJson, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @" SELECT DISTINCT a.ID, a.OOCode,CONVERT(NVARCHAR(15),CreateDateTime,23) AS PODate,ExtensionID,a.VenCode,d.VenName,ReleaseState,a.WorkPoint,c.WorkPointName,a.PlanArriveDate
FROM dbo.ICSOutsourcingOrder a
LEFT JOIN Sys_WorkPoint c on a.WorkPoint=c.WorkPointCode
left join ICSVendor d on a.VenCode=d.VenCode and a.WorkPoint=d.WorkPoint
WHERE 1=1 and ReleaseState='1'";
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["ORDERNO"].ToString()))
{
sql += " and a.ExtensionID like '%" + queryParam["ORDERNO"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
{
sql += " and a.OOCode like '%" + queryParam["POCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["BeginDate"].ToString()))
{
sql += " and a.PODate >='" + queryParam["BeginDate"].ToString() + "' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
{
sql += " and a.PODate <='" + queryParam["EndDate"].ToString() + "'";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
{
sql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
}
if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
{
sql += " and a.VenName like '%" + queryParam["VenName"].ToString() + "%'";
}
if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
{
string POStatus = queryParam["POStatus"].ToString();
if (POStatus == "1")
{
sql += " AND a.ArriveDate IS not NULL";
}
else if (POStatus == "2")
{
sql += " AND a.ArriveDate IS NULL";
}
}
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
{
sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode != "admin")
{
//已改多站点
sql += " and WorkPoint in (" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + ")";
}
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
/// <summary>
/// 子表查询
/// </summary>
/// <param name="queryJson"></param>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetSubGridJson(string queryJson, ref Pagination jqgridparam,string WorkPoint)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @"SELECT a.POCode, a.ID, a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.Quantity,CONVERT(NVARCHAR(50), a.PlanArriveDate,23) as PreArriveDate,
CONVERT(NVARCHAR(50),a.ArriveDate,23) as ArriveDate ,a.ExtensionID, CONVERT(NVARCHAR(50),a.DeliveryDate,23) as DeliveryDate,
case when isnull(a.ArriveDate,'')='' then '0' else '1' end as IsNew,
b.ClassName,b.InvDesc
FROM dbo.ICSPurchaseOrder a
left JOIN dbo.ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ID='" + queryJson + "' and a.WorkPoint='"+ WorkPoint + "'";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
/// <summary>
/// 子表查询
/// </summary>
/// <param name="queryJson"></param>
/// <param name="jqgridparam"></param>
/// <returns></returns>
public DataTable GetSubGridJsonWeiWai(string queryJson, ref Pagination jqgridparam,string WorkPoint)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string sql = @" SELECT a.OOCode, a.ID, a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.Quantity,CONVERT(NVARCHAR(50), a.PlanArriveDate,23) as PreArriveDate,
CONVERT(NVARCHAR(50),a.ArriveDate,23) as ArriveDate ,a.ExtensionID, CONVERT(NVARCHAR(50),a.DeliveryDate,23) as DeliveryDate,
case when isnull(a.ArriveDate,'')='' then '0' else '1' end as IsNew,
b.ClassName,b.InvDesc
FROM dbo.ICSOutsourcingOrder a
left JOIN dbo.ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ID='" + queryJson + "' and a.WorkPoint='"+ WorkPoint + "'";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
/// <summary>
/// 订单发布
/// </summary>
/// <param name="queryJson">参数</param>
/// <returns></returns>
public int SubmitPoMaintenance(string queryJson)
{
DataTable dt = new DataTable();
List<DbParameter> parameter = new List<DbParameter>();
ICSPO_PoMain[] list = JsonConvert.DeserializeObject<ICSPO_PoMain[]>(queryJson);
string sql = string.Empty;
//已改多站点
//string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
foreach (var obj in list)
{
if (!string.IsNullOrWhiteSpace(obj.DeliveryDate))
{
sql += ",DeliveryDate='" + obj.DeliveryDate + "' ,DeliveryUser='" + UserCode + "'";
}
if (obj.IsNew == "0")
{
if (!string.IsNullOrWhiteSpace(obj.ArriveDate))
sql += ",ArriveDate='" + obj.ArriveDate + "',ArriveUser='" + UserCode + "',MTIME=getdate() ";
}
sql += " where ID='" + obj.ID + "' and WorkPoint='" + obj.WorkPoint + "'";
sql += " \r\n";
sql = "update ICSPurchaseOrder set "+sql.Substring(1);
}
string U9ConnStr = "";
foreach (var obj in list)
{
if (obj.WorkPoint== "UFDATA_206_2019")
{
U9ConnStr= ConfigurationManager.ConnectionStrings["U8connstr2"].ConnectionString;
}
if (obj.WorkPoint == "UFDATA_106_2019")
{
U9ConnStr = ConfigurationManager.ConnectionStrings["U8connstr"].ConnectionString;
}
string sqlU9 = string.Format(@"update b
set b.cDefine28='" + obj.ArriveDate + @"'
from dbo.PO_Pomain a left join dbo.po_podetails b on a.POID=b.POID
where a.cPOID='" + obj.POCode + "' and b.ivouchrowno='" + obj.PORow + "'");
sqlU9 += "\r\n";
sqlU9 += string.Format(@"update b
set b.cDefine29='" + obj.DeliveryDate + @"'
from dbo.PO_Pomain a left join dbo.po_podetails b on a.POID=b.POID
where a.cPOID='" + obj.POCode + "' and b.ivouchrowno='" + obj.PORow + "'");
int i = SqlHelper.ExecuteNonQuery(U9ConnStr, sqlU9);
}
StringBuilder Str = new StringBuilder(sql);
return Repository().ExecuteBySql(Str);
}
/// <summary>
/// 订单发布
/// </summary>
/// <param name="queryJson">参数</param>
/// <returns></returns>
public int SubmitFormWeiWai(string queryJson)
{
DataTable dt = new DataTable();
List<DbParameter> parameter = new List<DbParameter>();
ICSPO_PoMain[] list = JsonConvert.DeserializeObject<ICSPO_PoMain[]>(queryJson);
string sql = string.Empty;
//已改多站点
//string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
foreach (var obj in list)
{
if (!string.IsNullOrWhiteSpace(obj.DeliveryDate))
{
sql += ",DeliveryDate='" + obj.DeliveryDate + "' ,DeliveryUser='" + UserCode + "'";
}
if (obj.IsNew == "0")
{
if (!string.IsNullOrWhiteSpace(obj.ArriveDate))
sql += ",ArriveDate='" + obj.ArriveDate + "',ArriveUser='" + UserCode + "',MTIME=getdate() ";
}
sql += " where ID='" + obj.ID + "' and WorkPoint='" + obj.WorkPoint + "'";
sql += " \r\n";
sql = "update ICSOutsourcingOrder set " + sql.Substring(1);
}
string U9ConnStr = "";
foreach (var obj in list)
{
if (obj.WorkPoint == "UFDATA_206_2019")
{
U9ConnStr = ConfigurationManager.ConnectionStrings["U8connstr2"].ConnectionString;
}
if (obj.WorkPoint == "UFDATA_106_2019")
{
U9ConnStr = ConfigurationManager.ConnectionStrings["U8connstr"].ConnectionString;
}
string sqlU9 = string.Format(@"update b
set b.cDefine28='" + obj.ArriveDate + @"'
from dbo.PO_Pomain a left join dbo.po_podetails b on a.POID=b.POID
where a.cPOID='" + obj.POCode + "' and b.ivouchrowno='" + obj.PORow + "'");
sqlU9 += "\r\n";
sqlU9 += string.Format(@"update b
set b.cDefine29='" + obj.DeliveryDate + @"'
from dbo.PO_Pomain a left join dbo.po_podetails b on a.POID=b.POID
where a.cPOID='" + obj.POCode + "' and b.ivouchrowno='" + obj.PORow + "'");
int i = SqlHelper.ExecuteNonQuery(U9ConnStr, sqlU9);
}
StringBuilder Str = new StringBuilder(sql);
return Repository().ExecuteBySql(Str);
}
}
}