Enventory
Enventory
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Inventory
{
public partial class frmAddProduct : Form
{
private string _ProductName;
private string _Category;
private string _MfgDate;
private string _ExpDate;
private string _Description;
private int _Quantity;
private double _SellPrice;
BindingSource showProductList;
public frmAddProduct()
{
InitializeComponent();
showProductList = new BindingSource();
}
}
public int Quantity(string qty)
{
try
{
if (!Regex.IsMatch(qty, @"^[0-9]"))
//Exception here
{
throw new StringFormException("There a StringFormatException");
}
{
return Convert.ToInt32(qty);
}
}
catch (StringFormException e)
{
MessageBox.Show("Error: " + e.Message);
return 0;
}
}
public double SellingPrice(string price)
{
try
{
if (!Regex.IsMatch(price.ToString(), @"^(\d*\.)?\d+$"))
//Exception here
{
throw new CurrencyFormatException("There a
StringFormatException");}
{
return Convert.ToDouble(price);
}
}
catch (CurrencyFormatException c)
{
MessageBox.Show("Error: " + c.Message);
return 0;
}
}
class NumberFormatException : Exception
{
public NumberFormatException(string qty) : base(qty) { }
}
class StringFormException : Exception
{
public StringFormException(string name) : base(name) { }
}
class CurrencyFormatException : Exception
{
public CurrencyFormatException(string price) : base(price) { }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Inventory
{
public partial class frmAddProduct : Form
{
private string _ProductName;
private string _Category;
private string _MfgDate;
private string _ExpDate;
private string _Description;
private int _Quantity;
private double _SellPrice;
BindingSource showProductList;
public frmAddProduct()
{
InitializeComponent();
showProductList = new BindingSource();
}
}
public int Quantity(string qty)
{
try
{
if (!Regex.IsMatch(qty, @"^[0-9]"))
//Exception here
{
throw new StringFormException("There a StringFormatException");
}
{
return Convert.ToInt32(qty);
}
}
catch (StringFormException e)
{
MessageBox.Show("Error: " + e.Message);
return 0;
}
}
public double SellingPrice(string price)
{
try
{
if (!Regex.IsMatch(price.ToString(), @"^(\d*\.)?\d+$"))
//Exception here
{
throw new CurrencyFormatException("There a
StringFormatException");}
{
return Convert.ToDouble(price);
}
}
catch (CurrencyFormatException c)
{
MessageBox.Show("Error: " + c.Message);
return 0;
}
}
class NumberFormatException : Exception
{
public NumberFormatException(string qty) : base(qty) { }
}
class StringFormException : Exception
{
public StringFormException(string name) : base(name) { }
}
class CurrencyFormatException : Exception
{
public CurrencyFormatException(string price) : base(price) { }
}
}