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.
124 lines
5.4 KiB
124 lines
5.4 KiB
using BiskLog_Point_Of_Sale.Multiple_Login;
|
|
using BiskLog_Point_Of_Sale.Properties;
|
|
using BiskLog_Point_Of_Sale.Users;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Security;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Point_Of_Sale_Managment
|
|
{
|
|
public partial class Drivers : Form
|
|
{
|
|
DatabaseConn conn = new DatabaseConn();
|
|
SqlConnection cn = new SqlConnection();
|
|
SqlCommand cm = new SqlCommand();
|
|
SqlDataReader dr;
|
|
int i = 1;
|
|
public Drivers()
|
|
{
|
|
InitializeComponent();
|
|
cn = new SqlConnection(conn.MyConnection());
|
|
loading.Left = (ClientSize.Width - loading.Width) / 2;
|
|
}
|
|
private async void users_Load(object sender = null, EventArgs e = null)
|
|
{
|
|
Task<int> task = new Task<int>(LoadUsers);
|
|
loading.Visible = true;
|
|
task.Start();
|
|
await task;
|
|
loading.Visible = false;
|
|
}
|
|
|
|
private void Button1_Click(object sender, EventArgs e)
|
|
{
|
|
AddDrivers newUser = new AddDrivers(this);
|
|
newUser.BringToFront();
|
|
newUser.ShowDialog();
|
|
}
|
|
public int LoadUsers()
|
|
{
|
|
try
|
|
{
|
|
dataGridView1.Invoke(new Action(() =>
|
|
{
|
|
dataGridView1.Rows.Clear();
|
|
i = 1;
|
|
cn.Open();
|
|
cm = new SqlCommand("Select driverID,firstname,surname,middlename,dateOfBirth,TT.licensePlate from tblDrivers TD Inner Join tblTrucks TT On " +
|
|
"TT.driver =TD.driverID where TD.branchID = @branchID and status = @status " +
|
|
"Select driverID,firstname,surname,middlename,dateOfBirth from tblDrivers TD where branchID = @branchID and status = @status2", cn);
|
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
|
cm.Parameters.AddWithValue("@status", "ASSIGNED");
|
|
cm.Parameters.AddWithValue("@status2", "UNASSIGNED");
|
|
cm.ExecuteNonQuery();
|
|
dr = cm.ExecuteReader();
|
|
while (dr.Read())
|
|
{
|
|
dataGridView1.Rows.Add(i, dr[0].ToString().ToUpper(), dr[1].ToString().ToUpper(), dr[2].ToString().ToUpper(), dr[3].ToString().ToUpper(),
|
|
Convert.ToDateTime(dr[4].ToString()).ToLongDateString(),dr[5].ToString().ToUpper());
|
|
|
|
i++;
|
|
}
|
|
dr.NextResult();
|
|
while (dr.Read())
|
|
{
|
|
dataGridView1.Rows.Add(i, dr[0].ToString().ToUpper(), dr[1].ToString().ToUpper(), dr[2].ToString().ToUpper(), dr[3].ToString().ToUpper(),
|
|
Convert.ToDateTime(dr[4].ToString()).ToLongDateString());
|
|
i++;
|
|
}
|
|
dr.Close();
|
|
cn.Close();
|
|
dataGridView1.ClearSelection();
|
|
}));
|
|
return 1;
|
|
}
|
|
catch
|
|
{
|
|
cn.Close();
|
|
return 2;
|
|
}
|
|
}
|
|
public void addToList(string driverID,string firstname,string surname,string middlename,DateTime DOB)
|
|
{
|
|
dataGridView1.Rows.Add(i, driverID, firstname.ToUpper(), surname.ToUpper(), middlename.ToUpper(), Convert.ToDateTime(DOB).ToLongDateString());
|
|
i++;
|
|
}
|
|
private void dataGridView1_CellContentClick(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 driver's record, deleting a driver will his truck unavailable " +
|
|
"for order assignments until a new driver is assigned to the truck";
|
|
Confirmation confirmation = new Confirmation(title, message);
|
|
confirmation.BringToFront();
|
|
confirmation.ShowDialog();
|
|
if (confirmation.DialogResult == DialogResult.Yes)
|
|
{
|
|
cn.Open();
|
|
cm = new SqlCommand("Delete from tblDrivers where driverID = @driverID and branchID = @branch " +
|
|
"Update tblTrucks set driver = '' where driver = @driverID and branchID = @branch", cn);
|
|
cm.Parameters.AddWithValue("@driverID", dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
|
|
cm.Parameters.AddWithValue("@branch", Settings.Default.BranchID);
|
|
cm.ExecuteNonQuery();
|
|
cn.Close();
|
|
|
|
users_Load();
|
|
|
|
string titled = "Deleted Record";
|
|
string messaged = "Driver has been successfully deleted.";
|
|
NoAction noAction = new NoAction(titled, messaged);
|
|
noAction.BringToFront();
|
|
noAction.ShowDialog();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|