Beispiel #1
0
    protected void btnSubmit_Click_1(object sender, EventArgs e)
    {
        lblOutput.Text = colorPicker.Value;



        Patient patient = PatientDB.GetByID(54950);

        if (patient == null)
        {
            throw new Exception("Invalid url id");
        }

        Hashtable selectedConditions = PatientConditionDB.GetHashtable_ByPatientID(patient.PatientID, false);

        foreach (ListItem li in chkBoxListConditions.Items)
        {
            if (li.Selected && selectedConditions[Convert.ToInt32(li.Value)] == null)
            {
                PatientConditionDB.Insert(patient.PatientID, Convert.ToInt32(li.Value), DateTime.MinValue, 0, "", false);
            }

            if (!li.Selected && selectedConditions[Convert.ToInt32(li.Value)] != null)
            {
                PatientConditionDB.Delete(patient.PatientID, Convert.ToInt32(li.Value));
            }
        }

        //SetErrorMessage("Updated");
        Response.Redirect(Request.RawUrl);
    }
    public static PatientCondition[] GetByPatientID(int patient_id, bool inc_deleted = false)
    {
        DataTable tbl = GetDatatable_ByPatientID(patient_id, inc_deleted);

        PatientCondition[] list = new PatientCondition[tbl.Rows.Count];
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            list[i] = PatientConditionDB.LoadAll(tbl.Rows[i]);
        }
        return(list);
    }
    protected void GrdConditionView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert"))
        {
            //ConditionDB.Insert(txtDescr.Text, Convert.ToInt32(ddlDisplayOrder.SelectedValue), false);

            FillGrdConditionView();
        }

        if (e.CommandName.Equals("_Delete") || e.CommandName.Equals("_UnDelete"))
        {
            int id = Convert.ToInt32(e.CommandArgument);

            try
            {
                if (e.CommandName.Equals("_Delete"))
                {
                    PatientConditionDB.UpdateInactive(id);
                }
                else
                {
                    PatientConditionDB.UpdateActive(id);
                }
            }
            catch (ForeignKeyConstraintException fkcEx)
            {
                if (Utilities.IsDev())
                {
                    SetErrorMessage("Can not delete because other records depend on this : " + fkcEx.Message);
                }
                else
                {
                    SetErrorMessage("Can not delete because other records depend on this");
                }
            }

            FillGrdConditionView();
        }
    }
    public static Hashtable GetHashtable_ByPatientID(int patient_id, bool inc_deleted = false)
    {
        Hashtable selectedConditions = new Hashtable();
        DataTable dt_pt_conditions   = GetDatatable_ByPatientID(patient_id, inc_deleted);

        for (int i = 0; i < dt_pt_conditions.Rows.Count; i++)
        {
            selectedConditions[Convert.ToInt32(dt_pt_conditions.Rows[i]["condition_condition_id"])] = PatientConditionDB.LoadAll(dt_pt_conditions.Rows[i]);
        }
        return(selectedConditions);
    }
    protected void FillGrdCondition(Patient patient = null)
    {
        if (patient == null)
        {
            patient = PatientDB.GetByID(GetFormPatientID());
        }

        DataTable dt            = ConditionDB.GetDataTable(false);
        Hashtable conditionHash = ConditionDB.GetHashtable(false);

        Session["patientcondition_data"] = dt;

        if (dt.Rows.Count > 0)
        {
            GrdCondition.DataSource = dt;
            try
            {
                GrdCondition.DataBind();

                Hashtable selectedConditions = PatientConditionDB.GetHashtable_ByPatientID(patient.PatientID, false);
                foreach (GridViewRow row in GrdCondition.Rows)
                {
                    Label        lblId          = row.FindControl("lblId") as Label;
                    CheckBox     chkSelect      = row.FindControl("chkSelect") as CheckBox;
                    DropDownList ddlDate_Day    = (DropDownList)row.FindControl("ddlDate_Day");
                    DropDownList ddlDate_Month  = (DropDownList)row.FindControl("ddlDate_Month");
                    DropDownList ddlDate_Year   = (DropDownList)row.FindControl("ddlDate_Year");
                    DropDownList ddlNbrWeeksDue = (DropDownList)row.FindControl("ddlNbrWeeksDue");

                    Label lblNextDue        = row.FindControl("lblNextDue") as Label;
                    Label lblWeeksLater     = row.FindControl("lblWeeksLater") as Label;
                    Label lblAdditionalInfo = row.FindControl("lblAdditionalInfo") as Label;


                    System.Web.UI.HtmlControls.HtmlControl br_date      = (System.Web.UI.HtmlControls.HtmlControl)row.FindControl("br_date");
                    System.Web.UI.HtmlControls.HtmlControl br_nweeksdue = (System.Web.UI.HtmlControls.HtmlControl)row.FindControl("br_nweeksdue");
                    System.Web.UI.HtmlControls.HtmlControl br_text      = (System.Web.UI.HtmlControls.HtmlControl)row.FindControl("br_text");

                    TextBox txtText = (TextBox)row.FindControl("txtText");

                    if (lblId == null || chkSelect == null)
                    {
                        continue;
                    }

                    Condition condition = (Condition)conditionHash[Convert.ToInt32(lblId.Text)];

                    br_date.Visible           = condition.ShowDate;
                    ddlDate_Day.Visible       = condition.ShowDate;
                    ddlDate_Month.Visible     = condition.ShowDate;
                    ddlDate_Year.Visible      = condition.ShowDate;
                    br_nweeksdue.Visible      = condition.ShowNWeeksDue;
                    ddlNbrWeeksDue.Visible    = condition.ShowNWeeksDue;
                    lblNextDue.Visible        = condition.ShowNWeeksDue;
                    lblWeeksLater.Visible     = condition.ShowNWeeksDue;
                    br_text.Visible           = condition.ShowText;
                    txtText.Visible           = condition.ShowText;
                    lblAdditionalInfo.Visible = condition.ShowText;


                    if (selectedConditions[Convert.ToInt32(lblId.Text)] != null)
                    {
                        PatientCondition ptCondition = (PatientCondition)selectedConditions[Convert.ToInt32(lblId.Text)];

                        chkSelect.Checked = selectedConditions[Convert.ToInt32(lblId.Text)] != null;

                        if (condition.ShowDate)
                        {
                            if (ptCondition.Date != DateTime.MinValue)
                            {
                                ddlDate_Day.SelectedValue   = ptCondition.Date.Day.ToString();
                                ddlDate_Month.SelectedValue = ptCondition.Date.Month.ToString();
                                ddlDate_Year.SelectedValue  = ptCondition.Date.Year.ToString();
                            }
                        }
                        if (condition.ShowNWeeksDue)
                        {
                            ddlNbrWeeksDue.SelectedValue = ptCondition.NWeeksDue.ToString();
                        }
                        if (condition.ShowText)
                        {
                            txtText.Text = ptCondition.Text;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SetErrorMessage("", ex.ToString());
            }

            //Sort("parent_descr", "ASC");
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdCondition.DataSource = dt;
            GrdCondition.DataBind();

            int TotalColumns = GrdCondition.Rows[0].Cells.Count;
            GrdCondition.Rows[0].Cells.Clear();
            GrdCondition.Rows[0].Cells.Add(new TableCell());
            GrdCondition.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdCondition.Rows[0].Cells[0].Text       = "No Record Found";
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Patient patient = PatientDB.GetByID(GetFormPatientID());

        if (patient == null)
        {
            throw new Exception("Invalid url id");
        }

        Hashtable selectedConditions = PatientConditionDB.GetHashtable_ByPatientID(patient.PatientID, false);

        foreach (GridViewRow row in GrdCondition.Rows)
        {
            Label        lblId          = row.FindControl("lblId") as Label;
            CheckBox     chkSelect      = row.FindControl("chkSelect") as CheckBox;
            DropDownList ddlDate_Day    = (DropDownList)row.FindControl("ddlDate_Day");
            DropDownList ddlDate_Month  = (DropDownList)row.FindControl("ddlDate_Month");
            DropDownList ddlDate_Year   = (DropDownList)row.FindControl("ddlDate_Year");
            DropDownList ddlNbrWeeksDue = (DropDownList)row.FindControl("ddlNbrWeeksDue");
            TextBox      txtText        = (TextBox)row.FindControl("txtText");


            if (lblId == null || chkSelect == null)
            {
                continue;
            }


            DateTime date = DateTime.MinValue;
            if (ddlDate_Day.Visible && ddlDate_Month.Visible && ddlDate_Year.Visible)
            {
                if (!IsValidDate(Convert.ToInt32(ddlDate_Day.Text), Convert.ToInt32(ddlDate_Month.Text), Convert.ToInt32(ddlDate_Year.Text)))
                {
                    SetErrorMessage("Please enter a valid date or unset all");
                    return;
                }
                else
                {
                    date = GetDateFromForm(Convert.ToInt32(ddlDate_Day.Text), Convert.ToInt32(ddlDate_Month.Text), Convert.ToInt32(ddlDate_Year.Text));
                }
            }

            int    nweeksdue = ddlNbrWeeksDue.Visible ? Convert.ToInt32(ddlNbrWeeksDue.Text) : 0;
            string text      = txtText.Visible ? txtText.Text.Trim() : string.Empty;

            if (chkSelect.Checked && selectedConditions[Convert.ToInt32(lblId.Text)] == null)
            {
                PatientConditionDB.Insert(patient.PatientID, Convert.ToInt32(lblId.Text), date, nweeksdue, text, false);
            }

            if (!chkSelect.Checked && selectedConditions[Convert.ToInt32(lblId.Text)] != null)
            {
                PatientConditionDB.Delete(patient.PatientID, Convert.ToInt32(lblId.Text));
            }

            if (chkSelect.Checked && selectedConditions[Convert.ToInt32(lblId.Text)] != null)
            {
                PatientConditionDB.Update(patient.PatientID, Convert.ToInt32(lblId.Text), date, nweeksdue, text, false);
            }
        }

        FillGrdCondition(patient);
        FillGrdConditionView(patient);

        SetErrorMessage("Updated");
    }
    protected void FillGrdConditionView(Patient patient = null)
    {
        if (patient == null)
        {
            patient = PatientDB.GetByID(GetFormPatientID());
        }

        DataTable dt            = ConditionDB.GetDataTable(false);
        Hashtable conditionHash = ConditionDB.GetHashtable(false);

        Session["patientconditionview_data"] = dt;

        if (dt.Rows.Count > 0)
        {
            GrdConditionView.DataSource = dt;
            try
            {
                GrdConditionView.DataBind();

                Hashtable selectedConditions = PatientConditionDB.GetHashtable_ByPatientID(patient.PatientID, false);

                for (int i = GrdConditionView.Rows.Count - 1; i >= 0; i--)
                {
                    Label lblId = GrdConditionView.Rows[i].FindControl("lblId") as Label;

                    Label lblDate = GrdConditionView.Rows[i].FindControl("lblDate") as Label;

                    Label lblNextDue = GrdConditionView.Rows[i].FindControl("lblNextDue") as Label;
                    Label lblDateDue = GrdConditionView.Rows[i].FindControl("lblDateDue") as Label;

                    Label lblAdditionalInfo = GrdConditionView.Rows[i].FindControl("lblAdditionalInfo") as Label;
                    Label lblText           = GrdConditionView.Rows[i].FindControl("lblText") as Label;

                    System.Web.UI.HtmlControls.HtmlControl br_date      = (System.Web.UI.HtmlControls.HtmlControl)GrdConditionView.Rows[i].FindControl("br_date");
                    System.Web.UI.HtmlControls.HtmlControl br_nweeksdue = (System.Web.UI.HtmlControls.HtmlControl)GrdConditionView.Rows[i].FindControl("br_nweeksdue");
                    System.Web.UI.HtmlControls.HtmlControl br_text      = (System.Web.UI.HtmlControls.HtmlControl)GrdConditionView.Rows[i].FindControl("br_text");


                    if (lblId == null)
                    {
                        continue;
                    }

                    Condition condition = (Condition)conditionHash[Convert.ToInt32(lblId.Text)];

                    br_date.Visible           = condition.ShowDate;
                    lblDate.Visible           = condition.ShowDate;
                    br_nweeksdue.Visible      = condition.ShowNWeeksDue;
                    lblNextDue.Visible        = condition.ShowNWeeksDue;
                    lblDateDue.Visible        = condition.ShowNWeeksDue;
                    br_text.Visible           = condition.ShowText;
                    lblText.Visible           = condition.ShowText;
                    lblAdditionalInfo.Visible = condition.ShowText;


                    if (selectedConditions[Convert.ToInt32(lblId.Text)] != null)
                    {
                        PatientCondition ptCondition = (PatientCondition)selectedConditions[Convert.ToInt32(lblId.Text)];

                        if (condition.ShowDate)
                        {
                            lblDate.Text = ptCondition.Date == DateTime.MinValue ? "[Date Not Set]" : ptCondition.Date.ToString("d MMM, yyyy");
                        }
                        if (condition.ShowNWeeksDue)
                        {
                            bool expired = ptCondition.Date != DateTime.MinValue && ptCondition.Date.AddDays(7 * ptCondition.NWeeksDue) < DateTime.Today;
                            lblDateDue.Text = ptCondition.Date == DateTime.MinValue ? "[Date Not Set]" : (expired ? "<font color=\"red\">" : "") + ptCondition.Date.AddDays(7 * ptCondition.NWeeksDue).ToString("d MMM, yyyy") + (expired ? "</font>" : "");
                        }
                        if (condition.ShowText)
                        {
                            lblText.Text = ptCondition.Text.Length == 0 ? "[Blank]" : ptCondition.Text;
                        }
                    }
                    else
                    {
                        GrdConditionView.Rows[i].Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                SetErrorMessage("", ex.ToString());
            }

            //Sort("parent_descr", "ASC");
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdConditionView.DataSource = dt;
            GrdConditionView.DataBind();

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