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.
1000 lines
39 KiB
1000 lines
39 KiB
3 months ago
|
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)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
cn = new SqlConnection(databasecon.MyConnection());
|
||
|
proList = pList;
|
||
|
this.productID = productID;
|
||
|
}
|
||
|
|
||
|
public int getProduct()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
name.Invoke(new Action(() =>
|
||
|
{
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Select p.product_name,p.pdesc,b.brand,c.category,p.barcode,p.costprice,u.unitshort,p.price,I.quantity from " +
|
||
|
"tblProduct p Inner Join tblInventory I On I.pcode = p.pcode Inner Join tblBrand b On b.id = p.bid Inner Join tblCategory c " +
|
||
|
"On c.id = p.cid Inner Join UnitOfMeasure u On u.unitCode = p.baseUnit where p.branchID = @branchID and p.pcode = @pcode " +
|
||
|
"Select u.unitshort,PAU.[quantity/unit],PAU.[price/unit] from ProductAltUnit PAU Inner Join UnitOfMeasure u On u.unitCode = PAU.unitCode " +
|
||
|
"where PAU.pcode = @pcode and PAU.branchID=@branchID", cn);
|
||
|
cm.Parameters.AddWithValue("@pcode", productID);
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
dr.Read();
|
||
|
if (dr.HasRows)
|
||
|
{
|
||
|
name.Text = dr[0].ToString();
|
||
|
txtDesc.Text = dr[1].ToString();
|
||
|
cbcBrand.Text = dr[2].ToString();
|
||
|
cbcCategory.Text = dr[3].ToString();
|
||
|
txtPcode.Text = productID;
|
||
|
txtBarcode.Text = dr[4].ToString();
|
||
|
baseUnit.Text = dr[6].ToString();
|
||
|
costP.Text = dr[5].ToString();
|
||
|
txtPrice.Text = dr[7].ToString();
|
||
|
txtQty.Text = dr[8].ToString();
|
||
|
}
|
||
|
dr.NextResult();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
if (String.IsNullOrEmpty(unit1.Text))
|
||
|
{
|
||
|
unit1.Text = dr[0].ToString();
|
||
|
unit1P.Text = dr[2].ToString();
|
||
|
unit1QTY.Text = dr[1].ToString();
|
||
|
}
|
||
|
else if (String.IsNullOrEmpty(unit2.Text))
|
||
|
{
|
||
|
unit2.Text = dr[0].ToString();
|
||
|
unit2P.Text = dr[2].ToString();
|
||
|
unit2QTY.Text = dr[1].ToString();
|
||
|
}
|
||
|
else if (String.IsNullOrEmpty(unit3.Text))
|
||
|
{
|
||
|
unit3.Text = dr[0].ToString();
|
||
|
unit3P.Text = dr[2].ToString();
|
||
|
unit3QTY.Text = dr[1].ToString();
|
||
|
}
|
||
|
else if (String.IsNullOrEmpty(unit4.Text))
|
||
|
{
|
||
|
unit4.Text = dr[0].ToString();
|
||
|
unit4P.Text = dr[2].ToString();
|
||
|
unit4QTY.Text = dr[1].ToString();
|
||
|
}
|
||
|
else if (String.IsNullOrEmpty(unit5.Text))
|
||
|
{
|
||
|
unit5.Text = dr[0].ToString();
|
||
|
unit5P.Text = dr[2].ToString();
|
||
|
unit5QTY.Text = dr[1].ToString();
|
||
|
}
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
cn.Close();
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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 void GeneratePcode()
|
||
|
{
|
||
|
string product_name = name.Text.Substring(0, 3).ToUpper();
|
||
|
txtPcode.Text = product_name + String.Format("{0:d12}", (DateTime.Now.Ticks / 10) % 1000000000);
|
||
|
Bcode = txtPcode.Text.Substring(3);
|
||
|
Bcode1 = String.Format("{0:d12}", (DateTime.Now.Ticks / 10) % 1000000000) + "01";
|
||
|
Bcode2 = String.Format("{0:d12}", (DateTime.Now.Ticks / 10) % 1000000000) + "02";
|
||
|
Bcode3 = String.Format("{0:d12}", (DateTime.Now.Ticks / 10) % 1000000000) + "03";
|
||
|
Bcode4 = String.Format("{0:d12}", (DateTime.Now.Ticks / 10) % 1000000000) + "04";
|
||
|
Bcode5 = String.Format("{0:d12}", (DateTime.Now.Ticks / 10) % 1000000000) + "05";
|
||
|
txtBarcode.Text = Bcode;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
private async void btnSave_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (!String.IsNullOrEmpty(cbcBrand.Text) && !String.IsNullOrEmpty(cbcCategory.Text) && !String.IsNullOrEmpty(baseUnit.Text))
|
||
|
{
|
||
|
Task<int> task = new Task<int>(() => AddProducts());
|
||
|
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 = "";
|
||
|
if (String.IsNullOrEmpty(cbcBrand.Text))
|
||
|
{
|
||
|
message = "You need to select the brand of the product";
|
||
|
}
|
||
|
else if (String.IsNullOrEmpty(cbcBrand.Text))
|
||
|
{
|
||
|
message = "You need to select the category of the product";
|
||
|
}
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
public int AddProducts()
|
||
|
{
|
||
|
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)
|
||
|
{
|
||
|
txtPcode.Invoke(new Action(() =>
|
||
|
{
|
||
|
cn.Open();
|
||
|
transaction = cn.BeginTransaction();
|
||
|
cm = new SqlCommand("Update tblProduct set pdesc = @pdesc,bid = @bid,cid = @cid,product_name = @product_name where pcode = @pcode " +
|
||
|
"and branchID = @branchID ", cn);
|
||
|
cm.Parameters.AddWithValue("@pcode", txtPcode.Text);
|
||
|
cm.Parameters.AddWithValue("@pdesc", txtDesc.Text);
|
||
|
cm.Parameters.AddWithValue("@bid", (cbcBrand.SelectedItem as ComboboxItem).Value.ToString());
|
||
|
cm.Parameters.AddWithValue("@cid", (cbcCategory.SelectedItem as ComboboxItem).Value.ToString());
|
||
|
cm.Parameters.AddWithValue("@product_name", name.Text);
|
||
|
cm.Parameters.AddWithValue("@branchID", Form1.branch);
|
||
|
cm.Transaction = transaction;
|
||
|
cm.ExecuteNonQuery();
|
||
|
|
||
|
transaction.Commit();
|
||
|
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");
|
||
|
}
|
||
|
public void Clear()
|
||
|
{
|
||
|
txtPcode.Invoke(new Action(() =>
|
||
|
{
|
||
|
txtPcode.Clear();
|
||
|
txtBarcode.Clear();
|
||
|
txtDesc.Clear();
|
||
|
txtPrice.Clear();
|
||
|
txtQty.Clear();
|
||
|
cbcBrand.Text = "";
|
||
|
cbcCategory.Text = "";
|
||
|
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();
|
||
|
}));
|
||
|
return 1;
|
||
|
});
|
||
|
task.Start();
|
||
|
await task;
|
||
|
|
||
|
toolParameterComboBoxes.Add(baseUnit);
|
||
|
toolParameterComboBoxes.Add(unit1);
|
||
|
toolParameterComboBoxes.Add(unit2);
|
||
|
toolParameterComboBoxes.Add(unit3);
|
||
|
toolParameterComboBoxes.Add(unit4);
|
||
|
toolParameterComboBoxes.Add(unit5);
|
||
|
baseUnit.Enabled = false;
|
||
|
unit1.Enabled = false;
|
||
|
unit2.Enabled = false;
|
||
|
unit3.Enabled = false;
|
||
|
unit4.Enabled = false;
|
||
|
unit5.Enabled = false;
|
||
|
unit3QTY.Enabled = false;
|
||
|
unit3P.Enabled = false;
|
||
|
unit1QTY.Enabled = false;
|
||
|
unit1P.Enabled = false;
|
||
|
unit2P.Enabled = false;
|
||
|
unit2QTY.Enabled = false;
|
||
|
unit4P.Enabled = false;
|
||
|
unit4QTY.Enabled = false;
|
||
|
unit5P.Enabled = false;
|
||
|
unit5QTY.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();
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
unit1.Enabled = true;
|
||
|
unit2.Enabled = true;
|
||
|
unit3.Enabled = true;
|
||
|
unit4.Enabled = true;
|
||
|
unit5.Enabled = true;
|
||
|
}
|
||
|
}
|
||
|
private void unit1_TextChanged(object sender, EventArgs e)
|
||
|
{
|
||
|
if (!String.IsNullOrEmpty(unit1.Text))
|
||
|
{
|
||
|
unit1QTY.Enabled = true;
|
||
|
unit1P.Enabled = true;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|