-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathInventoryForm.cs
154 lines (131 loc) · 5.13 KB
/
InventoryForm.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
using System.Drawing;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
namespace shopManager
{
public partial class InventoryForm : Form
{
private static InventoryForm instance;
public static InventoryForm Instance
{
get
{
if (instance == null || instance.IsDisposed)
{
instance = new InventoryForm();
}
return instance;
}
}
public static StackDataList dataList;
private InventoryForm()
{
InitializeComponent();
dataList = new StackDataList();
// Ensure that the entire application is closed when MyForm is closed
this.FormClosed += (sender, e) => Application.Exit();
}
private void addProdButton_Click(object sender, EventArgs e)
{
AddProductForm addProduct = new AddProductForm();
addProduct.ShowDialog();
}
public void LoadProductsToDataGridView()
{
// Clear existing data
dataGridView.Rows.Clear();
// Get all products from the stack
List<Product> products = dataList.GetAllProducts();
for (int i = 0; i < products.Count(); i++)
{
dataGridView.Rows.Add(products[i].Name, products[i].ID, products[i].Category, products[i].Quantity, products[i].TotalPrice() + "$", "Edit", "Delete");
if (products[i].Category == "Phones")
{
dataGridView.Rows[i].Cells[2].Style.BackColor = Color.Red;
}
else if (products[i].Category == "Cameras")
{
dataGridView.Rows[i].Cells[2].Style.BackColor = Color.DarkGreen;
}
else
{
dataGridView.Rows[i].Cells[2].Style.BackColor = Color.DarkBlue;
}
}
}
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs dataGrid)
{
if (dataGrid.RowIndex >= 0)
{
int columnIndex = dataGrid.ColumnIndex;
int rowIndex = dataGrid.RowIndex;
// Check if the "Sell" button is clicked
if (columnIndex == dataGridView.Columns["Column6"].Index)
{
string prodId = dataGridView.Rows[rowIndex].Cells[1].Value.ToString();
int id = int.Parse(prodId);
SellProductForm sellProduct = new SellProductForm(id, 'S');
sellProduct.ShowDialog();
}
// Check if the "Delete" button is clicked
else if (columnIndex == dataGridView.Columns["Column7"].Index)
{
string prodId = dataGridView.Rows[rowIndex].Cells[1].Value.ToString();
dataList.RemovedSpesProduct(int.Parse(prodId));
LoadProductsToDataGridView();
}
}
}
private void UpdateDataGridViewWithProduct(Product product)
{
// Clear existing data
dataGridView.Rows.Clear();
// Update UI with the retrieved product information
dataGridView.Rows.Add(product.Name, product.ID, product.Category, product.Quantity, product.TotalPrice() + "$", "Edit", "Delete");
}
private void cancelSearchButton_Click(object sender, EventArgs e)
{
searchTextBox.Text = "";
LoadProductsToDataGridView();
}
private void home2Button_Click(object sender, EventArgs e)
{
HomepageForm home = new HomepageForm();
this.Hide();
home.Show();
}
private void searchIcon_Click_1(object sender, EventArgs e)
{
string proID = searchTextBox.Text;
if (int.TryParse(proID, out int id))
{
if (id >= 1111110)
{
Product wantedProd = dataList.GetSpecificProductById(id);
if (wantedProd != null)
{
UpdateDataGridViewWithProduct(wantedProd);
}
else
{
MessageBox.Show($"Product with ID {id} not found.", "Product Not Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("Please enter a valid product ID.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("Please enter a valid numeric product ID.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void InventoryForm_Load(object sender, EventArgs e)
{
dataGridView.CellContentClick += dataGridView_CellContentClick;
// Load existing products into dataGridView
LoadProductsToDataGridView();
}
}
}