247 lines
8.1 KiB
C#
247 lines
8.1 KiB
C#
using ADODB;
|
|
using log4net;
|
|
using MSXML2;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.UI.WebControls;
|
|
using UFGeneralFilterOCX;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Common;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Entity;
|
|
using UFIDA.U8.Framework.Api.ControlObject.PU;
|
|
using UFIDA.U8.Framework.Api.ControlObject.U8M;
|
|
|
|
namespace UFIDA.U8.Framework.Api.ControlObject.SA
|
|
{
|
|
/// <summary>
|
|
/// 销售管理
|
|
/// </summary>
|
|
public class ClsVoucherCO_SA
|
|
{
|
|
protected readonly ILog _logInfo = LogManager.GetLogger("logInfo");
|
|
|
|
private dynamic InitCo(BaseLogin login, int enmVoucherType)
|
|
{
|
|
var errorMsg = "";
|
|
|
|
var oSystem = "USSAServer.clsSystem".GetComObject();
|
|
|
|
if (!oSystem.Init(login._vbLogin, ref errorMsg))
|
|
{
|
|
throw new Exception($"初始化失败:{errorMsg}");
|
|
}
|
|
|
|
var co = "VoucherCO_Sa.ClsVoucherCO_SA".GetComObject();
|
|
|
|
try
|
|
{
|
|
co.Init(enmVoucherType: enmVoucherType, oLogin: ref login._vbLogin, oConn: ref login.Connection, sysObj: oSystem);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"初始化失败:{ex.Message}");
|
|
}
|
|
|
|
return co;
|
|
}
|
|
|
|
public async Task<BaseResult<string>> Save(BaseLogin baseLogin, Dictionary<string, object> dictionary, string cardNumber, VoucherTypeSA enmVoucherType, int VoucherState = 0, bool bGetCode = false, string codeKey = null, bool bAudit = false, bool iswfcontrolled = false, string cFlowFieldName = "IsWfControlled")
|
|
{
|
|
try
|
|
{
|
|
var errorMsg = "";
|
|
_logInfo.Debug("开始输出登录信息");
|
|
_logInfo.Debug(baseLogin._vbLogin.userToken);
|
|
|
|
var co = InitCo(baseLogin, (int)enmVoucherType);
|
|
|
|
IXMLDOMDocument2 domHead = new DOMDocument();
|
|
IXMLDOMDocument2 domBody = new DOMDocument();
|
|
IXMLDOMDocument2 domCur = new DOMDocument();
|
|
|
|
_logInfo.Debug("开始获取单据默认模板...");
|
|
co.GetVoucherData(ref domHead, ref domBody, null, true, "1=2");
|
|
|
|
_logInfo.Debug("填充表头DOM...");
|
|
|
|
domHead = dictionary.ToDocument2(domHead);
|
|
|
|
if (!dictionary.TryGetValue("body", out var bodys))
|
|
{
|
|
await Task.Delay(1);
|
|
throw new Exception("无法获取表体数据");
|
|
}
|
|
|
|
if (!(bodys is List<Dictionary<string, object>> dictionarys) || dictionarys.Count <= 0)
|
|
{
|
|
await Task.Delay(1);
|
|
throw new Exception("无法获取表体数据");
|
|
}
|
|
|
|
if (bGetCode)
|
|
{
|
|
errorMsg = "";
|
|
var newCode = "";
|
|
|
|
if (!co.GetVoucherNO(ref domHead, ref newCode, ref errorMsg))
|
|
{
|
|
throw new Exception(errorMsg);
|
|
}
|
|
|
|
_logInfo.Debug($"获取新单号:{newCode}");
|
|
|
|
if (!string.IsNullOrWhiteSpace(newCode))
|
|
{
|
|
domHead.SetDomKeyValue(codeKey, newCode);
|
|
}
|
|
}
|
|
|
|
_logInfo.Debug("填充表体DOM...");
|
|
domBody = dictionarys.ToDocument2(domBody);
|
|
|
|
object vouchId = "";
|
|
IXMLDOMDocument2 domMsg = new DOMDocument();
|
|
IXMLDOMDocument2 curDom = new DOMDocument();
|
|
|
|
_logInfo.Debug($"{baseLogin.Connection.State},{baseLogin.Connection.ConnectionString}");
|
|
|
|
_logInfo.Debug("开始查询单据配置...");
|
|
var vouchers = CommonHelper.GetVouchers(baseLogin.Connection, cardNumber);
|
|
|
|
var res = new BaseResult<string>();
|
|
|
|
|
|
_logInfo.Debug("开始保存...");
|
|
|
|
errorMsg = co.Save(ref domHead, ref domBody, VoucherState, ref vouchId, ref domCur);
|
|
|
|
_logInfo.Debug("保存结束...");
|
|
_logInfo.Debug(errorMsg);
|
|
_logInfo.Debug($"{vouchId}");
|
|
|
|
res.bSuccess = string.IsNullOrWhiteSpace(errorMsg) && !string.IsNullOrWhiteSpace($"{vouchId}");
|
|
|
|
if (!res.bSuccess)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(errorMsg))
|
|
{
|
|
throw new Exception(errorMsg);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(domMsg.xml))
|
|
{
|
|
throw new Exception(domMsg.xml);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(curDom.xml))
|
|
{
|
|
throw new Exception(curDom.xml);
|
|
}
|
|
|
|
throw new Exception("未知错误");
|
|
|
|
}
|
|
|
|
if (iswfcontrolled == false && VoucherState == 2)
|
|
{
|
|
var strSql = $"UPDATE {vouchers.cBTTblName} SET {cFlowFieldName} = 0 WHERE {vouchers.voucherIdFieldName}={vouchId}";
|
|
|
|
object rsts = new Recordset();
|
|
|
|
baseLogin.Connection.Execute(strSql, out rsts);
|
|
}
|
|
|
|
|
|
res.voucherCode = CommonHelper.GetVoucherCode(baseLogin.Connection, vouchId, vouchers);
|
|
res.voucherId = $"{vouchId}";
|
|
res.result = errorMsg;
|
|
|
|
|
|
|
|
if (!res.bSuccess)
|
|
{
|
|
res.message = "保存失败";
|
|
|
|
return res;
|
|
}
|
|
|
|
res.message = "保存成功";
|
|
|
|
_logInfo.Debug($"{baseLogin.Connection.State},{baseLogin.Connection.ConnectionString}");
|
|
|
|
var strWhere = CommonHelper.GetVoucherWhereSqlById(vouchers, vouchId);
|
|
|
|
if (res.bSuccess && bAudit)
|
|
{
|
|
try
|
|
{
|
|
errorMsg = VerifyVouch(co, baseLogin.Connection, enmVoucherType, res.voucherCode, res.voucherId, strWhere, true);
|
|
|
|
if (!string.IsNullOrWhiteSpace(errorMsg))
|
|
{
|
|
|
|
throw new Exception(errorMsg);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
res.bSuccess = false;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
_logInfo.Debug("提交事务...");
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "保存失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
public async Task<BaseResult<string>> VerifyVouch(dynamic voucherCO, Connection conn, VoucherTypeSA sVouchType, string cCode, object vouchId, string strWhere, bool bVerify)
|
|
{
|
|
IXMLDOMDocument2 domHead = new DOMDocument();
|
|
IXMLDOMDocument2 domBody = new DOMDocument();
|
|
IXMLDOMDocument2 domMsg = new DOMDocument();
|
|
|
|
_logInfo.Debug("开始获取单据数据...");
|
|
voucherCO.GetVoucherData(ref domHead, ref domBody, vouchId, true, strWhere);
|
|
|
|
var res = new BaseResult<string>
|
|
{
|
|
voucherCode = cCode,
|
|
voucherId = $"{vouchId}"
|
|
};
|
|
|
|
var errorMsg = voucherCO.VerifyVouch(ref domHead, bVerify);
|
|
|
|
res.bSuccess = string.IsNullOrWhiteSpace(errorMsg);
|
|
|
|
if (res.bSuccess)
|
|
{
|
|
res.message = "审核成功";
|
|
res.result = res.voucherId;
|
|
|
|
}
|
|
else
|
|
{
|
|
res.message = "审核失败";
|
|
res.result = string.IsNullOrWhiteSpace(errorMsg) ? domMsg.xml : errorMsg;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
}
|
|
}
|