Пример #1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="strAccount">帐号</param>
        /// <param name="strPassword">密码</param>
        /// <param name="strIP">IP地址</param>
        /// <returns></returns>
        public AccountModel Login(string strAccount, string strPassword, string strIP)
        {
            AccountModel accountModel = new AccountModel();
            //if (strAccount.Equals("3shine"))
            //{
            //    accountModel.LoginState = AccountState.Succeed;
            //}
            //else
            //{
                accountModel = LoginAccount(strAccount, strPassword);      // 帐号登录
            //}

            //if (accountModel.LoginState == AccountState.Succeed)
            //{
            AccountLogModel logModel = new AccountLogModel();

            logModel.AccountName = strAccount;
            logModel.LoginTime = DateTime.Now;
            logModel.Result = GetEnumValue.GetDescription(accountModel.LoginState);
            logModel.LoginIP = strIP;
            logModel.Type = 0;
            logModel.ID = accountModel.ID.ToString();

            dal.SaveLoginLog(logModel);          // 记录日志
            //}
            return accountModel;
        }
Пример #2
0
        /// <summary>
        /// 帐号登录
        /// </summary>
        /// <param name="strAccount">帐号</param>
        /// <param name="strPassword">密码</param>
        /// <param name="strURL">登录网站</param>
        /// <param name="strIPAddress">登录IP地址</param>
        /// <returns></returns>
        public AccountModel LoginAccount(string strAccount)
        {
            AccountModel accountModel = new AccountModel();
            accountModel.LoginState = AccountState.None;

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from Power_Accounts left join Power_Groups on dbo.Power_Groups.ID=Power_Accounts.GroupID Where AcountName=@AcountName ");
            SqlParameter[] sqlParams = {
                                           new SqlParameter("@AcountName", SqlDbType.NVarChar, 20)
                                        };
            sqlParams[0].Value = strAccount;

            try
            {
                SqlDataReader sqlDataReader = DbHelperSQL.ExecuteReader(strSql.ToString(), sqlParams);
                if (sqlDataReader.Read())
                {
                    accountModel.ID = int.Parse(sqlDataReader["ID"].ToString());
                    accountModel.AccountNO = sqlDataReader["AccountNO"].ToString();
                    accountModel.AcountName = sqlDataReader["AcountName"].ToString();
                    accountModel.Password = sqlDataReader["Password"].ToString();
                    accountModel.IsOpenExpirationDate = bool.Parse(sqlDataReader["IsOpenExpirationDate"].ToString());
                    accountModel.ExpirationDate = DateTime.Parse(sqlDataReader["ExpirationDate"].ToString());
                    accountModel.IsBlocked = bool.Parse(sqlDataReader["IsBlocked"].ToString());
                    accountModel.GroupID = int.Parse(sqlDataReader["GroupID"].ToString());
                    accountModel.LoginState = AccountState.DataReady;
                }
                else
                {
                    // 帐号不存在
                    accountModel.LoginState = AccountState.Account;
                    return accountModel;
                }

                sqlDataReader.Close();
                sqlDataReader.Dispose();
            }
            catch
            {
                accountModel.LoginState = AccountState.DataError;
            }

            return accountModel;
        }
