|
|
using ICS.WCF.Base; using ICSSoft.Entity; 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.Exceptions1; using UFSoft.UBF.Service; using UFSoft.UBF.Util.Context; using www.ufida.org.EntityData;
namespace ICS.CreateSMShip { public class CreateSMShip { private static string ORGCode = ConfigurationManager.AppSettings["orgCode"].ToString(); public OperationResult CustCreateSMShip(List<SMShip> modellist) { OperationResult result = new OperationResult(); //object context = new object();
try { StringBuilder beginstrlog = new StringBuilder(); beginstrlog.AppendLine("创建委外备料单(传入数据开始)"); beginstrlog.AppendLine("*****************************************************"); foreach (var model in modellist) { //beginstrlog.AppendLine("生产订单:" + model.MOCODE);
//foreach (var item in model.linelist)
//{
// beginstrlog.AppendLine("行号:" + item.DOCLINENO);
// beginstrlog.AppendLine("料号:" + item.ITEM);
// beginstrlog.AppendLine("实际需求数量:" + item.ActualReqQty);
// beginstrlog.AppendLine("标准用量:" + item.STDReqQty);
//}
beginstrlog.AppendLine("--------------------------------------------------");
} beginstrlog.AppendLine("*****************************************************"); beginstrlog.AppendLine("创建委外备料单(传入数据结束)"); Appconfig.WriteLogFile(beginstrlog.ToString(), "创建委外备料单"); string _MOCode = string.Empty; UFIDAU9ISVSMISMPullSrcDocSVClient client = new UFIDAU9ISVSMISMPullSrcDocSVClient(); MessageBase[] message = null;
StringBuilder str = new StringBuilder();
string OrgID = "";
OrgID = Appconfig.IsExistsCode(ORGCode, "Base_Organization");
if (string.IsNullOrEmpty(OrgID)) { throw new Exception("组织编码:" + ORGCode + "在U9中不存在。"); } ThreadContext context = CreateContextObj(OrgID); //context = CreateContextObj(OrgID);
//UFIDAU9ISVMOIssueKeyDTOData[] _result = null;
long shipDocTypeID = 1002303100391036; DateTime shipDate = DateTime.Now;
List<UFIDAU9ISVSMSrcDocInfoDTOData> list = new List<UFIDAU9ISVSMSrcDocInfoDTOData>();
foreach (var item in modellist) { UFIDAU9ISVSMSrcDocInfoDTOData model = new UFIDAU9ISVSMSrcDocInfoDTOData(); model.m_curShipQty1 = item.CurShipQty1; model.m_sOIsConsign = true; model.m_srcDocType = item.SrcDocType; string SrcID = Appconfig.GetSOLineID(item.SrcDocNo, item.SrcDocLineNo,item.SrcDocSubLineNo); string _OrgID = Appconfig.GetOrgID(item.SrcDocNo, item.SrcDocLineNo); if (!string.IsNullOrWhiteSpace(SrcID)) { model.m_srcDocLineID = long.Parse(SrcID); } else { //_result.Message = "传入销售订单信息有误,请核对";
//_result.IsSuccess = false;
//str = JsonConvert.SerializeObject(_result);
//result.Content = new StringContent(str.ToString(), Encoding.GetEncoding("UTF-8"), "application/json");
//Appconfig.WriteLogFile(str.ToString(), "创建标准出货单异常日志");
//return result;
} string WHID = Appconfig.GetWhIDByCode(item.WH, OrgID); model.m_wH = long.Parse(WHID); list.Add(model); }
long[] IDD = client.Do(out message, context, shipDocTypeID, shipDate, list.ToArray()); List<string> LLCodeList = new List<string>(); StringBuilder endstr = new StringBuilder(); endstr.AppendLine("**************创建委外备料单返回日志******************"); //if (_result != null && _result.Count() > 0)
//{
// for (int i = 0; i < _result.Count(); i++)
// {
// LLCodeList.Add(_result[i].ToString());
// endstr.AppendLine("退料单号" + _result[i].ToString());
// }
//}
endstr.AppendLine("**************创建委外备料单返回日志结束******************"); Appconfig.WriteLogFile(endstr.ToString(), "创建委外备料单");
} catch (Exception ex) { string Message = GetExceptionMessage(ex); result.IsSuccess = false; result.MESSAGE += Message; StringBuilder str = new StringBuilder(); str.AppendLine("创建委外备料单:"); //for (int i = 0; i < modellist.Count(); i++)
//{
// str.AppendLine("单号:" + modellist[i]);
//}
str.AppendLine("返回错误信息:" + result.MESSAGE); Appconfig.WriteLogFile(str.ToString(), "创建委外备料单"); }
return result; }
// private UFIDAU9ISVMOIssueDTOData[] createiss(List<IssueData> modellist, string OrgID)
// {
// List<UFIDAU9ISVMOIssueDTOData> lsslist = new List<UFIDAU9ISVMOIssueDTOData>();
// foreach (IssueData model in modellist)
// {
// string moid = "";
// UFIDAU9ISVMOIssueDTOData lss = new UFIDAU9ISVMOIssueDTOData();
// if (!string.IsNullOrWhiteSpace(model.MOCODE))
// {
// string orgsql = @"select ID from MO_MO
// where DocNo='{0}'";
// orgsql = string.Format(orgsql, model.MOCODE);
// DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
// if (orgdt.Rows.Count != 0)
// {
// moid = orgdt.Rows[0]["ID"].ToString();
// }
// else
// throw new Exception("工单:" + model.MOCODE + "不存在!");
// List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData> molst = new List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData>();
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData mo1 = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// mo1.m_iD = Convert.ToInt64(moid);
// mo1.m_code = model.MOCODE;
// molst.Add(mo1);
// lss.m_mOs = molst.ToArray();
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData d = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// d.m_iD = Convert.ToInt64(OrgID);
// d.m_code = ORGCode;
// lss.m_issueOrg = d;
// List<UFIDAU9ISVMOPickListDTOData> picklst = new List<UFIDAU9ISVMOPickListDTOData>();
// UFIDAU9ISVMOPickListDTOData pick = new UFIDAU9ISVMOPickListDTOData();
// foreach (IssueDatas line in model.linelist)
// {
// string ORGID = Appconfig.IsExistsCode(line.ORGCODE, "Base_Organization");
// if (string.IsNullOrEmpty(ORGID))
// {
// throw new Exception("组织编码:" + line.ORGCODE + "在U9中不存在。");
// }
// pick.m_aCDType = 0;
// //无备料领料
// pick.m_isNoPickLine = true;
// //生产订单
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData mo = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// mo.m_iD = Convert.ToInt64(moid);
// mo.m_code = model.MOCODE;
// pick.m_mO = mo;
// // 料品
// string itemid = "";
// orgsql = @"select id from CBO_ItemMaster where code=='{0}'";
// orgsql = string.Format(orgsql, line.ITEM);
// orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
// if (orgdt.Rows.Count != 0)
// itemid = orgdt.Rows[0]["ID"].ToString();
// else
// throw new Exception("料品:" + line.ITEM + "不存在!");
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData item = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// mo.m_iD = Convert.ToInt64(itemid);
// mo.m_code = line.ITEM;
// pick.m_item = item;
// //领料单位
// if (Appconfig.uomid(line.UOM) != "")
// {
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData uom = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// mo.m_iD = Convert.ToInt64(Appconfig.uomid(line.UOM));
// mo.m_code = line.UOM;
// pick.m_issueUOM = uom;
// }
// //发料数量
// pick.m_issuedQty = Convert.ToDecimal(line.ActualReqQty);
// // 应发数量
// pick.m_issueQty = Convert.ToDecimal(line.ActualReqQty);
// //存储地点
// if (string.IsNullOrWhiteSpace(line.WH))
// {
// throw new Exception("第 " + line.DOCLINENO + " 行,请传入仓库 ");
// }
// if (Appconfig.GetWhCodeByBinid(line.WH, ORGID) != "")
// {
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData ww = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// mo.m_iD = Convert.ToInt64(Appconfig.GetWhCodeByBinid(line.WH, ORGID));
// mo.m_code = line.WH;
// pick.m_issueWh = ww;
// }
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// mo.m_iD = Convert.ToInt64(ORGID);
// mo.m_code = line.ORGCODE;
// pick.m_ownerOrg = org;
// //库位
// //子料项目号
// if (!string.IsNullOrEmpty(line.Project))
// {
// if (Appconfig.GetProjectid(line.Project, ORGID) != "")
// {
// UFIDAU9CBOPubControllerCommonArchiveDataDTOData project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
// mo.m_iD = Convert.ToInt64(Appconfig.GetProjectid(line.Project, ORGID));
// mo.m_code = line.Project;
// pick.m_project = project;
// }
// }
// pick.m_issueDocLineID = 1;
// picklst.Add(pick);
// }
// lss.m_pickListDTOs = picklst.ToArray();
// lsslist.Add(lss);
// }
// else
// {
// throw new Exception("存在生产订单号为空!");
// }
// }
// return lsslist.ToArray();
// }
# region 辅助方法
/// <summary>
/// 创建上下文
/// </summary>
/// <returns></returns>
//private static object CreateContextObj(string OrgID)
//{
// // 实例化应用上下文对象
// object thContext = new object();
// 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 = ns;
// return thContext;
//}
private static ThreadContext CreateContextObj(string 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 提取异常信息
/// <summary>
/// 提取异常信息
/// </summary>
/// <param name="ex"></param>
private static 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
public class OperationResult { /// <summary>
/// 结果状态,默认值false
/// </summary>
public bool IsSuccess { get; set; }
/// <summary>
///处理消息
/// </summary>
public string MESSAGE { get; set; }
/// <summary>
/// 输出领料订单
/// </summary>
public string LLCode { get; set; } }
public class IssueData { public string MOCODE { get; set; } public string DOCNO { get; set; }
public List<IssueDatas> linelist { get; set; } } public class IssueDatas { public string ORGCODE { get; set; } public string DOCLINENO { get; set; } public string ITEM { get; set; } public string UOM { get; set; } public string Project { get; set; } public string WH { get; set; } public decimal ActualReqQty { get; set; } public decimal STDReqQty { get; set; }
} } }
|