using log4net; using MSXML2; using System; using System.Collections.Generic; using System.Threading.Tasks; using UFIDA.U8.Framework.Api.ControlObject.Common; using UFIDA.U8.Framework.Api.ControlObject.Entity; using UFIDA.U8.Framework.Api.ControlObject.Json; using UFIDA.U8.Framework.Api.ControlObject.U8M; namespace UFIDA.U8.Framework.Api.ControlObject.ST { /// /// 库存管理 /// public class USERPCO { protected readonly ILog logInfo = LogManager.GetLogger("logInfo"); public async Task> Insert(BaseLogin baseLogin, Dictionary dictionary,string sVouchType,bool bGetCode=false,bool bCheck=true,bool bBeforCheckStock=true,bool bIsRedVouch=false,string sAddedState="", bool bReMote=false) { try { var co = "USERPCO.USERPCO".GetComObject(); var errorMsg = ""; if (!co.IniLogin(baseLogin._vbLogin, ref errorMsg)) { await Task.Delay(1); throw new Exception(errorMsg); } var domHead = dictionary.ToDocument2(); if (!dictionary.TryGetValue("body", out var bodys)) { await Task.Delay(1); throw new Exception("无法获取表体数据"); } if (!(bodys is List> dictionarys) || dictionarys.Count <= 0) { await Task.Delay(1); throw new Exception("无法获取表体数据"); } var domBody = dictionarys.ToDocument2(); IXMLDOMDocument2 domPosition = new DOMDocument(); IXMLDOMDocument2 domMsg = new DOMDocument(); errorMsg = ""; baseLogin.Connection.BeginTrans(); var vouchId = ""; var res = new BaseResult(); try { res.bSuccess = co.Update(sVouchType, domHead, domBody, domPosition, ref errorMsg, baseLogin.Connection, ref vouchId, ref domMsg, bCheck, bBeforCheckStock, bIsRedVouch, sAddedState, bReMote); } catch (Exception ex) { await Task.Delay(1); baseLogin.Connection.RollbackTrans(); throw ex; } if (!res.bSuccess) { res.message = "新增失败"; res.result = errorMsg; } else { res.message = "新增成功"; res.result = vouchId; } return res; //var bodys = dictionary.TryGetValue() dictionary["body"]; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "新增失败", result = ex.Message }; } } public async Task> Update(BaseLogin baseLogin, Dictionary dictionary, string sCardNum , string sVouchType, bool bCheck = true, bool bBeforCheckStock = true, bool bIsRedVouch = false, string sAddedState = "", bool bUpdateNeedEas = true) { try { var co = "USERPCO.VoucherCO".GetComObject(); var errorMsg = ""; if (!co.IniLogin(baseLogin._vbLogin, ref errorMsg)) { await Task.Delay(1); throw new Exception(errorMsg); } IXMLDOMDocument2 domHead = new DOMDocument(); IXMLDOMDocument2 domBody = new DOMDocument(); IXMLDOMDocument2 domPosition = new DOMDocument(); errorMsg = ""; if (!co.GetDefaultVoucherDom(sVouchType, sCardNum, ref domHead, ref domBody, ref domPosition, ref errorMsg)) { throw new Exception(errorMsg); } domHead = dictionary.ToDocument2(domHead); var bodys = dictionary["body"] as List> ?? $"{dictionary["body"]}".ToObject>>(); if (bodys==null || bodys.Count<=0) { await Task.Delay(1); throw new Exception("无法获取表体数据"); } //if (!(bodys is List> dictionarys) || dictionarys.Count <= 0) //{ // await Task.Delay(1); // throw new Exception("无法获取表体数据"); //} domBody = bodys.ToDocument2(domBody); IXMLDOMDocument2 domMsg = new DOMDocument(); errorMsg = ""; baseLogin.Connection.BeginTrans(); var vouchId = ""; var res = new BaseResult(); try { res.bSuccess = co.Update(sVouchType, domHead, domBody, domPosition); } catch (Exception ex) { baseLogin.Connection.RollbackTrans(); throw ex; } if (!res.bSuccess) { baseLogin.Connection.RollbackTrans(); res.message = "新增失败"; res.result = errorMsg; } else { baseLogin.Connection.CommitTrans(); res.message = "新增成功"; res.result = vouchId; } return res; //var bodys = dictionary.TryGetValue() dictionary["body"]; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "新增失败", result = ex.Message }; } } } }