private void buttonDeleteEmployee_Click(object sender, EventArgs e) { try { ClinicEmployeesRow currentSelectedValue = (ClinicEmployeesRow)((DataRowView)clinicEmployeesBindingSource.Current).Row; SqlCommand command; DataSet dataSet = new DataSet(); adapter.SelectCommand = new SqlCommand("SELECT * FROM ClinicEmployees where 1 = 2", connection); adapter.Fill(dataSet, "ClinicEmployees"); command = new SqlCommand("UPDATE ClinicEmployees SET Active=@active WHERE UserLogin=@userLogin", connection); adapter.UpdateCommand = command; adapter.UpdateCommand.Parameters.AddWithValue("@userLogin", currentSelectedValue.UserLogin); adapter.UpdateCommand.Parameters.AddWithValue("@active", 0); adapter.UpdateCommand = command; adapter.SelectCommand = command; adapter.Fill(dataSet, "ClinicEmployees"); adapter.Update(dataSet, "ClinicEmployees"); MessageBox.Show("Zwolniono pracownika."); } catch (Exception ex) { MessageBox.Show("Nie zaznaczono pracownika."); } }
private void buttonEditEployee_Click(object sender, EventArgs e) { if (openNextWindow("EditEmployeeForm")) { ClinicEmployeesRow currentSelectedValue = (ClinicEmployeesRow)((DataRowView)clinicEmployeesBindingSource.Current).Row; EditEmployeeForm window = new EditEmployeeForm(currentSelectedValue); window.Show(); } }
public EditEmployeeForm(ClinicEmployeesRow currentSelectedValue) { InitializeComponent(); connection = new SqlConnection("Data Source=ASIA-HP;Initial Catalog=Clinic;Persist Security Info=True;User ID=sa;Password=praktyka"); adapter = new SqlDataAdapter(); Update_combobox(city = new DataTable("City"), comboBoxEmployeeCity, "select * from Cities", "CityName"); Update_combobox(voivodeships = new DataTable("Voivodeships"), comboBoxEmployeeVoivodeship, "select * from Voivodeships", "VoivodeshipName"); Update_combobox(userGroups = new DataTable("UserGroups"), comboBoxEmployeeGroup, "select * from UserGroups", "GroupName"); Update_combobox(medicalSpecializations = new DataTable("MedicalSpecializations"), comboBoxEmployeeAddSpecialization, "select * from MedicalSpecializations", "MedicalSpecializationName"); editedEmployee = currentSelectedValue; textBoxEmployeeFirstName.Text = currentSelectedValue.FirstName; textBoxEmployeeLastName.Text = currentSelectedValue.LastName; textBoxEmployeeStreet.Text = currentSelectedValue.Street; textBoxEmployeeStreetNo.Text = currentSelectedValue.StreetNumer; textBoxEmployeePostalCode.Text = currentSelectedValue.PostalCode; DataTable temp = new DataTable(); SqlCommand command = new SqlCommand("SELECT * FROM Voivodeships where VoivodeshipID = " + "(SELECT VoivodeshipID FROM Cities WHERE CityID = @cityID); ", connection); adapter.SelectCommand = command; adapter.SelectCommand.Parameters.AddWithValue("@cityID", currentSelectedValue.CityID); adapter.Fill(temp); adapter.Update(temp); comboBoxEmployeeVoivodeship.Text = temp.Rows[0]["VoivodeshipName"].ToString(); comboBoxEmployeeCity.SelectedItem = comboBoxEmployeeCity.Items.Cast <ComboBoxItem>().Where(x => x.Hidden["CityID"].ToString().Equals(currentSelectedValue.CityID.ToString())).Single(); comboBoxEmployeeGroup.SelectedItem = comboBoxEmployeeGroup.Items.Cast <ComboBoxItem>().Where(x => x.Hidden["UserGroupID"].ToString().Equals(currentSelectedValue.UserGroupID.ToString())).Single(); textBoxEmployeePhoneNo.Text = currentSelectedValue.PhoneNumber.ToString(); textBoxEmployeeDescription.Text = currentSelectedValue.EmployeeDescription; textBoxEmployeeLogin.Text = currentSelectedValue.UserLogin; MemoryStream stream = new MemoryStream((byte[])currentSelectedValue.Picture); pictureBox.Image = Image.FromStream(stream); fillSpecializationBoxes(currentSelectedValue.EmployeeID.ToString()); }