private void DashBoardView()
        {
            try
            {
                string PageSEOName = string.Empty;
                if (Request.QueryString["pgnm"] != null)
                {
                    PageSEOName = Request.QueryString["pgnm"].ToString();
                }
                else
                {
                    PageBase        pb       = new PageBase();
                    SageUserControl SageUser = new SageUserControl();
                    PageSEOName = pb.GetPageSEOName(SageUser.PagePath);
                }
                DashboardController  objController = new DashboardController();
                List <DashboardInfo> lstDashboard  = objController.DashBoardView(PageSEOName, GetUsername, GetPortalID);

                GroupItemInfo objbnInfo = new GroupItemInfo();
                //objbnInfo.PortalID = portalID;
                List <GroupItemInfo> objGroupItem = objController.GroupGetAll(GetPortalID, PageSEOName, GetUsername);
                if (objGroupItem.Count > 0)
                {
                    BindGroups(objGroupItem);
                }
                StringBuilder html = new StringBuilder();
                html.Append("<ul  class='" + dragClass + " storePages clearfix' data-groupid='0'>");
                foreach (DashboardInfo objDashboard in lstDashboard)
                {
                    html.Append("<li class='page' data-pageID='" + objDashboard.PageID + "' data-itemid='0'>");
                    objDashboard.IconFile = "<i class='icon-" + objDashboard.PageName.Replace(" ", "-").ToLower() + "'></i>";
                    objDashboard.Url      = objDashboard.Url + Extension;
                    html.Append("<a href=" + objDashboard.Url + "><span class='sfModuleicon'>");
                    html.Append(objDashboard.IconFile);
                    html.Append("</span>");
                    html.Append("<span  class='sfModulename'>" + objDashboard.PageName + "</span>");
                    html.Append("</a>");
                    html.Append("</li>");
                }
                html.Append("</ul>");
                ltradminPageList.Text = html.ToString();
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
        void groupsListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (!e.IsSelected)
                return;

            updateButtons();
            updateSelectedGroupItem();
            selectedGroupItem = null;
            updateSelectedGroup();
            selectedGroup = null;
            selectedListItem = null;

            allowGroupItemUpdate = false;
            resetSQLGroup();
            resetDynamicGroup();

            if (groupsListView.SelectedItems.Count > 1)
                return;

            selectedListItem = e.Item;
            selectedGroup = e.Item.Tag as RomGroup;
            if (selectedGroup == null)
            {
                selectedListItem = null;
                return;
            }

            txt_Title.Text = selectedGroup.Title;
            sortDescCheckBox.Checked = selectedGroup.SortDescending;
            bool found = false;
            foreach (KeyValuePair<string, ListItemProperty> keyVal in sortDropdownItems)
            {
                if (keyVal.Value == selectedGroup.SortProperty)
                {
                    found = true;
                    sortComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
                sortComboBox.SelectedIndex = 0;

            found = false;
            foreach (KeyValuePair<string, int> keyVal in layoutDropdownItems)
            {
                if (keyVal.Value == selectedGroup.Layout)
                {
                    found = true;
                    layoutComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
                layoutComboBox.SelectedIndex = 0;

            groupItemsTreeView.Nodes.Clear();
            foreach (GroupItemInfo item in selectedGroup.GroupItemInfos)
            {
                TreeNode newNode = new TreeNode() { Tag = item };
                switch (item.ItemType)
                {
                    case GroupItemType.SQL:
                        newNode.Text = "SQL";
                        newNode.Nodes.Add("Loading...");
                        break;
                    case GroupItemType.DYNAMIC:
                        newNode.Text = "Dynamic";
                        newNode.Nodes.Add("Loading...");
                        break;
                    case GroupItemType.EMULATOR:
                        if (item.ItemId == GroupItemInfo.ALL_ITEMS_ID)
                        {
                            newNode.Text = "All Emulators";
                            newNode.Nodes.Add("Loading...");
                        }
                        else
                        {
                            Emulator emu;
                            if (allEmulators.TryGetValue(item.ItemId, out emu))
                                newNode.Text = emu.Title;
                            else
                                continue;
                        }
                        break;
                    case GroupItemType.GAME:
                        if (item.ItemId == GroupItemInfo.ALL_ITEMS_ID)
                        {
                            newNode.Text = "All Games";
                            newNode.Nodes.Add("Loading...");
                        }
                        else
                        {
                            Game game;
                            if (allGames.TryGetValue(item.ItemId, out game))
                                newNode.Text = game.Title;
                            else
                                continue;
                        }
                        break;
                }                
                groupItemsTreeView.Nodes.Add(newNode);
            }
            allowGroupItemUpdate = true;
        }
 void addChildNodes(TreeNode selectedNode, GroupItemInfo info)
 {
     selectedNode.Nodes.Clear();
     switch (info.ItemType)
     {
         case GroupItemType.SQL:
             foreach (Game game in info.GetItems(ListItemProperty.TITLE))
                 selectedNode.Nodes.Add(new TreeNode(game.Title) { BackColor = Color.DarkGray });
             break;
         case GroupItemType.DYNAMIC:
             foreach (RomGroup group in info.GetItems(ListItemProperty.TITLE))
                 selectedNode.Nodes.Add(new TreeNode(group.Title) { BackColor = Color.DarkGray });
             break;
         case GroupItemType.EMULATOR:
             if (info.ItemId == -2)
             {
                 foreach (Emulator emu in Emulator.GetAll(true))
                     selectedNode.Nodes.Add(new TreeNode(emu.Title) { BackColor = Color.LightGray });
             }
             break;
         case GroupItemType.GAME:
             if (info.ItemId == -2)
             {
                 foreach (Game game in Game.GetAll())
                     selectedNode.Nodes.Add(new TreeNode(game.Title) { BackColor = Color.LightGray });
             }
             break;
     }
     if (selectedNode.Nodes.Count < 1)
         selectedNode.Nodes.Add("No items");
 }
        private void groupItemsTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            updateGroupItemButtons();
            allowGroupItemUpdate = false;
            updateSelectedGroupItem();
            resetSQLGroup();
            resetDynamicGroup();

            if (selectedGroup == null)
                return;

            TreeNode selectedNode = groupItemsTreeView.SelectedNode;
            if (selectedNode == null)
                return;

            selectedGroupItem = selectedNode.Tag as GroupItemInfo;
            if (selectedGroupItem == null)
            {
                selectedTreeNode = null;
                return;
            }
            selectedTreeNode = selectedNode;

            if (selectedGroupItem.ItemType == GroupItemType.SQL)
            {
                sqlGroupBox.Enabled = true;
                txt_Where.Text = selectedGroupItem.SQL;
                txt_Order.Text = selectedGroupItem.Order;
            }
            else if (selectedGroupItem.ItemType == GroupItemType.DYNAMIC)
            {
                dynamicGroupBox.Enabled = true;
                dyn_ColumnComboBox.SelectedItem = selectedGroupItem.Column;
                if (selectedGroupItem.Order == "DESC")
                    dyn_OrderComboBox.SelectedIndex = 1;
                else
                    dyn_OrderComboBox.SelectedIndex = 0;
            }
            allowGroupItemUpdate = true;
        }
        public void ProcessResult(Stream input)
        {
            XPathDocument doc = new XPathDocument(input);
            XPathNavigator nav = doc.CreateNavigator();

            // Get the package purpose
            string purpose = nav.Eval(sXp_PackagePurpose);
            if (!string.Equals(purpose, ExpectedPackageType.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("  Skipping package. Type is '{0}' but processing '{1}'.", purpose, ExpectedPackageType);
                return;
            }

            // Get the test info
            string testName = nav.Eval(sXp_TestName);
            string testSubject = nav.Eval(sXp_TestSubject);
            string testGrade = nav.Eval(sXp_TestGrade);
            string testType = nav.Eval(sXp_TestType);

            // Index the group item info
            Dictionary<string, GroupItemInfo> indexGroupItemInfo = new Dictionary<string,GroupItemInfo>();
            {
                XPathNodeIterator nodes = nav.Select(sXp_GroupItem);
                while (nodes.MoveNext())
                {
                    XPathNavigator node = nodes.Current;
                    string itemId = Strip200(node.GetAttribute("itemid", string.Empty));
                    string isFieldTest = node.GetAttribute("isfieldtest", string.Empty);
                    string isActive = node.GetAttribute("isactive", string.Empty);
                    string responseRequired = node.GetAttribute("responserequired", string.Empty);
                    string adminRequired = node.GetAttribute("adminrequired", string.Empty);
                    string formPosition = node.GetAttribute("formposition", string.Empty);

                    GroupItemInfo gii;
                    if (indexGroupItemInfo.TryGetValue(itemId, out gii))
                    {
                        if (!string.Equals(gii.IsFieldTest, isFieldTest, StringComparison.Ordinal))
                        {
                            ReportError(testName, ErrorSeverity.Degraded, itemId, "Conflicting isfieldtest info: '{0}' <> '{1}'", isFieldTest, gii.IsFieldTest);
                        }
                        if (!string.Equals(gii.IsActive, isActive, StringComparison.Ordinal))
                        {
                            ReportError(testName, ErrorSeverity.Degraded, itemId, "Conflicting isactive info: '{0}' <> '{1}'", isActive, gii.IsActive);
                        }
                        if (!string.Equals(gii.ResponseRequired, responseRequired, StringComparison.Ordinal))
                        {
                            ReportError(testName, ErrorSeverity.Degraded, itemId, "Conflicting responserequired info: '{0}' <> '{1}'", responseRequired, gii.ResponseRequired);
                        }
                        if (!string.Equals(gii.AdminRequired, adminRequired, StringComparison.Ordinal))
                        {
                            ReportError(testName, ErrorSeverity.Degraded, itemId, "Conflicting adminrequired info: '{0}' <> '{1}'", adminRequired, gii.AdminRequired);
                        }
                        if (!string.Equals(gii.FormPosition, formPosition, StringComparison.Ordinal))
                        {
                            ReportError(testName, ErrorSeverity.Degraded, itemId, "Conflicting formposition info: '{0} <> '{1}'", formPosition, gii.FormPosition);
                        }
                    }
                    else
                    {
                        gii = new GroupItemInfo();
                        gii.IsFieldTest = isFieldTest;
                        gii.IsActive = isActive;
                        gii.ResponseRequired = responseRequired;
                        gii.AdminRequired = adminRequired;
                        gii.FormPosition = formPosition;
                        indexGroupItemInfo.Add(itemId, gii);
                        //Console.WriteLine(itemId);
                    }

                }
            }

            // Report the item fields
            int itemCount = 0;
            if (m_itemWriter != null)
            {
                XPathNodeIterator nodes = nav.Select(sXp_Item);
                while (nodes.MoveNext())
                {
                    ++itemCount;
                    XPathNavigator node = nodes.Current;

                    // Collect the item fields
                    string[] itemFields = new string[ItemFieldNamesCount];
                    itemFields[(int)ItemFieldNames.TestName] = testName;
                    itemFields[(int)ItemFieldNames.TestSubject] = testSubject;
                    itemFields[(int)ItemFieldNames.TestGrade] = testGrade;
                    itemFields[(int)ItemFieldNames.TestType] = testType;
                    string itemId = Strip200(node.Eval(sXp_ItemId));
                    itemFields[(int)ItemFieldNames.ItemId] = itemId;
                    itemFields[(int)ItemFieldNames.Filename] = node.Eval(sXp_Filename);
                    itemFields[(int)ItemFieldNames.Version] = node.Eval(sXp_Version);
                    itemFields[(int)ItemFieldNames.ItemType] = node.Eval(sXp_ItemType);
                    itemFields[(int)ItemFieldNames.PassageRef] = Strip200(node.Eval(sXp_PassageRef));

                    // Process PoolProperties
                    List<string> glossary = new List<string>();
                    XPathNodeIterator ppNodes = node.Select(sXp_PoolProperty);
                    while (ppNodes.MoveNext())
                    {
                        XPathNavigator ppNode = ppNodes.Current;
                        string ppProperty = ppNode.Eval(sXp_PPProperty).Trim();
                        string ppValue = ppNode.Eval(sXp_PPValue).Trim();
                        if (!string.IsNullOrEmpty(ppProperty) && !string.IsNullOrEmpty(ppValue))
                        {
                            // Special case for Braille language
                            int fieldIndex;
                            if (ppProperty.Equals("Language", StringComparison.Ordinal) && ppValue.Equals("ENU-Braille", StringComparison.Ordinal))
                            {
                                itemFields[(int)ItemFieldNames.LanguageBraille] = ppValue;
                            }

                            // Special case for Spanish language
                            else if (ppProperty.Equals("Language", StringComparison.Ordinal) && ppValue.Equals("ESN", StringComparison.Ordinal))
                            {
                                itemFields[(int)ItemFieldNames.Spanish] = "Y";
                            }

                            // Special case for Spanish language
                            else if (ppProperty.Equals("Spanish Translation", StringComparison.Ordinal))
                            {
                                itemFields[(int)ItemFieldNames.Spanish] = ppValue;
                            }

                            // Special case for Glossary
                            else if (ppProperty.Equals("Glossary", StringComparison.Ordinal))
                            {
                                glossary.Add(ppValue);
                            }

                            else if (sPoolPropertyMapping.TryGetValue(ppProperty, out fieldIndex))
                            {
                                if (fieldIndex != 0)
                                {
                                    if (!string.IsNullOrEmpty(itemFields[fieldIndex]))
                                        ReportError(testName, ErrorSeverity.Degraded, itemId, "'{0}={1}' Multiple values for pool property", ppProperty, ppValue);
                                    itemFields[fieldIndex] = ppValue;
                                }
                            }
                            else
                            {
                                ReportError(testName, ErrorSeverity.Degraded, itemId, "'{0}={1}' Unrecognized Pool Property", ppProperty, ppValue);
                            }
                        }
                    }
                    glossary.Sort();
                    itemFields[(int)ItemFieldNames.Glossary] = string.Join(";", glossary);

                    itemFields[(int)ItemFieldNames.MeasurementModel] = node.Eval(sXp_MeasurementModel);
                    itemFields[(int)ItemFieldNames.Weight] = FormatDouble(node.Eval(sXp_Weight));
                    itemFields[(int)ItemFieldNames.ScorePoints] = node.Eval(sXp_ScorePoints);
                    itemFields[(int)ItemFieldNames.a] = FormatDouble(node.Eval(sXp_Parameter1));
                    itemFields[(int)ItemFieldNames.b0_b] = FormatDouble(node.Eval(sXp_Parameter2));
                    itemFields[(int)ItemFieldNames.b1_c] = FormatDouble(node.Eval(sXp_Parameter3));
                    itemFields[(int)ItemFieldNames.b2] = FormatDouble(node.Eval(sXp_Parameter4));
                    itemFields[(int)ItemFieldNames.b3] = FormatDouble(node.Eval(sXp_Parameter5));

                    // Check known measurement model
                    if (!sKnownMeasurementModels.Contains(itemFields[(int)ItemFieldNames.MeasurementModel]))
                        ReportError(testName, ErrorSeverity.Benign, itemId, "'{0}' Unrecognized Measurement Model", itemFields[(int)ItemFieldNames.MeasurementModel]);

                    // Check known parameters
                    XPathNodeIterator pnNodes = node.Select(sXp_ParameterName);
                    while (pnNodes.MoveNext())
                    {
                        string name = pnNodes.Current.Value;
                        if (!sKnownMeasurementParameters.Contains(name))
                            ReportError(testName, ErrorSeverity.Benign, itemId, "'{0}' Unrecognized Measurement Parameter", name);
                    }

                    // bprefs
                    int bpIndex = 0;
                    XPathNodeIterator bpNodes = node.Select(sXp_Bpref);
                    while (bpNodes.MoveNext())
                    {
                        string bpref = bpNodes.Current.Value;
                        if (bpIndex >= MaxBpRefs)
                            ReportError(testName, ErrorSeverity.Benign, itemId, "More than {0} bpref nodes", MaxBpRefs);
                        else
                            itemFields[(int)ItemFieldNames.bpref1 + bpIndex++] = bpref;

                        // Attempt to parse the bpref as an SBAC standard
                        // See http://www.smarterapp.org/documents/InterpretingSmarterBalancedStandardIDs.html
                        // A proper Math standard ID should be in this format: SBAC-MA-v6:1|P|TS04|D-6
                        // However, the bpref form substitutes "SBAC-" for "SBAC-MA-v6:"
                        // A proper ELA standard ID should be in this format: SBAC-ELA-v1:3-L|4-6|6.SL.2
                        // However, the bpref form substitutes "SBAC-" FOR "SBAC-ELA-v1:" and it drops the
                        // last segment which is the common core state standard.
                        if (testSubject.Equals("Math", StringComparison.OrdinalIgnoreCase))
                        {
                            Match match = s_Rx_BprefMath.Match(bpref);
                            if (match.Success)
                            {
                                itemFields[(int)ItemFieldNames.Standard] = string.Concat(c_MathStdPrefix, match.Value.Substring(5));
                                itemFields[(int)ItemFieldNames.Claim] = match.Groups[1].Value;
                                itemFields[(int)ItemFieldNames.Target] = match.Groups[2].Value;
                            }
                        }
                        else if (testSubject.Equals("ELA", StringComparison.OrdinalIgnoreCase))
                        {
                            Match match = s_Rx_BprefEla.Match(bpref);
                            if (match.Success)
                            {
                                itemFields[(int)ItemFieldNames.Standard] = string.Concat(c_ElaStdPrefix, match.Value.Substring(5));
                                itemFields[(int)ItemFieldNames.Claim] = match.Groups[1].Value + "\t";   // Adding tab character prevents Excel from treating these as dates.
                                itemFields[(int)ItemFieldNames.Target] = match.Groups[2].Value + "\t";
                            }
                        }
                    }
                    if (itemFields[(int)ItemFieldNames.Standard] == null) itemFields[(int)ItemFieldNames.Standard] = string.Empty;
                    if (itemFields[(int)ItemFieldNames.Claim] == null) itemFields[(int)ItemFieldNames.Claim] = string.Empty;
                    if (itemFields[(int)ItemFieldNames.Target] == null) itemFields[(int)ItemFieldNames.Target] = string.Empty;

                    GroupItemInfo gii;
                    if (indexGroupItemInfo.TryGetValue(itemId, out gii))
                    {
                        itemFields[(int)ItemFieldNames.IsFieldTest] = gii.IsFieldTest;
                        itemFields[(int)ItemFieldNames.IsActive] = gii.IsActive;
                        itemFields[(int)ItemFieldNames.ResponseRequired] = gii.ResponseRequired;
                        itemFields[(int)ItemFieldNames.AdminRequired] = gii.AdminRequired;
                        itemFields[(int)ItemFieldNames.FormPosition] = gii.FormPosition;
                    }
                    else
                    {
                        itemFields[(int)ItemFieldNames.IsFieldTest] = string.Empty;
                        itemFields[(int)ItemFieldNames.IsActive] = string.Empty;
                        itemFields[(int)ItemFieldNames.ResponseRequired] = string.Empty;
                        itemFields[(int)ItemFieldNames.AdminRequired] = string.Empty;
                        itemFields[(int)ItemFieldNames.FormPosition] = string.Empty;
                    }

                    // Write one line to the CSV
                    m_itemWriter.Write(itemFields);
                }
            }

            // Report the stimuli fields
            if (m_stimWriter != null)
            {
                XPathNodeIterator nodes = nav.Select(sXp_Stim);
                while (nodes.MoveNext())
                {
                    XPathNavigator node = nodes.Current;

                    // Collect the stim fields
                    string[] stimFields = new string[StimFieldNamesCount];
                    stimFields[(int)StimFieldNames.TestName] = testName;
                    stimFields[(int)StimFieldNames.TestSubject] = testSubject;
                    stimFields[(int)StimFieldNames.TestGrade] = testGrade;
                    stimFields[(int)StimFieldNames.TestType] = testType;
                    stimFields[(int)StimFieldNames.StimId] = Strip200(node.Eval(sXp_ItemId));
                    stimFields[(int)StimFieldNames.Filename] = node.Eval(sXp_Filename);
                    stimFields[(int)StimFieldNames.Version] = node.Eval(sXp_Version);

                    // Write one line to the CSV
                    m_stimWriter.Write(stimFields);
                }
            }

            // Get the item counts
            int opitemcount = int.Parse(nav.Eval(XPathExpression.Compile("/testspecification//bpelement[@elementtype='test']/@opitemcount")));
            int ftitemcount = int.Parse(nav.Eval(XPathExpression.Compile("/testspecification//bpelement[@elementtype='test']/@ftitemcount")));
            int maxopitems = int.Parse(nav.Eval(XPathExpression.Compile("/testspecification//bpelement[@elementtype='test']/@maxopitems")));
            //Console.WriteLine("  opitemcount = {0}", opitemcount);
            //Console.WriteLine("  ftitemcount = {0}", ftitemcount);
            //Console.WriteLine("  totalcount  = {0}", opitemcount + ftitemcount);
            //Console.WriteLine("  maxopitems  = {0}", maxopitems);
            //Console.WriteLine("  opitemcount/maxopitems = {0}/{1} = {2}", opitemcount, maxopitems, ((double)opitemcount) / ((double)maxopitems));
            //Debug.WriteLine("{0},{1},{2}", testName, opitemcount, maxopitems);
        }