Пример #1
0
        protected void AddNewStaff(object sender, EventArgs e)
        {

            var environmentParametersViewModel = new EnvironmentParametersFactory(AppSettings.ConnectionStringName).GetEnvironmentParameters();
            var staffManagement = new StaffManagement(environmentParametersViewModel);

            var doesUserExist = staffManagement.DoesUserExist(loginID.Text);
            staffManagement.Dispose();

            if (doesUserExist)
            {
                var radalertscript = "<script language='javascript'>function f(){radalert('" + string.Format("Cannot Add User, this user already exists.  User: {0}", loginID.Text) + "', 300, 300, 'Duplicate User Detected'); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
                Page.ClientScript.RegisterStartupScript(GetType(), "radalert", radalertscript); 
                return;
            }

            var staffIdentificationTable = new dtGeneric_String_String();
            var schoolIdTable = new dtGeneric_Int();
            var userTypeIdTable = new dtGeneric_String();
            string restrictionsValue = string.Empty ;

            staffIdentificationTable.Rows.Add("FirstName", firstName.Text);
            staffIdentificationTable.Rows.Add("MiddleName", middleName.Text);
            staffIdentificationTable.Rows.Add("LastName", lastName.Text);
            staffIdentificationTable.Rows.Add("Email", email.Text);
            staffIdentificationTable.Rows.Add("LoginID", loginID.Text);
            
            switch (DataIntegrity.ConvertToInt(restrictionsDropdown.SelectedIndex))     // using index is not best way to accomplish this... but easy to fix in the future if we need to reorder dropdown
            {
                case (int)Restrictions.None:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "false");
                    staffIdentificationTable.Rows.Add("IsApproved", "true");
                    staffIdentificationTable.Rows.Add("Restrictions", "None");
                    restrictionsValue = "None";
                    break;
                case (int)Restrictions.Revoked:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "false");
                    staffIdentificationTable.Rows.Add("IsApproved", "false");
                    staffIdentificationTable.Rows.Add("Restrictions", "None");
                    restrictionsValue = "None";
                    break;
                case (int)Restrictions.LockedOut:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "true");
                    staffIdentificationTable.Rows.Add("IsApproved", "true");
                    staffIdentificationTable.Rows.Add("Restrictions", "None");
                    restrictionsValue = "None";
                    break;
                case (int)Restrictions.ChangePassword:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "false");
                    staffIdentificationTable.Rows.Add("IsApproved", "true");
                    staffIdentificationTable.Rows.Add("Restrictions", ThinkgateUser.ChangePasswordRestrictionValue);
                    restrictionsValue = ThinkgateUser.ChangePasswordRestrictionValue.ToString(CultureInfo.InvariantCulture);
                    break;
            }
            foreach (RadComboBoxItem item in schoolDropdown.Items)
            {
                var itemCheckbox = (CheckBox)item.FindControl("schoolCheckbox");
                var itemLabel = (Label)item.FindControl("schoolLabel");

                if (itemCheckbox != null && itemCheckbox.Checked && itemLabel.Text != @"All" && itemLabel.Text.ToLower().IndexOf("<img", StringComparison.Ordinal) == -1)
                {
                    schoolIdTable.Add(DataIntegrity.ConvertToInt(item.Value));
                }
            }
			StringBuilder userSyncRoles = new StringBuilder();
            foreach (RadComboBoxItem item in userTypeDropdown.Items)
            {
                var itemCheckbox = (CheckBox)item.FindControl("userTypeCheckbox");
                var itemLabel = (Label)item.FindControl("userTypeLabel");

                if (itemCheckbox != null && itemCheckbox.Checked && itemLabel.Text != @"All" && itemLabel.Text.ToLower().IndexOf("<img", StringComparison.Ordinal) == -1)
                {
                    userTypeIdTable.Add(item.Text);
					userSyncRoles.Append(itemLabel.Text);
                }
            }

            /*  Create the user record  */
            /* Validate Results - if error, give message and go back to user */
            SqlParameterCollection parms = new SqlCommand().Parameters;
            parms.AddWithValue("ApplicationName", AppSettings.ApplicationName);
            parms.AddWithValue("UserName", loginID.Text);
            parms.AddWithValue("FirstName", firstName.Text);
            parms.AddWithValue("MiddleName", middleName.Text);
            parms.AddWithValue("LastName", lastName.Text);
            parms.AddWithValue("Password", DistrictParms.LoadDistrictParms().DefaultPasswordEncrypted);
            parms.AddWithValue("PasswordSalt", DistrictParms.LoadDistrictParms().DefaultPasswordEncryptedSalt);
            parms.AddWithValue("Email", email.Text);
            parms.Add(ThinkgateDataAccess.GetParmFromTable(userTypeIdTable.ToSql(), "Roles"));
            parms.Add(ThinkgateDataAccess.GetParmFromTable(schoolIdTable.ToSql(), "Schools"));
            parms.AddWithValue("PrimarySchool", DataIntegrity.ConvertToInt(cmbPrimarySchool.SelectedItem.Value));
            parms.AddWithValue("PrimaryUser", cmbPrimaryUser.SelectedItem.Text);
            parms.AddWithValue("TeacherID", string.Empty);
            parms.AddWithValue("Restrictions", restrictionsValue);   

            var drNewStaffUserPage = ThinkgateDataAccess.FetchDataRow(AppSettings.ConnectionString,
                                                                      Base.Classes.Data.StoredProcedures.ASPNET_TG_SECURITY_USER_CREATE_USER,
                                                                      System.Data.CommandType.StoredProcedure,
                                                                      parms,
                                                                      SessionObject.GlobalInputs);
            /*
             * Extract UserPage ID out of recordset and put in hidden field so that when we return to the client side, we
             * can offer user (through javascript) the opportunity to bring up Staff Object Page with new staff in it.
            */
            if (drNewStaffUserPage != null)
            {
                hdnNewStaffIDEncrypted.Value = Standpoint.Core.Classes.Encryption.EncryptString(drNewStaffUserPage["UserPage"].ToString());
                KenticoBusiness.AddUserAndRoles(loginID.Text);
            }

			//Dan - UserSync - Queue a UserSync Message here!
            //TODO: Michael Rue - complete user sync functionality
			//UserSyncHelperFactory.GetMsmqHelper().AddOrUpdateUser(loginID.Text, loginID.Text, null, email.Text, JsonConvert.SerializeObject(userSyncRoles));

            ScriptManager.RegisterStartupScript(this, typeof(AddStaff), "AddedStaff", "autoSizeWindow();", true);

            resultPanel.Visible = true;
            addPanel.Visible = false;
            lblResultMessage.Text = @"Staff successfully added!";
        }
        protected void UpdateStaff(object sender, EventArgs e)
        {
            lblResultMessage.Text = string.Empty;
            var staffIdentificationTable = new dtGeneric_String_String();
            var schoolIDTable = new dtGeneric_Int();
            var userTypeIDTable = new dtGeneric_String();

		    string currLoginID = _selectedStaff.LoginID;
			string newLoginID = loginID.Text;
            string imageFileName = string.Empty;
            if (imgPhoto.Src != string.Empty)
            {
                imageFileName = Path.GetFileName(imgPhoto.Src);
            }
            staffIdentificationTable.Rows.Add("FirstName", firstName.Text);
            staffIdentificationTable.Rows.Add("MiddleName", middleName.Text);
            staffIdentificationTable.Rows.Add("LastName", lastName.Text);
            staffIdentificationTable.Rows.Add("Email", email.Text);
            staffIdentificationTable.Rows.Add("LoginID", loginID.Text);
            staffIdentificationTable.Rows.Add("Image_FileName", imageFileName);
            //staffIdentificationTable.Rows.Add("Restrictions", restrictionsDropdown.Text);
            switch (DataIntegrity.ConvertToInt(restrictionsDropdown.SelectedIndex))     // using index is not best way to accomplish this... but easy to fix in the future if we need to reorder dropdown
            {
                case (int) Restrictions.None:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "false");
                    staffIdentificationTable.Rows.Add("IsApproved", "true");
                    staffIdentificationTable.Rows.Add("Restrictions", "None");
                    break;
                case (int) Restrictions.Revoked:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "false");
                    staffIdentificationTable.Rows.Add("IsApproved", "false");
                    staffIdentificationTable.Rows.Add("Restrictions", "None");
                    break;
                case (int) Restrictions.LockedOut:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "true");
                    staffIdentificationTable.Rows.Add("IsApproved", "true");
                    staffIdentificationTable.Rows.Add("Restrictions", "None");
                    break;
                case (int) Restrictions.ChangePassword:
                    staffIdentificationTable.Rows.Add("IsLockedOut", "false");
                    staffIdentificationTable.Rows.Add("IsApproved", "true");
                    staffIdentificationTable.Rows.Add("Restrictions", ThinkgateUser.ChangePasswordRestrictionValue);
                    break;
            }

            foreach(RadComboBoxItem item in schoolDropdown.Items)
            {
                CheckBox itemCheckbox = (CheckBox)item.FindControl("schoolCheckbox");
                Label itemLabel = (Label)item.FindControl("schoolLabel");

                if (itemCheckbox != null && itemCheckbox.Checked && itemLabel.Text != "All" && itemLabel.Text.IndexOf("<img") == -1)
                {
                    schoolIDTable.Add(DataIntegrity.ConvertToInt(item.Value));
                }
            }

			List<String> userSyncRoles = new List<string>();

            foreach (RadComboBoxItem item in userTypeDropdown.Items)
            {
                CheckBox itemCheckbox = (CheckBox)item.FindControl("userTypeCheckbox");
                Label itemLabel = (Label)item.FindControl("userTypeLabel");

	            if (itemCheckbox != null && itemCheckbox.Checked && itemLabel.Text != "All" &&
	                itemLabel.Text.IndexOf("<img") == -1)
                {
                    userTypeIDTable.Add(item.Value);
					userSyncRoles.Add(itemLabel.Text);
                }
            }

            Base.Classes.Staff.UpdateStaff(staffIdentificationTable, schoolIDTable, userTypeIDTable, _selectedStaff.UserID.ToString(), DataIntegrity.ConvertToInt(cmbPrimarySchool.SelectedItem.Value), cmbPrimaryUser.SelectedItem.Text.ToLower());

            if (_fromTeacherPage) Base.Classes.Cache.Remove("Teacher_" + GetDecryptedEntityId(X_ID));

            Base.Classes.Cache.Remove("Staff_" + GetDecryptedEntityId(X_ID));

			//Dan - UserSync - Queue a UserSync Message here!
			//string usroles = JsonConvert.SerializeObject(userSyncRoles);

            //TODO: Michael Rue - complete user sync functionality
			//UserSyncHelperFactory.GetMsmqHelper().AddOrUpdateUser(currLoginID, newLoginID, null, email.Text, usroles);

	      
            string js = "parent.window.location.reload();";
            ScriptManager.RegisterStartupScript(Page, typeof(Page), "StaffIdentificationEditSaveAndClose", js, true);
        }
        /// <summary>
        /// Once a standard is selected, need to load the bank of questions. Binds to bank repeater
        /// </summary>
        private string LoadBankQuestions(int assessmentID, Label targetCountLabel, dtGeneric_Int standardList = null, Dictionary<int, string> standard_lookup = null, string keywords = null)
        {
            if (selectedAssessment == null)
            {
                selectedAssessment = (Assessment)Cache.Get(this.CacheKey);

                if (selectedAssessment == null)
                {
                    LoadAssessmentObject();
                }
            }
            var itemList = new List<BankQuestion>();

            string testCategory = GetSecureTestCategory(selectedAssessment.TestCategory);

            dtItemBank itemBanks = ItemBankMasterList.GetItemBanksForStandardSearch(SessionObject.LoggedInUser, testCategory);

            if (standardList != null)
            {
                if (standardList.Count > 0)
                {
                    itemList = BankQuestion.GetBankQuestionsByStandardList(assessmentID, standardList, itemBanks, true,
                                                                    selectedAssessment.currCourseID,
                                                                    selectedAssessment.Year);
                    foreach (var ques in itemList)
                    {
                        ques.StandardName = standard_lookup[ques.StandardID];
                    }
                }
            }
            else
            {
                itemList = BankQuestion.GetBankQuestionsByKeyword(keywords, itemBanks, true,
                                                                   selectedAssessment.currCourseID,
                                                                   selectedAssessment.Year);
                foreach (var ques in itemList)
                {
                    if (ques.Standards.Count > 0)
                    {
                        //foreach (var standard in ques.Standards)
                        //{
                        //    var row = StandardMasterList.GetStandardRowByID(standard.ID);
                        //    standard.StandardName = row["StandardName"].ToString();
                        //    standard.Desc = row["Desc"].ToString();
                        //}

                        // set initial standard to first one for item
                        ques.StandardID = ques.Standards[0].ID;
                        ques.StandardName = ques.Standards[0].StandardName;
                    }
                }
            }

            if (itemList.Count > 0)
            {
                //Start: Bug#:252 and 247 , 18 Dec 2012: Jeetendra Kumar, When a keyword search is executed from an assessment you cannot end the search.                
                if (itemList.Count > 500)
                {
                    targetCountLabel.Text = "More than 500 items found. Please narrow search criteria and use expanded Item search.";
                    return "[]";
                }
                //End: Bug#:252 and 247 , 18 Dec 2012: Jeetendra Kumar, When a keyword search is executed from an assessment you cannot end the search. 

                targetCountLabel.Text = itemList.Count.ToString() + " items found";

                if (_serializer == null) _serializer = new JavaScriptSerializer();
                _serializer.RegisterConverters(new JavaScriptConverter[] { new BankQuestionSerializerForAssessmentPage(), new StandardsSerializer() });

                return _serializer.Serialize(itemList);
            }
            else
            {
                targetCountLabel.Text = "No items found";

                return "[]";
            }
        }
        protected void comboStandardFilter_OnSelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            int selectedStandard = DataIntegrity.ConvertToInt(e.Value);
            var standardList = new dtGeneric_Int();
            standardList.Add(selectedStandard);
            Dictionary<int, string> standard_lookup = new Dictionary<int, string>();
            standard_lookup.Add(selectedStandard, e.Text);

            var itemListStr = LoadBankQuestions(_assessmentID, lblBankCount_filter, standardList, standard_lookup);

            ScriptManager.RegisterStartupScript(this, typeof(string), "ajaxPanel_Bank_filter_Loaded", "var Bank_filter_items=" + itemListStr + "; ajaxPanel_Bank_filter_Loaded()", true);
        }
        /// <summary>
        /// User has clicked on a standard in the standard outline tree. Need to built the list of standards for that branch and pass to bank binder
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Web.UI.RadTreeNodeEventArgs"/> instance containing the event data.</param>
        protected void OutlineStandardTree_OnClick(object sender, RadTreeNodeEventArgs e)
        {
            Dictionary<int, string> standard_lookup = new Dictionary<int, string>();
            _selectedStandardOutline = Standpoint.Core.Utilities.DataIntegrity.ConvertToInt(e.Node.Value);
            standard_lookup.Add(_selectedStandardOutline, e.Node.Attributes["ButtonText"]);

            var standardList = new dtGeneric_Int();
            standardList.Add(_selectedStandardOutline);

            foreach (RadTreeNode node in e.Node.GetAllNodes())
            {
                standardList.Add(DataIntegrity.ConvertToInt(node.Value));
                standard_lookup.Add(DataIntegrity.ConvertToInt(node.Value), node.Text.Substring(0, node.Text.IndexOf("(")));
            }

            RadTreeView tree = (RadTreeView)sender;
            RadComboBoxItem comboItem = (RadComboBoxItem)tree.NamingContainer;
            RadComboBox combo = (RadComboBox)comboItem.NamingContainer;
            combo.Items[0].Text = e.Node.Attributes["ButtonText"];

            e.Node.Selected = true;
            var itemListStr = LoadBankQuestions(_assessmentID, lblBankCount, standardList, standard_lookup);

            ScriptManager.RegisterStartupScript(this, typeof(string), "ajaxPanel_Bank_Loaded", "var Bank_items=" + itemListStr + "; ajaxPanel_Bank_Loaded()", true);
        }