private void Clear_Click(object sender, RoutedEventArgs e) { NameCustomerText.Clear(); SiteText.Clear(); RepresentativeText.Clear(); PhoneNumberText.Clear(); ClientsListBox.SelectedItem = -1; }
private void DeleteClient_Click(object sender, RoutedEventArgs e) { try { foreach (Customer cs in lc.Cust) { if (ClientsListBox.SelectedItem != null) { if (cs.Name == ClientsListBox.SelectedItem.ToString()) { NameCustomerText.Text = cs.Name; SiteText.Text = cs.Site; RepresentativeText.Text = cs.Representative; PhoneNumberText.Text = cs.RepPhone.ToString(); Log.logging("Удален клиент: " + cs.Name + " " + DateTime.Now); lc.Cust.Remove(cs); break; } } } Serialization.Serialize(lc); ClientsListBox.Items.Clear(); foreach (var item in lc.Cust) { ClientsListBox.Items.Add(item.Name); } NameCustomerText.Clear(); SiteText.Clear(); RepresentativeText.Clear(); PhoneNumberText.Clear(); MessageBox.Show("Удалено!"); } catch (Exception ex) { MessageBox.Show(ex.Message); Log.logging("Ошибка: " + ex); } }
private void AddClient_Click(object sender, RoutedEventArgs e) { try { if (ClientsListBox.SelectedItem.ToString() != NameCustomerText.Text) { Customer cust = new Customer(NameCustomerText.Text, SiteText.Text, RepresentativeText.Text, PhoneNumberText.Text); lc.Cust.Add(cust); Log.logging("Добавлен клиент: " + cust.Name + " " + DateTime.Now); Serialization.Serialize(lc); ClientsListBox.Items.Clear(); lc = Serialization.Deserialze(lc); NameCustomerText.Clear(); SiteText.Clear(); RepresentativeText.Clear(); PhoneNumberText.Clear(); foreach (var item in lc.Cust) { ClientsListBox.Items.Add(item.Name); } MessageBox.Show("Сохранено!"); } else { MessageBox.Show("Такой заказчик уже существует!"); NameCustomerText.Clear(); SiteText.Clear(); RepresentativeText.Clear(); PhoneNumberText.Clear(); ClientsListBox.SelectedItem = -1; } } catch (Exception ex) { MessageBox.Show(ex.Message); Log.logging("Ошибка" + ex); } }