Exemplo n.º 1
0
 /// <summary>
 /// get the values Name/Description/Xml from the ListBox item
 /// </summary>
 /// <param name="item">usually the selected item in the list box as ReportListBoxItem</param>
 /// <param name="createTmpFile">true if should create the file in the xml on disk</param>
 /// <param name="reportName">ref to the report Name</param>
 /// <param name="reportDesc">ref to the report Description</param>
 /// <param name="filePath">ref to the reportFilePath</param>
 private void GetItemValues(ReportListBoxItem item, bool createTmpFile, ref string reportName,
                            ref string reportDesc, ref string filePath, ref FluidTrade.Reporting.Interfaces.IStaticReportTranslation translator)
 {
     if (item.Row != null)
     {
         //the item is pointing to a row in the dataModel
         ReportXmlHelper.XmlToTempFile(item.Row.Xaml, createTmpFile, out reportName, out reportDesc, out filePath, out translator);
     }
     else if (string.IsNullOrEmpty(item.LocalFilePath) == false)
     {
         //item is pointing at a local file
         reportName = filePath = item.LocalFilePath;
         reportDesc = string.Empty;
     }
     else if (string.IsNullOrEmpty(item.Xml) == false)
     {
         //item is pointing at a newly imported report
         ReportXmlHelper.XmlToTempFile(item.Xml, createTmpFile, out reportName, out reportDesc, out filePath, out translator);
     }
     else
     {
         //error
         return;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// handler for the property button click. Will show the properties window if
        /// the listbox has a selected item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void propBtn_Click(object sender, ExecutedRoutedEventArgs e)
        {
            //get the selected item
            ReportListBoxItem item = this.listBox1.SelectedItem as ReportListBoxItem;

            if (item == null)
            {
                return;                 //no selected item so return
            }
            string reportName = null;
            string reportDesc = null;
            string filePath   = null;

            FluidTrade.Reporting.Interfaces.IStaticReportTranslation translator = null;
            //get the values from the item
            this.GetItemValues(item, false, ref reportName, ref reportDesc, ref filePath, ref translator);

            //show the properties window
            WindowImportProperties win = new WindowImportProperties(reportName, reportDesc);

            win.ShowDialog();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Static helper method to show PickReport window
        /// returns true if user clicked OK,
        ///
        /// </summary>
        /// <param name="name">Name of the report the user picked</param>
        /// <param name="path">path to the report file on disk</param>
        /// <param name="translator"></param>
        /// <returns>true if your clicked OK</returns>
        public static bool PickReport(out string name, out string path, out FluidTrade.Reporting.Interfaces.IStaticReportTranslation translator)
        {
            name       = null;
            path       = null;
            translator = null;
            //try to load a crystal report dll. if not there don't let user continue
            System.Reflection.Assembly testAssembly = null;
            try
            {
                const String crystalAssebly = "CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304";
                testAssembly = System.Reflection.Assembly.Load(crystalAssebly);
            }
            catch
            {
            }
            if (testAssembly == null)
            {
                //TODO: LOCALIZE
                MessageBox.Show("Crystal reports are needed for reporting feature. Crystal Reports install can be found at: install directory\\Dependancy\\CrystalReports\\setup.exe");
                return(false);
            }
            //create the PickReport window
            WindowPickReport window = new WindowPickReport();

            if (true.Equals(window.ShowDialog()))
            {
                //if the user clicked ok set the return values
                path       = window.FilePath;
                name       = window.ReportName;
                translator = window.translator;
                return(true);
            }

            //nothing seleceted
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// deserialize xml document to name and description and optionally fill stream with content
        /// </summary>
        /// <param name="xml">xml containing data</param>
        /// <param name="name">Name attribute in xml</param>
        /// <param name="description">description attribute</param>
        /// <param name="outputStream">null if no content is not required</param>
        public static void XmlToTempFile(string xml, string tmpFilePath, out string name, out string description, out FluidTrade.Reporting.Interfaces.IStaticReportTranslation translator)
        {
            Stream outputStream = null;

            if (string.IsNullOrEmpty(tmpFilePath) == false)
            {
                outputStream = File.Open(tmpFilePath, FileMode.CreateNew);
            }
            name        = null;
            description = null;
            string base64File = null;
            string base64TranslationContent = null;

            translator = null;
            //create the xmlReader to walk the xml doc
            using (StringReader stringReader = new StringReader(xml))
            {
                using (System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(stringReader))
                {
                    xmlReader.WhitespaceHandling = System.Xml.WhitespaceHandling.Significant;
                    //read to get to the first node
                    xmlReader.Read();

                    //get the name and description attributes
                    name        = xmlReader.GetAttribute(Name);
                    description = xmlReader.GetAttribute(Description);


                    if (outputStream == null)
                    {
                        return;                        //dont need to do anymore
                    }
                    //get to the content
                    xmlReader.Read();
                    base64File = xmlReader.ReadElementContentAsString();

                    //get to the translator
                    if (xmlReader.NodeType != System.Xml.XmlNodeType.EndElement)
                    {
                        xmlReader.Read();
                        base64TranslationContent = xmlReader.ReadContentAsString();
                    }
                    xmlReader.ReadEndElement();
                }
            }

            //if no outputStream or no content in xml then nothing left to do
            if (outputStream == null || string.IsNullOrEmpty(base64File))
            {
                return;
            }

            //convert the content to bytes
            Byte[] bytes = Convert.FromBase64String(base64File);

            //write the bytes to the stream
            using (BinaryWriter binWriter = new BinaryWriter(outputStream))
            {
                binWriter.Write(bytes);
                binWriter.Flush();
            }


            if (string.IsNullOrEmpty(base64TranslationContent) == false)
            {
                //convert the content to bytes
                Byte[] translationBytes = Convert.FromBase64String(base64TranslationContent);

                System.Reflection.Assembly translationAssembly = AppDomain.CurrentDomain.Load(translationBytes);
                Type[] types = translationAssembly.GetTypes();
                foreach (Type t in types)
                {
                    if (t.GetInterface("FluidTrade.Reporting.Interfaces.IStaticReportTranslation") != null)
                    {
                        translator = Activator.CreateInstance(t) as FluidTrade.Reporting.Interfaces.IStaticReportTranslation;
                        break;
                    }
                }
            }
        }