-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProducts.cs
235 lines (194 loc) · 7.96 KB
/
Products.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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;
using System.Data.Sql;
using System.Data.SqlClient;
namespace Varsity_Phamarcy
{
public partial class Products1 : Form
{
//private string categoryID;
Suppliers suppliers1 = new Suppliers();
string Id;
string status;
public int Quant;
public Products1()
{
InitializeComponent();
}
private void Products_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Products' table. You can move, or remove it, as needed.
this.productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
// TODO: This line of code loads data into the 'varsityPharmacyDataSet.Products' table. You can move, or remove it, as needed.
this.productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Do You Want To Update Product ?", "Confirmation", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
try
{
if (radioButton1.Checked == true)
{
status = "Available";
}
else
{
status = "Unavailable";
}
productsTableAdapter.UpdateQuery(productName.Text, Convert.ToInt32(productQuantity.Text), Convert.ToDecimal(productSale.Text), Convert.ToDecimal(productCost.Text), status, productCategory.Text, Int32.Parse(productID.Text), Int32.Parse(productID.Text));
productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
productID.Text = "";
productName.Text = "";
productQuantity.Text = "";
productCost.Text = "";
productSale.Text = "";
productCategory.Text = "";
radioButton1.Checked = false;
radioButton2.Checked = false;
MessageBox.Show("Updated");
}
catch
{
MessageBox.Show("Error While Updating");
}
}
else if (result == DialogResult.No)
{
MessageBox.Show("Canceled To Update Product!");
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Do You Want To Add New Product ?", "Confirmation", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
try
{
productsTableAdapter.InsertQuery(productName.Text, Convert.ToInt32(productQuantity.Text) + Quant, Convert.ToDecimal(productSale.Text), Convert.ToDecimal(productCost.Text), status, productCategory.Text);
productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
productID.Text = "";
productName.Text = "";
productQuantity.Text = "";
productCost.Text = "";
productSale.Text = "";
productCategory.Text = "";
radioButton1.Checked = false;
radioButton2.Checked = false;
MessageBox.Show("Products Is Added Successfully!");
}
catch
{
MessageBox.Show("Error While Adding Product!");
}
}
else if (result == DialogResult.No)
{
MessageBox.Show("Canceled To Add New Product!");
}
}
private void btnHome_Click(object sender, EventArgs e)
{
MainMenu menu = new MainMenu();
this.Hide();
menu.Show();
}
private void btnClear_Click(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
productID.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
Id = dataGridView1.CurrentRow.Cells[0].Value.ToString();
productName.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
productCost.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
productQuantity.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
productSale.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
productCategory.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
status = dataGridView1.CurrentRow.Cells[5].Value.ToString();
if (status.Equals("Available")){
radioButton1.Checked = true;
radioButton2.Checked = false;
}else if (status.Equals("Unavailable"))
{
radioButton2.Checked = true;
radioButton1.Checked = false;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
searchBox.ReadOnly = false;
searchBox.Visible = true;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
searchBox.ReadOnly = false;
searchBox.Visible = true;
}
private void searchBox_TextChanged(object sender, EventArgs e)
{
String name = "%" + searchBox.Text + "%";
this.productsTableAdapter.FillBy(this.varsityPharmacyDataSet.Products, name);
}
private void radioButton1_CheckedChanged_1(object sender, EventArgs e)
{
radioButton1.Text = "Available";
}
private void radioButton2_CheckedChanged_1(object sender, EventArgs e)
{
radioButton2.Text = "Unavailable";
}
private void button1_Click_1(object sender, EventArgs e)
{
}
private void button1_Click_2(object sender, EventArgs e)
{
Suppliers suppliers = new Suppliers();
this.Hide();
suppliers.Show();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button2_Click_1(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Do You Want To Delete a Product ?", "Confirmation", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
try
{
productsTableAdapter.DeleteQuery(Convert.ToInt32(Id));
productsTableAdapter.Fill(this.varsityPharmacyDataSet.Products);
productID.Text = "";
productName.Text = "";
productQuantity.Text = "";
productCost.Text = "";
productSale.Text = "";
productCategory.Text = "";
radioButton1.Checked = false;
radioButton2.Checked = false;
MessageBox.Show("Product Deleted Successfully!");
}
catch
{
MessageBox.Show("Error While Deleting Products!");
}
}
else if (result == DialogResult.No)
{
MessageBox.Show("Canceled To Delete Product!");
}
}
}
}