protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
    {
        // dont allow sorting if in edit mode
        if (GrdBooking.EditIndex >= 0)
        {
            return;
        }

        DataTable dataTable = Session["bookinglist_data"] as DataTable;

        if (dataTable != null)
        {
            if (Session["bookinglist_sortexpression"] == null)
            {
                Session["bookinglist_sortexpression"] = "";
            }

            DataView dataView    = new DataView(dataTable);
            string[] sortData    = Session["bookinglist_sortexpression"].ToString().Trim().Split(' ');
            string   newSortExpr = (e.SortExpression == sortData[0] && sortData[1] == "ASC") ? "DESC" : "ASC";
            dataView.Sort = e.SortExpression + " " + newSortExpr;
            Session["bookinglist_sortexpression"] = e.SortExpression + " " + newSortExpr;

            GrdBooking.DataSource = dataView;
            GrdBooking.DataBind();
        }
    }
示例#2
0
    protected void FillGrid()
    {
        Booking booking = BookingDB.GetByID(GetFormBooking());

        DataTable dt = Letter.GenerateInvoiceLines_ByBookingID(GetFormBooking(chkIncAddOns.Checked), booking.Organisation.IsAgedCare);

        // add to sort on room correctly
        dt.Columns.Add("PaddedRoom", typeof(String));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["PaddedRoom"] = dt.Rows[i]["Room"] == DBNull.Value ? DBNull.Value : (object)PadRoomNbr(dt.Rows[i]["Room"].ToString().Trim(), true);
        }

        Session["invoicelistac_data"] = dt;

        if (dt.Rows.Count > 0)
        {
            if (IsPostBack && Session["invoicelistac_sortexpression"] != null && Session["invoicelistac_sortexpression"].ToString().Length > 0)
            {
                DataView dataView = new DataView(dt);
                dataView.Sort         = Session["invoicelistac_sortexpression"].ToString();
                GrdBooking.DataSource = dataView;
            }
            else
            {
                GrdBooking.DataSource = dt;
            }


            try
            {
                GrdBooking.DataBind();
            }
            catch (Exception ex)
            {
                HideTableAndSetErrorMessage("", ex.ToString());
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdBooking.DataSource = dt;
            GrdBooking.DataBind();

            int TotalColumns = GrdBooking.Rows[0].Cells.Count;
            GrdBooking.Rows[0].Cells.Clear();
            GrdBooking.Rows[0].Cells.Add(new TableCell());
            GrdBooking.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdBooking.Rows[0].Cells[0].Text       = "No Record Found";
        }

        if (!booking.Organisation.IsAgedCare)
        {
            GrdBooking.Columns[1].Visible = false;
        }
    }
    protected void FillGrid()
    {
        DateTime fromDate = IsValidDate(txtStartDate.Text) ? GetDate(txtStartDate.Text)                             : DateTime.MinValue;
        DateTime toDate   = IsValidDate(txtEndDate.Text)   ? GetDate(txtEndDate.Text).Add(new TimeSpan(23, 59, 59)) : DateTime.MinValue;

        ArrayList list = new ArrayList();

        if (chkIncCompleted.Checked)
        {
            list.Add("187");
        }
        if (chkIncCancelled.Checked)
        {
            list.Add("188");
        }
        if (chkIncIncomplete.Checked)
        {
            list.Add("0");
        }
        if (chkIncDeleted.Checked)
        {
            list.Add("-1");
        }
        string statusIDsToInclude = string.Join(",", (string[])list.ToArray(Type.GetType("System.String")));


        DataTable dt = null;

        /*
         * if (IsValidFormPatient())
         * {
         *  int patient_id = GetFormPatient(false);
         *  Patient patient = PatientDB.GetByID(patient_id);
         *  if (patient == null)
         *      throw new CustomMessageException("Invalid patient ID");
         *
         *  heading.InnerText = "Bookings List for : ";
         *  lnkToEntity.Text = patient.Person.FullnameWithoutMiddlename;
         *  lnkToEntity.NavigateUrl = "PatientDetailV2.aspx?type=view&id=" + patient.PatientID;
         *
         *  dt = BookingDB.GetDataTable_Between(fromDate, toDate, null, null, patient, chkIncDeleted.Checked, statusIDsToInclude, false, txtBookingNbrSearch.Text.Trim());
         * }
         * else if (IsValidFormOrganisation())
         * {
         *  int org_id = GetFormOrganisation(false);
         *  Organisation org = OrganisationDB.GetByID(org_id);
         *  if (org == null)
         *      throw new CustomMessageException("Invalid organisation ID");
         *
         *  heading.InnerText = "Bookings List for : ";
         *  lnkToEntity.Text = org.Name;
         *  lnkToEntity.NavigateUrl = "OrganisationDetailV2.aspx?type=view&id=" + org.OrganisationID;
         *
         *  dt = BookingDB.GetDataTable_Between(fromDate, toDate, null, new Organisation[] { org }, null, chkIncDeleted.Checked, statusIDsToInclude, false, txtBookingNbrSearch.Text.Trim());
         * }
         * else if (IsValidFormProvider())
         * {
         *  int provider_id = GetFormProvider(false);
         *  Staff provider = StaffDB.GetByID(provider_id);
         *  if (provider == null)
         *      throw new CustomMessageException("Invalid provider ID");
         *
         *  heading.InnerText = "Bookings List for : ";
         *  lnkToEntity.Text = provider.Person.FullnameWithoutMiddlename;
         *  lnkToEntity.NavigateUrl = "StaffDetailV2.aspx?type=view&id=" + provider.StaffID;
         *
         *  dt = BookingDB.GetDataTable_Between(fromDate, toDate, new Staff[] { provider }, null, null, chkIncDeleted.Checked, statusIDsToInclude, false, txtBookingNbrSearch.Text.Trim());
         * }
         * else
         *  throw new CustomMessageException("No entity to get bookings for");
         */

        Patient      patient  = null;
        Organisation org      = null;
        Staff        provider = null;


        if (IsValidFormPatient())
        {
            int patientID = GetFormPatient(false);
            patient = PatientDB.GetByID(patientID);
            if (patient == null)
            {
                throw new CustomMessageException("Invalid patient ID");
            }
        }
        if (IsValidFormOrganisation())
        {
            int orgID = GetFormOrganisation(false);
            org = OrganisationDB.GetByID(orgID);
            if (org == null)
            {
                throw new CustomMessageException("Invalid organisation ID");
            }
        }
        if (IsValidFormProvider())
        {
            int provID = GetFormProvider(false);
            provider = StaffDB.GetByID(provID);
            if (provider == null)
            {
                throw new CustomMessageException("Invalid provider ID");
            }
        }


        if (patient == null && org == null && provider == null)
        {
            throw new CustomMessageException("No entity to get bookings for");
        }

        UserView userView = UserView.GetInstance();

        lblHeading.Text = "Bookings List for:";
        int items = (patient == null ? 0 : 1) + (provider == null ? 0 : 1) + (org == null ? 0 : 1);

        if (patient != null)
        {
            lblHeading.Text += (items > 1 ? "<br />&nbsp;&nbsp;Patient " : " ") + "<a href=\"PatientDetailV2.aspx?type=view&id=" + patient.PatientID + "\">" + patient.Person.FullnameWithoutMiddlename + "</a>";
        }
        if (provider != null && userView.IsAdminView)
        {
            lblHeading.Text += (items > 1 ? "<br />&nbsp;&nbsp;Provider " : " ") + "<a href=\"StaffDetailV2.aspx?type=view&id=" + provider.StaffID + "\">" + provider.Person.FullnameWithoutMiddlename + "</a>";
        }
        if (provider != null && !userView.IsAdminView)
        {
            lblHeading.Text += (items > 1 ? "<br />&nbsp;&nbsp;Provider " : " ") + provider.Person.FullnameWithoutMiddlename;
        }
        if (org != null)
        {
            lblHeading.Text += (items > 1 ? "<br />&nbsp;&nbsp;Clinic " : " ") + "<a href=\"OrganisationDetailV2.aspx?type=view&id=" + org.OrganisationID + "\">" + org.Name + "</a>";
        }


        if (txtBookingNbrSearch.Text.Trim().Length > 0)
        {
            fromDate = DateTime.MinValue;
            toDate   = DateTime.MinValue;
        }

        dt = BookingDB.GetDataTable_Between(fromDate, toDate, provider == null ? null : new Staff[] { provider }, org == null ? null : new Organisation[] { org }, patient, null, chkIncDeleted.Checked, statusIDsToInclude, false, txtBookingNbrSearch.Text.Trim());

        // above query gets for org OR prov .. so remove those
        for (int i = dt.Rows.Count - 1; i >= 0; i--)
        {
            Booking booking = BookingDB.LoadFull(dt.Rows[i]);

            if ((patient != null && (booking.Patient == null || booking.Patient.PatientID != patient.PatientID)) ||
                (org != null && (booking.Organisation == null || booking.Organisation.OrganisationID != org.OrganisationID)) ||
                (provider != null && (booking.Provider == null || booking.Provider.StaffID != provider.StaffID)) ||
                (booking.BookingTypeID != 34))
            {
                dt.Rows.RemoveAt(i);
            }
        }


        // if confirmed by email/sms, display booking_confirmed_by_type.descr
        // if confirmed by person, display their name
        dt.Columns.Add("confirmed_by_text", typeof(string));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i]["booking_booking_confirmed_by_type_id"] == DBNull.Value)
            {
                dt.Rows[i]["confirmed_by_text"] = DBNull.Value;
            }
            else if (Convert.ToInt32(dt.Rows[i]["booking_booking_confirmed_by_type_id"]) == 2 || Convert.ToInt32(dt.Rows[i]["booking_booking_confirmed_by_type_id"]) == 3)
            {
                dt.Rows[i]["confirmed_by_text"] = dt.Rows[i]["booking_confirmed_by_type_descr"];
            }
            else if (Convert.ToInt32(dt.Rows[i]["booking_booking_confirmed_by_type_id"]) == 1)
            {
                dt.Rows[i]["confirmed_by_text"] = dt.Rows[i]["person_confirmed_by_person_id"] == DBNull.Value ? (object)DBNull.Value : dt.Rows[i]["person_confirmed_by_firstname"] + " " + dt.Rows[i]["person_confirmed_by_surname"];
            }
        }

        Session["bookinglist_data"] = dt;

        if (dt.Rows.Count > 0)
        {
            if (IsPostBack && Session["bookinglist_sortexpression"] != null && Session["bookinglist_sortexpression"].ToString().Length > 0)
            {
                DataView dataView = new DataView(dt);
                dataView.Sort         = Session["bookinglist_sortexpression"].ToString();
                GrdBooking.DataSource = dataView;
            }
            else if (Session["bookinglist_sortexpression"] == null || Session["bookinglist_sortexpression"].ToString().Length == 0)
            {
                DataView dataView = new DataView(dt);
                dataView.Sort = "booking_date_start DESC";
                Session["bookinglist_sortexpression"] = dataView.Sort;
                GrdBooking.DataSource = dataView;
            }
            else
            {
                GrdBooking.DataSource = dt;
            }


            try
            {
                GrdBooking.DataBind();
            }
            catch (Exception ex)
            {
                HideTableAndSetErrorMessage("", ex.ToString());
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdBooking.DataSource = dt;
            GrdBooking.DataBind();

            int TotalColumns = GrdBooking.Rows[0].Cells.Count;
            GrdBooking.Rows[0].Cells.Clear();
            GrdBooking.Rows[0].Cells.Add(new TableCell());
            GrdBooking.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdBooking.Rows[0].Cells[0].Text       = "No Record Found";
        }



        bool hasInvoices          = false;
        bool hasCompletedInvoices = false;

        foreach (GridViewRow row in GrdBooking.Rows)
        {
            if (row.RowType == DataControlRowType.Pager)
            {
                continue;
            }
            if (row.FindControl("lblViewInvoice") != null && ((Label)row.FindControl("lblViewInvoice")).Text.Length > 0)
            {
                hasInvoices = true;
            }
            if (row.FindControl("lblGeneratedSystemLetters") != null && ((Label)row.FindControl("lblGeneratedSystemLetters")).Text.Length > 0 && ((Label)row.FindControl("lblGeneratedSystemLetters")).Visible)
            {
                hasCompletedInvoices = true;
            }
        }
        GrdBooking.Columns[12].Visible = hasInvoices;
        GrdBooking.Columns[9].Visible  = hasCompletedInvoices;
    }