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.
402 lines
18 KiB
402 lines
18 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 UFIDA.ISV.BFIssueApprove;
|
|
using UFIDA.ISV.BFIssueDelete;
|
|
using UFIDA.ISV.CreateLotMaster;
|
|
using UFSoft.UBF.Exceptions;
|
|
using UFSoft.UBF.Service;
|
|
using UFSoft.UBF.Util.Context;
|
|
using www.ufida.org.EntityData;
|
|
|
|
namespace UFIDA.ISV.CreateIssue
|
|
{
|
|
public class CustCreateIssue
|
|
{
|
|
/// <summary>
|
|
/// 创建退料单
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
///
|
|
public OperationResult CreateIssue(List<IssueData> modellist)
|
|
{
|
|
OperationResult result = new OperationResult();
|
|
ThreadContext context = new ThreadContext();
|
|
try
|
|
{
|
|
StringBuilder beginstrlog = new StringBuilder();
|
|
beginstrlog.AppendLine("创建退料单(传入数据开始)");
|
|
beginstrlog.AppendLine("*****************************************************");
|
|
foreach (var model in modellist)
|
|
{
|
|
beginstrlog.AppendLine("生产领料单:" + model.LLCode);
|
|
beginstrlog.AppendLine("备注:" + model.Memo);
|
|
beginstrlog.AppendLine("组织编码:" + model.OrgCode);
|
|
beginstrlog.AppendLine("用户编码:" + model.UserCode);
|
|
foreach (var item in model.linelist)
|
|
{
|
|
bool isLotCheck = Appconfig.WHLotCheckState(item.WHCode, model.OrgCode);
|
|
if (isLotCheck == false)
|
|
{
|
|
item.LotNO = "";
|
|
}
|
|
beginstrlog.AppendLine("领料单行号:" + item.LLLineNO);
|
|
beginstrlog.AppendLine("料号:" + item.ItemCode);
|
|
beginstrlog.AppendLine("数量:" + item.ItemQty);
|
|
beginstrlog.AppendLine("仓库:" + item.WHCode);
|
|
beginstrlog.AppendLine("批号:" + item.LotNO);
|
|
}
|
|
beginstrlog.AppendLine("--------------------------------------------------");
|
|
|
|
}
|
|
beginstrlog.AppendLine("*****************************************************");
|
|
beginstrlog.AppendLine("创建退料单(传入数据结束)");
|
|
Appconfig.WriteLogFile(beginstrlog.ToString(), "创建退料单");
|
|
string _MOCode = string.Empty;
|
|
UFIDAU9ISVMOICreatRecedeIssueDocSVClient client = new UFIDAU9ISVMOICreatRecedeIssueDocSVClient();
|
|
MessageBase[] message = null;
|
|
List<UFIDAU9ISVMORecedeItemAndSnDTOData> molist = new List<UFIDAU9ISVMORecedeItemAndSnDTOData>();
|
|
UFIDAU9ISVMORecedeItemAndSnDTOData mo = new UFIDAU9ISVMORecedeItemAndSnDTOData();
|
|
|
|
UFIDAU9CBOPubControllerCommonArchiveDataDTOData docType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
|
|
|
|
StringBuilder str = new StringBuilder();
|
|
str.AppendLine("************领料单日志记录开始**************");
|
|
str.AppendLine("组织编码:" + modellist[0].OrgCode);
|
|
string OrgID = "";
|
|
string orgsql = @"select ID from Base_Organization
|
|
where Code='{0}'";
|
|
orgsql = string.Format(orgsql, modellist[0].OrgCode);
|
|
DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
|
|
if (orgdt.Rows.Count != 0)
|
|
{
|
|
OrgID = orgdt.Rows[0]["ID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "组织编码:" + modellist[0].OrgCode + "不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
#region 获取业务员名称
|
|
string CreateBy = string.Empty;
|
|
string usersql = @"select B.Name from CBO_Operators A
|
|
LEFT JOIN CBO_Operators_Trl B
|
|
ON B.ID=A.ID
|
|
where A.Code='{0}' and A.Org='{1}'";
|
|
usersql = string.Format(usersql, modellist[0].UserCode, OrgID);
|
|
DataTable userdt = DBhlper.Query(usersql, Appconfig.GetU9ConnStr());
|
|
#endregion
|
|
if (userdt.Rows.Count != 0)
|
|
{
|
|
CreateBy = userdt.Rows[0]["Name"].ToString();
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
foreach (IssueData model in modellist)
|
|
{
|
|
|
|
if (!string.IsNullOrWhiteSpace(model.LLCode))
|
|
{
|
|
str.AppendLine("单号:" + model.LLCode);
|
|
string LLID = "";
|
|
string llsql = @"select ID from MO_IssueDoc
|
|
where DocNo='{0}' And Org='{1}'";
|
|
llsql = string.Format(llsql, model.LLCode, OrgID);
|
|
DataTable lldt = DBhlper.Query(llsql, Appconfig.GetU9ConnStr());
|
|
if (lldt.Rows.Count > 0)
|
|
{
|
|
LLID = lldt.Rows[0]["ID"].ToString();
|
|
str.AppendLine("主键ID:" + LLID);
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "领料单:" + model.LLCode + "不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
#region 遍历入参LL单行
|
|
foreach (var item in model.linelist)
|
|
{
|
|
mo = new UFIDAU9ISVMORecedeItemAndSnDTOData();
|
|
long lllineID = 0;
|
|
llsql = @"select ID,IsIssued from MO_IssueDocLine
|
|
where IssueDoc='{0}'
|
|
AND LineNum={1}";
|
|
llsql = string.Format(llsql, LLID, item.LLLineNO);
|
|
lldt = DBhlper.Query(llsql, Appconfig.GetU9ConnStr());
|
|
if (lldt.Rows.Count > 0)
|
|
{
|
|
if (lldt.Rows[0]["IsIssued"].ToString() != "True" && lldt.Rows[0]["IsIssued"].ToString() != "true")
|
|
{
|
|
result.MESSAGE = "领料单:'" + model.LLCode + "'对应领料单行:'" + item.LLLineNO + "'未进行发料确认,不能退料!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
lllineID = long.Parse(lldt.Rows[0]["ID"].ToString());
|
|
str.AppendLine("子表主键ID:" + lllineID);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "领料单:'" + model.LLCode + "'对应领料单行:'" + item.LLLineNO + "'不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
|
|
mo.m_issueDocLine = lllineID;
|
|
string strCcode = item.ItemCode; //子料
|
|
|
|
string strWhCode = string.Empty; //仓库
|
|
string _strWhID = string.Empty;//仓库ID
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCcode))
|
|
{
|
|
string sqlWH = @"select ID,Code from CBO_Wh
|
|
WHERE Code='" + item.WHCode + "' AND Org='" + OrgID + "'";
|
|
sqlWH = string.Format(sqlWH);
|
|
DataTable _dtWH = DBhlper.Query(sqlWH, Appconfig.GetU9ConnStr());
|
|
if (_dtWH.Rows.Count == 0)
|
|
{
|
|
result.MESSAGE = strCcode + "没有仓库信息 ";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
strWhCode = _dtWH.Rows[0]["Code"].ToString();
|
|
_strWhID = _dtWH.Rows[0]["ID"].ToString();
|
|
mo.m_whCode = strWhCode;
|
|
mo.m_wh = long.Parse(_strWhID);
|
|
str.AppendLine("仓库:" + mo.m_whCode);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = strCcode + "没有子料信息 ";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
int i = Appconfig.IsExistItem(strCcode);
|
|
if (i < 1)
|
|
{
|
|
result.MESSAGE = "料品编码不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
str.AppendLine("数量:" + item.ItemQty);
|
|
str.AppendLine("物料编码:" + item.ItemCode);
|
|
str.AppendLine("批号:" + item.LotNO);
|
|
|
|
mo.m_recedeQty = item.ItemQty;
|
|
mo.m_itemCode = item.ItemCode;
|
|
mo.m_recedeReason = 3;
|
|
#region 创建批号接口调用
|
|
string LotID = "";
|
|
if (item.LotNO != "")
|
|
{
|
|
CustCreateLotMaster LotMasterCreate = new CustCreateLotMaster();
|
|
string lotWHCode = item.WHCode;
|
|
string lotItemCode = item.ItemCode;
|
|
string LotCode = item.LotNO;
|
|
LotMasterCreate.CustCreateRCVLotMaster(lotWHCode, lotItemCode, LotCode, OrgID, ref LotID);
|
|
if (LotID != "")
|
|
{
|
|
mo.m_lotMaster = long.Parse(LotID);
|
|
mo.m_lotNo = item.LotNO;
|
|
}
|
|
}
|
|
#endregion
|
|
str.AppendLine("批号ID:" + LotID);
|
|
molist.Add(mo);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "存在领料单号为空";
|
|
result.IsSuccess = false;
|
|
|
|
return result;
|
|
}
|
|
docType.m_code = "21";
|
|
docType.m_iD = 1002201100110115;
|
|
docType.m_name = "退料补料(补料)";
|
|
}
|
|
|
|
str.AppendLine("////////////molist记录开始/////////////");
|
|
foreach (var item in molist)
|
|
{
|
|
str.AppendLine("item.m_issueDocLine:" + item.m_issueDocLine);
|
|
str.AppendLine("item.m_recedeQty:" + item.m_recedeQty);
|
|
str.AppendLine("item.m_itemCode:" + item.m_itemCode);
|
|
str.AppendLine("item.m_whCode:" + item.m_whCode);
|
|
str.AppendLine("item.m_wh:" + item.m_wh);
|
|
}
|
|
str.AppendLine("////////////molist记录结束/////////////");
|
|
str.AppendLine("**************日志结束******************");
|
|
Appconfig.WriteLogFile(str.ToString(), "创建退料单");
|
|
context = CreateContextObj(OrgID);
|
|
string[] _result = null;
|
|
_result = client.Do(out message, context, molist.ToArray(), false, docType);
|
|
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(), "创建退料单");
|
|
if (LLCodeList != null)
|
|
{
|
|
CustApproveIssue.OperationResult shResult = new CustApproveIssue.OperationResult();
|
|
CustApproveIssue sh = new CustApproveIssue();
|
|
shResult = sh.CustBFApproveIssue(LLCodeList, modellist[0].OrgCode);
|
|
if (shResult.IsSuccess == true)
|
|
{
|
|
result.IsSuccess = true;
|
|
result.LLCode = _result[0].ToString();
|
|
result.MESSAGE = "退料单创建成功!";
|
|
}
|
|
else
|
|
{
|
|
CustBFIssueDelete issueDelete = new CustBFIssueDelete();
|
|
issueDelete.CustDeleteIssue(LLCodeList, OrgID);
|
|
result.IsSuccess = false;
|
|
result.MESSAGE = shResult.MESSAGE;
|
|
}
|
|
}
|
|
|
|
}
|
|
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;
|
|
}
|
|
|
|
|
|
# region 辅助方法
|
|
|
|
|
|
/// <summary>
|
|
/// 创建上下文
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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; }
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|