private void buttonEdit_Click(object sender, EventArgs e) { if (listViewPay.SelectedItems.Count == 1) { PaySet pay = listViewPay.SelectedItems[0].Tag as PaySet; pay.idCitizen = Convert.ToInt32(comboBoxCitizen.SelectedItem.ToString().Split('.')[0]); pay.Type = comboBoxType.Text; pay.Date = textBoxDate.Text; Program.znt.SaveChanges(); ShowPay(); } }
private void listViewPay_SelectedIndexChanged(object sender, EventArgs e) { if (listViewPay.SelectedItems.Count == 1) { PaySet pay = listViewPay.SelectedItems[0].Tag as PaySet; comboBoxCitizen.SelectedIndex = comboBoxCitizen.FindString(pay.idCitizen.ToString()); comboBoxType.Text = pay.Type; textBoxDate.Text = pay.Date; } else { comboBoxCitizen.SelectedItem = null; comboBoxType.SelectedItem = null; textBoxDate.Text = ""; } }
private void buttonAdd_Click(object sender, EventArgs e) { if (comboBoxCitizen.SelectedItem != null && comboBoxType.SelectedItem != null && textBoxDate.Text != "") { PaySet pay = new PaySet(); pay.idCitizen = Convert.ToInt32(comboBoxCitizen.SelectedItem.ToString().Split('.')[0]); pay.Type = comboBoxType.Text; pay.Date = textBoxDate.Text; Program.znt.PaySet.Add(pay); Program.znt.SaveChanges(); ShowPay(); } else { MessageBox.Show("Выберите данные", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewPay.SelectedItems.Count == 1) { PaySet pay = listViewPay.SelectedItems[0].Tag as PaySet; Program.znt.PaySet.Remove(pay); Program.znt.SaveChanges(); ShowPay(); } comboBoxCitizen.SelectedItem = null; comboBoxType.SelectedItem = null; textBoxDate.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }