private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "CSV export| *.csv";
            dlg.Title = "Export current History view to Excel (csv)";
                            // 0        1       2           3       4       5           6           7                   8       9               10              11              12
            string[] colh = { "Time", "Event", "System", "Body", "Ship" , "Summary", "Description", "Detailed Info", "Note" , "Travel Dist", "Travel Time" , "Travel Jumps" , "Travelled MisJumps" };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Export.ExportGrid grd = new ExportGrid();
                grd.onGetCell += delegate (int r, int c)
                {
                    if (c == -1)    // next line?
                        return r < dataGridViewTravel.Rows.Count;
                    else if (c < colh.Length && dataGridViewTravel.Rows[r].Visible)
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Cells[TravelHistoryColumns.HistoryTag].Tag;
                        if (c == 0)
                            return dataGridViewTravel.Rows[r].Cells[0].Value;
                        else if (c == 1)
                            return he.journalEntry.EventTypeStr;
                        else if (c == 2)
                            return (he.System != null) ? he.System.name : "Unknown";    // paranoia
                        else if (c == 3)
                            return he.WhereAmI;
                        else if (c == 4)
                            return he.ShipInformation != null ? he.ShipInformation.Name : "Unknown";
                        else if (c == 5)
                            return he.EventSummary;
                        else if (c == 6)
                            return he.EventDescription;
                        else if (c == 7)
                            return he.EventDetailedInfo;
                        else if (c == 8)
                            return dataGridViewTravel.Rows[r].Cells[4].Value;
                        else if (c == 9)
                            return he.isTravelling ? he.TravelledDistance.ToString("0.0") : "";
                        else if (c == 10)
                            return he.isTravelling ? he.TravelledSeconds.ToString() : "";
                        else if (c == 11)
                            return he.isTravelling ? he.Travelledjumps.ToStringInvariant() : "";
                        else 
                            return he.isTravelling ? he.TravelledMissingjump.ToStringInvariant() : "";
                    }
                    else
                        return null;
                };

                grd.onGetHeader += delegate (int c)
                {
                    return (c < colh.Length) ? colh[c] : null;
                };

                grd.Csvformat = discoveryform.ExportControl.radioButtonCustomEU.Checked ? CSVFormat.EU : CSVFormat.USA_UK;
                if (grd.ToCSV(dlg.FileName))
                    System.Diagnostics.Process.Start(dlg.FileName);
            }
        }
Example #2
0
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "CSV export| *.csv";
            dlg.Title  = "Export current History view to Excel (csv)";
            // 0        1       2           3            4               5           6           7             8              9              10              11              12
            string[] colh = { "Time", "System", "Visits", "Other Info", "Visit List", "Body", "Ship", "Description", "Detailed Info", "Travel Dist", "Travel Time", "Travel Jumps", "Travelled MisJumps" };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Export.ExportGrid grd = new ExportGrid();
                grd.onGetCell += delegate(int r, int c)
                {
                    if (c == -1)    // next line?
                    {
                        return(r < dataGridViewStarList.Rows.Count);
                    }
                    else if (c < colh.Length && dataGridViewStarList.Rows[r].Visible)
                    {
                        List <HistoryEntry> syslist = dataGridViewStarList.Rows[r].Tag as List <HistoryEntry>;
                        HistoryEntry        he      = syslist[0];

                        if (c == 0)
                        {
                            return(dataGridViewStarList.Rows[r].Cells[0].Value);
                        }
                        else if (c == 1)
                        {
                            return(dataGridViewStarList.Rows[r].Cells[1].Value);
                        }
                        else if (c == 2)
                        {
                            return(dataGridViewStarList.Rows[r].Cells[2].Value);
                        }
                        else if (c == 3)
                        {
                            return(dataGridViewStarList.Rows[r].Cells[3].Value);
                        }
                        else if (c == 4)
                        {
                            string tlist = "";
                            if (syslist.Count > 1)
                            {
                                for (int i = 1; i < syslist.Count; i++)
                                {
                                    tlist = tlist.AppendPrePad(syslist[i].EventTimeLocal.ToShortDateString() + " " + syslist[i].EventTimeLocal.ToShortTimeString(), ", ");
                                }
                            }
                            return(tlist);
                        }
                        else if (c == 5)
                        {
                            return(he.WhereAmI);
                        }
                        else if (c == 6)
                        {
                            return(he.ShipInformation != null ? he.ShipInformation.Name : "Unknown");
                        }
                        else if (c == 7)
                        {
                            return(he.EventDescription);
                        }
                        else if (c == 8)
                        {
                            return(he.EventDetailedInfo);
                        }
                        else if (c == 9)
                        {
                            return(he.isTravelling ? he.TravelledDistance.ToString("0.0") : "");
                        }
                        else if (c == 10)
                        {
                            return(he.isTravelling ? he.TravelledSeconds.ToString() : "");
                        }
                        else if (c == 11)
                        {
                            return(he.isTravelling ? he.Travelledjumps.ToStringInvariant() : "");
                        }
                        else    // 12
                        {
                            return(he.isTravelling ? he.TravelledMissingjump.ToStringInvariant() : "");
                        }
                    }
                    else
                    {
                        return(null);
                    }
                };

                grd.onGetHeader += delegate(int c)
                {
                    return((c < colh.Length) ? colh[c] : null);
                };

                grd.Csvformat = discoveryform.ExportControl.radioButtonCustomEU.Checked ? BaseUtils.CVSWrite.CSVFormat.EU : BaseUtils.CVSWrite.CSVFormat.USA_UK;
                if (grd.ToCSV(dlg.FileName))
                {
                    System.Diagnostics.Process.Start(dlg.FileName);
                }
            }
        }