private void addClient_Click(object sender, EventArgs e) { AddEditClient form = new AddEditClient(); form.Text = "Добавить клиента"; try { if (form.ShowDialog() == DialogResult.OK) { string lastName = form.lastName.Text; string firstName = form.firstName.Text; string middleName = form.middleName.Text; decimal power = form.power.Value; decimal price = form.price.Value; string[] brends = form.brends.Items.Cast <string>().ToArray(); string[] contacts = form.contacts.Items.Cast <string>().ToArray(); if (lastName == "" || firstName == "" || middleName == "" || brends.Length == 0 || contacts.Length == 0) { return; } Client client = new Client(lastName, firstName, middleName, (Transmission.TransmissionEnum)(form.transmission.SelectedIndex + 1), form.newOrOld.Checked ? State.StateEnum.New : State.StateEnum.Old, power, price, brends); foreach (string i in contacts) { client.AddContact(i); } clients.Add(client); clientsList.Items.Clear(); clientsList.Items.AddRange(clients.ToArray()); } } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void editClient_Click(object sender, EventArgs e) { if (clientsList.SelectedItem == null) { return; } AddEditClient form = new AddEditClient(); Client client = clients[clientsList.SelectedIndex]; form.lastName.Text = client.lastName; form.firstName.Text = client.firstName; form.middleName.Text = client.middleName; form.power.Value = client.minPower; form.price.Value = client.maxPrice; form.transmission.SelectedIndex = (int)client.transmission.transmission - 1; form.newOrOld.Checked = (int)client.state.state == 2; form.brends.Items.AddRange((clientsList.SelectedItem as Client).brends.ToArray()); form.contacts.Items.AddRange((clientsList.SelectedItem as Client).GetContacts()); form.Text = "Изменить клиента"; form.accept.Text = "Применить"; try { if (form.ShowDialog() == DialogResult.OK) { string lastName = form.lastName.Text; string firstName = form.firstName.Text; string middleName = form.middleName.Text; decimal power = form.power.Value; decimal price = form.price.Value; string[] brends = form.brends.Items.Cast <string>().ToArray(); string[] contacts = form.contacts.Items.Cast <string>().ToArray(); if (lastName == "" || firstName == "" || middleName == "" || brends.Length == 0 || contacts.Length == 0) { return; } client.lastName = lastName; client.firstName = firstName; client.middleName = middleName; client.minPower = power; client.maxPrice = price; client.transmission = new Transmission((Transmission.TransmissionEnum)(form.transmission.SelectedIndex + 1)); client.state = new State(form.newOrOld.Checked ? State.StateEnum.New : State.StateEnum.New | State.StateEnum.Old); client.brends.Clear(); client.brends.AddRange(brends); client.ClearContacts(); foreach (string i in contacts) { client.AddContact(i); } clientsList.Items.Clear(); clientsList.Items.AddRange(clients.ToArray()); autosList.Items.Clear(); autosList.Items.Add(String.Format("Марки: {0}", string.Join(", ", client.brends.ToArray()))); autosList.Items.Add(String.Format("Коробка передач: {0}", client.transmission.GetString)); autosList.Items.Add(String.Format("Состояние: {0}", client.state.GetString)); autosList.Items.Add(String.Format("Минимальная мощность: {0}", client.minPower)); autosList.Items.Add(String.Format("Максимальная стоимость: {0}", client.maxPrice)); autosList.Items.Add("Контакты:"); foreach (string s in client.GetContacts()) { autosList.Items.Add(s); } } } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }