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

364 lines
16 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 UFSoft.UBF.Exceptions;
using UFSoft.UBF.Service;
using www.ufida.org.EntityData;
namespace ICS.CreateIssueIN
{
public class CreateIssue
{
//private static string ORGCode = ConfigurationManager.AppSettings["orgCode"].ToString();
public OperationResult CreateIssue1(List<IssueData> 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);
beginstrlog.AppendLine("组织:" + model.OrgCode);
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;
UFIDAU9ISVMOICreateIssue4ExternalClient client = new UFIDAU9ISVMOICreateIssue4ExternalClient();
MessageBase[] message = null;
StringBuilder str = new StringBuilder();
string ORGCode = modellist[0].OrgCode;
string OrgID = "";
OrgID = Appconfig.IsExistsCode(ORGCode, "Base_Organization");
if (string.IsNullOrEmpty(OrgID))
{
throw new Exception("组织编码:" + ORGCode + "在U9中不存在。");
}
UFIDAU9ISVMOIssueDTOData[] molist = createiss(modellist, OrgID,ORGCode);
context = CreateContextObj(OrgID);
UFIDAU9ISVMOIssueKeyDTOData[] _result = null;
_result = client.Do(out message, context, molist);
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(), "创建生产备料单");
}
//"必需设置请指定IssueDTO.BusinessType属性,生产线日计划:51,标准生产:47,返工生产:48,报废生产:49"
return result;
}
private UFIDAU9ISVMOIssueDTOData[] createiss(List<IssueData> modellist,string OrgID,string ORGCode)
{
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();
lss.m_issueType = 0;
lss.sysState = 0;
UFIDAU9CBOPubControllerCommonArchiveDataDTOData d = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
d.m_iD = Convert.ToInt64(OrgID);
d.m_code = ORGCode;
lss.m_issueOrg = d;
lss.m_memo = model.memo;
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 (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;
//}
// 批号
//弹性栏位:
//pickListDTO.DescFlexField = new DescFlexSegmentsData();
//pickListDTO.DescFlexField.PrivateDescSeg1 = dd.ItemRLineID;//弹性栏位1存料品需求单行ID
// 备料
//pickListDTO.MOPickList = moPickList.ID;
// 货主组织
UFIDAU9CBOPubControllerCommonArchiveDataDTOData org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
mo.m_iD =long.Parse( OrgID);
mo.m_code = ORGCode;// 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;
}
# 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 OrgCode { get; set; }
public string memo { 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; }
}
}
}