private void buttonAdd_Click(object sender, EventArgs e) { Drugs drugs = new Drugs(); drugs.Name = textBoxName.Text; drugs.Phorm = comboBoxPhorm.Text; drugs.Dosage = textBoxDosage.Text; drugs.Proz = textBoxProz.Text; drugs.Time = textBoxTime.Text; Program.phrDb.Drugs.Add(drugs); Program.phrDb.SaveChanges(); ShowDrugs(); }
private void buttonEdit_Click(object sender, EventArgs e) { if (listViewDrugs.SelectedItems.Count == 1) { Drugs drugs = listViewDrugs.SelectedItems[0].Tag as Drugs; drugs.Name = textBoxName.Text; drugs.Phorm = comboBoxPhorm.Text; drugs.Dosage = textBoxDosage.Text; drugs.Proz = textBoxProz.Text; drugs.Time = textBoxTime.Text; Program.phrDb.SaveChanges(); ShowDrugs(); } }
private void listViewDrugs_SelectedIndexChanged(object sender, EventArgs e) { if (listViewDrugs.SelectedItems.Count == 1) { Drugs drugs = listViewDrugs.SelectedItems[0].Tag as Drugs; textBoxName.Text = drugs.Name; comboBoxPhorm.Text = drugs.Phorm; textBoxDosage.Text = drugs.Dosage; textBoxProz.Text = drugs.Proz; textBoxTime.Text = drugs.Time; } else { textBoxName.Text = ""; comboBoxPhorm.Text = ""; textBoxDosage.Text = ""; textBoxProz.Text = " "; textBoxTime.Text = " "; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewDrugs.SelectedItems.Count == 1) { Drugs drugs = listViewDrugs.SelectedItems[0].Tag as Drugs; Program.phrDb.Drugs.Remove(drugs); Program.phrDb.SaveChanges(); ShowDrugs(); } textBoxName.Text = ""; comboBoxPhorm.Text = ""; textBoxDosage.Text = ""; textBoxProz.Text = " "; textBoxTime.Text = " "; } catch { MessageBox.Show("Невозможно удалить, эта кнопка используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }