Skip to content

Commit

Permalink
Added Inventory Exception Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ytpixelcowboy authored Oct 13, 2024
1 parent 66520a6 commit ed2b3a9
Show file tree
Hide file tree
Showing 39 changed files with 982 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Inventory/Inventory.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inventory", "Inventory\Inventory.csproj", "{4577FB12-6D99-4CAF-863A-38C6CE029D6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4577FB12-6D99-4CAF-863A-38C6CE029D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4577FB12-6D99-4CAF-863A-38C6CE029D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4577FB12-6D99-4CAF-863A-38C6CE029D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4577FB12-6D99-4CAF-863A-38C6CE029D6E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {73B855CE-4A89-4E67-8CDB-40178284917B}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions Inventory/Inventory/CurrencyFormatException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Inventory
{
public class CurrencyFormatException : Exception
{
public CurrencyFormatException(string currency) : base(currency) { }
}
}
244 changes: 244 additions & 0 deletions Inventory/Inventory/Form1.Designer.cs

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

100 changes: 100 additions & 0 deletions Inventory/Inventory/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Text.RegularExpressions;
using System.Xml.Linq;

namespace Inventory
{
public partial class frmAddProduct : Form
{
BindingSource showProductList;
private int _Quantity;
private double _SellPrice;
private string _ProductName, _Category, _MfgDate, _ExpDate, _Description;

public frmAddProduct()
{
InitializeComponent();
showProductList = new BindingSource();
}

private void label4_Click(object sender, EventArgs e)
{

}

private void frmAddProduct_Load(object sender, EventArgs e)
{
string[] ListOfProductCategory = new string[] {
"Beverages",
"Bread/Bakery",
"Canned/Jarred Goods",
"Dairy",
"Frozen Goods",
"Meat",
"Personal Care",
"Other"
};

foreach (string items in ListOfProductCategory)
{
cbCategory.Items.Add(items);

}
}

public string Product_Name(string name)
{
if (!Regex.IsMatch(name, @"^[a-zA-Z]+$"))
{
throw new StringFormatException("");
}

return name;
}
public int Quantity(string qty)
{
if (!Regex.IsMatch(qty, @"^[0-9]"))
{
throw new NumberFormatException("");
}

return Convert.ToInt32(qty);
}
public double SellingPrice(string price)
{
if (!Regex.IsMatch(price.ToString(), @"^(\d*\.)?\d+$"))
{
throw new CurrencyFormatException("");
}
return Convert.ToDouble(price);
}

private void btnAddProduct_Click(object sender, EventArgs e)
{
try
{
_ProductName = Product_Name(txtProductName.Text);
_Category = cbCategory.Text;
_MfgDate = dtPickerMfgDate.Value.ToString("yyyy-MM-dd");
_ExpDate = dtPickerExpDate.Value.ToString("yyyy-MM-dd");
_Description = richTxtDescription.Text;
_Quantity = Quantity(txtQuantity.Text);
_SellPrice = SellingPrice(txtSellPrice.Text);
showProductList.Add(new ProductClass(_ProductName, _Category, _MfgDate, _ExpDate, _SellPrice, _Quantity, _Description));
gridViewProductList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
gridViewProductList.DataSource = showProductList;
}
catch (StringFormatException err)
{
MessageBox.Show(err.Message);
}
catch (CurrencyFormatException err1)
{
MessageBox.Show(err1.Message);
}
catch (NumberFormatException err2)
{
MessageBox.Show(err2.Message);
}
}
}
}
Loading

0 comments on commit ed2b3a9

Please sign in to comment.