Esempio n. 1
0
        /// <summary>
        /// 初始化配置数据
        /// </summary>
        private void InitConfig()
        {
            //创建xml配置文档
            XMLDAL.CreateXML();

            //获取复选框的状态
            bool checkBoxStatus = XMLDAL.GetCheckBoxStatus();

            ckbSavePassword.IsChecked = checkBoxStatus;//设置复选框的状态
            //获取下拉框的user
            userList = XMLDAL.GetUser();
            for (int i = userList.Count - 1; i >= 0; i--)
            {
                cbxUserName.Items.Add(userList[i][0]);//初始化下拉框
            }

            //如果处于保存密码状态,则将最近一次登录过的用户信息填上
            if (checkBoxStatus == true)
            {
                cbxUserName.Text = userList[userList.Count - 1][0];
                pwx.Password     = userList[userList.Count - 1][1];
                if (cbxUserName.Text != "用户名")
                {
                    cbxUserName.Foreground = new SolidColorBrush(Colors.Black);
                    pwx.Foreground         = new SolidColorBrush(Colors.Black);
                }
            }
        }
Esempio n. 2
0
        public MainViewModel()
        {
            _dal = new XMLDAL(Properties.Settings.Default.DataDirectory);

            SelectedDeckList = new DeckList();
            SelectedDeck     = new Deck();

            RefreshDeckLists();



            // Set commands
            CreateDeckListCommand = new RelayCommand <object>(new Action <object>(PromptToCreateDeckList));
            UpdateDeckListCommand = new RelayCommand <object>(new Action <object>(UpdateDeckList));
            DeleteDeckListCommand = new RelayCommand <object>(new Action <object>(DeleteDeckList));

            CreateDeckCommand = new RelayCommand <object>(new Action <object>(PromptToCreateDeck));
        }
Esempio n. 3
0
        private void Window_Closed(object sender, EventArgs e)
        {
            //关闭子窗体
            if (TransWindow.detailWindow != null)
            {
                TransWindow.detailWindow.Close();
            }
            if (TransWindow.rankDisplay != null)
            {
                TransWindow.rankDisplay.Close();
            }
            if (TransWindow.addWindField != null)
            {
                TransWindow.addWindField.Close();
            }

            XMLDAL.UpdateCheckBoxStatus(ckbSavePassword.IsChecked.ToString());//保存保存密码复选框的状态
            if (ckbSavePassword.IsChecked == false)
            {
                //如果不保存密码,则清空所有user的密码
                XMLDAL.CleanPassword();
            }
        }
Esempio n. 4
0
        private void loginWork()
        {
            //首先检查数据库连接
            if (LoginDAL.CheckDBConnection() != 0)
            {
                MessageBox.Show("连接失败,请检查网络连接!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                btnLogin.Content = "登录失败";
                return;
            }
            //获取全国的风机数量
            int pointNum = FanPointDAL.GetAllPoints().Count;

            labPointNum.Content = pointNum + " 台";
            //获取全国风场数量
            int windFieldNum = AllWindFieldDAL.GetWindFieldNumber();

            labWindFieldNumber.Content = windFieldNum + "个";
            //获取全国的公司数量
            int companyNum = AllWindFieldDAL.GetCompanyNumber();

            labCompanyNumber.Content = companyNum + " 家";
            initEvent(); //加载地图


            int ErrorTimeSpanMin = 30;//为保证账户安全,设置多次登录错误后的用户需要等待的时间

            if (cbxUserName.Text == "用户名" || pwx.Password == "*#*#*#")
            {
                MessageBox.Show("用户名或密码有误,请重新输入!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                cbxUserName.Focus();
                return;
            }
            User user = LoginDAL.GetAccountByUserName(cbxUserName.Text);//获取当前的用户信息

            if (user == null)
            {
                MessageBox.Show("不存在此用户!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                cbxUserName.Focus();
                return;
            }
            else
            {
                //如果距离上次登录成功已经超过30分钟,则将登录错误次数清零
                if (user.LoginTime != null)
                {
                    DateTime dt = LoginDAL.GetServerTime();                //获取服务器当前时间
                    TimeSpan ts = dt - (DateTime)user.LoginTime;           //获取当前用户最新的上一次登录的时间
                    if (ts.TotalMinutes >= ErrorTimeSpanMin)               //如果用户长时间没登录过,则将以前的登录错误次数清零
                    {
                        LoginDAL.ResetErrorTimesByUserName(user.UserName); //登录错误次数清零
                        user.ErrorTimes = 0;                               //本地记录的登录错误次数清零
                    }
                    else if (user.ErrorTimes >= 3)                         //如果登录错误次数超过了3次,则禁止用户在 ErrorTimeSpanMin 时间内登录(单位/分钟)
                    {
                        MessageBox.Show("登录失败次数过多,请 "
                                        + Math.Ceiling(ErrorTimeSpanMin - ts.TotalMinutes)
                                        + " 分钟后重试!",
                                        "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                }
            }

            string passWord = LoginDAL.GetMD5(pwx.Password);//获取加密后的密码

            if (passWord != user.Password)
            {
                LoginDAL.UpdateErrorTimesByUserName(user.UserName); //登录错误次数+1
                LoginDAL.UpdateLoginTimeByUserName(user.UserName);  //更新登录时间
                MessageBox.Show("密码不正确,请重新输入!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                pwx.Focus();
                return;
            }
            if ((cbxUserName.Text == user.UserName) && (passWord == user.Password))
            {
                //登录成功
                XMLDAL.UpdateUser(cbxUserName.Text, pwx.Password); //将登录成功的用户信息更新到配置文件里
                LoginDAL.UpdateLoginTimeByUserName(user.UserName); //更新登录时间
                LoginDAL.ResetErrorTimesByUserName(user.UserName); //登录错误次数清零

                LoginGrid.Visibility = Visibility.Hidden;
                MainGrid.Visibility  = Visibility.Visible;
            }
            else
            {
                LoginDAL.UpdateErrorTimesByUserName(user.UserName); //登录错误次数+1
                LoginDAL.UpdateLoginTimeByUserName(user.UserName);  //更新登录时间
                MessageBox.Show("登录失败,请重试!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }