using ADODB;
using log4net;
using MSXML2;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using UFIDA.U8.Framework.Api.ControlObject.Common;
using UFIDA.U8.Framework.Api.ControlObject.Entity;
using UFIDA.U8.Framework.Api.ControlObject.U8M;
namespace UFIDA.U8.Framework.Api.ControlObject.AP
{
public class clsVouchFacade
{
private readonly ILog _logInfo = LogManager.GetLogger("logInfo");
///
/// 保存单据
///
///
///
///
///
///
///
///
///
public async Task> SaveVouch(BaseLogin baseLogin, Dictionary input,string VouchClass,bool IsAdd = true,bool bVerify=false)
{
try
{
var clsVouchFacade = $"UFAPApplyPay.clsVouchFacade".GetComObject();
clsVouchFacade.init(VouchClass, baseLogin._vbLogin, baseLogin.Connection);
IXMLDOMDocument2 domHead = new DOMDocument();
IXMLDOMDocument2 domBody = new DOMDocument();
var errMsg = "";
_logInfo.Debug("填充表头DOM...");
domHead = input.ToDocument2(domHead);
if (!input.TryGetValue("body", out var bodys))
{
throw new Exception("无法获取表体数据");
}
if (!(bodys is List> dictionarys) || dictionarys.Count <= 0)
{
throw new Exception("无法获取表体数据");
}
_logInfo.Debug("填充表体DOM...");
domBody = dictionarys.ToDocument2(domBody);
var res = new BaseResult();
res.bSuccess = clsVouchFacade.SaveVouch(domHead, domBody, ref errMsg, IsAdd);
if (!res.bSuccess)
{
throw new Exception(errMsg);
}
if (bVerify)
{
clsVouchFacade.Verify();
}
res.message = "保存成功";
res.voucherCode = "";
res.voucherId = "";
return res;
}
catch (Exception ex)
{
await Task.Delay(1);
_logInfo.Error(ex.Message, ex);
return new BaseResult { bSuccess = false, message = "保存失败", result = ex.Message };
}
}
}
}