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.
172 lines
8.3 KiB
172 lines
8.3 KiB
3 months ago
|
using BiskLog_Point_Of_Sale.Classes;
|
||
|
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.Delivery
|
||
|
{
|
||
|
public partial class TruckInventory : Form
|
||
|
{
|
||
|
string truckID;
|
||
|
SqlConnection cn;
|
||
|
SqlCommand cm;
|
||
|
SqlDataReader dr;
|
||
|
DatabaseConn conn = new DatabaseConn();
|
||
|
bool driver;
|
||
|
public TruckInventory(string truckID, bool driver = false)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
cn = new SqlConnection(conn.MyConnection());
|
||
|
this.driver = driver;
|
||
|
this.truckID = truckID;
|
||
|
}
|
||
|
|
||
|
private void exitBTN_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
this.Close();
|
||
|
}
|
||
|
private void exitBTN_MouseEnter(object sender, EventArgs e)
|
||
|
{
|
||
|
exitBTN.BackColor = Color.Crimson;
|
||
|
}
|
||
|
public int loadDetails(string id)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
truckDriver.Invoke(new Action(() =>
|
||
|
{
|
||
|
int i = 1;
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Declare @truckDriver varchar(50) = (Select driver from tblTrucks where truckID = @truck and branchID = @branchID) " +
|
||
|
"Declare @license varchar(50) = (Select licensePlate from tblTrucks where truckID = @truck and branchID = @branchID) " +
|
||
|
"Declare @netWorth decimal(19, 2) = Case when(Select SUM(TP.price * TI.quantity) from tblTruckInventory TI Inner Join " +
|
||
|
"tblProduct TP On TP.pcode = TI.pcode where truckID = @truck and branchID = @branchID and TP.baseUnit = TI.unit and " +
|
||
|
"TI.pcode in (Select TI.pcode from tblTruckInventory where truckID = @truck and branchID = @branchID)) is null then 0 " +
|
||
|
"else (Select SUM(TP.price * TI.quantity) from tblTruckInventory TI Inner Join tblProduct TP On TP.pcode = TI.pcode " +
|
||
|
"where truckID = @truck and branchID = @branchID and TP.baseUnit = TI.unit and TI.pcode in " +
|
||
|
"(Select TI.pcode from tblTruckInventory where truckID = @truck and branchID = @branchID)) end " +
|
||
|
"Declare @netWorth1 decimal(19, 2) = Case when(Select SUM(PAU.[price/unit] * TI.quantity) from tblTruckInventory TI " +
|
||
|
"Inner Join ProductAltUnit PAU On PAU.pcode = TI.pcode where truckID = @truck and branchID = @branchID and PAU.unitCode = TI.unit " +
|
||
|
"and TI.pcode in (Select TI.pcode from tblTruckInventory where truckID = @truck and branchID = @branchID)) is null then 0 else " +
|
||
|
"(Select SUM(PAU.[price/unit] * TI.quantity) from tblTruckInventory TI Inner Join ProductAltUnit PAU On PAU.pcode = TI.pcode " +
|
||
|
"where truckID = @truck and branchID = @branchID and PAU.unitCode = TI.unit and TI.pcode in (Select TI.pcode from tblTruckInventory " +
|
||
|
"where truckID = @truck and branchID = @branchID)) end Declare @total decimal(19, 2) = @networth + @networth1 " +
|
||
|
"Select firstname, surname, @license, @total from tblDrivers where driverID = @truckDriver and branchID = @branchID " +
|
||
|
"Select TI.pcode,TP.product_name,TI.quantity,u.unitname from tblTruckInventory TI Inner Join tblProduct TP On TP.pcode = TI.pcode " +
|
||
|
"Inner Join UnitOfMeasure u On u.unitCode = TI.unit where TI.pcode in " +
|
||
|
"(Select TI.pcode from tblTruckInventory TI where truckID = @truck and TP.branchID = @branchID) and truckID = @truck", cn);
|
||
|
cm.Parameters.AddWithValue("@truck", id);
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
dr.Read();
|
||
|
if (dr.HasRows)
|
||
|
{
|
||
|
truckDriver.Text = dr[0].ToString().ToUpper() + " " + dr[1].ToString().ToUpper();
|
||
|
registrationNumber.Text = dr[2].ToString().ToUpper();
|
||
|
inventoryWorth.Text = Settings.Default.currrencyCode + " " + dr[3].ToString().ToUpper();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
truckDriver.Text = "";
|
||
|
registrationNumber.Text = "";
|
||
|
inventoryWorth.Text = "";
|
||
|
}
|
||
|
dr.NextResult();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
tInventory.Rows.Add(i, dr[0].ToString(), dr[1].ToString().ToUpper(), dr[2].ToString(),dr[3].ToString());
|
||
|
i++;
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
cn.Close();
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
public int loadDetail(string id)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
truckDriver.Invoke(new Action(() =>
|
||
|
{
|
||
|
int i = 1;
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Declare @license varchar(50) = (Select licensePlate from tblTrucks where truckID = @truck and branchID = @branchID) " +
|
||
|
"Declare @netWorth decimal(19, 2) = (Select SUM(TP.price) from tblTruckInventory TI Inner Join tblProduct TP On TP.pcode = TI.pcode where truckID = @truck and branchID = @branchID " +
|
||
|
"and TI.pcode in (Select TI.pcode tblTruckInventory where truckID = @truck and branchID = @branchID)) " +
|
||
|
"Select @license,@netWorth " +
|
||
|
"Select TI.pcode,TP.product_name,TI.quantity from tblTruckInventory TI " +
|
||
|
"Inner Join tblProduct TP On TP.pcode = TI.pcode where TI.pcode in (Select TI.pcode from tblTruckInventory TI where truckID = @truck and branchID = @branchID) and truckID = @truck", cn);
|
||
|
cm.Parameters.AddWithValue("@truck", id);
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
dr.Read();
|
||
|
if (dr.HasRows)
|
||
|
{
|
||
|
truckDriver.Text = "NO DRIVER ASSIGNED";
|
||
|
registrationNumber.Text = dr[0].ToString().ToUpper();
|
||
|
inventoryWorth.Text = Settings.Default.currrencyCode + " " + dr[1].ToString().ToUpper();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
truckDriver.Text = "NO DRIVER ASSIGNED";
|
||
|
registrationNumber.Text = "";
|
||
|
inventoryWorth.Text = "";
|
||
|
}
|
||
|
dr.NextResult();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
tInventory.Rows.Add(i, dr[0].ToString(), dr[1].ToString().ToUpper(), dr[2].ToString());
|
||
|
i++;
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
cn.Close();
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
private void exitBTN_MouseLeave(object sender, EventArgs e)
|
||
|
{
|
||
|
exitBTN.BackColor = Color.FromArgb(20, 158, 137);
|
||
|
}
|
||
|
private async void TruckInventory_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
if (driver)
|
||
|
{
|
||
|
Task<int> task = new Task<int>(() => loadDetails(truckID));
|
||
|
task.Start();
|
||
|
await task;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Task<int> task = new Task<int>(() => loadDetail(truckID));
|
||
|
task.Start();
|
||
|
await task;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|