protected void btnPrintBookingList_Click(object sender, EventArgs e)
    {
        DataTable tblBookingList = SetBookingsList();

        if (tblBookingList == null)
        {
            return;
        }

        try
        {
            string originalFile        = Letter.GetLettersDirectory() + @"BookingListForPatient.docx";
            string tmpLettersDirectory = Letter.GetTempLettersDirectory();
            string tmpOutputFile       = FileHelper.GetTempFileName(tmpLettersDirectory + "BookingList." + System.IO.Path.GetExtension(originalFile));


            // create table data to populate

            DataTable dt = tblBookingList;
            string[,] tblInfo = null;
            bool tblEmpty = (dt.Rows.Count == 1 && dt.Rows[0][0] == DBNull.Value);
            if (tblEmpty)
            {
                tblInfo       = new string[1, 4];
                tblInfo[0, 0] = "No Bookings Found";
                tblInfo[0, 1] = "";
                tblInfo[0, 2] = "";
                tblInfo[0, 3] = "";
            }
            else
            {
                tblInfo = new string[dt.Rows.Count, 4];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string inv_type_text = tblBookingList.Rows[i]["inv_type_text"].ToString();
                    if (inv_type_text.Length > 0)
                    {
                        inv_type_text = " (" + inv_type_text + ")";
                    }

                    Booking booking = BookingDB.LoadFull(dt.Rows[i]);
                    tblInfo[i, 0] = booking.DateStart.ToString("d MMM yyyy") + Environment.NewLine + booking.DateStart.ToString("h:mm") + " - " + booking.DateEnd.ToString("h:mm") + (booking.DateEnd.Hour < 12 ? "am" : "pm");
                    tblInfo[i, 1] = booking.Patient == null ? "" : booking.Patient.Person.FullnameWithoutMiddlename;
                    tblInfo[i, 2] = (booking.Offering == null ? "" : booking.Offering.Name + Environment.NewLine) + booking.Provider.Person.FullnameWithoutMiddlename + " @ " + booking.Organisation.Name;
                    tblInfo[i, 3] = booking.BookingStatus.Descr + Environment.NewLine + inv_type_text;
                }
            }


            // create empty dataset

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


            // merge

            string errorString = null;
            WordMailMerger.Merge(

                originalFile,
                tmpOutputFile,
                sourceDataSet,

                tblInfo,
                1,
                true,

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

            if (errorString != string.Empty)
            {
                throw new CustomMessageException(errorString);
            }

            Letter.FileContents fileContents = new Letter.FileContents(System.IO.File.ReadAllBytes(tmpOutputFile), "BookingList." + System.IO.Path.GetExtension(originalFile));
            System.IO.File.Delete(tmpOutputFile);


            // Nothing gets past the "DownloadDocument" method because it outputs the file
            // which is writing a response to the client browser and calls Response.End()
            // So make sure any other code that functions goes before this
            Letter.DownloadDocument(Response, fileContents.Contents, fileContents.DocName);
        }
        catch (CustomMessageException cmEx)
        {
            SetErrorMessage(cmEx.Message);
        }
        catch (Exception ex)
        {
            SetErrorMessage(ex.ToString());
        }
    }
