-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductsuc.cs
170 lines (148 loc) · 5.83 KB
/
productsuc.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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 ProductsUC : UserControl
{
DBSQLProducts productSQL;
DBSQLSupplier supplierSQL;
public ProductsUC()
{
InitializeComponent();
}
private void ProductsUC_Load(object sender, EventArgs e)
{
//Directory of Microsoft Access file
string dbPath = Application.StartupPath + @"\..\..\ProjectDB.accdb";
productSQL = new DBSQLProducts(@"Provider=microsoft.ACE.OLEDB.12.0;dATA Source=" + dbPath + "; Persist Security Info=False;");
supplierSQL = new DBSQLSupplier(@"Provider=microsoft.ACE.OLEDB.12.0;dATA Source=" + dbPath + "; Persist Security Info=False;");
//supplier & Products array to get data from database
Products[] proudctArr;
Supplier[] supplierArr;
proudctArr = productSQL.GetProductId();
supplierArr = supplierSQL.GetSupplierId();
for (int i = 0; i < proudctArr.Length; i++)
cmbProductIddel.Items.Add(proudctArr[i].ID);
for (int i = 0; i < proudctArr.Length; i++)
cmbProductIdedit.Items.Add(proudctArr[i].ID);
for (int i = 0; i < supplierArr.Length; i++)
{
cmbSupplierID.Items.Add(supplierArr[i].ID);
cmbSupplierIDedit.Items.Add(supplierArr[i].ID);
}
}
private void AddProductBTN_Click(object sender, EventArgs e)//Adding new product to database
{
Products product = new Products();
int id;
if (int.TryParse(ProductID.Text, out id) == true)
product.ID = int.Parse(ProductID.Text);
else
{
MessageBox.Show("Incorrect Input", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
product.Name = ProductName.Text;
product.Amount = (int)ProductAmount.Value;
product.Description = ProductDesc.Text;
double price = (double)ProductPrice.Value;
int SupplierID = int.Parse(cmbSupplierID.Text);
try
{
productSQL.InsertProduct(product);
productSQL.InsertSupplierProduct(product.ID, SupplierID, price);
MessageBox.Show("Product has been added successfully!", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void editProductBTN_Click(object sender, EventArgs e)//Editing product and updating it on database
{
Products product = new Products();
product.ID = int.Parse(cmbProductIdedit.Text);
product.Name = ProductNewName.Text;
product.Amount = (int)ProductAmountedit.Value;
product.Description = ProductDescedit.Text;
try
{
productSQL.UpdateProduct(product);
productSQL.updateProductSupplier(int.Parse(cmbSupplierIDedit.Text), product.ID, (int)ProductPriceedit.Value);
MessageBox.Show("Product has been updated successfully!", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void DeleteProductBTN_Click(object sender, EventArgs e)//Deletes the product from database
{
Products product = new Products();
product.ID = int.Parse(cmbProductIddel.Text);
try
{
productSQL.DeleteProduct(product.ID);
MessageBox.Show("Product has been removed!", "Mona Computers",
MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbProductIddel.Items.Remove(product.ID);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ProductID_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
private void ProductName_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
private void ProductDesc_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
}
}
private void ProductNewName_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
private void ProductDescedit_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}