private void buttonAdd_Click(object sender, EventArgs e) { OrderSet orderSet = new OrderSet(); orderSet.idClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); orderSet.idEmployee = Convert.ToInt32(comboBoxEmployee.SelectedItem.ToString().Split('.')[0]); orderSet.idProduct = Convert.ToInt32(comboBoxProduct.SelectedItem.ToString().Split('.')[0]); orderSet.Date = textBoxDate.Text; Program.master.OrderSet.Add(orderSet); Program.master.SaveChanges(); ShowOrderSet(); }
private void buttonEdit_Click(object sender, EventArgs e) { if (listViewOrders.SelectedItems.Count == 1) { OrderSet orderSet = listViewOrders.SelectedItems[0].Tag as OrderSet; orderSet.idClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); orderSet.idEmployee = Convert.ToInt32(comboBoxEmployee.SelectedItem.ToString().Split('.')[0]); orderSet.idProduct = Convert.ToInt32(comboBoxProduct.SelectedItem.ToString().Split('.')[0]); orderSet.Date = textBoxDate.Text; Program.master.SaveChanges(); ShowOrderSet(); } }
private void listViewOrders_SelectedIndexChanged(object sender, EventArgs e) { if (listViewOrders.SelectedItems.Count == 1) { OrderSet orderSet = listViewOrders.SelectedItems[0].Tag as OrderSet; comboBoxClient.SelectedIndex = comboBoxClient.FindString(orderSet.idClient.ToString()); comboBoxEmployee.SelectedIndex = comboBoxEmployee.FindString(orderSet.idEmployee.ToString()); comboBoxProduct.SelectedIndex = comboBoxProduct.FindString(orderSet.idProduct.ToString()); textBoxDate.Text = orderSet.Date; } else { comboBoxClient.SelectedItem = null; comboBoxEmployee.SelectedItem = null; comboBoxProduct.SelectedItem = null; textBoxDate.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewOrders.SelectedItems.Count == 1) { OrderSet orderSet = listViewOrders.SelectedItems[0].Tag as OrderSet; Program.master.OrderSet.Remove(orderSet); Program.master.SaveChanges(); ShowOrderSet(); } comboBoxClient.SelectedItem = null; comboBoxEmployee.SelectedItem = null; comboBoxProduct.SelectedItem = null; textBoxDate.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }