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 Assignments : Form { string truckID; SqlConnection cn; SqlCommand cm; SqlDataReader dr; DatabaseConn conn = new DatabaseConn(); bool driver; public Assignments(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) " + "Select firstname,surname,@license from tblDrivers where driverID = @truckDriver and branchID = @branchID " + "Select orderID, dateAssigned,cost from tblTruckAssignments where orderID not in (Select deliveryID from tblDeliveryHead where branchID = @branchID and status = @status) and truckID = @truck", cn); cm.Parameters.AddWithValue("@truck", id); cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID); cm.Parameters.AddWithValue("@status", "DELIVERED"); 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(); } else { truckDriver.Text = ""; registrationNumber.Text = ""; } dr.NextResult(); while (dr.Read()) { tInventory.Rows.Add(i, dr[0].ToString(), Convert.ToDateTime(dr[1].ToString()).ToLongDateString(), dr[2].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) " + "Select @license " + "Select orderID, dateAssigned,cost from tblTruckAssignments where orderID not in (Select deliveryID from tblDeliveryHead where branchID = @branchID and status = @status) and truckID = @truck", cn); cm.Parameters.AddWithValue("@truck", id); cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID); cm.Parameters.AddWithValue("@status", "DELIVERED"); cm.ExecuteNonQuery(); dr = cm.ExecuteReader(); dr.Read(); if (dr.HasRows) { truckDriver.Text = "NO DRIVER ASSIGNED"; registrationNumber.Text = dr[0].ToString().ToUpper(); } else { truckDriver.Text = "NO DRIVER ASSIGNED"; registrationNumber.Text = ""; } dr.NextResult(); while (dr.Read()) { tInventory.Rows.Add(i, dr[0].ToString(), Convert.ToDateTime(dr[1].ToString()).ToLongDateString(), 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 task = new Task(() => loadDetails(truckID)); task.Start(); await task; } else { Task task = new Task(() => loadDetail(truckID)); task.Start(); await task; } } } }