/// <summary> /// 从配置文件中读取数据库信息 /// </summary> /// <returns></returns> public static OperationReturn GetDBInfo(string strFilePath, ref DatabaseInfo dbInfo) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = Defines.RET_SUCCESS; dbInfo = new DatabaseInfo(); try { string LStrXmlFileName = string.Empty; LStrXmlFileName = Path.Combine(strFilePath, @"UMP.Server\Args01.UMP.xml"); if (!File.Exists(LStrXmlFileName)) { optReturn.Code = ConstDefines.RET_Database_Null; optReturn.Result = false; return(optReturn); } XmlDocument LXmlDocArgs01 = new XmlDocument(); LXmlDocArgs01.Load(LStrXmlFileName); XmlNodeList LXmlNodeListDatabase = LXmlDocArgs01.SelectSingleNode("DatabaseParameters").ChildNodes; if (LXmlNodeListDatabase.Count <= 0) { optReturn.Code = ConstDefines.RET_Database_Null; optReturn.Result = false; optReturn.Message = "database xml node count = " + LXmlNodeListDatabase.Count; return(optReturn); } string LStrAttributesData = string.Empty; #region 数据库连接参数 foreach (XmlNode LXmlNodeSingleDatabase in LXmlNodeListDatabase) { LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P03"].Value; LStrAttributesData = EncryptOperations.DecryptWithM004(LStrAttributesData); //UMPService00.IEventLog.WriteEntry("Database Enable: " + LStrAttributesData); if (LStrAttributesData != "1") { continue; } //数据库类型 LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P02"].Value; dbInfo.TypeID = int.Parse(LStrAttributesData); //数据库服务器名或IP地址 LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P04"].Value; dbInfo.Host = EncryptOperations.DecryptWithM004(LStrAttributesData); //数据库服务端口 LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P05"].Value; dbInfo.Port = int.Parse(EncryptOperations.DecryptWithM004(LStrAttributesData)); //数据库名或Service Name LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P06"].Value; dbInfo.DBName = EncryptOperations.DecryptWithM004(LStrAttributesData); //登录用户 LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P07"].Value; dbInfo.LoginName = EncryptOperations.DecryptWithM004(LStrAttributesData); //登录密码 LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P08"].Value; dbInfo.Password = EncryptOperations.DecryptWithM004(LStrAttributesData); break; } #endregion switch (dbInfo.TypeID) { case 2: dbInfo.TypeName = "MSSQL"; break; case 3: dbInfo.TypeName = "ORCL"; break; } if (string.IsNullOrEmpty(dbInfo.DBName)) { optReturn.Code = ConstDefines.RET_Database_Null; optReturn.Result = false; return(optReturn); } optReturn.Data = dbInfo; return(optReturn); } catch (Exception ex) { optReturn.Code = ConstDefines.Get_Database_Info_Exception; optReturn.Result = false; optReturn.Message = ex.Message; return(optReturn); } }
/// <summary> /// 检查用户是否可以登录(检查用户名、密码、有效期、是否是管理员) /// </summary> /// <param name="strUserName"></param> /// <param name="strPwd"></param> /// <returns></returns> public static OperationReturn CheckUser(string strUserName, string strPwd) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = Defines.RET_SUCCESS; try { DatabaseInfo dbInfo = App.currDBInfo; string strDBConnString = dbInfo.GetConnectionString(); string strSql = string.Empty; string strUserNameEncrypted = EncryptOperations.EncryptWithM002(strUserName); switch (App.currDBInfo.TypeID) { case 2: strSql = "SELECT * FROM T_11_005_{0} where C002='{1}'"; strSql = string.Format(strSql, App.strRent, strUserNameEncrypted); optReturn = MssqlOperation.GetDataSet(strDBConnString, strSql); break; case 3: strSql = "SELECT * FROM T_11_005_{0} where C002='{1}'"; strSql = string.Format(strSql, App.strRent, strUserNameEncrypted); optReturn = OracleOperation.GetDataSet(strDBConnString, strSql); break; } if (!optReturn.Result) { return(optReturn); } DataSet ds = optReturn.Data as DataSet; if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) { optReturn.Result = false; optReturn.Code = ConstDefines.UserName_Or_Pwd_Not_Exists; return(optReturn); } string strUserID = ds.Tables[0].Rows[0]["C001"].ToString(); string strPwdInDB = ds.Tables[0].Rows[0]["C004"].ToString(); string strPwdInput = EncryptOperations.EncryptUserPwd(strUserID, strPwd); if (!strPwdInDB.Equals(strPwdInput)) { optReturn.Result = false; optReturn.Code = ConstDefines.UserName_Or_Pwd_Not_Exists; return(optReturn); } DateTime dtFrom = DateTime.Parse(EncryptOperations.DecryptWithM002(ds.Tables[0].Rows[0]["C017"].ToString())); string strTo = EncryptOperations.DecryptWithM002(ds.Tables[0].Rows[0]["C018"].ToString()); if (!strTo.Equals(ConstDefines.strUNLIMITED)) { //如果有效期不是UNLIMITED 需要判断是否过期 DateTime dtTo = DateTime.Parse(strTo); if (!(DateTime.Now > dtFrom && DateTime.Now < dtTo)) { optReturn.Result = false; optReturn.Code = ConstDefines.User_Overdue; return(optReturn); } } //检查用户是否是管理员角色 switch (dbInfo.TypeID) { case 2: strSql = "SELECT * FROM T_11_201_{0} where C004 ={1} and C003 =1060000000000000001"; strSql = string.Format(strSql, App.strRent, strUserID); optReturn = MssqlOperation.GetDataSet(strDBConnString, strSql); break; case 3: strSql = "SELECT * FROM T_11_201_{0} where C004 ={1} and C003 =1060000000000000001"; strSql = string.Format(strSql, App.strRent, strUserID); optReturn = OracleOperation.GetDataSet(strDBConnString, strSql); break; } if (!optReturn.Result) { optReturn.Code = ConstDefines.Get_User_Role_Failed; return(optReturn); } ds = optReturn.Data as DataSet; if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) { optReturn.Result = false; optReturn.Code = ConstDefines.User_Not_Admin; return(optReturn); } optReturn.Data = strUserID; return(optReturn); } catch (Exception ex) { optReturn.Result = false; optReturn.Code = ConstDefines.Check_User_Exception; optReturn.Message = ex.Message; } return(optReturn); }