private void buttonDeletePatient_Click(object sender, EventArgs e) { try { Patients_viewRow currentSelectedValue = (Patients_viewRow)((DataRowView)patients_viewBindingSource.Current).Row; SqlCommand command; DataSet dataSet = new DataSet(); adapter.SelectCommand = new SqlCommand("SELECT * FROM Patients where 1 = 2", connection); adapter.Fill(dataSet, "Patients"); command = new SqlCommand("UPDATE Patients SET Active=@active WHERE PESEL=@pesel", connection); adapter.UpdateCommand = command; adapter.UpdateCommand.Parameters.AddWithValue("@pesel", currentSelectedValue.PESEL); adapter.UpdateCommand.Parameters.AddWithValue("@active", 0); adapter.UpdateCommand = command; adapter.SelectCommand = command; adapter.Fill(dataSet, "Patients"); adapter.Update(dataSet, "Patients"); MessageBox.Show("Wypisano pacjenta."); } catch (Exception ex) { MessageBox.Show("Nie zaznaczono pacjenta."); } }
public EditPatientForm(Patients_viewRow 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"), comboBoxNewPatientCity, "select * from Cities", "CityName"); Update_combobox(voivodeships = new DataTable("Voivodeships"), comboBoxNewPatientVoivodeship, "select * from Voivodeships", "VoivodeshipName"); editedPatient = GetPatientInfo(currentSelectedValue); textBoxNewPatientFirstName.Text = editedPatient.FirstName; textBoxNewPatientLastName.Text = editedPatient.LastName; textBoxNewPatientStreet.Text = editedPatient.Street; textBoxNewPatientStreetNo.Text = editedPatient.StreetNumer; textBoxNewPatientPostalCode.Text = editedPatient.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", editedPatient.CityID); adapter.Fill(temp); adapter.Update(temp); comboBoxNewPatientVoivodeship.Text = temp.Rows[0]["VoivodeshipName"].ToString(); comboBoxNewPatientCity.SelectedItem = comboBoxNewPatientCity.Items.Cast <ComboBoxItem>().Where(x => x.Hidden["CityID"].ToString().Equals(editedPatient.CityID.ToString())).Single(); textBoxNewPatientPhoneNo.Text = editedPatient.PhoneNumber.ToString(); textBoxNewPatientPesel.Text = editedPatient.PESEL; checkBoxNewPatientNFZ.Checked = editedPatient.NFZ; }
private void buttonEditPatient_Click(object sender, EventArgs e) { if (openNextWindow("EditPatientForm")) { Patients_viewRow currentSelectedValue = (Patients_viewRow)((DataRowView)patients_viewBindingSource.Current).Row; EditPatientForm window = new EditPatientForm(currentSelectedValue); window.Show(); } }
private Patient GetPatientInfo(Patients_viewRow currentSelectedValue) { return(MainWindow.Instance.Db.Patients.Single(pat => pat.PESEL.Equals(currentSelectedValue.PESEL))); }