示例#1
0
 public ChangePasswordForm(User user)
 {
     InitializeComponent();
     this.DialogResult = DialogResult.Cancel;
     this.Text = user.login;
     userId = user.id;
 }
示例#2
0
        public static void LogOut()
        {
            Properties.Settings.Default.Password = "";
            Properties.Settings.Default.Save();

            loggedUser = null;
            if (activeForm != null)
                activeForm.Close();
            activeForm = new LoginForm();
            ShowActiveForm();
        }
示例#3
0
        public static bool TryLogin(string login, string password, bool auto = false)
        {
            try
            {
                if (login == "")
                    throw new Exception("Имя пользователя не может быть пустым");
                
                string queryString = String.Format("SELECT * FROM users WHERE login = '******'", login );
                List<User> userList = DataProvider.GetRecordsFromQuery<User>(queryString);
                if (userList.Count == 0)
                    throw new Exception(String.Format("Пользователь {0} отсутствует в базе", login));

                User user = userList[0];
                if (user.password == null)
                {
                    DialogResult result = new ChangePasswordForm(user).ShowDialog();
                    if (result != DialogResult.OK)
                        return false;
                }
                else
                {
                    if (user.password != Utils.MD5(password))
                        throw new Exception("Пароль не подходит");
                }

                loggedUser = user;

                if (activeForm != null)
                    activeForm.Close();
                activeForm = new MainForm();
                ShowActiveForm();

            }
            catch (Exception error)
            {
                if(!auto)
                    Utils.ErrorMessage(error.Message);
                return false;
            }

            return true;
        }
示例#4
0
 private void ListView_SelectedIndexChanged(object sender, EventArgs e)
 {
     Apply(true);
     if (ListView.SelectedIndices.Count == 0)
     {
         selectedUser = null;
         return;
     }
     selectedUser = userList[ListView.SelectedIndices[0]];
     FillFields();
 }