using ICSSoft.Common;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSSoft.Entity;
using UFSoft.UBF.Util.Context;
using System.ServiceModel;
using www.ufida.org.EntityData;
using UFSoft.UBF.Exceptions1;
namespace ICSSoft.APIUnApproveCompRpt
{
public class UnApproveCompRpt
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
///
/// 弃审完工报告(外部通过API调用)
///
///
///
public bool UnApprove(List infos)
{
bool ResultFlag = false;
try
{
//实例化代理类
UFIDAU9ISVMOIUnApproveCompleteRptClient client = new UFIDAU9ISVMOIUnApproveCompleteRptClient();
//服务返回结果
UFIDAU9ISVMOCompRptKeyDTOData[] returnValue;
//返回异常信息,目前还没有使用此属性
UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
//上下文信息
object context;
//UFSoft.UBF.Business.BusinessEntity.EntityKey dochead = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
//传入 参数
UFIDAU9ISVMOCompRptKeyDTOData[] dOList;
string OrgID = "";
string orgsql = @"select ID from Base_Organization
where Code='{0}'";
orgsql = string.Format(orgsql, infos[0].WorkPoint);
DataTable orgdt = DBHelper.Query(orgsql, connString);
if (orgdt.Rows.Count != 0)
{
OrgID = orgdt.Rows[0]["ID"].ToString();
}
else
{
throw new Exception("传入组织编码错误!");
}
//给上下文信息赋值
context = CreateContextObj(OrgID);
//给传入参数赋值
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
List DocList = new List();
UFIDAU9ISVMOCompRptKeyDTOData[] DocArray = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
foreach (ICSManufactureReceiveDoc Info in infos)
{
long DocID = GetTypeID(Info.MRCVCode, OrgID);
UFIDAU9ISVMOCompRptKeyDTOData DocInfo = new UFIDAU9ISVMOCompRptKeyDTOData();
DocInfo.m_iD = DocID;
DocList.Add(DocInfo);
}
DocArray = DocList.ToArray();
ResultFlag = client.Do(out returnMsg, context, DocArray);
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
return ResultFlag;
}
///
/// 弃审完工报告(接口内部调用,如:创建退料单后调用审核单据)
///
///
///
///
public bool UnApprove(List DocNOList, string OrgCode)
{
bool ResultFlag = false;
try
{
//实例化代理类
UFIDAU9ISVMOIUnApproveCompleteRptClient client = new UFIDAU9ISVMOIUnApproveCompleteRptClient();
//服务返回结果
UFIDAU9ISVMOCompRptKeyDTOData[] returnValue;
//返回异常信息,目前还没有使用此属性
UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
//上下文信息
object context;
//UFSoft.UBF.Business.BusinessEntity.EntityKey dochead = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
//传入 参数
UFIDAU9ISVMOCompRptKeyDTOData[] dOList;
string OrgID = "";
string orgsql = @"select ID from Base_Organization
where Code='{0}'";
orgsql = string.Format(orgsql, OrgCode);
DataTable orgdt = DBHelper.Query(orgsql, connString);
if (orgdt.Rows.Count != 0)
{
OrgID = orgdt.Rows[0]["ID"].ToString();
}
else
{
throw new Exception("传入组织编码错误!");
}
//给上下文信息赋值
context = CreateContextObj(OrgID);
//给传入参数赋值
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
List DocList = new List();
UFIDAU9ISVMOCompRptKeyDTOData[] DocArray = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
foreach (string DocNo in DocNOList)
{
long DocID = GetTypeID(DocNo, OrgID);
UFIDAU9ISVMOCompRptKeyDTOData DocInfo = new UFIDAU9ISVMOCompRptKeyDTOData();
DocInfo.m_iD = DocID;
DocList.Add(DocInfo);
}
DocArray = DocList.ToArray();
ResultFlag = client.Do(out returnMsg, context, DocArray);
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
return ResultFlag;
}
private static long GetTypeID(string docTypeCode, string OrgID)
{
string sql = @"select ID from MO_CompleteRpt where DocNo='" + docTypeCode + "' AND Org='" + OrgID + "' ";
DataTable dt = DBHelper.Query(sql, connString);
if (dt.Rows.Count > 0)
{
return long.Parse(dt.Rows[0][0].ToString());
}
else
{
return 0;
}
}
#region 给上下文信息赋值
///
/// 给上下文信息赋值
///
///
private static ThreadContext CreateContextObj(string OrgID)
{
// 实例化应用上下文对象
ThreadContext thContext = new ThreadContext();
System.Collections.Generic.Dictionary