-
Notifications
You must be signed in to change notification settings - Fork 0
/
Category.cs
124 lines (100 loc) · 3.42 KB
/
Category.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
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 InventoryManagement
{
public partial class Category : UserControl
{
inventoryDataContext idc = new inventoryDataContext(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\FASHAKINALEALEXANDER\Documents\FProjects\InventoryManagementSystem-master\InventoryManagement\InventoryManagement\inventory_management.mdf;Integrated Security=True");
private string name = "";
private static Category _instance;
public static Category Instance
{
get
{
if (_instance == null)
_instance = new Category();
return _instance;
}
}
public Category()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
public void refresh()
{
txtCatName.Text = "";
lblError.Text = "";
}
private void btnSearchCat_Click(object sender, EventArgs e)
{
}
private void btnAddCat_Click(object sender, EventArgs e)
{
name = tbCat.Text.ToString();
category c = new category();
c.cat_title = name;
if (!name.Equals("") )
{
idc.categories.InsertOnSubmit(c);
idc.SubmitChanges();
MessageBox.Show("Successfully Added a category.");
}
else
{
lblError.Text = "Please fill all the fields.";
}
}
private void Category_Load(object sender, EventArgs e)
{
var proTable = from q in idc.categories select q;
gridCategory.DataSource = proTable;
}
private void btnUpdateCat_Click(object sender, EventArgs e)
{
if (gridCategory.SelectedCells[0].Value != null)
{
if (!tbCat.Text.Equals(""))
{
int id = Convert.ToInt32(gridCategory.SelectedCells[0].Value.ToString());
category br = idc.categories.SingleOrDefault(x => x.cat_id == id);
br.cat_title = tbCat.Text;
idc.SubmitChanges();
MessageBox.Show("Successfully updated a category.");
}
else
{
lblError.Text = "Enter a name to proceed.";
}
}
else
{
lblError.Text = "Please select a row to update.";
}
}
private void btnDeleteCategory_Click(object sender, EventArgs e)
{
if (gridCategory.SelectedCells[0].Value != null)
{
int id = Convert.ToInt32(gridCategory.SelectedCells[0].Value.ToString());
category br = idc.categories.SingleOrDefault(x => x.cat_id == id);
idc.categories.DeleteOnSubmit(br);
idc.SubmitChanges();
MessageBox.Show("Successfully deleted a category.");
}
else
{
lblError.Text = "Please select a row to delete.";
}
}
}
}