Esempio n. 1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(txtUsername.Text) || String.IsNullOrEmpty(txtPassword.Text))
     {
         lblError.Text = "Логин или пароль пустые";
         lblError.Show();
         return;
     }
     if (txtUsername.Text == "admin")
     {
         SQLiteConnection conn = new SQLiteConnection();
         try
         {
             conn = new SQLiteConnection(strConnect);
             conn.Open();
             SQLiteCommand CMD = conn.CreateCommand();
             CMD.CommandText = "SELECT password FROM LoginTable WHERE username = @username";
             CMD.Parameters.Add("@username", System.Data.DbType.String).Value = txtUsername.Text;
             SQLiteDataReader SQL = CMD.ExecuteReader();
             if (SQL.HasRows)
             {
                 while (SQL.Read())
                 {
                     if (SQL["password"].ToString() != txtPassword.Text)
                     {
                         lblError.Text = "Неправильный пароль";
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
         }
         AdminProfileForm adminProfileForm = new AdminProfileForm();
         adminProfileForm.Show();
         this.Hide();
     }
     else
     {
         string error = UserHandler.CheckUser(txtUsername.Text, txtPassword.Text);
         if (error == "ОК")
         {
             Worker          user            = UserHandler.GetUser(txtUsername.Text);
             UserProfileForm userProfileForm = new UserProfileForm(user);
             userProfileForm.Show();
             this.Hide();
         }
         else
         {
             lblError.Text = error;
         }
     }
 }
Esempio n. 2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>()
            {
                { "username", username },
                { "password", password },
                { "name", txtName.Text },
                { "surname", txtSurname.Text },
                { "role", cmbRole.Text },
            };

            Worker user = UserHandler.UserCreated(parameters, dtStartDate.Value.Date);

            UserProfileForm profile = new UserProfileForm(user);

            profile.Show();
            this.Hide();
        }