public void btnRefresh_Click(object sender, EventArgs e) { //a refresh button in order to refresh the data from the database //if statemnet checking for the text in the title label so after refreshing will load the form with all matching properties for the user that is logged in if (label1.Text == "LC DELIVERIES") { DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "LC DELIVERIES"; DeliveriesForm.btnBackLCDeliveries.Visible = true; DeliveriesForm.btnBackdeliveriesAdmin.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = true; DeliveriesForm.btnEditLCDeliveries.Visible = true; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; } else if (label1.Text == "ADMIN DELIVERIES") { DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "ADMIN DELIVERIES"; DeliveriesForm.btnBackLCDeliveries.Visible = false; DeliveriesForm.btnBackdeliveriesAdmin.Visible = true; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; DeliveriesForm.btnEditLCDeliveries.Visible = false; } }
public void btnCancelAdd_Click(object sender, EventArgs e) { //if for canceling to add a new delivery and checking who is logged in if (label1.Text == "LC DELIVERIES") { //depending on who is logged in hides and shows buttons when loading the form DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "LC DELIVERIES"; DeliveriesForm.btnBackLCDeliveries.Visible = true; DeliveriesForm.btnBackdeliveriesAdmin.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = true; DeliveriesForm.btnBackLCDeliveries.Visible = true; DeliveriesForm.btnSaveDeliveries.Visible = false; DeliveriesForm.btnCancelAdd.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; } else if (label1.Text == "ADMIN DELIVERIES") { //depending on who is logged in hides and shows buttons when loading the form DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "ADMIN DELIVERIES"; DeliveriesForm.btnBackLCDeliveries.Visible = false; DeliveriesForm.btnBackdeliveriesAdmin.Visible = true; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; DeliveriesForm.btnBackLCDeliveries.Visible = false; } }
private void button2_Click(object sender, EventArgs e) { //if for checking the title text if (lblTitle.Text == "WELCOME ADMIN") { //hiding, showing the correct buttons depending on the label text that we changed when logged in Admin and loads the delivery form with changed title label DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "ADMIN DELIVERIES"; DeliveriesForm.btnEditLCDeliveries.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; DeliveriesForm.btnBackLCDeliveries.Visible = false; } else if (lblTitle.Text == "WELCOME LC") { //hiding, showing the correct buttons depending on the label text that we changed when logged in LC and loads the delivery form with changed title label DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "LC DELIVERIES"; DeliveriesForm.btnSaveEditDeliveryLC.Visible = true; DeliveriesForm.btnBackLCDeliveries.Visible = true; DeliveriesForm.btnBackdeliveriesAdmin.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; } }
public void btnDeleteDeliverie_Click(object sender, EventArgs e) { //setting DataSet to populate with the data I use the same name as in my customer form dsCustomer = new DataSet(); //in order to read the dataabse sql code is used as shown below String Update = "DELETE FROM DeliveriesTbl WHERE DeliveriesID='" + txtboxDeliverieID.Text + "'"; //seting a new sql connection based on my already loaded one SqlConnection conn = new SqlConnection(newCon.ConnectionString); SqlCommand cmd = new SqlCommand(Update, conn); SqlDataReader read; //try and catch n order to confirm if the record has been deleted try { //open the database connection conn.Open(); //read the cmd reader and assign to read read = cmd.ExecuteReader(); MessageBox.Show("Record Deleted"); } catch { MessageBox.Show("Not able to Delete the record from the databse "); } conn.Close(); //if checking the titile label so it will load the corect functions when the delete button is pressed if (label1.Text == "ADMIN DELIVERIES") { DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "ADMIN DELIVERIES"; DeliveriesForm.btnEditLCDeliveries.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; DeliveriesForm.btnBackLCDeliveries.Visible = false; } else if (label1.Text == "LC DELIVERIES") { DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "LC DELIVERIES"; DeliveriesForm.btnSaveEditDeliveryLC.Visible = true; DeliveriesForm.btnBackLCDeliveries.Visible = true; DeliveriesForm.btnBackdeliveriesAdmin.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; } }
public void btnSaveEditDeliveryLC_Click(object sender, EventArgs e) { DateTime startTime = Convert.ToDateTime("08:30"); DateTime endTime = Convert.ToDateTime("16:30"); DateTime cStartTime = Convert.ToDateTime(txtboxDeliverieHourStart.Text); DateTime cEndtTime = Convert.ToDateTime(txtboxDeliveryHourEnd.Text); if (cStartTime > startTime && cEndtTime < endTime) { String Update = "UPDATE DeliveriesTbl SET DeliveryHoursStart='" + txtboxDeliverieHourStart.Text + "', DeliveryHoursEnd='" + txtboxDeliveryHourEnd.Text + "', DeliveryDayStart='" + txtboxDeliverieDayStart.Text + "', DeliveryDayEnd='" + txtboxDeliverieDayEnd.Text + "', CourierID='" + txtboxCourierID.Text + "', Contracted='" + txtboxContracted.Text + "' WHERE DeliveriesID='" + txtboxDeliverieID.Text + "'"; SqlConnection conn = new SqlConnection(newCon.ConnectionString); SqlCommand cmd = new SqlCommand(Update, conn); SqlDataReader read; try { //open the database connection conn.Open(); read = cmd.ExecuteReader(); MessageBox.Show("Record Updated"); } catch { MessageBox.Show("Not able to update the databse "); } //closing the databse connection conn.Close(); //if checking which form properties to load when the editsave button is pressed if (label1.Text == "LC DELIVERIES") { DeliveriesForm DeliveriesForm = new DeliveriesForm(); this.Hide(); DeliveriesForm.Show(); DeliveriesForm.label1.Text = "LC DELIVERIES"; DeliveriesForm.btnSaveEditDeliveryLC.Visible = true; DeliveriesForm.btnBackLCDeliveries.Visible = true; DeliveriesForm.btnBackdeliveriesAdmin.Visible = false; DeliveriesForm.btnSaveEditDeliveryLC.Visible = false; } } else { MessageBox.Show("Delivery times must be betwen 08:30 and 16:30"); } }