/// <summary> /// 构造函数 /// </summary> public WorkFlowApiController() { //获取AppInfo值 头部信息记录 #region 设置当前线程数据库 var base64EncodedBytes = Convert.FromBase64String(HttpContext.Current.Request.Headers.GetValues("AppInfo").First()); var jsonText = Encoding.UTF8.GetString(base64EncodedBytes); var AppInfo = JsonConvert.DeserializeObject <ApiControllerBase.Models.AppInfoBase>(jsonText); if (AppInfo != null) { DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder(); string result, userConn; var pubConn = dbbuilder.GetMainConnStringElement(0, out result, false); string defaultConn = dbbuilder.GetDefaultConnString(); if (AppInfo.DbName.ToLower() == "ngsoft") { userConn = pubConn; } else { userConn = string.IsNullOrWhiteSpace(AppInfo.DbName) ? defaultConn : dbbuilder.GetAccConnstringElement(0, AppInfo.DbName, pubConn, out result); } //设置当前数据库连接信息 ConnectionInfoService.SetCallContextConnectString(userConn); MultiDelegatingDbProvider.CurrentDbProviderName = AppInfo.DbName; } #endregion service = new WorkFlowServiceProxy(); }
private static void TestOracle() { string result; DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder(); string pubConn = string.Empty; string userConn = string.Empty; pubConn = dbbuilder.GetMainConnStringElement(0, out result, false); //取第一个(默认)服务器 userConn = dbbuilder.GetDefaultConnString(); //取默认连接串 userConn = dbbuilder.GetAccConnstringElement("10.0.16.168:1521/orclup.rd.ngsoft.com", "NG0001", pubConn, out result); userConn = dbbuilder.GetAccConnstringElement(0, "NG0001", pubConn, out result); DataTable tb = dbbuilder.GetDBserverList(); DataTable dt = dbbuilder.GetAccountList("10.0.0.233:1521/orcl.rd.ngsoft.com"); }
public override void OnActionExecuting(HttpActionContext actionContext) { //获取AppInfo值 头部信息记录 var base64EncodedBytes = Convert.FromBase64String(HttpContext.Current.Request.Headers.GetValues("AppInfo").First()); var jsonText = Encoding.UTF8.GetString(base64EncodedBytes); var AppInfo = JsonConvert.DeserializeObject <AppInfoBase>(jsonText); if (AppInfo != null) { string curConnect = DbHelper.ConnectString; if (curConnect.IndexOf(AppInfo.DbName, StringComparison.CurrentCultureIgnoreCase) > 0) { //连接串包含了当前数据库 } else { DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder(); string result, userConn; var pubConn = dbbuilder.GetMainConnStringElement(0, out result, false); string defaultConn = dbbuilder.GetDefaultConnString(); if (AppInfo.DbName.ToLower() == "ngsoft") { userConn = pubConn; } else { userConn = string.IsNullOrWhiteSpace(AppInfo.DbName) ? defaultConn : dbbuilder.GetAccConnstringElement(0, AppInfo.DbName, pubConn, out result); } //设置当前数据库连接信息 ConnectionInfoService.SetCallContextConnectString(userConn); MultiDelegatingDbProvider.CurrentDbProviderName = AppInfo.DbName; } } base.OnActionExecuting(actionContext); }
public static DBConnectionStringBuilder GetAcountDBConnectString(string svrName, string database, out string pubConn, out string userConn) { var dbbuilder = new DBConnectionStringBuilder(); string result; if (string.IsNullOrWhiteSpace(svrName)) { pubConn = dbbuilder.GetMainConnStringElement(0, out result, false);//取第一个(默认)服务器 } else { pubConn = dbbuilder.GetMainConnStringElement(svrName, out result); } if (string.IsNullOrWhiteSpace(database)) { userConn = dbbuilder.GetDefaultConnString();//取默认连接串 } else { userConn = dbbuilder.GetAccConnstringElement(svrName, "NG" + database.Replace("NG", ""), pubConn, out result); } return(dbbuilder); }
public string getUserInfo() { //string mobileno = System.Web.HttpContext.Current.Request.Params["mobileno"]; //人员手机号码 string mobileno = CasAuthentication.CurrentPrincipal.Identity.Name; //根据手机号码获取人员信息 DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder(); string theResult; string pubConn = dbbuilder.GetMainConnStringElement(0, out theResult, false); //取第一个(默认)服务器 string userConn = dbbuilder.GetDefaultConnString(); //取默认连接串 DataTable dt = null; object userData = null; if (string.IsNullOrEmpty(mobileno)) { return(DataConverterHelper.SerializeObject(new { Status = ResponseStatus.Error, Msg = "没有获取到云平台的cas的手机号码." })); } try { string sqlType = ""; string connectString = ""; //ConnectType=ORACLEClient;Data Source=10.0.14.34:1521/DQW;User ID=NG0001;Password=NG0001;Self Tuning=false;Statement Cache Size=0;Metadata Pooling=false //ConnectType=SqlClient;Server=10.0.13.168;Database=NG0012;User ID=sa;Password=123456; if (userConn.IndexOf("ConnectType=SqlClient", StringComparison.OrdinalIgnoreCase) >= 0) { sqlType = "sqlclient"; string server = NG.NGKeyValueUtility.GetValue(userConn, "Server"); string dataBase = NG.NGKeyValueUtility.GetValue(userConn, "Database", "Initial Catalog"); string userid = NG.NGKeyValueUtility.GetValue(userConn, "User ID"); string password = NG.NGKeyValueUtility.GetValue(userConn, "Password"); connectString = string.Format("Server={0};Database={1};User ID={2};Password={3}", server, dataBase, userid, password); } if (userConn.IndexOf("ConnectType=OracleClient", StringComparison.OrdinalIgnoreCase) >= 0) { sqlType = "oracle"; string source = NG.NGKeyValueUtility.GetValue(userConn, "Data Source"); string[] arrySource = source.Split(new char[] { ':', '/' }, StringSplitOptions.RemoveEmptyEntries); string host = arrySource[0]; string port = arrySource[1]; string Server_name = arrySource[2]; string userid = NG.NGKeyValueUtility.GetValue(userConn, "User ID"); string password = NG.NGKeyValueUtility.GetValue(userConn, "Password"); connectString = string.Format("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})));Persist Security Info=True;User ID={3};Password={4};", host, port, Server_name, userid, password); } //"oracle":"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.6.139)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));Persist Security Info=True;User ID=PUBDATA;Password=pubdata;"; //"sqlclient":"Server=218.108.53.111,1433;Database=DMPBase;User ID=sa;Password=newgrand@123"; string SQLString = string.Format("select userno,pwd from fg3_user where mobileno='{0}'", mobileno); if (sqlType == "sqlclient") { using (SqlConnection connection = new SqlConnection(connectString)) { DataSet ds = new DataSet(); try { connection.Open(); SqlDataAdapter command = new SqlDataAdapter(SQLString, connection); command.Fill(ds, "ds"); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } } } else if (sqlType == "oracle") { using (OracleConnection connection = new OracleConnection(connectString)) { DataSet ds = new DataSet(); try { connection.Open(); OracleDataAdapter command = new OracleDataAdapter(SQLString, connection); command.Fill(ds, "ds"); } catch (OracleException ex) { throw ex; } finally { connection.Close(); } dt = ds.Tables[0]; } } } catch (Exception e) { //throw e; return(DataConverterHelper.SerializeObject(new { Status = ResponseStatus.Error, Msg = e.ToString() })); } if (dt != null && dt.Rows.Count > 0) { if (dt.Rows.Count > 1) { return(DataConverterHelper.SerializeObject(new { Status = ResponseStatus.Error, Msg = "当前的人员的手机号:" + mobileno + ",含有多个数据" })); } string dbpwd = ""; if (!string.IsNullOrEmpty(dt.Rows[0]["pwd"].ToString())) { dbpwd = NG3.NGEncode.DecodePassword(dt.Rows[0]["pwd"].ToString(), 128); } userData = new { logid = dt.Rows[0]["userno"].ToString(), pwd = string.IsNullOrEmpty(dt.Rows[0]["pwd"].ToString()) ? "" : dt.Rows[0]["pwd"].ToString() }; } else { return(DataConverterHelper.SerializeObject(new { Status = ResponseStatus.Error, Msg = "当前的人员的手机号:" + mobileno + ",没有对应的账号" })); } var data = new { Status = ResponseStatus.Success, Msg = "", Data = userData }; return(DataConverterHelper.SerializeObject(data)); }
/// <summary> /// 登录 /// </summary> /// <param name="svrName">数据库服务器名</param> /// <param name="account">帐套</param> /// <param name="logid">登录id</param> /// <param name="pwd">密码</param> /// <param name="msg">消息</param> /// <returns></returns> public bool Login(string svrName, string account, string logid, string pwd, ref string msg) { string result; DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder(); string pubConn = string.Empty; string userConn = string.Empty; if (string.IsNullOrWhiteSpace(svrName)) { pubConn = dbbuilder.GetMainConnStringElement(0, out result, false);//取第一个(默认)服务器 } else { pubConn = dbbuilder.GetMainConnStringElement(svrName, out result); } if (string.IsNullOrWhiteSpace(account)) { userConn = dbbuilder.GetDefaultConnString();//取默认连接串 } else { userConn = dbbuilder.GetAccConnstringElement(svrName, account, pubConn, out result); } I6WebAppInfo appInfo = new I6WebAppInfo(); appInfo.UserType = UserType.OrgUser; #region 校验用户是否存在 object obj = DbHelper.ExecuteScalar(userConn, string.Format("select count(logid) from secuser where logid='{0}'", logid)); if (obj == null || obj == DBNull.Value || obj.ToString() == "0") { //检测系统管理员 obj = DbHelper.ExecuteScalar(pubConn, string.Format("select count(cname) from ngrights where cname='{0}'", logid)); if (obj == null || obj == DBNull.Value || obj.ToString() == "0") { //this.SetErrMsg(ps, "不存在该用户!"); //return false; msg = "不存在该用户!"; return(false); } else { appInfo.UserType = SUP.Common.Base.UserType.System; } } #endregion #region 用户状态 string sql = "select status from secuser where logid='" + logid + "'"; string ret = DbHelper.GetString(userConn, sql); if (ret == "1") { msg = "用户已锁定,请联系系统管理员!"; return(false); } #endregion #region 校验密码 if (UserType.OrgUser == appInfo.UserType) { obj = DbHelper.ExecuteScalar(userConn, string.Format("select pwd from secuser where logid='{0}'", logid)); } else { obj = DbHelper.ExecuteScalar(pubConn, string.Format("select cpwd from ngrights where cname='{0}'", logid)); } if (string.IsNullOrEmpty(pwd)) { if (obj != null && obj != DBNull.Value) { if (obj.ToString().Length > 0) { msg = "密码不正确"; return(false); } } } else { if (obj == null || obj == DBNull.Value) { msg = "密码不正确"; return(false); } else { string dbpwd = NG3.NGEncode.DecodePassword(obj.ToString(), 128); if (dbpwd.Equals(pwd) == false) { msg = "密码不正确"; return(false); } } } #endregion return(true); }
public void Check(ref string msg, ref bool loginflag, string svrName, string account, string logid, string pwd) { string result; DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder(); string pubConn = string.Empty; string userConn = string.Empty; if (string.IsNullOrWhiteSpace(svrName)) { pubConn = dbbuilder.GetMainConnStringElement(0, out result, false);//取第一个(默认)服务器 } else { pubConn = dbbuilder.GetMainConnStringElement(svrName, out result); } if (string.IsNullOrWhiteSpace(account)) { userConn = dbbuilder.GetDefaultConnString();//取默认连接串 } else { userConn = dbbuilder.GetAccConnstringElement(svrName, account, pubConn, out result); } I6WebAppInfo appInfo = new I6WebAppInfo(); appInfo.UserType = UserType.OrgUser; #region 用户状态 string sql = "select status from secuser where logid='" + logid + "'"; string ret = DbHelper.GetString(userConn, sql); if (ret == "1") { msg = "用户[" + logid + "]已锁定,请联系系统管理员!"; loginflag = false; return; } int sysErrortimes = this.dac.GetSysErrTimes(userConn);//系统定义出错次数 int currentErrorTimes = this.dac.GetErrTimes(logid, userConn); if (currentErrorTimes == sysErrortimes) { this.dac.SetUserStateOff(logid, userConn);//锁定用户 msg = "用户[" + logid + "]已锁定,请联系系统管理员!"; loginflag = false; return; } #endregion string username = string.Empty; //校验用户 object obj = DbHelper.ExecuteScalar(userConn, string.Format("select count(logid) from secuser where logid='{0}'", logid)); if (obj == null || obj == DBNull.Value || obj.ToString() == "0") { //检测系统管理员 obj = DbHelper.ExecuteScalar(pubConn, string.Format("select count(cname) from ngrights where cname='{0}'", logid)); if (obj == null || obj == DBNull.Value || obj.ToString() == "0") { //this.SetErrMsg(ps, "不存在该用户!"); //return false; msg = "用户名或密码错误!";//"不存在该用户!"; loginflag = false; this.dac.AddErrTimes(logid, userConn); return; } else { appInfo.UserType = SUP.Common.Base.UserType.System; } username = logid; } else { string usernameSql = string.Format("select u_name from secuser where logid='{0}'", logid); username = DbHelper.GetString(userConn, usernameSql); } #region 校验密码 if (UserType.OrgUser == appInfo.UserType) { obj = DbHelper.ExecuteScalar(userConn, string.Format("select pwd from secuser where logid='{0}'", logid)); } else { obj = DbHelper.ExecuteScalar(pubConn, string.Format("select cpwd from ngrights where cname='{0}'", logid)); } if (string.IsNullOrEmpty(pwd)) { if (obj != null && obj != DBNull.Value) { if (obj.ToString().Length > 0) { msg = "用户名或密码错误!";//"密码不正确"; loginflag = false; this.dac.AddErrTimes(logid, userConn); return; } } } else { if (obj == null || obj == DBNull.Value) { msg = "用户名或密码错误!"; //"密码不正确"; loginflag = false; this.dac.AddErrTimes(logid, userConn); return; } else { string dbpwd = NG3.NGEncode.DecodePassword(obj.ToString(), 128); if (dbpwd.Equals(pwd) == false) { msg = "用户名或密码错误!";//"密码不正确"; loginflag = false; this.dac.AddErrTimes(logid, userConn); return; } } } #endregion //错误次数清零 this.dac.ClearErr(logid, userConn); //普通用户,获取组织 string ocode = string.Empty; if (UserType.System != appInfo.UserType) { ocode = DbHelper.ExecuteScalar(userConn, string.Format("select lastloginorg from secuser where logid='{0}'", logid)).ToString(); if (string.IsNullOrWhiteSpace(ocode)) { sql = "select ocode from fg_orglist"; DataTable dt = DbHelper.GetDataTable(userConn, sql); if (dt.Rows.Count > 0) { ocode = dt.Rows[0]["ocode"].ToString();//取第一个组织作为默认组织 } } } #region 在线用户 //string message = this.CheckUserOnline(logid, account, string.Empty); string message = this.CheckTheSameSessionUser(logid); if (!string.IsNullOrEmpty(message)) { msg = message; loginflag = false; return; } #endregion appInfo.PubConnectString = pubConn; appInfo.UserConnectString = userConn; appInfo.LoginID = logid; appInfo.UserName = username; appInfo.OCode = ocode; appInfo.UCode = account; appInfo.UserID = Convert.ToInt64(DbHelper.GetString(userConn, string.Format("select phid from fg3_user where userno='{0}'", logid))); appInfo.OrgID = Convert.ToInt64(DbHelper.GetString(userConn, string.Format("select phid from fg_orglist where ocode='{0}'", ocode))); System.Web.HttpContext.Current.Session[UPAppInfoNameInSession] = appInfo; NG3.Data.Service.ConnectionInfoService.SetSessionConnectString(appInfo.UserConnectString);//初始化2.0的dbhelper }