Biskilog POS desktop appilcation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1203 lines
50 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using BarcodeLib;
using System.IO;
using System.Drawing.Imaging;
using System.Web.Security;
using BiskLog_Point_Of_Sale.Multiple_Login;
using BiskLog_Point_Of_Sale.Properties;
using BiskLog_Point_Of_Sale.Classes;
using BiskLog_Point_Of_Sale.Company_Setup;
using BiskLog_Point_Of_Sale.Products_Module;
namespace Point_Of_Sale_Managment
{
public partial class EditProductModule : Form
{
SqlConnection cn = new SqlConnection();
SqlCommand cm, cm1, cm2;
DatabaseConn databasecon = new DatabaseConn();
SqlDataReader dr;
ProductListForm proList;
SqlTransaction transaction;
public static string CardPicture, Bcode, Bcode1, Bcode2, Bcode3, Bcode4, Bcode5;
List<FundamentalQuantities> listofQTY = new List<FundamentalQuantities>();
List<FundamentalQuantities> quantitiesunitBase = new List<FundamentalQuantities>();
List<FundamentalQuantities> quantitiesunit1 = new List<FundamentalQuantities>();
List<FundamentalQuantities> quantitiesunit2 = new List<FundamentalQuantities>();
List<FundamentalQuantities> quantitiesunit3 = new List<FundamentalQuantities>();
List<FundamentalQuantities> quantitiesunit4 = new List<FundamentalQuantities>();
List<FundamentalQuantities> quantitiesunit5 = new List<FundamentalQuantities>();
List<ComboBox> toolParameterComboBoxes = new List<ComboBox>();
int numberofUnit = 1;
string productID;
public EditProductModule(ProductListForm pList, string productID, string productname, string productDescription,
string barcode, string quantity,string brand,string category)
{
InitializeComponent();
cn = new SqlConnection(databasecon.MyConnection());
proList = pList;
this.productID = productID;
txtPcode.Text = productID;
this.name.Text = productname;
txtDesc.Text = productDescription;
txtBarcode.Text = barcode;
if (quantity != "N/A")
txtQty.Text = quantity;
lblCategory.Text = category;
lblBrand.Text = brand;
}
public int getProduct()
{
try
{
name.Invoke(new Action(() =>
{
cn.Open();
cm = new SqlCommand("Exec usp_get_product_unit_price_amendmentForm @pcode =@pcode1,@branchID=@branchID1", cn);
cm.Parameters.AddWithValue("@pcode1", productID);
cm.Parameters.AddWithValue("@branchID1", Settings.Default.BranchID);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
txtPrice.Text = dr["basePrice"].ToString();
costP.Text = dr["baseCost"].ToString();
baseUnit.Text = listofQTY.Where(u => u.fullname.ToLower() == dr["baseUnit"].ToString().ToLower()).Select(c => c.shortname).FirstOrDefault();
if (String.IsNullOrEmpty(unit1.Text))
{
unit1.Text = listofQTY.Where(u => u.fullname.ToLower() == dr["unitname"].ToString().ToLower()).Select(c => c.shortname).FirstOrDefault();
unit1P.Text = dr["unitPrice"].ToString();
unit1QTY.Text = dr["unitQuantity"].ToString();
}
else if (String.IsNullOrEmpty(unit2.Text))
{
unit2.Text = listofQTY.Where(u => u.fullname.ToLower() == dr["unitname"].ToString().ToLower()).Select(c => c.shortname).FirstOrDefault();
unit2P.Text = dr["unitPrice"].ToString();
unit2QTY.Text = dr["unitQuantity"].ToString();
}
else if (String.IsNullOrEmpty(unit3.Text))
{
unit3.Text = listofQTY.Where(u => u.fullname.ToLower() == dr["unitname"].ToString().ToLower()).Select(c => c.shortname).FirstOrDefault();
unit3P.Text = dr["unitPrice"].ToString();
unit3QTY.Text = dr["unitQuantity"].ToString();
}
else if (String.IsNullOrEmpty(unit4.Text))
{
unit4.Text = listofQTY.Where(u => u.fullname.ToLower() == dr["unitname"].ToString().ToLower()).Select(c => c.shortname).FirstOrDefault();
unit4P.Text = dr["unitPrice"].ToString();
unit4QTY.Text = dr["unitQuantity"].ToString();
}
else if (String.IsNullOrEmpty(unit5.Text))
{
unit5.Text = listofQTY.Where(u => u.fullname.ToLower() == dr["unitname"].ToString().ToLower()).Select(c => c.shortname).FirstOrDefault();
unit5P.Text = dr["unitPrice"].ToString();
unit5QTY.Text = dr["unitQuantity"].ToString();
}
}
dr.Close();
cn.Close();
}));
return 1;
}
catch (Exception ex)
{
cn.Close();
ErrorLogging.WriteToFile(ex.ToString());
return 0;
}
}
private void newUnit(string check)
{
if (String.IsNullOrEmpty(check))
{
baseUnit.Enabled = true;
txtQty.Enabled = true;
costP.Enabled = true;
txtPrice.Enabled = true;
}
}
#region notInuse
//public int LoadCategory()
//{
// try
// {
// cbcCategory.Invoke(new Action(() =>
// {
// cbcCategory.Items.Clear();
// cn.Open();
// cm = new SqlCommand("Select category,id from tblCategory where branchID = @branchID", cn);
// cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
// cm.ExecuteNonQuery();
// dr = cm.ExecuteReader();
// while (dr.Read())
// {
// ComboboxItem combobox = new ComboboxItem();
// combobox.Text = dr[0].ToString();
// combobox.Value = dr[1].ToString();
// cbcCategory.Items.Add(combobox);
// }
// dr.Close();
// cn.Close();
// }));
// return 1;
// }
// catch (Exception ex)
// {
// cn.Close();
// ErrorLogging.WriteToFile(ex.ToString());
// return 0;
// }
//}
//public int LoadBrand()
//{
// try
// {
// cbcBrand.Invoke(new Action(() =>
// {
// cbcBrand.Items.Clear();
// cn.Open();
// cm = new SqlCommand("Select brand,id from tblBrand where branchID = @branchID", cn);
// cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
// cm.ExecuteNonQuery();
// dr = cm.ExecuteReader();
// while (dr.Read())
// {
// ComboboxItem combobox = new ComboboxItem();
// combobox.Text = dr[0].ToString();
// combobox.Value = dr[1].ToString();
// cbcBrand.Items.Add(combobox);
// }
// dr.Close();
// cn.Close();
// }));
// return 1;
// }
// catch (Exception ex)
// {
// cn.Close();
// ErrorLogging.WriteToFile(ex.ToString());
// return 0;
// }
//}
#endregion
public List<FundamentalQuantities> readyThem()
{
List<FundamentalQuantities> listOfFundamental = new List<FundamentalQuantities>();
if (!String.IsNullOrEmpty(baseUnit.Text))
{
FundamentalQuantities quantities = new FundamentalQuantities();
quantities.fullname = txtQty.Text.ToString();
quantities.shortname = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
quantities.id = Bcode;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit1.Text))
{
FundamentalQuantities quantities = new FundamentalQuantities();
quantities.fullname = unit1QTY.Text.ToString();
quantities.shortname = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
quantities.id = Bcode1;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit2.Text))
{
FundamentalQuantities quantities = new FundamentalQuantities();
quantities.fullname = unit2QTY.Text.ToString();
quantities.shortname = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
quantities.id = Bcode2;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit3.Text))
{
FundamentalQuantities quantities = new FundamentalQuantities();
quantities.fullname = unit3QTY.Text.ToString();
quantities.shortname = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
quantities.id = Bcode3;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit4.Text))
{
FundamentalQuantities quantities = new FundamentalQuantities();
quantities.fullname = unit4QTY.Text.ToString();
quantities.shortname = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
quantities.id = Bcode4;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit5.Text))
{
FundamentalQuantities quantities = new FundamentalQuantities();
quantities.fullname = unit5QTY.Text.ToString();
quantities.shortname = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
quantities.id = Bcode5;
listOfFundamental.Add(quantities);
}
return listOfFundamental;
}
public List<ProductAltUnit> readied()
{
List<ProductAltUnit> listOfFundamental = new List<ProductAltUnit>();
if (!String.IsNullOrEmpty(unit1.Text) && !String.IsNullOrEmpty(unit1P.Text) && !String.IsNullOrEmpty(unit1QTY.Text))
{
ProductAltUnit quantities = new ProductAltUnit();
quantities.pcode = txtPcode.Text.ToString();
quantities.price = unit1P.Text.ToString();
quantities.unitCode = (unit1.SelectedItem as FundamentalQuantities).id.ToString();
quantities.measuringqty = unit1QTY.Text;
quantities.distinctiveCode = txtPcode.Text.ToString() + "-01";
quantities.unitBarcode = Bcode1;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit2.Text) && !String.IsNullOrEmpty(unit2P.Text) && !String.IsNullOrEmpty(unit2QTY.Text))
{
ProductAltUnit quantities = new ProductAltUnit();
quantities.pcode = txtPcode.Text.ToString();
quantities.price = unit2P.Text.ToString();
quantities.unitCode = (unit2.SelectedItem as FundamentalQuantities).id.ToString();
quantities.measuringqty = unit2QTY.Text;
quantities.distinctiveCode = txtPcode.Text.ToString() + "-02";
quantities.unitBarcode = Bcode2;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit3.Text) && !String.IsNullOrEmpty(unit3P.Text) && !String.IsNullOrEmpty(unit3QTY.Text))
{
ProductAltUnit quantities = new ProductAltUnit();
quantities.pcode = txtPcode.Text.ToString();
quantities.price = unit3P.Text.ToString();
quantities.unitCode = (unit3.SelectedItem as FundamentalQuantities).id.ToString();
quantities.measuringqty = unit3QTY.Text;
quantities.distinctiveCode = txtPcode.Text.ToString() + "-03";
quantities.unitBarcode = Bcode3;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit4.Text) && !String.IsNullOrEmpty(unit4P.Text) && !String.IsNullOrEmpty(unit4QTY.Text))
{
ProductAltUnit quantities = new ProductAltUnit();
quantities.pcode = txtPcode.Text.ToString();
quantities.price = unit4P.Text.ToString();
quantities.unitCode = (unit4.SelectedItem as FundamentalQuantities).id.ToString();
quantities.measuringqty = unit4QTY.Text;
quantities.distinctiveCode = txtPcode.Text.ToString() + "-04";
quantities.unitBarcode = Bcode4;
listOfFundamental.Add(quantities);
}
if (!String.IsNullOrEmpty(unit5.Text) && !String.IsNullOrEmpty(unit5P.Text) && !String.IsNullOrEmpty(unit5QTY.Text))
{
ProductAltUnit quantities = new ProductAltUnit();
quantities.pcode = txtPcode.Text.ToString();
quantities.price = unit5P.Text.ToString();
quantities.unitCode = (unit5.SelectedItem as FundamentalQuantities).id.ToString();
quantities.measuringqty = unit5QTY.Text;
quantities.distinctiveCode = txtPcode.Text.ToString() + "-05";
quantities.unitBarcode = Bcode5;
listOfFundamental.Add(quantities);
}
return listOfFundamental;
}
private async void btnSave_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(baseUnit.Text))
{
List<FundamentalQuantities> listOfFundamental = readyThem();
numberofUnit = listOfFundamental.Count;
List<ProductAltUnit> ready = readied();
Task<int> task = new Task<int>(() => AddProducts(ready));
holding.Visible = true;
btnSave.Enabled = false;
task.Start();
int result = await task;
if (result == 1)
{
string title = "Product Added";
string message = "Product information has been updated successfully";
NoAction confirm = new NoAction(title, message);
confirm.BringToFront();
confirm.ShowDialog();
}
holding.Visible = false;
btnSave.Enabled = true;
}
else
{
string title = "Action Required";
string message = "Error while saving changes";
NoAction noAction = new NoAction(title, message);
noAction.BringToFront();
noAction.ShowDialog();
}
}
public int AddProducts(List<ProductAltUnit> quantities)
{
try
{
string Messenger = "Are you sure you want to save this product ?";
string heading = "Save Product";
Confirmation Confirmation = new Confirmation(message: Messenger, title: heading);
Confirmation.BringToFront();
Confirmation.ShowDialog();
if (Confirmation.DialogResult == DialogResult.Yes)
{
var readyQuantity = new DataTable();
readyQuantity.Columns.Add("pcode", typeof(string));
readyQuantity.Columns.Add("unitCode", typeof(string));
readyQuantity.Columns.Add("unitBarcode", typeof(string));
readyQuantity.Columns.Add("price", typeof(decimal));
readyQuantity.Columns.Add("measuringqty", typeof(int));
readyQuantity.Columns.Add("distinctiveCode", typeof(string));
quantities.ForEach((e) => {
readyQuantity.Rows.Add(e.pcode, e.unitCode, e.unitBarcode, decimal.Parse(e.price), int.Parse(e.measuringqty), e.distinctiveCode);
});
txtPcode.Invoke(new Action(() =>
{
cn.Open();
cm = new SqlCommand("EXEC usp_update_product_details @pcode = @pcode1,@barcode = @barcode1,@pdesc = @pdesc1," +
"@product_name = @product_name1,@branchID = @branchID1,@price = @price1,@costprice = @costprice1," +
"@baseUnit = @baseUnit1,@quantity = @quantity1,@date = @date1,@stockinby = @stockinby1,@refno = @ref1,@countID = @countID1," +
"@listofUnits = @listofUnits1,@restockwarnlevel = @restockwarnlevel1,@restockwarnunit = @restockwarnunit1", cn);
cm.Parameters.AddWithValue("@pcode1", txtPcode.Text);
cm.Parameters.AddWithValue("@barcode1", txtBarcode.Text);
cm.Parameters.AddWithValue("@pdesc1", txtDesc.Text);
cm.Parameters.AddWithValue("@price1", txtPrice.Text);
cm.Parameters.AddWithValue("@costprice1", costP.Text);
cm.Parameters.AddWithValue("@product_name1", name.Text);
cm.Parameters.AddWithValue("@branchID1", Form1.branch);
cm.Parameters.AddWithValue("@baseUnit1", (baseUnit.SelectedItem as FundamentalQuantities).id.ToString());
cm.Parameters.AddWithValue("@quantity1", txtQty.Text);
cm.Parameters.AddWithValue("@date1", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffff"));
cm.Parameters.AddWithValue("@stockinby1", MainLogin.login_user);
cm.Parameters.AddWithValue("@countID1", txtPcode.Text + Form1.branch + DateTime.Now.ToString("yyyyMMddHHmmssfff"));
cm.Parameters.Add(new SqlParameter
{
ParameterName = "@listofUnits1",
SqlDbType = SqlDbType.Structured,
Value = readyQuantity,
TypeName = "[ProductAltUnit]"
});
cm.Parameters.AddWithValue("@restockwarnunit1", (reoderUnit.SelectedItem as FundamentalQuantities).id.ToString());
cm.Parameters.AddWithValue("@restockwarnlevel1", warnLevel.Value);
cm.Parameters.AddWithValue("@ref1", getReference());
cm.ExecuteNonQuery();
proList.LoadRecords();
cn.Close();
}));
return 1;
}
else
{
return 2;
}
}
catch (SqlException ex)
{
transaction.Rollback();
cn.Close();
ErrorLogging.WriteToFile(ex.ToString());
return 0;
}
catch (Exception ex)
{
ErrorLogging.WriteToFile(ex.ToString());
cn.Close();
return 0;
}
}
public string getReference()
{
return txtPcode.Text.Substring(0, 3).ToUpper() + DateTime.Now.ToString("/yyyy/MM/dd/HH/mm/ss/fff");
}
private void getRestockSettings()
{
try
{
cn.Open();
cm = new SqlCommand("Exec usp_get_product_reorder_level @pcode =@pcode1,@branchID=@branchID1", cn);
cm.Parameters.AddWithValue("@pcode1", productID);
cm.Parameters.AddWithValue("@branchID1", Settings.Default.BranchID);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
warnLevel.Value = int.Parse(dr["warnLevel"].ToString());
reoderUnit.Text = listofQTY.Where(u => u.id.ToLower() == dr["unit"].ToString().ToLower()).Select(c => c.shortname).FirstOrDefault();
}
dr.Close();
cn.Close();
}
catch(Exception ex)
{
ErrorLogging.WriteToFile(ex.ToString());
cn.Close();
}
}
public void Clear()
{
txtPcode.Invoke(new Action(() =>
{
txtPcode.Clear();
txtBarcode.Clear();
txtDesc.Clear();
txtPrice.Clear();
txtQty.Clear();
txtPcode.Focus();
costP.Text = "";
name.Text = "";
btnSave.Enabled = true;
baseUnit.DataSource = null;
unit1.DataSource = null;
unit1P.Text = "";
unit1QTY.Text = "";
unit2.DataSource = null;
unit2P.Text = "";
unit2QTY.Text = "";
unit3.DataSource = null;
unit3P.Text = "";
unit3QTY.Text = "";
unit4.DataSource = null;
unit4P.Text = "";
unit4QTY.Text = "";
unit5.DataSource = null;
unit5P.Text = "";
unit5QTY.Text = "";
addToCombos();
}));
}
private async void AddProductModule_Load(object sender, EventArgs e)
{
Task<int> task = new Task<int>(() =>
{
//LoadBrand();
//LoadCategory();
loadUnits();
baseUnit.Invoke(new Action(() =>
{
addToCombos();
addToCombos1();
addToCombos2();
addToCombos3();
addToCombos4();
addToCombos5();
getProduct();
getRestockSettings();
}));
return 1;
});
task.Start();
await task;
toolParameterComboBoxes.Add(baseUnit);
toolParameterComboBoxes.Add(unit1);
toolParameterComboBoxes.Add(unit2);
toolParameterComboBoxes.Add(unit3);
toolParameterComboBoxes.Add(unit4);
toolParameterComboBoxes.Add(unit5);
if (!String.IsNullOrEmpty(baseUnit.Text))
{
baseUnit.Enabled = false;
txtQty.Enabled = false;
costP.Enabled = false;
txtPrice.Enabled = false;
}
}
public void refresh()
{
addToCombos();
addToCombos1();
addToCombos2();
addToCombos3();
addToCombos4();
addToCombos5();
}
private void txtPrice_TextChanged(object sender, EventArgs e)
{
}
private void validateComboBox(object sender, EventArgs e)
{
ComboBox thisCB = sender as ComboBox;
if (thisCB.Text != "")
{
foreach (ComboBox cb in toolParameterComboBoxes)
{
if (thisCB.Name != cb.Name && thisCB.Text == cb.Text && thisCB.Text != "" && cb.Text != "")
{
//MessageBox.Show("You cannot duplicate tool parameters." + "\r\n" + "\r\n"
// + "That option has been selected in " + cb.Name.Replace("comboBox", ""), "Error");
thisCB.SelectedIndex = -1;
break;
}
}
}
}
public void addToCombos()
{
quantitiesunitBase.Clear();
List<string> there = new List<string>();
if (unit1.SelectedItem != null)
{
string unit1selected = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit1selected);
}
if (unit2.SelectedItem != null)
{
string unit2selected = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit2selected);
}
if (unit3.SelectedItem != null)
{
string unit3selected = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit3selected);
}
if (unit4.SelectedItem != null)
{
string unit4selected = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit4selected);
}
if (unit5.SelectedItem != null)
{
string unit5selected = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit5selected);
}
if (baseUnit.SelectedItem != null)
{
string baseselected = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(baseselected);
}
FundamentalQuantities fundamentalQuantities = new FundamentalQuantities();
fundamentalQuantities.fullname = " ";
fundamentalQuantities.id = " ";
fundamentalQuantities.shortname = " ";
quantitiesunitBase.Add(fundamentalQuantities);
foreach (FundamentalQuantities quantity in listofQTY)
{
if (!there.Contains(quantity.shortname))
{
quantitiesunitBase.Add(quantity);
}
}
baseUnit.DataSource = null;
baseUnit.DataSource = quantitiesunitBase;
baseUnit.DisplayMember = "shortname";
baseUnit.ValueMember = "id";
baseUnit.SelectedIndex = -1;
}
public void addToCombos1()
{
quantitiesunit1.Clear();
List<string> there = new List<string>();
if (unit1.SelectedItem != null)
{
string unit1selected = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit1selected);
}
if (unit2.SelectedItem != null)
{
string unit2selected = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit2selected);
}
if (unit3.SelectedItem != null)
{
string unit3selected = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit3selected);
}
if (unit4.SelectedItem != null)
{
string unit4selected = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit4selected);
}
if (unit5.SelectedItem != null)
{
string unit5selected = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit5selected);
}
if (baseUnit.SelectedItem != null)
{
string baseselected = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(baseselected);
}
FundamentalQuantities fundamentalQuantities = new FundamentalQuantities();
fundamentalQuantities.fullname = " ";
fundamentalQuantities.id = " ";
fundamentalQuantities.shortname = " ";
quantitiesunit1.Add(fundamentalQuantities);
foreach (FundamentalQuantities quantity in listofQTY)
{
if (!there.Contains(quantity.shortname))
quantitiesunit1.Add(quantity);
}
unit1.DataSource = quantitiesunit1;
unit1.DisplayMember = "shortname";
unit1.ValueMember = "id";
unit1.SelectedIndex = -1;
}
public void addToCombos2()
{
quantitiesunit2.Clear();
List<string> there = new List<string>();
if (unit1.SelectedItem != null)
{
string unit1selected = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit1selected);
}
if (unit2.SelectedItem != null)
{
string unit2selected = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit2selected);
}
if (unit3.SelectedItem != null)
{
string unit3selected = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit3selected);
}
if (unit4.SelectedItem != null)
{
string unit4selected = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit4selected);
}
if (unit5.SelectedItem != null)
{
string unit5selected = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit5selected);
}
if (baseUnit.SelectedItem != null)
{
string baseselected = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(baseselected);
}
FundamentalQuantities fundamentalQuantities = new FundamentalQuantities();
fundamentalQuantities.fullname = " ";
fundamentalQuantities.id = " ";
fundamentalQuantities.shortname = " ";
quantitiesunit2.Add(fundamentalQuantities);
foreach (FundamentalQuantities quantity in listofQTY)
{
if (!there.Contains(quantity.shortname))
quantitiesunit2.Add(quantity);
}
unit2.DataSource = quantitiesunit2;
unit2.DisplayMember = "shortname";
unit2.ValueMember = "id";
unit2.SelectedIndex = -1;
}
public void addToCombos3()
{
quantitiesunit3.Clear();
List<string> there = new List<string>();
if (unit1.SelectedItem != null)
{
string unit1selected = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit1selected);
}
if (unit2.SelectedItem != null)
{
string unit2selected = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit2selected);
}
if (unit3.SelectedItem != null)
{
string unit3selected = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit3selected);
}
if (unit4.SelectedItem != null)
{
string unit4selected = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit4selected);
}
if (unit5.SelectedItem != null)
{
string unit5selected = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit5selected);
}
if (baseUnit.SelectedItem != null)
{
string baseselected = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(baseselected);
}
FundamentalQuantities fundamentalQuantities = new FundamentalQuantities();
fundamentalQuantities.fullname = " ";
fundamentalQuantities.id = " ";
fundamentalQuantities.shortname = " ";
quantitiesunit3.Add(fundamentalQuantities);
foreach (FundamentalQuantities quantity in listofQTY)
{
if (!there.Contains(quantity.shortname))
quantitiesunit3.Add(quantity);
}
unit3.DataSource = quantitiesunit3;
unit3.DisplayMember = "shortname";
unit3.ValueMember = "id";
unit3.SelectedIndex = -1;
}
public void addToCombos4()
{
quantitiesunit4.Clear();
List<string> there = new List<string>();
if (unit1.SelectedItem != null)
{
string unit1selected = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit1selected);
}
if (unit2.SelectedItem != null)
{
string unit2selected = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit2selected);
}
if (unit3.SelectedItem != null)
{
string unit3selected = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit3selected);
}
if (unit4.SelectedItem != null)
{
string unit4selected = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit4selected);
}
if (unit5.SelectedItem != null)
{
string unit5selected = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit5selected);
}
if (baseUnit.SelectedItem != null)
{
string baseselected = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(baseselected);
}
FundamentalQuantities fundamentalQuantities = new FundamentalQuantities();
fundamentalQuantities.fullname = " ";
fundamentalQuantities.id = " ";
fundamentalQuantities.shortname = " ";
quantitiesunit4.Add(fundamentalQuantities);
foreach (FundamentalQuantities quantity in listofQTY)
{
if (!there.Contains(quantity.shortname))
quantitiesunit4.Add(quantity);
}
unit4.DataSource = quantitiesunit4;
unit4.DisplayMember = "shortname";
unit4.ValueMember = "id";
unit4.SelectedIndex = -1;
}
public void addToCombos5()
{
quantitiesunit5.Clear();
List<string> there = new List<string>();
if (unit1.SelectedItem != null)
{
string unit1selected = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit1selected);
}
if (unit2.SelectedItem != null)
{
string unit2selected = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit2selected);
}
if (unit3.SelectedItem != null)
{
string unit3selected = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit3selected);
}
if (unit4.SelectedItem != null)
{
string unit4selected = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit4selected);
}
if (unit5.SelectedItem != null)
{
string unit5selected = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit5selected);
}
if (baseUnit.SelectedItem != null)
{
string baseselected = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(baseselected);
}
FundamentalQuantities fundamentalQuantities = new FundamentalQuantities();
fundamentalQuantities.fullname = " ";
fundamentalQuantities.id = " ";
fundamentalQuantities.shortname = " ";
quantitiesunit5.Add(fundamentalQuantities);
foreach (FundamentalQuantities quantity in listofQTY)
{
if (!there.Contains(quantity.shortname))
quantitiesunit5.Add(quantity);
}
unit5.DataSource = quantitiesunit5;
unit5.DisplayMember = "shortname";
unit5.ValueMember = "id";
unit5.SelectedIndex = -1;
}
private void txtPrice_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 46)
{
// accepts . character
}
else if (e.KeyChar == 8)
{
//accepts backspace
}
else if ((e.KeyChar < 48) || (e.KeyChar > 57)) //ascii code 48-57 between 0-9
{
e.Handled = true;
}
}
public void printBarcode(string code, int qty)
{
Barcode barcodeAPI = new Barcode();
Color foreColor = Color.Black;
Color backColor = Color.Transparent;
Image barcodeImage = barcodeAPI.Encode(TYPE.CODE128, code, foreColor, backColor, 290, 120);
MemoryStream ms = new MemoryStream();
barcodeImage.Save(ms, ImageFormat.Png);
byte[] imageBytes = ms.ToArray();
CardPicture = Convert.ToBase64String(imageBytes);
BarcodePrinter view = new BarcodePrinter(CardPicture, code, qty);
Form1.printerDialog = view;
view.BringToFront();
view.ShowDialog();
Form1.printerDialog = null;
}
private void cbcCategory_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtQty_TextChanged(object sender, EventArgs e)
{
}
private void ExitBTN_Click(object sender, EventArgs e)
{
this.Close();
}
public int loadUnits()
{
listofQTY.Clear();
try
{
cn.Open();
cm = new SqlCommand("Select unitCode,unitname,unitshort from UnitOfMeasure where branchID = @branchID and status = @status", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@status", "ACTIVE");
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
FundamentalQuantities fundamentalQuantities = new FundamentalQuantities();
fundamentalQuantities.id = dr[0].ToString();
fundamentalQuantities.fullname = dr[1].ToString();
fundamentalQuantities.shortname = dr[2].ToString();
listofQTY.Add(fundamentalQuantities);
}
dr.Close();
cn.Close();
return 1;
}
catch (Exception ex)
{
ErrorLogging.WriteToFile(ex.ToString());
cn.Close();
return 0;
}
}
private void button1_Click(object sender, EventArgs e)
{
UnitMeasure measure = new UnitMeasure(editproductModule: this, available: listofQTY.Select(p => p.fullname).ToList());
measure.BringToFront();
measure.ShowDialog();
if (measure.newQuantity != null && measure.newQuantity.Count > 0)
{
List<FundamentalQuantities> quantities = measure.newQuantity;
foreach (FundamentalQuantities quantities1 in quantities)
{
listofQTY.Add(quantities1);
quantitiesunitBase.Add(quantities1);
quantitiesunit1.Add(quantities1);
quantitiesunit2.Add(quantities1);
quantitiesunit3.Add(quantities1);
quantitiesunit4.Add(quantities1);
quantitiesunit5.Add(quantities1);
string currentValue = "-1";
if (baseUnit.SelectedValue != null)
currentValue = baseUnit.SelectedValue.ToString();
baseUnit.DataSource = null;
baseUnit.DataSource = quantitiesunitBase;
baseUnit.DisplayMember = "shortname";
baseUnit.ValueMember = "id";
baseUnit.SelectedIndex = -1;
if (currentValue != "-1")
baseUnit.SelectedValue = currentValue;
string currentValue1 = "-1";
if (unit1.SelectedValue != null)
currentValue1 = unit1.SelectedValue.ToString();
unit1.DataSource = null;
unit1.DataSource = quantitiesunit1;
unit1.DisplayMember = "shortname";
unit1.ValueMember = "id";
unit1.SelectedIndex = -1;
if (currentValue1 != "-1")
unit1.SelectedValue = currentValue1;
string currentValue2 = "-1";
if (unit2.SelectedValue != null)
currentValue2 = unit2.SelectedValue.ToString();
unit2.DataSource = null;
unit2.DataSource = quantitiesunit2;
unit2.DisplayMember = "shortname";
unit2.ValueMember = "id";
unit2.SelectedIndex = -1;
if (currentValue2 != "-1")
unit2.SelectedValue = currentValue2;
string currentValue3 = "-1";
if (unit3.SelectedValue != null)
currentValue3 = unit3.SelectedValue.ToString();
unit3.DataSource = null;
unit3.DataSource = quantitiesunit3;
unit3.DisplayMember = "shortname";
unit3.ValueMember = "id";
unit3.SelectedIndex = -1;
if (currentValue3 != "-1")
unit3.SelectedValue = currentValue3;
string currentValue4 = "-1";
if (unit4.SelectedValue != null)
currentValue4 = unit4.SelectedValue.ToString();
unit4.DataSource = null;
unit4.DataSource = quantitiesunit4;
unit4.DisplayMember = "shortname";
unit4.ValueMember = "id";
unit4.SelectedIndex = -1;
if (currentValue4 != "-1")
unit4.SelectedValue = currentValue4;
string currentValue5 = "-1";
if (unit5.SelectedValue != null)
currentValue5 = unit5.SelectedValue.ToString();
unit5.DataSource = null;
unit5.DataSource = quantitiesunit5;
unit5.DisplayMember = "shortname";
unit5.ValueMember = "id";
unit5.SelectedIndex = -1;
if (currentValue5 != "-1")
unit5.SelectedValue = currentValue5;
}
}
}
private void exitBTN_MouseEnter(object sender, EventArgs e)
{
exitBTN.BackColor = Color.Crimson;
}
private void manageUnitsToolStripMenuItem_Click(object sender, EventArgs e)
{
ManageUnits measure = new ManageUnits(editproductModule: this);
measure.BringToFront();
measure.ShowDialog();
}
public void addToReOrderCombos()
{
List<FundamentalQuantities> reorderQuan = new List<FundamentalQuantities>();
List<string> there = new List<string>();
if (unit1.SelectedItem != null)
{
string unit1selected = (unit1.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit1selected);
}
if (unit2.SelectedItem != null)
{
string unit2selected = (unit2.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit2selected);
}
if (unit3.SelectedItem != null)
{
string unit3selected = (unit3.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit3selected);
}
if (unit4.SelectedItem != null)
{
string unit4selected = (unit4.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit4selected);
}
if (unit5.SelectedItem != null)
{
string unit5selected = (unit5.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(unit5selected);
}
if (baseUnit.SelectedItem != null)
{
string baseselected = (baseUnit.SelectedItem as FundamentalQuantities).shortname.ToString();
there.Add(baseselected);
}
foreach (FundamentalQuantities quantity in listofQTY)
{
if (there.Contains(quantity.shortname))
{
reorderQuan.Add(quantity);
}
}
reoderUnit.DataSource = null;
reoderUnit.DataSource = reorderQuan;
reoderUnit.DisplayMember = "shortname";
reoderUnit.ValueMember = "id";
reoderUnit.SelectedIndex = -1;
if (String.IsNullOrEmpty(reoderUnit.Text) && reoderUnit.Items.Count > 0)
reoderUnit.SelectedIndex = 0;
}
private void baseUnit_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(baseUnit.Text) || baseUnit.SelectedIndex == -1)
{
unit1.SelectedIndex = -1;
unit2.SelectedIndex = -1;
unit3.SelectedIndex = -1;
unit4.SelectedIndex = -1;
unit5.SelectedIndex = -1;
unit1.Enabled = false;
unit2.Enabled = false;
unit3.Enabled = false;
unit4.Enabled = false;
unit5.Enabled = false;
txtQty.Enabled = false;
costP.Enabled = false;
txtPrice.Enabled = false;
reoderUnit.Enabled = false;
warnLevel.Enabled = false;
}
else
{
unit1.Enabled = true;
unit2.Enabled = true;
unit3.Enabled = true;
unit4.Enabled = true;
unit5.Enabled = true;
txtQty.Enabled = true;
costP.Enabled = true;
txtPrice.Enabled = true;
reoderUnit.Enabled = true;
warnLevel.Enabled = true;
addToReOrderCombos();
}
}
private void unit1_TextChanged(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(unit1.Text))
{
unit1QTY.Enabled = true;
unit1P.Enabled = true;
addToReOrderCombos();
}
else
{
unit1QTY.Enabled = false;
unit1P.Enabled = false;
}
}
private void unit2_TextChanged(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(unit2.Text))
{
unit2QTY.Enabled = true;
unit2P.Enabled = true;
addToReOrderCombos();
}
else
{
unit2P.Enabled = false;
unit2QTY.Enabled = false;
}
}
private void unit3_TextChanged(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(unit3.Text))
{
unit3QTY.Enabled = true;
unit3P.Enabled = true;
addToReOrderCombos();
}
else
{
unit3QTY.Enabled = false;
unit3P.Enabled = false;
}
}
private void unit4_TextChanged(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(unit4.Text))
{
unit4QTY.Enabled = true;
unit4P.Enabled = true;
addToReOrderCombos();
}
else
{
unit4QTY.Enabled = false;
unit4P.Enabled = false;
}
}
private void unit5_TextChanged(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(unit5.Text))
{
unit5QTY.Enabled = true;
unit5P.Enabled = true;
addToReOrderCombos();
}
else
{
unit5QTY.Enabled = false;
unit5P.Enabled = false;
}
}
private void ExitBTN_MouseLeave(object sender, EventArgs e)
{
exitBTN.BackColor = Color.Transparent;
}
private void txtQty_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 46)
{
// accepts . character
}
else if (e.KeyChar == 8)
{
//accepts backspace
}
else if ((e.KeyChar < 48) || (e.KeyChar > 57)) //ascii code 48-57 between 0-9
{
e.Handled = true;
}
}
}
}