Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Util.AlignRadDatePicker(dp_start_date);
            Util.AlignRadDatePicker(dp_end_date);
            Security.BindPageValidatorExpressions(this);
            if (Util.IsBrowser(this, "IE"))
            {
                rfd.Visible = false;
            }

            if (Request.QueryString["off"] != null && !String.IsNullOrEmpty(Request.QueryString["off"]))
            {
                hf_office.Value = Request.QueryString["off"];
                Util.MakeCountryDropDown(dd_country);
                BindReps();

                String CompanyID = CompanyManager.AddTemporaryCompany("Media Sales");
                ContactManager.CompanyID = CompanyID;
                ContactManager.BindContacts(CompanyID);
            }
            else
            {
                Util.PageMessage(this, "There was an error getting the office information, please close and reload this window.");
            }
        }
    }
Example #2
0
    private void BindTemplate()
    {
        String qry = "SELECT dbl_lead.*, db_company.*, db_contact.ctc_id " +
                     "FROM dbl_lead, db_contact, db_company " +
                     "WHERE dbl_lead.ContactID = db_contact.ctc_id " +
                     "AND db_contact.new_cpy_id = db_company.cpy_id " +
                     "AND dbl_lead.LeadID=@LeadID;";
        DataTable dt_lead = SQL.SelectDataTable(qry, "@LeadID", hf_lead_id.Value);

        if (dt_lead.Rows.Count > 0)
        {
            String cpy_id     = dt_lead.Rows[0]["cpy_id"].ToString();
            String ctc_id     = dt_lead.Rows[0]["ctc_id"].ToString();
            String project_id = dt_lead.Rows[0]["ProjectID"].ToString();

            hf_project_id.Value        = project_id;
            hf_parent_project_id.Value = LeadsUtil.GetProjectParentIDFromID(hf_project_id.Value);
            hf_cpy_id.Value            = cpy_id;
            hf_ctc_id.Value            = ctc_id;

            // Bind Company and Contacts
            CompanyManager.BindCompany(cpy_id);
            ContactManager.BindContacts(ctc_id);

            // Bind Notes and Next Action
            ContactNotesManager.LeadID = hf_lead_id.Value;
            ContactNotesManager.Bind(ctc_id);

            // Bind Other Contacts
            BindOtherContacts(null, null);

            // Bind destination projects
            LeadsUtil.BindProjects(dd_projects, dd_buckets, hf_parent_project_id.Value, hf_project_id.Value, true);
        }
    }
Example #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Util.SetRebindOnWindowClose(this, false);
            if (Request.QueryString["cpy_id"] != null && !String.IsNullOrEmpty(Request.QueryString["cpy_id"]) &&
                Request.QueryString["cpy_type"] != null && !String.IsNullOrEmpty(Request.QueryString["cpy_type"]) &&
                Request.QueryString["issue"] != null && !String.IsNullOrEmpty(Request.QueryString["issue"]))
            {
                hf_cpy_id.Value   = Request.QueryString["cpy_id"];
                hf_cpy_type.Value = Request.QueryString["cpy_type"];
                hf_issue.Value    = Request.QueryString["issue"];
                switch (hf_cpy_type.Value)
                {
                case "f": hf_cpy_type.Value = "Feature"; ContactManager.IncludeContactTypes = false; ContactManager.TargetSystem = String.Empty; break;

                case "a": hf_cpy_type.Value = "Advert"; break;
                }
                CompanyManager.SmartSocialIssue       = hf_issue.Value;
                CompanyManager.SmartSocialCompanyType = hf_cpy_type.Value;
                CompanyManager.BindCompany(hf_cpy_id.Value);

                if (Request.QueryString["ctc_id"] != null && !String.IsNullOrEmpty(Request.QueryString["ctc_id"]))
                {
                    hf_ctc_id.Value = Request.QueryString["ctc_id"];
                    ContactManager.FocusContactID = hf_ctc_id.Value;
                }
                ContactManager.BindContacts(hf_cpy_id.Value);
            }
            else
            {
                Util.PageMessageAlertify(this, LeadsUtil.LeadsGenericError, "Error");
            }
        }
    }
    protected void UpdateCompanyAndContacts(object sender, EventArgs e)
    {
        ContactManager.UpdateContacts(hf_cpy_id.Value); // also merges as AutoContactMergingEnabled is true
        CompanyManager.UpdateCompany();                 // also merges as AutoCompanyMergingEnabled is true
        CompanyManager.BindCompany(hf_cpy_id.Value);    // rebind things like date last updated
        ContactManager.BindContacts(hf_cpy_id.Value);

        Util.PageMessageSuccess(this, "Updated!", "top-right");

        Util.SetRebindOnWindowClose(this, true);
    }
