using log4net;
using System;
using System.Collections.Generic;
using ADODB;
using MSXML2;
using UFIDA.U8.Framework.Api.ControlObject.Common;
using UFIDA.U8.Framework.Api.ControlObject.Entity;
using UFIDA.U8.Framework.Api.ControlObject.U8M;
using System.Collections;
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable StringLiteralTypo
namespace UFIDA.U8.Framework.Api.ControlObject.AP
{
public class UFAPBO
{
protected readonly ILog logInfo = LogManager.GetLogger("logInfo");
///
/// 收付款单保存
///
/// 登录对象
/// 单据数据
/// 子系统Id
/// 是否新增
/// 是否期初
/// 表体数据字段
///
public BaseResult CloseBillSave(BaseLogin baseLogin,Dictionary dictionary,string cSubId,bool isAdd=true, bool bFirst=false,string bodyKey="body")
{
try
{
var m_Login = baseLogin._vbLogin;
var domHead = dictionary.ToDocument2();
IXMLDOMDocument2 domBody = new DOMDocument();
if (dictionary[bodyKey] is List> bodyList && bodyList.Count > 0)
{
domBody = bodyList.ToDocument2(domBody);
}
var bo = "UFAPBO.clsCloseBill".GetComObject();
var m_conn = new Connection();
m_conn.Open(m_Login.UfDbName);
bo.Init(m_Login, m_conn, null,cSubId);
bo.First = bFirst;
var errorMessage = "";
var checkFlag = bo.VouchCheck(domHead, domBody, ref errorMessage, isAdd);
if (!checkFlag)
throw new Exception(errorMessage);
errorMessage = "";
var saveFlag = bo.SaveVouch(domHead, domBody, ref errorMessage, isAdd);
if (!saveFlag)
throw new Exception(errorMessage);
return new BaseResult { bSuccess = true, message = "保存成功", result = "保存成功" };
}
catch (Exception ex)
{
logInfo.Error(ex.Message, ex);
return new BaseResult { bSuccess = false, message = "保存失败", result = ex.Message };
}
}
///
/// 收付款单审核
///
/// 登录对象
/// 单号
/// 单据类型
/// 单据Id
/// 子系统Id
/// 是否期初
///
public BaseResult CloseBillSign(BaseLogin baseLogin,string cLink,string cVouchType,string cVouchID, string cSubId, bool bFirst = false)
{
try
{
IXMLDOMDocument2 oDom = new DOMDocument();
oDom.loadXML("");
var oElm = oDom.documentElement;
oElm.setAttribute("type", 0);
oElm.setAttribute("cLink", cLink);
oElm.setAttribute("cVouchType", cVouchType);
oElm.setAttribute("cVouchID", cVouchID);
oElm.setAttribute("bFirst", bFirst);
var bo = "UFAPBO.clsCloseBill".GetComObject();
var m_Login = baseLogin._vbLogin;
var m_conn = new Connection();
m_conn.Open(m_Login.UfDbName);
bo.Init(m_Login, m_conn, null, cSubId);
var errorMessage = "";
var signFlag = bo.Sign(oElm.xml, ref errorMessage);
if (!signFlag)
throw new Exception(errorMessage);
return new BaseResult { bSuccess = true, message = "审核成功", result = "审核成功" };
}
catch (Exception ex)
{
logInfo.Error(ex.Message, ex);
return new BaseResult { bSuccess = false, message = "审核失败", result = ex.Message };
}
}
///
/// 票据录入
///
/// 登录对象
/// 单据数据
/// 是否新增
///
///
public BaseResult ApNote_SaveVouch(BaseLogin baseLogin, Dictionary dictionary, string cSubId, bool isAdd = true, bool bFirst = false)
{
try
{
var m_Login = baseLogin._vbLogin;
var domHead = dictionary.ToDocument2();
var ap = "UFAPBO.clsAccount_AP".GetComObject();
var bo = "UFAPBO.clsApNote".GetComObject();
bool initResult = ap.Init(m_Login, cSubId);
if (!initResult)
{
logInfo.Debug($"1-----初始化参数失败,正在重新初始化");
initResult = ap.Init(m_Login);
if (!initResult)
{
logInfo.Debug($"2-----初始化参数失败");
}
}
var m_conn = new Connection();
m_conn.Open(m_Login.UfDbName);
var boResult = false;
if (initResult)
{
bool b = ap.InitSubOption2(cSubId);
if (!b)
{
logInfo.Debug($"初始化参数2失败");
}
logInfo.Debug($"调用初始化方法1");
boResult = bo.Init(m_Login, m_conn, ap);
}
else
{
logInfo.Debug($"调用初始化方法2");
boResult = bo.Init(m_Login, m_conn);
}
var errorMessage = "";
bool saveFlag = bo.SaveVouch(domHead, ref errorMessage);
if (!saveFlag)
{
throw new Exception(errorMessage);
}
return new BaseResult { bSuccess = true, message = "保存成功", result = "保存成功" };
}
catch (Exception ex)
{
logInfo.Error(ex.Message, ex);
return new BaseResult { bSuccess = false, message = "保存失败", result = ex.Message };
}
}
public BaseResult ApNote_Sign(BaseLogin baseLogin, string cLink, string cSubId, bool isAdd = true, bool bFirst = false)
{
try
{
var m_Login = baseLogin._vbLogin;
var ap = "UFAPBO.clsAccount_AP".GetComObject();
var bo = "UFAPBO.clsApNote".GetComObject();
bool initResult = ap.Init(m_Login, cSubId);
if (!initResult)
{
logInfo.Debug($"1-----初始化参数失败,正在重新初始化");
initResult = ap.Init(m_Login);
if (!initResult)
{
logInfo.Debug($"2-----初始化参数失败");
}
}
var m_conn = new Connection();
m_conn.Open(m_Login.UfDbName);
if (initResult)
{
bool b = ap.InitSubOption2(cSubId);
if (!b)
{
logInfo.Debug($"初始化参数2失败");
}
logInfo.Debug($"调用初始化方法1");
bo.Init(m_Login, m_conn, ap);
}
else
{
logInfo.Debug($"调用初始化方法2");
bo.Init(m_Login, m_conn);
}
var xmlCondition = $"";
var errorMessage = "";
bool saveFlag = bo.Sign(xmlCondition, ref errorMessage);
if (!saveFlag)
{
throw new Exception(errorMessage);
}
//if (saveFlag)
//{
// saveFlag = bo.Sign($"", ref errorMessage);
//}
//logInfo.Debug($"bo.SaveVouch:{errorMessage}");
//if (!saveFlag)
// throw new Exception(errorMessage);
return new BaseResult { bSuccess = true, message = "保存成功", result = "保存成功" };
}
catch (Exception ex)
{
logInfo.Error(ex.Message, ex);
return new BaseResult { bSuccess = false, message = "保存失败", result = ex.Message };
}
}
}
}