-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathClientChooseForm.cs
92 lines (71 loc) · 2.36 KB
/
ClientChooseForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DvizhSeller
{
public partial class ClientChooseForm : Form
{
CashierForm cashierForm;
services.Database db = new services.Database();
repositories.Client clients;
services.DataMapper dataMapper;
public ClientChooseForm(CashierForm setCashierForm)
{
cashierForm = setCashierForm;
clients = new repositories.Client(db);
dataMapper = new services.DataMapper(db);
dataMapper.FillClients(clients);
InitializeComponent();
}
private void ClientsForm_Load(object sender, EventArgs e)
{
RenderClients(clients.GetList());
}
private void RenderClients(List<entities.Client> products)
{
clientsListView.Items.Clear();
foreach (entities.Client client in products)
{
Item item = new Item(client.GetName(), client.GetId());
dynamic row = clientsListView.Items.Add(client.GetName());
row.Tag = item.Value;
int index = row.Index;
clientsListView.Items[index].SubItems.Add(client.GetPhone().ToString());
}
}
private class Item
{
public string Name;
public int Value;
public Item(string name, int value)
{
Name = name; Value = value;
}
public override string ToString()
{
return Name;
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (searchBox.Text == "")
RenderClients(clients.GetList());
else
RenderClients(clients.FindByString(searchBox.Text));
}
private void clientsListView_DoubleClick(object sender, EventArgs e)
{
foreach (ListViewItem item in clientsListView.SelectedItems)
{
entities.Client client = clients.FindOne(Convert.ToInt32(item.Tag));
cashierForm.ChooseClient(client.GetId(), client.GetName());
}
this.Close();
}
}
}