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.
117 lines
4.4 KiB
117 lines
4.4 KiB
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.Users
|
|
{
|
|
public partial class AddDrivers : Form
|
|
{
|
|
SqlConnection cn;
|
|
SqlCommand cm;
|
|
DatabaseConn conn = new DatabaseConn();
|
|
Drivers drivers;
|
|
string id = "";
|
|
public AddDrivers(Drivers drivers)
|
|
{
|
|
InitializeComponent();
|
|
cn = new SqlConnection(conn.MyConnection());
|
|
this.drivers = drivers;
|
|
}
|
|
public int newConductor()
|
|
{
|
|
try
|
|
{
|
|
txtFirstname.Invoke(new Action(() =>
|
|
{
|
|
cn.Open();
|
|
id = Settings.Default.BranchID + (String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000) + "DR");
|
|
cm = new SqlCommand("Insert into tblDrivers (driverID,firstname,surname,middlename,dateOfBirth,address1,address2,telephone,email,state," +
|
|
"status,city,branchID) values (@driverID,@firstname,@surname,@middlename,@dateOfBirth,@address1,@address2,@telephone,@email,@state,@status," +
|
|
"@city,@branchID)", cn);
|
|
cm.Parameters.AddWithValue("@driverID", id);
|
|
cm.Parameters.AddWithValue("@firstname", txtFirstname.Text);
|
|
cm.Parameters.AddWithValue("@surname", txtSurname.Text);
|
|
cm.Parameters.AddWithValue("@middlename", txtMiddlename.Text);
|
|
cm.Parameters.AddWithValue("@dateOfBirth", dateofbirth.Value.ToString("yyyy-MM-dd"));
|
|
cm.Parameters.AddWithValue("@address1", txtStreet.Text);
|
|
cm.Parameters.AddWithValue("@address2", txtStreet2.Text);
|
|
cm.Parameters.AddWithValue("@telephone", txtTelephone.Text);
|
|
cm.Parameters.AddWithValue("@email", txtEmail.Text);
|
|
cm.Parameters.AddWithValue("@state", txtState.Text);
|
|
cm.Parameters.AddWithValue("@city", txtCityLocale.Text);
|
|
cm.Parameters.AddWithValue("@status", "UNASSIGNED");
|
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
|
cm.ExecuteNonQuery();
|
|
cn.Close();
|
|
}));
|
|
return 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
cn.Close();
|
|
ErrorLogging.WriteToFile(ex.ToString());
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
private async void Button1_Click(object sender, EventArgs e)
|
|
{
|
|
Task<int> task = new Task<int>(newConductor);
|
|
loading.Visible = true;
|
|
task.Start();
|
|
int result = await task;
|
|
if (result == 1)
|
|
{
|
|
drivers.addToList(id, txtFirstname.Text, txtSurname.Text, txtMiddlename.Text, dateofbirth.Value);
|
|
string title = "Success";
|
|
string message = "New truck driver added successfully";
|
|
NoAction noAction = new NoAction(title, message);
|
|
noAction.BringToFront();
|
|
noAction.ShowDialog();
|
|
clearBoxes();
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
string title = "Error Occurred";
|
|
string message = "An error occurred while trying to add a new truck driver";
|
|
NoAction noAction = new NoAction(title, message);
|
|
noAction.BringToFront();
|
|
noAction.ShowDialog();
|
|
}
|
|
loading.Visible = false;
|
|
}
|
|
private void clearBoxes()
|
|
{
|
|
try
|
|
{
|
|
foreach (Control c in content.Controls)
|
|
{
|
|
if (c is TextBox)
|
|
{
|
|
c.Text = "";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLogging.WriteToFile(ex.ToString());
|
|
}
|
|
}
|
|
private void Button2_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
|