Esempio n. 1
0
    protected string GetContactDetail(DataRow[] rows)
    {
        string output = string.Empty;

        for (int i = 0; i < rows.Length; i++)
        {
            ContactAus contact = ContactAusDB.LoadAll(rows[i]);

            bool isAddress = contact.ContactType.ContactTypeGroup.ID == 1;
            bool isPhone   = contact.ContactType.ContactTypeGroup.ID == 2;
            bool isBedroom = contact.ContactType.ContactTypeGroup.ID == 3;

            bool isEmail   = contact.ContactType.ContactTypeID == 27;
            bool isWebsite = contact.ContactType.ContactTypeID == 28;


            if (isAddress)
            {
                output += @"<tr><td style=""min-width:140px"">" + contact.ContactType.Descr + @"</td><td style=""min-width:10px;""></td><td>" + contact.GetFormattedAddress() + "<br>" + "</td></tr>";
            }
            else if (isPhone)
            {
                output += @"<tr><td style=""min-width:140px"">" + contact.ContactType.Descr + @"</td><td style=""min-width:10px;""></td><td>" + contact.GetFormattedPhoneNumber() + "</td></tr>";
            }
            else if (isEmail)
            {
                output += @"<tr><td style=""min-width:140px"">" + contact.ContactType.Descr + @"</td><td style=""min-width:10px;""></td><td>" + contact.AddrLine1 + "</td></tr>";
            }
        }

        return(output);
    }
Esempio n. 2
0
 public static ContactAus[] GetByEntityIDs(int contact_type_group_id, int[] entity_ids, int contact_type_id = -1, int site_id = -1, bool orderByShippingBeforeBilling = false)
 {
     DataTable tbl = GetDataTable_ByEntityIDs(contact_type_group_id, entity_ids, contact_type_id, site_id, orderByShippingBeforeBilling);
     ContactAus[] list = new ContactAus[tbl.Rows.Count];
     for (int i = 0; i < tbl.Rows.Count; i++)
         list[i] = LoadAll(tbl.Rows[i]);
     return list;
 }
Esempio n. 3
0
 public static ContactAus[] GetByAddrLine1(string contact_type_group_ids, string addr_line1, int contact_type_id = -1, bool orderByShippingBeforeBilling = false)
 {
     DataTable tbl = GetDataTable_ByAddrLine1(contact_type_group_ids, addr_line1, contact_type_id, orderByShippingBeforeBilling);
     ContactAus[] list = new ContactAus[tbl.Rows.Count];
     for (int i = 0; i < tbl.Rows.Count; i++)
         list[i] = LoadAll(tbl.Rows[i]);
     return list;
 }
Esempio n. 4
0
 public static ContactAus[] GetByEntityID(string contact_type_group_ids, int entity_id, string contact_type_ids = null, bool orderByShippingBeforeBilling = false, string DB = null)
 {
     DataTable tbl = GetDataTable_ByEntityID(contact_type_group_ids, entity_id, contact_type_ids, orderByShippingBeforeBilling, DB);
     ContactAus[] list = new ContactAus[tbl.Rows.Count];
     for (int i = 0; i < tbl.Rows.Count; i++)
         list[i] = LoadAll(tbl.Rows[i]);
     return list;
 }
Esempio n. 5
0
    public static ContactAus[] GetByEntityIDs(string contact_type_group_id, int[] entity_ids, string contact_type_id = null, int site_id = -1, bool orderByShippingBeforeBilling = false)
    {
        DataTable tbl = GetDataTable_ByEntityIDs(contact_type_group_id, entity_ids, contact_type_id, site_id, orderByShippingBeforeBilling);

        ContactAus[] list = new ContactAus[tbl.Rows.Count];
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            list[i] = LoadAll(tbl.Rows[i]);
        }
        return(list);
    }
Esempio n. 6
0
    public static ContactAus[] GetByAddrLine1(string contact_type_group_ids, string addr_line1, int contact_type_id = -1, bool orderByShippingBeforeBilling = false)
    {
        DataTable tbl = GetDataTable_ByAddrLine1(contact_type_group_ids, addr_line1, contact_type_id, orderByShippingBeforeBilling);

        ContactAus[] list = new ContactAus[tbl.Rows.Count];
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            list[i] = LoadAll(tbl.Rows[i]);
        }
        return(list);
    }
Esempio n. 7
0
    public static ContactAus[] GetByEntityID(string contact_type_group_ids, int entity_id, string contact_type_ids = null, bool orderByShippingBeforeBilling = false, string DB = null)
    {
        DataTable tbl = GetDataTable_ByEntityID(contact_type_group_ids, entity_id, contact_type_ids, orderByShippingBeforeBilling, DB);

        ContactAus[] list = new ContactAus[tbl.Rows.Count];
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            list[i] = LoadAll(tbl.Rows[i]);
        }
        return(list);
    }
Esempio n. 8
0
    public static string[] GetFaxesByEntityID(int entityID) // clone from ContactAus.GetEmailsByEntityID(entityID)
    {
        string[] faxes;
        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            faxes = Contact.RemoveInvalidPhoneNumbers(ContactDB.GetByEntityID(-1, entityID, 29)).Select(r => Regex.Replace(r.AddrLine1, "[^0-9]", "")).ToArray();
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            faxes = ContactAus.RemoveInvalidPhoneNumbers(ContactAusDB.GetByEntityID(-1, entityID, 29)).Select(r => Regex.Replace(r.AddrLine1, "[^0-9]", "")).ToArray();
        }
        else
        {
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
        }

        return(faxes);
    }
Esempio n. 9
0
    public static string[] GetEmailsByEntityID(int entityID) // clone from ContactAus.GetEmailsByEntityID(entityID)
    {
        string[] emails;
        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            emails = Contact.RemoveInvalidEmailAddresses(ContactDB.GetByEntityID(-1, entityID, 27)).Select(r => r.AddrLine1).ToArray();
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            emails = ContactAus.RemoveInvalidEmailAddresses(ContactAusDB.GetByEntityID(-1, entityID, 27)).Select(r => r.AddrLine1).ToArray();
        }
        else
        {
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
        }

        return(emails);
    }
    protected void CreateTable(PlaceHolder placeHolder, DataRow[] rows, int width, int height)
    {
        placeHolder.Controls.Clear();
        Table t = new Table();

        placeHolder.Controls.Add(t);
        for (int i = 0; i < rows.Length; i++)
        {
            ContactAus contact = ContactAusDB.LoadAll(rows[i]);
            if (contact.FreeText.Trim().Length > 0)
            {
                t.Rows.Add(CreateNewRow(contact, width, height, true, true));
                t.Rows.Add(CreateNewRow(contact, width, height, true, false));
            }
            else
            {
                t.Rows.Add(CreateNewRow(contact, width, height, false, false));
            }
        }
    }
Esempio n. 11
0
    public static ContactAus LoadAll(DataRow row)
    {
        ContactAus a = Load(row, "ad_");

        a.ContactType = ContactTypeDB.Load(row, "at_");
        a.ContactType.ContactTypeGroup = IDandDescrDB.Load(row, "atg_contact_type_group_id", "atg_descr");
        if (row["act_address_channel_type_id"] != DBNull.Value)
        {
            a.AddressChannelType = IDandDescrDB.Load(row, "act_address_channel_type_id", "act_descr");
        }
        if (row["s_suburb_id"] != DBNull.Value)
        {
            a.Suburb = SuburbDB.Load(row, "s_");
        }
        if (row["c_country_id"] != DBNull.Value)
        {
            a.Country = IDandDescrDB.Load(row, "c_country_id", "c_descr");
        }
        if (row["ad_site_id"] != DBNull.Value)
        {
            a.Site.Name = Convert.ToString(row["site_name"]);
        }
        return(a);
    }
