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.ExportAsJournals) { try { using (StreamWriter writer = new StreamWriter(frm.Path)) { foreach (DataGridViewRow dgvr in dataGridViewJournal.Rows) { HistoryEntry he = dgvr.Cells[JournalHistoryColumns.HistoryTag].Tag as HistoryEntry; if (dgvr.Visible && he.EventTimeLocal.CompareTo(frm.StartTime) >= 0 && he.EventTimeLocal.CompareTo(frm.EndTime) <= 0) { string forExport = he.journalEntry.GetJson()?.ToString().Replace("\r\n", ""); if (forExport != null) { forExport = System.Text.RegularExpressions.Regex.Replace(forExport, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); writer.Write(forExport); writer.WriteLine(); } } } } if (frm.AutoOpen) { try { System.Diagnostics.Process.Start(frm.Path); } catch { ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to open " + frm.Path, "Warning".Tx(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch { ExtendedControls.MessageBoxTheme.Show(this.FindForm(), "Failed to write to " + frm.Path, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { 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) { DataGridViewRow rw = dataGridViewJournal.Rows[r]; 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); }; grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm()); } } } }
private void extButtonExcel_Click(object sender, EventArgs e) { Forms.ExportForm frm = new Forms.ExportForm(); frm.Init(new string[] { "Export Current View", "All" }, disablestartendtime: true); if (frm.ShowDialog(this.FindForm()) == DialogResult.OK) { BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid(); grd.SetCSVDelimiter(frm.Comma); grd.GetLineHeader += delegate(int c) { if (c == 0) { return new string[] { "Time", "System", "Body", "Note", "Tags" } } ; else { return(null); } }; if (frm.SelectedIndex == 1) { List <CaptainsLogClass> logs = GlobalCaptainsLogList.Instance.LogEntries; int i = 0; grd.GetLine += delegate(int r) { while (i < logs.Count) { CaptainsLogClass ent = logs[i++]; if (ent.Commander == EDCommander.CurrentCmdrID) { return(new object[] { EDDConfig.Instance.ConvertTimeToSelectedFromUTC(ent.TimeUTC), ent.SystemName, ent.BodyName, ent.Note, ent.Tags }); } } return(null); }; } else { grd.GetLine += delegate(int r) { if (r < dataGridView.RowCount) { DataGridViewRow rw = dataGridView.Rows[r]; CaptainsLogClass ent = rw.Tag as CaptainsLogClass; return(new Object[] { rw.Cells[0].Value, rw.Cells[1].Value, rw.Cells[2].Value, rw.Cells[3].Value, ent.Tags }); } return(null); }; } grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm()); } }
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); } } } }
private void toolStripButtonExport_Click(object sender, EventArgs e) { var rt = new SavedRouteClass(); SaveGridIntoRoute(rt); if (rt.Systems.Count < 1) { ExtendedControls.MessageBoxTheme.Show(FindForm(), "There is no route to export ".T(EDTx.UserControlExpedition_NoRouteExport), "Warning".T(EDTx.Warning), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Forms.ExportForm frm = new Forms.ExportForm(); frm.Init(new string[] { "Route", "Grid" }, disablestartendtime: true, outputext: new string[] { "Text File|*.txt", "CSV export| *.csv" }); if (frm.ShowDialog(FindForm()) == DialogResult.OK) { if (frm.SelectedIndex == 0) // old route export { try { using (StreamWriter writer = new StreamWriter(frm.Path, false)) { foreach (var sysname in rt.Systems) { if (!string.IsNullOrWhiteSpace(sysname)) { writer.WriteLine(sysname); } } } if (frm.AutoOpen) { try { System.Diagnostics.Process.Start(frm.Path); } catch { ExtendedControls.MessageBoxTheme.Show(FindForm(), "Failed to open " + frm.Path, "Warning".Tx(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch { ExtendedControls.MessageBoxTheme.Show(FindForm(), $"Problem exporting route. Is file {frm.Path} already open?", "Export route", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid(); grd.SetCSVDelimiter(frm.Comma); grd.GetLineStatus += delegate(int r) { if (r < dataGridView.Rows.Count) { return(BaseUtils.CSVWriteGrid.LineStatus.OK); } else { return(BaseUtils.CSVWriteGrid.LineStatus.EOF); } }; grd.GetLine += delegate(int r) { DataGridViewRow rw = dataGridView.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 }); }; grd.GetHeader += delegate(int c) { return((c < 6 && frm.IncludeHeader) ? dataGridView.Columns[c].HeaderText : null); }; grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm()); } } }
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", "Scan Value", "Unused", "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) { HistoryEntry he = dataGridViewStarList.Rows[r].Tag as HistoryEntry; return((dataGridViewStarList.Rows[r].Visible && he.EventTimeUTC.CompareTo(frm.StartTimeUTC) >= 0 && he.EventTimeUTC.CompareTo(frm.EndTimeUTC) <= 0) ? BaseUtils.CSVWriteGrid.LineStatus.OK : BaseUtils.CSVWriteGrid.LineStatus.Skip); } else { return(BaseUtils.CSVWriteGrid.LineStatus.EOF); } }; grd.GetLine += delegate(int r) { HistoryEntry he = dataGridViewStarList.Rows[r].Tag as HistoryEntry; DataGridViewRow rw = dataGridViewStarList.Rows[r]; he.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, rw.Cells[4].Value, "", 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.ToString() : "", he.isTravelling ? he.TravelledMissingjump.ToString() : "", }); }; grd.GetHeader += delegate(int c) { return((c < colh.Length && frm.IncludeHeader) ? colh[c] : null); }; grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm()); } } }
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(), ", "); } } 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", he.EventDescription, he.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); } } } }
private void buttonExtExcel_Click(object sender, EventArgs e) { 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); var found = ReadHistory(out int prospectorsused, out int collectorsused, out int asteroidscracked, out int prospected, out int[] content); grd.GetPreHeader += delegate(int r) { if (r == 0) { return new Object[] { "Limpets left ", limpetsleftdisplay, "Prospectors Fired", prospectorsused, "Collectors Deployed", collectorsused } } ; else if (r == 1) { return(new object[0]); } else { return(null); } }; grd.GetSetsPad = delegate(int s, int r) { return(r < 2 ? new object[0] : null); }; { grd.GetSetsHeader.Add(delegate(int s, int r) { if (r == 0) { return new object[] { "", "Ref.", "Coll.", "Pros", "Ratio%", "Avg%", "Min%", "Max%", "M.Load", "High Ct", "Med Ct", "Low Ct", "Discv" } } ; else { return(null); } }); grd.GetSetsData.Add(delegate(int s, int r) { if (r == 0) { return(new object[] { "", "", "", prospected.ToString("N0"), "", "", "", "", "", content[0].ToString("N0"), content[1].ToString("N0"), content[2].ToString("N0") }); } else if (r <= found.Count) { MaterialsFound f = found[r - 1]; return(new object[] { f.friendlyname, f.amountrefined, f.amountcollected - f.amountdiscarded, f.prospectednoasteroids > 0 ? f.prospectednoasteroids.ToString("N0") : "", f.prospectednoasteroids > 0 ? (100.0 * (double)f.prospectednoasteroids / prospected).ToString("N1") : "", f.prospectednoasteroids > 0 ? f.prospectedamounts.Average().ToString("N1") : "", f.prospectednoasteroids > 0 ? f.prospectedamounts.Min().ToString("N1") : "", f.prospectednoasteroids > 0 ? f.prospectedamounts.Max().ToString("N1") : "", f.motherloadasteroids > 0 ? f.motherloadasteroids.ToString("N0") : "", f.prospectednoasteroids > 0 ? f.content[0].ToString("N0") :"", f.prospectednoasteroids > 0 ? f.content[1].ToString("N0") : "", f.prospectednoasteroids > 0 ? f.content[2].ToString("N0") : "", f.discovered ? "*" : "" }); } else { return(null); } }); } var prosmat = found.Where(x => x.prospectednoasteroids > 0).ToList(); { grd.GetSetsHeader.Add(delegate(int s, int r) { if (r == 0) { Object[] ret = new object[prosmat.Count + 1]; ret[0] = "CDFb"; for (int i = 0; i < prosmat.Count; i++) { ret[i + 1] = prosmat[i].friendlyname; } return(ret); } else { return(null); } }); grd.GetSetsData.Add(delegate(int s, int r) { if (r < CFDbMax) { Object[] ret = new object[prosmat.Count + 1]; int percent = r; ret[0] = percent.ToString("N0") + "%"; for (int m = 0; m < prosmat.Count; m++) { if (prosmat[m].prospectednoasteroids > 0) { ret[m + 1] = ((double)prosmat[m].prospectedamounts.Count(x => x >= percent) / prosmat[m].prospectednoasteroids * 100.0).ToString("N1"); } else { ret[m + 1] = ""; } } return(ret); } else { return(null); } }); } { const int precol = 4; grd.GetSetsHeader.Add(delegate(int s, int r) { if (r == 0) { Object[] ret = new object[found.Count + precol]; ret[0] = "Event"; ret[1] = "Time"; ret[2] = "Content"; ret[3] = "Motherload"; for (int i = 0; i < prosmat.Count; i++) { ret[i + precol] = prosmat[i].friendlyname; } return(ret); } else { return(null); } }); var proslist = curlist.Where(x => x.EntryType == JournalTypeEnum.ProspectedAsteroid).ToList(); grd.GetSetsData.Add(delegate(int s, int r) { if (r < proslist.Count) { var jp = proslist[r].journalEntry as JournalProspectedAsteroid; Object[] ret = new object[prosmat.Count + precol]; ret[0] = (r + 1).ToString("N0"); ret[1] = jp.EventTimeUTC.ToStringZulu(); ret[2] = jp.Content.ToString(); ret[3] = MaterialCommodityData.GetByFDName(jp.MotherlodeMaterial)?.Name ?? jp.MotherlodeMaterial; for (int m = 0; m < prosmat.Count; m++) { int mi = Array.FindIndex(jp.Materials, x => x.Name == prosmat[m].matnamefd2); if (mi >= 0) { ret[m + precol] = jp.Materials[mi].Proportion.ToString("N2"); } else { ret[m + precol] = ""; } } return(ret); } else { return(null); } }); } grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm()); } }
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.EDSMID, he.System.EDDBID, }); }; 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); } } }