Example #1
0
        //用户登录的方法
        public Model.LoginForm.UserInfo SelectUser(string userId, string Password)
        {
            //建立数据库连接
            MySqlConnectionStringBuilder connectionString = new MySqlConnectionStringBuilder();

            connectionString.Server             = "localhost";
            connectionString.UserID             = "root";
            connectionString.Password           = "******";
            connectionString.Database           = "cnpc_lmats1";
            connectionString.AllowUserVariables = true;

            using (MySqlConnection conn = new MySqlConnection(connectionString.ToString()))
            {
                //执行SQL语句进行查询
                MySqlCommand cmd = conn.CreateCommand();
                //添加两个参数
                cmd.Parameters.Add(new MySqlParameter(@"UserID", userId));
                cmd.Parameters.Add(new MySqlParameter(@"Password", Password));
                cmd.CommandText = string.Format("SELECT UserID,Password FROM users WHERE UserID =@UserID AND Password =@Password");
                //输出查询结果
                cmd.CommandType = CommandType.Text;

                conn.Open();
                MySqlDataReader reader = cmd.ExecuteReader();

                Model.LoginForm.UserInfo user = null;

                //读取具体的数据
                while (reader.Read())
                {
                    if (user == null)
                    {
                        user = new Model.LoginForm.UserInfo();
                    }
                    //读取查询到的数据
                    user.UserId   = reader.GetString(0);
                    user.Password = reader.GetString(1);
                    //if (!reader.IsDBNull(3))
                    //{
                    //    user.Email = reader.GetString(3);
                    //}
                }
                return(user);
            }
        }
Example #2
0
        public Model.LoginForm.UserInfo UserLogin(string userName, string password)
        {
            UserDB UserDB = new UserDB();

            Model.LoginForm.UserInfo user = UserDB.SelectUser(userName, password);
            if (user == null)
            {
                string sql = "update  table_name set canUpdate = 1";
                DbManager.Ins.ExecuteNonquery(sql);


                return(user);
            }
            else
            {
                throw new WrongInfoException();
            }
        }
Example #3
0
        private void LoginAction()
        {
            LoginProgress.IsEnabled = false;
            loginBtn.IsEnabled      = false;
            user.IsEnabled          = false;
            psw.IsEnabled           = false;
            accRemBox.IsEnabled     = false;
            Storyboard storyboard = LoginProgress.Resources["inProgressBoard"] as Storyboard;


            DependencyProperty[] propertyChain = new DependencyProperty[]
            {
                Label.OpacityProperty
            };
            DoubleAnimation txtAnimation = new DoubleAnimation();
            Storyboard      storyboard1  = new Storyboard();

            txtAnimation.From     = 0;
            txtAnimation.To       = 1;
            txtAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
            storyboard1.Children.Add(txtAnimation);
            storyboard1.AutoReverse    = true;
            storyboard1.RepeatBehavior = RepeatBehavior.Forever;
            Storyboard.SetTarget(txtAnimation, LoginInfoTxt);
            Storyboard.SetTargetProperty(txtAnimation, new PropertyPath("(0)", propertyChain));
            storyboard.Begin();
            storyboard1.Begin();
            AutoResetEvent auto     = new AutoResetEvent(false);
            string         UserId   = user.Text.Trim().ToString();
            string         Password = psw.Password;

            Thread loginThread = new Thread(() =>
            {
                try
                {
                    //DispatcherTimer timer = new DispatcherTimer();
                    //timer.Interval = new TimeSpan(10000000);
                    //timer.Tick += Timer_Tick;
                    //timer.Start();
                    BLL.LoginManager loginManager = new BLL.LoginManager();
                    auto.WaitOne(2000);
                    Model.LoginForm.UserInfo userQuest = loginManager.UserLogin(UserId, Password);

                    if (userQuest != null)
                    {
                        globalUser = userQuest;
                        this.Dispatcher.Invoke(
                            new Action(() =>
                        {
                            storyboard1.Stop();
                            LoginInfoTxt.Opacity  = 1;
                            LoginInfoTxt.Content  = "欢迎,";
                            LoginInfoTxt.Content += userQuest.UserId;
                        }));
                    }
                    auto.WaitOne(2000);

                    this.Dispatcher.Invoke(
                        new Action(() =>
                    {
                        editPanel.Show();
                        this.Close();
                    }));
                }
                catch (WrongInfoException e)
                {
                    MessageBox.Show("ERR_LOGIN:0001\n用户名或密码不正确,请重新输入。");
                    this.Dispatcher.Invoke(
                        new Action(() =>
                    {
                        LoginProgress.IsEnabled = true;
                        loginBtn.IsEnabled      = true;
                        user.IsEnabled          = true;
                        psw.IsEnabled           = true;
                        accRemBox.IsEnabled     = true;
                        storyboard.Stop();
                        storyboard1.Stop();
                        psw.Password = null;
                    }));
                }
                //catch (TimeoutException)
                //{
                //    MessageBox.Show("ERR_LOGIN_TIMEOUT:0002");
                //}
            });

            loginThread.IsBackground = true;
            loginThread.Start();
        }