using MSXML2; using System; using System.Collections.Generic; using System.Text; using U8Login; using UFIDA.U8.U8APIFramework; using UFIDA.U8.U8MOMAPIFramework; using Dapper; namespace NX.ERP.U8 { public class U8LoginContext : IDisposable { private static U8LoginContext _u8LoginContext; public static U8LoginContext Instance { get { if (_u8LoginContext == null) { _u8LoginContext = new U8LoginContext(); } return _u8LoginContext; } } private UFSoft.U8.Framework.Login.UI.clsLogin uiLogin; private clsLogin _clslogin; public string cAcc_id { get { return this._clslogin.get_cAcc_Id(); } } public U8LoginContext() { } public clsLogin ClsLogin { get { if (this._clslogin == null) { this.Login(); } return this._clslogin; } } //public int GetDefaultPoTaxRate() //{ // try // { // string strSQL = "Select cValue from AccInformation Where cSysID=N'PU' and cName=N'iDefaultZHBVRate'"; // using (var conn = new System.Data.SqlClient.SqlConnection(U8LoginContext.Instance.Constr4Net)) // { // return conn.ExecuteScalar(strSQL, null, null, 0, System.Data.CommandType.Text); // } // } // catch (Exception) // { // throw; // } // finally // { // } //} public void Dispose() { if (uiLogin != null) { uiLogin.SubLogout(AccID); uiLogin.ShutDown(); uiLogin = null; } } public string UserId { get; set; } = "003"; public string PassWord { get; set; } = "123456"; public string Server { get; set; } = "192.168.0.250"; public string AccID { get; set; } = "(default)@001"; public string Serial { get; set; } /// /// ADO.NET 链接字符串 /// public string Constr4Net { get { return this.ClsLogin.UFDataConnstringForNet; } } public string LoginUserName { get { return this.ClsLogin.cUserName; } } public string LoginUserId { get { return this.ClsLogin.cUserId; } } /// /// ADO的链接字符串 /// public string Constr { get { return this.ClsLogin.UfDbName; } } private UFSoft.U8.Framework.Login.UI.clsLogin UiLogin { get { if (uiLogin == null) { uiLogin = new UFSoft.U8.Framework.Login.UI.clsLogin(); } return uiLogin; } } public void Login(bool showlogin = false) { if (showlogin) { if (!UiLogin.login("DP")) { throw new Exception(UiLogin.ErrDescript); } } else { if (!UiLogin.login("DP", "wx999", "!@#qwe123", "192.168.0.168", DateTime.Today.ToString("yyyy-MM-dd"), AccID, Serial)) { throw new Exception(UiLogin.ErrDescript); } } if (UiLogin.SubLogin("ST") == null) { throw new Exception(UiLogin.ErrDescript); } this._clslogin = new clsLoginClass(); if (!_clslogin.ConstructLogin(UiLogin.userToken)) { throw new Exception(_clslogin.ShareString); } _clslogin.set_TaskId(UiLogin.GetTaskID("ST")); } public void AddRdVoucher(string URL, VoucherParameter para) { try { U8EnvContext u8EnvContext = new U8EnvContext(); u8EnvContext.U8Login = this.ClsLogin; U8ApiAddress apiAddress = new U8ApiAddress(URL); U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext); u8ApiBroker.AssignNormalValue("sVouchType", para.VoucherType); u8ApiBroker.AssignNormalValue("DomHead", para.DomHead); u8ApiBroker.AssignNormalValue("domBody", para.DomBody); if (para.DomPosition != null && para.DomPosition.selectNodes("//z:row").length != 0) { u8ApiBroker.AssignNormalValue("domPosition", para.DomPosition); } u8ApiBroker.AssignNormalValue("cnnFrom", null); if (para.DOMMsg != null) { u8ApiBroker.AssignNormalValue("domMsg", para.DOMMsg); } else { u8ApiBroker.AssignNormalValue("domMsg", new DOMDocumentClass()); } u8ApiBroker.AssignNormalValue("bCheck", para.IsCheck); u8ApiBroker.AssignNormalValue("bBeforCheckStock", para.IsBeforCheckStock); u8ApiBroker.AssignNormalValue("bIsRedVouch", para.IsRedVouch); u8ApiBroker.AssignNormalValue("sAddedState", para.AddedState); u8ApiBroker.AssignNormalValue("bReMote", para.IsReMote); if (!u8ApiBroker.Invoke()) { Exception exception = u8ApiBroker.GetException(); if (exception != null) { if (exception is MomSysException) { MomSysException ex = exception as MomSysException; } else if (exception is MomBizException) { MomBizException ex2 = exception as MomBizException; } string exceptionString = u8ApiBroker.GetExceptionString(); if (exceptionString.Length != 0) { } } para.ReturnValue = false; u8ApiBroker.Release(); return; } para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue()); para.DOMMsg = u8ApiBroker.GetResult("domMsg") as DOMDocument; para.ErrMsg = u8ApiBroker.GetResult("errMsg") as string; if (para.ReturnValue) { para.VoucherId = u8ApiBroker.GetResult("VouchId") as string; if (para.VoucherType.Equals("12")) { //para.VoucherCode = base.Util.GetTransVoucherCode(para.VoucherId); } else if (para.VoucherType.Equals("18")) { //para.VoucherCode = base.Util.GetCheckVoucherCode(para.VoucherId); } else if (para.VoucherType.Equals("19")) { // para.VoucherCode = base.Util.GetAdjustVoucherCode(para.VoucherId); //if (base.Util.dbHelper.U8ExcuteNoneQuery("Update AdjustPVouchs Set cVouchCode = '" + para.VoucherCode + "' Where id = " + para.VoucherId) == 0) //{ // para.ErrMsg = "更新货位调整单子表单号失败!"; // para.ReturnValue = false; //} } else { //para.VoucherCode = base.Util.GetSTVoucherCode(para.VoucherId, para.VoucherType); } } else { throw new Exception(para.ErrMsg); } u8ApiBroker.Release(); } catch (Exception ex3) { throw ex3; } } public void LoadRdVoucher(VoucherParameter para) { try { U8EnvContext u8EnvContext = new U8EnvContext(); u8EnvContext.U8Login = this.ClsLogin; U8ApiAddress apiAddress = new U8ApiAddress("U8API/PuStoreIn/Load"); U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext); u8ApiBroker.AssignNormalValue("sVouchType", para.VoucherType); u8ApiBroker.AssignNormalValue("sWhere", para.StrWhere); u8ApiBroker.AssignNormalValue("domPos", new DOMDocumentClass()); u8ApiBroker.AssignNormalValue("bGetBlank", para.IsGetBlank); u8ApiBroker.AssignNormalValue("sBodyWhere_Order", para.SBodyWhere_Order); if (!u8ApiBroker.Invoke()) { Exception exception = u8ApiBroker.GetException(); if (exception != null) { if (exception is MomSysException) { MomSysException ex = exception as MomSysException; } else if (exception is MomBizException) { MomBizException ex2 = exception as MomBizException; } string exceptionString = u8ApiBroker.GetExceptionString(); if (exceptionString.Length != 0) { } } para.ReturnValue = false; u8ApiBroker.Release(); return; } DOMDocument dOMDocument = u8ApiBroker.GetResult("DomHead") as DOMDocument; if (dOMDocument != null) { para.DomHead = new DOMDocumentClass(); para.DomHead.loadXML(dOMDocument.xml); } DOMDocument dOMDocument2 = u8ApiBroker.GetResult("domBody") as DOMDocument; if (dOMDocument2 != null) { para.DomBody = new DOMDocumentClass(); para.DomBody.loadXML(dOMDocument2.xml); } DOMDocument dOMDocument3 = u8ApiBroker.GetResult("domPos") as DOMDocument; if (dOMDocument3 != null) { para.DomPosition = new DOMDocumentClass(); para.DomPosition.loadXML(dOMDocument3.xml); } para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue()); para.ErrMsg = u8ApiBroker.GetResult("errMsg") as string; u8ApiBroker.Release(); } catch (Exception ex3) { throw new Exception("装载供应链库存单据失败!"); } } } }