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;
using UFSoft.UBF.Service;
namespace ICSSoft.APIApproveMiscShip
{
public class ApproveMiscShip
{
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 Approve(List infos)
{
bool ResultFlag = false;
UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient client = new UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient();
//返回异常信息,目前还没有使用此属性
MessageBase[] returnMsg;
//上下文信息
object context;
//传入 参数
try
{
if (infos == null || infos.Count == 0)
{
throw new Exception("传入数据不能为空!");
}
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("传入组织编码错误!");
}
UFIDAU9ISVMiscShipISVIC_MiscShipmentDTOData[] returnItems;
//给上下文信息赋值
context = CreateContextObj(OrgID);
//给传入参数赋值
//服务调用
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] queryArr = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] { };
List queryList = new List();
UFIDAU9CBOPubControllerCommonArchiveDataDTOData q = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
foreach (ICSOtherOutDoc Info in infos)
{
string DocNo = "";
string sql = @"SELECT DocNO FROM InvDoc_MiscShip a WHERE a.ID='" + Info.ID + "' AND Org='" + OrgID + "'";
DataTable dt = DBHelper.Query(sql, connString);
if (dt != null && dt.Rows.Count > 0)
{
string a = dt.Rows[0][0].ToString();
if (string.IsNullOrWhiteSpace(a))
{
throw new Exception("传入单据ID有误,请确认!");
}
else
{
DocNo = a;
}
}
else
{
throw new Exception("传入单据ID有误,请确认!");
}
q.m_iD = long.Parse(Info.ID);
q.m_code = DocNo;
queryList.Add(q);
}
queryArr = queryList.ToArray();
returnItems = client.Do(out returnMsg, context, queryArr);
ResultFlag = true;
}
catch (Exception ex)
{
log.Error(GetExceptionMessage(ex));
throw new Exception(GetExceptionMessage(ex));
}
return ResultFlag;
}
///
/// 审核杂发单(接口内部调用,如:创建退料单后调用审核单据)
///
///
///
///
public bool Approve(List DocIDList, string OrgCode)
{
bool ResultFlag = false;
UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient client = new UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient();
//返回异常信息,目前还没有使用此属性
MessageBase[] returnMsg;
//上下文信息
object context;
//传入 参数
try
{
if (DocIDList == null || DocIDList.Count == 0)
{
throw new Exception("传入数据不能为空!");
}
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("传入组织编码错误!");
}
UFIDAU9ISVMiscShipISVIC_MiscShipmentDTOData[] returnItems;
//给上下文信息赋值
context = CreateContextObj(OrgID);
//给传入参数赋值
//服务调用
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] queryArr = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] { };
List queryList = new List();
UFIDAU9CBOPubControllerCommonArchiveDataDTOData q = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
foreach (string ID in DocIDList)
{
string DocNo = "";
string sql = @"SELECT DocNO FROM InvDoc_MiscShip a WHERE a.ID='" + ID + "' AND Org='" + OrgID + "'";
DataTable dt = DBHelper.Query(sql, connString);
if (dt != null && dt.Rows.Count > 0)
{
string a = dt.Rows[0][0].ToString();
if (string.IsNullOrWhiteSpace(a))
{
throw new Exception("传入单据ID有误,请确认!");
}
else
{
DocNo = a;
}
}
else
{
throw new Exception("传入单据ID有误,请确认!");
}
q.m_iD = long.Parse(ID);
q.m_code = DocNo;
queryList.Add(q);
}
queryArr = queryList.ToArray();
returnItems = client.Do(out returnMsg, context, queryArr);
ResultFlag = true;
}
catch (Exception ex)
{
log.Error(GetExceptionMessage(ex));
throw new Exception(GetExceptionMessage(ex));
}
return ResultFlag;
}
#region 给上下文信息赋值
///
/// 给上下文信息赋值
///
///
private static ThreadContext CreateContextObj(string OrgID)
{
// 实例化应用上下文对象
ThreadContext thContext = new ThreadContext();
System.Collections.Generic.Dictionary