protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                UK_Film_Location_Class.BookingDetails objBooking = new UK_Film_Location_Class.BookingDetails();
                UK_Film_Location_Class.BookingDates objDate = new UK_Film_Location_Class.BookingDates();

                UK_Film_Location_Class.OpportunityDetails objOpportunity = new UK_Film_Location_Class.OpportunityDetails();
                UK_Film_Location_Class.ProjectDetails objProject = new UK_Film_Location_Class.ProjectDetails();

                objBooking.BookingID = Request.QueryString["BookingID"];
                objDate.BookingDateID = Request.QueryString["BookingDateID"];

                BookingID.Value = objBooking.BookingID;
                objDate.BookingID = objBooking.BookingID;

                if (!string.IsNullOrEmpty(objDate.BookingDateID))
                {
                    objDate.getBookedDate(objDate.BookingDateID);
                    BookingDateID.Value = objDate.BookingDateID;
                    BookingID.Value = objDate.BookingID;
                }
                else
                {
                    objBooking.getBooking(objBooking.BookingID);
                    objOpportunity.getOpportunity(objBooking.OpportunityID);
                    objProject.getProjectDetails(objOpportunity.ProjectID);

                    objDate.BookingDate = DateTime.Now;
                    objDate.StartTime = "09:00";
                    objDate.EndTime = "17:00";

                    objDate.AgreedDayRate = objOpportunity.LocationRate;
                    try
                    {
                        objDate.NoCrew = Convert.ToInt32(objOpportunity.NoCrew);
                    }
                    catch
                    {
                    }
                }

              //          ErrorLabel.Text = "BookingID : " + BookingID.Value;

                DateTextBox.Text = objDate.BookingDate.ToShortDateString();
                StartTimeTextBox.Text = objDate.StartTime;
                FinishTimeTextBox.Text = objDate.EndTime;
                NotesTextBox.Text = objDate.Notes;
                DateTextBox.Text = UK_Film_Location_Class.UKFilmLocation.makeSQLShortDate(objDate.BookingDate.ToString());
                NoCastCrewTextBox.Text = objDate.NoCrew.ToString();
                AgreedDayRateTextBox.Text = objDate.AgreedDayRate.ToString("0.00");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string UserEmail = "";

            HttpCookie myTestCookie = new HttpCookie("UKFilmLocationAdmin");
            myTestCookie = Request.Cookies["UKFilmLocationAdmin"];

            // Read the cookie information and display it.
            if (myTestCookie != null)
            {
                // User details collected

                UserEmail = myTestCookie.Value;

            }
            else
            {
                // No user cookie redirect to login

                Response.Redirect("/");
            }

            if (!IsPostBack)
            {

                DBConnection = new MySqlConnection(objUKFilmLocation.DBConnect);
                DBCommand = DBConnection.CreateCommand();

                string thisOpportunityID = Request.QueryString["OpportunityID"];
                string thisRecceID = Request.QueryString["RecceID"];

                UK_Film_Location_Class.RecceDates objRecceDate = new UK_Film_Location_Class.RecceDates();

                UK_Film_Location_Class.OpportunityDetails objOpportunity = new UK_Film_Location_Class.OpportunityDetails();
                UK_Film_Location_Class.LocationDetails objLocation = new UK_Film_Location_Class.LocationDetails();
                UK_Film_Location_Class.ContactDetails objLocationContact = new UK_Film_Location_Class.ContactDetails();
                UK_Film_Location_Class.ContactDetails objProjectCompany = new UK_Film_Location_Class.ContactDetails();
                UK_Film_Location_Class.ProjectDetails objProject = new UK_Film_Location_Class.ProjectDetails();

                if (!string.IsNullOrEmpty(thisRecceID))
                {
                    objRecceDate.getRecceAppointment(thisRecceID);
                    thisOpportunityID = objRecceDate.OpportunityID;

                    RecceDate.Text = UK_Film_Location_Class.UKFilmLocation.makeSQLShortDate(objRecceDate.RecceDate.ToShortDateString());
                    RecceTime.Text = objRecceDate.Time;
                    RecceNotes.Text = objRecceDate.Notes;

                }
                else
                {
                    RecceDate.Text = UK_Film_Location_Class.UKFilmLocation.makeSQLShortDate(DateTime.Now.ToShortDateString() );
                    RecceTime.Text = "00:00";
                }

                objOpportunity.getOpportunity(thisOpportunityID);

                objLocation.getLocationFromID(objOpportunity.LocationID);

                objLocationContact.getContact(objLocation.ContactID);

                objProjectCompany.getContact(objOpportunity.ContactID);

                objProject.getProjectDetails(objOpportunity.ProjectID);

                if (objRecceDate.RecordID > 0)
                {
                    ViewReccePDFLiteral.Text = " <a target=\"_blank\" href=\"http://ukfilmlocation.com/RecceAppointment.php?RecceDateID=" + objRecceDate.RecordID + "&Recipient=" + objProjectCompany.ContactID + "\" class=\"btn-default btn\">View Recce PDF&nbsp;<i class=\"fa fa-file-pdf-o\" title=\"Contact Details\"></i></a>";
                }

                JobRefLiteral.Text = "<a href=\"/OpportunityDetails.aspx?OpportunityID=" + objOpportunity.OpportunityID + "\">J" + objProject.RecordID + " / " + objOpportunity.LocationID + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Opportunity Details\"></i></a>";

                LocationLiteral.Text = "<p>Recce request for location <b><a href=\"/LocationDetails.aspx?LocationID=" + objLocation.LocationID + "\">" + objLocation.LocationID + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Location Details\"></i></a></b><br>" + objLocation.Title + "</p><br><br><p>Job Ref : <a href=\"/OpportunityDetails.aspx?OpportunityID=" + objOpportunity.OpportunityID + "\">J" + objProject.RecordID + " - " + objProject.WorkingTitle + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Opportunity Details\"></i></a></p><p>Location Contact : <a href=\"/ContactDetails.aspx?ContactID=" + objLocationContact.ContactID + "\">" + objLocationContact.Name + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Contact Details\"></i></a><br>Tel : " + objLocationContact.Tel + "<br>Mobile : " + objLocationContact.Mobile + "<br>Email : " + objLocationContact.Email + "</p><br><br><p>Project Company Contact : <a href=\"/ContactDetails.aspx?ContactID=" + objProjectCompany.ContactID + "\">" + objProjectCompany.Name + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Contact Details\"></i></a><br>Tel : " + objProjectCompany.Tel + "<br>Mobile : " + objProjectCompany.Mobile + "<br>Email : " + objProjectCompany.Email + "</p>";

                // Populate  Purpose Drop down

                DBConnection.Open();

                DBCommand.CommandText = "select RecordID, value from ReccePurposes;";

                DBResult = DBCommand.ExecuteReader();

                DataTable myData = new DataTable();

                myData.Load(DBResult);

                DataView myview = myData.DefaultView;
                myview.Sort = "RecordID asc";

                DBResult.Close();

                DBConnection.Close();

                ReccePurposeDropDownList.DataSource = myview;
                ReccePurposeDropDownList.DataTextField = "Value";
                ReccePurposeDropDownList.DataValueField = "Value";
                ReccePurposeDropDownList.DataBind();

                ReccePurposeDropDownList.SelectedValue = objRecceDate.Purpose;

                //ListItem list = new ListItem();

                //list = new ListItem();
                //list.Text = "Other";
                //list.Value = "";

                //ReccePurposeDropDownList.Items.Add(list);

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string thisID = Request.QueryString["RecceID"];

            if (!string.IsNullOrEmpty(thisID))
            {
                string Message = "";

                HttpCookie myTestCookie = new HttpCookie("UKFilmLocationAdmin");
                myTestCookie = Request.Cookies["UKFilmLocationAdmin"];

                UK_Film_Location_Class.UserDetails objUser = new UK_Film_Location_Class.UserDetails();
                objUser.getUserFromEmail(myTestCookie.Value);

                UK_Film_Location_Class.RecceDates objRecce = new UK_Film_Location_Class.RecceDates();
                objRecce.getRecceAppointment(thisID);

                UK_Film_Location_Class.OpportunityDetails objOpportunity = new UK_Film_Location_Class.OpportunityDetails();
                objOpportunity.getOpportunity(objRecce.OpportunityID);

                UK_Film_Location_Class.ContactDetails objProductionContact = new UK_Film_Location_Class.ContactDetails();
                objProductionContact.getContact(objOpportunity.ContactID);

                UK_Film_Location_Class.LocationDetails objLocation = new UK_Film_Location_Class.LocationDetails();
                objLocation.getLocationFromID(objOpportunity.LocationID);

                UK_Film_Location_Class.ContactDetails objLocationContact = new UK_Film_Location_Class.ContactDetails();
                objLocationContact.getContact(objLocation.ContactID);

                // Check Fields

                // Update or Create Record

                DBConnection = new MySqlConnection(objUKFilmLocation.DBConnect);
                DBCommand = DBConnection.CreateCommand();

                // Location Address

                string thisAddress = "";

                if (!string.IsNullOrEmpty(objLocation.Address)) thisAddress += objLocation.Address;
                if (!string.IsNullOrEmpty(objLocation.Street)) thisAddress += ", " + objLocation.Street;
                if (!string.IsNullOrEmpty(objLocation.Town)) thisAddress += ", " + objLocation.Town;
                if (!string.IsNullOrEmpty(objLocation.County)) thisAddress += ", " + objLocation.County;
                if (!string.IsNullOrEmpty(objLocation.Postcode)) thisAddress += ", " + objLocation.Postcode;

                DBConnection.Open();

                // Update Record
                DBCommand.CommandText = "update Tasks set IsComplete = '1', DateComplete = '" + UK_Film_Location_Class.UKFilmLocation.makeSQLDate(DateTime.Now.ToString()) + "' where TaskAttributes = '" + thisID + "' and TaskAction = 'RECCE REQUEST'";

                DBCommand.ExecuteNonQuery();

                DBConnection.Close();

                DBConnection.Open();

                // Update Record
                DBCommand.CommandText = "update RecceDates set EmailSent = '" + UK_Film_Location_Class.UKFilmLocation.makeSQLDate(DateTime.Now.ToString()) + "' where RecordID = '" + thisID + "'";

                DBCommand.ExecuteNonQuery();

                DBConnection.Close();

                // Send Owner Email

                Message = "<p>" + objLocationContact.Name + ", we are pleased to confirm the date(s) of the recce for " + objProductionContact.Name + " at location " + objLocation.LocationID + ". </p>";

                Message += "<p>";

                Message += "Below are the details of the confirmed recce booking. You can also view all your recce requests on our website, <a href=\"http://ukfilmlocation.dev/MyRecces.aspx\">click here</a>. If you have any questions please let us know, telephone 0844 669 5245.</p>";

                Message += "<p>You can download a PDF version of this appointment by <a target=\"_blank\" href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/RecceAppointment.php?RecceDateID=" + thisID + "&Recipient=" + objLocationContact.ContactID + "\">clicking here</a>.</p>";

                Message += "<h2>Recce Details</h2>";

                Message += "<p>Location Ref : <a href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/Location.aspx?LocationID=" + objLocation.LocationID + "\">" + objLocation.LocationID + "</a><br>";

                Message += "Address : " + thisAddress + "</p>";

                Message += "<p>";
                //        Message += "<p>Date Of Recce : " + DateTime.Parse(RecceDateLiteral.Text).ToShortDateString() + "<br>";
                //    Message += "Time Of Recce : " + RecceTimeLiteral.Text + "<br>";
                Message += "Contact : " + objProductionContact.Name + "<br>";
                Message += "Contact Tel : " + objProductionContact.Tel + "<br>";
                Message += "Contact Mobile : " + objProductionContact.Mobile + "<br>";
                //    Message += "Notes : " + RecceNotesTextBox.Text;
                Message += "</p>";

                Message += "<h2>Recce Details</h2>";

                Message += "<p>";
                if (!string.IsNullOrEmpty(objRecce.RecceDate.ToShortDateString())) Message += "Date Of Recce : " + objRecce.RecceDate.ToShortDateString().Replace(" 00:00:00", "") + "<br>";
                if (!string.IsNullOrEmpty(objRecce.Time)) Message += "Time Of Recce : " + objRecce.Time + "<br>";

                if (!string.IsNullOrEmpty(objOpportunity.TypeOfShoot)) Message += "Type Of Shoot : " + objOpportunity.TypeOfShoot + "<br>";
                //if (!string.IsNullOrEmpty(AgreedRateTextBox.Text)) Message += "Agreed Agency Rate % : " + AgreedRateTextBox.Text + "<br>";
                if (!string.IsNullOrEmpty(objRecce.Notes)) Message += "Notes : " + objRecce.Notes.Replace("\n", "<br>");
                Message += "</p>";

                Message += "<p>Agent : " + objUser.FirstName + " " + objUser.LastName + "<br>";
                Message += "Agent Email : " + objUser.Email + "<br>";
                Message += "Agent Tel : 0844 669 5245 / 01782 388090</p>";

                Message += "<p>We appreciate your feedback, please let us know how it went.</p>";

                Message += "<p><i>UKFilmLocation.com</i><br>";
                Message += "Tel 0844 669 5245</p>";

                UK_Film_Location_Class.UKFilmLocation.sendEmail(objLocationContact.Email, objUser.FirstName + " " + objUser.LastName, objUser.Email, "UKFilmLocation.com - Recce Confirmation for Location: " + objLocation.LocationID + " (" + UK_Film_Location_Class.LocationDetails.getTitleFromID(objLocation.LocationID) + ")", Message);

                // Send Project Company Email

                // Send emails

                Message = "<p>" + objProductionContact.Name + ", we are pleased to confirm the date(s) of your recce at location " + objLocation.LocationID + ". We hope the location lives up to your expectations.</p><p>You can download a printable PDF for this location by <a href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/LocationPDF.php?LocationID=" + objLocation.LocationID + "\" target=\"_blank\">clicking here</a>.</p>";

                Message += "<p>";

                Message += "Below are the details of the confirmed recce booking. You can also view all your recce requests on our website, <a href=\"http://ukfilmlocation.dev/MyRecces.aspx\">click here</a>. If you have any questions please let us know, telephone 0844 669 5245.</p>";

                Message += "<p>You can download a PDF version of this appointment by <a target=\"_blank\" href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/RecceAppointment.php?RecceDateID=" + thisID + "&Recipient=" + objProductionContact.ContactID + "\">clicking here</a>.</p>";

                Message += "<h2>Recce Details</h2>";

                Message += "<p>Location Ref : <a href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/Location.aspx?LocationID=" + objLocation.LocationID + "\">" + objLocation.LocationID + "</a><br>";
                Message += "Address : " + thisAddress + "</p>";

                Message += "<p>";
                // Date Of Recce : " + DateTime.Parse(RecceDateLiteral.Text).ToShortDateString() + "<br>";
                // Message += "Time Of Recce : " + RecceTimeLiteral.Text + "<br>";
                Message += "Owner : " + objLocationContact.Name + "<br>";
                Message += "Owner Tel : " + objLocationContact.Tel + "<br>";
                Message += "Owner Mobile : " + objLocationContact.Mobile + "<br>";
                // Message += "Notes : " + RecceNotesTextBox.Text;
                Message += "</p>";

                Message += "<h2>Recce Details</h2>";

                Message += "<p>";
                if (!string.IsNullOrEmpty(objRecce.RecceDate.ToShortDateString())) Message += "Date Of Recce : " + objRecce.RecceDate.ToShortDateString().Replace(" 00:00:00", "") + "<br>";
                if (!string.IsNullOrEmpty(objRecce.Time)) Message += "Time Of Recce : " + objRecce.Time + "<br>";

                if (!string.IsNullOrEmpty(objOpportunity.TypeOfShoot)) Message += "Type Of Shoot : " + objOpportunity.TypeOfShoot + "<br>";
                //if (!string.IsNullOrEmpty(AgreedRateTextBox.Text)) Message += "Agreed Agency Rate % : " + AgreedRateTextBox.Text + "<br>";
                if (!string.IsNullOrEmpty(objRecce.Notes)) Message += "Notes : " + objRecce.Notes.Replace("\n", "<br>");
                Message += "</p>";

                Message += "<p>Agent : " + objUser.FirstName + " " + objUser.LastName + "<br>";
                Message += "Agent Email : " + objUser.Email + "<br>";
                Message += "Agent Tel : 0844 669 5245 / 01782 388090</p>";

                Message += "<p><i>UKFilmLocation.com</i><br>";
                Message += "Tel 0844 669 5245</p>";

                UK_Film_Location_Class.UKFilmLocation.sendEmail(objProductionContact.Email, objUser.FirstName + " " + objUser.LastName, objUser.Email, "UKFilmLocation.com - Recce Confirmation for Location: " + objLocation.LocationID + " (" + UK_Film_Location_Class.LocationDetails.getTitleFromID(objLocation.LocationID) + ")", Message);

                Response.Redirect("/OpportunityDetails.aspx?OpportunityID=" + objOpportunity.OpportunityID);
            }

            DBConnection.Dispose();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string UserEmail = "";

            HttpCookie myTestCookie = new HttpCookie("UKFilmLocationAdmin");
            myTestCookie = Request.Cookies["UKFilmLocationAdmin"];

            // Read the cookie information and display it.
            if (myTestCookie != null)
            {
                // User details collected

                UserEmail = myTestCookie.Value;

            }
            else
            {
                // No user cookie redirect to login

                Response.Redirect("/");
            }

            if (!IsPostBack)
            {

                UK_Film_Location_Class.UserDetails objUser = new UK_Film_Location_Class.UserDetails();

                objUser.getUserFromEmail(UserEmail);

                UK_Film_Location_Class.BookingDetails objBooking = new UK_Film_Location_Class.BookingDetails();
                UK_Film_Location_Class.OpportunityDetails objOpportunity = new UK_Film_Location_Class.OpportunityDetails();

                objBooking.UserID = objUser.RecordID.ToString();
                objBooking.BookingID = Request.QueryString["BookingID"];
                objOpportunity.OpportunityID = Request.QueryString["OpportunityID"];

                if (!string.IsNullOrEmpty(objBooking.BookingID))
                {
                    objBooking.getBooking(objBooking.BookingID);
                    objOpportunity.OpportunityID = objBooking.OpportunityID;

                    CreatePanel.Visible = false;
                    BookingPanel.Visible = true;
                }
                else
                {
                    objBooking.DateBooked = DateTime.Now;

                    CreatePanel.Visible = true;
                    BookingPanel.Visible = false;

                }

                BookingID.Value = objBooking.BookingID;

                objOpportunity.getOpportunity(objOpportunity.OpportunityID);

                UK_Film_Location_Class.LocationDetails objLocation = new UK_Film_Location_Class.LocationDetails();
                objLocation.getLocationFromID(objOpportunity.LocationID);

                UK_Film_Location_Class.ContactDetails objLocationContact = new UK_Film_Location_Class.ContactDetails();
                objLocationContact.getContact(objLocation.ContactID);

                UK_Film_Location_Class.ContactDetails objProjectContact = new UK_Film_Location_Class.ContactDetails();
                objProjectContact.getContact(objOpportunity.ContactID);

                UK_Film_Location_Class.ProjectDetails objProject = new UK_Film_Location_Class.ProjectDetails();
                objProject.getProjectDetails(objOpportunity.ProjectID);

                if (!string.IsNullOrEmpty(objBooking.BookingID)) BookingRefLiteral.Text = "(" + objBooking.BookingID + ") <a class=\"btn-default btn\" target=\"_blank\" href=\"/BookingFormPDF.php?BookingID=" + objBooking.BookingID + "\">Booking Form&nbsp;<i class=\"fa fa-file-pdf-o\"></i></a>";

                if (!string.IsNullOrEmpty(objBooking.ContractTemplate)) BookingRefLiteral.Text += " <a class=\"btn-default btn\" target=\"_blank\" href=\"" + objBooking.ContractTemplate + "\">Contract&nbsp;<i class=\"fa fa-file-word-o\"></i></a>";

                BookingRefLiteral.Text += " <a class=\"btn-default btn\" target=\"_blank\" href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/InvoicePDF.php?BookingID=" + objBooking.BookingID + "\">Preview Invoice&nbsp;<i class=\"fa fa-file-pdf-o\"></i></a>";

                BookingLocationLiteral.Text = "<table width=\"100%\">";

                BookingLocationLiteral.Text += "<tr><td width=\"150\" style=\"font-size: larger;\">Job Ref</td><td style=\"font-size: larger;\"><a href=\"/OpportunityDetails.aspx?OpportunityID=" + objOpportunity.OpportunityID + "\">" + objOpportunity.JobRef + "-" + objBooking.BookingID + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Opportunity Details\"></i></a></td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Project Title</td><td><a href=\"/ProjectDetails.aspx?ProjectID=" + objProject.ProjectID + "\">" + objProject.WorkingTitle + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Project Details\"></i></a></td></tr>";
                BookingLocationLiteral.Text += "</table><br>";

                BookingLocationLiteral.Text += "<table width=\"100%\">";
                BookingLocationLiteral.Text += "<tr><td width=\"150\" style=\"font-size: larger;\">Location Ref</td><td style=\"font-size: larger;\"><a href=\"/LocationDetails.aspx?LocationID=" + objOpportunity.LocationID + "\">" + objOpportunity.LocationID + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Location Details\"></i></a></td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Date Booked</td><td>" + objBooking.DateBooked.ToShortDateString() + "</td></tr>";

                BookingLocationLiteral.Text += "<tr><td>Location Contact</td><td><a href=\"/ContactDetails.aspx?ContactID=" + objLocation.ContactID + "\">" + objLocationContact.Name + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Contact Details\"></i></a></td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Company</td><td>" + objLocationContact.Company + "</td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Tel</td><td>" + objLocationContact.Tel + "</td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Mobile</td><td>" + objLocationContact.Mobile + "</td></tr>";

                BookingLocationLiteral.Text += "</table><br>";

                BookingLocationLiteral.Text += "<table width=\"100%\">";
                BookingLocationLiteral.Text += "<tr><td width=\"150\">Project Contact</td><td><a href=\"/ContactDetails.aspx?ContactID=" + objProjectContact.ContactID + "\">" + objProjectContact.Name + "&nbsp;<i class=\"fa fa-external-link-square\" title=\"Contact Details\"></i></a></td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Company</td><td>" + objProjectContact.Company + "</td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Tel</td><td>" + objProjectContact.Tel + "</td></tr>";
                BookingLocationLiteral.Text += "<tr><td>Mobile</td><td>" + objProjectContact.Mobile + "</td></tr>";
                BookingLocationLiteral.Text += "</table><br>";

                if (!string.IsNullOrEmpty(objBooking.ContractTemplate))
                {
                    BookingLocationLiteral.Text += "<p>";
                    BookingLocationLiteral.Text += "Contract Generated : <a class=\"btn-default btn\" href=\"/Bookings/" + objBooking.BookingID + "/" + objBooking.BookingID + ".docx\" target=\"_blank\">Download&nbsp;<i class=\"fa fa-file-word-o\"></i></a>";
                    BookingLocationLiteral.Text += "</p>";
                }

                BookingFeesLiteral.Text += "<table width=\"100%\">";

                BookingFeesLiteral.Text += "<tr><td>Agreed Agency Rate</td><td align=\"right\">" + objOpportunity.AgreedRate + "%</td></tr>";
                BookingFeesLiteral.Text += "<tr><td>VAT Rate</td><td align=\"right\">" + objOpportunity.VATRate + "%</td></tr>";
                BookingFeesLiteral.Text += "<tr><td>Agreed Location Rate (per day)</td><td align=\"right\">£" + objOpportunity.LocationRate.ToString("0.00") + "</td></tr>";
                BookingFeesLiteral.Text += "<tr><td>Agreed Location VAT (per day)</td><td align=\"right\">£" + objOpportunity.LocationVAT.ToString("0.00") + "</td></tr>";

            //                BookingFeesLiteral.Text += "<tr><td>Agreed Agency Fee</td><td align=\"right\">£" + objOpportunity.AgencyRate.ToString("0.00") + "</td></tr>";
            //                BookingFeesLiteral.Text += "<tr><td>Agreed Agency VAT</td><td align=\"right\">£" + objOpportunity.AgencyVAT.ToString("0.00") + "</td></tr>";

                BookingFeesLiteral.Text += "<tr><td>Location Deposit</td><td align=\"right\">£" + objOpportunity.Deposit.ToString("0.00") + "</td></tr>";
                BookingFeesLiteral.Text += "<tr><td>Damage Deposit</td><td align=\"right\">£" + objOpportunity.DamageDeposit.ToString("0.00") + "</td></tr>";

                BookingFeesLiteral.Text += "</table><br>";

                // Get list of bookings

                DBConnection = new MySqlConnection(objUKFilmLocation.DBConnect);

                DBCommand = DBConnection.CreateCommand();

                // Opportunities

                DBConnection.Open();

                DBCommand.CommandText = "select BookingDates.NoCrew, BookingDates.BookingDate, BookingDates.BookingID, BookingDates.StartTime, BookingDates.EndTime, BookingDates.Notes, BookingDates.BookingDateID, BookingDates.AgreedDayRate from BookingDates where BookingDates.BookingID = '" + objBooking.BookingID + "' order by BookingDates.BookingDate asc;";

                DBResult = DBCommand.ExecuteReader();

                int noDays = 0;

                double totalDayHire = 0;

                while (DBResult.Read())
                {
                    double AgreedRate = double.Parse(DBResult["AgreedDayRate"].ToString());

                    BookingsLiteral.Text += "<tr><td><i class=\"fa fa-calendar-o fa-2x\"></i></td><td>" + DateTime.Parse(DBResult["BookingDate"].ToString()).ToShortDateString() + "</td><td>" + DBResult["StartTime"].ToString() + "</td><td>" + DBResult["EndTime"].ToString() + "</td><td>" + DBResult["NoCrew"].ToString() + "</td><td align=\"right\" width=\"150\">£" + AgreedRate.ToString("0.00") + "</td><td align=\"right\" width=\"180\"><a href=\"/BookingDateDetails.aspx?BookingDateID=" + DBResult["BookingDateID"].ToString() + "\" class=\"btn-default btn\">View / Change</a></td></tr>";

                    BookingsLiteral.Text += "<tr><td colspan=\"3\">" + DBResult["Notes"].ToString() + "</td><td></td></tr>";

                    if (!string.IsNullOrEmpty(DBResult["AgreedDayRate"].ToString()))
                    {
                        totalDayHire += double.Parse(DBResult["AgreedDayRate"].ToString());
                    }

                    noDays++;
                }

                DBResult.Close();

                DBConnection.Close();

                if (noDays > 0) GenerateContractBTN.Visible = true;

                double thisLocationVAT = 0;

                BookingFeesLiteral.Text += "<table width=\"100%\">";
                if (objLocation.VATRegistered == "1")
                {
                    BookingFeesLiteral.Text += "<tr><td>Total Location hire for " + noDays + " days</td><td align=\"right\">£" + totalDayHire.ToString("0.00") + " + VAT = £" + ((totalDayHire * (objOpportunity.VATRate / 100)) + totalDayHire).ToString("0.00") + "</td></tr>";
                    thisLocationVAT = (totalDayHire * (objOpportunity.VATRate / 100));
                }
                else
                {
                    BookingFeesLiteral.Text += "<tr><td>Total Location hire for " + noDays + " days</td><td align=\"right\">£" + totalDayHire.ToString("0.00") + "</td></tr>";
                }

                BookingFeesLiteral.Text += "</table><br>";

                BookingFeesLiteral.Text += "<table width=\"100%\">";

                double thisAgencyFee = totalDayHire * (objOpportunity.AgreedRate / 100);
                double thisAgencyVAT = thisAgencyFee * (objOpportunity.VATRate / 100);

                BookingFeesLiteral.Text += "<tr><td>Agency Fee @ " + objOpportunity.AgreedRate.ToString() + "%</td><td align=\"right\">£" + thisAgencyFee.ToString("0.00") + "</td></tr>";
                BookingFeesLiteral.Text += "<tr><td>Agency VAT</td><td align=\"right\">£" + thisAgencyVAT.ToString("0.00") + "</td></tr>";

                BookingFeesLiteral.Text += "</table><br>";

                BookingFeesLiteral.Text += "<table width=\"100%\">";

                //    BookingFeesLiteral.Text += "Day Hire = " + totalDayHire + ", AgencyFee = " + thisAgencyFee + ", AgencyVAT = " + thisAgencyVAT + ", Location VAT = " + thisLocationVAT;

                BookingFeesLiteral.Text += "<tr><td><span style=\"font-size: larger;\">Total Hire</span></td><td align=\"right\"><span style=\"font-size: larger;\">£" + (totalDayHire + thisAgencyFee + thisAgencyVAT + thisLocationVAT).ToString("0.00") + "</span></td></tr>";
                BookingFeesLiteral.Text += "<tr><td colspan=\"2\">Plus £" + (objOpportunity.Deposit + objOpportunity.DamageDeposit).ToString("0.00") + " deposit(s)</td></tr>";
                BookingFeesLiteral.Text += "<tr><td><span style=\"font-size: larger;\">Total Payable</span></td><td align=\"right\"><span style=\"font-size: larger;\"><b>£" + (totalDayHire + thisAgencyFee + thisAgencyVAT + thisLocationVAT + objOpportunity.Deposit + objOpportunity.DamageDeposit).ToString("0.00") + "</b></span></td></tr>";

                BookingFeesLiteral.Text += "</table>";

                if (objBooking.InvoiceSent.ToString() != "01/01/0001 00:00:00")
                {
                    UK_Film_Location_Class.InvoiceDetails objInvoice = new UK_Film_Location_Class.InvoiceDetails();
                    objInvoice.getInvoice(BookingID.Value);

                    BookingFeesLiteral.Text += "<p><b>";
                    BookingFeesLiteral.Text += "<br><br>Invoice Sent : " + objBooking.InvoiceSent.ToString().Substring(0, 10) + " #" + objInvoice.RecordID;
                    BookingFeesLiteral.Text += "</b></p>";
                }

                DBConnection.Dispose();
            }
        }
        protected void SendInvoice_Click(object sender, EventArgs e)
        {
            UK_Film_Location_Class.InvoiceDetails objInvoice = new UK_Film_Location_Class.InvoiceDetails();

            UK_Film_Location_Class.BookingDetails objBooking = new UK_Film_Location_Class.BookingDetails();
            objBooking.getBooking(Request.QueryString["BookingID"]);

            UK_Film_Location_Class.OpportunityDetails objOpportunity = new UK_Film_Location_Class.OpportunityDetails();
            objOpportunity.getOpportunity(objBooking.OpportunityID);

            UK_Film_Location_Class.ContactDetails objProjectContact = new UK_Film_Location_Class.ContactDetails();
            objProjectContact.getContact(objOpportunity.ContactID);

            if (objBooking.InvoiceSent.ToString().Contains("01/01/0001"))
            {
                //objBooking.InvoiceSent = DateTime.Now;
                //objBooking.saveBooking();

                objInvoice.CreateInvoice(objBooking.BookingID);
            }
            else
            {
                objInvoice.getInvoice(objBooking.BookingID);
            }

            string thisMessage = "";

            thisMessage += "<p>To " + objProjectContact.Name + ",<br><br>";
            thisMessage += "<p><a href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/InvoicePDF.php?BookingID=" + objBooking.BookingID + "\">Click here</a> to view your invoice, you can also view your invoices by logging in to <a href=\"http://UKFilmLocation.com\">UKFilmLocation.com</a> and navigating to your dashboard.</p><h4>Terms & Conditions</h4><ul><li>Payment may be made via BACS, TT or direct payment into a UK Bank. Add 4% for credit card payments</li><li>Hire is dependent on signed contracts, proof of identity, and proof of insurance being received prior to commencement of the shoot.</li><li>E&OE</li></ul><p>Many thanks for your order. We look forward to helping you again in the future.</p><p><b>UKFilmLocation.com</b></p>";

            //        UK_Film_Location_Class.UKFilmLocation.sendEmail(objProjectContact.Email, "Accounts", "*****@*****.**", "UKFilmLocation.com - Invoice : " + objInvoice.RecordID, thisMessage);
            UK_Film_Location_Class.UKFilmLocation.sendEmail("*****@*****.**", "Accounts", "*****@*****.**", "UKFilmLocation.com - Invoice : " + objInvoice.RecordID, thisMessage);
        }
        protected void SaveBtn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(StartDateTextBox.Text) && !string.IsNullOrEmpty(NoDaysTextBox.Text) && !string.IsNullOrEmpty(StartTimeTextBox.Text) && !string.IsNullOrEmpty(FinishTimeTextBox.Text))
            {

                string UserEmail = "";

                HttpCookie myTestCookie = new HttpCookie("UKFilmLocationAdmin");
                myTestCookie = Request.Cookies["UKFilmLocationAdmin"];

                // Read the cookie information and display it.
                if (myTestCookie != null)
                {
                    // User details collected

                    UserEmail = myTestCookie.Value;

                }

                UK_Film_Location_Class.UserDetails objUser = new UK_Film_Location_Class.UserDetails();

                objUser.getUserFromEmail(UserEmail);

                // Save Booking Data

                UK_Film_Location_Class.BookingDetails objBooking = new UK_Film_Location_Class.BookingDetails();

                if (!string.IsNullOrEmpty(BookingID.Value))
                {
                    objBooking.getBooking(BookingID.Value);
                }
                else
                {
                    objBooking.DateBooked = DateTime.Now;
                    objBooking.OpportunityID = Request.QueryString["OpportunityID"];
                    objBooking.UserID = objUser.RecordID.ToString();

                }

                objBooking.saveBooking();

                // From the start date

                DateTime thisDate = DateTime.Parse(StartDateTextBox.Text);
                int thisNoDays = Convert.ToInt32(NoDaysTextBox.Text);

                UK_Film_Location_Class.OpportunityDetails objOpportunity = new UK_Film_Location_Class.OpportunityDetails();
                objOpportunity.getOpportunity(objBooking.OpportunityID);

                int i = 0;

                for (i = 0; i < thisNoDays; i++)
                {
                    // Create Booked Days ready for editing!

                    UK_Film_Location_Class.BookingDates objDate = new UK_Film_Location_Class.BookingDates();

                    objDate.BookingDate = thisDate;
                    objDate.BookingID = objBooking.BookingID;
                    objDate.StartTime = StartTimeTextBox.Text;
                    objDate.EndTime = FinishTimeTextBox.Text;
                    objDate.AgreedDayRate = objOpportunity.LocationRate;
                    try
                    {
                        objDate.NoCrew = Convert.ToInt32(objOpportunity.NoCrew);
                    }
                    catch
                    {
                    }

                    objDate.Save();

                    thisDate = thisDate.AddDays(1);
                }

                string thisPath = Server.MapPath("~/Bookings/") + "/" + objBooking.BookingID;

                if (!System.IO.Directory.Exists(thisPath))
                {
                    System.IO.Directory.CreateDirectory(thisPath);
                }

                Response.Redirect("/BookLocation.aspx?BookingID=" + objBooking.BookingID);

            }
        }