private void btnExportExcel_Click(object sender, EventArgs e)
 {
     try
     {
         if (gridViewData.RowCount > 0)
         {
             string         path  = "";
             SaveFileDialog saved = new SaveFileDialog();
             saved.Filter = "Excel (*.xlsx)|*.xlsx|Excel (*.xls)|*.xls";
             if (DialogResult.OK == saved.ShowDialog())
             {
                 path = saved.FileName.ToString();
                 ExportTarget excel = ExportTarget.Xlsx;
                 gridViewData.BestFitColumns(true);
                 gridViewData.OptionsPrint.AutoWidth        = false;
                 gridViewData.OptionsPrint.ExpandAllDetails = true;
                 gridViewData.OptionsPrint.PrintVertLines   = false;
                 gridViewData.OptionsPrint.PrintHorzLines   = false;
                 gridViewData.Export(excel, path);
                 if (DialogResult.OK == XtraMessageBox.Show("Mở file \"" + Path.GetFileName(path) + "\" ?", "", MessageBoxButtons.OKCancel))
                 {
                     System.Diagnostics.Process.Start(path);
                 }
             }
         }
         else
         {
             XtraMessageBox.Show("Không tìm thấy dữ liệu!");
         }
     }
     catch { }
 }
        void OnExport(object sender, EventArgs e)
        {
            ExportTarget exportType  = GetCurrentExportType();
            string       fileName    = "grid." + exportType.ToString().ToLower();
            IPathService pathServise = GlobalServices.Instance.GetService <IPathService>();

            if (pathServise == null)
            {
                return;
            }

            string filePath = pathServise.GetAbsolutePath(fileName);

            pathServise.EnsurePathExists(filePath);

            using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) {
                if (grid.ExportToExcel(stream, exportType))
                {
                    txtPath.Text = stream.AbsolutePath;
                }
                else
                {
                    txtPath.Text = String.Empty;
                    DisplayAlert("GridDemo", "Make sure you have an application for opening " + exportType.ToString() + " files.", "Cancel");
                }
            }
        }
        public static void SaveFileFromGridView(this GridView g)
        {
            try
            {
                if (g.RowCount != 0)
                {
                    string         path  = "";
                    SaveFileDialog saved = new SaveFileDialog();
                    saved.Filter = "Excel (*.xlsx)|*.xlsx|Excel (*.xls)|*.xls";

                    saved.FileName = "Report_" + DateTime.Now.ToString("ddMMyyyy") + "";
                    if (DialogResult.OK == saved.ShowDialog())
                    {
                        path = saved.FileName.ToString();
                        ExportTarget excel = ExportTarget.Xlsx;
                        g.BestFitColumns(true);
                        g.OptionsPrint.AutoWidth        = false;
                        g.OptionsPrint.ExpandAllDetails = true;
                        g.OptionsPrint.PrintVertLines   = false;
                        g.OptionsPrint.PrintHorzLines   = false;
                        g.Export(excel, path);
                        if (DialogResult.OK == XtraMessageBox.Show("Mở file \"" + Path.GetFileName(path) + "\" ?", "", MessageBoxButtons.OKCancel))
                        {
                            System.Diagnostics.Process.Start(path);
                        }
                    }
                }
                else
                {
                    XtraMessageBox.Show("Không có dữ liệu!", "Thông báo");
                }
            }
            catch (Exception ex) { XtraMessageBox.Show("Lỗi: " + ex.Message, "Thông báo"); }
        }
Beispiel #4
0
        private void ExportProject(ExportTarget Target)
        {
            ExportProjectSectionOptions spriteSection;
            ExportProjectSectionOptions tileSection;

            using (var exportDialog = new ExportProjectDialog())
            {
                if (exportDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                spriteSection = exportDialog.SpriteOptions;
                tileSection   = exportDialog.TilesOptions;
            }

            switch (Target)
            {
            case Enums.ExportTarget.Editor:
                string content = GenerateProjectCode(spriteSection, tileSection);
                if (string.IsNullOrWhiteSpace(content))
                {
                    return;
                }
                TextEditor editor = new TextEditor(currentProject.Name, content);
                editor.MdiParent = this;
                editor.Show();
                break;

            case Enums.ExportTarget.Clipboard:
                string contentc = GenerateProjectCode(spriteSection, tileSection);
                if (string.IsNullOrWhiteSpace(contentc))
                {
                    return;
                }
                Clipboard.SetText(contentc);
                MessageBox.Show("Content copied to clipboard");
                break;

            case Enums.ExportTarget.File:

                string contentf = GenerateProjectCode(spriteSection, tileSection);
                if (string.IsNullOrWhiteSpace(contentf))
                {
                    return;
                }
                using (var dlg = new SaveFileDialog {
                    FileName = currentProject.Name + ".zxbas", Filter = "Basic files (.zxbas)|*.zxbas|Basic files (.bas)|*.bas"
                })
                {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        File.WriteAllText(dlg.FileName, contentf);
                    }
                }

                break;
            }
        }
 /// <summary>
 /// Does form load.
 /// </summary>
 private void DoFormLoad()
 {
     SaveSettingsDialog.InitialDirectory = Settings.GetExportDirectory();
     OpenSettingsDialog.InitialDirectory = SaveSettingsDialog.InitialDirectory;
     SaveSettingsDialog.Filter           = ExportTarget.CreateFilters();
     OpenSettingsDialog.Filter           = SaveSettingsDialog.Filter;
     LoadEditIntervals();
     LoadExportFileFormats();
 }
