Esempio n. 1
0
        private void SaveLoginInfo(LoginInfo lgi)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@UserID", lgi.User == null ? "-1" : lgi.User.UserName),
                new SqlParameter("@ServerIP", lgi.ServerIP),
                new SqlParameter("@ServerName", lgi.ServerName),
                new SqlParameter("@ClientIP", lgi.ClientIP),
                new SqlParameter("@ClientName", lgi.ClientName),
                new SqlParameter("@LoginPort", lgi.LoginPort),
                new SqlParameter("@LogMessage", lgi.Message),
                new SqlParameter("@Status", lgi.Status.GetHashCode())
            };

            int iLogID = (int)DataProvider.ExecuteScalar <decimal>("usp_Login", parameters);

            if (iLogID > 0)
            {
                lgi.SessionID = iLogID;
                lgi.ID        = iLogID;
            }
            else
            {
                throw new ApplicationException("数据库操作失败。");
            }
        }
Esempio n. 2
0
        public CommandResult GetUserByName(string name)
        {
            CommandResult res = new CommandResult();

            try
            {
                string str = string.Format("select count(*) from EAP_User where UserName='******'", name);
                res.IntResult = DataProvider.ExecuteScalar <int>(str);
            }catch (Exception e)
            {
                res.IntResult = 0;
                res.Message   = e.Message;
            }
            return(res);
        }
Esempio n. 3
0
        public CommandResult ChangePassword(int userID, string oldPassword, string newPass)
        {
            //var t = DESEncrypt.Encrypt("test");
            //var t1 = DESEncrypt.Decrypt(t);

            CommandResult result = new CommandResult();
            //SqlParameter outputPar = new SqlParameter("@Output", "") { Direction = System.Data.ParameterDirection.InputOutput,Size=32 };
            //SqlParameter resultPar = new SqlParameter("@Result", 1) { Direction = System.Data.ParameterDirection.InputOutput };

            //SqlParameter[] parameters = new SqlParameter[] {
            //        new SqlParameter("@UserID",userID),
            //        new SqlParameter("@OldPass",DESEncrypt.Encrypt(oldPassword)),
            //        new SqlParameter("@NewPass",DESEncrypt.Encrypt(newPass)),
            //        resultPar,outputPar
            //};

            //DataProvider.ExecuteNonQuery("usp_ChangePassword", parameters);
            //result.Result = (int)resultPar.Value == 1;
            //result.Message = outputPar.Value.ToString();
            //return result;

            var sql  = string.Format("select [PASSWORD] from EAP_User where ID={0} ", userID);
            var pass = DataProvider.ExecuteScalar <string>(sql);

            if (DESEncrypt.Decrypt(pass) == oldPassword)
            {
                result.Result = true;
                sql           = string.Format("update EAP_User set [PASSWORD]='{1}' where ID={0}", userID, DESEncrypt.Encrypt(newPass));
                DataProvider.ExecuteNonQuery(sql);
                result.Message = "密码修改成功";
            }
            else
            {
                result.Result  = false;
                result.Message = "原密码不正确";
            }
            return(result);
        }
Esempio n. 4
0
        public CommandResult AddRole(EAP_Role role)
        {
            CommandResult result = new CommandResult();

            result.Result = false;

            string sFields = "";
            string sValues = "";

            if (role.Items.Count <= 0)
            {
                return(result);
            }

            /*
             * role.Items.ForEach(e =>
             * {
             *  if (!string.IsNullOrEmpty(e.K) && e.S == EntityStatus.New)
             *  {
             *      sFields += string.Format("[{0}],", e.K);
             *      sValues += string.Format("'{0}',", e.V);
             *  }
             * });
             * */
            string sql = string.Format("select count(*) from EAP_Role where RoleName='{0}'", role.RoleName);

            /*
             * string sSql = string.Format(
             *  "INSERT INTO EAP_Role({0}) VALUES({1});SELECT CAST(scope_identity() AS int);",
             *  sFields.Trim().TrimEnd(','),
             *  sValues.Trim().TrimEnd(','));
             * int count = DataProvider.ExecuteScalar<int>(sql);
             */
            int count = (int)DataProvider.ExecuteScalar <decimal>(sql);

            if (count <= 0)
            {
                // int iPID = DataProvider.ExecuteScalar<int>(sSql);
                int iPID = DataProvider.DoInsert(role, "EAP_Role", true, null);
                if (iPID > 0)
                {
                    result.Result = true;
                    result.ReturnValue.Add(new LookupDataItem()
                    {
                        K = "ID", V = iPID.ToString()
                    });
                    result.Message = "新增成功。";
                }
                else
                {
                    result.Result  = false;
                    result.Message = "新增失败。";
                }
            }
            else
            {
                result.Result    = false;
                result.IntResult = 1;
                result.Message   = "该角色已经存在。";
            }
            return(result);
        }