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.
800 lines
40 KiB
800 lines
40 KiB
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using NFine.Code;
|
|
using NFine.Data.Extensions;
|
|
using NFine.Domain._03_Entity.SRM;
|
|
using NFine.Repository;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Net;
|
|
using NFine.Application.WMS;
|
|
using NFine.Application.Models;
|
|
using System.Reflection;
|
|
using NFine.Application.Entity;
|
|
using NFine.Domain.Entity.SystemSecurity;
|
|
using System.Xml;
|
|
using System.Collections;
|
|
|
|
namespace NFine.Application.HGWMS
|
|
{
|
|
|
|
public class WMSCreateItemLotApp : RepositoryFactory<ICSVendor>
|
|
{
|
|
#region 获取工单主表数据
|
|
/// <summary>
|
|
/// 获取工单主表数据
|
|
/// </summary>
|
|
/// <param name="queryJson"></param>
|
|
/// <param name="jqgridparam"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetGridJsonChengPing(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
object Figure = GetDecimalDigits();
|
|
|
|
#region [SQL]
|
|
string sql = @" select distinct a.ID, a.MODetailID,a.MOCode,a.EATTRIBUTE5 AS ParentMOCode,a.Sequence,
|
|
CAST(a.RCVQuantity AS DECIMAL(38,{0})) as RCVQuantity ,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
|
|
CAST( a.Quantity AS DECIMAL(38,{0})) as Quantity,CAST( a.Amount as DECIMAL(38,{0})) as Amount,a.StartDate,a.WHCode,warehouse.WarehouseName as WHName
|
|
,a.DueDate,a.MOStatus,a.ExtensionID,a.MUSERName,a.MTIME ,a.MOMemo
|
|
,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,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,b.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
|
|
a.EATTRIBUTE9,a.EATTRIBUTE10,b.MTIME as TMTime,dep.DepName,a.CreateDateTime
|
|
from ICSMO a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
left join (
|
|
select MOCode,WorkPoint,InvCode,Sequence from ICSMOSubInventoryLot
|
|
group by MOCode,WorkPoint,InvCode,Sequence
|
|
)c
|
|
on a.MOCode=c.MOCode and a.Sequence=c.Sequence and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join ICSDepartment dep ON dep.DepCode=a.DepCode and a.WorkPoint=dep.WorkPoint
|
|
left join ICSWarehouse warehouse on a.WHCode=warehouse.WarehouseCode and a.WorkPoint=warehouse.WorkPoint ";
|
|
sql += " WHERE 1=1 and a.MOStatus<>'3' and b.ClassCode like 'P010%' ";
|
|
sql = string.Format(sql, Figure);
|
|
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
|
|
{
|
|
sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
|
|
{
|
|
sql += " and b.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["FromTime"].ToString()))
|
|
{
|
|
sql += " and a.StartDate >= '" + queryParam["FromTime"].ToString() + "' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["ToTime"].ToString()))
|
|
{
|
|
sql += " and a.StartDate < '" + queryParam["ToTime"].ToString() + "' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
|
|
{
|
|
string POStatus = queryParam["POStatus"].ToString();
|
|
if (POStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (POStatus == "1")
|
|
{
|
|
sql += " and c.MoCode is not null";
|
|
}
|
|
else
|
|
{
|
|
sql += " and c.MoCode is null ";
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHStatus"].ToString()))
|
|
{
|
|
string WHStatus = queryParam["WHStatus"].ToString();
|
|
if (WHStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (WHStatus == "1")
|
|
{
|
|
sql += " and a.Quantity-ISNULL(a.RCVQuantity,0)>0 ";
|
|
}
|
|
else
|
|
{
|
|
sql += " and a.Quantity-ISNULL(a.RCVQuantity,0)=0 ";
|
|
}
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["ParentMoCode"].ToString()))
|
|
{
|
|
sql += " AND a.EATTRIBUTE5 like '%" + queryParam["ParentMoCode"].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);
|
|
}
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 获取子线条码信息
|
|
/// </summary>
|
|
/// <param name="ApplyNegCode"></param>
|
|
/// <param name="Sequence"></param>
|
|
/// <param name="Type"></param>
|
|
/// <param name="isPrint"></param>
|
|
/// <param name="jqgridparam"></param>
|
|
/// <returns></returns>
|
|
public DataTable GetSubGridJson(string ApplyNegCode, string Sequence, string Type, string isPrint, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
object Figure = GetDecimalDigits();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @" select a.MOCode,a.Sequence ,a.ID,a.LotNo, CAST( a.Quantity AS DECIMAL(38,{0})) as Quantity ,a.MUSERName,a.MTIME
|
|
,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,
|
|
case when isnull(a.LastPrintUser,'')='' then '未打印' else '已打印' end as isPrint,
|
|
case when Isnull(g.InvIQC,'0')='1' then '否' else '是' end as isExemption,a.Amount,
|
|
convert(varchar(20),a.ProductDate,23) as ProductDate,convert(varchar(20),a.ExpirationDate,23) as ExpirationDate ,g.EffectiveDays
|
|
from ICSMOSubInventoryLot a
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join ICSInventory g on a.InvCode=g.InvCode and a.WorkPoint=g.WorkPoint
|
|
WHERE isnull(a.EATTRIBUTE1,'')='' and a.MOCode='" + ApplyNegCode + "' and a.Sequence='" + Sequence + "' and a.WorkPoint in ('" + WorkPoint + "')";
|
|
if (!string.IsNullOrWhiteSpace(isPrint))
|
|
{
|
|
if (isPrint == "0")
|
|
{
|
|
}
|
|
else if (isPrint == "1")
|
|
{
|
|
sql += " and isnull(LastPrintUser,'')<>''";
|
|
}
|
|
else
|
|
{
|
|
sql += " and isnull(LastPrintUser,'')=''";
|
|
}
|
|
}
|
|
|
|
sql = string.Format(sql, Figure);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成品生成子线条码
|
|
/// </summary>
|
|
/// <param name="POCode"></param>
|
|
/// <param name="PORow"></param>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public string SubmitFormChengPing(string keyValue)
|
|
{
|
|
|
|
try
|
|
{
|
|
var moModels = keyValue.ToList<MOModel>();
|
|
string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string sql = string.Empty;
|
|
string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
if (moModels.Count<1)
|
|
{
|
|
throw new Exception("请传入参数");
|
|
}
|
|
moModels.ForEach(moModel =>
|
|
{
|
|
|
|
//获取生成工单子线条码个数
|
|
string invsql = $@"SELECT InvCode,EATTRIBUTE20,Isnull(EATTRIBUTE6,0) as SubCount, (SELECT Batchcode FROM ICSExtension with (nolock) WHERE ID='{moModel.ExtensionID}') Batchcode FROM ICSInventory with (nolock) WHERE InvCode='{moModel.InvCode}' AND WorkPoint='{WorkPoints}' ; ";
|
|
var dt = SqlHelper.CmdExecuteDataTable(invsql);
|
|
if (dt.Rows.Count<=0)
|
|
{
|
|
throw new Exception("未查询到工单对应的物料信息,请确认");
|
|
}
|
|
string checksql = $@" SELECT top 1 ID FROM ICSMOSubInventoryLot WHERE MOCode='{moModel.MOCode}' AND sequence='{moModel.Sequence}' AND WorkPoint='{WorkPoints}' ";
|
|
var checkdt= SqlHelper.CmdExecuteDataTable(checksql);
|
|
if (checkdt.Rows.Count > 0)
|
|
{
|
|
throw new Exception($"工单{moModel.MOCode}已经生成子线条码,请勿重复生成!");
|
|
}
|
|
int subCount = dt.Rows[0]["SubCount"].ToInt();
|
|
if (subCount==0)
|
|
{
|
|
throw new Exception("请先确认物料上面生成子线数量是否同步!");
|
|
}
|
|
string Pre = $"{dt.Rows[0]["InvCode"]}~{dt.Rows[0]["EATTRIBUTE20"]}~"; //物料编码~成品版本(料品表自定义20字段)~序列号~订单号~车号段(ICSExtension表batchcode字段)~供应商
|
|
string Pre1 = $"~{moModel.MOCode}~{dt.Rows[0]["Batchcode"]}~";
|
|
for (int i=0;i< subCount;i++)
|
|
{
|
|
var serial = (i + 1).ToString("D3");
|
|
var lotNo = Pre+ serial+ Pre1;
|
|
var figureNumber = moModel.InvCode + $"-{i + 1}";
|
|
sql += $@" INSERT INTO [dbo].[ICSMOSubInventoryLot] ([ID], [Sequence], [MOCode], [LotNo], [InvCode], [ProductDate], [ExpirationDate], [Quantity], [Amount], [ExtensionID], [PrintTimes], [LastPrintUser], [LastPrintTime], [MUSER], [MUSERName], [MTIME], [WorkPoint],[EATTRIBUTE2],[EATTRIBUTE3]) VALUES (NEWID(), N'{moModel.Sequence}', N'{moModel.MOCode}', N'{lotNo}', N'{moModel.InvCode}', '{date}', '2099-12-31 00:00:00.000', '{moModel.Quantity}', 0.000000, N'{moModel.ExtensionID}', NULL, NULL, NULL, N'{MUSER}', N'{MUSERNAME}', '{date}', N'{WorkPoints}','{figureNumber}',{i+1}); ";
|
|
}
|
|
|
|
});
|
|
int count = SqlHelper.CmdExecuteNonQueryLi(sql);
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
|
|
}
|
|
public object GetDecimalDigits()
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
try
|
|
{
|
|
string sql = string.Empty;
|
|
sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
|
|
object Figure = SqlHelper.ExecuteScalar(sql);
|
|
return Figure;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 删除条码
|
|
/// </summary>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public string DeleteItemLot(string MOCodes)
|
|
{
|
|
string msg = string.Empty;
|
|
try
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
string sql = $@"SELECT * FROM dbo.ICSMOSubInventoryLot
|
|
WHERE MOCode IN ({MOCodes}) and WorkPoint in ('{WorkPoint}') and isnull(EATTRIBUTE1,'') !='' ";
|
|
DataTable dtASN = SqlHelper.GetDataTableBySql(sql);
|
|
if (dtASN != null && dtASN.Rows.Count > 0)
|
|
{
|
|
msg = "所选条码已绑定,无法删除!";
|
|
return msg;
|
|
}
|
|
|
|
string sql2 = $@"SELECT * FROM ICSInspection WHERE LotNO in (SELECT LotNo FROM ICSMOSubInventoryLot WHERE MOCode in({MOCodes}) AND WorkPoint in ('{WorkPoint}')) and Enable='1'";
|
|
DataTable dtASN2 = SqlHelper.GetDataTableBySql(sql2);
|
|
if (dtASN2 != null && dtASN2.Rows.Count > 0)
|
|
{
|
|
msg = "所选条码已检验,无法删除!";
|
|
return msg;
|
|
}
|
|
if (string.IsNullOrEmpty(msg))
|
|
{
|
|
string sqls = $"DELETE FROM ICSMOSubInventoryLot WHERE MOCode in({MOCodes}) AND WorkPoint in ('{WorkPoint}') ";
|
|
SqlHelper.CmdExecuteNonQueryLi(sqls);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印子线条码
|
|
/// </summary>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public string PrintViewByLot(string MOCodes, string PrintTemplate)
|
|
{
|
|
string msg = string.Empty;
|
|
try
|
|
{
|
|
//通过工单获取子件数据
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string date = DateTime.Now.ToString("yyyyMMdd");
|
|
var moCodes = MOCodes.Substring(1, MOCodes.Length - 2).Split(',').ToList<string>();
|
|
//查询打印模板文件
|
|
string templatesql = $@"
|
|
SELECT b.F_ItemCode Code,b.F_ItemName Name,b.F_Define1,b.F_Define2,b.F_Define3 from Sys_SRM_Items a
|
|
INNER JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
|
|
WHERE a.F_EnCode = 'PrintTemplate' and b.F_ItemCode='{PrintTemplate}' ";
|
|
var templatedt = SqlHelper.CmdExecuteDataTable(templatesql);
|
|
if (templatedt.Rows.Count < 0)
|
|
{
|
|
throw new Exception("选择模板文件不存在");
|
|
}
|
|
moCodes.ForEach(moCode=>
|
|
{
|
|
MultitaskingViewModel multitaskingViewModel = new MultitaskingViewModel();
|
|
List<BatchGroupsItem> batchGroupsItems = new List<BatchGroupsItem>();
|
|
MultitaskingSetting multitaskingSetting = new MultitaskingSetting();
|
|
multitaskingViewModel.Setting = new MultitaskingSetting();
|
|
multitaskingViewModel.Setting.BatchName = moCode;
|
|
//获取打印的条码信息 20250609 (图号是规格型号 左下角的是HIGE+规格型号 原 a.EATTRIBUTE2)
|
|
string sql = $@"SELECT a.LotNo,a.EATTRIBUTE2,c.InvName,b.EATTRIBUTE30,b.Quantity,c.InvStd FROM dbo.ICSMOSubInventoryLot a
|
|
INNER JOIN ICSMO b ON A.MOCode=b.MOCode AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSInventory c ON b.InvCode =c.InvCode AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.MOCode ='{moCode}' and a.WorkPoint in ('{WorkPoint}') ORDER BY CAST(a.EATTRIBUTE3 as INT) asc ";
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
if (dt.Rows.Count<=0)
|
|
{
|
|
throw new Exception($"工单:{moCode}没有生成子线条码,请先生成条码后打印");
|
|
}
|
|
|
|
for (int i=0;i<dt.Rows.Count;i++)
|
|
{
|
|
BatchGroupsItem batchGroupsItem = new BatchGroupsItem
|
|
{
|
|
GroupName = $"任务{i + 1}",
|
|
LengthFixed = templatedt.Rows[0]["F_Define2"].ToInt()
|
|
};
|
|
FileMark fileMark = new FileMark();
|
|
List<MarkContentsItem> markContentsItems = new List<MarkContentsItem>();
|
|
MarkContentsItem markContentsItem = new MarkContentsItem();
|
|
List<VarsItem> varsItems = new List<VarsItem>
|
|
{
|
|
new VarsItem { Name = "BAR1", Value = dt.Rows[i]["LotNo"].ToString() },
|
|
new VarsItem { Name = "TXT1", Value = $"图号:{dt.Rows[i]["InvStd"]}" },
|
|
new VarsItem { Name = "TXT2", Value = $"名称:{dt.Rows[i]["InvName"]}" },
|
|
new VarsItem { Name = "TXT3", Value = "(CATL422kWh)" },
|
|
new VarsItem { Name = "TXT4", Value = $"HIGER{dt.Rows[i]["InvStd"]}" },
|
|
new VarsItem { Name = "TXT5", Value = $"{dt.Rows[i]["EATTRIBUTE30"]}{date}" }
|
|
};
|
|
fileMark.Vars = varsItems;
|
|
fileMark.FileName = templatedt.Rows[0]["F_Define1"].ToString();
|
|
fileMark.FileSize = templatedt.Rows[0]["F_Define3"].ToString();
|
|
markContentsItem.FileMark = fileMark;
|
|
markContentsItems.Add(markContentsItem);
|
|
batchGroupsItem.MarkContents = markContentsItems;
|
|
batchGroupsItem.Quantity = dt.Rows[i]["Quantity"].ToInt();
|
|
batchGroupsItems.Add(batchGroupsItem);
|
|
}
|
|
multitaskingViewModel.BatchGroups = batchGroupsItems;
|
|
|
|
#region 调用工单打印接口
|
|
if (!multitaskingViewModel.IsEmpty())
|
|
{
|
|
|
|
string APIURL = ConfigurationManager.ConnectionStrings["Print"].ConnectionString + "sszk/batch";
|
|
var erpinput = JsonConvert.SerializeObject(multitaskingViewModel);
|
|
string printllog = $@"INSERT INTO[dbo].[ICSPrintLog] ([ID], [Input], [MOCode], [MUSER], [MUSERName], [MTIME], [WorkPoint]) VALUES(NEWID(), '{erpinput}', '{moCode}', N'{MUSER}', N'{MUSERNAME}', GETDATE(), N'{WorkPoint}');";
|
|
SqlHelper.CmdExecuteNonQuery(printllog);
|
|
string result1 = HttpPost(APIURL, erpinput);
|
|
JObject Obj = (JObject)JsonConvert.DeserializeObject(result1);//或者JObject jo = JObject.Parse(jsonText);
|
|
string code = Obj["code"].ToString();
|
|
string message = Obj["message"].ToString();
|
|
string printllogout = $@"INSERT INTO[dbo].[ICSPrintLog] ([ID], [Output], [MOCode], [MUSER], [MUSERName], [MTIME], [WorkPoint]) VALUES(NEWID(), '{Obj}', '{moCode}', N'{MUSER}', N'{MUSERNAME}', GETDATE(), N'{WorkPoint}');";
|
|
SqlHelper.CmdExecuteNonQuery(printllogout);
|
|
if (code != "0")
|
|
{
|
|
msg += message;
|
|
}
|
|
else
|
|
{
|
|
string updatesql = $@" Update ICSMOSubInventoryLot set PrintTimes='1',LastPrintUser='{MUSERNAME}',LastPrintTime=GETDATE() WHERE MOCode ='{moCode}' and WorkPoint in ('{WorkPoint}') ";
|
|
SqlHelper.CmdExecuteNonQuery(updatesql);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
});
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印子线条码(单个条码)
|
|
/// </summary>
|
|
/// <param name="keyValue"></param>
|
|
/// <returns></returns>
|
|
public string PrintViewByLotSingle(string Lots, int PrintCount, string PrintTemplate)
|
|
{
|
|
string msg = string.Empty;
|
|
try
|
|
{
|
|
//通过工单获取子件数据
|
|
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
|
|
string MUSER= NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
string date = DateTime.Now.ToString("yyyyMMdd");
|
|
if (PrintCount<=0)
|
|
{
|
|
throw new Exception("请输入打印张数");
|
|
}
|
|
if (string.IsNullOrEmpty(PrintTemplate))
|
|
{
|
|
throw new Exception("请选择打印模板");
|
|
}
|
|
string templatesql = $@"
|
|
SELECT b.F_ItemCode Code,b.F_ItemName Name,b.F_Define1,b.F_Define2,b.F_Define3 from Sys_SRM_Items a
|
|
INNER JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
|
|
WHERE a.F_EnCode = 'PrintTemplate' and b.F_ItemCode='{PrintTemplate}' ";
|
|
var templatedt = SqlHelper.CmdExecuteDataTable(templatesql);
|
|
if (templatedt.Rows.Count<0)
|
|
{
|
|
throw new Exception("选择模板文件不存在");
|
|
}
|
|
var lots = Lots.Substring(1, Lots.Length-2).Split(',').ToList();
|
|
lots.ForEach(lot =>
|
|
{
|
|
for (int i= PrintCount;i>0;i--)
|
|
{
|
|
Single_taskingViewMOdel single_TaskingViewMOdel = new Single_taskingViewMOdel();
|
|
single_TaskingViewMOdel.Setting = new Setting();
|
|
SingleJob singleJob = new SingleJob();
|
|
//获取打印的条码信息
|
|
string sql = $@"SELECT a.LotNo,a.EATTRIBUTE2,c.InvName,b.EATTRIBUTE30,c.InvStd FROM dbo.ICSMOSubInventoryLot a
|
|
INNER JOIN ICSMO b ON A.MOCode=b.MOCode AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSInventory c ON b.InvCode =c.InvCode AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo ='{lot}' and a.WorkPoint in ('{WorkPoint}') ORDER BY CAST(a.EATTRIBUTE3 as INT) asc ";
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
if (dt.Rows.Count<=0)
|
|
{
|
|
throw new Exception("请先确认打印子线条码");
|
|
}
|
|
FileMark fileMark = new FileMark();
|
|
List<MarkContentsItem> markContentsItems = new List<MarkContentsItem>();
|
|
MarkContentsItem markContentsItem = new MarkContentsItem();
|
|
List<VarsItem> varsItems = new List<VarsItem>
|
|
{
|
|
new VarsItem { Name = "BAR1", Value = dt.Rows[0]["LotNo"].ToString() },
|
|
new VarsItem { Name = "TXT1", Value = $"图号:{dt.Rows[0]["InvStd"]}" },
|
|
new VarsItem { Name = "TXT2", Value = $"名称:{dt.Rows[0]["InvName"]}" },
|
|
new VarsItem { Name = "TXT3", Value = "(CATL422kWh)" },
|
|
new VarsItem { Name = "TXT4", Value = $"HIGER{dt.Rows[0]["InvStd"]}" },
|
|
new VarsItem { Name = "TXT5", Value = $"{dt.Rows[0]["EATTRIBUTE30"]}{date}" }
|
|
};
|
|
fileMark.FileName = templatedt.Rows[0]["F_Define1"].ToString();
|
|
fileMark.FileSize = templatedt.Rows[0]["F_Define3"].ToString();
|
|
fileMark.Vars = varsItems;
|
|
markContentsItem.FileMark = fileMark;
|
|
markContentsItems.Add(markContentsItem);
|
|
singleJob.MarkContents = markContentsItems;
|
|
singleJob.LengthFixed = templatedt.Rows[0]["F_Define2"].ToInt();
|
|
single_TaskingViewMOdel.SingleJob = singleJob;
|
|
|
|
#region 调用单任务打印接口
|
|
if (!single_TaskingViewMOdel.IsEmpty())
|
|
{
|
|
|
|
string APIURL = ConfigurationManager.ConnectionStrings["Print"].ConnectionString + "sszk/single";
|
|
var erpinput = JsonConvert.SerializeObject(single_TaskingViewMOdel);
|
|
string printllog = $@"INSERT INTO[dbo].[ICSPrintLog] ([ID], [Input], [LotNO], [MUSER], [MUSERName], [MTIME], [WorkPoint]) VALUES(NEWID(), '{erpinput}', '{lot}', N'{MUSER}', N'{MUSERNAME}', GETDATE(), N'{WorkPoint}');";
|
|
SqlHelper.CmdExecuteNonQuery(printllog);
|
|
string result1 = HttpPost(APIURL, erpinput);
|
|
JObject Obj = (JObject)JsonConvert.DeserializeObject(result1);//或者JObject jo = JObject.Parse(jsonText);
|
|
string code = Obj["code"].ToString();
|
|
string message = Obj["message"].ToString();
|
|
string printllogout = $@"INSERT INTO[dbo].[ICSPrintLog] ([ID], [Output], [LotNO], [MUSER], [MUSERName], [MTIME], [WorkPoint]) VALUES(NEWID(), '{Obj}', '{lot}', N'{MUSER}', N'{MUSERNAME}', GETDATE(), N'{WorkPoint}');";
|
|
SqlHelper.CmdExecuteNonQuery(printllogout);
|
|
if (code != "0")
|
|
{
|
|
msg += message;
|
|
}
|
|
else
|
|
{
|
|
string updatesql = $@" Update ICSMOSubInventoryLot set PrintTimes='1',LastPrintUser='{MUSERNAME}',LastPrintTime=GETDATE() WHERE LotNo ='{lot}' and WorkPoint in ('{WorkPoint}') ";
|
|
SqlHelper.CmdExecuteNonQuery(updatesql);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
public DataTable GetGridJsonChengPingNormal(string queryJson, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var queryParam = queryJson.ToJObject();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
object Figure = GetDecimalDigits();
|
|
|
|
#region [SQL]
|
|
string sql = @" select distinct a.ID, a.MODetailID,a.MOCode,a.Sequence,
|
|
CAST(a.RCVQuantity AS DECIMAL(38,{0})) as RCVQuantity ,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,
|
|
CAST( a.Quantity AS DECIMAL(38,{0})) as Quantity,CAST( a.Amount as DECIMAL(38,{0})) as Amount,a.StartDate,a.WHCode,warehouse.WarehouseName as WHName
|
|
,a.DueDate,a.MOStatus,a.ExtensionID,a.MUSERName,a.MTIME ,
|
|
CAST(c.LOTQTY AS DECIMAL(38,{0})) as LOTQTY ,
|
|
CAST( a.Quantity AS DECIMAL(38,{0})) -CAST(a.RCVQuantity AS DECIMAL(38,{0})) as ERPNum,CAST((a.Quantity-ISnull(a.RCVQuantity,0)) AS DECIMAL(38,{0})) as NRCVQuantity,a.MOMemo
|
|
,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,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
|
|
a.EATTRIBUTE9,a.EATTRIBUTE10,a.EATTRIBUTE11,a.EATTRIBUTE12,b.MTIME as TMTime,dep.DepName,a.CreateDateTime,b.EATTRIBUTE1 as ICSInventoryEATTRIBUTE1 ,b.EATTRIBUTE2 as ICSInventoryEATTRIBUTE2,b.EATTRIBUTE3 as ICSInventoryEATTRIBUTE3,b.EATTRIBUTE4 as ICSInventoryEATTRIBUTE4,b.EATTRIBUTE5 as ICSInventoryEATTRIBUTE5,b.EATTRIBUTE6 as ICSInventoryEATTRIBUTE6,b.EATTRIBUTE7 as ICSInventoryEATTRIBUTE7,b.EATTRIBUTE8 as ICSInventoryEATTRIBUTE8,
|
|
b.EATTRIBUTE9 as ICSInventoryEATTRIBUTE9,b.EATTRIBUTE10 as ICSInventoryEATTRIBUTE10
|
|
from ICSMO a
|
|
left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
|
|
left join (
|
|
select mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint from ICSInventoryLot ee
|
|
left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='3'
|
|
where isnull(ee.EATTRIBUTE1,'')=''
|
|
group by mm.TransCode,mm.TransSequence,ee.WorkPoint
|
|
)c
|
|
on a.MOCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join ICSDepartment dep ON dep.DepCode=a.DepCode and a.WorkPoint=dep.WorkPoint
|
|
left join ICSWarehouse warehouse on a.WHCode=warehouse.WarehouseCode and a.WorkPoint=warehouse.WorkPoint ";
|
|
sql += " WHERE 1=1 and a.MOStatus<>'3' ";
|
|
sql = string.Format(sql, Figure);
|
|
|
|
#endregion
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryJson))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
|
|
{
|
|
sql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
|
|
{
|
|
sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
|
|
{
|
|
sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
|
|
{
|
|
sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["SelGDLX"].ToString()))
|
|
{
|
|
sql += " and a.MOType like '%" + queryParam["SelGDLX"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
|
|
{
|
|
sql += " and b.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["FromTime"].ToString()))
|
|
{
|
|
sql += " and a.CreateDateTime >= '" + queryParam["FromTime"].ToString() + "' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["ToTime"].ToString()))
|
|
{
|
|
sql += " and a.CreateDateTime <= '" + queryParam["ToTime"].ToString() + "' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
|
|
{
|
|
sql += " and a.WHCode like '%" + queryParam["WHCode"].ToString() + "%' ";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
|
|
{
|
|
string POStatus = queryParam["POStatus"].ToString();
|
|
if (POStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (POStatus == "1")
|
|
{
|
|
sql += " and a.Quantity-ISNULL(c.LOTQTY,0)=0";
|
|
}
|
|
else
|
|
{
|
|
sql += " and a.Quantity-ISNULL(c.LOTQTY,0)>0";
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryParam["WHStatus"].ToString()))
|
|
{
|
|
string WHStatus = queryParam["WHStatus"].ToString();
|
|
if (WHStatus == "0")
|
|
{
|
|
//sql += " and a.Quantity=ISNULL(c.LotQty,0)";
|
|
}
|
|
else if (WHStatus == "1")
|
|
{
|
|
sql += " and a.Quantity-ISNULL(a.RCVQuantity,0)>0 ";
|
|
}
|
|
else
|
|
{
|
|
sql += " and a.Quantity-ISNULL(a.RCVQuantity,0)=0 ";
|
|
}
|
|
}
|
|
}
|
|
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 GetSubGridJsonNormal(string ApplyNegCode, string Sequence, string Type, string isPrint, ref Pagination jqgridparam)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
object Figure = GetDecimalDigits();
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string sql = @" select c.TransCode,c.TransSequence ,a.ID,a.LotNo, CAST( a.Quantity AS DECIMAL(38,{0})) as Quantity ,a.MUSERName,a.MTIME
|
|
,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,
|
|
case when isnull(d.ID,'')='' then '未入库' else '已入库' end as isStorage,
|
|
case when g.InvIQC='1'and isnull(e.ID,'')='' then '未检验' else '已检验' end as isInspection,
|
|
case when isnull(a.LastPrintUser,'')='' then '未打印' else '已打印' end as isPrint,
|
|
case when Isnull(g.InvFQC,'0')='1' then '否' else '是' end as isExemption,a.Amount,
|
|
convert(varchar(20),a.ProductDate,23) as ProductDate,convert(varchar(20),a.ExpirationDate,23) as ExpirationDate ,g.EffectiveDays,a.EATTRIBUTE4,a.EATTRIBUTE5
|
|
from ICSInventoryLot a
|
|
left join (select count(LotNo) LotNoCount,LotNo,WorkPoint from ICSWareHouseLotInfo
|
|
group by LotNo,WorkPoint)b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
|
|
left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
|
|
left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
|
|
left join dbo.ICSWareHouseLotInfo d on a.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint
|
|
left join ICSInspection e on a.LotNo=e.LotNo and e.Enable='1' and a.WorkPoint=e.WorkPoint
|
|
left join ICSInventory g on a.InvCode=g.InvCode and a.WorkPoint=g.WorkPoint
|
|
WHERE isnull(a.EATTRIBUTE1,'')='' and a.Type='" + Type + "' and c.TransCode='" + ApplyNegCode + "' and c.TransSequence='" + Sequence + "' and a.WorkPoint in ('" + WorkPoint + "')";
|
|
if (!string.IsNullOrWhiteSpace(isPrint))
|
|
{
|
|
if (isPrint == "0")
|
|
{
|
|
}
|
|
else if (isPrint == "1")
|
|
{
|
|
sql += " and isnull(LastPrintUser,'')<>''";
|
|
}
|
|
else
|
|
{
|
|
sql += " and isnull(LastPrintUser,'')=''";
|
|
}
|
|
}
|
|
|
|
sql = string.Format(sql, Figure);
|
|
return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
|
|
}
|
|
|
|
public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
|
|
{
|
|
string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
|
|
sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
|
|
//return Repository().FindTableBySql(sql.ToString());
|
|
return SqlHelper.ExecuteScalar(sql).ToString();
|
|
//return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
#region 获取单据类型
|
|
/// <summary>
|
|
/// 获取U9单据类型
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetPrintTemplate()
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
|
|
string UserRole = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode.TrimEnd(',');
|
|
string result = String.Empty;
|
|
string APIURL = String.Empty;
|
|
DataTable Resultdt = new DataTable();
|
|
try
|
|
{
|
|
string sql = @"SELECT '' Code,'' Name,'' F_Define1
|
|
UNION ALL
|
|
SELECT b.F_ItemCode Code,b.F_ItemName Name,b.F_Define1 from Sys_SRM_Items a
|
|
INNER JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
|
|
WHERE a.F_EnCode = 'PrintTemplate' ";
|
|
var dt = SqlHelper.CmdExecuteDataTable(sql);
|
|
return dt.ToJson();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result = ex.Message;
|
|
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 工单子线实体对象
|
|
/// <summary>
|
|
/// 新增工单子线实体对象
|
|
/// </summary>
|
|
public class MOModel
|
|
{
|
|
/// <summary>
|
|
/// 工单编码
|
|
/// </summary>
|
|
public string MOCode { get; set; }
|
|
/// <summary>
|
|
/// 行号
|
|
/// </summary>
|
|
public string Sequence { get; set; }
|
|
/// <summary>
|
|
/// 物料编码
|
|
/// </summary>
|
|
public string InvCode { get; set; }
|
|
/// <summary>
|
|
/// 数量
|
|
/// </summary>
|
|
public decimal Quantity { get; set; }
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string ExtensionID { get; set; }
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|