Example #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Util.SetRebindOnWindowClose(this, false);
            Security.BindPageValidatorExpressions(this);

            if (Request.QueryString["lead_id"] != null && !String.IsNullOrEmpty(Request.QueryString["lead_id"]))
            {
                hf_lead_id.Value = Request.QueryString["lead_id"];
                String qry = "SELECT TeamID, TeamName, db_userpreferences.UserID, db_userpreferences.Office, db_contact.ContactID, db_company.CompanyID " +
                             "FROM dbl_lead, dbl_project, db_userpreferences, db_ccateams, db_contact, db_company " +
                             "WHERE dbl_lead.ProjectID = dbl_project.ProjectID " +
                             "AND dbl_project.UserID = db_userpreferences.userid " +
                             "AND db_userpreferences.ccaTeam = db_ccateams.TeamID " +
                             "AND dbl_lead.ContactID = db_contact.ContactID " +
                             "AND db_contact.CompanyID = db_company.CompanyID " +
                             "AND LeadID=@lead_id";
                DataTable dt_user_info = SQL.SelectDataTable(qry, "@lead_id", hf_lead_id.Value);
                if (dt_user_info.Rows.Count > 0)
                {
                    hf_user_id.Value    = dt_user_info.Rows[0]["UserID"].ToString();
                    hf_team_id.Value    = dt_user_info.Rows[0]["TeamID"].ToString();
                    hf_office.Value     = dt_user_info.Rows[0]["Office"].ToString();
                    hf_team_name.Value  = dt_user_info.Rows[0]["TeamName"].ToString();
                    hf_company_id.Value = dt_user_info.Rows[0]["CompanyID"].ToString();
                    hf_contact_id.Value = dt_user_info.Rows[0]["ContactID"].ToString();

                    String[] forced_selected = new String[] { hf_contact_id.Value };

                    CompanyManager.BindCompany(hf_company_id.Value);
                    ContactManager.BindContacts(hf_company_id.Value, forced_selected); // for multiple

                    // Bind Destination Prospect teams
                    BindDestinationTeams();

                    if (CompanyManager.Turnover == String.Empty)
                    {
                        Util.PageMessageAlertify(this, "Company turnover is not specified and is required to push this Lead to Prospect.<br/><br/>Click the company edit pencil and specify a turnover value. ", "Turnover Required");
                    }
                }

                BindRepDropDown();
            }
            else
            {
                Util.PageMessageAlertify(this, "There was an error getting the team information. Please close this window and retry.", "Error");
            }

            Util.ResizeRadWindow(this);
        }
    }
    protected void BindCompanyAndContacts(object sender, EventArgs e)
    {
        if (hf_clicked_company_id.Value != String.Empty)
        {
            div_company.Visible = div_contacts.Visible = true;
            //CompanyManager.ShowCompanyNameHeader = !CompanyManager.AddingNewCompany;
            CompanyManager.BindCompany(hf_clicked_company_id.Value);
            ContactManager.BindContacts(hf_clicked_company_id.Value);

            ScriptManager.RegisterStartupScript(this, this.GetType(), "Resize", "var rw = GetRadWindow(); rw.autoSize(); rw.center();", true);

            tbl_add_lead.Visible = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["cpy_id"] != null && !String.IsNullOrEmpty(Request.QueryString["cpy_id"]))
            {
                hf_cpy_id.Value = Request.QueryString["cpy_id"];
                CompanyManager.BindCompany(hf_cpy_id.Value);
                hf_original_company_name.Value = CompanyManager.CompanyName;

                div_contacts.Visible = Request.QueryString["showcontacts"] == "true";
                if (div_contacts.Visible)
                {
                    ContactManager.BindContacts(hf_cpy_id.Value);
                }
            }
            else
            {
                Util.PageMessageAlertify(this, LeadsUtil.LeadsGenericError, "Error");
            }
        }
    }