Esempio n. 12
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (GetUrlParamType() == UrlParamType.View)
        {
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it redirects
            Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit"));
        }
        else if (GetUrlParamType() == UrlParamType.Edit)
        {
            if (!IsValidFormID())
            {
                HideTableAndSetErrorMessage();
                return;
            }
            ContactAus contact = ContactAusDB.GetByID(GetFormID());
            if (contact == null)
            {
                HideTableAndSetErrorMessage("Invalid contact ID");
                return;
            }

            bool isAddress  = contact.ContactType.ContactTypeGroup.ID == 1;
            bool isTelecoms = contact.ContactType.ContactTypeGroup.ID == 2;
            bool isBedroom  = contact.ContactType.ContactTypeGroup.ID == 3;
            bool isWeb      = contact.ContactType.ContactTypeGroup.ID == 4;
            bool isMobile   = Convert.ToInt32(ddlContactType.SelectedValue) == 30;
            bool isPOBox    = Convert.ToInt32(ddlContactType.SelectedValue) == 37 || Convert.ToInt32(ddlContactType.SelectedValue) == 262;

            bool isEmail   = Convert.ToInt32(ddlContactType.SelectedValue) == 27;
            bool isWebsite = Convert.ToInt32(ddlContactType.SelectedValue) == 28;

            txtAddrLine1.Text = txtAddrLine1.Text.Trim();
            if (isMobile && !System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").StartsWith("0"))
            {
                SetErrorMessage("Mobile number must start with 0");
                return;
            }
            if (isTelecoms && System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").Length > 13)
            {
                SetErrorMessage("Phone number can not be more than 13 digits");
                return;
            }
            if (isEmail && !Utilities.IsValidEmailAddress(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid email address");
                return;
            }
            if (isWebsite && !Utilities.IsValidWebURL(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid website");
                return;
            }
            if (isPOBox && !Regex.IsMatch(txtAddrLine1.Text, "PO Box", RegexOptions.IgnoreCase) && !Regex.IsMatch(txtAddrLine2.Text, "PO Box", RegexOptions.IgnoreCase))
            {
                SetErrorMessage("The address text must contain \"PO Box\"");
                return;
            }



            ContactAusDB.Update(Convert.ToInt32(lblId.Text),
                                Convert.ToInt32(ddlContactType.SelectedValue),
                                txtFreeText.Text,
                                isTelecoms ? System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "") : txtAddrLine1.Text,
                                txtAddrLine2.Text,
                                txtStreet.Text,
                                isAddress ? Convert.ToInt32(ddlAddressChannelType.SelectedValue) : (contact.AddressChannelType == null ? -1 : contact.AddressChannelType.ID),
                                //isAddress ? Convert.ToInt32(ddlSuburb.SelectedValue)             : (contact.Suburb             == null ? -1 : contact.Suburb.SuburbID),
                                isAddress ? Convert.ToInt32(suburbID.Value) : (contact.Suburb == null ? -1 : contact.Suburb.SuburbID),
                                isAddress ? Convert.ToInt32(ddlCountry.SelectedValue) : (contact.Country == null ? -1 : contact.Country.ID),
                                contact.Site == null ? Convert.ToInt32(Session["SiteID"]) : contact.Site.SiteID,
                                isAddress || isWeb ? chkIsBilling.Checked    : contact.IsBilling,
                                isAddress || isWeb ? chkIsNonBilling.Checked : contact.IsNonBilling);



            //close this window
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it closes

            bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

            if (refresh_on_close)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
        }
        else if (GetUrlParamType() == UrlParamType.Add)
        {
            if (!IsValidFormID())
            {
                HideTableAndSetErrorMessage();
                return;
            }

            int entityID = GetFormID();
            if (!EntityDB.IDExists(entityID))
            {
                HideTableAndSetErrorMessage("Invalid entity ID");
                return;
            }


            int contactTypeGroupID = -1;
            UrlParamContactTypeGroup urlParamContactTypeGroup = GetUrlParamContactTypeGroup();
            if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Mailing)
            {
                contactTypeGroupID = 1;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Telecoms)
            {
                contactTypeGroupID = 2;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Bedroom)
            {
                contactTypeGroupID = 3;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Internet)
            {
                contactTypeGroupID = 4;
            }
            else
            {
                HideTableAndSetErrorMessage("Invalid contact_group_type ID");
                return;
            }


            bool isAddress  = contactTypeGroupID == 1;
            bool isTelecoms = contactTypeGroupID == 2;
            bool isBedroom  = contactTypeGroupID == 3;
            bool isWeb      = contactTypeGroupID == 4;
            bool isMobile   = Convert.ToInt32(ddlContactType.SelectedValue) == 30;
            bool isPOBox    = Convert.ToInt32(ddlContactType.SelectedValue) == 37 || Convert.ToInt32(ddlContactType.SelectedValue) == 262;

            bool isEmail   = Convert.ToInt32(ddlContactType.SelectedValue) == 27;
            bool isWebsite = Convert.ToInt32(ddlContactType.SelectedValue) == 28;

            txtAddrLine1.Text = txtAddrLine1.Text.Trim();
            if (isMobile && !System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").StartsWith("0"))
            {
                SetErrorMessage("Mobile number must start with 0");
                return;
            }
            if (isTelecoms && System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").Length > 13)
            {
                SetErrorMessage("Phone number can not be more than 13 digits");
                return;
            }
            if (isEmail && !Utilities.IsValidEmailAddress(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid email address");
                return;
            }
            if (isWebsite && !Utilities.IsValidWebURL(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid website");
                return;
            }
            if (isPOBox && !Regex.IsMatch(txtAddrLine1.Text, "PO Box", RegexOptions.IgnoreCase) && !Regex.IsMatch(txtAddrLine2.Text, "PO Box", RegexOptions.IgnoreCase))
            {
                SetErrorMessage("The address text must contain \"PO Box\"");
                return;
            }

            int contactID = ContactAusDB.Insert(entityID,
                                                Convert.ToInt32(ddlContactType.SelectedValue),
                                                txtFreeText.Text,
                                                isTelecoms ? System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "") : txtAddrLine1.Text,
                                                txtAddrLine2.Text,
                                                txtStreet.Text,
                                                isAddress ? Convert.ToInt32(ddlAddressChannelType.SelectedValue) : -1,
                                                //isAddress ? Convert.ToInt32(ddlSuburb.SelectedValue)           : -1,
                                                isAddress ? Convert.ToInt32(suburbID.Value) : -1,
                                                isAddress ? Convert.ToInt32(ddlCountry.SelectedValue) : -1,
                                                Convert.ToInt32(Session["SiteID"]),
                                                isAddress || isWeb ? chkIsBilling.Checked    : true,
                                                isAddress || isWeb ? chkIsNonBilling.Checked : true);


            // close this window
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it closes

            bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

            if (refresh_on_close)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
        }
        else
        {
            HideTableAndSetErrorMessage("", "Invalid URL Parameters");
        }
    }
Esempio n. 13
0
    private void FillEditViewForm(bool isEditMode)
    {
        ContactAus contact = ContactAusDB.GetByID(GetFormID());

        if (contact == null)
        {
            HideTableAndSetErrorMessage("Invalid Contact ID");
            return;
        }

        DataTable addrTypes = ContactTypeDB.GetDataTable(contact.ContactType.ContactTypeGroup.ID);

        ddlContactType.DataSource = addrTypes;
        ddlContactType.DataBind();

        string type = "ContactAus";

        if (contact.ContactType.ContactTypeGroup.ID == 1)
        {
            type = "Address";
            lblLine1Descr.Text = "Line 1";
        }
        if (contact.ContactType.ContactTypeGroup.ID == 2)
        {
            type = "Phone Number";
            lblLine1Descr.Text = "Phone Number";
        }
        if (contact.ContactType.ContactTypeGroup.ID == 3)
        {
            type = "Bedroom";
            lblLine1Descr.Text = "Bedroom";
        }
        if (contact.ContactType.ContactTypeGroup.ID == 4)
        {
            type = "Email/Website";
            lblLine1Descr.Text = "Email/Website";
        }
        lblHeading.Text = isEditMode ? "Edit " + type : "View " + type;

        if (contact.ContactType.ContactTypeGroup.ID != 1)
        {
            line2Row.Visible   = false;
            streetRow.Visible  = false;
            suburbRow.Visible  = false;
            countryRow.Visible = false;
            if (contact.ContactType.ContactTypeGroup.ID != 4)
            {
                billingRow.Visible    = false;
                nonbillingRow.Visible = false;
            }
        }

        lblId.Text    = contact.ContactID.ToString();
        idRow.Visible = Utilities.IsDev();


        if (isEditMode)
        {
            ddlContactType.SelectedValue = contact.ContactType.ContactTypeID.ToString();
            txtFreeText.Text             = contact.FreeText;
            txtAddrLine1.Text            = contact.ContactType.ContactTypeGroup.ID == 2 ? Utilities.FormatPhoneNumber(contact.AddrLine1) : contact.AddrLine1;
            txtAddrLine2.Text            = contact.AddrLine2;

            txtStreet.Text = contact.StreetName;
            ddlAddressChannelType.SelectedValue = contact.AddressChannelType == null ? "-1" : contact.AddressChannelType.ID.ToString();
            suburbID.Value           = contact.Suburb == null ? "-1" : contact.Suburb.SuburbID.ToString();
            lblSuburbText.Text       = contact.Suburb == null ? "--" : contact.Suburb.Name + ", " + contact.Suburb.State + " (" + contact.Suburb.Postcode + ")";
            ddlCountry.SelectedValue = contact.Country == null ? "-1" : contact.Country.ID.ToString();
            chkIsBilling.Checked     = contact.IsBilling;
            chkIsNonBilling.Checked  = contact.IsNonBilling;

            lblContactType.Visible        = false;
            lblAddrLine1.Visible          = false;
            lblAddrLine2.Visible          = false;
            lblAddressChannelType.Visible = false;
            lblCountry.Visible            = false;
            lblIsBilling.Visible          = false;
            lblIsNonBilling.Visible       = false;
        }
        else
        {
            lblContactType.Text        = contact.ContactType.Descr;
            lblAddrLine1.Text          = contact.ContactType.ContactTypeGroup.ID == 2 ? Utilities.FormatPhoneNumber(contact.AddrLine1) : contact.AddrLine1;
            lblAddrLine2.Text          = contact.AddrLine2;
            lblStreet.Text             = contact.StreetName;
            lblAddressChannelType.Text = contact.AddressChannelType == null ? string.Empty : contact.AddressChannelType.Descr;
            suburbID.Value             = contact.Suburb == null ? "-1" : contact.Suburb.SuburbID.ToString();
            lblSuburbText.Text         = contact.Suburb == null ? "--" : contact.Suburb.Name + ", " + contact.Suburb.State + " (" + contact.Suburb.Postcode + ")";
            lblSuburbText.Font.Bold    = true;
            lblCountry.Text            = contact.Country == null ? string.Empty : contact.Country.Descr;
            lblIsBilling.Text          = contact.IsBilling ? "Yes" : "No";
            lblIsNonBilling.Text       = contact.IsNonBilling ? "Yes" : "No";

            lnkUpdateType.Visible = false;
            txtValidateAddrLine1Required.Visible = false;

            ddlContactType.Visible        = false;
            txtFreeText.Visible           = false;
            txtAddrLine1.Visible          = false;
            txtAddrLine2.Visible          = false;
            txtStreet.Visible             = false;
            ddlAddressChannelType.Visible = false;
            lnkGetSuburb.Visible          = false;
            lnkClearSuburb.Visible        = false;
            ddlCountry.Visible            = false;
            chkIsBilling.Visible          = false;
            chkIsNonBilling.Visible       = false;
        }



        if (isEditMode)
        {
            btnSubmit.Text = "Update Details";
        }
        else // is view mode
        {
            btnSubmit.Visible = false;
            btnCancel.Text    = "Close";
        }
    }
Esempio n. 14
0
    protected static void MergeDocument(string sourceTemplatePath, string outputDocPath,
                    Booking booking, Patient patient, Contact patientAddress, ContactAus patientAddressAus, Contact patientPhone, ContactAus patientPhoneAus, HealthCard medicareCard, HealthCard dvaCard, Site site,
                    Organisation org, Contact orgAddress, ContactAus orgAddressAus, Contact orgPhone, ContactAus orgPhoneAus, Contact orgFax, ContactAus orgFaxAus, Contact orgWeb, ContactAus orgWebAus, Contact orgEmail, ContactAus orgEmailAus,
                    Staff staff, RegisterReferrer regReferrer, Contact referrerAddress, ContactAus referrerAddressAus, Contact referrerPhone, ContactAus referrerPhoneAus, Contact referrerFax, ContactAus referrerFaxAus, HealthCardAction healthCardAction,

                    DateTime pt_last_bk_date, DateTime epc_expire_date, int      epc_count_remaining, 

                    bool isDoubleSidedPrinting, string[] extraPages,
                    bool keepHistoryInDB, bool keepHistoryInFile, int letterPrintHistorySendMethodID, string historyDir, string historyFileName, int letterID)
    {
        HealthCard activeHcCard = (medicareCard != null && medicareCard.IsActive) ? medicareCard : ((dvaCard != null && dvaCard.IsActive) ? dvaCard : null);

        DataSet sourceDataSet = new DataSet();
        sourceDataSet.Tables.Add("MergeIt");

        sourceDataSet.Tables[0].Columns.Add("curr_date");

        sourceDataSet.Tables[0].Columns.Add("pt_name");
        sourceDataSet.Tables[0].Columns.Add("pt_title");
        sourceDataSet.Tables[0].Columns.Add("pt_firstname");
        sourceDataSet.Tables[0].Columns.Add("pt_middlename");
        sourceDataSet.Tables[0].Columns.Add("pt_surname");
        sourceDataSet.Tables[0].Columns.Add("pt_gender");
        sourceDataSet.Tables[0].Columns.Add("pt_dob");
        sourceDataSet.Tables[0].Columns.Add("pt_dob_day_month_only");

        sourceDataSet.Tables[0].Columns.Add("pt_conditions");

        sourceDataSet.Tables[0].Columns.Add("pt_addr");
        sourceDataSet.Tables[0].Columns.Add("pt_addr_tabbedx1");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_line1");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_line2");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_street");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_suburb");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_postcode");
        //sourceDataSet.Tables[0].Columns.Add("pt_addr_country");
        sourceDataSet.Tables[0].Columns.Add("pt_phone");

        sourceDataSet.Tables[0].Columns.Add("pt_last_bk_date");

        sourceDataSet.Tables[0].Columns.Add("pt_hc_card_nbr");
        sourceDataSet.Tables[0].Columns.Add("pt_hc_card_name");
        sourceDataSet.Tables[0].Columns.Add("pt_hc_card_refsigneddate");
        sourceDataSet.Tables[0].Columns.Add("pt_epc_expire_date");
        sourceDataSet.Tables[0].Columns.Add("pt_epc_count_remaining");

        sourceDataSet.Tables[0].Columns.Add("pt_mc_card_nbr");
        sourceDataSet.Tables[0].Columns.Add("pt_mc_card_name");
        sourceDataSet.Tables[0].Columns.Add("pt_mc_card_refsigneddate");

        sourceDataSet.Tables[0].Columns.Add("pt_dvacard_nbr");
        sourceDataSet.Tables[0].Columns.Add("pt_dvacard_name");
        sourceDataSet.Tables[0].Columns.Add("pt_dvacard_refsigneddate");

        sourceDataSet.Tables[0].Columns.Add("org_name");
        sourceDataSet.Tables[0].Columns.Add("org_abn");
        sourceDataSet.Tables[0].Columns.Add("org_acn");
        sourceDataSet.Tables[0].Columns.Add("org_bpay_account");

        sourceDataSet.Tables[0].Columns.Add("org_addr");
        sourceDataSet.Tables[0].Columns.Add("org_addr_tabbedx1");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_line1");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_line2");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_street");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_suburb");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_postcode");
        //sourceDataSet.Tables[0].Columns.Add("org_addr_country");
        sourceDataSet.Tables[0].Columns.Add("org_phone");
        sourceDataSet.Tables[0].Columns.Add("org_office_fax");
        sourceDataSet.Tables[0].Columns.Add("org_web");
        sourceDataSet.Tables[0].Columns.Add("org_email");

        sourceDataSet.Tables[0].Columns.Add("ref_name");
        sourceDataSet.Tables[0].Columns.Add("ref_title");
        sourceDataSet.Tables[0].Columns.Add("ref_firstname");
        sourceDataSet.Tables[0].Columns.Add("ref_middlename");
        sourceDataSet.Tables[0].Columns.Add("ref_surname");
        //sourceDataSet.Tables[0].Columns.Add("ref_gender");
        //sourceDataSet.Tables[0].Columns.Add("ref_dob");

        sourceDataSet.Tables[0].Columns.Add("ref_addr");
        sourceDataSet.Tables[0].Columns.Add("ref_addr_tabbedx1");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_line1");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_line2");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_street");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_suburb");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_postcode");
        //sourceDataSet.Tables[0].Columns.Add("ref_addr_country");
        sourceDataSet.Tables[0].Columns.Add("ref_phone");
        sourceDataSet.Tables[0].Columns.Add("ref_fax");

        sourceDataSet.Tables[0].Columns.Add("bk_date");
        sourceDataSet.Tables[0].Columns.Add("bk_time");
        sourceDataSet.Tables[0].Columns.Add("bk_length");

        sourceDataSet.Tables[0].Columns.Add("bk_prov_name");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_title");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_firstname");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_middlename");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_surname");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_number");
        //sourceDataSet.Tables[0].Columns.Add("bk_prov_gender");
        //sourceDataSet.Tables[0].Columns.Add("bk_prov_dob");

        sourceDataSet.Tables[0].Columns.Add("bk_treatment_notes");

        sourceDataSet.Tables[0].Columns.Add("bk_offering_name");
        sourceDataSet.Tables[0].Columns.Add("bk_offering_short_name");
        sourceDataSet.Tables[0].Columns.Add("bk_offering_descr");

        string bookingNotes = string.Empty;
        if (booking != null)
        {
            if (booking.Patient != null)
            {
                foreach (Note note in booking.GetTreatmentNotes())
                    bookingNotes += "Treatment Note:" + Environment.NewLine + Environment.NewLine + note.Text + Environment.NewLine + Environment.NewLine;
            }
            else if (patient != null) // group bookings - but need patientID
            {
                BookingPatient bp = BookingPatientDB.GetByBookingAndPatientID(booking.BookingID, patient.PatientID);
                if (bp != null)
                    foreach (Note note in NoteDB.GetByEntityID(bp.EntityID, "252"))
                        bookingNotes += "Treatment Note:" + Environment.NewLine + Environment.NewLine + note.Text + Environment.NewLine + Environment.NewLine;
            }

        }

        /*  -- for testing
            string s1 = patient == null ? "No patient found" : patient.Person.FullnameWithTitleWithoutMiddlename;
            string s2 = patient == null ? "No patient found" : (patient.Person.Title.ID == 0 ? "" : patient.Person.Title.Descr);
            string s3 = patient == null ? "" : patient.Person.Firstname;
            string s4 = patient == null ? "" : patient.Person.Middlename;
            string s5 = patient == null ? "" : patient.Person.Surname;
            string s6 = patient == null ? "" : patient.Person.Gender;
            string s7 = patient == null ? "" : patient.Person.Dob == DateTime.MinValue ? "" : patient.Person.Dob.ToString("d MMMM, yyyy");

            string s8 = patientAddress == null ? "No address found" : patientAddress.AddrLine1;
            string s9 = patientAddress == null ? "" : patientAddress.AddrLine2;
            string s10 = patientAddress == null || patientAddress.AddressChannel == null ? "" : (patientAddress.AddressChannel.AddressChannelID == 1 ? "" : patientAddress.AddressChannel.DisplayName);
            string s11 = patientAddress == null ? "" : patientAddress.Suburb.Name;
            string s12 = patientAddress == null ? "" : patientAddress.Suburb.Postcode;
            string s13 = patientAddress == null || patientAddress.Country == null ? "" : patientAddress.Country.Descr;

            string s14 = activeHcCard == null ? "No hc card found" : activeHcCard.CardNbr + " - " + activeHcCard.CardFamilyMemberNbr;
            string s15 = activeHcCard == null ? "" : activeHcCard.CardName;
            string s16 = activeHcCard == null ? "" : activeHcCard.DateReferralSigned.ToString("d MMMM, yyyy");

            string s17 = medicareCard == null ? "No medicare card found" : medicareCard.CardNbr + " - " + medicareCard.CardFamilyMemberNbr;
            string s18 = medicareCard == null ? "" : medicareCard.CardName;
            string s19 = medicareCard == null ? "" : medicareCard.DateReferralSigned.ToString("d MMMM, yyyy");

            string s20 = dvaCard == null ? "No dva card found" : dvaCard.CardNbr;
            string s21 = dvaCard == null ? "" : dvaCard.CardName;
            string s22 = dvaCard == null ? "" : dvaCard.DateReferralSigned.ToString("d MMMM, yyyy");

            string s23 = org != null ? org.Name        : site.Name;
            string s24 = org != null ? org.Abn         : site.Abn;
            string s25 = org != null ? org.Acn         : site.Acn;
            string s26 = org != null ? org.BpayAccount : site.BankBpay;

            string s27 = orgAddress == null ? "No address found" : orgAddress.AddrLine1;
            string s28 = orgAddress == null ? "" : orgAddress.AddrLine2;
            string s29 = orgAddress == null ? "" : (orgAddress.AddressChannel.AddressChannelID == 1 ? "" : orgAddress.AddressChannel.DisplayName);
            string s30 = orgAddress == null ? "" : orgAddress.Suburb.Name;
            string s31 = orgAddress == null ? "" : orgAddress.Suburb.Postcode;
            string s32 = orgAddress == null || orgAddress.Country == null ? "" : orgAddress.Country.Descr;

            string s33 = regReferrer == null ? "No referrer found" : regReferrer.Referrer.Person.FullnameWithTitleWithoutMiddlename;
            string s34 = regReferrer == null ? "No referrer found" : (regReferrer.Referrer.Person.Title.ID == 0 ? "" : regReferrer.Referrer.Person.Title.Descr);
            string s35 = regReferrer == null ? "" : regReferrer.Referrer.Person.Firstname;
            string s36 = regReferrer == null ? "" : regReferrer.Referrer.Person.Middlename;
            string s37 = regReferrer == null ? "" : regReferrer.Referrer.Person.Surname;
            string s38 = regReferrer == null ? "" : regReferrer.Referrer.Person.Gender;
            string s39 = regReferrer == null ? "" : regReferrer.Referrer.Person.Dob.ToString("d MMMM, yyyy");

            string s40 = referrerAddress == null ? "No address found" : referrerAddress.AddrLine1;
            string s41 = referrerAddress == null ? "" : referrerAddress.AddrLine2;
            string s42 = referrerAddress == null ? "" : (referrerAddress.AddressChannel.AddressChannelID == 1 ? "" : referrerAddress.AddressChannel.DisplayName);
            string s43 = referrerAddress == null ? "" : referrerAddress.Suburb.Name;
            string s44 = referrerAddress == null ? "" : referrerAddress.Suburb.Postcode;
            string s45 = referrerAddress == null || referrerAddress.Country == null ? "" : referrerAddress.Country.Descr;

            string s46 = booking == null ? "" : booking.DateStart.ToString("d MMMM, yyyy");
            string s47 = booking == null ? "" : booking.DateStart.ToString("HH:mm");

            string s48 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.FullnameWithTitleWithoutMiddlename;
            string s49 = booking == null || booking.Provider == null ? "" : (booking.Provider.Person.Title.ID == 0 ? "" : booking.Provider.Person.Title.Descr);
            string s50 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Firstname;
            string s51 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Middlename;
            string s52 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Surname;
            string s53 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Gender;
            string s54 = booking == null || booking.Provider == null ? "" : booking.Provider.Person.Dob.ToString("d MMMM, yyyy");

            string s55 = booking == null ? "" : bookingNotes;

            string s56 = booking == null || booking.Offering == null ? "" : booking.Offering.Name;
            string s57 = booking == null || booking.Offering == null ? "" : booking.Offering.ShortName;
            string s58 = booking == null || booking.Offering == null ? "" : booking.Offering.Descr;
        */

        string patientAddressText  , patientAddressTabbedText  , patientPhoneText;
        string orgAddressText      , orgAddressTabbedText      , orgPhoneText       , orgFaxText, orgWebText, orgEmailText;
        string referrerAddressText , referrerAddressTabbedText , referrerPhoneText, referrerFaxText;
        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            patientAddressText        = patientAddress == null    ? "No address found"      : patientAddress.GetFormattedAddress("No address found");
            patientAddressTabbedText  = patientAddress == null    ? "No address found"      : patientAddress.GetFormattedAddress("No address found", 1);
            orgAddressText            = orgAddress     == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found");
            orgAddressTabbedText      = orgAddress     == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found", 1);
            referrerAddressText       = orgAddress     == null    ? "No address found"      : referrerAddress.GetFormattedAddress("No address found");
            referrerAddressTabbedText = orgAddress     == null    ? "No address found"      : referrerAddress.GetFormattedAddress("No address found", 1);
            patientPhoneText          = patientPhone   == null    ? "No phone number found" : patientPhone.GetFormattedPhoneNumber("No phone number found");
            orgPhoneText              = orgPhone       == null    ? "No phone number found" : orgPhone.GetFormattedPhoneNumber("No phone number found");
            referrerPhoneText         = referrerPhone  == null    ? "No phone number found" : referrerPhone.GetFormattedPhoneNumber("No phone number found");
            referrerFaxText           = referrerFax    == null    ? "No fax number found"   : referrerFax.GetFormattedPhoneNumber("No fax number found");
            orgFaxText                = orgFax         == null    ? "No fax number found"   : orgFax.GetFormattedPhoneNumber("No fax number found");
            orgWebText                = orgWeb         == null    ? "No website found"      : orgWeb.AddrLine1;
            orgEmailText              = orgEmail       == null    ? "No email found"        : orgEmail.AddrLine1;
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            patientAddressText        = patientAddressAus  == null ? "No address found"      : patientAddressAus.GetFormattedAddress("No address found");
            patientAddressTabbedText  = patientAddressAus  == null ? "No address found"      : patientAddressAus.GetFormattedAddress("No address found", 1);
            orgAddressText            = orgAddressAus      == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found");
            orgAddressTabbedText      = orgAddressAus      == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found", 1);
            referrerAddressText       = referrerAddressAus == null ? "No address found"      : referrerAddressAus.GetFormattedAddress("No address found");
            referrerAddressTabbedText = referrerAddressAus == null ? "No address found"      : referrerAddressAus.GetFormattedAddress("No address found", 1);
            patientPhoneText          = patientPhoneAus    == null ? "No phone number found" : patientPhoneAus.GetFormattedPhoneNumber("No phone number found");
            orgPhoneText              = orgPhoneAus        == null ? "No phone number found" : orgPhoneAus.GetFormattedPhoneNumber("No phone number found");
            referrerPhoneText         = referrerPhoneAus   == null ? "No phone number found" : referrerPhoneAus.GetFormattedPhoneNumber("No phone number found");
            referrerFaxText           = referrerFaxAus     == null ? "No fax number found"   : referrerFaxAus.GetFormattedPhoneNumber("No fax number found");
            orgFaxText                = orgFaxAus          == null ? "No fax number found"   : orgFaxAus.GetFormattedPhoneNumber("No fax number found");
            orgWebText                = orgWebAus          == null ? "No website found"      : orgWebAus.AddrLine1;
            orgEmailText              = orgEmailAus        == null ? "No email found"        : orgEmailAus.AddrLine1;
        }
        else
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());

        string    ptConditionsText   = string.Empty;
        Hashtable selectedConditions = PatientConditionDB.GetHashtable_ByPatientID(patient.PatientID, false);
        foreach (Condition condition in ConditionDB.GetAll())
            if (selectedConditions[condition.ConditionID] != null)
                ptConditionsText += (ptConditionsText.Length == 0 ? "" : Environment.NewLine) + " • " + ((PatientCondition)selectedConditions[condition.ConditionID]).Condition.Descr;
        if (ptConditionsText == string.Empty)
            ptConditionsText = " • None";

        string bk_prov_number = string.Empty;
        if (booking != null && booking.Provider != null && booking.Organisation != null)
        {
            RegisterStaff regStaff = RegisterStaffDB.GetByStaffIDAndOrganisationID(booking.Provider.StaffID, booking.Organisation.OrganisationID);
            bk_prov_number = (regStaff == null) ? string.Empty : regStaff.ProviderNumber;
        }

        TimeSpan bkTime = booking != null ? booking.DateEnd.Subtract(booking.DateStart) : TimeSpan.Zero;
        string bkTimeLength;
        if (bkTime.Minutes > 0 && bkTime.Hours > 0)
            bkTimeLength = bkTime.Hours + (bkTime.Hours > 1 ? "hrs " : "hr ") + bkTime.Minutes + " minutes";
        else if (bkTime.Hours > 0)
            bkTimeLength = bkTime.Hours + (bkTime.Hours > 1 ? "hours " : "hour ");
        else if (bkTime.Minutes > 0)
            bkTimeLength = bkTime.Minutes + bkTime.Minutes + " minutes";
        else
            bkTimeLength = bkTime.Minutes + " minutes";

        sourceDataSet.Tables[0].Rows.Add(

            DateTime.Now.ToString("d MMMM, yyyy"),

            patient == null ? "No patient found" : patient.Person.FullnameWithTitleWithoutMiddlename,
            patient == null ? "No patient found" : (patient.Person.Title.ID == 0 ? "" : patient.Person.Title.Descr),
            patient == null ? "" : patient.Person.Firstname,
            patient == null ? "" : patient.Person.Middlename,
            patient == null ? "" : patient.Person.Surname,
            patient == null ? "" : patient.Person.Gender,
            patient == null ? "" : patient.Person.Dob == DateTime.MinValue ? (object)DBNull.Value : patient.Person.Dob.ToString("d MMMM, yyyy"),
            patient == null ? "" : patient.Person.Dob == DateTime.MinValue ? (object)DBNull.Value : patient.Person.Dob.ToString("MMMM ") + Utilities.GetDateOrdinal(patient.Person.Dob.Day),

            ptConditionsText,

            patientAddressText,
            patientAddressTabbedText,
            //patientAddress == null                                          ? "No address found" : patientAddress.AddrLine1,
            //patientAddress == null                                          ? "" : patientAddress.AddrLine2,
            //patientAddress == null || patientAddress.AddressChannel == null ? "" : (patientAddress.AddressChannel.AddressChannelID == 1 ? "" : patientAddress.AddressChannel.DisplayName),
            //patientAddress == null || patientAddress.Suburb  == null        ? "" : patientAddress.Suburb.Name,
            //patientAddress == null || patientAddress.Suburb  == null        ? "" : patientAddress.Suburb.Postcode,
            //patientAddress == null || patientAddress.Country == null        ? "" : patientAddress.Country.Descr,
            patientPhoneText,

            pt_last_bk_date == DateTime.MinValue ? "No previous bookings found" : pt_last_bk_date.ToString("d MMMM, yyyy"),

            activeHcCard == null ? "No hc card found" : activeHcCard.CardNbr + " - " + activeHcCard.CardFamilyMemberNbr,
            activeHcCard == null ? "" : activeHcCard.CardName,
            activeHcCard == null ? (object)"" : activeHcCard.DateReferralSigned.ToString("d MMMM, yyyy"),
            epc_expire_date == DateTime.MinValue ? (object)"" : epc_expire_date.ToString("d MMMM, yyyy"),
            epc_expire_date == DateTime.MinValue ? (object)"" : epc_count_remaining,

            medicareCard == null ? "No medicare card found" : medicareCard.CardNbr + " - " + medicareCard.CardFamilyMemberNbr,
            medicareCard == null ? " " : medicareCard.CardName,
            medicareCard == null ? (object)" " : medicareCard.DateReferralSigned.ToString("d MMMM, yyyy"),

            dvaCard == null ? "No dva card found" : dvaCard.CardNbr,
            dvaCard == null ? "" : dvaCard.CardName,
            dvaCard == null ? (object)"" : dvaCard.DateReferralSigned.ToString("d MMMM, yyyy"),

            org != null ? org.Name        : site.Name,
            org != null ? org.Abn         : site.Abn,
            org != null ? org.Acn         : site.Acn,
            org != null ? org.BpayAccount : site.BankBpay,

            orgAddressText,
            orgAddressTabbedText,
            //orgAddress == null ? "No address found" : orgAddress.AddrLine1,
            //orgAddress == null ? "" : orgAddress.AddrLine2,
            //orgAddress == null ? "" : (orgAddress.AddressChannel.AddressChannelID == 1 ? "" : orgAddress.AddressChannel.DisplayName),
            //orgAddress == null ? "" : orgAddress.Suburb.Name,
            //orgAddress == null ? "" : orgAddress.Suburb.Postcode,
            //orgAddress == null || orgAddress.Country == null ? "" : orgAddress.Country.Descr,
            orgPhoneText,
            orgFaxText,
            orgWebText,
            orgEmailText,

            regReferrer == null ? "No referrer found" : regReferrer.Referrer.Person.FullnameWithTitleWithoutMiddlename,
            regReferrer == null ? "No referrer found" : (regReferrer.Referrer.Person.Title.ID == 0 ? "" : regReferrer.Referrer.Person.Title.Descr),
            regReferrer == null ? "" : regReferrer.Referrer.Person.Firstname,
            regReferrer == null ? "" : regReferrer.Referrer.Person.Middlename,
            regReferrer == null ? "" : regReferrer.Referrer.Person.Surname,
            //regReferrer == null ? "" : regReferrer.Referrer.Person.Gender,
            //regReferrer == null ? (object)"" : regReferrer.Referrer.Person.Dob.ToString("d MMMM, yyyy"),

            referrerAddressText,
            referrerAddressTabbedText,
            //referrerAddress == null ? "No address found" : referrerAddress.AddrLine1,
            //referrerAddress == null ? "" : referrerAddress.AddrLine2,
            //referrerAddress == null ? "" : (referrerAddress.AddressChannel.AddressChannelID == 1 ? "" : referrerAddress.AddressChannel.DisplayName),
            //referrerAddress == null ? "" : referrerAddress.Suburb.Name,
            //referrerAddress == null ? "" : referrerAddress.Suburb.Postcode,
            //referrerAddress == null || referrerAddress.Country == null ? "" : referrerAddress.Country.Descr,
            referrerPhoneText,
            referrerFaxText,

            booking == null ? "" : booking.DateStart.ToString("d MMMM, yyyy"),
            booking == null ? "" : booking.DateStart.ToString("HH:mm"),
            booking == null ? "" : bkTimeLength,

            booking == null || booking.Provider == null ? "" : booking.Provider.Person.FullnameWithTitleWithoutMiddlename,
            booking == null || booking.Provider == null ? "" : (booking.Provider.Person.Title.ID == 0 ? "" : booking.Provider.Person.Title.Descr),
            booking == null || booking.Provider == null ? "" : booking.Provider.Person.Firstname,
            booking == null || booking.Provider == null ? "" : booking.Provider.Person.Middlename,
            booking == null || booking.Provider == null ? "" : booking.Provider.Person.Surname,
            bk_prov_number,
            //booking == null || booking.Provider == null ? "" : booking.Provider.Person.Gender,
            //booking == null || booking.Provider == null ? "" : booking.Provider.Person.Dob.ToString("d MMMM, yyyy"),

            booking == null ? "" : bookingNotes,

            booking == null || booking.Offering == null ? "" : booking.Offering.Name,
            booking == null || booking.Offering == null ? "" : booking.Offering.ShortName,
            booking == null || booking.Offering == null ? "" : booking.Offering.Descr

            );

        //now merge
        string errorString = string.Empty;
        //if (!OfficeInterop.MailMerge.MergeDataWithWordTemplate(sourceTemplatePath, outputDocPath, sourceDataSet, isDoubleSidedPrinting, extraPages, out errorString))
        //    throw new CustomMessageException("Error:" + errorString);
        if (!WordMailMerger.Merge(sourceTemplatePath, outputDocPath, sourceDataSet, null, 0, false, isDoubleSidedPrinting, extraPages, true, null, out errorString))
            throw new CustomMessageException("Error:" + errorString);

        if (!historyDir.EndsWith(@"\"))
            historyDir += @"\";

        //
        // create pdf file to be stored because it's much smaller in size
        //
        string tmpLettersDirectory = Letter.GetTempLettersDirectory();
        if (!System.IO.Directory.Exists(tmpLettersDirectory))
            throw new CustomMessageException("Temp letters directory doesn't exist");
        string outputDocPathPDF = FileHelper.GetTempFileName(tmpLettersDirectory + Path.ChangeExtension(historyFileName, ".pdf"));
        string _errorString = string.Empty;
        if (keepHistoryInDB || keepHistoryInFile)
            OfficeInterop.FormatConverter.WordToPDF(outputDocPath, outputDocPathPDF, out _errorString);

        if (keepHistoryInDB)
        {
            byte[] doc_contents = System.IO.File.ReadAllBytes(outputDocPathPDF);
            int letterHistoryID = LetterPrintHistoryDB.Insert(letterID, letterPrintHistorySendMethodID, booking == null ? -1 : booking.BookingID, patient == null ? -1 : patient.PatientID, org != null ? org.OrganisationID : 0, regReferrer == null ? -1 : regReferrer.RegisterReferrerID, staff.StaffID, -1, historyFileName, doc_contents);

            if (keepHistoryInFile)
            {
                string filePath = historyDir + letterHistoryID + System.IO.Path.GetExtension(outputDocPathPDF);
                if (System.IO.File.Exists(filePath))
                    throw new CustomMessageException("File already exists: " + filePath);
                if (!Directory.Exists(historyDir))
                    Directory.CreateDirectory(historyDir);
                System.IO.File.Copy(outputDocPathPDF, filePath);
            }
        }
        else if (keepHistoryInFile)
        {
            int letterHistoryID = LetterPrintHistoryDB.Insert(letterID, letterPrintHistorySendMethodID, booking == null ? -1 : booking.BookingID, patient == null ? -1 : patient.PatientID, org != null ? org.OrganisationID : 0, regReferrer == null ? -1 : regReferrer.RegisterReferrerID, staff == null ? -1 : staff.StaffID, healthCardAction == null ? -1 : healthCardAction.HealthCardActionID, historyFileName, null);

            string filePath = historyDir + letterHistoryID + System.IO.Path.GetExtension(outputDocPathPDF);
            if (System.IO.File.Exists(filePath))
                throw new CustomMessageException("File already exists: " + filePath);
            if (!Directory.Exists(historyDir))
                Directory.CreateDirectory(historyDir);
            System.IO.File.Copy(outputDocPathPDF, filePath);
        }

        if (keepHistoryInDB || keepHistoryInFile)
            File.Delete(outputDocPathPDF);
    }
    protected TableRow CreateNewRow(ContactAus contact, int width, int height, bool hasFreeTextRow = false, bool isFreeTextRow = false)
    {
        bool isMobileDevice = Utilities.IsMobileDevice(Request);

        bool isAddress = contact.ContactType.ContactTypeGroup.ID == 1;
        bool isPhone   = contact.ContactType.ContactTypeGroup.ID == 2;
        bool isBedroom = contact.ContactType.ContactTypeGroup.ID == 3;

        bool isEmail   = contact.ContactType.ContactTypeID == 27;
        bool isWebsite = contact.ContactType.ContactTypeID == 28;

        int  rowspan      = !hasFreeTextRow ? 1 : (hasFreeTextRow && isFreeTextRow ? 2 : 0);
        bool showFreeText = hasFreeTextRow && isFreeTextRow;


        TableRow tr = new TableRow();

        if (rowspan > 0)
        {
            tr.Cells.Add(NewCell("[", false, 1, rowspan));

            string onclick;

            if (!isMobileDevice)
            {
                string allFeatures = "dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;resizable:no; scroll:no";
                // this was causing the outer page to validate its controls for no reason I can understand, so I just changed it to refresh the page
                //string onclick     = "onclick=\"javascript:window.showModalDialog('ContactAusDetailV2.aspx?type=edit&id=" + contact.ContactID.ToString() + "', '', '" + allFeatures + "');document.getElementById('" + btnUpdateAddresses.ClientID + "').click();return false;\"";
                onclick = "onclick=\"javascript:window.showModalDialog('ContactAusDetailV2.aspx?type=edit&id=" + contact.ContactID.ToString() + "', '', '" + allFeatures + "');window.location.href=window.location.href;return false;\"";
            }
            else
            {
                onclick = "onclick=\"open_new_tab('ContactAusDetailV2.aspx?type=edit&id=" + contact.ContactID.ToString() + "&refresh_on_close=1');return false;\"";
            }

            string href = "<a style=\"text-decoration: none\" title=\"Edit\" AlternateText=\"Edit\" " + onclick + " href=\"#\"><img src=\"/images/edit-icon-10.png\"></a>";

            tr.Cells.Add(NewCell(href, false, 1, rowspan));

            TableCell   cell = new TableCell();
            ImageButton btn  = new ImageButton()
            {
                ID              = "btnContact_" + contact.ContactID.ToString(),
                ImageUrl        = "~/images/Delete-icon-10.png",
                CommandArgument = contact.ContactID.ToString(),
                OnClientClick   = "javascript:if (!confirm('Are you sure you want to delete this?')) return false;",
                ToolTip         = "Delete"
            };
            btn.Command += new CommandEventHandler(DeleteContact_Command);
            btn.Style["text-decoration"] = "none";
            cell.Controls.Add(btn);
            if (rowspan > 1)
            {
                cell.RowSpan = rowspan;
            }
            tr.Cells.Add(cell);

            tr.Cells.Add(NewCell("]", false, 1, rowspan));
            tr.Cells.Add(NewCell("&nbsp;", false, 1, rowspan));
        }


        if (isAddress)
        {
            if (showFreeText)
            {
                tr.Cells.Add(NewCell(contact.FreeText + ":", false, 5));
            }
            else
            {
                tr.Cells.Add(NewCell(contact.AddrLine1, true));
                tr.Cells.Add(NewCell("&nbsp;"));
                tr.Cells.Add(NewCell(contact.StreetName + (contact.AddressChannelType == null ? "" : (contact.StreetName.Length == 0 ? "" : " ") + contact.AddressChannelType.Descr), true));
                tr.Cells.Add(NewCell("&nbsp;"));
                tr.Cells.Add(NewCell(contact.Suburb != null ? contact.Suburb.Name : "", true));
            }
        }
        else if (isBedroom)
        {
            if (showFreeText)
            {
                tr.Cells.Add(NewCell(contact.FreeText + ":", false, 3));
            }
            else
            {
                tr.Cells.Add(NewCell(contact.AddrLine1, true));
            }
        }
        else
        {
            if (showFreeText)
            {
                tr.Cells.Add(NewCell(contact.FreeText + ":", false, 3));
            }
            else
            {
                if (isPhone)
                {
                    tr.Cells.Add(NewCell(Utilities.FormatPhoneNumber(contact.AddrLine1), true));
                }
                else if (isEmail)
                {
                    bool updateOnClose = false;

                    /*
                     * string allFeaturesEmail = "dialogWidth:675px;dialogHeight:675px;center:yes;resizable:no; scroll:no";
                     * string onclickEmail = "onclick=\"javascript:window.showModalDialog('SendEmail.aspx?&id=" + contact.ContactID.ToString() + "', '', '" + allFeaturesEmail + "');" + (updateOnClose ? "document.getElementById('" + btnUpdateAddresses.ClientID + "').click();" : "") + "return false;\"";
                     * string hrefEmail = "<a style=\"text-decoration: none\" title=\"Edit\" AlternateText=\"Edit\" " + onclickEmail + " href=\"\">" + contact.AddrLine1 + "</a>";
                     * tr.Cells.Add(NewCell(hrefEmail, true));
                     */

                    tr.Cells.Add(NewCell(contact.AddrLine1, true));
                }
                else if (isWebsite)
                {
                    string allFeaturesEmail = ""; // "dialogWidth:675px;dialogHeight:600px;center:yes;resizable:no; scroll:no";
                    string onclickEmail     = "onclick=\"window.open('" + (contact.AddrLine1.StartsWith("http://") || contact.AddrLine1.StartsWith("https://") ? "" : "http://") + contact.AddrLine1 + "', '', '" + allFeaturesEmail + "');" + "return false;\"";
                    string hrefEmail        = "<a style=\"text-decoration: none\" " + onclickEmail + " href=\"\">" + contact.AddrLine1 + "</a>";
                    tr.Cells.Add(NewCell(hrefEmail, true));
                }
                else
                {
                    tr.Cells.Add(NewCell(contact.AddrLine1, true));
                }

                tr.Cells.Add(NewCell("&nbsp;&nbsp;&nbsp;"));
                tr.Cells.Add(NewCell("(" + contact.ContactType.Descr + ")", true));
            }
        }

        return(tr);
    }
Esempio n. 16
0
    protected void MergeFile(bool isAgedCare, string originalFile, string outputFile)
    {
        Booking   booking = BookingDB.GetByID(GetFormBooking());
        DataTable dt      = Session["invoicelistac_data"] as DataTable;


        string orgAddressText, orgAddressTabbedText, orgPhoneText, orgFaxText, orgWebText, orgEmailText;

        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            Contact orgAddress = ContactDB.GetFirstByEntityID(1, booking.Organisation != null ? booking.Organisation.EntityID : -1);
            Contact orgPhone   = ContactDB.GetFirstByEntityID(null, booking.Organisation != null ? booking.Organisation.EntityID : -1, "30,33,34");
            Contact orgFax     = ContactDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 29);
            Contact orgWeb     = ContactDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 28);
            Contact orgEmail   = ContactDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 27);

            orgAddressText       = orgAddress == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found");
            orgAddressTabbedText = orgAddress == null    ? "No address found"      : orgAddress.GetFormattedAddress("No address found", 1);
            orgPhoneText         = orgPhone == null    ? "No phone number found" : orgPhone.GetFormattedPhoneNumber("No phone number found");
            orgFaxText           = orgFax == null    ? "No fax number found"   : orgFax.GetFormattedPhoneNumber("No fax number found");
            orgWebText           = orgWeb == null    ? "No website found"      : orgWeb.AddrLine1;
            orgEmailText         = orgEmail == null    ? "No email found"        : orgEmail.AddrLine1;
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            ContactAus orgAddressAus = ContactAusDB.GetFirstByEntityID(1, booking.Organisation != null ? booking.Organisation.EntityID : -1);
            ContactAus orgPhoneAus   = ContactAusDB.GetFirstByEntityID(null, booking.Organisation != null ? booking.Organisation.EntityID : -1, "30,33,34");
            ContactAus orgFaxAus     = ContactAusDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 29);
            ContactAus orgWebAus     = ContactAusDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 28);
            ContactAus orgEmailAus   = ContactAusDB.GetFirstByEntityID(-1, booking.Organisation != null ? booking.Organisation.EntityID : -1, 27);

            orgAddressText       = orgAddressAus == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found");
            orgAddressTabbedText = orgAddressAus == null ? "No address found"      : orgAddressAus.GetFormattedAddress("No address found", 1);
            orgPhoneText         = orgPhoneAus == null ? "No phone number found" : orgPhoneAus.GetFormattedPhoneNumber("No phone number found");
            orgFaxText           = orgFaxAus == null ? "No fax number found"   : orgFaxAus.GetFormattedPhoneNumber("No fax number found");
            orgWebText           = orgWebAus == null ? "No website found"      : orgWebAus.AddrLine1;
            orgEmailText         = orgEmailAus == null ? "No email found"        : orgEmailAus.AddrLine1;
        }
        else
        {
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
        }


        string providerNumber = booking.Provider.ProviderNumber;

        if (!isAgedCare)
        {
            RegisterStaff regStaff = RegisterStaffDB.GetByStaffIDAndOrganisationID(booking.Provider.StaffID, booking.Organisation.OrganisationID, true);
            if (regStaff != null)
            {
                providerNumber = regStaff.ProviderNumber;
            }
        }


        System.Data.DataSet sourceDataSet = new System.Data.DataSet();
        sourceDataSet.Tables.Add("MergeIt");


        sourceDataSet.Tables[0].Columns.Add("curr_date");

        sourceDataSet.Tables[0].Columns.Add("bk_prov_fullname");
        sourceDataSet.Tables[0].Columns.Add("bk_prov_number");
        sourceDataSet.Tables[0].Columns.Add("bk_date");

        sourceDataSet.Tables[0].Columns.Add("bk_org_name");
        sourceDataSet.Tables[0].Columns.Add("bk_org_abn");
        sourceDataSet.Tables[0].Columns.Add("bk_org_acn");
        sourceDataSet.Tables[0].Columns.Add("bk_org_bpay_account");
        sourceDataSet.Tables[0].Columns.Add("bk_org_addr");
        sourceDataSet.Tables[0].Columns.Add("bk_org_addr_tabbedx1");
        sourceDataSet.Tables[0].Columns.Add("bk_org_phone");
        sourceDataSet.Tables[0].Columns.Add("bk_org_office_fax");
        sourceDataSet.Tables[0].Columns.Add("bk_org_web");
        sourceDataSet.Tables[0].Columns.Add("bk_org_email");


        sourceDataSet.Tables[0].Rows.Add(
            DateTime.Now.ToString("d MMMM, yyyy"),

            booking.Provider.Person.FullnameWithoutMiddlename,
            providerNumber,
            booking.DateStart.ToString("d MMMM, yyyy"),

            booking.Organisation.Name,
            booking.Organisation.Abn,
            booking.Organisation.Acn,
            booking.Organisation.BpayAccount,
            orgAddressText,
            orgAddressTabbedText,
            orgPhoneText,
            orgFaxText,
            orgWebText,
            orgEmailText
            );



        string[,] tblInfo = new string[dt.Rows.Count, isAgedCare ? 5 : 4];

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (isAgedCare)
            {
                /*
                 *  0 = i (row nbr)
                 *  1 = room (addr1 of patient)
                 *  2 = resident
                 *  3 = resident type
                 *  4 = debtor
                 */

                tblInfo[i, 0] = (i + 1).ToString();
                tblInfo[i, 1] = dt.Rows[i]["Room"].ToString();
                tblInfo[i, 2] = dt.Rows[i]["PatientName"].ToString();
                tblInfo[i, 3] = dt.Rows[i]["ItemDescr"].ToString();
                tblInfo[i, 4] = dt.Rows[i]["Debtor"].ToString();
            }
            else
            {
                /*
                 *  0 = i (row nbr)
                 *  1 = patient
                 *  2 = service
                 *  3 = debtor
                 */

                tblInfo[i, 0] = (i + 1).ToString();
                tblInfo[i, 1] = dt.Rows[i]["PatientName"].ToString();
                tblInfo[i, 2] = dt.Rows[i]["ItemDescr"].ToString();
                tblInfo[i, 3] = dt.Rows[i]["Debtor"].ToString();
            }
        }



        // merge

        string errorString = null;

        WordMailMerger.Merge(

            originalFile,
            outputFile,
            sourceDataSet,

            tblInfo,
            1,
            true,

            true,
            null,
            true,
            null,
            out errorString);

        if (errorString != string.Empty)
        {
            throw new Exception(errorString);
        }
    }
