private void btnUpdateDeliveryBooking_Click(object sender, EventArgs e) { if (cbxDeliveryID.SelectedItem == null || cbxDeliveryID.SelectedItem.ToString() == "New...") { MessageBox.Show("Cannot Update"); } else { ComboBoxItems truckidvar = (ComboBoxItems)cbxBookingTruckID.SelectedItem; ComboBoxItems staffidvar = (ComboBoxItems)cbxBookingStaffID.SelectedItem; ComboBoxItems clientidvar = (ComboBoxItems)cbxBookingClientID.SelectedItem; ComboBoxItems goodidvar = (ComboBoxItems)cbxBookingGoodsID.SelectedItem; ComboBoxItems driveridvar = (ComboBoxItems)cbxBookingDriverID.SelectedItem; cmd.Parameters.AddWithValue("@truckb_id", truckidvar.value); cmd.Parameters.AddWithValue("@staffb_id", staffidvar.value); cmd.Parameters.AddWithValue("@clientb_id", clientidvar.value); cmd.Parameters.AddWithValue("@goodb_id", goodidvar.value); cmd.Parameters.AddWithValue("@driverb_id", driveridvar.value); cmd.Parameters.AddWithValue("@dateb_id", Convert.ToDateTime(tbxBookingDateMade.Text).Date); cmd.Parameters.AddWithValue("@delivDistb_id", tbxDeliveryDistance.Text); cmd.Parameters.AddWithValue("@Notesb_id", rtbBookingNotes.Text); cmd.Parameters.AddWithValue("@DepartDateb_id", Convert.ToDateTime(tbxDepartureDate.Text).Date); cmd.Parameters.AddWithValue("@DepartStreetNameb_id", tbxDepartureStreetName.Text); cmd.Parameters.AddWithValue("@DepartAdrNumb_id", tbxDepartureAdrNumber.Text); cmd.Parameters.AddWithValue("@DepartAdrAreab_id", tbxDepartureAdrArea.Text); cmd.Parameters.AddWithValue("@Depart_cityb_id", tbxDepartureCity.Text); cmd.Parameters.AddWithValue("@ArrivalDateb_id", Convert.ToDateTime(tbxArrivalDate.Text).Date); cmd.Parameters.AddWithValue("@ArrivalStreetNameb_id", tbxArrivalStreetName.Text); cmd.Parameters.AddWithValue("@ArrivalAdrNumberb_id", tbxArrivalAdrNumber.Text); cmd.Parameters.AddWithValue("@ArrivalAdrAreab_id", tbxArrivalAdrArea.Text); cmd.Parameters.AddWithValue("@ArrivalCityb_id", tbxArrivalCity.Text); string update = "UPDATE BookingTruck SET booking_date_made = @dateb_id,booking_departure_date = @DepartDateb_id,booking_arrival_date = @ArrivalDateb_id,departure_street_number = @DepartStreetNameb_id,departure_street_name = @DepartStreetNameb_id,departure_street_area = @DepartAdrAreab_id,departure_city = @Depart_cityb_id,arrival_street_number = @ArrivalAdrNumberb_id,arrival_street_name = @ArrivalStreetNameb_id,arrival_street_area = @ArrivalAdrAreab_id,arrival_city = @ArrivalCityb_id,truck_id = @truckb_id,staff_id = @staffb_id,goods_id = @goodb_id,booking_notes = @Notesb_id,client_id = @clientb_id,driver_id = @driverb_id,delivery_distance = @delivDistb_id WHERE booking_id = @updateID"; try { cmd.Connection = conn; cmd.CommandText = update; conn.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("Successfully Updated Delivery"); } catch (Exception error) { MessageBox.Show("Error: " + error.Message); } finally { conn.Close(); this.Close(); } } }
private void btnSendMail_Click(object sender, EventArgs e) { if (txtBxMessage.Text == "" || txtBxSubject.Text == "") { MessageBox.Show("Please provide information to send."); } else { ComboBoxItems item = (ComboBoxItems)cmbClients.SelectedItem; string toSend = item.value; string subject = txtBxSubject.Text; string message = txtBxMessage.Text; email.handleEmail("normal", toSend, message, subject); } }
private void btnAddDeliveryBooking_Click(object sender, EventArgs e) { int clientlog = -1; string emaill = ""; int deliveryid = -1; if (cbxDeliveryID.SelectedItem != null) { if (cbxDeliveryID.SelectedItem.ToString() == "New...") { Boolean stop = false; stop = checkIfNotNull(cbxBookingTruckID); stop = checkIfNotNull(cbxBookingStaffID); stop = checkIfNotNull(cbxBookingClientID); stop = checkIfNotNull(cbxBookingGoodsID); stop = checkIfNotNull(cbxBookingDriverID); stop = checkIfNotNull(tbxBookingDateMade.Text); stop = checkIfNotNull(tbxDeliveryDistance.Text); stop = checkIfNotNull(rtbBookingNotes.Text); stop = checkIfNotNull(tbxDepartureDate.Text); stop = checkIfNotNull(tbxDepartureStreetName.Text); stop = checkIfNotNull(tbxDepartureAdrNumber.Text); stop = checkIfNotNull(tbxDepartureAdrArea.Text); stop = checkIfNotNull(tbxDepartureCity.Text); stop = checkIfNotNull(tbxArrivalDate.Text); stop = checkIfNotNull(tbxArrivalStreetName.Text); stop = checkIfNotNull(tbxArrivalAdrNumber.Text); stop = checkIfNotNull(tbxArrivalAdrArea.Text); stop = checkIfNotNull(tbxArrivalCity.Text); if (stop == false) { MessageBox.Show("Unable to Add, Please make sure that all fields are filled-in"); } else { //peform insert ComboBoxItems truckidvar = (ComboBoxItems)cbxBookingTruckID.SelectedItem; ComboBoxItems staffidvar = (ComboBoxItems)cbxBookingStaffID.SelectedItem; ComboBoxItems clientidvar = (ComboBoxItems)cbxBookingClientID.SelectedItem; ComboBoxItems goodidvar = (ComboBoxItems)cbxBookingGoodsID.SelectedItem; ComboBoxItems driveridvar = (ComboBoxItems)cbxBookingDriverID.SelectedItem; cmd.Parameters.AddWithValue("@truckb_id", truckidvar.value); cmd.Parameters.AddWithValue("@staffb_id", staffidvar.value); cmd.Parameters.AddWithValue("@clientb_id", clientidvar.value); cmd.Parameters.AddWithValue("@goodb_id", goodidvar.value); cmd.Parameters.AddWithValue("@driverb_id", driveridvar.value); cmd.Parameters.AddWithValue("@dateb_id", Convert.ToDateTime(tbxBookingDateMade.Text).Date); cmd.Parameters.AddWithValue("@delivDistb_id", tbxDeliveryDistance.Text); cmd.Parameters.AddWithValue("@Notesb_id", rtbBookingNotes.Text); cmd.Parameters.AddWithValue("@DepartDateb_id", Convert.ToDateTime(tbxDepartureDate.Text).Date); cmd.Parameters.AddWithValue("@DepartStreetNameb_id", tbxDepartureStreetName.Text); cmd.Parameters.AddWithValue("@DepartAdrNumb_id", tbxDepartureAdrNumber.Text); cmd.Parameters.AddWithValue("@DepartAdrAreab_id", tbxDepartureAdrArea.Text); cmd.Parameters.AddWithValue("@Depart_cityb_id", tbxDepartureCity.Text); cmd.Parameters.AddWithValue("@ArrivalDateb_id", Convert.ToDateTime(tbxArrivalDate.Text).Date); cmd.Parameters.AddWithValue("@ArrivalStreetNameb_id", tbxArrivalStreetName.Text); cmd.Parameters.AddWithValue("@ArrivalAdrNumberb_id", tbxArrivalAdrNumber.Text); cmd.Parameters.AddWithValue("@ArrivalAdrAreab_id", tbxArrivalAdrArea.Text); cmd.Parameters.AddWithValue("@ArrivalCityb_id", tbxArrivalCity.Text); string insertStr = "INSERT INTO BookingTruck (booking_date_made,booking_departure_date,booking_arrival_date,departure_street_number,departure_street_name,departure_street_area,departure_city,arrival_street_number,arrival_street_name,arrival_street_area,arrival_city,truck_id,staff_id,goods_id,booking_notes,client_id,driver_id,delivery_distance) VALUES(@dateb_id,@DepartDateb_id,@ArrivalDateb_id,@DepartAdrNumb_id,@DepartStreetNameb_id,@DepartAdrAreab_id,@Depart_cityb_id,@ArrivalAdrNumberb_id,@ArrivalStreetNameb_id,@ArrivalAdrAreab_id,@ArrivalCityb_id,@truckb_id,@staffb_id,@goodb_id,@Notesb_id,@clientb_id,@driverb_id,@delivDistb_id); SELECT CAST(scope_identity() AS int)"; try { cmd.Connection = conn; cmd.CommandText = insertStr; conn.Open(); deliveryid = (int)cmd.ExecuteScalar(); MessageBox.Show("Successfully Added Booking"); } catch (Exception error) { MessageBox.Show("Error: " + error.Message); } finally { conn.Close(); string exec = "SELECT * FROM Clients WHERE client_id = @clientb_id"; try { cmd.CommandText = exec; cmd.Connection = conn; conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { clientlog = (Int32)reader["client_login"]; } conn.Close(); string find = "SELECT * FROM ClientLogin WHERE clientLogin_id = @cliLog"; if (cmd.Parameters.Contains("@cliLog")) { cmd.Parameters["@cliLog"].Value = clientlog; } else { cmd.Parameters.AddWithValue("@cliLog", clientlog); } cmd.Connection = conn; cmd.CommandText = find; conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { emaill = reader["clientMail"].ToString(); } } catch (Exception error) { MessageBox.Show("Error: " + error.Message); } conn.Close(); //Send XML Parsed Email if (emaill == "" || deliveryid == -1 || clientlog == -1) { MessageBox.Show("Something went wrong"); } else { email.handleEmail("booking", emaill, "", deliveryid.ToString()); } this.Close(); } } } else { MessageBox.Show("Please select the New... option from the delivery ID dropdown"); } } else { MessageBox.Show("Please select the New... option from the delivery ID dropdown"); } }