Beispiel #6
0
 void AddExportTarget(ExportTarget target) {
     var exportItem = new DXMenuCheckItem()
     {
         Caption = target.ToString(),
         Tag = target
     };
     menuExport.Items.Add(exportItem);
     exportItem.Click += exportItem_Click;
 }
Beispiel #7
0
        void AddExportTarget(ExportTarget target)
        {
            var exportItem = new DXMenuCheckItem()
            {
                Caption = target.ToString(),
                Tag     = target
            };

            menuExport.Items.Add(exportItem);
            exportItem.Click += exportItem_Click;
        }
Beispiel #8
0
        private void BeginExport(ExportTarget Target)
        {
            using (var dlg = new ExportCharSetDialog())
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    ExportEventArgs args = new ExportEventArgs
                    {
                        Prefix    = dlg.Prefix,
                        Postfix   = dlg.Postfix,
                        SingleDim = dlg.SingleDimension,
                        CharSet   = CurrentSet,
                        Target    = Target,
                        Colors    = dlg.IncludeColors
                    };

                    Export(this, args);
                }
            }
        }
Beispiel #9
0
 public void ExportTo(GridCellGroup rootCell, string fileName, ExportTarget target)
 {
     switch (target)
     {
         case ExportTarget.Xml:
             {
                 FileStream stream = new FileStream(fileName, FileMode.Create);
                 XmlWriterSettings settings = new XmlWriterSettings
                 {
                     Indent = true,
                     OmitXmlDeclaration = true,
                     ConformanceLevel = ConformanceLevel.Auto
                 };
                 XmlWriter writer = XmlWriter.Create(stream, settings);
                 SaveResults(rootCell, writer);
                 writer.Close();
             }
             break;
     }
 }
Beispiel #10
0
        public void ExportTo(GridCellGroup rootCell, string fileName, ExportTarget target)
        {
            string ext = Path.GetExtension(fileName);
            AbstractWriter writer = null;
            switch (target)
            {
                case ExportTarget.Xml:
                    writer = new XmlFileWriter(fileName);
                    break;

                case ExportTarget.Csv:
                    writer = new CsvWriter(fileName, 
                        CultureInfo.CurrentCulture.TextInfo.ListSeparator, true);
                    break;

                case ExportTarget.TabDelimited:
                    writer = new CsvWriter(fileName, "\t", true);
                    break;

                case ExportTarget.FixedLength:
                    writer = new FlvWriter(fileName, true);
                    break;

                case ExportTarget.AdoNet:
                    writer = new AdoNetWriter(fileName);
                    break;
            }
            if (writer != null)
            {
                ResultsetGridBuilder builder = new ResultsetGridBuilder();
                Resultset rs = builder.CreateResultset((ResultsetGridBuilder.RootCell)rootCell);
                writer.Write(rs);
            }
        }
Beispiel #11
0
 private void exportItem_Click(object sender, EventArgs e)
 {
     SelectedExport = (ExportTarget)((DXMenuItem)sender).Tag;
 }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// RtfCreator constructor.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public RtfCreator(PaProject project, ExportTarget target, ExportFormat format,
                          DataGridView grid, WordListCache cache, string rtfEditor)
        {
            m_project      = project;
            m_exportTarget = target;
            m_exportFormat = format;
            m_grid         = grid;

            if (m_grid != null)
            {
                m_graphics = m_grid.CreateGraphics();

                // Store the dots per inch value from the grid's graphic object
                m_pixelsPerInch = m_graphics.DpiX;
            }

            m_cache                = cache;
            m_rtfEditor            = rtfEditor;
            m_createSearchItemTabs = CreateSearchItemTabs.FirstTab;
            m_rtfBldr              = new StringBuilder();

            // Default value is 1/8" gap between columns.
            m_colRightPadding = Properties.Settings.Default.RTFExportGapBetweenColumns;

            // Add support for highlighting the search item
            if (m_cache.IsForSearchResults)
            {
                Dictionary <int, int> colorReferences;
                RtfHelper.ColorTable(Properties.Settings.Default.QuerySearchItemBackColor, out colorReferences);
                m_searchItemColorRefNumber = colorReferences[Properties.Settings.Default.QuerySearchItemBackColor.ToArgb()];
            }

            // Sort the visible columns by their display order.
            m_sortedColumns = new SortedList <int, DataGridViewColumn>();
            foreach (DataGridViewColumn col in m_grid.Columns)
            {
                if (col.Visible && !(col is SilHierarchicalGridColumn))
                {
                    m_sortedColumns[col.DisplayIndex] = col;
                }
            }

            GetPaperAndMarginValues();
            CalculateColumnWidths();
            OutputRTFHeadingStuff();

            // This is only for running tests
            if (m_maxFieldWidths.Count > 0)
            {
                MakeFinalWidthAdjustments();
                m_rtfBldr.AppendFormat(@"\paperw{0}\paperh{1}", m_paperWidth, m_paperHeight);
                m_rtfBldr.AppendFormat(@"\margl{0}\margr{1}", m_leftMargin, m_rightMargin);
                m_rtfBldr.AppendFormat(@"\margt{0}\margb{1}", m_topMargin, m_bottomMargin);
                m_rtfBldr.AppendLine();

                OutputReportHeadingInformation();
                OutputColumnInformation();
                OutputDataRows();
                WriteToFileOrClipboard();
            }

            if (m_graphics != null)
            {
                m_graphics.Dispose();
            }
        }