Пример #1
0
        static public bool WriteGrid(this BaseUtils.CSVWriteGrid grid, string file, bool autoopen, Form parent)
        {
            if (grid.WriteCSV(file))
            {
                if (autoopen)
                {
                    try
                    {
                        System.Diagnostics.Process.Start(file);
                        return(true);
                    }
                    catch
                    {
                        FailedToOpen(parent, file);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                WriteFailed(parent, file);
            }

            return(false);
        }
Пример #2
0
        static public bool WriteGrid(this BaseUtils.CSVWriteGrid grid, string file, bool autoopen, Form parent)
        {
            if (grid.WriteCSV(file))
            {
                if (autoopen)
                {
                    try
                    {
                        System.Diagnostics.Process.Start(file);
                        return(true);
                    }
                    catch
                    {
                        ExtendedControls.MessageBoxTheme.Show(parent, "Failed to open " + file, "Warning".Tx(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                ExtendedControls.MessageBoxTheme.Show(parent, "Failed to write to " + file, "Warning".Tx(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return(false);
        }
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "Export Current View" }, allowRawJournalExport: true);

            if (frm.ShowDialog(this.FindForm()) == DialogResult.OK)
            {
                if (frm.SelectedIndex == 0)
                {
                    BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                    grd.SetCSVDelimiter(frm.Comma);
                    grd.GetLineStatus += delegate(int r)
                    {
                        if (r < dataGridViewJournal.Rows.Count)
                        {
                            HistoryEntry he = dataGridViewJournal.Rows[r].Cells[JournalHistoryColumns.HistoryTag].Tag as HistoryEntry;
                            return((dataGridViewJournal.Rows[r].Visible &&
                                    he.EventTimeLocal.CompareTo(frm.StartTime) >= 0 &&
                                    he.EventTimeLocal.CompareTo(frm.EndTime) <= 0) ? BaseUtils.CSVWriteGrid.LineStatus.OK : BaseUtils.CSVWriteGrid.LineStatus.Skip);
                        }
                        else
                        {
                            return(BaseUtils.CSVWriteGrid.LineStatus.EOF);
                        }
                    };

                    grd.GetLine += delegate(int r)
                    {
                        HistoryEntry    he = dataGridViewJournal.Rows[r].Cells[JournalHistoryColumns.HistoryTag].Tag as HistoryEntry;
                        DataGridViewRow rw = dataGridViewJournal.Rows[r];
                        if (frm.ExportAsJournals)
                        {
                            return(new Object[] { he.journalEntry.GetJson()?.ToString() });
                        }
                        else
                        {
                            return new Object[] { rw.Cells[0].Value, rw.Cells[2].Value, rw.Cells[3].Value }
                        };
                    };

                    grd.GetHeader += delegate(int c)
                    {
                        return((c < 3 && frm.IncludeHeader) ? dataGridViewJournal.Columns[c + ((c > 0) ? 1 : 0)].HeaderText : null);
                    };

                    if (grd.WriteCSV(frm.Path))
                    {
                        if (frm.AutoOpen)
                        {
                            System.Diagnostics.Process.Start(frm.Path);
                        }
                    }
                    else
                    {
                        ExtendedControls.MessageBoxTheme.Show(this.FindForm(), "Failed to write to " + frm.Path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
Пример #4
0
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            if (dataGridViewRoute.Rows.Count == 0)
            {
                ExtendedControls.MessageBoxTheme.Show(FindForm(), "No Route Plotted", "Route", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "All" }, disablestartendtime: true);

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                grd.SetCSVDelimiter(frm.Comma);

                grd.GetLineStatus += delegate(int r)
                {
                    if (r < dataGridViewRoute.Rows.Count)
                    {
                        return(BaseUtils.CSVWriteGrid.LineStatus.OK);
                    }
                    else
                    {
                        return(BaseUtils.CSVWriteGrid.LineStatus.EOF);
                    }
                };

                grd.GetLine += delegate(int r)
                {
                    DataGridViewRow rw = dataGridViewRoute.Rows[r];

                    return(new Object[] { rw.Cells[0].Value, rw.Cells[1].Value,
                                          rw.Cells[2].Value, rw.Cells[3].Value, rw.Cells[4].Value,
                                          rw.Cells[5].Value, rw.Cells[6].Value });
                };

                grd.GetHeader += delegate(int c)
                {
                    return((c < dataGridViewRoute.Columns.Count) ? dataGridViewRoute.Columns[c].HeaderText : null);
                };


                if (grd.WriteCSV(frm.Path))
                {
                    if (frm.AutoOpen)
                    {
                        System.Diagnostics.Process.Start(frm.Path);
                    }
                }
                else
                {
                    ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to write to " + frm.Path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Пример #5
0
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "View", "FSD Jumps only", "With Notes only", "With Notes, no repeat" });

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                grd.SetCSVDelimiter(frm.Comma);

                List <SystemNoteClass> sysnotecache = new List <SystemNoteClass>();
                string[] colh = null;

                grd.GetLineStatus += delegate(int r)
                {
                    if (r < dataGridViewTravel.Rows.Count)
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Cells[TravelHistoryColumns.HistoryTag].Tag;
                        return((dataGridViewTravel.Rows[r].Visible &&
                                he.EventTimeLocal.CompareTo(frm.StartTime) >= 0 &&
                                he.EventTimeLocal.CompareTo(frm.EndTime) <= 0) ? BaseUtils.CSVWriteGrid.LineStatus.OK : BaseUtils.CSVWriteGrid.LineStatus.Skip);
                    }
                    else
                    {
                        return(BaseUtils.CSVWriteGrid.LineStatus.EOF);
                    }
                };

                if (frm.SelectedIndex == 1)     // export fsd jumps
                {
                    colh = new string[] { "Time", "Name", "X", "Y", "Z", "Distance", "Fuel Used", "Fuel Left", "Boost", "Note" };

                    grd.VerifyLine += delegate(int r)       // addition qualifier for FSD jump
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Cells[TravelHistoryColumns.HistoryTag].Tag;
                        return(he.EntryType == JournalTypeEnum.FSDJump);
                    };

                    grd.GetLine += delegate(int r)
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Cells[TravelHistoryColumns.HistoryTag].Tag;
                        EliteDangerousCore.JournalEvents.JournalFSDJump fsd = he.journalEntry as EliteDangerousCore.JournalEvents.JournalFSDJump;

                        return(new Object[] {
                            fsd.EventTimeLocal,
                            fsd.StarSystem,
                            fsd.StarPos.X,
                            fsd.StarPos.Y,
                            fsd.StarPos.Z,
                            fsd.JumpDist,
                            fsd.FuelUsed,
                            fsd.FuelLevel,
                            fsd.BoostUsed,
                            he.snc != null ? he.snc.Note : "",
                        });
                    };
                }
                else
                {
                    colh = new string[] { "Time", "Event", "System", "Body",                    //0
                                          "Ship", "Summary", "Description", "Detailed Info",    //4
                                          "Note", "Travel Dist", "Travel Time", "Travel Jumps", //8
                                          "Travelled MisJumps", "X", "Y", "Z",                  //12
                                          "JID", "EDSMID", "EDDBID" };                          //16

                    grd.GetLine += delegate(int r)
                    {
                        HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Cells[TravelHistoryColumns.HistoryTag].Tag;
                        return(new Object[] {
                            dataGridViewTravel.Rows[r].Cells[0].Value,
                            he.journalEntry.EventTypeStr,
                            (he.System != null) ? he.System.name : "Unknown",    // paranoia
                            he.WhereAmI,
                            he.ShipInformation != null ? he.ShipInformation.Name : "Unknown",
                            he.EventSummary,
                            he.EventDescription,
                            he.EventDetailedInfo,
                            dataGridViewTravel.Rows[r].Cells[4].Value,
                            he.isTravelling ? he.TravelledDistance.ToString("0.0") : "",
                            he.isTravelling ? he.TravelledSeconds.ToString() : "",
                            he.isTravelling ? he.Travelledjumps.ToStringInvariant() : "",
                            he.isTravelling ? he.TravelledMissingjump.ToStringInvariant() : "",
                            he.System.x,
                            he.System.y,
                            he.System.z,
                            he.Journalid,
                            he.System.id_edsm,
                            he.System.id_eddb,
                        });
                    };

                    if (frm.SelectedIndex == 2 || frm.SelectedIndex == 3) // export notes
                    {
                        grd.VerifyLine += delegate(int r)                 // second hook to reject line
                        {
                            HistoryEntry he = (HistoryEntry)dataGridViewTravel.Rows[r].Cells[TravelHistoryColumns.HistoryTag].Tag;
                            if (he.snc != null)
                            {
                                if (sysnotecache.Contains(he.snc))
                                {
                                    return(false);
                                }
                                else
                                {
                                    if (frm.SelectedIndex == 3)
                                    {
                                        sysnotecache.Add(he.snc);
                                    }
                                    return(true);
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        };
                    }
                }

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

                if (grd.WriteCSV(frm.Path))
                {
                    if (frm.AutoOpen)
                    {
                        System.Diagnostics.Process.Start(frm.Path);
                    }
                }
                else
                {
                    ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to write to " + frm.Path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Пример #6
0
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            if (dataGridViewEDSM.Rows.Count == 0)
            {
                ExtendedControls.MessageBoxTheme.Show(FindForm(), "No data to export", "Export EDSM", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "Export Current View" }, disablestartendtime: true);

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                if (frm.SelectedIndex == 0)
                {
                    BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                    grd.SetCSVDelimiter(frm.Comma);

                    grd.GetLineStatus += delegate(int r)
                    {
                        if (r < dataGridViewEDSM.Rows.Count)
                        {
                            return(BaseUtils.CSVWriteGrid.LineStatus.OK);
                        }
                        else
                        {
                            return(BaseUtils.CSVWriteGrid.LineStatus.EOF);
                        }
                    };

                    string[] colh = new string[] { "Star", "Distance", "X", "Y", "Z", "ID" };

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

                    grd.GetLine += delegate(int r)
                    {
                        DataGridViewRow rw  = dataGridViewEDSM.Rows[r];
                        ISystem         sys = rw.Tag as ISystem;
                        return(new Object[]
                        {
                            rw.Cells[0].Value, rw.Cells[1].Value, sys.X.ToString("0.#"), sys.Y.ToString("0.#"), sys.Z.ToString("0.#"), rw.Cells[3].Value
                        });
                    };

                    if (grd.WriteCSV(frm.Path))
                    {
                        if (frm.AutoOpen)
                        {
                            System.Diagnostics.Process.Start(frm.Path);
                        }
                    }
                    else
                    {
                        ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to write to " + frm.Path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
Пример #7
0
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            if (dataGridViewBookMarks.Rows.Count == 0)
            {
                ExtendedControls.MessageBoxTheme.Show(FindForm(), "No data to export", "Export EDSM", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "Export Current View" }, disablestartendtime: true);

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                if (frm.SelectedIndex == 0)
                {
                    string path = frm.Path;               //string path = "C:\\code\\f.csv"; // debug

                    BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                    grd.SetCSVDelimiter(frm.Comma);

                    List <string> colh = new List <string>();
                    colh.AddRange(new string[] { "Type", "Time", "System/Region", "Note", "X", "Y", "Z", "Planet", "Name", "Comment", "Lat", "Long" });

                    grd.GetHeader += delegate(int c)
                    {
                        return((c < colh.Count && frm.IncludeHeader) ? colh[c] : null);
                    };

                    int bkrowno = 0;
                    IEnumerator <Tuple <PlanetMarks.Planet, PlanetMarks.Location> > planetloc = null;

                    System.Diagnostics.Debug.WriteLine("Rows " + dataGridViewBookMarks.Rows.Count);

                    grd.GetLineStatus += delegate(int r)
                    {
                        return(bkrowno < dataGridViewBookMarks.Rows.Count ? BaseUtils.CSVWriteGrid.LineStatus.OK : BaseUtils.CSVWriteGrid.LineStatus.EOF);
                    };

                    grd.GetLine += delegate(int r)
                    {
                        DataGridViewRow rw             = dataGridViewBookMarks.Rows[bkrowno];
                        BookmarkClass   bk             = rw.Tag as BookmarkClass;
                        bool            firstplanetrow = false;

                        if (planetloc == null && bk.hasPlanetaryMarks)          // if not iterating planets, but it has one, iterate
                        {
                            planetloc = bk.PlanetaryMarks.GetEnumerator();
                            planetloc.MoveNext();       // move to first
                            firstplanetrow = true;
                        }

                        List <Object> retrow = new List <Object>
                        {
                            bk.isRegion ? "Region" : "System",
                                      bk.Time.ToStringYearFirst(),
                                      bk.isRegion ? bk.Heading : bk.StarName,
                                      bk.Note,
                                      bk.x.ToString("0.##"),
                            bk.y.ToString("0.##"),
                            bk.z.ToString("0.##"),
                        };

                        System.Diagnostics.Debug.WriteLine("Export system " + bkrowno + " " + bk.StarName);

                        if (planetloc != null)
                        {
                            var           plloc     = planetloc.Current;
                            List <Object> planetrow = new List <Object>
                            {
                                plloc.Item1.Name,
                                plloc.Item2.Name,
                                plloc.Item2.Comment,
                                plloc.Item2.IsWholePlanetBookmark ? "" : plloc.Item2.Latitude.ToString("0.##"),
                                plloc.Item2.IsWholePlanetBookmark ? "" : plloc.Item2.Longitude.ToString("0.##"),
                            };

                            if (!firstplanetrow)
                            {
                                retrow = new List <object>()
                                {
                                    "", "", "", "", "", "", ""
                                };
                            }

                            retrow.AddRange(planetrow);
                        }

                        if (planetloc == null || planetloc.MoveNext() == false)
                        {
                            planetloc = null;
                            bkrowno++;
                        }

                        return(retrow.ToArray());
                    };

                    if (grd.WriteCSV(path))
                    {
                        if (frm.AutoOpen)
                        {
                            System.Diagnostics.Process.Start(path);
                        }
                    }
                    else
                    {
                        ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to write to " + path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
Пример #8
0
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "Export Current View" });

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                if (frm.SelectedIndex == 0)
                {
                    // 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" };

                    BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                    grd.SetCSVDelimiter(frm.Comma);
                    grd.GetLineStatus += delegate(int r)
                    {
                        if (r < dataGridViewStarList.Rows.Count)
                        {
                            List <HistoryEntry> syslist = dataGridViewStarList.Rows[r].Tag as List <HistoryEntry>;
                            HistoryEntry        he      = syslist[0];

                            return((dataGridViewStarList.Rows[r].Visible &&
                                    he.EventTimeLocal.CompareTo(frm.StartTime) >= 0 &&
                                    he.EventTimeLocal.CompareTo(frm.EndTime) <= 0) ? BaseUtils.CSVWriteGrid.LineStatus.OK : BaseUtils.CSVWriteGrid.LineStatus.Skip);
                        }
                        else
                        {
                            return(BaseUtils.CSVWriteGrid.LineStatus.EOF);
                        }
                    };
                    grd.GetLine += delegate(int r)
                    {
                        List <HistoryEntry> syslist = dataGridViewStarList.Rows[r].Tag as List <HistoryEntry>;
                        HistoryEntry        he      = syslist[0];
                        DataGridViewRow     rw      = dataGridViewStarList.Rows[r];

                        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(), ", ");
                            }
                        }

                        he.journalEntry.FillInformation(out string EventDescription, out string EventDetailedInfo);

                        return(new Object[] {
                            rw.Cells[0].Value,
                            rw.Cells[1].Value,
                            rw.Cells[2].Value,
                            rw.Cells[3].Value,
                            tlist,
                            he.WhereAmI,
                            he.ShipInformation != null ? he.ShipInformation.Name : "Unknown",
                            EventDescription,
                            EventDetailedInfo,
                            he.isTravelling ? he.TravelledDistance.ToString("0.0") : "",
                            he.isTravelling ? he.TravelledSeconds.ToString() : "",
                            he.isTravelling ? he.Travelledjumps.ToStringInvariant() : "",
                            he.isTravelling ? he.TravelledMissingjump.ToStringInvariant() : "",
                        });
                    };

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

                    if (grd.WriteCSV(frm.Path))
                    {
                        if (frm.AutoOpen)
                        {
                            System.Diagnostics.Process.Start(frm.Path);
                        }
                    }
                    else
                    {
                        ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to write to " + frm.Path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
Пример #9
0
        public void Excel(int columnsout)
        {
            if (Rows.Count == 0)
            {
                ExtendedControls.MessageBoxTheme.Show(FindForm(), "No data to export", "Export EDSM", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "Export Current View" }, disablestartendtime: true);

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                if (frm.SelectedIndex == 0)
                {
                    BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                    grd.SetCSVDelimiter(frm.Comma);

                    grd.GetLineStatus += delegate(int r)
                    {
                        if (r < Rows.Count)
                        {
                            return(BaseUtils.CSVWriteGrid.LineStatus.OK);
                        }
                        else
                        {
                            return(BaseUtils.CSVWriteGrid.LineStatus.EOF);
                        }
                    };

                    List <string> colh = new List <string>();
                    for (int i = 0; i < columnsout; i++)
                    {
                        colh.Add(Columns[i].HeaderText);
                    }
                    colh.AddRange(new string[] { "X", "Y", "Z", "ID" });

                    grd.GetHeader += delegate(int c)
                    {
                        return((c < colh.Count && frm.IncludeHeader) ? colh[c] : null);
                    };

                    grd.GetLine += delegate(int r)
                    {
                        DataGridViewRow rw   = Rows[r];
                        ISystem         sys  = SysFrom(rw.Tag);
                        List <Object>   data = new List <object>();
                        for (int i = 0; i < columnsout; i++)
                        {
                            data.Add(rw.Cells[i].Value);
                        }

                        data.Add(sys.X.ToString("0.#"));
                        data.Add(sys.Y.ToString("0.#"));
                        data.Add(sys.Z.ToString("0.#"));
                        data.Add(sys.EDSMID);

                        return(data.ToArray());
                    };

                    if (grd.WriteCSV(frm.Path))
                    {
                        if (frm.AutoOpen)
                        {
                            System.Diagnostics.Process.Start(frm.Path);
                        }
                    }
                    else
                    {
                        ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to write to " + frm.Path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }