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.

153 lines
5.6 KiB

using BiskLog_Point_Of_Sale.Classes;
using BiskLog_Point_Of_Sale.Dialogs;
using BiskLog_Point_Of_Sale.Multiple_Login;
using BiskLog_Point_Of_Sale.Properties;
using Point_Of_Sale_Managment;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BiskLog_Point_Of_Sale.Products_Module
{
public partial class UnitMeasure : Form
{
SqlConnection cn;
DatabaseConn conn = new DatabaseConn();
SqlCommand cm;
public List<FundamentalQuantities> newQuantity = new List<FundamentalQuantities>();
string uniCode = "";
AddProductModule productModule;
SqlDataReader dr;
List<string> availableUnits;
EditProductModule editproductModule;
public UnitMeasure(AddProductModule productModule = null, EditProductModule editproductModule = null, List<string>available = null)
{
InitializeComponent();
cn = new SqlConnection(conn.MyConnection());
this.productModule = productModule;
this.availableUnits = available;
this.editproductModule = editproductModule;
}
private void exitBTN_Click(object sender, EventArgs e)
{
this.Close();
}
public int addUnits()
{
try
{
int result = 0;
taller.Invoke(new Action(() =>
{
if (!availableUnits.Contains(taller.Text))
{
uniCode = Settings.Default.BranchID + DateTime.Now.ToString("yyyyMMddHHmmssfff") + maashorti.Text;
cn.Open();
cm = new SqlCommand("Insert into UnitOfMeasure (unitCode,unitname,unitshort,status,branchID) values " +
"(@unitCode,@unitname,@unitshort,@status,@branchID)", cn);
cm.Parameters.AddWithValue("@unitCode", uniCode);
cm.Parameters.AddWithValue("@unitname", taller.Text);
cm.Parameters.AddWithValue("@unitshort", maashorti.Text);
cm.Parameters.AddWithValue("@status", "ACTIVE");
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.ExecuteNonQuery();
result = 1;
cn.Close();
}
else
{
result = 2;
}
}));
return result;
}
catch (Exception ex)
{
ErrorLogging.WriteToFile(ex.ToString());
cn.Close();
return 0;
}
}
private async void customerHistory_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(taller.Text) && !String.IsNullOrEmpty(maashorti.Text))
{
Task<int> task = new Task<int>(addUnits);
task.Start();
int result = await task;
if (result == 1)
{
FundamentalQuantities quantities = new FundamentalQuantities();
quantities.fullname = taller.Text;
quantities.shortname = maashorti.Text;
quantities.id = uniCode;
newQuantity.Add(quantities);
string title = "Operation Successful";
string message = "Unit Added Successfully";
NoAction prompt = new NoAction(title, message);
prompt.BringToFront();
prompt.ShowDialog();
taller.Text = "";
maashorti.Text = "";
}
else if (result == 2)
{
string title = "Unit Already exists";
string message = "Unit has already been created, cannot create units with the same name";
NoAction prompt = new NoAction(title, message);
prompt.BringToFront();
prompt.ShowDialog();
taller.Text = "";
maashorti.Text = "";
if (productModule != null)
{
productModule.refresh();
}
else
{
editproductModule.refresh();
}
this.Close();
}
else
{
string title = "An error occurred";
string message = "An error occurred while trying to add new unit of measure";
NoAction prompt = new NoAction(title, message);
prompt.BringToFront();
prompt.ShowDialog();
}
}
else
{
string title = "Empty Fields";
string message = "Fill all spaces to continue";
NoAction prompt = new NoAction(title, message);
prompt.BringToFront();
prompt.ShowDialog();
}
}
private void exitBTN_MouseEnter(object sender, EventArgs e)
{
exitBTN.BackColor = Color.Crimson;
}
private void exitBTN_MouseLeave(object sender, EventArgs e)
{
exitBTN.BackColor = Color.Transparent;
}
}
}