Exemple #1
0
        private bool ExportToExcelFile(string AFilename)
        {
            bool ExportOnlyLowestLevel = false;

            // Add the parameter export_only_lowest_level to the Parameters if you don't want to export the
            // higher levels. In some reports (Supporting Churches Report or Partner Contact Report) the csv
            // output looks much nicer if it doesn't contain the unnecessary higher levels.
            if (FParameterList.Exists("csv_export_only_lowest_level"))
            {
                ExportOnlyLowestLevel = FParameterList.Get("csv_export_only_lowest_level").ToBool();
            }

            XmlDocument doc = FResultList.WriteXmlDocument(FParameterList, ExportOnlyLowestLevel);

            if (doc != null)
            {
                using (FileStream fs = new FileStream(AFilename, FileMode.Create))
                {
                    if (TCsv2Xml.Xml2ExcelStream(doc, fs, false))
                    {
                        fs.Close();
                    }
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// export to an Excel xlsx file
        /// </summary>
        public void ExportToExcelFile()
        {
            if (dlgSaveXLSXFile.FileName.Length == 0)
            {
                dlgSaveXLSXFile.FileName = this.ReportName + '.' + dlgSaveXLSXFile.DefaultExt;
            }

            if (dlgSaveXLSXFile.ShowDialog() == DialogResult.OK)
            {
                bool ExportOnlyLowestLevel = false;

                // Add the parameter export_only_lowest_level to the Parameters if you don't want to export the
                // higher levels. In some reports (Supporting Churches Report or Partner Contact Report) the csv
                // output looks much nicer if it doesn't contain the unnecessary higher levels.
                if (Parameters.Exists("csv_export_only_lowest_level"))
                {
                    ExportOnlyLowestLevel = Parameters.Get("csv_export_only_lowest_level").ToBool();
                }

                XmlDocument doc = Results.WriteXmlDocument(Parameters, ExportOnlyLowestLevel);

                if (doc != null)
                {
                    using (FileStream fs = new FileStream(dlgSaveXLSXFile.FileName, FileMode.Create))
                    {
                        if (TCsv2Xml.Xml2ExcelStream(doc, fs, false))
                        {
                            fs.Close();
                        }
                    }

                    try
                    {
                        System.Diagnostics.Process excelProcess;
                        excelProcess = new System.Diagnostics.Process();
                        excelProcess.EnableRaisingEvents = false;
                        excelProcess.StartInfo.FileName  = dlgSaveXLSXFile.FileName;
                        excelProcess.Start();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Catalog.GetString("Failed to save file"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void tbtCreateExtractClick(System.Object sender, System.EventArgs e)
        {
            XmlDocument doc = Results.WriteXmlDocument(Parameters, true);
            DataTable   Tbl = new DataTable();

            Tbl.Columns.Add("PartnerKey", typeof(Int64));
            XmlNodeList Rows       = doc.SelectNodes("*/Element");
            XmlNode     FirstRow   = Rows[0];
            String      ColumnName = SelectColumnNameForExract(FirstRow);

            this.UseWaitCursor = true;

            foreach (XmlNode node in Rows)
            {
                XmlAttribute Attr = node.Attributes[ColumnName];

                if (Attr != null)
                {
                    Int64 intPartnerKey;

                    if (Int64.TryParse(Attr.Value, out intPartnerKey))
                    {
                        DataRow Row = Tbl.NewRow();
                        Row["PartnerKey"] = intPartnerKey;
                        Tbl.Rows.Add(Row);
                    }
                }
            }

            this.UseWaitCursor = false;

            if (Tbl.Rows.Count < 1)
            {
                MessageBox.Show(Catalog.GetString("Error - no Partner keys found"), Catalog.GetString("Generate Extract"));
                return;
            }

            TFrmExtractNamingDialog ExtractNameDialog = new TFrmExtractNamingDialog(this);
            string ExtractName;
            string ExtractDescription;

            ExtractNameDialog.ShowDialog();

            if (ExtractNameDialog.DialogResult != System.Windows.Forms.DialogResult.Cancel)
            {
                /* Get values from the Dialog */
                ExtractNameDialog.GetReturnedParameters(out ExtractName, out ExtractDescription);
            }
            else
            {
                // dialog was cancelled, do not continue with extract generation
                return;
            }

            ExtractNameDialog.Dispose();

            this.UseWaitCursor = true;

            // Create extract with given name and description and store it
            int ExtractId = 0;
            IPartnerUIConnectorsPartnerNewExtract PartnerExtractObject = TRemote.MPartner.Extracts.UIConnectors.PartnerNewExtract();
            Boolean CreateOk = PartnerExtractObject.CreateExtractFromListOfPartnerKeys(ExtractName, ExtractDescription, out ExtractId, Tbl, 0, false);

            this.UseWaitCursor = false;

            if (CreateOk)
            {
                MessageBox.Show(String.Format(Catalog.GetString("Extract Created with {0} Partners."),
                                              Tbl.Rows.Count),
                                Catalog.GetString("Generate Extract"));
            }
            else
            {
                MessageBox.Show(Catalog.GetString("Creation of extract failed"),
                                Catalog.GetString("Generate Extract"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Stop);
            }
        }