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.
384 lines
17 KiB
384 lines
17 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.Exceptions1;
|
|
using UFSoft.UBF.Service;
|
|
using UFSoft.UBF.Util.Context;
|
|
using www.ufida.org.EntityData;
|
|
|
|
namespace UFIDA.ISV.BFIssueApprove
|
|
{
|
|
public class CustApproveIssue
|
|
{
|
|
/// <summary>
|
|
/// 审核领料单
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
///
|
|
public OperationResult CustBFApproveIssue(List<string> LLCodeList, string OrgCode)
|
|
{
|
|
OperationResult result = new OperationResult();
|
|
ThreadContext context;
|
|
try
|
|
{
|
|
StringBuilder strHead = new StringBuilder();
|
|
string _MOCode = string.Empty;
|
|
UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient client = new UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient();
|
|
MessageBase[] message = null;
|
|
List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData> LLlist = new List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData>();
|
|
UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
|
|
UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] resultList = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] { };
|
|
string OrgID = "";
|
|
if (LLCodeList != null && LLCodeList.Count != 0)
|
|
{
|
|
strHead.AppendLine("***************审核领料单开始****************:");
|
|
strHead.AppendLine("组织编码:" + OrgCode);
|
|
string orgsql = @"select ID from Base_Organization
|
|
where Code='{0}'";
|
|
orgsql = string.Format(orgsql, OrgCode);
|
|
DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
|
|
if (orgdt.Rows.Count != 0)
|
|
{
|
|
OrgID = orgdt.Rows[0]["ID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "组织编码:" + OrgCode + "不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
foreach (string Code in LLCodeList)
|
|
{
|
|
strHead.AppendLine("单号:" + Code);
|
|
string checksql = @"select * from MO_IssueDoc
|
|
where DocNo='" + Code + "' AND Org='" + OrgID + "'";
|
|
checksql = string.Format(checksql);
|
|
DataTable dtcheck = DBhlper.Query(checksql, Appconfig.GetU9ConnStr());
|
|
if (dtcheck.Rows.Count == 0)
|
|
{
|
|
result.MESSAGE = "领料单号:'" + Code + "'不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
|
|
LL.m_docNo = Code;
|
|
LL.m_operateType = true;
|
|
LLlist.Add(LL);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "传入数据不能为空!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
|
|
strHead.AppendLine("***************审核领料单结束****************:");
|
|
Appconfig.WriteLogFile(strHead.ToString(), "审核生产领料单");
|
|
context = CreateContextObj(OrgID);
|
|
resultList = client.Do(out message, context, LLlist.ToArray(), false, false);
|
|
if (resultList != null && resultList.Count() > 0)
|
|
{
|
|
StringBuilder str = new StringBuilder();
|
|
foreach (var item in resultList)
|
|
{
|
|
if (item.m_isSucceed == true)
|
|
{
|
|
#region 审核成功后修改单据的修改人和审核人为WMS
|
|
foreach (string Code in LLCodeList)
|
|
{
|
|
Appconfig.UpdateDocApproveMan(Code, OrgID, "WMS", "MO_IssueDoc", "MO_IssueDocLine");
|
|
}
|
|
#endregion
|
|
}
|
|
result.LLCode = item.m_docNo;
|
|
result.MESSAGE = item.m_errorMsg;
|
|
result.IsSuccess = item.m_isSucceed;
|
|
str.AppendLine("审核生产领料单:");
|
|
str.AppendLine("单号:" + item.m_docNo);
|
|
str.AppendLine("返回信息:" + item.m_errorMsg);
|
|
}
|
|
Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
|
|
}
|
|
else
|
|
{
|
|
#region 审核成功后修改单据的修改人和审核人为WMS
|
|
foreach (string Code in LLCodeList)
|
|
{
|
|
Appconfig.UpdateDocApproveMan(Code, OrgID, "WMS", "MO_IssueDoc", "MO_IssueDocLine");
|
|
}
|
|
#endregion
|
|
StringBuilder str = new StringBuilder();
|
|
foreach (string docNo in LLCodeList)
|
|
{
|
|
str.AppendLine("审核生产领料单:");
|
|
str.AppendLine("单号:" + docNo);
|
|
str.AppendLine("审核成功");
|
|
}
|
|
Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
|
|
result.MESSAGE = "审核成功";
|
|
result.IsSuccess = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = GetExceptionMessage(ex);
|
|
result.IsSuccess = false;
|
|
result.MESSAGE += Message;
|
|
StringBuilder str = new StringBuilder();
|
|
str.AppendLine("审核生产领料单:");
|
|
for (int i = 0; i < LLCodeList.Count(); i++)
|
|
{
|
|
str.AppendLine("单号:" + LLCodeList[i]);
|
|
}
|
|
str.AppendLine("返回错误信息:" + Message);
|
|
Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
|
|
}
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 审核领料单
|
|
/// </summary>
|
|
/// <param name="LLCodeList"></param>
|
|
/// <param name="OrgCode"></param>
|
|
/// <param name="UserCode"></param>
|
|
/// <returns></returns>
|
|
public OperationResult CustBFApproveIssue(string LLCode, string OrgCode, string UserCode)
|
|
{
|
|
OperationResult result = new OperationResult();
|
|
ThreadContext context;
|
|
try
|
|
{
|
|
StringBuilder strHead = new StringBuilder();
|
|
string _MOCode = string.Empty;
|
|
UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient client = new UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient();
|
|
MessageBase[] message = null;
|
|
List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData> LLlist = new List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData>();
|
|
UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
|
|
UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] resultList = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] { };
|
|
string OrgID = "";
|
|
string CreateBy = string.Empty;
|
|
if (LLCode != null && LLCode != "")
|
|
{
|
|
strHead.AppendLine("***************审核领料单开始****************:");
|
|
strHead.AppendLine("组织编码:" + OrgCode);
|
|
string orgsql = @"select ID from Base_Organization
|
|
where Code='{0}'";
|
|
orgsql = string.Format(orgsql, OrgCode);
|
|
DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
|
|
if (orgdt.Rows.Count != 0)
|
|
{
|
|
OrgID = orgdt.Rows[0]["ID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "组织编码:" + OrgCode + "不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
#region 获取业务员名称
|
|
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, UserCode, OrgID);
|
|
DataTable userdt = DBhlper.Query(usersql, Appconfig.GetU9ConnStr());
|
|
#endregion
|
|
if (userdt.Rows.Count != 0)
|
|
{
|
|
CreateBy = userdt.Rows[0]["Name"].ToString();
|
|
}
|
|
else
|
|
{
|
|
CreateBy = "U9ERP";
|
|
}
|
|
strHead.AppendLine("单号:" + LLCode);
|
|
string checksql = @"select * from MO_IssueDoc
|
|
where DocNo='" + LLCode + "' AND Org='" + OrgID + "'";
|
|
checksql = string.Format(checksql);
|
|
DataTable dtcheck = DBhlper.Query(checksql, Appconfig.GetU9ConnStr());
|
|
if (dtcheck.Rows.Count == 0)
|
|
{
|
|
result.MESSAGE = "领料单号:'" + LLCode + "'不存在!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
|
|
LL.m_docNo = LLCode;
|
|
LL.m_operateType = true;
|
|
LLlist.Add(LL);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result.MESSAGE = "传入领料单号不能为空!";
|
|
result.IsSuccess = false;
|
|
return result;
|
|
}
|
|
|
|
strHead.AppendLine("***************审核领料单结束****************:");
|
|
Appconfig.WriteLogFile(strHead.ToString(), "审核生产领料单");
|
|
context = CreateContextObj(OrgID);
|
|
resultList = client.Do(out message, context, LLlist.ToArray(), false, false);
|
|
if (resultList != null && resultList.Count() > 0)
|
|
{
|
|
StringBuilder str = new StringBuilder();
|
|
foreach (var item in resultList)
|
|
{
|
|
result.LLCode = item.m_docNo;
|
|
result.MESSAGE = item.m_errorMsg;
|
|
result.IsSuccess = item.m_isSucceed;
|
|
str.AppendLine("审核生产领料单:");
|
|
str.AppendLine("单号:" + item.m_docNo);
|
|
str.AppendLine("返回信息:" + item.m_errorMsg);
|
|
}
|
|
Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
|
|
}
|
|
else
|
|
{
|
|
StringBuilder str = new StringBuilder();
|
|
str.AppendLine("审核生产领料单:");
|
|
str.AppendLine("单号:" + LLCode);
|
|
str.AppendLine("审核成功");
|
|
Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
|
|
result.MESSAGE = "审核成功";
|
|
result.IsSuccess = true;
|
|
}
|
|
if (result.IsSuccess == true)
|
|
{
|
|
string updatesql = @"select ID from MO_IssueDoc
|
|
where DOCNO='{0}' AND Org='{1}'";
|
|
updatesql = string.Format(updatesql, LLCode, OrgID);
|
|
DataTable updatedt = DBhlper.Query(updatesql, Appconfig.GetU9ConnStr());
|
|
if (updatedt.Rows.Count != 0)
|
|
{
|
|
string LLID = updatedt.Rows[0]["ID"].ToString();
|
|
updatesql = @"update MO_IssueDoc set ApproveBy='{1}'
|
|
where ID='{0}'";
|
|
updatesql = string.Format(updatesql, LLID, CreateBy);
|
|
DBhlper.EXecute(updatesql, Appconfig.GetU9ConnStr());
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = GetExceptionMessage(ex);
|
|
result.IsSuccess = false;
|
|
result.MESSAGE += Message;
|
|
StringBuilder str = new StringBuilder();
|
|
str.AppendLine("审核生产领料单:");
|
|
str.AppendLine("单号:" + LLCode);
|
|
str.AppendLine("返回错误信息:" + Message);
|
|
Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <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());
|
|
ns.Add("acttype", ConfigurationManager.AppSettings["acttype"].ToString());
|
|
thContext.nameValueHas = ns;
|
|
|
|
return thContext;
|
|
|
|
return thContext;
|
|
}
|
|
|
|
|
|
#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; }
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|