Exemplo n.º 1
0
        protected void btnSaveAssessmentItem_Click(object sender, EventArgs e)
        {
            string pErrMsg = string.Empty;

            if (!Validate_Data(ref pErrMsg))
            {
                Set_Error_Message(pErrMsg);
                return;
            }
            if (gPageMode == Constants.enPageMode.NEW_DATA)
            {
                List <BusinessRules.ClsListAssessmentItem> listAIs = gAssessment.GetAssessmentItemListFromCache(gAssessmentID);
                if (listAIs != null && listAIs.Count > 0)
                {
                    List <BusinessRules.ClsListAssessmentItem> listT = listAIs.FindAll(o => o.Order == Convert.ToInt32(txtOrder.Text));
                    if (listT != null && listT.Count > 0)
                    {
                        Set_Error_Message("Another item with the same order exists! Please swap the records");
                        return;
                    }
                }
            }

            DataAccess.AssessmentItem _objAssessment;
            if (gPageMode == Constants.enPageMode.NEW_DATA)
            {
                _objAssessment         = new DataAccess.AssessmentItem();
                _objAssessment.Version = 1;
                _objAssessment.AssessmentItemTreeID = gAssessment.GetNextAssessmentItemTreeID();
            }
            else
            {
                _objAssessment         = gAssessment.GetAssessmentItemByItemIDFromCache(AssessmentItemID);
                _objAssessment.Version = gAssessment.GetNextVersionNumber(_objAssessment.AssessmentItemTreeID);
            }
            _objAssessment.AssessmentID     = gAssessmentID;
            _objAssessment.DisplayCondition = "";
            _objAssessment.HelpText         = txtHelpText.Text;
            _objAssessment.Text             = txtText.Text;
            _objAssessment.Order            = Convert.ToInt32(txtOrder.Text);
            _objAssessment.TypeID           = Convert.ToInt32(cmbType.SelectedValue);
            _objAssessment.IsMandatory      = Convert.ToBoolean(chkIsRequired.Checked);
            _objAssessment.IsPageBreak      = false;
            _objAssessment.IsLatest         = true;
            _objAssessment.AssessmentItemID = AssessmentItemID;
            _objAssessment.DisplayCondition = txtFormula.Text;
            bool res = gAssessment.Save_Assessment_Item(_objAssessment);

            if (res == false)
            {
                Set_Error_Message("An error oocured during assessment item save process");
                return;
            }
            else
            {
                foreach (string item in ListSelectedAssessmentItems)
                {
                    int _id = Convert.ToInt32(item);
                    res = gAssessment.Save_Assessment_Item_RelatedDCIds(_id, _objAssessment.AssessmentItemID.ToString() + ",");
                    if (res == false)
                    {
                        Set_Error_Message("Assessment Item saved successfully but display condition has thrown error! Please update the display condition and try again later.");
                        return;
                    }
                }
            }

            string scr = string.Empty;

            scr = @"$('#choice_header').goTo();";
            //+ string.Format("$('#{0}').addClass('disabledbutton');"
            if (_objAssessment.TypeID != Convert.ToInt32(Constants.enAssessmentItemType.PAGE_BREAK))
            {
                if (Page.IsPostBack == false)
                {
                    this.Page.ClientScript.RegisterClientScriptBlock(pnlAI.GetType(), "InitDTgrid" + Guid.NewGuid().ToString(), scr, true);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(pnlAI, pnlAI.GetType(), "PBInitDTGrid" + Guid.NewGuid().ToString(), scr, true);
                }
                pnlChoice.Visible = true;
                AssessmentItemID  = _objAssessment.AssessmentItemID;
                Prepare_Choice_Section();
            }
            Set_Success_Message("Question is saved successfully. You can add the choices.");
        }