Skip to content

Commit

Permalink
feat(Product):
Browse files Browse the repository at this point in the history
Create Product UI Add Edit Remove
ref #4
  • Loading branch information
Hibino02 committed May 5, 2024
1 parent ecadd93 commit c754780
Show file tree
Hide file tree
Showing 16 changed files with 1,047 additions and 6 deletions.
13 changes: 11 additions & 2 deletions View/Dimensions/DimensionSource/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,16 @@ private void AttemptAdd()
conversionFailed = false;
return;
}
string selectedUnitOfDimension = unitOfVolumeListBox.SelectedItem.ToString();
unitOfDimensionName = new UnitOfDimension(selectedUnitOfDimension);
if (unitOfVolumeListBox.SelectedItem != null)
{
string selectedUnitOfDimension = unitOfVolumeListBox.SelectedItem.ToString();
unitOfDimensionName = new UnitOfDimension(selectedUnitOfDimension);
}
else
{
MessageBox.Show("Please select Unit of Volume");
return;
}
add = new WHIO.Model.Dimension(width, length, height, unitOfDimensionName,name);
if (add.Create())
{
Expand All @@ -90,6 +98,7 @@ private void AttemptAdd()
Close();
}
else MessageBox.Show(this, "Create Fail");
return;
}

private double convertToDouble(string text)
Expand Down
1 change: 1 addition & 0 deletions View/MainForm.Designer.cs

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

12 changes: 12 additions & 0 deletions View/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Warehouse_IO.View;
using Warehouse_IO.View.Dimension.UnitOfVolumeSource;
using Warehouse_IO.View.Dimensions.DimensionSource;
using Warehouse_IO.View.ProductSource;
using Warehouse_IO.View.SupplierFormSource;
using Warehouse_IO.View.TruckFormSource;
using Warehouse_IO.View.UOMSource;
Expand All @@ -25,6 +26,7 @@ public partial class MainForm : Form
PackagingForm pack;
UOMForm uom;
DimensionsForm dimension;
ProductForm product;

public MainForm()
{
Expand Down Expand Up @@ -176,5 +178,15 @@ private void click_Dimension(object sender, EventArgs e)
DisableMainForm();
dimension.returnMain += EventToActiveAdmin;
}

private void click_Product(object sender, EventArgs e)
{
product = new ProductForm();
product.MdiParent = this;
product.Show();

DisableMainForm();
product.returnMain += EventToActiveAdmin;
}
}
}
56 changes: 56 additions & 0 deletions View/ProductSource/Add.Designer.cs

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

112 changes: 112 additions & 0 deletions View/ProductSource/Add.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Warehouse_IO.WHIO.Model;
using Warehouse_IO.View.Add_Edit_Remove_Components;
using System;
using System.Windows.Forms;
using System.Collections.Generic;

namespace Warehouse_IO.View.ProductSource
{
public partial class Add : AddEditProductForm
{
Product add;
UOM uom;
Warehouse_IO.WHIO.Model.Dimension dimension;
List<UOM> uomList;
List<Warehouse_IO.WHIO.Model.Dimension> dimensionList;
private List<int> dimensionId = new List<int>();
private List<int> uomId = new List<int>();

public event EventHandler UpdateGrid;

public Add()
{
InitializeComponent();
nameTextBox.KeyPress += AddButton_KeyPress;
UoMListBox.KeyPress += AddButton_KeyPress;
dimensionListBox.KeyPress += AddButton_KeyPress;

dimensionList = new List<Warehouse_IO.WHIO.Model.Dimension>();
uomList = new List<UOM>();
updateList();
}

private void updateList()
{
dimensionList = Warehouse_IO.WHIO.Model.Dimension.GetDimensionList();
uomList = UOM.GetUOMList();
dimensionList.Sort((x, y) => x.Name.CompareTo(y.Name));
uomList.Sort((x, y) => x.Name.CompareTo(y.Name));

UoMListBox.Items.Clear();
dimensionListBox.Items.Clear();

foreach (Warehouse_IO.WHIO.Model.Dimension dimension in dimensionList)
{
string formattedDimension = $"{dimension.Width} x {dimension.Length} x {dimension.Height} {dimension.Unit.Name} {dimension.Name}";
dimensionListBox.Items.Add(formattedDimension);
dimensionId.Add(dimension.ID);
}
foreach (UOM uom in uomList)
{
string formattedDimension = $"{uom.Quantity}{uom.Unit.Name}/{uom.Package.Name} {uom.Name}";
UoMListBox.Items.Add(formattedDimension);
uomId.Add(uom.ID);
}
}

private void AttemptAdd()
{
if (string.IsNullOrEmpty(nameTextBox.Text))
{
MessageBox.Show(this, "Please enter a product name.");
return;
}
int selectedUOMIndex = UoMListBox.SelectedIndex;
if (selectedUOMIndex >= 0 && selectedUOMIndex < uomId.Count)
{
int selectedUOMID = uomId[selectedUOMIndex];
uom = new UOM(selectedUOMID);
}
else
{
MessageBox.Show(this, "Please select UOM");
return;
}
int selectedDimensionIndex = dimensionListBox.SelectedIndex;
if (selectedDimensionIndex >= 0 && selectedDimensionIndex < dimensionId.Count)
{
int selectedDimensionID = dimensionId[selectedDimensionIndex];
dimension = new Warehouse_IO.WHIO.Model.Dimension(selectedDimensionID);
}
else
{
MessageBox.Show(this, "Please select Dimension");
return;
}
add = new Product(nameTextBox.Text,uom,dimension);
if (add.Create())
{
MessageBox.Show(this, "Product Create");
UpdateGrid?.Invoke(this, EventArgs.Empty);
Close();
}
else MessageBox.Show(this, "Create Fail");
}

private void AddButton_Click(object sender, EventArgs e)
{
AttemptAdd();
}
private void AddButton_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
AttemptAdd();
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
Close();
}
}
}
120 changes: 120 additions & 0 deletions View/ProductSource/Add.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading

0 comments on commit c754780

Please sign in to comment.