-
Notifications
You must be signed in to change notification settings - Fork 0
/
CategoryForm.cs
190 lines (174 loc) · 6.95 KB
/
CategoryForm.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
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.SqlClient;
namespace MIni_market_Managment_System
{
public partial class CategoryForm : Form
{
DBConnect dbConnect = new DBConnect();
public CategoryForm()
{
InitializeComponent();
}
private void CategoryForm_Load(object sender, EventArgs e)
{
getTable();
}
private void label_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void label_exit_MouseEnter(object sender, EventArgs e)
{
label_exit.ForeColor = Color.Red;
}
private void label_exit_MouseLeave(object sender, EventArgs e)
{
label_exit.ForeColor = Color.Sienna;
}
private void button_product_Click(object sender, EventArgs e)
{
ProductForm productForm = new ProductForm();
productForm.Show();
this.Hide();
}
private void button_logout_MouseEnter(object sender, EventArgs e)
{
button_logout.ForeColor = Color.Red;
}
private void button_logout_MouseLeave(object sender, EventArgs e)
{
button_logout.ForeColor = Color.Sienna;
}
private void button_logout_Click(object sender, EventArgs e)
{
LoginForm loginForm = new LoginForm();
loginForm.Show();
this.Hide();
}
private void getTable()
{
string selectQuerry = "SELECT * FROM Category";
SqlCommand command=new SqlCommand(selectQuerry,dbConnect.GetCon());
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
dataGridView_category.DataSource = table;
}
private void button_add_Click(object sender, EventArgs e)
{
try
{
if (textBox_id.Text == "" || textBox_name.Text == "" || textBox_descript.Text == "")
{
MessageBox.Show("Missing Information", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string insertQuery = "INSERT INTO Category VALUES (" + textBox_id.Text + ",'" + textBox_name.Text + "','" + textBox_descript.Text + "')";
SqlCommand command = new SqlCommand(insertQuery, dbConnect.GetCon());
dbConnect.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Category Added Successfully", "Add Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dbConnect.CloseCon();
clear();
getTable();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button_update_Click(object sender, EventArgs e)
{
try
{
if (textBox_id.Text == "" || textBox_name.Text == "" || textBox_descript.Text == "")
{
MessageBox.Show("Missing Information", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string updateQuery = "UPDATE Category SET CatName='" + textBox_name.Text + "', CatDesc='" + textBox_descript.Text + "'WHERE CatId=" + textBox_id.Text + "";
SqlCommand command = new SqlCommand(updateQuery, dbConnect.GetCon());
dbConnect.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Category Updated Successfully", "Update Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dbConnect.CloseCon();
clear();
getTable();
}
}
catch(Exception ex )
{
MessageBox.Show(ex.Message );
}
}
private void dataGridView_category_Click(object sender, EventArgs e)
{
textBox_id.Text = dataGridView_category.SelectedRows[0].Cells[0].Value.ToString();
textBox_name.Text = dataGridView_category.SelectedRows[0].Cells[1].Value.ToString();
textBox_descript.Text = dataGridView_category.SelectedRows[0].Cells[2].Value.ToString();
}
private void clear()
{
textBox_id.Clear();
textBox_name.Clear();
textBox_descript.Clear();
}
private void button_delete_Click(object sender, EventArgs e)
{
try
{
if (textBox_id.Text == "")
{
MessageBox.Show("Missing Information", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if ((MessageBox.Show("Are you sure you want to delete this record?", "Delete record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
{
string deleteQuery = "DELETE FROM Category WHERE CatId=" + textBox_id.Text + "";
SqlCommand command = new SqlCommand(deleteQuery, dbConnect.GetCon());
dbConnect.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Category Deleted Successfully", "Delete Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dbConnect.CloseCon();
clear();
getTable();
}
}
}
catch( Exception ex )
{
MessageBox.Show(ex.Message);
}
}
private void button_seller_Click(object sender, EventArgs e)
{
SellerForm form = new SellerForm();
form.Show();
this.Hide();
}
private void button_selling_Click(object sender, EventArgs e)
{
SellingForm form = new SellingForm();
form.Show();
this.Hide();
}
private void dataGridView_category_Click_1(object sender, EventArgs e)
{
textBox_id.Text = dataGridView_category.SelectedRows[0].Cells[0].Value.ToString();
textBox_name.Text = dataGridView_category.SelectedRows[0].Cells[1].Value.ToString();
textBox_descript.Text= dataGridView_category.SelectedRows[0].Cells[2].Value.ToString();
}
}
}