示例#1
0
        public static bool Print(Oid rootOID, ReportConfiguration reportConfig)
        {
            bool Rslt = false;

            //Create a Excel object and add the Template specified in ReportPath.
            object oExcel         = Excel.GetExcel(false);
            object oExcelTemplate = Excel.GetExcelTemplate(
                Excel.GetExcelWorkbooks(oExcel), reportConfig.ReportFilePath);

            //Get the XML query requests.
            string XmlReport = Excel.DataRequest(rootOID, oExcelTemplate);

            if (XmlReport.Length > 0)
            {
                //Execute the queries.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(XmlReport);
                XmlNode nodeRslt = PrintToXML.GetQueryXML(rootOID, xmlDoc.DocumentElement);
                Excel.DataProcessing(oExcelTemplate, nodeRslt.OuterXml);
                Excel.SetVisibleExcel(true, oExcel);
                Rslt = true;
            }

            return(Rslt);
        }
示例#2
0
        public static bool Print(Oid rootOID, ReportConfiguration reportConfig)
        {
            bool Rslt = false;

            //Create a Excel object and add the Template specified in ReportPath.
            object oExcel = Excel.GetExcel(false);
            object oExcelTemplate = Excel.GetExcelTemplate(
            Excel.GetExcelWorkbooks(oExcel), reportConfig.ReportFilePath);

            //Get the XML query requests.
            string XmlReport = Excel.DataRequest(rootOID, oExcelTemplate);
            if (XmlReport.Length > 0)
            {
                //Execute the queries.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(XmlReport);
                XmlNode nodeRslt = PrintToXML.GetQueryXML(rootOID, xmlDoc.DocumentElement);
                Excel.DataProcessing(oExcelTemplate, nodeRslt.OuterXml);
                Excel.SetVisibleExcel(true, oExcel);
                Rslt = true;
            }

            return Rslt;
        }
示例#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);
            }
        }
示例#4
0
		public static bool Print(Oid rootOID, ReportConfiguration reportConfig, bool preview, int numCopies, string printerName, string fileName)
		{
			bool Rslt = false;

			//Create a Word object and add the Template specified in ReportPath.
			object oWord = Word.GetWord(false);
			object oWordTemplate = Word.GetWordDocumentTemplate(
				Word.GetWordDocuments(oWord), reportConfig.ReportFilePath);

			//Get the XML query requests.
			string XmlReport = Word.DataRequest(rootOID, oWordTemplate);
			if (XmlReport.Length > 0)
			{
				try
				{
					//Execute the queries.
					XmlDocument xmlDoc = new XmlDocument();
					xmlDoc.LoadXml(XmlReport);

					XmlNode nodeRslt = PrintToXML.GetQueryXML(rootOID, xmlDoc.DocumentElement);
					Word.DataProcessing(oWordTemplate, nodeRslt.OuterXml);

					// Ask for extra information, Preview or not, number of copies ...

					if (preview)
					{
						Word.SetVisibleWord(true, oWord);
					}
					else
					{
						// If filename has values, save the document else print it
						if (fileName != "")
						{
							Word.SaveAs(oWordTemplate, fileName);
							Word.Close(WordSaveOptions.wdDoNotSaveChanges, oWordTemplate);
						}
						else
						{
							// Print and close Word
							Word.ActivePrinter(oWord, printerName);
							Word.PrintOut(oWordTemplate, numCopies);
							// Before closing the created document, it must be saved.
							//  Save in the temp folder and delete it
							string tempFileName = System.IO.Path.GetTempFileName();
							Word.SaveAs(oWordTemplate, tempFileName);
							Word.Close(WordSaveOptions.wdDoNotSaveChanges, oWordTemplate);
							System.IO.File.Delete(tempFileName);
						}
						// Quit from Word
						Word.Quit(WordSaveOptions.wdDoNotSaveChanges, oWord);
					}
				}
				catch(Exception e)
				{
					Word.Quit(WordSaveOptions.wdDoNotSaveChanges,oWord);
					throw new Exception(e.Message,e);
				}
				Rslt = true;
			}
			return Rslt;
		}
示例#5
0
        public static bool Print(Oid rootOID, ReportConfiguration reportConfig, bool preview, int numCopies, string printerName, string fileName)
        {
            bool Rslt = false;

            //Create a Word object and add the Template specified in ReportPath.
            object oWord         = Word.GetWord(false);
            object oWordTemplate = Word.GetWordDocumentTemplate(
                Word.GetWordDocuments(oWord), reportConfig.ReportFilePath);

            //Get the XML query requests.
            string XmlReport = Word.DataRequest(rootOID, oWordTemplate);

            if (XmlReport.Length > 0)
            {
                try
                {
                    //Execute the queries.
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(XmlReport);

                    XmlNode nodeRslt = PrintToXML.GetQueryXML(rootOID, xmlDoc.DocumentElement);
                    Word.DataProcessing(oWordTemplate, nodeRslt.OuterXml);

                    // Ask for extra information, Preview or not, number of copies ...

                    if (preview)
                    {
                        Word.SetVisibleWord(true, oWord);
                    }
                    else
                    {
                        // If filename has values, save the document else print it
                        if (fileName != "")
                        {
                            Word.SaveAs(oWordTemplate, fileName);
                            Word.Close(WordSaveOptions.wdDoNotSaveChanges, oWordTemplate);
                        }
                        else
                        {
                            // Print and close Word
                            Word.ActivePrinter(oWord, printerName);
                            Word.PrintOut(oWordTemplate, numCopies);
                            // Before closing the created document, it must be saved.
                            //  Save in the temp folder and delete it
                            string tempFileName = System.IO.Path.GetTempFileName();
                            Word.SaveAs(oWordTemplate, tempFileName);
                            Word.Close(WordSaveOptions.wdDoNotSaveChanges, oWordTemplate);
                            System.IO.File.Delete(tempFileName);
                        }
                        // Quit from Word
                        Word.Quit(WordSaveOptions.wdDoNotSaveChanges, oWord);
                    }
                }
                catch (Exception e)
                {
                    Word.Quit(WordSaveOptions.wdDoNotSaveChanges, oWord);
                    throw new Exception(e.Message, e);
                }
                Rslt = true;
            }
            return(Rslt);
        }
示例#6
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);
            }
        }