Example #8
0
    protected void BindProspectInfo()
    {
        String qry = "SELECT PLevel, ListGeneratorFriendlyname, Emails, Grade, Notes, IsHot, pr.DateAdded, DateListDue, DateLetterHeadDue, LeadHookAngle, BenchmarkNotes, " + // prospect info
                     "cpy.CompanyName, cpy.CompanyID, cpy.Industry, cpy.SubIndustry, cpy.Turnover, cpy.Employees, cpy.Phone, cpy.Website " +                                  // company info
                     "FROM db_prospectreport pr, db_company cpy WHERE pr.CompanyID = cpy.CompanyID AND ProspectID=@pros_id";
        DataTable dt_pros_info = SQL.SelectDataTable(qry, "@pros_id", hf_pros_id.Value);

        if (dt_pros_info.Rows.Count > 0)
        {
            lbl_prospect.Text = "Currently editing <b>" + dt_pros_info.Rows[0]["CompanyName"] + "</b>";

            // LH due
            String lh_due = dt_pros_info.Rows[0]["DateLetterHeadDue"].ToString();
            if (lh_due.Trim() != String.Empty)
            {
                DateTime dt_lh_due = new DateTime();
                if (DateTime.TryParse(lh_due, out dt_lh_due))
                {
                    dp_lh_due.SelectedDate = dt_lh_due;
                }
            }
            // List due
            String list_due = dt_pros_info.Rows[0]["DateListDue"].ToString();
            if (list_due.Trim() != String.Empty)
            {
                DateTime dt_list_due = new DateTime();
                if (DateTime.TryParse(list_due, out dt_list_due))
                {
                    dp_list_due.SelectedDate = dt_list_due;
                }
            }

            // Rep
            String rep     = dt_pros_info.Rows[0]["ListGeneratorFriendlyname"].ToString();
            int    rep_idx = dd_rep.Items.IndexOf(dd_rep.Items.FindByText(rep));
            if (rep_idx == -1)
            {
                dd_rep.Items.Insert(0, new ListItem(rep)); // in case user is no longer employed
                dd_rep.SelectedIndex = 0;
            }
            else
            {
                dd_rep.SelectedIndex = rep_idx;
            }

            int idx = dd_emails.Items.IndexOf(dd_emails.Items.FindByValue(dt_pros_info.Rows[0]["Emails"].ToString()));
            if (idx != -1)
            {
                dd_emails.SelectedIndex = idx;
            }

            dd_p1_p2.Text          = dt_pros_info.Rows[0]["PLevel"].ToString();
            dd_grade.Text          = dt_pros_info.Rows[0]["Grade"].ToString();
            tb_notes.Text          = dt_pros_info.Rows[0]["Notes"].ToString();
            tb_lha.Text            = dt_pros_info.Rows[0]["LeadHookAngle"].ToString();
            tb_benchmark_data.Text = dt_pros_info.Rows[0]["BenchmarkNotes"].ToString();

            // Bind company
            hf_cpy_id.Value = dt_pros_info.Rows[0]["CompanyID"].ToString();
            CompanyManager.BindCompany(hf_cpy_id.Value);

            // Bind contacts
            DateTime ContactContextCutOffDate = new DateTime(2017, 4, 6);
            DateTime ProspectAdded            = Convert.ToDateTime(dt_pros_info.Rows[0]["DateAdded"].ToString());
            if (ProspectAdded >= ContactContextCutOffDate)
            {
                ContactManager.TargetSystemID = hf_pros_id.Value;
            }
            ContactManager.BindContacts(hf_cpy_id.Value);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Security.BindPageValidatorExpressions(this);
            if (!Util.IsBrowser(this, "IE"))
            {
                tbl.Style.Add("position", "relative; top:10px; left:8px;");
            }
            else
            {
                rfd.Visible = false;
            }

            if (Request.QueryString["bid"] != null && !String.IsNullOrEmpty(Request.QueryString["bid"]) &&
                Request.QueryString["rows"] != null && !String.IsNullOrEmpty(Request.QueryString["rows"]) &&
                Request.QueryString["totr"] != null && !String.IsNullOrEmpty(Request.QueryString["totr"]) &&
                Request.QueryString["end_d"] != null && !String.IsNullOrEmpty(Request.QueryString["end_d"]) &&
                Request.QueryString["off"] != null && !String.IsNullOrEmpty(Request.QueryString["off"]))
            {
                hf_book_id.Value       = Request.QueryString["bid"];
                hf_grid_rows.Value     = Request.QueryString["rows"];
                hf_total_revenue.Value = Request.QueryString["totr"];
                hf_book_end_date.Value = Request.QueryString["end_d"];
                hf_office.Value        = Request.QueryString["off"];

                String qry = "SELECT IssueName FROM db_salesbookhead WHERE SalesBookID=@sb_id";
                hf_book_name.Value = SQL.SelectString(qry, "IssueName", "@sb_id", hf_book_id.Value);

                hf_total_ads.Value = Request.QueryString["tota"];
                if (hf_total_ads.Value == String.Empty)
                {
                    hf_total_ads.Value = "0";
                }

                SetFeatures();
                SetMagazines();
                SetFriendlynames();
                Util.MakeCountryDropDown(dd_new_country);

                bool is_uk = Util.IsOfficeUK(hf_office.Value);
                tr_magazine_note.Visible = rfv_magazine_note.Enabled = is_uk;

                if (is_uk || hf_office.Value == "ANZ")
                {
                    tr_conversion.Visible = true;

                    if (hf_office.Value != "ANZ")
                    {
                        cb_to_details.Checked  = true; // Only show details sheet after add for UK
                        tb_new_conversion.Text = String.Empty;
                    }
                    else
                    {
                        tb_new_conversion.ReadOnly  = true;
                        tb_new_conversion.BackColor = Color.LightGray;
                    }
                }

                String CompanyID = CompanyManager.AddTemporaryCompany("SB Advertiser");
                ContactManager.CompanyID = CompanyID;
                ContactManager.BindContacts(CompanyID);
            }
            else
            {
                Util.PageMessage(this, "There was a problem getting the book issue information. Please close this window and retry.");
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Util.SetRebindOnWindowClose(this, false);

            bool error = false;
            if (Request.QueryString["cpy_id"] != null && !String.IsNullOrEmpty(Request.QueryString["cpy_id"]))
            {
                hf_cpy_id.Value = Request.QueryString["cpy_id"];
            }
            else if (Request.QueryString["ctc_id"] != null && !String.IsNullOrEmpty(Request.QueryString["ctc_id"]))
            {
                hf_ctc_id.Value = Request.QueryString["ctc_id"];
                String qry = "SELECT CompanyID FROM db_contact WHERE ContactID=@ContactID";
                hf_cpy_id.Value = SQL.SelectString(qry, "CompanyID", "@ContactID", hf_ctc_id.Value);
            }
            else
            {
                Util.PageMessageAlertify(this, LeadsUtil.LeadsGenericError, "Error");
                error = true;
            }

            // Disable adding to Leads system/selecting contacts when add_leads=false
            bool InLeadsMode = true;
            if (Request.QueryString["add_leads"] != null && Request.QueryString["add_leads"].ToString() == "false")
            {
                div_add_leads.Visible             = lbl_pad.Visible = false;
                InLeadsMode                       = false;
                ContactManager.SelectableContacts = false;
            }

            if (!error)
            {
                if (hf_ctc_id.Value != String.Empty)
                {
                    ContactManager.FocusContactID = hf_ctc_id.Value;
                }

                String[] ForcedSelectedContactIDs = null;
                if (hf_ctc_id.Value != String.Empty)
                {
                    ForcedSelectedContactIDs = new String[] { hf_ctc_id.Value }
                }
                ;

                CompanyManager.BindCompany(hf_cpy_id.Value);
                ContactManager.BindContacts(hf_cpy_id.Value, ForcedSelectedContactIDs);

                if (InLeadsMode)
                {
                    // Allow adding Leads to projects if this user has projects (or has used Leads system)
                    hf_project_id.Value = LeadsUtil.GetLastViewedProjectID();
                    if (hf_project_id.Value != String.Empty)
                    {
                        div_add_leads.Visible      = true;
                        hf_parent_project_id.Value = LeadsUtil.GetProjectParentIDFromID(hf_project_id.Value);

                        // Bind destination projects
                        LeadsUtil.BindProjects(dd_projects, dd_buckets, hf_parent_project_id.Value, hf_project_id.Value, true);
                    }
                    // Otherwise disable adding Leads and allow updates to CTC/CPY only
                    else
                    {
                        ContactManager.SelectableContacts = false;
                    }
                }
            }
        }

        Util.ResizeRadWindow(this);
    }
    // Bind
    protected void BindSaleInfo()
    {
        // Get sale
        String    qry          = "SELECT * FROM db_mediasales WHERE MediaSaleID=@ms_id";
        DataTable dt_saleinfo  = SQL.SelectDataTable(qry, "@ms_id", hf_ms_id.Value);
        DataTable dt_childinfo = new DataTable();

        // Grab child data if child
        if (hf_type.Value == "child")
        {
            qry          = "SELECT * FROM db_mediasalespayments WHERE MediaSalePaymentID=@msp_id";
            dt_childinfo = SQL.SelectDataTable(qry, "@msp_id", hf_msp_id.Value);
        }

        if (dt_saleinfo.Rows.Count > 0)
        {
            hf_cpy_id.Value = dt_saleinfo.Rows[0]["CompanyID"].ToString();
            qry             = "SELECT * FROM db_company WHERE CompanyID=@CompanyID";
            DataTable dt_cpy = SQL.SelectDataTable(qry, "@CompanyID", hf_cpy_id.Value);


            String client = dt_saleinfo.Rows[0]["Client"].ToString();
            if (dt_cpy.Rows.Count > 0)
            {
                client = dt_cpy.Rows[0]["CompanyName"].ToString();
            }
            String channel = dt_saleinfo.Rows[0]["Channel"].ToString();
            if (dt_cpy.Rows.Count > 0)
            {
                channel = dt_cpy.Rows[0]["Industry"].ToString();
            }
            String country = dt_saleinfo.Rows[0]["Country"].ToString();
            if (dt_cpy.Rows.Count > 0)
            {
                country = dt_cpy.Rows[0]["Country"].ToString();
            }

            String ent_date       = dt_saleinfo.Rows[0]["DateAdded"].ToString();
            String agency         = dt_saleinfo.Rows[0]["Agency"].ToString();
            String media_type     = dt_saleinfo.Rows[0]["MediaType"].ToString();
            String size           = dt_saleinfo.Rows[0]["Size"].ToString();
            String rep            = dt_saleinfo.Rows[0]["Rep"].ToString();
            String units          = dt_saleinfo.Rows[0]["Units"].ToString();
            String unit_price     = dt_saleinfo.Rows[0]["UnitPrice"].ToString();
            String prospect_price = dt_saleinfo.Rows[0]["ProspectPrice"].ToString();
            String discount       = dt_saleinfo.Rows[0]["Discount"].ToString();
            String discount_type  = dt_saleinfo.Rows[0]["DiscountType"].ToString();
            String confidence     = dt_saleinfo.Rows[0]["Confidence"].ToString();
            String start_date     = dt_saleinfo.Rows[0]["StartDate"].ToString();
            String end_date       = dt_saleinfo.Rows[0]["EndDate"].ToString();
            String s_notes        = dt_saleinfo.Rows[0]["SaleNotes"].ToString();
            String f_notes        = dt_saleinfo.Rows[0]["FinanceNotes"].ToString();

            // Set Label
            lbl_sale.Text = "<b>" + Server.HtmlEncode(client) + " - " + Server.HtmlEncode(agency) + "</b> " + lbl_sale.Text;

            // Bind contacts
            DateTime ContactContextCutOffDate = new DateTime(2017, 4, 25);
            DateTime SaleAdded = Convert.ToDateTime(ent_date);
            if (SaleAdded > ContactContextCutOffDate)
            {
                ContactManager.TargetSystemID = hf_ms_id.Value;
            }
            ContactManager.BindContacts(hf_cpy_id.Value);

            // Set Fields
            tb_client.Text                 = client;
            tb_agency.Text                 = agency;
            tb_channel.Text                = channel;
            tb_country.Text                = country;
            tb_media_type.Text             = media_type;
            tb_size.Text                   = size;
            tb_units.Text                  = units;
            tb_unit_price.Text             = unit_price;
            dd_discount_type.SelectedIndex = dd_discount_type.Items.IndexOf(dd_discount_type.Items.FindByText(discount_type));
            tb_discount.Text               = discount;
            tb_prospect_price.Text         = prospect_price;
            tb_confidence.Text             = confidence;
            tb_s_notes.Text                = s_notes;
            tb_f_notes.Text                = f_notes;

            // Attempt to set rep idx, if rep no longer exists, add to dd
            int rep_idx = dd_rep.Items.IndexOf(dd_rep.Items.FindByText(rep));
            if (rep_idx != -1)
            {
                dd_rep.SelectedIndex = rep_idx;
            }
            else
            {
                dd_rep.Items.Insert(0, rep); dd_rep.SelectedIndex = 0;
            }

            // Start date
            if (start_date.Trim() != String.Empty)
            {
                DateTime dt_start_date = new DateTime();
                if (DateTime.TryParse(start_date, out dt_start_date))
                {
                    dp_start_date.SelectedDate = dt_start_date;
                }
            }
            // End date
            if (end_date.Trim() != String.Empty)
            {
                DateTime dt_end_date = new DateTime();
                if (DateTime.TryParse(end_date, out dt_end_date))
                {
                    dp_end_date.SelectedDate = dt_end_date;
                }
            }

            // Set child information (if applicable)
            if (hf_type.Value == "child" && dt_childinfo.Rows.Count > 0)
            {
                String child_price  = dt_childinfo.Rows[0]["Price"].ToString();
                String date_paid    = dt_childinfo.Rows[0]["DatePaid"].ToString();
                String outstanding  = dt_childinfo.Rows[0]["Outstanding"].ToString();
                String invoice      = dt_childinfo.Rows[0]["Invoice"].ToString();
                String invoice_date = dt_childinfo.Rows[0]["InvoiceDate"].ToString();
                String terms        = dt_childinfo.Rows[0]["Terms"].ToString();
                hf_issue_name.Value = dt_childinfo.Rows[0]["IssueName"].ToString();

                tb_outstanding.Text    = outstanding;
                tb_price.Text          = child_price;
                tb_invoice.Text        = invoice;
                dd_terms.SelectedIndex = dd_terms.Items.IndexOf(dd_terms.Items.FindByValue(terms));
                DateTime dt_tmp = new DateTime();
                if (DateTime.TryParse(date_paid, out dt_tmp))
                {
                    dp_date_paid.SelectedDate = dt_tmp;
                }
                if (DateTime.TryParse(invoice_date, out dt_tmp))
                {
                    dp_invoice_date.SelectedDate = dt_tmp;
                }
            }
        }
        else
        {
            lbl_sale.Text = "Error getting sale information.";
        }
    }
    protected void BindSaleInfo()
    {
        ClearSaleInfo();
        String    qry         = "SELECT * FROM db_salesbook sb, db_financesales fs WHERE sb.ent_id = fs.SaleID AND sb.ent_id=@ent_id";
        DataTable dt_saleinfo = SQL.SelectDataTable(qry, "@ent_id", hf_ent_id.Value);

        if (dt_saleinfo.Rows.Count > 0)
        {
            hf_ad_cpy_id.Value   = dt_saleinfo.Rows[0]["ad_cpy_id"].ToString();
            hf_feat_cpy_id.Value = dt_saleinfo.Rows[0]["feat_cpy_id"].ToString();
            qry = "SELECT * FROM db_company WHERE CompanyID=@CompanyID";
            DataTable dt_ad_cpy   = SQL.SelectDataTable(qry, "@CompanyID", hf_ad_cpy_id.Value);
            DataTable dt_feat_cpy = SQL.SelectDataTable(qry, "@CompanyID", hf_feat_cpy_id.Value);

            String advertiser = dt_saleinfo.Rows[0]["advertiser"].ToString();
            String country    = String.Empty;
            String timezone   = String.Empty;
            if (dt_ad_cpy.Rows.Count > 0)
            {
                advertiser = dt_ad_cpy.Rows[0]["CompanyName"].ToString();
                country    = dt_ad_cpy.Rows[0]["Country"].ToString();
                timezone   = dt_ad_cpy.Rows[0]["TimeZone"].ToString();
            }
            if (dt_saleinfo.Rows[0]["Country"].ToString() != String.Empty)
            {
                country = dt_saleinfo.Rows[0]["Country"].ToString();
            }
            if (dt_saleinfo.Rows[0]["TimeZone"].ToString() != String.Empty)
            {
                timezone = dt_saleinfo.Rows[0]["TimeZone"].ToString();
            }

            String feature = dt_saleinfo.Rows[0]["Feature"].ToString();
            if (dt_feat_cpy.Rows.Count > 0)
            {
                feature = dt_feat_cpy.Rows[0]["CompanyName"].ToString();
            }

            String date_added    = dt_saleinfo.Rows[0]["ent_date"].ToString();
            String invoice_date  = dt_saleinfo.Rows[0]["InvoiceDate"].ToString();
            String invoice       = dt_saleinfo.Rows[0]["invoice"].ToString();
            String vat_number    = dt_saleinfo.Rows[0]["VATNumber"].ToString();
            String date_promised = dt_saleinfo.Rows[0]["PromisedDate"].ToString();
            String fnotes        = dt_saleinfo.Rows[0]["fnotes"].ToString();
            String date_paid     = dt_saleinfo.Rows[0]["date_paid"].ToString();
            String outstanding   = dt_saleinfo.Rows[0]["Outstanding"].ToString();
            String foreign_price = dt_saleinfo.Rows[0]["ForeignPrice"].ToString();
            int    bp            = Convert.ToInt32(dt_saleinfo.Rows[0]["BP"]);
            String tab_id        = dt_saleinfo.Rows[0]["FinanceTabID"].ToString();
            String bank          = dt_saleinfo.Rows[0]["Bank"].ToString();
            String br_pageno     = dt_saleinfo.Rows[0]["br_page_no"].ToString();
            String ch_pageno     = dt_saleinfo.Rows[0]["ch_page_no"].ToString();
            String ter_mag       = dt_saleinfo.Rows[0]["territory_magazine"].ToString();
            String channel_mag   = dt_saleinfo.Rows[0]["channel_magazine"].ToString();
            String links_mail_cc = dt_saleinfo.Rows[0]["links_mail_cc"].ToString();
            int    pre_mag_sent  = Convert.ToInt32(dt_saleinfo.Rows[0]["PreMagMailSent"]);
            int    post_mag_sent = Convert.ToInt32(dt_saleinfo.Rows[0]["PostMagMailSent"]);
            String al_rag        = dt_saleinfo.Rows[0]["al_rag"].ToString();
            String al_notes      = dt_saleinfo.Rows[0]["al_notes"].ToString();

            String s_last_u = dt_saleinfo.Rows[0]["s_last_updated"].ToString();
            if (s_last_u == String.Empty)
            {
                s_last_u = "Never";
            }
            String f_last_u = dt_saleinfo.Rows[0]["f_last_updated"].ToString();
            if (f_last_u == String.Empty)
            {
                f_last_u = "Never";
            }
            // Set LU
            lbl_lu.Text = "Finance data last upated: <b>" + Server.HtmlEncode(f_last_u) + "</b>. Sale data last updated: <b>" + Server.HtmlEncode(s_last_u) + "</b>.";

            Util.WriteLogWithDetails("Editing finance account: Advertiser: " + advertiser + " Feature: " + feature + " Office: " + hf_office.Value + " Account ID: " + hf_ent_id.Value, "finance_log");

            // Bind contacts
            DateTime ContactContextCutOffDate = new DateTime(2017, 4, 25);
            DateTime SaleAdded = Convert.ToDateTime(date_added);
            if (SaleAdded > ContactContextCutOffDate)
            {
                ContactManager.TargetSystemID = hf_ent_id.Value;
            }
            ContactManager.BindContacts(hf_ad_cpy_id.Value);

            tb_advertiser.Text    = advertiser;
            tb_feature.Text       = feature;
            tb_invoice.Text       = invoice;
            tb_vat_number.Text    = vat_number;
            tb_fnotes.Text        = fnotes;
            tb_dnotes.Text        = al_notes;
            tb_outstanding.Text   = outstanding;
            tb_foreign_price.Text = foreign_price;
            tb_br_pageno.Text     = br_pageno;
            tb_ch_pageno.Text     = ch_pageno;
            tb_links_mail_cc.Text = links_mail_cc;

            // country
            // attempt to set country, if no longer exists, add it to dd
            int country_idx = dd_country.Items.IndexOf(dd_country.Items.FindByText(country));
            if (country_idx != -1)
            {
                dd_country.SelectedIndex = country_idx;
            }
            else
            {
                dd_country.Items.Insert(0, country); dd_country.SelectedIndex = 0;
            }

            // timezone
            tb_timezone.Text = timezone;

            // Dates
            if (date_promised.Trim() != String.Empty)
            {
                DateTime dt_date_promised = new DateTime();
                if (DateTime.TryParse(date_promised, out dt_date_promised))
                {
                    dp_date_promised.SelectedDate = dt_date_promised;
                }
            }
            if (date_paid.Trim() != String.Empty)
            {
                DateTime dt_date_paid = new DateTime();
                if (DateTime.TryParse(date_paid, out dt_date_paid))
                {
                    dp_date_paid.SelectedDate = dt_date_paid;
                }
            }
            if (invoice_date.Trim() != String.Empty)
            {
                DateTime dt_invoice_date = new DateTime();
                if (DateTime.TryParse(invoice_date, out dt_invoice_date))
                {
                    dp_invoice_date.SelectedDate = dt_invoice_date;
                }
            }

            // BP
            cb_bp.Checked = (bp == 1);

            // Bank
            dd_bank.SelectedIndex = Convert.ToInt32(bank);

            // attempt to set ter mag and channel idx, if mag no longer exists, add it to dd
            int mag_idx = dd_magazine.Items.IndexOf(dd_magazine.Items.FindByText(ter_mag));
            if (mag_idx != -1)
            {
                dd_magazine.SelectedIndex = mag_idx;
            }
            else
            {
                dd_magazine.Items.Insert(0, ter_mag); dd_magazine.SelectedIndex = 0;
            }

            int channel_idx = dd_channel.Items.IndexOf(dd_channel.Items.FindByText(channel_mag));
            if (channel_idx != -1)
            {
                dd_channel.SelectedIndex = channel_idx;
            }
            else
            {
                dd_channel.Items.Insert(0, channel_mag); dd_channel.SelectedIndex = 0;
            }

            lbl_sale.Text = "Currently editing " + Server.HtmlEncode(advertiser) + " - " + Server.HtmlEncode(feature) + ".";
        }
        else
        {
            lbl_sale.Text = "Error getting sale information.";
        }
    }