public bool FromJson(JObject jo) { try { id = JSONHelper.GetLong(jo["id"]); name = JSONHelper.GetStringDef(jo["name"]); faction = JSONHelper.GetStringDef(jo["faction"]); jcommodities = (JArray)jo["commodities"]; if (jcommodities != null) { commodities = new List <CCommodities>(); foreach (JObject commodity in jcommodities) { CCommodities com = new CCommodities(commodity); commodities.Add(com); } } return(true); } catch { return(false); } }
public bool FromJson(JObject jo) { try { id = jo["id"].Long(); name = jo["name"].Str(); outpostType = jo["outpostType"].Str(); jcommodities = (JArray)jo["commodities"]; if (jcommodities != null) { commodities = new List <CCommodities>(); foreach (JObject commodity in jcommodities) { CCommodities com = new CCommodities(commodity); commodities.Add(com); } } return(true); } catch { return(false); } }
private void Display() { Stopwatch swp = new Stopwatch(); swp.Start(); DataGridViewColumn sortcol = dataGridViewMarketData.SortedColumn != null ? dataGridViewMarketData.SortedColumn : dataGridViewMarketData.Columns[0]; SortOrder sortorder = dataGridViewMarketData.SortOrder; int firstdisplayed = dataGridViewMarketData.FirstDisplayedScrollingRowIndex; string commodity = (dataGridViewMarketData.CurrentRow != null) ? (string)dataGridViewMarketData.CurrentRow.Cells[1].Value : null; int currentoffset = (dataGridViewMarketData.CurrentRow != null) ? dataGridViewMarketData.CurrentRow.Index - firstdisplayed : 0; dataGridViewMarketData.Rows.Clear(); labelLocation.Text = "No Data"; toolTip.SetToolTip(labelLocation, null); HistoryEntry left = (eddmd_left != null) ? eddmd_left : last_eddmd; // if we have a selected left, use it, else use the last eddmd HistoryEntry cargo = (eddmd_left != null) ? eddmd_left : last_he; // if we have a selected left, use it, else use the last he if (left != null) // we know it has a journal entry of EDD commodity.. { System.Diagnostics.Debug.WriteLine(Environment.NewLine + "From " + current_displayed?.WhereAmI + " to " + left.WhereAmI); JournalEDDCommodityPrices ecp = left.journalEntry as JournalEDDCommodityPrices; List <CCommodities> list = ecp.Commodities; System.Diagnostics.Debug.WriteLine("Test Right " + eddmd_right?.WhereAmI + " vs " + left.WhereAmI); if (eddmd_right != null && !Object.ReferenceEquals(eddmd_right, left)) // if got a comparision, and not the same data.. { if (checkBoxAutoSwap.Checked && left.System.name.Equals(eddmd_right.System.name) && // if left system being displayed is same as right system left.WhereAmI.Equals(eddmd_right.WhereAmI)) // that means we can autoswap comparisions around { System.Diagnostics.Debug.WriteLine("Arrived at last left station, repick " + current_displayed.WhereAmI + " as comparision"); int index = comboboxentries.FindIndex(x => x.System.name.Equals(current_displayed.System.name) && x.WhereAmI.Equals(current_displayed.WhereAmI)); if (index >= 0) // if found it, swap to last instance of system { comboBoxCustomTo.Enabled = false; comboBoxCustomTo.SelectedIndex = index + 1; comboBoxCustomTo.Enabled = true; eddmd_right = comboboxentries[index]; System.Diagnostics.Debug.WriteLine("Right is now " + eddmd_right.WhereAmI); } } System.Diagnostics.Debug.WriteLine("Right " + eddmd_right.System.name + " " + eddmd_right.WhereAmI); list = CCommodities.Merge(list, ((JournalEDDCommodityPrices)eddmd_right.journalEntry).Commodities, eddmd_right.WhereAmI); } List <MaterialCommodities> mclist = cargo.MaterialCommodity.Sort(true); // stuff we have.. commodities only List <MaterialCommodities> notfound = new List <MaterialCommodities>(); foreach (MaterialCommodities m in mclist) { int index = list.FindIndex(x => x.name.EqualsAlphaNumOnlyNoCase(m.name)); // try and match, remove any spaces/_ and lower case it for matching if (index >= 0) { list[index].CargoCarried = m.count; // found it, set cargo count.. } else { notfound.Add(m); // not found, add to list for bottom } } FontFamily ff = new FontFamily(this.Font.Name); bool buyonly = checkBoxBuyOnly.Checked; foreach (CCommodities c in list) { if (!buyonly || (c.buyPrice > 0 || c.ComparisionBuy)) { object[] rowobj = { c.type, c.name, c.sellPrice > 0 ? c.sellPrice.ToString() : "", c.buyPrice > 0 ? c.buyPrice.ToString() : "", c.CargoCarried, c.demand > 1 ? c.demand.ToString() : "", c.stock > 0 ? c.stock.ToString() : "", c.meanPrice > 0 ? c.meanPrice.ToString() : "", c.ComparisionLR, c.ComparisionRL, }; int rowno = dataGridViewMarketData.Rows.Add(rowobj); if (c.ComparisionRightOnly && ff != null && ff.IsStyleAvailable(FontStyle.Italic)) { for (int i = 1; i < dataGridViewMarketData.Columns.Count; i++) { dataGridViewMarketData.Rows[rowno].Cells[i].Style.Font = new Font(this.Font, FontStyle.Italic); } } dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText = dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = c.ToString(); } } foreach (MaterialCommodities m in notfound) { if (m.count > 0) { object[] rowobj = { m.type, m.name, "", "", m.count, "", "", "", "", "", }; int rowno = dataGridViewMarketData.Rows.Add(rowobj); dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText = dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = "Cargo only, no market data on this item"; } } current_displayed = left; labelLocation.Text = left.System.name + ":" + left.WhereAmI; string r = "Recorded at " + ((EDDiscoveryForm.EDDConfig.DisplayUTC) ? left.EventTimeUTC.ToString() : left.EventTimeLocal.ToString()); toolTip.SetToolTip(labelLocation, r); } dataGridViewMarketData.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending); dataGridViewMarketData.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder; if (commodity != null) { foreach (DataGridViewRow rw in dataGridViewMarketData.Rows) { string v = (string)rw.Cells[1].Value; if (v.Equals(commodity)) // Find the commodity, and set it to the same relative position as before. { dataGridViewMarketData.CurrentCell = dataGridViewMarketData.Rows[rw.Index].Cells[1]; dataGridViewMarketData.FirstDisplayedScrollingRowIndex = Math.Max(rw.Index - currentoffset, 0); break; } } } System.Diagnostics.Debug.WriteLine("Stop watch" + swp.ElapsedMilliseconds); }
public void Display() { DataGridViewColumn sortcol = dataGridViewMarketData.SortedColumn != null ? dataGridViewMarketData.SortedColumn : dataGridViewMarketData.Columns[0]; SortOrder sortorder = dataGridViewMarketData.SortOrder; dataGridViewMarketData.Rows.Clear(); labelLocation.Text = "No Data"; toolTip1.SetToolTip(labelLocation, null); HistoryEntry left = (eddmd_left != null) ? eddmd_left : last_eddmd; // if we have a selected left, use it, else use the last eddmd HistoryEntry cargo = (eddmd_left != null) ? eddmd_left : last_he; // if we have a selected left, use it, else use the last he if (left != null) // we know it has a journal entry of EDD commodity.. { JournalEDDCommodityPrices ecp = left.journalEntry as JournalEDDCommodityPrices; List <CCommodities> list = ecp.Commodities; if (eddmd_right != null && !Object.ReferenceEquals(eddmd_right, left)) // if got a comparision, and not the same { list = CCommodities.Merge(list, ((JournalEDDCommodityPrices)eddmd_right.journalEntry).Commodities, eddmd_right.WhereAmI); } List <MaterialCommodities> mclist = cargo.MaterialCommodity.Sort(true); // stuff we have.. commodities only List <MaterialCommodities> notfound = new List <MaterialCommodities>(); foreach (MaterialCommodities m in mclist) { int index = list.FindIndex(x => x.name.EqualsAlphaNumOnlyNoCase(m.name)); // try and match, remove any spaces/_ and lower case it for matching if (index >= 0) { list[index].CargoCarried = m.count; // found it, set cargo count.. } else { notfound.Add(m); // not found, add to list for bottom } } FontFamily ff = new FontFamily(this.Font.Name); bool buyonly = checkBoxBuyOnly.Checked; foreach (CCommodities c in list) { if (!buyonly || (c.buyPrice > 0 || c.ComparisionBuy)) { object[] rowobj = { c.type, c.name, c.sellPrice > 0 ? c.sellPrice.ToString() : "", c.buyPrice > 0 ? c.buyPrice.ToString() : "", c.CargoCarried, c.demand > 1 ? c.demand.ToString() : "", c.stock > 0 ? c.stock.ToString() : "", c.meanPrice > 0 ? c.meanPrice.ToString() : "", c.ComparisionLR, c.ComparisionRL, }; int rowno = dataGridViewMarketData.Rows.Add(rowobj); if (c.ComparisionRightOnly && ff != null && ff.IsStyleAvailable(FontStyle.Italic)) { for (int i = 1; i < dataGridViewMarketData.Columns.Count; i++) { dataGridViewMarketData.Rows[rowno].Cells[i].Style.Font = new Font(this.Font, FontStyle.Italic); } } dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText = dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = c.ToString(); } } foreach (MaterialCommodities m in notfound) { if (m.count > 0) { object[] rowobj = { m.type, m.name, "", "", m.count, "", "", "", "", "", }; int rowno = dataGridViewMarketData.Rows.Add(rowobj); dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText = dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = "Cargo only, no market data on this item"; } } labelLocation.Text = left.System.name + ":" + left.WhereAmI; string r = "Recorded at " + ((EDDiscoveryForm.EDDConfig.DisplayUTC) ? left.EventTimeUTC.ToString() : left.EventTimeLocal.ToString()); toolTip1.SetToolTip(labelLocation, r); } dataGridViewMarketData.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending); dataGridViewMarketData.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder; }