private void btnConfirm_Click(object sender, RoutedEventArgs e) { try { DataTable datatable = new DataTable(); if (connection.State == ConnectionState.Closed) { connection.Open(); } string commandstring = "Update Pracownicy set Imię ='" + txtFirstName.Text + "', Nazwisko ='" + txtLastName.Text + "', PESEL = '" + txtPESEL.Text + "', Data_urodzenia = '" + txtBirthDate.Text.ToString() + "', data_zatrudnienia = '" + txtEmployment.Text.ToString() + "', stanowisko = '" + txtPosition.Text + "', Nume_konta_bankowego = '" + txtAccount.Text + "', numer_telefonu = '" + txtTelephone.Text + "', adres_email = ' " + txtEmail.Text + "'" + " where ID_pracownika = " + ID; command = new SqlCommand(commandstring, connection); command.ExecuteNonQuery(); this.Close(); if (name.Equals("pracownik")) { pracownik_window.Show(); } else { admmin_window.Show(); } } catch (Exception err) { MessageBox.Show(err.Message); } }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { dt = new DataTable(); txtPassword.PasswordChar = '*'; string role = String.Empty; string profession = String.Empty; int id; conn = new SqlConnection(ConfigurationManager.AppSettings["constring"]); try { conn.Open(); SqlCommand command = new SqlCommand("Select * FROM[dbo].[Konta] Where username='******' and hasło = '" + txtPassword.Password.ToString() + "'", conn); reader = command.ExecuteReader(); dt.Load(reader); if (dt.Rows.Count > 0) { role = dt.Rows[0].ItemArray[2].ToString(); string_id = dt.Rows[0].ItemArray[3].ToString(); } reader.Close(); conn.Close(); if (dt.Rows.Count == 1) { if (role.Contains("prezes")) { } else if (role.Contains("klient")) { } else if (role.Contains("administrator")) { id = Int32.Parse(string_id); Administrator admin = new Administrator(id, conn, txtPassword.Password.ToString(), this); txtUserName.Text = String.Empty; txtPassword.Clear(); this.Hide(); admin.Show(); } else if (role.Contains("kierownik")) { id = Int32.Parse(string_id); Pracownik pracownik = new Pracownik(id, conn, txtPassword.Password.ToString(), this); txtUserName.Text = String.Empty; txtPassword.Clear(); this.Hide(); pracownik.Show(); } } else { MessageBox.Show("There is no user with these credentials in database. Write your username and login once again."); txtUserName.Text = String.Empty; txtPassword.Clear(); conn.Close(); } } catch (Exception error) { MessageBox.Show(error.Message); txtUserName.Text = String.Empty; txtPassword.Clear(); conn.Close(); } }