Пример #3
0
    public void OnLogin()
    {
        Session["Account"] = txtAccount.Text.Trim();

        //userEntity.Account = txtAccount.Text.Trim();
        Session["User_Account"] = txtAccount.Text.Trim();
        //userEntity.User_Account = txtAccount.Text.Trim();

        Session["User_Password"] = txtPassword.Text.Trim();
        //userEntity.User_Password = txtPassword.Text.Trim();

        //将Ip地址转换成十进制调用WebServers访问数据库
        if (txtAccount.Text.Trim().Length == 0)
        {

            txtPassword.Text = "";
            txtAccount.Focus();
        }
        else
        {

            //用户登录,并写入登录日志
            accountModel = accountbll.Login(txtAccount.Text.Trim(), DESEncrypt.EncryptMD5(txtPassword.Text.Trim()), Page.Request.UserHostAddress.ToString());
            switch (accountModel.LoginState)
            {
                case  ShineKJ.Model.Power.Account.AccountState.Succeed:
                    Session.Add("GroupID", accountModel.GroupID.ToString());
                    //userEntity.GroupID = accountMould.GroupID.ToString();
                    Session.Add("AccountID", accountModel.ID.ToString());
                    //userEntity.AccountID = accountMould.ID.ToString();

                    usermodel = accountbll.Get_UserModel(accountModel.ID);

                    Session.Add("UserName", usermodel.AcountName);
                    Session.Add("User_Account", usermodel.AcountName);
                    Session.Add("Account", usermodel.AcountName);
                    Session.Add("UserPwd", usermodel.Password);
                    Session.Add("DEPT_ID", usermodel.DEPT_ID);
                    DataSet DS = dalDept.Querys(" and DEPT_ID=" + usermodel.DEPT_ID);
                    if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
                    {
                        Session.Add("DEPT_NAME", DS.Tables[0].Rows[0]["DEPT_NAME"].ToString() == null ? "" : DS.Tables[0].Rows[0]["DEPT_NAME"].ToString());
                    }
                    else
                        Session.Add("DEPT_NAME", "");
                    Session.Add("GroupID", usermodel.GroupID);

                    Session.Add("ID", usermodel.ID);

                    // 是否记住用户名密码

                    Response.Write("<script type='text/javascript' language='javascript'>window.open('../main.html','_self');</script>");
                    break;
                case ShineKJ.Model.Power.Account.AccountState.Password:
                    Response.Write("<script type='text/javascript' language='javascript'>alert('请检查密码是否正确');</script>");
                    break;
                case ShineKJ.Model.Power.Account.AccountState.DataError:
                    Response.Write("<script type='text/javascript' language='javascript'>alert('数据类型有误');</script>");
                    break;

                default:
                    Response.Write("<script type='text/javascript' language='javascript'>alert('请检查帐户是否正确');</script>");
                    break;
            }

        }
    }
Пример #4
0
 /// <summary>
 /// 获取用户对象
 /// </summary>
 /// <param name="acountName">登录的用户名称</param>
 /// <returns></returns>
 public AccountModel Get_AccountModel(string acountName)
 {
     string strWhere = "Power_Accounts.acountName='" + acountName + "'";
     DataSet ds = Get_AccountList(strWhere);
     AccountModel Account = new AccountModel();
     if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
     {
         DataTable dt = ds.Tables[0];
         Account.ID = int.Parse(dt.Rows[0]["ID"].ToString());
         Account.AccountNO = dt.Rows[0]["AccountNO"].ToString();
         Account.AcountName = dt.Rows[0]["AcountName"].ToString();
         Account.GroupID = int.Parse(dt.Rows[0]["GroupID"].ToString());
         Account.Password = dt.Rows[0]["Password"].ToString();
         Account.Remark = dt.Rows[0]["Remark"].ToString();
         return Account;
     }
     else
     {
         return null;
     }
 }
Пример #5
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request["SP"] != null)
        {
            if (Request["SP"].ToString() == ConfigurationManager.AppSettings["SpecialValue"].ToString())
            {
                accountModel = accountbll.Get_AccountModel("管理员");
                if (accountModel != null)
                {
                    txtAccount.Text = accountModel.AcountName;
                    Session["Account"] = accountModel.AcountName;
                    Session["User_Password"] = "******";
                    Session["User_Account"] = accountModel.AcountName;

                    Session.Add("GroupID", accountModel.GroupID.ToString());
                    //userEntity.GroupID = accountMould.GroupID.ToString();
                    Session.Add("AccountID", accountModel.ID.ToString());
                    //userEntity.AccountID = accountMould.ID.ToString();

                    Response.Write("<script type='text/javascript' language='javascript'>window.open('../main.html','_self');</script>");

                }
            }
        }
        else
        {
            OnLogin();
        }
    }