Пример #2
0
    protected void CreateNoteFile(string tmpFilename)
    {
        string header = string.Empty;

        Booking booking = BookingDB.GetByEntityID(GetFormID());

        if (booking != null)
        {
            Site site = SiteDB.GetByID(Convert.ToInt32(Session["SiteID"]));

            string[] phNums;
            if (Utilities.GetAddressType().ToString() == "Contact")
            {
                phNums = ContactDB.GetByEntityID(-1, booking.Organisation.EntityID, 34).Select(r => r.AddrLine1).ToArray();
            }
            else if (Utilities.GetAddressType().ToString() == "ContactAus")
            {
                phNums = ContactAusDB.GetByEntityID(-1, booking.Organisation.EntityID, 34).Select(r => r.AddrLine1).ToArray();
            }
            else
            {
                throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
            }

            if (phNums.Length == 0)
            {
                if (Utilities.GetAddressType().ToString() == "Contact")
                {
                    phNums = ContactDB.GetByEntityID(-1, site.EntityID, 34).Select(r => r.AddrLine1).ToArray();
                }
                else if (Utilities.GetAddressType().ToString() == "ContactAus")
                {
                    phNums = ContactAusDB.GetByEntityID(-1, site.EntityID, 34).Select(r => r.AddrLine1).ToArray();
                }
                else
                {
                    throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
                }
            }

            string numbers = string.Empty;
            if (phNums.Length > 0)
            {
                numbers += " - TEL " + phNums[0];
            }
            if (phNums.Length > 1)
            {
                numbers += ", " + phNums[1];
            }

            header += site.Name + numbers + Environment.NewLine;
            header += "Clinic:  " + booking.Organisation.Name + Environment.NewLine;

            if (booking.Patient != null)
            {
                header += "Patient:  " + booking.Patient.Person.FullnameWithoutMiddlename + Environment.NewLine;
            }
            if (booking.Offering != null)
            {
                header += "Service:  " + booking.Offering.Name + Environment.NewLine;
            }

            header += "Provider:  " + booking.Provider.Person.FullnameWithoutMiddlename + Environment.NewLine;
            header += "Date of Consultation: " + booking.DateStart.ToString("d MMM yyyy") + Environment.NewLine + Environment.NewLine + "Treatment Note:" + Environment.NewLine;
        }


        System.Collections.ArrayList notesList = new System.Collections.ArrayList();
        foreach (GridViewRow row in GrdNote.Rows)
        {
            Label    lblId    = row.FindControl("lblId") as Label;
            Label    lblText  = row.FindControl("lblText") as Label;
            CheckBox chkPrint = row.FindControl("chkPrint") as CheckBox;

            if (lblId == null || lblText == null || chkPrint == null)
            {
                continue;
            }

            if (chkPrint.Checked)
            {
                notesList.Add(header + lblText.Text.Replace("<br/>", "\n"));
            }
        }

        if (notesList.Count == 0)
        {
            throw new CustomMessageException("Please select at least one note to print.");
        }

        UserView userView     = UserView.GetInstance();
        bool     isAgedCare   = booking != null && booking.Organisation != null ? booking.Organisation.IsAgedCare : userView.IsAgedCareView;
        string   filename     = isAgedCare ? "BlankTemplateAC.docx" : "BlankTemplate.docx";
        string   originalFile = Letter.GetLettersDirectory() + filename;

        if (!System.IO.File.Exists(originalFile))
        {
            throw new CustomMessageException("Template File '" + filename + "' does not exist.");
        }

        string errorString = string.Empty;

        if (!WordMailMerger.Merge(originalFile, tmpFilename, null, null, 0, false, true, (string[])notesList.ToArray(typeof(string)), false, null, out errorString))
        {
            throw new CustomMessageException("Error:" + errorString);
        }
    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        // re-fill grid in case two broswer windows are open with 2 different booking lists and only the one on the other page is in the session memory...
        FillGrid();

        try
        {
            string originalFile        = Letter.GetLettersDirectory() + @"BookingList.docx";
            string tmpLettersDirectory = Letter.GetTempLettersDirectory();
            string tmpOutputFile       = FileHelper.GetTempFileName(tmpLettersDirectory + "BookingList." + System.IO.Path.GetExtension(originalFile));


            // create table data to populate

            DataTable dt = Session["bookinglist_data"] as DataTable;
            string[,] tblInfo = null;
            bool tblEmpty = (dt.Rows.Count == 1 && dt.Rows[0][0] == DBNull.Value);
            if (tblEmpty)
            {
                tblInfo       = new string[1, 4];
                tblInfo[0, 0] = "No Bookings Found";
                tblInfo[0, 1] = "";
                tblInfo[0, 2] = "";
                tblInfo[0, 3] = "";
            }
            else
            {
                tblInfo = new string[dt.Rows.Count, 4];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Booking booking = BookingDB.LoadFull(dt.Rows[i]);
                    tblInfo[i, 0] = booking.DateStart.ToString("d MMM") + " " + booking.DateStart.ToString("h:mm") + " - " + booking.DateEnd.ToString("h:mm") + (booking.DateEnd.Hour < 12 ? "am" : "pm");
                    tblInfo[i, 1] = booking.Patient == null ? "" : booking.Patient.Person.FullnameWithoutMiddlename;
                    tblInfo[i, 2] = booking.Provider.Person.FullnameWithoutMiddlename;
                    tblInfo[i, 3] = booking.Organisation.Name;
                }
            }


            // create empty dataset

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


            // merge

            string errorString = null;
            WordMailMerger.Merge(

                originalFile,
                tmpOutputFile,
                sourceDataSet,

                tblInfo,
                1,
                true,

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

            if (errorString != string.Empty)
            {
                throw new CustomMessageException(errorString);
            }

            Letter.FileContents fileContents = new Letter.FileContents(System.IO.File.ReadAllBytes(tmpOutputFile), "BookingList." + System.IO.Path.GetExtension(originalFile));
            System.IO.File.Delete(tmpOutputFile);


            // Nothing gets past the "DownloadDocument" method because it outputs the file
            // which is writing a response to the client browser and calls Response.End()
            // So make sure any other code that functions goes before this
            Letter.DownloadDocument(Response, fileContents.Contents, fileContents.DocName);
        }
        catch (CustomMessageException cmEx)
        {
            SetErrorMessage(cmEx.Message);
        }
        catch (Exception ex)
        {
            SetErrorMessage(ex.ToString());
        }
    }
Пример #4
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);
        }
    }