示例#1
0
        private void LoadConfigurationReportsFile()
        {
            // Remove Report item controller and the report menu entries.
            if (mController.HatElementNodes.Exist("Report_0"))
            {
                mController.HatElementNodes.Remove(mController.HatElementNodes["Report_0"]);
                mnuReports.DropDownItems.Clear();
            }
            // Hide Reports menu option.
            mnuReports.Visible = false;

            HatNodeController lController = null;

            try
            {
                // Verify the path and file specified in MainMenuReports Settings.
                string lFilePath = Properties.Settings.Default.MainMenuReports;
                if (!System.IO.File.Exists(lFilePath))
                {
                    lFilePath = System.Windows.Forms.Application.StartupPath + "\\" + lFilePath;
                    if (!System.IO.File.Exists(lFilePath))
                    {
                        return;
                    }
                }


                XmlDocument lXMLDoc = new XmlDocument();
                lXMLDoc.Load(lFilePath);

                XmlNodeList lMainNodeList = lXMLDoc.GetElementsByTagName("Reports");
                if (lMainNodeList.Count != 1)
                {
                    return;
                }

                // Main Reports node.
                XmlNode lMainNode = lMainNodeList[0];

                // Get the Reports Menu information.
                char[] lSeparators          = new char[] { ',' };
                string lAgentsWithoutBlanks = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lMainNode, "agents");
                lAgentsWithoutBlanks = lAgentsWithoutBlanks.Replace(" ", string.Empty);
                string[] lAgents = lAgentsWithoutBlanks.Split(lSeparators, StringSplitOptions.RemoveEmptyEntries);
                if (lAgents.Length > 0 && !Logics.Logic.Agent.IsActiveFacet(lAgents))
                {
                    return;
                }

                // No agent specified means all the agents of the application.
                lAgents = Logics.Agents.All;

                XmlNodeList lLanguageNodeList = lMainNode.SelectNodes("Language");
                bool        lExistLanguage    = false;
                string      lAlias            = "";
                foreach (XmlNode lNodeLanguage in lLanguageNodeList)
                {
                    string lLanguageKey = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "key");
                    if (lLanguageKey.Length == 0 ||
                        lLanguageKey.Equals(CultureManager.Culture.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        lAlias         = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "alias");
                        lExistLanguage = true;
                        break;
                    }
                }

                // If report is not for current language, skip it.
                if (lExistLanguage)
                {
                    lController = new HatNodeController("Report_0", lAlias, "", lAgents);

                    // Assign the presentation to the controller.
                    lController.Label = new ToolStripMenuItemPresentation(mnuReports, false);

                    // Add the controller item to the Hat list.
                    mController.HatElementNodes.Add(lController);

                    // Get the sub menu items.
                    AddReportMenuItems(lMainNode.ChildNodes, mnuReports);
                }
            }
            catch (Exception e)
            {
                Exception exc = new Exception(CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_LOADING_REPORTSCONFIG, LanguageConstantValues.L_ERROR_LOADING_REPORTSCONFIG), e);
                ScenarioManager.LaunchErrorScenario(exc);
            }

            if (mnuReports.DropDownItems.Count > 0)
            {
                mnuReports.Visible = true;
            }
        }