Esempio n. 17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                Utilities.SetNoCache(Response);
            }
            HideErrorMessage();

            if (!IsPostBack)
            {
                PagePermissions.EnforcePermissions_RequireAny(Session, Response, true, true, true, true, true, false);
                Session.Remove("invoicelistac_sortexpression");
                Session.Remove("invoicelistac_data");

                if (!IsValidFormBooking())
                {
                    throw new CustomMessageException("No booking in url");
                }

                Booking booking = BookingDB.GetByID(GetFormBooking());


                string orgAddressText;
                if (Utilities.GetAddressType().ToString() == "Contact")
                {
                    Contact orgAddress = ContactDB.GetFirstByEntityID(1, booking.Organisation != null ? booking.Organisation.EntityID : -1);
                    orgAddressText = orgAddress == null    ? "No address found" : orgAddress.GetFormattedAddress("No address found");
                }
                else if (Utilities.GetAddressType().ToString() == "ContactAus")
                {
                    ContactAus orgAddressAus = ContactAusDB.GetFirstByEntityID(1, booking.Organisation != null ? booking.Organisation.EntityID : -1);
                    orgAddressText = orgAddressAus == null ? "No address found" : orgAddressAus.GetFormattedAddress("No address found");
                }
                else
                {
                    throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
                }


                lblTreatmentDate.Text = booking.DateStart.ToString("d MMM, yyyy") + "&nbsp;&nbsp;" + booking.DateStart.ToString("H:mm") + (booking.DateStart.Hour < 12 ? "am" : "pm");
                lblOrgType.Text       = booking.Organisation.OrganisationType.Descr;
                lblOrgName.Text       = booking.Organisation.Name;
                lblOrgAddress.Text    = orgAddressText.Replace(Environment.NewLine, "<br />");
                lblProviderName.Text  = booking.Provider.Person.FullnameWithoutMiddlename;
                lblProviderNbr.Text   = booking.Provider.ProviderNumber;

                string link = @"http://localhost:2524/Invoice_ViewV2.aspx?booking_id=264225";
                lblInvLink.Text = "<a href=\"" + link + "\" onclick=\"open_new_tab('" + link + "');return false;\">View All Invoices</a>";


                if (!booking.Organisation.IsAgedCare)
                {
                    tr_address.Visible             = false;
                    btnEmailToFac.Visible          = false;
                    br_before_email_to_fac.Visible = false;

                    RegisterStaff regStaff = RegisterStaffDB.GetByStaffIDAndOrganisationID(booking.Provider.StaffID, booking.Organisation.OrganisationID, true);
                    if (regStaff != null)
                    {
                        lblProviderNbr.Text = regStaff.ProviderNumber;
                    }
                }


                FillGrid();
            }

            this.GrdBooking.EnableViewState = true;
        }
        catch (CustomMessageException ex)
        {
            if (IsPostBack)
            {
                SetErrorMessage(ex.Message);
            }
            else
            {
                HideTableAndSetErrorMessage(ex.Message);
            }
        }
        catch (Exception ex)
        {
            if (IsPostBack)
            {
                SetErrorMessage("", ex.ToString());
            }
            else
            {
                HideTableAndSetErrorMessage("", ex.ToString());
            }
        }
    }