private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewClients.SelectedItems.Count == 1) { ClientsSet clientsSet = listViewClients.SelectedItems[0].Tag as ClientsSet; if (textBoxLastName.Text == "" || textBoxFirstName.Text == "" || textBoxTelephone.Text == "") { throw new Exception("Обязательные данные не заполнены"); } else { clientsSet.LastName = textBoxLastName.Text; clientsSet.FirstName = textBoxFirstName.Text; clientsSet.Phone = textBoxTelephone.Text; } Program.varr.SaveChanges(); ShowClients(); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonGo_Click(object sender, EventArgs e) { try { ClientsSet clientsSet = new ClientsSet(); if (textBoxLastName.Text == "" || textBoxFirstName.Text == "" || textBoxTelephone.Text == "") { throw new Exception("Обязательные данные не заполнены"); } else { clientsSet.LastName = textBoxLastName.Text; clientsSet.FirstName = textBoxFirstName.Text; clientsSet.Phone = textBoxTelephone.Text; } Program.varr.ClientsSet.Add(clientsSet); Program.varr.SaveChanges(); MessageBox.Show("Клиент успешно добавлен!", "Клиент добавлен", MessageBoxButtons.OK, MessageBoxIcon.Information); FormOrderBy formOrderBy = new FormOrderBy(); formOrderBy.Show(); this.Hide(); } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void listViewClients_SelectedIndexChanged(object sender, EventArgs e) { if (listViewClients.SelectedItems.Count == 1) { ClientsSet clientsSet = listViewClients.SelectedItems[0].Tag as ClientsSet; textBoxFirstName.Text = clientsSet.FirstName; textBoxLastName.Text = clientsSet.LastName; textBoxTelephone.Text = clientsSet.Phone; } else { textBoxFirstName.Text = ""; textBoxLastName.Text = ""; textBoxTelephone.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewClients.SelectedItems.Count == 1) { ClientsSet clientsSet = listViewClients.SelectedItems[0].Tag as ClientsSet; Program.varr.ClientsSet.Remove(clientsSet); Program.varr.SaveChanges(); ShowClients(); } textBoxFirstName.Text = ""; textBoxLastName.Text = ""; textBoxTelephone.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonAdd_Click(object sender, EventArgs e) { try { ClientsSet clientsSet = new ClientsSet(); if (textBoxLastName.Text == "" || textBoxFirstName.Text == "" || textBoxTelephone.Text == "") { throw new Exception("Обязательные данные не заполнены"); } else { clientsSet.LastName = textBoxLastName.Text; clientsSet.FirstName = textBoxFirstName.Text; clientsSet.Phone = textBoxTelephone.Text; } Program.varr.ClientsSet.Add(clientsSet); Program.varr.SaveChanges(); ShowClients(); } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }