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 UFSoft.UBF.Exceptions1; using UFSoft.UBF.Service; using UFSoft.UBF.Util.Context; using www.ufida.org.EntityData; namespace UFIDA.ISV.ApproveMiscRcv { public class CustApproveMiscRcv { /// /// 审核杂收单 /// /// public OperationResult_ApproveMiscRcv CustApproveMis(string docNo, string OrgCode) { //List result = new List(); OperationResult_ApproveMiscRcv result = new OperationResult_ApproveMiscRcv(); #region 服务调用框架结构 UFIDAU9ISVMiscRcvISVICommonApproveMiscRcvClient client = new UFIDAU9ISVMiscRcvISVICommonApproveMiscRcvClient(); //返回异常信息,目前还没有使用此属性 MessageBase[] returnMsg; //上下文信息 object context; //传入 参数 try { string OrgID = ""; 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.IsSuccess = false; result.Message = "传入组织编码:" + OrgCode + "不存在!"; result.DocNo = docNo; return result; } long ID = 0L; string sql = @"SELECT ID FROM InvDoc_MiscRcvTrans a WHERE a.DocNo='" + docNo + "' AND Org='" + OrgID + "'"; DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr()); if (dt != null && dt.Rows.Count > 0) { string a = dt.Rows[0][0].ToString(); if (string.IsNullOrWhiteSpace(a)) { result.IsSuccess = false; result.Message = "请传入单号有误,请重新输入"; result.DocNo = docNo; return result; } else { ID = long.Parse(a); } } else { result.IsSuccess = false; result.Message = "请传入单号有误,请重新输入"; result.DocNo = docNo; return result; } UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData[] returnItems; //给上下文信息赋值 context = CreateContextObj(OrgID); //给传入参数赋值 //服务调用 (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue; (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue; UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] queryList = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] { }; List query = new List(); UFIDAU9CBOPubControllerCommonArchiveDataDTOData q = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData(); //q.m_code = "Mis2019110031"; q.m_iD = ID; q.m_code = docNo; query.Add(q); queryList = query.ToArray(); returnItems = client.Do(out returnMsg, context, queryList); if (returnItems != null && returnItems.Length > 0) { //获取返回信息得到创建的收货单信息 foreach (var item in returnItems) { //OperationResult_ApproveMiscRcv model = new OperationResult_ApproveMiscRcv(); result.IsSuccess = true; result.Message = "审核杂收单成功"; result.DocNo = docNo; //result.Add(model); } } else { //OperationResult_ApproveMiscRcv model = new OperationResult_ApproveMiscRcv(); result.IsSuccess = true; result.Message = "审核杂收单成功"; result.DocNo = docNo; //result.Add(model); } StringBuilder str = new StringBuilder(); str.AppendLine("审核杂收"); str.AppendLine("单号:" + docNo); str.AppendLine("消息:" + result.Message); str.AppendLine("结果:" + result.IsSuccess); Appconfig.WriteLogFile(str.ToString(), "审核杂收单"); return result; } catch (Exception ex) { //异常信息捕获 //OperationResult_ApproveMiscRcv model = new OperationResult_ApproveMiscRcv(); result.IsSuccess = false; result.Message = GetExceptionMessage(ex); result.DocNo = docNo; //result.Add(model); StringBuilder str = new StringBuilder(); str.AppendLine("审核杂收单异常"); str.AppendLine("单号:" + docNo); str.AppendLine("错误消息:" + result.Message); str.AppendLine("结果:" + "false"); Appconfig.WriteLogFile(str.ToString(), "审核杂收单异常"); return result; } #endregion } #region 给上下文信息赋值 /// /// 给上下文信息赋值 /// /// private ThreadContext CreateContextObj(string OrgID) { // 实例化应用上下文对象 ThreadContext thContext = new ThreadContext(); System.Collections.Generic.Dictionary ns = new Dictionary(); 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 string GetExceptionMessage(Exception ex) { string faultMessage = "未知错误,请查看ERP日志!"; System.TimeoutException timeoutEx = ex as System.TimeoutException; if (timeoutEx != null) { faultMessage = "访问服务超时,请修改配置信息!"; } else { FaultException faultEx = ex as FaultException; 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_ApproveMiscRcv { public string DocNo { get; set; } public bool IsSuccess { get; set; } public string Message { get; set; } } } }