Esempio n. 1
0
        //用户登陆功能
        public int userLogin(string account, string password)
        {
            try
            {
                string sql = "select * from users as u where u.ACCOUNT='" + @account + "'";

                parameter.ParameterName = "@account";
                parameter.Value         = account;
                reade = MySqlHelper.ExecuteReader(MySqlHelper.Conn, CommandType.Text, sql, parameter);
                if (reade.Read() == false)
                {
                    return(ERROR);
                }
                string passwordStr = Session.MD5Encrypt(password);
                if (!passwordStr.Equals(reade["PASSWORD"]))
                {
                    return(ERROR);
                }
                Session.UserAccount = account;
                Session.UserId      = (int)reade["ID"];
                Console.WriteLine(reade["TYPE"]);
                Session.UserType  = (int)reade["TYPE"];
                Session.LoginTime = Convert.ToDateTime(reade["LOGIN_TIME"]).ToString("yyyy-MM-dd hh:mm:ss");
                //登陆成功后更新最近登陆时间
                DateTime         loginTime  = Convert.ToDateTime(DateTime.Now); //yyyy-MM-dd hh:mm:ss
                string           updateSql  = "update users as u set u.LOGIN_TIME='" + @loginTime + "' where u.ID=" + @Session.UserId;
                MySqlParameter[] parameters =
                {
                    new MySqlParameter("@loginTime",      loginTime),
                    new MySqlParameter("@Session.UserId", Session.UserId),
                };
                parameter.ParameterName = "@loginTime";
                parameter.Value         = loginTime.ToString("yyyy-MM-dd hh:mm:ss");
                MySqlHelper.ExecuteNonQuery(MySqlHelper.Conn, CommandType.Text, updateSql, parameter);
                string logSql = "insert into users_log(USER_ID,LOGIN_TIME) values(" + @Session.UserId + ",'" + @loginTime + "')";
                Session.LogId = MySqlHelper.ExecuteNonQueryId(MySqlHelper.Conn, CommandType.Text, logSql, parameters);
                TimeEvent  exitTime = new TimeEvent(Session.LogId);
                AlarmClass alarm    = new AlarmClass();
                exitTime.TimerRun();
                alarm.TimerRun();
            }catch (Exception e) {
                e.GetBaseException();
                return(SYSTEM_EXCEPTION);
            }
            return(SUCCESS);
        }