-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brands.cs
117 lines (97 loc) · 3.31 KB
/
Brands.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
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 Brands : 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 Brands _instance;
public static Brands Instance
{
get
{
if (_instance == null)
_instance = new Brands();
return _instance;
}
}
public void refresh()
{
txtBrandName.Text = "";
lblError.Text = "";
}
public Brands()
{
InitializeComponent();
}
private void btnAddBrand_Click(object sender, EventArgs e)
{
name = tbBrands.Text.ToString();
brand b = new brand();
b.brand_title = name;
if (!name.Equals("") )
{
idc.brands.InsertOnSubmit(b);
idc.SubmitChanges();
MessageBox.Show("Successfully Added a brand.");
}
else
{
lblError.Text = "Please fill all the fields.";
}
}
private void tbBrands_TextChanged(object sender, EventArgs e)
{
}
private void Brands_Load(object sender, EventArgs e)
{
var proTable = from q in idc.brands select q;
gridBrand.DataSource = proTable;
}
private void btnUpdateBrand_Click(object sender, EventArgs e)
{
if (gridBrand.SelectedCells[0].Value != null)
{
if(!tbBrands.Text.Equals(""))
{
int id = Convert.ToInt32(gridBrand.SelectedCells[0].Value.ToString());
brand br = idc.brands.SingleOrDefault(x => x.brand_id == id);
br.brand_title = tbBrands.Text;
idc.SubmitChanges();
MessageBox.Show("Successfully updated a brand.");
}
else
{
lblError.Text = "Enter a name to proceed.";
}
}
else
{
lblError.Text = "Please select a row to update.";
}
}
private void btnDeleteBrands_Click(object sender, EventArgs e)
{
if (gridBrand.SelectedCells[0].Value != null)
{
int id = Convert.ToInt32(gridBrand.SelectedCells[0].Value.ToString());
brand br = idc.brands.SingleOrDefault(x => x.brand_id == id);
idc.brands.DeleteOnSubmit(br);
idc.SubmitChanges();
MessageBox.Show("Successfully deleted a brand.");
}
else
{
lblError.Text = "Please select a row to delete.";
}
}
}
}