-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientForm.cs
More file actions
107 lines (101 loc) · 3.49 KB
/
Copy pathClientForm.cs
File metadata and controls
107 lines (101 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lab1
{
public partial class ClientForm : Form
{
private ClientManager clientManager;
public ClientForm()
{
clientManager = new ClientManager();
InitializeComponent();
}
private void ClientForm_Load(object sender, EventArgs e)
{
UpdateClientsList();
}
private void UpdateClientsList()
{
clientsListBox.Items.Clear();
foreach (var client in clientManager.Clients)
{
clientsListBox.Items.Add($"{client.Name} - {client.Email} ({client.Phone})");
}
}
private void AddClientButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(nameTextBox.Text) || string.IsNullOrEmpty(emailTextBox.Text)
|| string.IsNullOrEmpty(phoneTextBox.Text) || string.IsNullOrEmpty(addressTextBox.Text))
{
MessageBox.Show("Заполните все поля!");
return;
}
Client newClient = new Client(nameTextBox.Text, emailTextBox.Text,
phoneTextBox.Text, addressTextBox.Text);
try
{
clientManager.AddClient(newClient);
nameTextBox.Clear();
emailTextBox.Clear();
phoneTextBox.Clear();
addressTextBox.Clear();
UpdateClientsList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void RemoveClientButton_Click(object sender, EventArgs e)
{
if (clientsListBox.SelectedIndex == -1)
{
MessageBox.Show("Выберите клиента для удаления!");
return;
}
string selectedItem = clientsListBox.SelectedItem.ToString();
string[] parts = selectedItem.Split(new[] { '-' }, StringSplitOptions.None);
if (parts.Length >= 2)
{
string name = parts[0].Trim();
string email = parts[1].Trim();
/* email = email.Remove(email.IndexOf(" "));*/
var clientToRemove = clientManager.Clients.Find(c => c.Name == name && c.Email + " (" + c.Phone + ")"
== email);
if (clientToRemove != null)
{
try
{
clientManager.RemoveClient(clientToRemove);
UpdateClientsList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
private void SearchButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(searchTextBox.Text))
{
UpdateClientsList();
return;
}
var searchResults = clientManager.SearchClients(searchTextBox.Text);
clientsListBox.Items.Clear();
foreach (var client in searchResults)
{
clientsListBox.Items.Add($"{client.Name} - {client.Email} ({client.Phone})");
}
}
}
}