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

487 lines
22 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;
using System.Data.SqlClient;
using ICS.Data;
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;
//}
/// <summary>
/// 新增盘点单接口
/// </summary>
/// <param name="Parameter"></param>
/// <returns></returns>
public string AddICSCheck(string Parameter)
{
string msg = "";
try
{
List<ICSCheck> model = JsonConvert.DeserializeObject<List<ICSCheck>>(Parameter.ToString());
if (model == null || model.Count<=0)
{
msg = "操作失败";
return msg;
}
string sql = string.Empty;
foreach (var item in model)
{
if (string.IsNullOrEmpty(item.User))
{
throw new Exception("操作人不能为空!");//"操作人不能为空!");
}
if (string.IsNullOrEmpty(item.WorkPoint))
{
throw new Exception("站点不能为空");//"站点不能为空!"
}
//创建盘点单
foreach (var itemInfo in item.Detail)
{
string Code = string.Empty;
//获取单号
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
BEGIN
RAISERROR('操作人不存在',16,1);
RETURN
END
DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
IF @MaxNO IS NULL
BEGIN
SELECT @date+'00001' AS Code
END
ELSE
BEGIN
SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
END ";
sql = string.Format(sql, item.User, item.WorkPoint);
Code = SqlHelper.ExecuteScalar(sql).ToString();
if (string.IsNullOrWhiteSpace(Code))
{
throw new Exception("盘点单号不能为空");//"盘点单单号不能为空!");
}
int len = itemInfo.SelectLevel.Length;
sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
BEGIN
RAISERROR('维护库位在库存中没有记录!',16,1);
RETURN
END
INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
FROM ICSWareHouseLotInfo a
INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
GROUP BY b.F_Account,b.F_RealName,b.F_Location";
sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
if (SqlHelper.ExecuteNonQuery(sql)<=0)
{
throw new Exception("盘点单创建失败");//"盘点单创建失败!");
}
}
}
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}
/// <summary>
///
/// </summary>
public class ICSCheck
{
/// <summary>
/// 用户
/// </summary>
public string User { get; set; }
/// <summary>
/// 操作时间
/// </summary>
public string MTIME { get; set; }
/// <summary>
///
/// 站点
/// </summary>
public string WorkPoint { get; set; }
/// <summary>
/// 详情
/// </summary>
public List<Detail> Detail { get; set; }
}
/// <summary>
///
/// </summary>
public class Detail
{
/// <summary>
/// 仓库编码
/// </summary>
public string SelectLevel { get; set; }
}
//接口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 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 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);
}
}
}