-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomersuc.cs
155 lines (133 loc) · 5.03 KB
/
customersuc.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FinalProject
{
public partial class CustomersUC : UserControl
{
DBSQLCustomer customerSQL;
public CustomersUC()
{
InitializeComponent();
}
private void AddCustomerBtn_Click(object sender, EventArgs e)
{
Customer customer = new Customer();
int id; //To check if the new id does not exists
if (int.TryParse(CustomerID.Text, out id) == true) //If the id doesn't exists, then it'll be added
customer.ID = int.Parse(CustomerID.Text);
else
{
MessageBox.Show("ID Already exists!", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
customer.Name = CustomerName.Text;
customer.phone = CustomerPhone.Text;
customer.City = CustomerCity.Text;
try
{
customerSQL.InsertCustomer(customer);
MessageBox.Show("Customer has been added successfuly!", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void CustomersUC_Load(object sender, EventArgs e)
{
string dbPath = Application.StartupPath + @"\..\..\ProjectDB.accdb";
customerSQL = new DBSQLCustomer(@"Provider=microsoft.ACE.OLEDB.12.0;dATA Source=" + dbPath + "; Persist Security Info=False;");
//Array to add the customers to database
Customer[] customerArr;
customerArr = customerSQL.GetCustomerId();
for (int i = 0; i < customerArr.Length; i++)
{
txtbCustomerID.Items.Add(customerArr[i].ID);
txtbCustomerIdDel.Items.Add(customerArr[i].ID);
}
}
//Editing customer that already exists
private void EditCustomerBtn_Click(object sender, EventArgs e)
{
Customer customer = new Customer();
customer.ID = int.Parse(txtbCustomerID.Text);
customer.Name = EditCustomerName.Text;
customer.phone = EditCustomerPhone.Text;
customer.City = EditCustomerCity.Text;
try
{
customerSQL.UpdateCustomer(customer);
MessageBox.Show("Customer has been updated successfully", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//Removing customer from DB
private void DeleteCustomerBTN_Click(object sender, EventArgs e)
{
Customer customer = new Customer();
customer.ID = int.Parse(txtbCustomerIdDel.Text);
try
{
customerSQL.DeleteCustomer(customer.ID); //Deletes customer from DBSQLCustomer
MessageBox.Show("Customer has been successfully removed", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
txtbCustomerIdDel.Items.Remove(customer.ID);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void cmbCustomerIddel_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void CustomerID_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
private void CustomerCity_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
private void EditCustomerCity_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
private void EditCustomerName_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
private void CustomerName_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
}
}