protected void Page_Load(object sender, EventArgs e)
        {
            var gradeList = new List<string>();
            var subjectList = new List<string>();

            SessionObject = (SessionObject)Session["SessionObject"];
            _itemBankTbl = ItemBankMasterList.GetItemBanksForUser(SessionObject.LoggedInUser, ThinkgatePermission.PermissionLevelValues.ItemBankEdit, "Search");

            if (LoadRubric() == false)
                return;

            _standardCourseList = CourseMasterList.GetStandardCoursesForUser(SessionObject.LoggedInUser);
            _gradeList = _standardCourseList.GetGradeList();
            _subjectList = _standardCourseList.FilterByGrade(_rubric.Grade).GetSubjectList();

            gradeList.Add(_rubric.Grade);
            subjectList.Add(_rubric.Subject);
            _courseList = _standardCourseList.FilterByGradesAndSubjects(gradeList, subjectList);

            BindPageControls();

            /* Preview consists of Directions section + Content */
            ContentEditor_Rubric_Preview_Directions.InnerHtml = _rubric.Directions;
            ContentEditor_Rubric_Preview_Contents.InnerHtml = _rubric.Content;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SessionObject = (SessionObject)Session["SessionObject"];
            _itemBankTbl = ItemBankMasterList.GetItemBanksForUser(SessionObject.LoggedInUser, ThinkgatePermission.PermissionLevelValues.ItemBankEdit, "Search");
            LoadItemImage();
            _standardCourseList = CourseMasterList.GetStandardCoursesForUser(SessionObject.LoggedInUser);
            _gradeList = _standardCourseList.GetGradeList();
            _subjectList = _standardCourseList.FilterByGrade(_selectedAddendum.Addendum_Grade).GetSubjectList();

            var gradeList = new List<string>();
            var subjectList = new List<string>();
            gradeList.Add(_selectedAddendum.Addendum_Grade);
            subjectList.Add(_selectedAddendum.Addendum_Subject);

            _courseList = _standardCourseList.FilterByGradesAndSubjects(gradeList, subjectList);
            BindPageControls();
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            SessionObject = (SessionObject)Page.Session["SessionObject"];
            subject = SessionObject.AssessmentBuildParms.ContainsKey("Subject") ? SessionObject.AssessmentBuildParms["Subject"] : "";
            courseID = SessionObject.AssessmentBuildParms.ContainsKey("Course") ? DataIntegrity.ConvertToInt(SessionObject.AssessmentBuildParms["Course"]) : 0;
            Base.Classes.Course assessmentCourse = CourseMasterList.GetCurrCourseById(courseID);
            courseName = assessmentCourse != null ? assessmentCourse.CourseName : "";
            grade = SessionObject.AssessmentBuildParms.ContainsKey("Grade") ? SessionObject.AssessmentBuildParms["Grade"] : "";
            type = SessionObject.AssessmentBuildParms.ContainsKey("Type") ? SessionObject.AssessmentBuildParms["Type"] : "";
            term = SessionObject.AssessmentBuildParms.ContainsKey("Term") ? DataIntegrity.ConvertToInt(SessionObject.AssessmentBuildParms["Term"]) : 0;
            description = SessionObject.AssessmentBuildParms.ContainsKey("Description") ? SessionObject.AssessmentBuildParms["Description"] : "";
            currUserID = SessionObject.LoggedInUser != null ? (SessionObject.LoggedInUser.Page > 0 ? SessionObject.LoggedInUser.Page : AppSettings.Demo_TeacherID) : AppSettings.Demo_TeacherID;

            testCategory = SessionObject.AssessmentBuildParms.ContainsKey("TestCategory") ? SessionObject.AssessmentBuildParms["TestCategory"] : "Classroom";
            rigorLevels = SessionObject.Standards_RigorLevels_ItemCounts;

            //Selected Item Banks table
            selectedItemBanksTable = new dtItemBank();       
        }
        private void BindItemBankCheckBoxes()
        {
            _itemBankTbl = ItemBankMasterList.GetItemBanksForUser(SessionObject.LoggedInUser, ThinkgatePermission.PermissionLevelValues.ItemBankEdit, "Search");
            string renderItemsScript = "var itemBankList = [";

            string tbl = @"<table style=""width:100%;"">";
            int aCounter = 0;
            foreach (DataRow ibR in _itemBankTbl.Rows)
            {

                tbl += @"<tr>";
                tbl += @"<td class=""fieldLabel"" style=""width:20%; padding: 0px 10px 0px 10px; text-align:right;"">";
                tbl += @"<input type=""checkbox"" cbtype=""ItemBank"" ID=""ItemBank_" + ibR["TargetType"] + "_" + ibR["Target"] + @"""";
                tbl += @" class=""itemBankUpdate"" title=""Click to add this item to the " + ibR["Label"] + @" item bank""";

                tbl += @" TargetType=""" + ibR["TargetType"] + @"""";
                tbl += @" Target=""" + ibR["Target"] + @"""";
                tbl += @" multiBanks=""" + (ibR["MultiBanks"].ToString().ToLower() == "true" ? "true" : "") + @"""";

                string tf;
                if (IsItemBankInMasterList(ibR["Label"].ToString()))
                {
                    tbl += @" inBank=""true""";
                    tbl += @" checked=""true""";
                    tf = "true";
                }
                else
                {
                    tbl += @" inBank=""false""";
                    tf = "false";
                }
                if (IsItemBankLocked(ibR))
                {
                    tbl += @" disabled=""true""";
                }
                tbl += @" onclick=""updateItemBanks(this);""/>";
                tbl += @"</td>";
                tbl += @"<td style=""width:80%"">" + ibR["Label"] + @"</td>";
                tbl += @"</tr>";

                aCounter++;
                renderItemsScript += "['" + ibR["TargetType"] + "','" + ibR["Target"] + "','" + tf + "','" + (ibR["MultiBanks"].ToString().ToLower() == "true" ? "true" : "") + "']";
                if (aCounter != _itemBankTbl.Rows.Count)
                    renderItemsScript += ",";
            }
            renderItemsScript += "];";

            tbl += @"</table>";
            ItemBankCheckBoxes.InnerHtml = tbl;

            ScriptManager.RegisterStartupScript(this, typeof(string), "itemBankList", renderItemsScript, true);
        }
        /// <summary>
        /// Get the initial values from query string 
        /// Loads the test question or bank question
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            SessionObject = (SessionObject)Session["SessionObject"];
            _itemBankTbl = ItemBankMasterList.GetItemBanksForUser(SessionObject.LoggedInUser, ThinkgatePermission.PermissionLevelValues.ItemBankEdit, "Search");

            _imagesUrl = ConfigHelper.GetImagesUrl();
            lbl_OTCUrl.Value = AppSettings.OTCUrl + DistrictParms.ClientID.ToString(CultureInfo.CurrentCulture);

            UpdateItem();
            LoadItem();
            _standardCourseList = CourseMasterList.GetStandardCoursesForUser(SessionObject.LoggedInUser);
            _gradeList = _standardCourseList.GetGradeList();
            _subjectList = _standardCourseList.FilterByGrade(UseTq ? _itemTestQuestion.Grade : _itemBankQuestion.Grade).GetSubjectList();

            var gradeList = new List<string>();
            var subjectList = new List<string>();
            gradeList.Add(UseTq ? _itemTestQuestion.Grade : _itemBankQuestion.Grade);
            subjectList.Add(UseTq ? _itemTestQuestion.Subject : _itemBankQuestion.Subject);

            BindPageControls();
            SetItemPageValues();

            ScriptManager.RegisterStartupScript(this, typeof(string), "appClient", "var appClient = '" + AppClient() + "';", true);
            ScriptManager.RegisterStartupScript(this, typeof (string), "debug_message", "function debug_message(message) {}", true);

            rtbBtnLRMI.Visible = DistrictParms.LRMITagging == "true";
        }
        protected void LoadItemBankTables()
        {
            bool hasPermission = SessionObject.LoggedInUser.HasPermission(Permission.Access_SecureTesting);
            Dictionary<string, bool> dictionaryItem = Base.Classes.TestTypes.TypeWithSecureFlag(testCategory);
            bool isSecuredFlag = dictionaryItem != null && dictionaryItem.Where(x => Boolean.Parse(x.Value.ToString())).Select(y => y.Key).ToList().Distinct().Any();
            if (hasPermission && isSecuredFlag && SecureType)
                    testCategory = type;

            hiddenAccessSecureTesting.Value = hasPermission.ToString();
            hiddenIsSecuredFlag.Value = isSecuredFlag.ToString();
            hiddenSecureType.Value = SecureType.ToString();

            itemBankListTable = ItemBankMasterList.GetItemBanksForStandardSearch(SessionObject.LoggedInUser, testCategory);
            itemBankListTableByLabel = ItemBankMasterList.GetItemBanksForStandardSearch(SessionObject.LoggedInUser, testCategory).DistinctByLabel();
            if (SessionObject.ItemBanks != null && SessionObject.ItemBanks.Count > 0)
            {
                foreach (string item in SessionObject.ItemBanks)
                {
                    DataRow newRow = selectedItemBanksTable.NewRow();
                    DataRow itemBankRow = itemBankListTable.Select("Label = '" + item.ToString() + "'")[0];

                    selectedItemBanksTable.Add(DataIntegrity.ConvertToInt(itemBankRow["TargetType"]),
                                                itemBankRow["Target"].ToString(),
                                                DataIntegrity.ConvertToInt(itemBankRow["ApprovalSource"]),
                                                itemBankRow["Label"].ToString());
                }
            }
            else
            {
                if (SessionObject.ItemBanks != null) SessionObject.ItemBanks.Clear();

                foreach (DataRow row in itemBankListTableByLabel.Rows)
                {
                    DataRow itemBankRow = itemBankListTable.Select("Label = '" + row["Label"] + "'")[0];

                    selectedItemBanksTable.Add(DataIntegrity.ConvertToInt(itemBankRow["TargetType"]),
                                                itemBankRow["Target"].ToString(),
                                                DataIntegrity.ConvertToInt(itemBankRow["ApprovalSource"]),
                                                itemBankRow["Label"].ToString());

                    if (SessionObject.ItemBanks != null) SessionObject.ItemBanks.Add(row["Label"].ToString());
                }
            }
        }
		/// <summary>
		/// Create a new item and set its id in a hidden field.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void btnContinue_Click(object sender, EventArgs e)
		{
			// Create the table valued item banks to send to the stored proc if needed.
			SQLTableValueInput outputItemBanksSQL = null;
			if(cmbItemBanks.Visible)
			{
				dtItemBank inputItemBanks = ItemBanksForUser;
				dtItemBank outputItemBanks = new dtItemBank();
				foreach(var v in cmbItemBanks.CheckedItems)
				{
					String bankName = v.Text;
					foreach(DataRow row in inputItemBanks.Rows)
					{
						if(row["Label"].ToString() == bankName)
							outputItemBanks.Add(row);
					}
				}
				outputItemBanksSQL = outputItemBanks.ToSql();
			}

			// We must also get item type and score type abbreviations.
			String questionTypeAbbrev = "", scoreTypeAbbrev = "";
			if(cmbQuestionType.Visible)
				questionTypeAbbrev = Thinkgate.Base.Classes.BankQuestion.AbbrevForQuestionTypeName(cmbQuestionType.Text);
			if(cmbScoreType.Visible)
				scoreTypeAbbrev = Thinkgate.Base.Classes.BankQuestion.AbbrevForScoreTypeName(cmbScoreType.Text);
			// Get a string for the copyright.
			String copyright = (cbxYes.Checked) ? "Yes" : "No";
		   	// The id of the new item created.
			DataRow drRow;
			Int32 id = 0;

            switch (itemType)
			{
				case ItemTypes.Image:
					drRow = ThinkgateDataAccess.FetchDataRow("E3_Image_Create", new object[] { tbxName.Text, outputItemBanksSQL, copyright });
					id = (Int32)drRow[0];
					break;

				case ItemTypes.Item:
                    drRow = ThinkgateDataAccess.FetchDataRow("E3_Question_Create", new object[] { cmbGrade.Text, cmbSubject.Text, outputItemBanksSQL, questionTypeAbbrev, scoreTypeAbbrev, copyright});
					id = (Int32)drRow[0];
					break;

				case ItemTypes.Addendum:
                    drRow = ThinkgateDataAccess.FetchDataRow("E3_Addendum_Create", new object[] { tbxName.Text, cmbGrade.Text, cmbSubject.Text, cmbCourse.Text, outputItemBanksSQL, copyright, cmbAddendumType.Text, cmbAddendumGenre.Text });
					id = (Int32)drRow[0];
					break;

				case ItemTypes.RubricHolistic:
                    drRow = ThinkgateDataAccess.FetchDataRow("E3_Rubric_Create", new object[] { tbxName.Text, cmbGrade.Text, cmbSubject.Text, cmbCourse.Text, outputItemBanksSQL, copyright, "B" });
					id = (Int32)drRow[0];
					break;

				case ItemTypes.RubricAnalytical:
                    drRow = ThinkgateDataAccess.FetchDataRow("E3_Rubric_Create", new object[] { tbxName.Text, cmbGrade.Text, cmbSubject.Text, cmbCourse.Text, outputItemBanksSQL, copyright, "A" });
					id = (Int32)drRow[0];
					break;
				
				case ItemTypes.Rubric:
                    drRow = ThinkgateDataAccess.FetchDataRow("E3_Rubric_Create", new object[] { tbxName.Text, cmbGrade.Text, cmbSubject.Text, cmbCourse.Text, outputItemBanksSQL, copyright, "B" });
					id = (Int32)drRow[0];
					break;
			}

		inpxID.Value = id.ToString();
		inpxIDEnc.Value = Standpoint.Core.Classes.Encryption.EncryptInt(id);
    }