圣珀
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.
 
 
 

727 lines
29 KiB

using ICS.WCF.Base;
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 UFSoft.UBF.Service;
using UFSoft.UBF.Util.Context;
using www.ufida.org.EntityData;
namespace UFIDA.ISV.CreateBFStandardShip
{
public class CustCreateBFStandardShip
{
public List<rtnRcvInfo> CreateBFStandardShip(List<shiphead> shipInfoList)
{
#region 接口传入参数日志
StringBuilder firststrlog = new StringBuilder();
firststrlog.AppendLine("传入数据开始");
firststrlog.AppendLine("*****************************************************");
foreach (var item in shipInfoList)
{
firststrlog.AppendLine("单据类型:" + item.DocType);
//firststrlog.AppendLine("服务工单号:" + item.ServiceMoCode);
firststrlog.AppendLine("组织编码:" + item.OrgCode);
firststrlog.AppendLine("客户编码:" + item.ClientCode);
firststrlog.AppendLine("用户名:" + item.UserName);
foreach (var line in item.lines)
{
firststrlog.AppendLine("料品编码:" + line.ItemCode);
firststrlog.AppendLine("料品数量:" + line.ReqQty);
//firststrlog.AppendLine("批号:" + line.Batch);
firststrlog.AppendLine("仓库:" + line.WhCode);
}
}
firststrlog.AppendLine("*****************************************************");
firststrlog.AppendLine("传入数据结束");
Appconfig.WriteLogFile(firststrlog.ToString(), "创建标准出货单");
#endregion
#region 服务调用框架结构
UFIDAU9ISVSMICreateShipSVClient client = new UFIDAU9ISVSMICreateShipSVClient();
//服务返回结果
UFIDAU9ISVSMDocKeyDTOData[] returnItems;
//返回异常信息,目前还没有使用此属性
UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
//上下文信息
object context;
//传入 参数
UFIDAU9ISVSMShipDTOForIndustryChainData[] pOList;
//空
string[] splitBy = new string[] { };
try
{
List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
long PickID = 0;
long ItemID = 0;
if (shipInfoList == null || shipInfoList.Count == 0)
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "传入参数不能为空";
rtnpos.Add(rtnpo);
return rtnpos;
}
foreach (var item in shipInfoList)
{
if (item.DocType == null || item.DocType == "")
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "传入单据类型不能为空";
rtnpos.Add(rtnpo);
return rtnpos;
}
if (item.lines == null || item.lines.Count() == 0)
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "传入行信息不能为空";
rtnpos.Add(rtnpo);
return rtnpos;
}
foreach (var _item in item.lines)
{
if (_item.ItemCode == null || _item.ItemCode == "")
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "传入行信息中料号不能为空!";
rtnpos.Add(rtnpo);
return rtnpos;
}
if (_item.ReqQty == 0)
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "传入行信息中数量不能为空";
rtnpos.Add(rtnpo);
return rtnpos;
}
if (_item.WhCode == null || _item.WhCode == "")
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "传入行信息中仓库不能为空";
rtnpos.Add(rtnpo);
return rtnpos;
}
}
}
//给传入参数赋值
//pOList = SetrCVDtos(rCVInfoList);
StringBuilder strlog = new StringBuilder();
string orgID = "";
strlog.AppendLine("创建标准出货单");
strlog.AppendLine("*****************************************************");
List<UFIDAU9ISVSMShipDTOForIndustryChainData> shipList = new List<UFIDAU9ISVSMShipDTOForIndustryChainData>();
foreach (var shiphead in shipInfoList)
{
strlog.AppendLine("组织编码:" + shiphead.OrgCode);
#region 获取组织ID
string orgsql = @"select ID from Base_Organization
where Code='{0}' ";
orgsql = string.Format(orgsql, shiphead.OrgCode);
DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
if (orgdt.Rows.Count == 0)
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "组织编码不存在";
rtnpos.Add(rtnpo);
return rtnpos;
}
else
{
orgID = orgdt.Rows[0]["ID"].ToString();
}
#endregion
#region 获取单据类型ID
string docsql = @"select ID,ISNULL(ConfirmMode,0) AS ConfirmMode
,ISNULL(ConfirmAccording,0) AS ConfirmAccording
,ISNULL(InvoiceAccording,0) AS InvoiceAccording from SM_ShipDocType
where Code='{0}' AND Org='{1}'";
docsql = string.Format(docsql, shiphead.DocType, orgID);
DataTable docdt = DBhlper.Query(docsql, Appconfig.GetU9ConnStr());
long docTypeID = 0;
int ConfirmMode = 0;
long ConfirmAccording = 0;
long InvoiceAccording = 0;
if (docdt != null && docdt.Rows.Count > 0)
{
docTypeID = long.Parse(docdt.Rows[0]["ID"].ToString());
ConfirmMode = int.Parse(docdt.Rows[0]["ConfirmMode"].ToString());
ConfirmAccording = long.Parse(docdt.Rows[0]["ConfirmAccording"].ToString());
InvoiceAccording = long.Parse(docdt.Rows[0]["InvoiceAccording"].ToString());
}
if (docTypeID == 0)
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "未获取到单据类型ID";
rtnpos.Add(rtnpo);
return rtnpos;
}
#endregion
#region 获取客户ID
string cussql = @"select ID,ISNULL(ARConfirmTerm,0) AS ARConfirmTerm from CBO_Customer
where Code='{0}' AND Org='{1}'";
cussql = string.Format(cussql, shiphead.ClientCode, orgID);
DataTable cusdt = DBhlper.Query(cussql, Appconfig.GetU9ConnStr());
long cusID = 0;
long ARConfirmTermID = 0;
if (cusdt != null && cusdt.Rows.Count > 0)
{
cusID = long.Parse(cusdt.Rows[0]["ID"].ToString());
ARConfirmTermID = long.Parse(cusdt.Rows[0]["ARConfirmTerm"].ToString());
}
if (cusID == 0)
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "未获取到客户ID";
rtnpos.Add(rtnpo);
return rtnpos;
}
#endregion
UFIDAU9ISVSMShipDTOForIndustryChainData ship = new UFIDAU9ISVSMShipDTOForIndustryChainData();
ship.m_documentType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
ship.m_documentType.m_code = shiphead.DocType;
ship.m_documentType.m_iD = docTypeID;
ship.m_orderBy = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
ship.m_orderBy.m_code = shiphead.ClientCode;
ship.m_orderBy.m_iD = cusID;
ship.m_srcDocType = 1;
ship.m_shipOrg = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
ship.m_shipOrg.m_code = shiphead.OrgCode;
ship.m_shipOrg.m_iD = long.Parse(orgID);
//ship.m_descFlexField = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
//ship.m_descFlexField.m_pubDescSeg5 = shiphead.ServiceMoCode;
//ship.m_exchangeRateType = 2;
ship.m_exchangeRateType = 2;
//ship.m_totalMoneyTC = 11300;
ship.m_shipConfirmDate = DateTime.Now;
//#region 交易币
//ship.m_totalMoneyTC = shiphead.lines.Length;
//ship.m_totalNetMoneyTC = shiphead.lines.Length;
//#endregion
//#region 本币
//ship.m_totalMoneyFC = shiphead.lines.Length;
//ship.m_totalNetMoneyFC = shiphead.lines.Length;
//#endregion
//#region 核币
//ship.m_totalMoney = shiphead.lines.Length;
//ship.m_totalNetMoneyAC = shiphead.lines.Length;
//#endregion
List<UFIDAU9ISVSMShipLineDTOForIndustryChainData> shipLineList = new List<UFIDAU9ISVSMShipLineDTOForIndustryChainData>();
foreach (shipLine line in shiphead.lines)
{
#region 获取料品ID
string sqlitem = @"select ID from CBO_ItemMaster
where Code='" + line.ItemCode + "' AND Org='" + orgID + "'";
sqlitem = string.Format(sqlitem);
DataTable dtitem = DBhlper.Query(sqlitem, Appconfig.GetU9ConnStr());
if (dtitem.Rows.Count > 0)
{
ItemID = long.Parse(dtitem.Rows[0]["ID"].ToString());
}
else
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "料品不存在!";
rtnpos.Add(rtnpo);
return rtnpos;
}
#endregion
#region 获取仓库ID
string sqlWH = @"select ID,Code from CBO_Wh
WHERE Code='" + line.WhCode + "' AND Org='" + orgID + "' ";
sqlWH = string.Format(sqlWH);
DataTable _dtWH = DBhlper.Query(sqlWH, Appconfig.GetU9ConnStr());
string WHCode = string.Empty;
long WHID = 0;
if (_dtWH != null && _dtWH.Rows.Count > 0)
{
WHCode = _dtWH.Rows[0]["Code"].ToString();
WHID = long.Parse(_dtWH.Rows[0]["ID"].ToString());
}
if (string.IsNullOrWhiteSpace(WHCode))
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = "未获取到仓库";
rtnpos.Add(rtnpo);
return rtnpos;
}
#endregion
UFIDAU9ISVSMShipLineDTOForIndustryChainData shipLine = new UFIDAU9ISVSMShipLineDTOForIndustryChainData();
shipLine.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData();
shipLine.m_itemInfo.m_itemCode = line.ItemCode;
shipLine.m_itemInfo.ItemID = ItemID;
shipLine.m_itemInfo.ItemID_SKey = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
shipLine.m_itemInfo.ItemID_SKey.ID = ItemID;
shipLine.m_shipQtyInvAmount = line.ReqQty;
shipLine.m_rejectReason = -1;
shipLine.m_wH = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
shipLine.m_wH.m_code = line.WhCode;
shipLine.m_wH.m_iD = WHID;
shipLine.m_storageType = 4;
shipLine.m_donationType = -1;
//shipLine.m_orderPrice = 0;
//shipLine.m_orderPriceTC = 0;
shipLine.m_srcDocNo = line.SOCode;
shipLine.m_srcDocLineNo = line.SOLineNO;
//TotalMnyAC
//shipLine.m_cATotalMoneyAC = 113000;
//shipLine.m_finallyPriceTC = 100;
//shipLine.m_totalMoneyTC = 11300;
//shipLine.m_totalNetMoneyTC = 10000;
//shipLine.m_totalTaxTC = 1300;
shipLine.m_orderPrice = 1;
shipLine.m_orderPriceTC = 1;
shipLine.m_configResult = -1;
shipLine.m_shipTogetherFlag = -1;
shipLine.m_shipLineMemo = line.Memo;
shipLine.m_seiban = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
if (ARConfirmTermID != 0)
{
shipLine.m_confirmTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
shipLine.m_confirmTerm.m_iD = ARConfirmTermID;
}
if (ConfirmAccording != 0)
{
shipLine.m_confirmAccording = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
shipLine.m_confirmAccording.m_iD = ConfirmAccording;
}
shipLine.m_confirmMode = ConfirmMode;
if (InvoiceAccording != 0)
{
shipLine.m_invoiceAccording = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
shipLine.m_invoiceAccording.m_iD = InvoiceAccording;
}
strlog.AppendLine("料品编码:" + line.ItemCode);
strlog.AppendLine("料品数量:" + line.ReqQty);
strlog.AppendLine("仓库:" + WHCode);
shipLineList.Add(shipLine);
}
ship.m_shipLines = shipLineList.ToArray();
shipList.Add(ship);
}
pOList = shipList.ToArray();
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
List<string> shDocList = new List<string>();
//给上下文信息赋值
context = CreateContextObj(shipInfoList, long.Parse(orgID));
returnItems = client.Do(out returnMsg, context, pOList, false);
strlog.AppendLine("返回数据:");
foreach (var info in returnItems)
{
strlog.AppendLine("单号:" + info.m_docNO);
}
strlog.AppendLine("*****************************************************");
Appconfig.WriteLogFile(strlog.ToString(), "创建标准出货单");
if (returnItems != null)
{
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = true;
rtnpo.DocNo = returnItems[0].m_docNO;
rtnpo.Message = "标准出货单创建成功";
rtnpos.Add(rtnpo);
}
#region 单据创建成功后更新创建人字段
string updatesql = @"Update SM_Ship set CreatedBy='{0}'
where DocNo='{1}' AND ShipOrg='{2}'";
updatesql = string.Format(updatesql, shipInfoList[0].UserName, returnItems[0].m_docNO, orgID);
DBhlper.EXecute(updatesql, Appconfig.GetU9ConnStr());
#endregion
return rtnpos;
}
catch (Exception ex)
{
//异常信息捕获
List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
rtnRcvInfo rtnpo = new rtnRcvInfo();
rtnpo.IsSuccess = false;
rtnpo.Message = GetExceptionMessage(ex);
rtnpos.Add(rtnpo);
StringBuilder strlog = new StringBuilder();
strlog.AppendLine("创建标准出货单");
strlog.AppendLine("*****************************************************");
foreach (var item in shipInfoList)
{
strlog.AppendLine("组织编码:" + item.OrgCode);
foreach (var line in item.lines)
{
strlog.AppendLine("料品编码:" + line.ItemCode);
strlog.AppendLine("料品数量:" + line.ReqQty);
strlog.AppendLine("仓库:" + line.WhCode);
//strlog.AppendLine("批号:" + line.Batch);
}
}
strlog.AppendLine("返回消息:" + rtnpo.Message);
strlog.AppendLine("*****************************************************");
Appconfig.WriteLogFile(strlog.ToString(), "创建标准出货单");
return rtnpos;
}
#endregion
}
#region 表头类
public class shiphead
{
private shipLine[] _lines;
private string _DocType;
private string _OrgCode;
private string _ClientCode;
private string _UserName;
private string _ServiceMoCode;
//private string _DocType;
public shipLine[] lines
{
get { return _lines; }
set { _lines = value; }
}
/// <summary>
/// 单据类型
/// </summary>
public string DocType
{
get { return _DocType; }
set { _DocType = value; }
}
/// <summary>
/// 组织编号
/// </summary>
public string OrgCode
{
get { return _OrgCode; }
set { _OrgCode = value; }
}
/// <summary>
/// 客户
/// </summary>
public string ClientCode
{
get { return _ClientCode; }
set { _ClientCode = value; }
}
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
//public string ServiceMoCode
//{
// get { return _ServiceMoCode; }
// set { _ServiceMoCode = value; }
//}
//public string DocType
//{
// get { return _DocType; }
// set { _DocType = value; }
// }
}
#endregion
#region 表体类
public class shipLine
{
public string SOCode { get; set; }
public int SOLineNO { get; set; }
/// <summary>
/// 数量
/// </summary>
public decimal ReqQty { get; set; }
public string WhCode { get; set; }
//public string BinCode { get; set; }
/// <summary>
/// 料号
/// </summary>
public string ItemCode { get; set; }
/// <summary>
/// 受益部门
/// </summary>
public string DeptCode { get; set; }
/// <summary>
/// 库存批号
/// </summary>
//public string Batch { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Memo { get; set; }
}
#endregion
#region 提取异常信息
/// <summary>
/// 提取异常信息
/// </summary>
/// <param name="ex"></param>
private string GetExceptionMessage(Exception ex)
{
string faultMessage = "未知错误,请查看ERP日志!";
System.TimeoutException timeoutEx = ex as System.TimeoutException;
if (timeoutEx != null)
{
faultMessage = "访问服务超时,请修改配置信息!";
}
else
{
FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
if (faultEx == null)
{
faultMessage = ex.Message;
}
else
{
ServiceException serviceEx = faultEx.Detail;
if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
&& !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
{
// 错误信息在faultEx.Message中,请提取,
// 格式为"Fault:料品不能为空,请录入\n 在....."
int startIndex = serviceEx.Message.IndexOf(":");
int endIndex = serviceEx.Message.IndexOf("\n");
if (endIndex == -1)
endIndex = serviceEx.Message.Length;
if (endIndex > 0 && endIndex > startIndex + 1)
{
faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
}
else
{
faultMessage = serviceEx.Message;
}
}
}
}
return faultMessage;
}
#endregion
#region 给上下文信息赋值
/// <summary>
/// 给上下文信息赋值
/// </summary>
/// <returns></returns>
private ThreadContext CreateContextObj(List<shiphead> rcvInfoList, long OrgID)
{
// 实例化应用上下文对象
ThreadContext thContext = new ThreadContext();
System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
ns.Add("OrgID", OrgID);
ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
thContext.nameValueHas = ns;
return thContext;
}
#endregion
#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
}
#region 上下文类信息
public class contextInfo
{
private long _OrgID;
private string _OrgCode;
private long _UserID;
private string _UserCode;
private DateTime _Datetime;
private string _CultureName;
private string _EnterpriseID;
/// <summary>
/// 组织ID
/// </summary>
public long OrgID
{
get { return _OrgID; }
set { _OrgID = value; }
}
/// <summary>
/// 组织编码
/// </summary>
public string OrgCode
{
get { return _OrgCode; }
set { _OrgCode = value; }
}
/// <summary>
/// 操作员ID
/// </summary>
public long UserID
{
get { return _UserID; }
set { _UserID = value; }
}
/// <summary>
/// 操作员编码
/// </summary>
public string UserCode
{
get { return _UserCode; }
set { _UserCode = value; }
}
/// <summary>
/// 时间
/// </summary>
public DateTime Datetime
{
get { return _Datetime; }
set { _Datetime = value; }
}
/// <summary>
/// 语言
/// </summary>
public string CultureName
{
get { return _CultureName; }
set { _CultureName = value; }
}
/// <summary>
/// 企业ID号
/// </summary>
public string EnterpriseID
{
get { return _EnterpriseID; }
set { _EnterpriseID = value; }
}
public contextInfo()
{
CultureName = "zh_CN";
Datetime = DateTime.Now;
}
}
#endregion
#region 返回信息类
public class rtnRcvInfo
{
public string DocNo { get; set; }
public bool IsSuccess { get; set; }
public string Message { get; set; }
public rtnRcvLine[] rtnLines { get; set; }
}
public class rtnRcvLine
{
public int LineNo { get; set; }
//public string srcDocNo { get; set; }
//public int srcLineNo { get; set; }
//public decimal reqQty { get; set; }
//public string proCode { get; set; }
}
#endregion
#region 表体类
//public class rCVLine
//{
// /// <summary>
// /// 来源采购订单
// /// </summary>
// public string srcDocPONo { get; set; }
// private int _srcDocPOLineNo;
// private decimal _reqQty;
// public string WhCode { get; set; }
// /// <summary>
// /// 炉号
// /// </summary>
// public string FurnaceNo { get; set; }
// /// <summary>
// /// 数量
// /// </summary>
// public decimal ReqQty
// {
// get { return _reqQty; }
// set { _reqQty = value; }
// }
// /// <summary>
// /// 来源采购订单行
// /// </summary>
// public int srcDocPOLineNo
// {
// get { return _srcDocPOLineNo; }
// set { _srcDocPOLineNo = value; }
// }
//}
#endregion
}