private void button1_Click(object sender, EventArgs e) { //Lista_wypozyczen frm = (Lista_wypozyczen)Application.OpenForms["Lista_wypozyczen"]; DM_Wydanie_czesci newWypozyczenie_czesci = new DM_Wydanie_czesci(); //newWypozyczenie_czesci.Id_wydania_czesci = Convert.ToInt32(comboBox1.SelectedValue); newWypozyczenie_czesci.Id_pracownik_pobierajacy = Convert.ToInt32(comboBox2.SelectedValue); newWypozyczenie_czesci.Id_pracownik_wydajacy = Convert.ToInt32(comboBox3.SelectedValue); newWypozyczenie_czesci.Data_i_godzina = Convert.ToDateTime(dateTimePicker1.Value); newWypozyczenie_czesci.Uwagi = textBox1.Text; this.database.DM_Wydanie_czesci.Add(newWypozyczenie_czesci); this.database.SaveChanges(); //frm.dgvWypozyczenia.DataSource = this.database.vDM_Wydanie_czesci.ToList(); this.Close(); this.Hide(); Lista_wypozyczen lista = new Lista_wypozyczen(this.database); lista.ShowDialog(); }
private void button2_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Czy chcesz usunąć wypożyczenie?", "Usuwanie wypożyczenia", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int id = Convert.ToInt32(this.dgvWypozyczenia.CurrentRow.Cells[0].Value); DM_Wydanie_czesci toRemove = this.database.DM_Wydanie_czesci.Where(czesc => czesc.Id_wydania_czesci == id).First(); this.database.DM_Wydanie_czesci.Remove(toRemove); // DELETE this.database.SaveChanges(); initDataGridView(); } else { DialogResult dialog1Result = MessageBox.Show("Nie udało się usunąć wypozyczenia?"); } }