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.
377 lines
14 KiB
377 lines
14 KiB
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ICS.WCF.Base;
|
|
using UFIDA.U9.ISV.Mobile.TransferInISV;
|
|
using UFSoft.UBF.Service;
|
|
|
|
namespace ICS.CreateTransInDoc
|
|
{
|
|
public class CreateTransInDoc
|
|
{
|
|
private static string ORGCode = ConfigurationManager.AppSettings["orgCode"].ToString();
|
|
private static string ERPConStr = Appconfig.GetU9ConnStr();
|
|
private static string UserCode = ConfigurationManager.AppSettings["userCode"].ToString();
|
|
public static ReturnValue CustCreatePR(List<ITEMREQDATA> PRList)
|
|
{
|
|
#region 服务调用框架结构
|
|
//实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
|
|
CreateTransferInRestSVClient client = new CreateTransferInRestSVClient();
|
|
//服务返回结果
|
|
|
|
//UFIDAU9ISVPRSVPRBizKeyDTOData[] returnItems;
|
|
TransInRestResultDTOData[] returnItems;
|
|
//返回异常信息,目前还没有使用此属性
|
|
//UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
|
|
//上下文信息
|
|
ISVContext context;
|
|
//传入 参数
|
|
|
|
string[] splitBy = new string[] { };
|
|
|
|
try
|
|
{
|
|
if (PRList == null || PRList.Count == 0)
|
|
{
|
|
throw new Exception("传入数据为空");
|
|
}
|
|
|
|
string ORGID = "";
|
|
string OrgCode = "";
|
|
|
|
|
|
|
|
|
|
ORGID = Appconfig.IsExistsCode(ORGCode, "Base_Organization");
|
|
|
|
if (string.IsNullOrEmpty(ORGID))
|
|
{
|
|
throw new Exception("组织编码:" + ORGCode + "在U9中不存在。");
|
|
}
|
|
|
|
|
|
|
|
|
|
//给上下文信息赋值
|
|
context = CreateContextObj(ORGID);
|
|
//给传入参数赋值
|
|
|
|
|
|
|
|
TransInRestInputDTOData[] itemDatas = setDataForItem(PRList, ORGID, ORGCode);
|
|
|
|
|
|
//服务调用
|
|
|
|
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
|
|
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
|
|
returnItems = client.Do(context, itemDatas.ToArray(), 0,false);
|
|
|
|
foreach (TransInRestResultDTOData data in returnItems)
|
|
{
|
|
StringBuilder str = new StringBuilder();
|
|
str.AppendLine("创建U9调入单");
|
|
str.AppendLine("单号:" + data.DocNo);
|
|
Appconfig.WriteLogFile(str.ToString(), "创建U9调入单");
|
|
}
|
|
ReturnValue value = new ReturnValue();
|
|
value.IsSuccess = true;
|
|
value.Message = "调入单成功";
|
|
List<RtnPRData> values = new List<RtnPRData>();
|
|
int msgnumber = 0;
|
|
foreach (TransInRestResultDTOData data in returnItems)
|
|
{
|
|
msgnumber++;
|
|
if (msgnumber != 1)
|
|
{
|
|
continue;
|
|
}
|
|
RtnPRData prvalue = new RtnPRData();
|
|
prvalue.DocNo = data.DocNo;
|
|
prvalue.msg = data.SyncErrMsg;
|
|
if (prvalue.msg != null)
|
|
{
|
|
value.IsSuccess = false;
|
|
value.Message = "调入单失败";
|
|
}
|
|
values.Add(prvalue);
|
|
}
|
|
value.PRList = values;
|
|
Appconfig.WriteLogFile("成功", "创建U9调入单");
|
|
return value;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//异常信息捕获
|
|
string HeadList = string.Empty;
|
|
|
|
|
|
StringBuilder str = new StringBuilder();
|
|
foreach (ITEMREQDATA data in PRList)
|
|
{
|
|
str.AppendLine("创建U9调入单");
|
|
str.AppendLine(ex.ToString());
|
|
HeadList += "\r\n 数量:" + data.TransferQty + ",调入仓库:" + data.TransInWh + ",库位:" + data.TransInBin + ",批号:" + data.LotCode + ",单位:" + data.Uom;
|
|
HeadList += "\r\n 数量:" + data.TransferQty + ",调出仓库:" + data.TransOutWh + ",库位:" + data.TransOutBin + ",批号:" + data.LotCode + ",单位:" + data.Uom;
|
|
}
|
|
str.AppendLine(HeadList);
|
|
str.AppendLine("结果:" + "False");
|
|
|
|
|
|
Appconfig.WriteLogFile(str.ToString(), "创建U9调入单");
|
|
|
|
ReturnValue value = new ReturnValue();
|
|
value.IsSuccess = false;
|
|
value.Message = ex.ToString();
|
|
return value;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
|
|
|
|
#region 给上下文信息赋值1
|
|
/// <summary>
|
|
/// 给上下文信息赋值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static ISVContext CreateContextObj(string ORGID)
|
|
{
|
|
// 实例化应用上下文对象
|
|
ISVContext isvContext = new ISVContext();
|
|
|
|
isvContext.OrgID = Convert.ToInt64(ORGID);
|
|
isvContext.OrgCode = ORGCode;
|
|
isvContext.UserCode = UserCode;
|
|
isvContext.EntCode = ConfigurationManager.AppSettings["enterpriseID"].ToString();
|
|
|
|
return isvContext;
|
|
}
|
|
#endregion
|
|
|
|
private static TransInRestInputDTOData[] setDataForItem(List<ITEMREQDATA> datas, string ORGID, string OrgCode)
|
|
{
|
|
|
|
int number = 0;
|
|
|
|
List<TransInRestInputDTOData> prs = new List<TransInRestInputDTOData>();
|
|
|
|
|
|
|
|
List<ItemCURR> lstitem = new List<ItemCURR>();
|
|
foreach (ITEMREQDATA data in datas)
|
|
{
|
|
|
|
|
|
string INORGID = Appconfig.IsExistsCode(data.TransInOrg, "Base_Organization");
|
|
|
|
if (string.IsNullOrEmpty(INORGID))
|
|
{
|
|
throw new Exception("调入组织编码:" + data.TransInOrg + "在U9中不存在。");
|
|
}
|
|
string OUTORGID = Appconfig.IsExistsCode(data.TransOutOrg, "Base_Organization");
|
|
|
|
if (string.IsNullOrEmpty(OUTORGID))
|
|
{
|
|
throw new Exception("调入组织编码:" + data.TransOutOrg + "在U9中不存在。");
|
|
}
|
|
if (INORGID!=OUTORGID)
|
|
{
|
|
throw new Exception("调入组织不一致!请重新操作!");
|
|
}
|
|
ORGID = INORGID;
|
|
|
|
ItemCURR item = new ItemCURR();
|
|
if (lstitem.Count == 0)
|
|
{
|
|
item.BIN = data.TransOutBin;
|
|
item.LOTNO = data.LotCode;
|
|
item.ITEM = data.ItemMaster;
|
|
item.WH = data.TransOutWh;
|
|
item.ORG = data.TransOutOrg;
|
|
item.QTY = 0;
|
|
lstitem.Add(item);
|
|
}
|
|
else
|
|
{
|
|
int isrd = 0;
|
|
foreach (ItemCURR item1 in lstitem)
|
|
{
|
|
if (item1.BIN == data.TransOutBin && item1.LOTNO == data.LotCode && item1.ITEM == data.ItemMaster && item1.WH == data.TransOutWh && item1.ORG == data.TransOutOrg)
|
|
{
|
|
isrd++;
|
|
}
|
|
|
|
}
|
|
if (isrd == 0)
|
|
{
|
|
item.BIN = data.TransOutBin;
|
|
item.LOTNO = data.LotCode;
|
|
item.ITEM = data.ItemMaster;
|
|
item.WH = data.TransOutWh;
|
|
item.ORG = data.TransOutOrg;
|
|
item.QTY = 0;
|
|
lstitem.Add(item);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
foreach (ITEMREQDATA data in datas)
|
|
{
|
|
foreach (ItemCURR item1 in lstitem)
|
|
{
|
|
|
|
if (item1.BIN == data.TransOutBin && item1.LOTNO == data.LotCode && item1.ITEM == data.ItemMaster && item1.WH == data.TransOutWh && item1.ORG == data.TransOutOrg)
|
|
{
|
|
item1.QTY += data.TransferQty;
|
|
}
|
|
|
|
}
|
|
}
|
|
string msg = "";
|
|
foreach (ItemCURR item1 in lstitem)
|
|
{
|
|
DataTable request = Appconfig.GetItemRequestList(item1.LOTNO, item1.BIN, item1.ITEM, item1.WH, item1.QTY.ToString(), item1.ORG, ERPConStr);
|
|
TransInRestInputDTOData pr = new TransInRestInputDTOData();
|
|
if (request != null && request.Rows.Count > 0)
|
|
{
|
|
string ky = request.Rows[0]["可用量"].ToString();
|
|
if (Convert.ToDecimal(ky) < 0)
|
|
{
|
|
msg += "组织:" + item1.ORG + ",料号:" + item1.ITEM
|
|
+ @",存储地点:" + item1.WH + ",库位:" + item1.BIN + ",批号:" + item1.LOTNO + "可用量不足;";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg += "组织:" + item1.ORG + ",料号:" + item1.ITEM
|
|
+ @",存储地点:" + item1.WH + ",库位:" + item1.BIN + ",批号:" + item1.LOTNO + "没有可以用量;";
|
|
}
|
|
}
|
|
|
|
if (msg != "")
|
|
{
|
|
throw new Exception("料品需求单:" + msg + "");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (ITEMREQDATA data in datas)
|
|
{
|
|
number++;
|
|
TransInRestInputDTOData pr = new TransInRestInputDTOData();
|
|
|
|
if (Appconfig.Getusername(data.CreatedBy) != null)
|
|
pr.CreatedBy = data.CreatedBy;//创建人
|
|
else
|
|
throw new Exception("用户:" + data.CreatedBy + "不存在");
|
|
|
|
pr.DocTypeCode = data.DocTypeCode;
|
|
string INORGID = Appconfig.IsExistsCode(data.TransInOrg, "Base_Organization");
|
|
pr.TransInOrg = Convert.ToInt64(INORGID);
|
|
string OUTORGID = Appconfig.IsExistsCode(data.TransOutOrg, "Base_Organization");
|
|
pr.TransOutOrg = Convert.ToInt64(OUTORGID);
|
|
|
|
pr.ItemMaster = Convert.ToInt64(Appconfig.ITEMMATERID(data.ItemMaster, ORGID));//料品
|
|
pr.ItemBarCode = data.ItemBarCode;//料品条码
|
|
|
|
pr.GroupFlag = data.GroupFlag;
|
|
pr.OtherDesc = data.OtherDesc;
|
|
|
|
if (Appconfig.GetMarkid(data.Mfc) != "")
|
|
pr.Mfc = Convert.ToInt64(Appconfig.GetMarkid(data.Mfc));
|
|
else
|
|
pr.Mfc = 0;
|
|
|
|
|
|
if (Appconfig.uomid(data.Uom) != "")
|
|
pr.Uom = Convert.ToInt64(Appconfig.uomid(data.Uom));
|
|
else
|
|
throw new Exception("计量单位:" + data.Uom + "不存在");
|
|
|
|
if (Appconfig.GetWhCodeByBinid(data.TransOutWh, ORGID) != "")
|
|
pr.TransOutWh = Convert.ToInt64(Appconfig.GetWhCodeByBinid(data.TransOutWh, ORGID)); //调出仓库id
|
|
else
|
|
pr.TransOutWh = 0;
|
|
|
|
if (Appconfig.GetWhCodeByBinid(data.TransInWh, ORGID) != "")
|
|
pr.TransInWh = Convert.ToInt64(Appconfig.GetWhCodeByBinid(data.TransInWh, ORGID)); //调出仓库id
|
|
else
|
|
pr.TransInWh = 0;
|
|
|
|
|
|
//throw new Exception("存储地点:" + data.Wh + "不存在");
|
|
if (Appconfig.GetByBinid(data.TransOutBin, ORGID) != "")
|
|
pr.TransOutBin = Convert.ToInt64(Appconfig.GetByBinid(data.TransOutBin, ORGID));
|
|
else
|
|
pr.TransOutBin = 0;
|
|
if (Appconfig.GetByBinid(data.TransInBin, ORGID) != "")
|
|
pr.TransInBin = Convert.ToInt64(Appconfig.GetByBinid(data.TransInBin, ORGID));
|
|
else
|
|
pr.TransInBin = 0;
|
|
//throw new Exception("库位:" + data.Bin + "不存在");
|
|
if (Appconfig.GetBysupid(data.Supplier, ORGID) != "")
|
|
pr.Supplier = Convert.ToInt64(Appconfig.GetBysupid(data.Supplier, ORGID));
|
|
else
|
|
pr.Supplier = 0;
|
|
|
|
|
|
//if (Appconfig.GetProjectid(data.Project, ORGID) != "")
|
|
// pr.Project = Convert.ToInt64(Appconfig.GetProjectid(data.Project, ORGID));
|
|
//else
|
|
// pr.Project = 0;
|
|
//throw new Exception("项目:" + data.Project + "不存在");
|
|
//pr.SrcLineID = Convert.ToInt64(request.Rows[0]["id"].ToString());//行号
|
|
//pr.ShipDate = data.ShipDate;//杂发时间
|
|
pr.TransferQty = Convert.ToDecimal(data.TransferQty);//数量
|
|
pr.LotCode = data.LotCode;
|
|
prs.Add(pr);
|
|
}
|
|
return prs.ToArray();
|
|
}
|
|
|
|
#region 时间戳方法
|
|
private DateTime TimestampToDateTime(long timestamp)
|
|
{
|
|
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
|
long lTime = timestamp * 10000000;
|
|
TimeSpan nowTimeSpan = new TimeSpan(lTime);
|
|
DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
|
|
return resultDateTime;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
|
|
public class ItemCURR
|
|
{
|
|
public string LOTNO { get; set; }//批号
|
|
public string ORG { get; set; }//组织编码
|
|
public string WH { get; set; }//仓库
|
|
public string BIN { get; set; }//库位
|
|
public string ITEM { get; set; }//物料
|
|
public decimal QTY { get; set; }//数量
|
|
}
|
|
public class ItemRatio
|
|
{
|
|
public long ID { get; set; }//单位编码
|
|
public string Code { get; set; }//单位编码
|
|
public decimal Ratio { get; set; }//位数
|
|
public int Precision { get; set; }//精度
|
|
}
|
|
|
|
|
|
|
|
}
|