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

365 lines
17 KiB

using NFine.Data.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using NFine.Code;
using NFine.Repository;
using System.Data.Common;
using NFine.Domain._03_Entity.SRM;
using Newtonsoft.Json;
using System.Configuration;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
namespace NFine.Application.WMS
{
public class BlitemApp : RepositoryFactory<ICSVendor>
{
public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
#region [SQL]
string sql = @"SELECT ID, CheckCode, SelectLevel, Status, Quantity, Amount, MUSER, MUSERName, MTIME, WorkPoint
FROM dbo.ICSCheck";
sql += " WHERE 1=1";
sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
#endregion
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
{
sql += " and CheckCode like '%" + queryParam["POCode"].ToString() + "%' ";
}
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
{
sql += " and WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
{
sql += " and VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
}
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetSubGridJson(string ID, string Sequence, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = @" SELECT distinct a.ID, b.InvCode,
b.InvName ,
b.InvStd ,
a.LotNo,
a.Quantity,
d.WarehouseCode,
d.LocationCode,
a.PrimaryQuantity,
a.PrimaryAmount,
a.ReplayQuantity,
a.ReplayAmount,
a.CheckQuantity,
a.CheckAmount
FROM ICSCheckDetail a
left join ICSInventoryLot c on a.LotNo=c.LotNO and a.WorkPoint=c.WorkPoint
left join ICSInventory b on c.InvCode=b.InvCode AND c.WorkPoint=b.WorkPoint
left join ICSWareHouseLotInfo d on c.LotNO=d.LotNO AND c.WorkPoint=d.WorkPoint
WHERE a.CheckID='" + ID + "' and a.WorkPoint in ('" + WorkPoint + "')";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public string DeleteICSCheckDetail(string ID)
{
//站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string msg = "";
string sql = string.Empty;
try
{
sql = string.Format(@"DELETE FROM ICSCheckDetail WHERE ID ='{0}' and WorkPoint ='{1}'", ID, WorkPoint);
SqlHelper.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return msg;
}
/// <summary>
/// 获取仓库
/// </summary>
/// <returns></returns>
public DataTable GetWHCode()
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = @" select '' as ID,'' as WarehouseName union all
SELECT ID+'|'+WarehouseCode,WarehouseName FROM ICSWarehouse WITH (NOLOCK) WHERE WorkPoint = '{0}' ";
sql = string.Format(sql, WorkPoint);
//string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
//if (role != "admin")
//{
// sql += " and b.WorkPoint='" + WorkPoint + "'";
//}
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
public DataTable GetQU(string WHCodeID)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = @" select '' as QUValue,'' as QUName union all
SELECT Region as QUValue,Region+'区' as QUName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}'
";
sql = string.Format(sql, WHCodeID, WorkPoint);
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
//public DataTable GetQU(string WHCodeID)
//{
// string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
// string sql = @"SELECT Region as QUValue,Region+'区' as QUName FROM ICSLocation WHERE WHID = '{0}' AND WorkPoint='{1}'";
// sql = string.Format(sql, WHCodeID, WorkPoint);
// DataTable dt = Repository().FindTableBySql(sql);
// return dt;
//}
public DataTable GetPai(string WHCodeID, string Qu)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = @" select '' as PaiValue,'' as PaiName union all
SELECT Row as PaiValue,Row+'排' as PaiName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}'
";
sql = string.Format(sql, WHCodeID, WorkPoint, Qu);
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
public DataTable GetHuoJia(string WHCodeID, string Qu, string Pai)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = @" select '' as HuoJiaValue,'' as HuoJiaName union all
SELECT GoodsShelf as HuoJiaValue,GoodsShelf +'货架' as HuoJiaName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}'
";
sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai);
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
public DataTable GetCeng(string WHCodeID, string Qu, string Pai, string HuoJia)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = @" select '' as CengValue,'' as CengName union all
SELECT Tier as CengValue,Tier +'层' as CengName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}' and GoodsShelf ='{4}'
";
sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai, HuoJia);
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
public DataTable GetGe(string WHCodeID, string Qu, string Pai, string HuoJia, string Ceng)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string sql = @" select '' as GeValue,'' as GeName union all
SELECT Grid as GeValue,Grid +'格' as GeName FROM ICSLocation WITH (NOLOCK) WHERE WHID = '{0}' AND WorkPoint='{1}' and Region='{2}' and Row='{3}' and GoodsShelf ='{4}' and Tier='{5}'
";
sql = string.Format(sql, WHCodeID, WorkPoint, Qu, Pai, HuoJia, Ceng);
DataTable dt = SqlHelper.GetDataTableBySql(sql);
return dt;
}
public string AddICSCheck(string Parameter)
{
string msg = "";
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Check/Create";
string result = HttpPost(APIURL, Parameter);
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;
}
//接口api解析
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);
}
}
public string DeleteICSCheck(string keyValue)
{
//站点信息
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string msg = "";
keyValue = keyValue.Substring(1, keyValue.Length - 2);
string sql = string.Empty;
try
{
sql += string.Format(@" IF EXISTS(SELECT CheckID FROM ICSCheckDetail WHERE CheckID in ({0}) )
BEGIN
RAISERROR('该盘点计划已存在盘点明细信息,无法删除!',16,1);
RETURN
END
DELETE FROM dbo.ICSCheck WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
sql += string.Format(@"DELETE FROM dbo.ICSCheckDetail WHERE CheckID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
SqlHelper.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}
public DataTable GetGridJsonWarehouse(string queryJson, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
#region [SQL]
string sql = @"select distinct ID, WarehouseCode as SelectLevel ,WarehouseCode,WarehouseName from ICSWarehouse";
sql += " WHERE 1=1";
sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
#endregion
if (!string.IsNullOrWhiteSpace(queryJson))
{
if (!string.IsNullOrWhiteSpace(queryParam["WarehouseCode"].ToString()))
{
sql += " and WarehouseCode like '%" + queryParam["WarehouseCode"].ToString() + "%' ";
}
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
{
sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
}
if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
{
sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
}
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetSubGridJsonRegion(string ID, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = @" select distinct b.WarehouseCode+'-'+a.Region as SelectLevel, a.WHID, b.WarehouseCode,a.Region from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
WHERE a.WHID='" + ID + "' and a.WorkPoint in ('" + WorkPoint + "')";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetSubGridJsonRow(string WHID, string Region, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row
from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and isnull(a.Row,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetSubGridJsonGoodsShelf(string WHID, string Region, string Row, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'')+'-'+isnull(a.GoodsShelf,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row,a.GoodsShelf
from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and a.Row='" + Row + "' and isnull(a.GoodsShelf,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetSubGridJsonTier(string WHID, string Region, string Row, string GoodsShelf, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'')+'-'+isnull(a.GoodsShelf,'') +'-'+isnull(a.Tier,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row,a.GoodsShelf ,a.Tier
from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and a.Row='" + Row + "' and a.GoodsShelf='" + GoodsShelf + "' and isnull(a.Tier,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
public DataTable GetSubGridJsonGrid(string WHID, string Region, string Row, string GoodsShelf, string Tier, ref Pagination jqgridparam)
{
DataTable dt = new DataTable();
//var queryParam = queryJson.ToJObject();
List<DbParameter> parameter = new List<DbParameter>();
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
string sql = @" select distinct isnull(b.WarehouseCode,'')+'-'+isnull(a.Region,'')+'-'+isnull(a.Row,'')+'-'+isnull(a.GoodsShelf,'') +'-'+isnull(a.Tier,'') as SelectLevel, a.WHID, b.WarehouseCode,a.Region ,a.Row ,a.GoodsShelf ,a.Tier,a.Grid
from ICSLocation a left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint
WHERE a.WHID='" + WHID + "' and a.Region='" + Region + "' and a.Row='" + Row + "' and a.Tier='" + Tier + "' and a.GoodsShelf='" + GoodsShelf + "' and isnull(a.Grid,'') !='' and a.WorkPoint in ('" + WorkPoint + "')";
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
}
}
}