Skip to content

Commit

Permalink
feat: Creat Search Box in Product Group Inbound & Outbound window
Browse files Browse the repository at this point in the history
ref #4
  • Loading branch information
Hibino02 committed May 13, 2024
1 parent 79e6261 commit 96761ae
Show file tree
Hide file tree
Showing 24 changed files with 349 additions and 117 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions View/Add,Edit,Remove Components/AddEdit_Outbound_Form.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions View/Dimensions/DimensionSource/DimensionsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void UpdateDatagridView()
{
list = Warehouse_IO.WHIO.Model.Dimension.GetDimensionList();
bind.DataSource = list;
list.Sort((x, y) => x.ID.CompareTo(y.ID));
list.Sort((x, y) => x.GetM3().CompareTo(y.GetM3()));
dataGridView.DataSource = bind;

dataGridView.CellFormatting += DataGridView_CellFormatting;
Expand All @@ -45,11 +45,11 @@ private void DataGridView_CellFormatting(object sender, DataGridViewCellFormatti
{
if (dataGridView.Rows[e.RowIndex].DataBoundItem != null)
{
Warehouse_IO.WHIO.Model.Dimension uom = (Warehouse_IO.WHIO.Model.Dimension)dataGridView.Rows[e.RowIndex].DataBoundItem;
Warehouse_IO.WHIO.Model.Dimension dimension = (Warehouse_IO.WHIO.Model.Dimension)dataGridView.Rows[e.RowIndex].DataBoundItem;

if (e.ColumnIndex == 5)
{
e.Value = uom.Unit.Name;
e.Value = dimension.GetM3();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions View/InboundSource/AddV2.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 54 additions & 14 deletions View/InboundSource/AddV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using MySql.Data.MySqlClient;
using Warehouse_IO.WHIO.Model;
using Warehouse_IO.View.Add_Edit_Remove_Components;
using System.Linq;
using Warehouse_IO.Common;

namespace Warehouse_IO.View.InboundSource
{
Expand All @@ -24,7 +26,9 @@ public partial class AddV2 : AddEdit_Inbound_Outbound_FormV2
private List<int> supplierID = new List<int>();
private List<int> truckID = new List<int>();
private List<int> storageID = new List<int>();
private List<int> productID = new List<int>();

//Variable for tracking product after filtered
private readonly Dictionary<string, Product> productNameToProduct = new Dictionary<string, Product>();

//Variable for create selected object on CreateNewShipment()
Supplier supplier;
Expand Down Expand Up @@ -76,7 +80,7 @@ private void updateComponent()
}

truckList = Truck.GetTruckList();
truckList.Sort((x, y) => x.Name.CompareTo(y.Name));
truckList.Sort((x, y) => x.Description.CompareTo(y.Description));
truckListBox.Items.Clear();
foreach (Truck truck in truckList)
{
Expand All @@ -98,8 +102,10 @@ private void updateComponent()
productListBox.Items.Clear();
foreach (Product product in productList)
{
productListBox.Items.Add(product.Name);
productID.Add(product.ID);
string displayedName = product.Name;
productListBox.Items.Add(displayedName);

productNameToProduct[displayedName] = product;
}
}

Expand Down Expand Up @@ -128,6 +134,7 @@ private void UpdateProductGridView()
datatable.Columns.Add("Name");
datatable.Columns.Add("Quantity", typeof(int));
datatable.Columns.Add("ID", typeof(int));
datatable.Columns.Add("M3", typeof(double));
foreach (KeyValuePair<Product, int> productGridlistEntry in newInbound.QuantityOfProductList)
{
Product product = productGridlistEntry.Key;
Expand All @@ -136,10 +143,24 @@ private void UpdateProductGridView()
row["Name"] = product.Name;
row["Quantity"] = quantity;
row["ID"] = product.ID;

Warehouse_IO.WHIO.Model.Dimension dimension = product.Dimension;
if (dimension != null)
{
double m3PerUnit = dimension.GetM3();
double totalM3PerItem = quantity * m3PerUnit;
row["M3"] = totalM3PerItem.ToString("0.00");
}
else
{
row["M3"] = "0.00";
}
datatable.Rows.Add(row);
}
datatable.DefaultView.Sort = "Name ASC";
datatable.DefaultView.Sort = "M3 DESC";
productListDatagridView.DataSource = datatable.DefaultView;

productListDatagridView.Columns["ID"].Visible = false;
}

//Create new shipment
Expand Down Expand Up @@ -318,23 +339,25 @@ private void removeTruckButton_Click(object sender, EventArgs e)
//Add product to shipment
private void AddProductToShipment()
{
if (productListBox.SelectedItem != null)
if (productListBox.SelectedIndex >= 0)
{
int selectedProductIndex = productListBox.SelectedIndex;
if (selectedProductIndex >= 0 && selectedProductIndex < productID.Count)
string selectedName = (string)productListBox.SelectedItem;
if (productNameToProduct.ContainsKey(selectedName))
{
int selectedProductID = productID[selectedProductIndex];
product = new WHIO.Model.Product(selectedProductID);
Product selectedProduct = productNameToProduct[selectedName];
int selectedProductID = selectedProduct.ID;

product = new Product(selectedProductID);
if (!newInbound.QuantityOfProductList.ContainsKey(product))
{
int quantity = int.Parse(productQuantityTextBox.Text);
newInbound.AddProduct(product, quantity);
double kgs = double.Parse(productQuantityTextBox.Text);
int kgsToQuantity = product.GetQuantity(kgs);
newInbound.AddProduct(product, kgsToQuantity);
productQuantityTextBox.Text = "";
UpdateProductGridView();
}
else MessageBox.Show(this, "Same product is added");
}
}
}
}
private void addProductButton_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -373,9 +396,10 @@ private void EditProductQuantity()
if (productListDatagridView.SelectedRows.Count > 0)
{
editQuantity.Owner = main;

Global.tempPkey = -1;
DataGridViewRow selectedRow = productListDatagridView.CurrentRow;
int id = Convert.ToInt32(selectedRow.Cells[2].Value);
Global.tempPkey = id;

editQuantity.ShowDialog();

Expand Down Expand Up @@ -448,5 +472,21 @@ private void cancelButton_Click(object sender, EventArgs e)
{
CheckAllThings();
}

//Searching product algorithm
private void productNameSearchTextBox_TextChanged(object sender, EventArgs e)
{
string searchText = productNameSearchTextBox.Text.ToLower();

productListBox.Items.Clear();

foreach(Product item in productList)
{
if (item.Name.ToLower().Contains(searchText))
{
productListBox.Items.Add(item.Name);
}
}
}
}
}
15 changes: 8 additions & 7 deletions View/InboundSource/EditQuantityWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows.Forms;
using Warehouse_IO.Common;
using Warehouse_IO.WHIO.Model;

namespace Warehouse_IO.View.InboundSource
{
Expand All @@ -12,14 +14,13 @@ public EditQuantityWindow()
}
private void EditQuantity()
{
string qty = EditTextBox.Text;
if (int.TryParse(qty, out editQty))
double qty = double.Parse(EditTextBox.Text);
if (qty > 0)
{
if (editQty > 0)
{
EditTextBox.Text = "";
Close();
}
Product product = new Product(Global.tempPkey);
editQty = product.GetQuantity(qty);
EditTextBox.Text = "";
Close();
}
else MessageBox.Show(this, "Need number more than 0");
}
Expand Down
7 changes: 7 additions & 0 deletions View/InboundSource/EditV2.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96761ae

Please sign in to comment.