Skip to content

Commit

Permalink
feat: Change product ID field from int to string for product name as …
Browse files Browse the repository at this point in the history
…PrimaryKey

#2
  • Loading branch information
Hibino02 committed May 14, 2024
1 parent 96761ae commit 1242e1c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion WHIO/Model/Inbound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void getquantityofproductlist()
{
while (reader.Read())
{
int product = Convert.ToInt32(reader["ProductID"]);
string product = reader["ProductID"].ToString();
Product item = new Product(product);
int qty = Convert.ToInt32(reader["Quantity"]);
QuantityOfProductList.Add(item, qty);
Expand Down
2 changes: 1 addition & 1 deletion WHIO/Model/Outbound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void getquantityofproductlist()
{
while (reader.Read())
{
int product = Convert.ToInt32(reader["ProductID"]);
string product = reader["ProductID"].ToString();
Product item = new Product(product);
int qty = Convert.ToInt32(reader["Quantity"]);
QuantityOfProductList.Add(item, qty);
Expand Down
16 changes: 9 additions & 7 deletions WHIO/Model/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Warehouse_IO.WHIO.Model
{
class Product
{
int id;
public int ID { get { return id; } }
string id;
public string ID { get { return id; }set { id = value; } }
string name;
public string Name { get { return name; }set { name = value; } }
UOM uom;
Expand All @@ -34,7 +34,7 @@ void CheckAndUpdateField(string columnName, string value)
{
if (reader.Read())
{
id = Convert.ToInt32(reader["ID"]);
id = reader["ID"].ToString();
name = reader["Name"].ToString();
uom = new UOM(Convert.ToInt32(reader["UOMID"]));
dimension = new Dimension(Convert.ToInt32(reader["DimensionID"]));
Expand All @@ -50,12 +50,13 @@ void CheckAndUpdateField(string columnName, string value)
}
}

public Product(int id)
public Product(string id)
{
CheckAndUpdateField("ID", id.ToString());
}
public Product(string name,UOM uom,Dimension dimension)
public Product(string id,string name,UOM uom,Dimension dimension)
{
this.id = id;
this.name = name;
this.uom = uom;
this.dimension = dimension;
Expand All @@ -70,8 +71,9 @@ public bool Create()
conn.Open();
using (var cmd = conn.CreateCommand())
{
string insert = "INSERT INTO product (ID, Name, UOMID, DimensionID) VALUES (NULL, @name, @uom, @dimension)";
string insert = "INSERT INTO product (ID, Name, UOMID, DimensionID) VALUES (@id, @name, @uom, @dimension)";
cmd.CommandText = insert;
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@uom", uom.ID);
cmd.Parameters.AddWithValue("@dimension", dimension.ID);
Expand Down Expand Up @@ -161,7 +163,7 @@ public static List<Product> GetProductList()
{
while (reader.Read())
{
int id = Convert.ToInt32(reader["ID"]);
string id = reader["ID"].ToString();
Product item = new Product(id);
productList.Add(item);
}
Expand Down
4 changes: 4 additions & 0 deletions WHIO/Model/Transport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public bool Equals(Product x, Product y)
}
public int GetHashCode(Product obj)
{
if (obj.ID == null)
{
return 0;
}
return obj.ID.GetHashCode();
}
}
Expand Down

0 comments on commit 1242e1c

Please sign in to comment.