示例#2
0
        /// <summary>
        /// Add report menu items recursively, from the XML node.
        /// </summary>
        /// <param name="xmlNodeList">List of nodes that represent reports or submenu entries.</param>
        /// <param name="menuItem">ToolStripMenuItem object to be filled with nodes information.</param>
        private void AddReportMenuItems(XmlNodeList xmlNodeList, ToolStripMenuItem menuItem)
        {
            char[] lSeparators = new char[] { ',' };

            // Process each node: Report or SubMenu.
            foreach (XmlNode node in xmlNodeList)
            {
                try
                {
                    if (node.Name.Equals("Report", StringComparison.InvariantCultureIgnoreCase))
                    {
                        #region Get Report information
                        string lAgentsWithoutBlanks = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "agents");
                        lAgentsWithoutBlanks = lAgentsWithoutBlanks.Replace(" ", string.Empty);
                        string[] lAgents = lAgentsWithoutBlanks.Split(lSeparators, StringSplitOptions.RemoveEmptyEntries);
                        if (lAgents.Length > 0 && !Logics.Logic.Agent.IsActiveFacet(lAgents))
                        {
                            continue;
                        }

                        // Connected agent can see this report.
                        lAgents = Logics.Agents.All;
                        string lClassName       = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "class");
                        string lFilterName      = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "filtername");
                        string lDataSetFileName = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "datasetfile");
                        if (File.Exists(lDataSetFileName))
                        {
                            FileInfo lDataSetFileInfo = new FileInfo(lDataSetFileName);
                            lDataSetFileName = lDataSetFileInfo.FullName;
                        }

                        #region Get report language information
                        XmlNodeList lLanguageNodeList = node.SelectNodes("Language");
                        bool        lExistLanguage    = false;
                        string      lAlias            = "";
                        string      lTitle            = "";
                        string      lReportFileName   = "";
                        foreach (XmlNode lNodeLanguage in lLanguageNodeList)
                        {
                            string lLanguageKey = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "key");
                            if (lLanguageKey.Length == 0 ||
                                lLanguageKey.Equals(CultureManager.Culture.Name, StringComparison.InvariantCultureIgnoreCase))
                            {
                                lAlias          = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "alias");
                                lTitle          = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "title");
                                lReportFileName = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "reportfilepath");
                                lExistLanguage  = true;
                                break;
                            }
                        }
                        #endregion Get report language information

                        // If report is not for current language, skip it.
                        if (!lExistLanguage)
                        {
                            continue;
                        }

                        if (File.Exists(lReportFileName))
                        {
                            FileInfo lReportFileInfo = new FileInfo(lReportFileName);
                            lReportFileName = lReportFileInfo.FullName;
                        }

                        // Create the Menu Report Controller.
                        HatLeafReportController lController = new HatLeafReportController("Report_" + mController.HatElementNodes.Count.ToString(), lClassName, lFilterName, lAlias, lDataSetFileName, lReportFileName, lTitle, lAgents);

                        // Add the option to the menu.
                        ToolStripMenuItem lItem = new ToolStripMenuItem(lController.Alias);
                        menuItem.DropDownItems.Add(lItem);
                        // Assign the presentation to the controller.
                        lController.Trigger = new ToolStripMenuItemPresentation(lItem, true);
                        // Add the controller item to the Hat list.
                        mController.HatElementNodes.Add(lController);
                        #endregion Get Report information
                    }

                    if (node.Name.Equals("SubMenu", StringComparison.InvariantCultureIgnoreCase))
                    {
                        #region Get SubMenu information
                        string lAgentsWithoutBlanks = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, node, "agents");
                        lAgentsWithoutBlanks = lAgentsWithoutBlanks.Replace(" ", string.Empty);
                        string[] lAgents = lAgentsWithoutBlanks.Split(lSeparators, StringSplitOptions.RemoveEmptyEntries);
                        if (lAgents.Length > 0 && !Logics.Logic.Agent.IsActiveFacet(lAgents))
                        {
                            continue;
                        }

                        // Connected agent can see this report.
                        lAgents = Logics.Agents.All;

                        #region Get submenu language information
                        XmlNodeList lLanguageNodeList = node.SelectNodes("Language");
                        bool        lExistLanguage    = false;
                        string      lAlias            = "";
                        foreach (XmlNode lNodeLanguage in lLanguageNodeList)
                        {
                            string lLanguageKey = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "key");
                            if (lLanguageKey.Length == 0 ||
                                lLanguageKey.Equals(CultureManager.Culture.Name, StringComparison.InvariantCultureIgnoreCase))
                            {
                                lAlias         = UtilFunctions.GetProtectedXmlNodeValue(Properties.Settings.Default.MainMenuReports, lNodeLanguage, "alias");
                                lExistLanguage = true;
                                break;
                            }
                        }
                        #endregion Get submenu language information

                        // If report is not for current language, skip it.
                        if (!lExistLanguage)
                        {
                            continue;
                        }

                        // Create the Sub Menu Controller.
                        HatNodeController lController = new HatNodeController("Report_" + mController.HatElementNodes.Count.ToString(), lAlias, "", lAgents);

                        // Add the option to the menu.
                        ToolStripMenuItem lItem = new ToolStripMenuItem(lController.Alias);
                        menuItem.DropDownItems.Add(lItem);
                        // Add the controller item to the Hat list.
                        mController.HatElementNodes.Add(lController);

                        // Add the sub elements of this sub menu.
                        if (node.ChildNodes.Count > 0)
                        {
                            AddReportMenuItems(node.ChildNodes, lItem);
                        }
                        #endregion Get SubMenu information
                    }
                }
                catch (Exception e)
                {
                    Exception exc = new Exception(CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_LOADING_REPORTSCONFIG, LanguageConstantValues.L_ERROR_LOADING_REPORTSCONFIG), e);
                    ScenarioManager.LaunchErrorScenario(exc);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Load report from the XML configuration file.
        /// </summary>
        /// <param name="configurationFile">Reports configuration file name.</param>
        public void LoadFromFile(string configurationFile)
        {
            Reports.Clear();

            // Verify the path and file specified in MainMenuReports Settings.
            string lFilePath = configurationFile;

            if (!System.IO.File.Exists(lFilePath))
            {
                lFilePath = System.Windows.Forms.Application.StartupPath + "\\" + lFilePath;
                if (!System.IO.File.Exists(lFilePath))
                {
                    return;
                }
            }

            try
            {
                XmlDocument lXMLDoc = new XmlDocument();
                lXMLDoc.Load(lFilePath);

                XmlNodeList lNodeList = lXMLDoc.GetElementsByTagName("Report");

                int    lCode       = 1;
                char[] lSeparators = new char[] { ',' };
                foreach (XmlNode lNode in lNodeList)
                {
                    string lAgentsWithoutBlanks = UtilFunctions.GetProtectedXmlNodeValue(configurationFile, lNode, "agents");
                    lAgentsWithoutBlanks = lAgentsWithoutBlanks.Replace(" ", string.Empty);
                    string[] lAgents = lAgentsWithoutBlanks.Split(lSeparators, StringSplitOptions.RemoveEmptyEntries);
                    // If connected agent is not in the list, skip that report.
                    if (lAgents.Length > 0 && !Logics.Logic.Agent.IsActiveFacet(lAgents))
                    {
                        continue;
                    }

                    // Get report info.
                    string lClass            = UtilFunctions.GetProtectedXmlNodeValue(configurationFile, lNode, "class");
                    string lReportTypeString = UtilFunctions.GetProtectedXmlNodeValue(configurationFile, lNode, "reporttype");

                    // If type is not supported, skip it.
                    ReportTypes lReportType = ReportTypes.Unknown;
                    switch (lReportTypeString.ToUpper())
                    {
                    case "WORD":
                        lReportType = ReportTypes.Word;
                        break;

                    case "EXCEL":
                        lReportType = ReportTypes.Excel;
                        break;

                    case "CRYSTAL":
                        lReportType = ReportTypes.CrystalReports;
                        break;

                    case "RDLC":
                        lReportType = ReportTypes.RDLC;
                        break;
                    }
                    if (lReportType == ReportTypes.Unknown)
                    {
                        continue;
                    }

                    string lDataSetFileName = UtilFunctions.GetProtectedXmlNodeValue(configurationFile, lNode, "datasetfile");

                    // Get complete filename.
                    if (File.Exists(lDataSetFileName))
                    {
                        FileInfo lDataSetFile = new FileInfo(lDataSetFileName);
                        lDataSetFileName = lDataSetFile.FullName;
                    }

                    // Get language information.
                    XmlNodeList lLanguageNodeList = lNode.SelectNodes("Language");
                    bool        lExistLanguage    = false;
                    string      lAlias            = "";
                    string      lReportFileName   = "";
                    foreach (XmlNode lNodeLanguage in lLanguageNodeList)
                    {
                        string lLanguageKey = UtilFunctions.GetProtectedXmlNodeValue(configurationFile, lNodeLanguage, "key");
                        if (lLanguageKey.Length == 0 ||
                            lLanguageKey.Equals(CultureManager.Culture.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            lAlias          = UtilFunctions.GetProtectedXmlNodeValue(configurationFile, lNodeLanguage, "alias");
                            lReportFileName = UtilFunctions.GetProtectedXmlNodeValue(configurationFile, lNodeLanguage, "reportfilepath");
                            lExistLanguage  = true;
                            break;
                        }
                    }

                    // If report is not for current language, skip it.
                    if (!lExistLanguage)
                    {
                        continue;
                    }

                    if (File.Exists(lReportFileName))
                    {
                        FileInfo lReportFile = new FileInfo(lReportFileName);
                        lReportFileName = lReportFile.FullName;
                    }

                    // Add instance report info to the list.
                    ReportConfiguration lReport = new ReportConfiguration(lCode.ToString(), lAlias, lClass, lReportFileName, lReportType, lDataSetFileName);
                    Reports.Add(lReport);
                    lCode++;
                }
            }
            catch (Exception e)
            {
                Exception excProcessingFile = new Exception(CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_LOADING_REPORTSCONFIG, LanguageConstantValues.L_ERROR_LOADING_REPORTSCONFIG), e);
                Presentation.ScenarioManager.LaunchErrorScenario(excProcessingFile);
            }
        }