protected void SaveBtn_Click(object sender, EventArgs e)
        {
            UK_Film_Location_Class.LocationDetails objLocation = new UK_Film_Location_Class.LocationDetails();

            UK_Film_Location_Class.Counties objCounty = new UK_Film_Location_Class.Counties();

            // Check Fields

            bool isOK = true;

            //if (string.IsNullOrEmpty(LocationID.Text))
            //{
            //    isOK = false;
            //    LocationIDPanel.CssClass = "has-error";
            //}

            if (string.IsNullOrEmpty(LocationTitle.Text))
            {
                isOK = false;
                TitlePanel.CssClass = "has-error";
            }
            if (string.IsNullOrEmpty(ShortDescription.Text))
            {
                isOK = false;
                ShortDescriptionPanel.CssClass = "has-error";
            }

            if (string.IsNullOrEmpty(ContactsDropDownList.SelectedValue))
            {
                isOK = false;

                ContactIDPanel.CssClass = "has-error";
            }

            if (string.IsNullOrEmpty(AvgDayRate.Text))
            {
                isOK = false;

                AvgDayRatePanel.CssClass = "has-error";
            }

            //      if (string.IsNullOrEmpty(Address.Text)) isOK = false;
            //      if (string.IsNullOrEmpty(Street.Text)) isOK = false;
            //      if (string.IsNullOrEmpty(Town.Text)) isOK = false;

            //if (string.IsNullOrEmpty(CountyDDL.SelectedValue))
            //{
            //    isOK = false;

            //    CountyPanel.CssClass = "has-error";
            //}

            if (string.IsNullOrEmpty(Country.SelectedValue))
            {
                isOK = false;

                CountryPanel.CssClass = "has-error";
            }

            //      if (string.IsNullOrEmpty(Postcode.Text)) isOK = false;

            if (!isOK) ErrorLabel.Text = "<div class=\"alert alert-danger\" role=\"alert\"><strong>Save Failed!</strong> Please check the details and try again.</div>";
            else
            {
                ErrorLabel.Text = "<div class=\"alert alert-success\" role=\"alert\"><strong>Save OK!</strong></div>";
                //if (!string.IsNullOrEmpty(CountyDDL.SelectedValue))
                //{

                //    string Ref = objCounty.getRefPrefixFromCountyID(CountyDDL.SelectedValue);

                //    objLocation.LocationID = Ref + objLocation.getNextRef();
                //    LocationID.Text = objLocation.LocationID;
                //}

                if (!string.IsNullOrEmpty(Request.QueryString["RecordID"]) && string.IsNullOrEmpty(objLocation.LocationID))
                {
                    // legacy location
                    objLocation.getLocationFromRecordID(Request.QueryString["RecordID"]);
                    objLocation.LocationID = LocationID.Text;
                }
                else
                {

                    if (!string.IsNullOrEmpty(LocationID.Text))
                    {
                        objLocation.getLocationFromID(LocationID.Text);
                    }
                    else
                    {

                        if (!string.IsNullOrEmpty(Request.QueryString["LocationID"]))
                        {
                            objLocation.getLocationFromID(Request.QueryString["LocationID"]);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(Request.QueryString["RecordID"]))
                            {
                                objLocation.getLocationFromRecordID(Request.QueryString["RecordID"]);

                            }
                        }
                    }
                }

                objLocation.Title = LocationTitle.Text;
                // objLocation.TypeID =
                objLocation.ShortDescription = ShortDescription.Text;
                objLocation.Address = Address.Text;
                objLocation.Street = Street.Text;
                objLocation.Town = Town.Text;
                objLocation.LocationTel = LocationTel.Text;
                objLocation.LocationCompany = LocationCompany.Text;

                objLocation.County = CountyDDL.SelectedValue;
                objLocation.Postcode = Postcode.Text;
                objLocation.Country = Country.SelectedValue;
                objLocation.ContactID = ContactsDropDownList.SelectedValue;
                objLocation.TravelZone = TravelZoneDropDownList.SelectedValue;

                objLocation.Keywords = Keywords.Text;

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

                CompanyLiteral.Text = objContact.Company;
                EmailLiteral.Text = objContact.Email;
                TelLiteral.Text = objContact.Tel;
                MobileLiteral.Text = objContact.Mobile;

                objLocation.Notes = Notes.Text;
                objLocation.LocationVideo = LocationVideo.Text;
                objLocation.KitchenDescription = KitchenDescription.Text;

                objLocation.AgentID = AgentID.SelectedValue;
                objLocation.AvgDayRate = Convert.ToDouble(AvgDayRate.Text);

                // Items collection
                string myIDList = "";

                // Items collection
                foreach (ListItem item in LocationTypeListBox.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }

                objLocation.TypeID = myIDList;
                myIDList = "";

                foreach (ListItem item in FacilitiesCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.Facilities = myIDList;
                myIDList = "";

                foreach (ListItem item in ParkingCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.Parking = myIDList;
                myIDList = "";

                objLocation.InteriorDescription = InteriorDescription.Text;

                objLocation.ExteriorDescription = ExteriorDescription.Text;

                foreach (ListItem item in KitchenTypeCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.KitchenType = myIDList;
                myIDList = "";

                foreach (ListItem item in KitchenFacilitiesCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.KitchenFacilities = myIDList;
                myIDList = "";

                objLocation.NoBedrooms = Convert.ToInt32(NoBedrooms.Text);

                foreach (ListItem item in BedroomTypeCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.BedroomTypes = myIDList;
                myIDList = "";

                objLocation.NoBathrooms = Convert.ToInt32(NoBathrooms.Text);

                foreach (ListItem item in BathroomTypeCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.BathroomTypes = myIDList;
                myIDList = "";

                foreach (ListItem item in RoomsCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.Rooms = myIDList;
                myIDList = "";

                foreach (ListItem item in InteriorFeaturesCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.InteriorFeatures = myIDList;
                myIDList = "";

                foreach (ListItem item in FloorsCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.Floors = myIDList;
                myIDList = "";

                foreach (ListItem item in WallsAndWindowsCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.WallsAndWindows = myIDList;
                myIDList = "";

                foreach (ListItem item in ViewsCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.Views = myIDList;
                myIDList = "";

                foreach (ListItem item in ExteriorFeaturesCheckBoxList.Items)
                {
                    if (item.Selected)
                    {
                        myIDList += item.Value + ";";
                    }
                }
                objLocation.ExteriorFeatures = myIDList;
                myIDList = "";

                if (WithInM25.Checked) objLocation.WithInM25 = "Yes";
                else objLocation.WithInM25 = "No";

                if (!Featured.Checked)
                {
                    objLocation.Featured = "No";
                }
                else
                {
                    objLocation.Featured = "Yes";
                }

                if (objLocation.Approved == "1")
                {
                    if (!Approved.Checked)
                    {
                        objLocation.Approved = "0";
                        ApprovedDate.Text = "";
                    }
                }
                else
                {
                    if (objLocation.Approved == "0" && Approved.Checked)
                    {

                        objLocation.Approved = "1";
                        objLocation.ApprovedDate = DateTime.Now.ToString();
                        ApprovedDate.Text = DateTime.Parse(objLocation.ApprovedDate).ToShortDateString();

                        // Send email to contact

                        UK_Film_Location_Class.UKFilmLocation.sendEmail(objContact.Email, "UKFilmLocation.com", "*****@*****.**", "UKFilmLocation.com : Your location listing has been approved!", "<h1>Your location listing has been approved!</h1><p>Hi " + objContact.Name + ",</p><p></p><p>Your location has been approved and is now visible on our website;</p><p><a href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/Location.aspx?LocationID=" + objLocation.LocationID + "\">http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/Location.aspx?LocationID=" + objLocation.LocationID + "</a></p><p>You can also download a printable PDF brochure of your location by clicking here;</p><p><a href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/LocationPDF.php?LocationID=" + objLocation.LocationID + "\">http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/LocationPDF.php?LocationID=" + objLocation.LocationID + "</a></p><p>You can add more locations and monitor this location by logging on to our website. Recce appointments for this location and any other locations you may have registered with us can also be viewed on your personal dashboard. <a href=\"http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/Dashboard.aspx\">Click here to login.</a></p><p><b>Thank you.</b></p>");

                        UK_Film_Location_Class.UKFilmLocation.postSocialLink(objLocation.LocationID + " : " + objLocation.Title + " #FilmLocation", objLocation.ShortDescription, "http://" + UK_Film_Location_Class.UKFilmLocation.DefaultWebsite + "/Location.aspx?LocationID=" + objLocation.LocationID + "");

                    }
                    else
                    {
                        objLocation.Approved = "0";
                        ApprovedDate.Text = "";
                    }
                }

                objLocation.saveLocation();

                LocationID.Text = objLocation.LocationID;

                Response.Redirect("/LocationDetails.aspx?LocationID=" + objLocation.LocationID);
            }
        }
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            // csv

            bool isLive = true;

            if (FileUpload.HasFiles)
            {
                foreach (HttpPostedFile uploadedFile in FileUpload.PostedFiles)
                {

                    string Filename = "";
                    string Extension = "";

                    Filename = uploadedFile.FileName;
                    Extension = Path.GetExtension(Filename).ToLower();

                    string thisID = Guid.NewGuid().ToString();

                    if (Extension == ".csv")
                    {

                        uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Temp/"), thisID + Extension));

                        //MySqlConnection DBConnection;
                        //MySqlCommand DBCommand;

                        //MySqlDataReader DBResult;

                        FileHelperEngine engine = new FileHelperEngine(typeof(ContactsVerticalBar));

                        DataTable objTable = engine.ReadFileAsDT(System.IO.Path.Combine(Server.MapPath("~/Temp/"), thisID + Extension));

                        ResultsLiteral.Text += "<table><tr><th>Name</th><th>Company</th><th>Tel</th><th>Mobile</th><th>Email</th></tr>";

                        ResultsStatsLiteral.Text = "Importing " + objTable.Rows.Count + " rows...";

                        foreach (DataRow row in objTable.Rows)
                        {
                            string thisName = row["Name"].ToString();
                            string thisCompany = row["Company"].ToString();
                            string thisTel = row["Tel"].ToString();
                            string thisMobile = row["Mobile"].ToString();
                            string thisEmail = row["Email"].ToString();

                            string thisPosition = row["Position"].ToString();
                            string thisAddress = row["Address"].ToString();
                            string thisStreet = row["Street"].ToString();
                            string thisTown = row["Town"].ToString();
                            string thisCounty = row["County"].ToString();
                            string thisPostcode = row["Postcode"].ToString();
                            string thisLocationID = row["LocationID"].ToString();
                            string thisContactType = row["ContactType"].ToString();

                            string thisContactTypeText = "";

                            if (!string.IsNullOrEmpty(thisName))
                            {

                                switch (thisContactType)
                                {
                                    case "1":
                                        thisContactTypeText = "Location Owner";
                                        break;
                                    case "2":
                                        thisContactTypeText = "Project Company";
                                        break;
                                    default:
                                        thisContactTypeText = "";
                                        thisContactTypeText = "Location Owner";
                                        thisContactType = "1";
                                        break;
                                }

                                ResultsLiteral.Text += "<tr><td valign=\"top\">" + thisContactTypeText + "</td><td>" + thisName + "</td><td>" + thisCompany + "</td><td>" + thisTel + "</td><td>" + thisMobile + "</td><td>" + thisEmail + "</td></tr>";

                                ResultsLiteral.Text += "<tr><td></td><td colspan=\"5\">";

                                ResultsLiteral.Text += "<b>Notes:</b>";

                                UK_Film_Location_Class.ContactDetails objContact = new UK_Film_Location_Class.ContactDetails();

                                bool foundContact = false;

                                if (!string.IsNullOrEmpty(thisEmail))
                                {
                                    objContact.getContactFromEmail(thisEmail);

                                    if (!string.IsNullOrEmpty(objContact.ContactID))
                                    {
                                        ResultsLiteral.Text += "<p>Contact found by Email!</p>";
                                        foundContact = true;
                                    }

                                }

                                if (!foundContact && !string.IsNullOrEmpty(thisTel))
                                {
                                    objContact.getContactFromTel(thisTel);
                                    if (!string.IsNullOrEmpty(objContact.ContactID))
                                    {
                                        ResultsLiteral.Text += "<p>Contact found by Tel!</p>";
                                        foundContact = true;

                                    }
                                }

                                if (!foundContact && !string.IsNullOrEmpty(thisName))
                                {
                                    objContact.getContactFromName(thisName);
                                    if (!string.IsNullOrEmpty(objContact.ContactID))
                                    {
                                        ResultsLiteral.Text += "<p>Contact found by Name :/</p>";
                                        foundContact = true;

                                    }
                                }

                                // Compare Data on found records

                                if (foundContact)
                                {
                                    bool isMod = false;

                                    ResultsLiteral.Text += "<p><i>Updating Contact!</i></p>";

                                    if (string.IsNullOrEmpty(objContact.Company) && !string.IsNullOrEmpty(thisCompany))
                                    {
                                        objContact.Company = thisCompany.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Company!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.Name) && !string.IsNullOrEmpty(thisName))
                                    {
                                        objContact.Name = thisName.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Name!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.Tel) && !string.IsNullOrEmpty(thisTel))
                                    {
                                        objContact.Tel = thisTel.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Tel!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.Mobile) && !string.IsNullOrEmpty(thisMobile))
                                    {
                                        objContact.Mobile = thisMobile.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Mobile!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.ContactType) && !string.IsNullOrEmpty(thisContactType))
                                    {
                                        objContact.ContactType = thisContactType.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Contact Type!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.Email) && !string.IsNullOrEmpty(thisEmail))
                                    {
                                        objContact.Email = thisEmail.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Email Address!</p>";

                                    }

                                    if (string.IsNullOrEmpty(objContact.Address) && !string.IsNullOrEmpty(thisAddress))
                                    {
                                        objContact.Address = thisAddress.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Address!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.Street) && !string.IsNullOrEmpty(thisStreet))
                                    {
                                        objContact.Street = thisStreet.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Street!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.Town) && !string.IsNullOrEmpty(thisTown))
                                    {
                                        objContact.Town = thisTown.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Town!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.County) && !string.IsNullOrEmpty(thisCounty))
                                    {
                                        objContact.County = thisCounty.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating County!</p>";

                                    }
                                    if (string.IsNullOrEmpty(objContact.PostCode) && !string.IsNullOrEmpty(thisPostcode))
                                    {
                                        objContact.PostCode = thisPostcode.Trim();
                                        isMod = true;
                                        ResultsLiteral.Text += "<p>Updating Postcode!</p>";

                                    }

                                    if (isMod)
                                    {
                                        if (isLive) objContact.Update();
                                        ResultsLiteral.Text += "<p>Updated!</p>";
                                    }
                                    else ResultsLiteral.Text += "<p>Up to Date!</p>";
                                }
                                else
                                {
                                    ResultsLiteral.Text += "<p>New Contact!</p>";

                                    objContact.Name = thisName.Trim();
                                    objContact.Company = thisCompany.Trim();
                                    objContact.Tel = thisTel.Trim();
                                    objContact.Mobile = thisMobile.Trim();
                                    objContact.Email = thisEmail.Trim();

                                    if (!string.IsNullOrEmpty(thisLocationID))
                                    {
                                        objContact.ContactType = "1";
                                    }
                                    else
                                    {
                                        objContact.ContactType = thisContactType.Trim();
                                    }

                                    objContact.Address = thisAddress.Trim();
                                    objContact.Street = thisStreet.Trim();
                                    objContact.Town = thisTown.Trim();
                                    objContact.County = thisCounty.Trim();
                                    objContact.PostCode = thisPostcode.Trim();

                                    if (isLive) objContact.Create();

                                }

                                // Check LocationID's

                                if (!string.IsNullOrEmpty(thisLocationID))
                                {
                                    UK_Film_Location_Class.LocationDetails objLocation = new UK_Film_Location_Class.LocationDetails();

                                    objLocation.getLocationFromID(thisLocationID);

                                    if (objLocation.RecordID > 0)
                                    {
                                        objLocation.ContactID = objContact.ContactID;
                                        if (isLive) objLocation.saveLocation();

                                        ResultsLiteral.Text += "<p>Associated contact with location " + thisLocationID + "!</p>";
                                    }
                                    else
                                    {
                                        ResultsLiteral.Text += "<p>Lcation " + thisLocationID + " NOT FOUND!</p>";
                                    }
                                }

                            }
                        }

                            ResultsLiteral.Text += "</td></tr>";

                        }
                        ResultsLiteral.Text += "</table>";

                        //var engine = new FileHelperAsyncEngine<ContactsVerticalBar>();
                        //engine.BeginReadFile(System.IO.Path.Combine(Server.MapPath("~/Temp/"), thisID + Extension));

                        // The Async engines are IEnumerable
                        //foreach (ContactsVerticalBar cust in engine)
                        //{
                        //    // your code here
                        //    ResultsLiteral.Text = cust.Name + " - " + cust.Email + "<br>";
                        //}

                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Check authorised user!

            string UserEmail = "";

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

            // Read the cookie information and display it.
            if (myTestCookie == null)
            {
                Response.Write("/");
            }
            else
            {
                UserEmail = myTestCookie.Value;

                // Connect to database

                DBConnection = new MySqlConnection(objUKFilmLocation.DBConnect);

                DBCommand = DBConnection.CreateCommand();

                // Perform location analysis

                MessageLiteral.Text = "<p>Location Analysis...</p>";

                int LocationsCount = 0;

                DBConnection.Open();

                DBCommand.CommandText = "select count(*) as numrecs from Locations where Address = '' or Address is null or Postcode = ''  or postcode is null;";

                DBResult = DBCommand.ExecuteReader();

                if (DBResult.Read())
                {
                    LocationsCount = Convert.ToInt32(DBResult["NumRecs"].ToString());
                }

                DBConnection.Close();

                MessageLiteral.Text += "<p>" + LocationsCount + " Locations Need Address Details!</p>";

                // Loop locations and retrieve address details from contacts

                MessageLiteral.Text += "<p>Attempting Address Lookup From Contact...</p>";

                UK_Film_Location_Class.ContactDetails objContact = new UK_Film_Location_Class.ContactDetails();
                UK_Film_Location_Class.LocationDetails objLocation = new UK_Film_Location_Class.LocationDetails();

                DBConnection.Open();

                DBCommand.CommandText = "select * from Locations where Address = '' or Address is null or Postcode = ''  or postcode is null or county = '' or county is null;";

                DBResult = DBCommand.ExecuteReader();

                int SuccessCount = 0;
                int FailCount = 0;
                int ErrorCount = 0;

                string FailMessage = "";
                string SuccessMessage = "";

                while (DBResult.Read())
                {
                    ErrorCount++;

                    objLocation.getLocationFromID(DBResult["LocationID"].ToString());
                    objContact.getContact(DBResult["ContactID"].ToString());

                    if (!string.IsNullOrEmpty(objLocation.County))
                    {
                        objContact.Address = objContact.Address.Replace(", " + objLocation.County, "").Replace("\"", "");
                        objContact.Address = objContact.Address.Replace(objLocation.County, "");
                    }

                    // Check valid contact id
                    if (string.IsNullOrEmpty(DBResult["ContactID"].ToString()))
                    {
                        FailCount += 1;
                        FailMessage += "<li><a href=\"/LocationDetails.aspx?LocationID=" + DBResult["LocationID"].ToString() + "\">" + DBResult["LocationID"].ToString() + " " + DBResult["Title"].ToString() + " does not have a contact!</a><br>";
                    }
                    else
                    {
                        // check contact has address
                        if (string.IsNullOrEmpty(objContact.Address) && string.IsNullOrEmpty(objContact.Street) && string.IsNullOrEmpty(objContact.Town) && string.IsNullOrEmpty(objContact.County) && string.IsNullOrEmpty(objContact.PostCode) )
                        {
                            FailCount += 1;
                            FailMessage += "<li><a href=\"/ContactDetails.aspx?ContactID=" + objContact.ContactID + "\">" + objContact.Name + "</a> does not have an address for location <a href=\"/LocationDetails.aspx?LocationID=" + DBResult["LocationID"].ToString() + "\">" + DBResult["LocationID"].ToString() + " " + DBResult["Title"].ToString() + "</a>!<br>";
                        }
                        else
                        {
                            // is contact address valid?  How do you tell?

                            // is Address empty?
                            if (string.IsNullOrEmpty(objContact.Address))
                            {
                                // next check

                                FailCount += 1;
                                FailMessage += "<li><a href=\"/ContactDetails.aspx?ContactID=" + objContact.ContactID + "\">" + objContact.Name + "</a> does not have an address at all! (<a href=\"/LocationDetails.aspx?LocationID=" + DBResult["LocationID"].ToString() + "\">" + DBResult["LocationID"].ToString() + " " + DBResult["Title"].ToString() + "</a>)<br>";

                            }
                            else
                            {
                                // Is Address valid?
                                if (string.IsNullOrEmpty(objLocation.LocationCompany)) objLocation.LocationCompany = objContact.Company;
                                if (string.IsNullOrEmpty(objLocation.Street)) objLocation.Address = objContact.Street;
                                if (string.IsNullOrEmpty(objLocation.Town)) objLocation.Address = objContact.Town;
                                if (string.IsNullOrEmpty(objLocation.LocationTel)) objLocation.LocationTel = objContact.Tel;

                                // Does contact have postcode?
                                if (string.IsNullOrEmpty(objContact.PostCode))
                                {
                                }
                                else objLocation.Postcode = objContact.PostCode;

                                if (string.IsNullOrEmpty(objContact.Town))
                                {
                                }
                                else objLocation.Postcode = objContact.Town;

                                if (string.IsNullOrEmpty(objContact.Town))
                                {
                                }
                                else objLocation.Postcode = objContact.Town;

                                if (string.IsNullOrEmpty(objContact.Street))
                                {
                                }
                                else objLocation.Postcode = objContact.Street;

                                if (string.IsNullOrEmpty(objLocation.Address))
                                {
                                  //  objLocation.Address = objContact.Address;
                                    SuccessMessage += "<div style=\"padding-top: 50px;\">";
                                    if (string.IsNullOrEmpty(objLocation.Postcode))
                                    {
                                        SuccessMessage += "<p>Working with >" + objContact.Address + "<</p>";

                                        // Assume Address in one line?
                                        string[] Address = objContact.Address.Split(',');

                                        if (Address.Count() > 0)
                                        {
                                            SuccessMessage += "<li><a href=\"/ContactDetails.aspx?ContactID=" + objContact.ContactID + "\">" + objContact.Name + "</a> has an address for location <a href=\"/LocationDetails.aspx?LocationID=" + DBResult["LocationID"].ToString() + "\">" + DBResult["LocationID"].ToString() + " " + DBResult["Title"].ToString() + "</a>! (Address Items Found : " + Address.Count() + ")<br>";
                                            int LineCount = 0;
                                            for (int i = Address.Count() - 1; i >= 0; i--)
                                            {
                                                LineCount++;
                                                SuccessMessage += Address[i] + "<br>";

                                                if (LineCount == 1)
                                                {
                                                    if (string.IsNullOrEmpty(objLocation.Postcode)) objLocation.Postcode = Address[i];
                                                    if (string.IsNullOrEmpty(objContact.PostCode)) objContact.PostCode = Address[i];
                                                }

                                                if (Address.Count() == 2)
                                                {

                                                    if (LineCount == 2)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Address)) objLocation.Address = Address[i];
                                                        objContact.Address = Address[i];
                                                    }
                                                }

                                                if (Address.Count() == 3)
                                                {
                                                    if (LineCount == 1)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Postcode)) objLocation.Postcode = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.PostCode)) objContact.PostCode = Address[i];
                                                    }

                                                    if (LineCount == 2)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Street)) objLocation.Street = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Street)) objContact.Street = Address[i];
                                                    }
                                                    if (LineCount == 3)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Address)) objLocation.Address = Address[i];
                                                        objContact.Address = Address[i];
                                                    }
                                                }

                                                if (Address.Count() == 4)
                                                {
                                                    if (LineCount == 2)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Town)) objLocation.Town = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Town)) objContact.Town = Address[i];
                                                    }
                                                    if (LineCount == 3)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Street)) objLocation.Street = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Street)) objContact.Street = Address[i];
                                                    }
                                                    if (LineCount == 4)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Address)) objLocation.Address = Address[i];
                                                        objContact.Address = Address[i];
                                                    }
                                                }

                                                if (Address.Count() == 5)
                                                {
                                                    if (LineCount == 2)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Town)) objLocation.Town = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Town)) objContact.Town = Address[i];
                                                    }
                                                    if (LineCount == 3)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Street)) objLocation.Street = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Street)) objContact.Street = Address[i];
                                                    }
                                                    if (LineCount == 4)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Address)) objLocation.Address = Address[i];
                                                        objContact.Address = Address[i];
                                                    }
                                                    if (LineCount == 5)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Company)) objLocation.Company = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Company)) objContact.Company = Address[i];
                                                    }
                                                }

                                                if (Address.Count() >= 6)
                                                {

                                                    if (LineCount == 2)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Town)) objLocation.Town = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Town)) objContact.Town = Address[i];
                                                    }
                                                    if (LineCount == 3)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Street)) objLocation.Street = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Street)) objContact.Street = Address[i];
                                                    }
                                                    if (LineCount == 4)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Address)) objLocation.Address = Address[i];
                                                        objContact.Address = Address[i];
                                                    }
                                                    if (LineCount == 5)
                                                    {
                                                        if (string.IsNullOrEmpty(objLocation.Company)) objLocation.Company = Address[i];
                                                        if (string.IsNullOrEmpty(objContact.Company)) objContact.Company = Address[i];
                                                    }
                                                    if (LineCount >= 6)
                                                    {
                                                        objLocation.Company = Address[i] + ", " + objLocation.Company;
                                                        objContact.Company = Address[i] + ", " + objContact.Company;
                                                        SuccessMessage += "<p>Line Count 6 Envoked! -" + Address[i] + "-</p>";
                                                    }

                                                }
                                            }

                                            SuccessMessage += "<h4>New Location Address : </h4>";

                                            objLocation.Postcode = objLocation.Postcode.ToUpper();
                                            objContact.PostCode = objContact.PostCode.ToUpper();
                                            if (string.IsNullOrEmpty(objContact.County)) objContact.County = objLocation.County;

                                            SuccessMessage += "Company : " + objLocation.Company + "<br>";
                                            SuccessMessage += "Address : " + objLocation.Address + "<br>";
                                            SuccessMessage += "Street : " + objLocation.Street + "<br>";
                                            SuccessMessage += "Town : " + objLocation.Town + "<br>";
                                            SuccessMessage += "County : " + objLocation.County + "<br>";
                                            SuccessMessage += "PostCode : " + objLocation.Postcode + "<br>";

                                            SuccessMessage += "<h4>New Contact Address : </h4>";

                                            SuccessMessage += "Company : " + objContact.Company + "<br>";
                                            SuccessMessage += "Address : " + objContact.Address + "<br>";
                                            SuccessMessage += "Street : " + objContact.Street + "<br>";
                                            SuccessMessage += "Town : " + objContact.Town + "<br>";
                                            SuccessMessage += "County : " + objContact.County + "<br>";
                                            SuccessMessage += "PostCode : " + objContact.PostCode + "<br>";

                                            objLocation.saveLocation();
                                            objContact.Update();

                                            SuccessCount += 1;

                                            SuccessMessage += "<li><a href=\"/ContactDetails.aspx?ContactID=" + objContact.ContactID + "\">" + objContact.Name + "</a> has an address for location <a href=\"/LocationDetails.aspx?LocationID=" + DBResult["LocationID"].ToString() + "\">" + DBResult["LocationID"].ToString() + " " + DBResult["Title"].ToString() + "</a>!<br>";

                                       //     SuccessMessage += "<li><a href=\"/ContactDetails.aspx?ContactID=" + objContact.ContactID + "\">" + objContact.Address + "</a> is being assinged to <a href=\"/LocationDetails.aspx?LocationID=" + DBResult["LocationID"].ToString() + "\">" + DBResult["LocationID"].ToString() + " " + DBResult["Title"].ToString() + "</a>!</a><br>";
                                        }
                                        else
                                        {
                                            // Assumption incorrect!
                                            FailCount += 1;
                                            FailMessage += "<li><a href=\"/ContactDetails.aspx?ContactID=" + objContact.ContactID + "\">" + objContact.Name + "</a> does not have a full address! Postcode missing for location <a href=\"/LocationDetails.aspx?LocationID=" + DBResult["LocationID"].ToString() + "\">" + DBResult["LocationID"].ToString() + " " + DBResult["Title"].ToString() + "</a><br>";

                                        }

                                   //     objLocation.Address = objContact.Address;
                                    }

                                    SuccessMessage += "</div>";
                                }

                            }
                        }

                    }

                }

                DBConnection.Close();

                MessageLiteral.Text += "<h2>Fail!</h2>" + FailMessage;
                MessageLiteral.Text += "<h2>Success!</h2>" + SuccessMessage;

                MessageLiteral.Text += "<h3>Total Errors Detected : " + ErrorCount + "</h3>";
            }
        }