Ejemplo n.º 1
0
    protected void GrdNote_Sorting(object sender, GridViewSortEventArgs e)
    {
        // dont allow sorting if in edit mode
        if (GrdNote.EditIndex >= 0)
        {
            return;
        }

        DataTable dataTable = ViewState["noteinfo_data"] as DataTable;

        if (dataTable != null)
        {
            if (ViewState["noteinfo_sortexpression"] == null)
            {
                ViewState["noteinfo_sortexpression"] = "";
            }

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

            GrdNote.DataSource = dataView;
            GrdNote.DataBind();
        }
    }
    protected void FillGrid()
    {
        Note note = GetFormNote();

        if (note == null)
        {
            SetErrorMessage("Invalid note id");
            return;
        }


        DataTable dt = NoteHistoryDB.GetDataTable(note.NoteID);

        Session["noteedithistory_data"] = dt;

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


            try
            {
                GrdNote.DataBind();
                GrdNote.PagerSettings.FirstPageText = "1";
                GrdNote.PagerSettings.LastPageText  = GrdNote.PageCount.ToString();
                GrdNote.DataBind();
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex.ToString());
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdNote.DataSource = dt;
            GrdNote.DataBind();

            int TotalColumns = GrdNote.Rows[0].Cells.Count;
            GrdNote.Rows[0].Cells.Clear();
            GrdNote.Rows[0].Cells.Add(new TableCell());
            GrdNote.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdNote.Rows[0].Cells[0].Text       = "No Record Found";
        }
    }
Ejemplo n.º 3
0
    protected void FillNoteGrid()
    {
        if (!IsValidFormID())
        {
            if (!Utilities.IsDev() || Request.QueryString["id"] != null)
            {
                HideTableAndSetErrorMessage();
                return;
            }

            // can still view all if dev and no id set .. but no insert/edit
            GrdNote.Columns[5].Visible = false;
        }

        if (!IsValidFormScreen() && !Utilities.IsDev())
        {
            HideTableAndSetErrorMessage();
            return;
        }


        DataTable dt = IsValidFormID() ? NoteDB.GetDataTable_ByEntityID(GetFormID(), null, true, true) : NoteDB.GetDataTable(true);


        if (IsValidFormScreen())
        {
            Hashtable allowedNoteTypes = new Hashtable();
            DataTable noteTypes        = ScreenNoteTypesDB.GetDataTable_ByScreenID(GetFormScreen());
            for (int i = 0; i < noteTypes.Rows.Count; i++)
            {
                allowedNoteTypes[Convert.ToInt32(noteTypes.Rows[i]["note_type_id"])] = 1;
            }

            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                if (allowedNoteTypes[Convert.ToInt32(dt.Rows[i]["note_type_id"])] == null)
                {
                    dt.Rows.RemoveAt(i);
                }
            }
        }

        UserView userView         = UserView.GetInstance();
        bool     canSeeModifiedBy = userView.IsStakeholder || userView.IsMasterAdmin;

        dt.Columns.Add("last_modified_note_info_visible", typeof(Boolean));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["last_modified_note_info_visible"] = canSeeModifiedBy;
        }


        ViewState["noteinfo_data"] = dt;



        // add note info to hidden field to use when emailing notes

        string emailBodyText = string.Empty;

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

        if (booking != null)
        {
            emailBodyText += @"<br /><br />
<u>Treatment Information</u>
<br />
<table border=""0"" cellpadding=""0"" cellspacing=""0"">" +
                             (booking.Patient == null ? "" : @"<tr><td>Patient</td><td style=""width:10px;""></td><td>" + booking.Patient.Person.FullnameWithoutMiddlename + @"</td></tr>") +
                             (booking.Offering == null ? "" : @"<tr><td>Service</td><td></td><td>" + booking.Offering.Name + @"</td></tr>") + @"
    <tr><td>Date</td><td></td><td>" + booking.DateStart.ToString("dd-MM-yyyy") + @"</td></tr>
    <tr><td>Provider</td><td></td><td>" + booking.Provider.Person.FullnameWithoutMiddlename + @"</td></tr>
</table>";
        }

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            Note n = NoteDB.Load(dt.Rows[i]);
            emailBodyText += "<br /><br /><u>Note (" + n.DateAdded.ToString("dd-MM-yyyy") + ")</u><br />" + n.Text.Replace(Environment.NewLine, "<br />");
        }
        emailText.Value = emailBodyText + "<br /><br />" + SystemVariableDB.GetByDescr("LettersEmailSignature").Value;;



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


            try
            {
                GrdNote.DataBind();
            }
            catch (Exception ex)
            {
                this.lblErrorMessage.Visible = true;
                this.lblErrorMessage.Text    = ex.ToString();
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdNote.DataSource = dt;
            GrdNote.DataBind();

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


        Tuple <string, string, string, string> refsEmailInfo = GetReferrersEmail();
        ImageButton btnEmail = GrdNote.HeaderRow.FindControl("btnEmail") as ImageButton;

        if (refsEmailInfo != null)
        {
            btnEmail.Visible = true;
            ((HiddenField)GrdNote.HeaderRow.FindControl("hiddenRefEmail")).Value           = refsEmailInfo.Item1;
            ((HiddenField)GrdNote.HeaderRow.FindControl("hiddenRefName")).Value            = refsEmailInfo.Item2;
            ((HiddenField)GrdNote.HeaderRow.FindControl("hiddenBookingOrg")).Value         = refsEmailInfo.Item3;
            ((HiddenField)GrdNote.HeaderRow.FindControl("HiddenBookingPatientName")).Value = refsEmailInfo.Item4;
        }
        else
        {
            btnEmail.Visible = false;
        }

        DisallowAddEditIfNoPermissions(); // place this after databinding
    }