private void buttonGo_Click(object sender, EventArgs e) { try { OrdersSet ordersSet = new OrdersSet(); if (comboBoxAutoparts.SelectedItem == null || comboBoxClient.SelectedItem == null || comboBoxManager.SelectedItem == null) { throw new Exception("Обязательные данные не заполнены"); } else { ordersSet.IdAutopart = Convert.ToInt32(comboBoxAutoparts.SelectedItem.ToString().Split('.')[0]); ordersSet.IdManager = Convert.ToInt32(comboBoxManager.SelectedItem.ToString().Split('.')[0]); ordersSet.IdClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); } Program.varr.OrdersSet.Add(ordersSet); Program.varr.SaveChanges(); MessageBox.Show("Заказ успешно оформлен!", "Заказ оформлен", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void listViewOrders_SelectedIndexChanged(object sender, EventArgs e) { if (listViewOrders.SelectedItems.Count == 1) { OrdersSet ordersSet = listViewOrders.SelectedItems[0].Tag as OrdersSet; comboBoxManager.Text = ordersSet.IdManager.ToString() + ". " + ordersSet.ManagerSet.IdUser.ToString() + ". " + ordersSet.ManagerSet.Users.Login; comboBoxAutoparts.Text = ordersSet.IdAutopart.ToString() + ". " + ordersSet.AutopartsSet.NameAutopart; comboBoxClient.Text = ordersSet.IdClient.ToString() + ". " + ordersSet.ClientsSet.LastName + " " + ordersSet.ClientsSet.FirstName; } else { comboBoxManager.SelectedItem = null; comboBoxAutoparts.SelectedItem = null; comboBoxClient.SelectedItem = null; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewOrders.SelectedItems.Count == 1) { OrdersSet ordersSet = listViewOrders.SelectedItems[0].Tag as OrdersSet; Program.varr.OrdersSet.Remove(ordersSet); Program.varr.SaveChanges(); ShowOrders(); } comboBoxManager.Text = null; comboBoxAutoparts.Text = null; comboBoxClient.Text = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewOrders.SelectedItems.Count == 1) { OrdersSet ordersSet = listViewOrders.SelectedItems[0].Tag as OrdersSet; if (comboBoxAutoparts.SelectedItem == null || comboBoxClient.SelectedItem == null || comboBoxManager.SelectedItem == null) { throw new Exception("Обязательные данные не заполнены"); } else { ordersSet.IdAutopart = Convert.ToInt32(comboBoxAutoparts.SelectedItem.ToString().Split('.')[0]); ordersSet.IdManager = Convert.ToInt32(comboBoxManager.SelectedItem.ToString().Split('.')[0]); ordersSet.IdClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); } Program.varr.SaveChanges(); ShowOrders(); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }