Files
U8-Import/NX.ERP.U8/U8LoginContext.cs

379 lines
8.6 KiB
C#
Raw Normal View History

2021-01-06 12:43:05 +08:00
using MSXML2;
using System;
2021-01-05 11:11:28 +08:00
using System.Collections.Generic;
using System.Text;
using U8Login;
2021-01-06 12:43:05 +08:00
using UFIDA.U8.U8APIFramework;
using UFIDA.U8.U8MOMAPIFramework;
2021-01-07 17:01:56 +08:00
using Dapper;
2021-01-05 11:11:28 +08:00
namespace NX.ERP.U8
{
public class U8LoginContext : IDisposable
{
#region 单例
2021-01-28 10:10:32 +08:00
private static readonly object locker = new object();
2021-01-05 11:11:28 +08:00
private static U8LoginContext _u8LoginContext;
/// <summary>
/// 默认实例
/// </summary>
2021-01-05 11:11:28 +08:00
public static U8LoginContext Instance
{
get
{
if (_u8LoginContext == null)
{
2021-01-28 10:10:32 +08:00
lock (locker)
{
if (_u8LoginContext == null)
{
_u8LoginContext = new U8LoginContext();
2021-01-28 10:10:32 +08:00
}
}
2021-01-05 11:11:28 +08:00
}
return _u8LoginContext;
}
}
private UFSoft.U8.Framework.Login.UI.clsLogin uiLogin;
private clsLogin _clslogin;
#endregion
private string EaiPort = System.Configuration.ConfigurationManager.AppSettings["EaiPort"];
private string EaiPath = System.Configuration.ConfigurationManager.AppSettings["EaiPath"];
2021-01-05 16:49:51 +08:00
public string cAcc_id
2021-01-05 11:11:28 +08:00
{
2021-01-05 16:49:51 +08:00
get
{
return this._clslogin.get_cAcc_Id();
}
2021-01-05 11:11:28 +08:00
}
/// <summary>
///
/// </summary>
2021-01-05 16:49:51 +08:00
public U8LoginContext()
{
}
/// <summary>
///
/// </summary>
/// <param name="Server"></param>
/// <param name="Accid"></param>
public U8LoginContext(string Server, string Accid)
{
this._server = Server;
this._accid = Accid;
}
public U8LoginContext(string userid, string password, string server, string accid) : this(server, accid)
{
this._password = password;
this._userId = userid;
}
2021-01-28 10:10:32 +08:00
private static readonly object locker1 = new object();
2021-01-05 11:11:28 +08:00
public clsLogin ClsLogin
{
get
{
if (this._clslogin == null)
{
2021-01-28 10:10:32 +08:00
lock (locker1)
{
if (this._clslogin == null)
{
this.Login();
}
}
2021-01-05 11:11:28 +08:00
}
return this._clslogin;
2021-01-28 10:10:32 +08:00
2021-01-05 11:11:28 +08:00
}
}
2021-01-07 17:01:56 +08:00
2021-01-25 09:47:41 +08:00
public System.Data.IDbConnection Connection
{
get
{
return new System.Data.SqlClient.SqlConnection(this.Constr4Net);
}
}
2021-01-28 10:10:32 +08:00
2021-01-25 09:47:41 +08:00
2021-01-07 17:01:56 +08:00
//public int GetDefaultPoTaxRate()
//{
// try
// {
// string strSQL = "Select cValue from AccInformation Where cSysID=N'PU' and cName=N'iDefaultZHBVRate'";
2021-01-25 09:47:41 +08:00
// using (var conn = U8LoginContext.Instance.Connection)
2021-01-07 17:01:56 +08:00
// {
// return conn.ExecuteScalar<int>(strSQL, null, null, 0, System.Data.CommandType.Text);
// }
// }
// catch (Exception)
// {
// throw;
// }
// finally
// {
// }
//}
2021-01-05 11:11:28 +08:00
public void Dispose()
{
if (uiLogin != null)
{
2021-01-16 15:38:29 +08:00
uiLogin.SubLogout(this._accid);
2021-01-05 11:11:28 +08:00
uiLogin.ShutDown();
uiLogin = null;
}
}
2021-01-16 15:38:29 +08:00
private string _userId = "";
2021-01-05 11:11:28 +08:00
2021-01-16 15:38:29 +08:00
public string UserId
{
set
{
this._userId = value;
}
}
private string _password = "";
public string PassWord
{
set
{
this._password = value;
}
}
private string _server;
public string Server
{
set
{
this._server = value;
}
}
private string _accid;
public string AccID
{
set
{
this._accid = value;
}
2021-01-23 11:00:17 +08:00
get
{
2021-01-19 11:10:39 +08:00
return this.ClsLogin.get_cAcc_Id();
}
}
public string AccName
{
get
{
return this.ClsLogin.cAccName;
}
2021-01-16 15:38:29 +08:00
}
2021-01-23 11:00:17 +08:00
2021-01-19 11:10:39 +08:00
2021-01-05 11:11:28 +08:00
public string Serial { get; set; }
2021-01-18 09:24:45 +08:00
public string EAIUrl
{
get
{
2021-01-23 14:41:33 +08:00
2021-01-28 10:10:32 +08:00
2021-01-23 14:41:33 +08:00
return $"http://{this.ClsLogin.cServer}:{EaiPort}/{EaiPath}";
2021-01-18 09:24:45 +08:00
}
}
2021-01-25 09:47:41 +08:00
private string _conStr4net;
2021-01-18 09:24:45 +08:00
2021-01-05 16:49:51 +08:00
/// <summary>
/// ADO.NET 链接字符串
/// </summary>
2021-01-05 11:11:28 +08:00
public string Constr4Net
{
get
{
2021-01-25 09:47:41 +08:00
if (string.IsNullOrEmpty(this._conStr4net))
{
this._conStr4net = this.ClsLogin.UFDataConnstringForNet;
}
return this._conStr4net;
}
set
{
this._conStr4net = value;
2021-01-05 11:11:28 +08:00
}
}
2021-01-07 17:01:56 +08:00
public string LoginUserName
{
get
{
return this.ClsLogin.cUserName;
}
}
public string LoginUserId
{
get
{
return this.ClsLogin.cUserId;
}
}
2021-01-05 16:49:51 +08:00
/// <summary>
/// ADO的链接字符串
/// </summary>
2021-01-05 11:11:28 +08:00
public string Constr
{
get
{
return this.ClsLogin.UfDbName;
}
}
private UFSoft.U8.Framework.Login.UI.clsLogin UiLogin
{
get
{
2021-01-28 10:10:32 +08:00
2021-01-05 11:11:28 +08:00
if (uiLogin == null)
{
uiLogin = new UFSoft.U8.Framework.Login.UI.clsLogin();
}
return uiLogin;
}
}
2021-01-23 14:41:33 +08:00
/// <summary>
/// 判断是否使用UI登录
/// </summary>
2021-01-16 15:38:29 +08:00
public bool NeedUiLogin
{
get
{
return string.IsNullOrEmpty(this._userId) ||
string.IsNullOrEmpty(this._password) ||
string.IsNullOrEmpty(this._server) ||
string.IsNullOrEmpty(this._accid);
}
}
public void Login(string userId, string password)
2021-01-05 11:11:28 +08:00
{
2021-01-28 10:10:32 +08:00
if (!UiLogin.login("DP", userId, password, this._server, DateTime.Today.ToString("yyyy-MM-dd"), this._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"));
}
2021-01-28 10:10:32 +08:00
/// <summary>
/// 登录ID 唯一凭据
/// </summary>
public string loginId
{
get
{
return this.UserToken == null ? "" : this.UserToken.UserTokenData.SignedToken.Id;
}
}
2021-01-28 10:10:32 +08:00
public ufsoft UserToken
{
get
{
if (this._clslogin == null)
{
return null;
}
if (this._clslogin.userToken=="")
{
return null;
}
return XmlHelper.XmlDeserialize<ufsoft>(this._clslogin.userToken, Encoding.UTF8);
}
}
public void Login()
{
2021-01-16 15:38:29 +08:00
if (NeedUiLogin)
2021-01-05 11:11:28 +08:00
{
2021-01-05 16:49:51 +08:00
if (!UiLogin.login("DP"))
{
throw new Exception(UiLogin.ErrDescript);
}
2021-01-05 11:11:28 +08:00
}
2021-01-05 16:49:51 +08:00
else
{
2021-01-16 15:38:29 +08:00
if (!UiLogin.login("DP", this._userId, this._password, this._server, DateTime.Today.ToString("yyyy-MM-dd"), this._accid, Serial))
2021-01-05 16:49:51 +08:00
{
throw new Exception(UiLogin.ErrDescript);
}
}
2021-01-05 11:11:28 +08:00
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"));
}
2021-01-06 12:43:05 +08:00
2021-01-07 14:06:26 +08:00
2021-01-16 15:38:29 +08:00
2021-01-07 14:06:26 +08:00
2021-01-07 17:01:56 +08:00
2021-01-07 14:06:26 +08:00
2021-01-05 11:11:28 +08:00
}
}