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.
139 lines
5.1 KiB
139 lines
5.1 KiB
3 months ago
|
using BiskLog_Point_Of_Sale.Classes;
|
||
|
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 ManageUnits : Form
|
||
|
{
|
||
|
SqlConnection cn;
|
||
|
SqlCommand cm;
|
||
|
SqlDataReader dr;
|
||
|
DatabaseConn conn = new DatabaseConn();
|
||
|
AddProductModule productModule;
|
||
|
EditProductModule editproductModule;
|
||
|
public ManageUnits(AddProductModule productModule = null,EditProductModule editproductModule = null)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
cn = new SqlConnection(conn.MyConnection());
|
||
|
holding.Left = (ClientSize.Width - holding.Width) / 2;
|
||
|
holding.Top = (ClientSize.Height - holding.Height) / 2;
|
||
|
this.productModule = productModule;
|
||
|
this.editproductModule = editproductModule;
|
||
|
}
|
||
|
public int loadUnits()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
dataGridView1.Invoke(new Action(() =>
|
||
|
{
|
||
|
int i = 1;
|
||
|
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())
|
||
|
{
|
||
|
dataGridView1.Rows.Add(i, dr[0].ToString(), dr[1].ToString(), dr[2].ToString());
|
||
|
i++;
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
cn.Close();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private async void ManageUnits_Load(object sender=null, EventArgs e=null)
|
||
|
{
|
||
|
Task<int> task = new Task<int>(loadUnits);
|
||
|
holding.Visible = true;
|
||
|
task.Start();
|
||
|
int result = await task;
|
||
|
if (result == 0)
|
||
|
{
|
||
|
string title = "Error Occurred";
|
||
|
string message = "An error occurred while trying to get product units of measurement";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
holding.Visible = false;
|
||
|
}
|
||
|
|
||
|
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
||
|
{
|
||
|
string colName = dataGridView1.Columns[e.ColumnIndex].Name;
|
||
|
switch (colName)
|
||
|
{
|
||
|
case "Delete":
|
||
|
string title = "Deleting record";
|
||
|
string message = "Are you sure you would like to delete this record ?";
|
||
|
Confirmation confirmation = new Confirmation(title, message);
|
||
|
confirmation.BringToFront();
|
||
|
confirmation.ShowDialog();
|
||
|
if (confirmation.DialogResult == DialogResult.Yes)
|
||
|
{
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Update UnitOfMeasure set status = @status where unitCode = @unit and branchID = @branch", cn);
|
||
|
cm.Parameters.AddWithValue("@status", "INACTIVE");
|
||
|
cm.Parameters.AddWithValue("@unit", dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
|
||
|
cm.Parameters.AddWithValue("@branch", Settings.Default.BranchID);
|
||
|
cm.ExecuteNonQuery();
|
||
|
cn.Close();
|
||
|
if (productModule != null)
|
||
|
{
|
||
|
productModule.refresh();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
editproductModule.refresh();
|
||
|
}
|
||
|
|
||
|
string titled = "Deleted Record";
|
||
|
string messaged = "Unit has been successfully deleted.";
|
||
|
NoAction noAction = new NoAction(titled, messaged);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
ManageUnits_Load();
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void label1_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
this.Close();
|
||
|
}
|
||
|
|
||
|
private void label1_MouseEnter(object sender, EventArgs e)
|
||
|
{
|
||
|
label1.BackColor = Color.Crimson;
|
||
|
}
|
||
|
|
||
|
private void label1_MouseLeave(object sender, EventArgs e)
|
||
|
{
|
||
|
label1.BackColor = Color.Transparent;
|
||
|
}
|
||
|
}
|
||
|
}
|