예제 #1
0
        private void refreshData_Click(object sender, EventArgs e)
        {
            MagazynEntities tmpContext = new MagazynEntities();

            dataGridView.DataSource = tmpContext.Users.ToList();
            tmpContext.Dispose();
        }
예제 #2
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            MagazynEntities context    = new MagazynEntities();
            Users           user       = new Users();
            Users           veryfiUser = new Users();

            user.Username = textBoxUsername.Text;
            user.Password = CreateMD5(textBoxPassword.Text);

            if (String.IsNullOrEmpty(user.Username) || String.IsNullOrEmpty(user.Password))
            {
                MessageBox.Show("Nazwa użytkownika i hasło nie mogą być puste!");
                return;
            }
            else
            {
                veryfiUser = context.Users.FirstOrDefault(u => u.Username == user.Username && u.Password == user.Password);
                if (veryfiUser == null)
                {
                    MessageBox.Show("Proszę podaj poprawną nazwe użytkownika lub hasło.");
                    return;
                }
            }

            if (user.Username == veryfiUser.Username)
            {
                if (user.Password == veryfiUser.Password)
                {
                    frmMain main = new frmMain(veryfiUser);
                    this.Hide();
                    main.Show();
                    return;
                }
                else
                {
                    MessageBox.Show("Proszę podaj poprawną nazwe użytkownika lub hasło.");
                    return;
                }
            }
        }
예제 #3
0
        private void buttonNewPass_Click(object sender, EventArgs e)
        {
            try
            {
                MagazynEntities context = new MagazynEntities();

                if (String.IsNullOrEmpty(textBoxPassword.Text) ||
                    String.IsNullOrEmpty(textBoxNewPassword.Text) ||
                    String.IsNullOrEmpty((textBoxNewPasswordVeryfi.Text)))
                {
                    throw new Exception("Wszystkie dane muszą być uzupełnione.");
                }
                if (String.Compare(textBoxNewPassword.Text, textBoxNewPasswordVeryfi.Text) == -1)
                {
                    throw new Exception("Wpisane hasła muszą być identycze.");
                }

                var result = context.Users.SingleOrDefault(b => b.Username == tmp.Username);
                if (result != null && result.Password == CreateMD5(textBoxPassword.Text))
                {
                    result.Password = CreateMD5(textBoxNewPassword.Text);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Aktualne hasło jest nieprawidłowe.");
                }

                MessageBox.Show("Hasło zostało pomyślnie zmienione.");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }