コード例 #1
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            int         help = -1;
            List <User> U    = new List <User>();

            U = ShopDatabase.GetUser("Admin");
            string username = usernameTextBox.Text;
            string password = passwordTextBox.Text;

            for (int i = 0; i < U.Count; i++)
            {
                if (U[i].Username == username && U[i].Password == password)
                {
                    help = i;
                    this.Hide();
                    U[i].SetList(U[i]);
                    U[i].SetID(1);
                    MessageBox.Show(username + " successfully logged in");
                    Main sistema = new Main();
                    sistema.ShowDialog();
                    this.Close();
                }
            }
            if (help == -1)
            {
                MessageBox.Show("Wrong username or password");
            }
        }
コード例 #2
0
ファイル: Registration.cs プロジェクト: dziugas84/PSI-PROJECT
 private void createUser_Click(object sender, EventArgs e)
 {
     if (nameTextBox.Text == "" || surnameTextBox.Text == "" || usernameTextBox.Text == "" || passwordTextBox.Text == "")
     {
         MessageBox.Show("Fill in all text boxes");
     }
     else
     {
         User u = new User();
         u.Name     = nameTextBox.Text;
         u.Surname  = surnameTextBox.Text;
         u.Username = usernameTextBox.Text;
         u.Password = passwordTextBox.Text;
         List <User> help = new List <User>();
         int         h    = 0;
         help = ShopDatabase.GetUser("User");
         for (int i = 0; i < help.Count; i++)
         {
             if (help[i].Username == u.Username)
             {
                 MessageBox.Show("This Username is already taken");
                 h = 1;
                 i = help.Count + 1;
             }
         }
         if (h == 0)
         {
             ShopDatabase.SaveUser("User", u);
             MessageBox.Show("New user has been created");
             Close();
         }
     }
     nameTextBox.Text     = "";
     surnameTextBox.Text  = "";
     usernameTextBox.Text = "";
     passwordTextBox.Text = "";
 }