コード例 #1
0
        private void dataGridViewDistances_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
        {
            if (e.Column.Index == 1)
            {
                double?v1 = DistanceParser.ParseInterstellarDistance(e.CellValue1?.ToString());
                double?v2 = DistanceParser.ParseInterstellarDistance(e.CellValue2?.ToString());

                if (v1 != null || v2 != null)
                {
                    if (v1 == null)
                    {
                        e.SortResult = 1;
                    }
                    else if (v2 == null)
                    {
                        e.SortResult = -1;
                    }
                    else
                    {
                        e.SortResult = v1.Value.CompareTo(v2.Value);
                    }

                    e.Handled = true;
                }
            }
        }
コード例 #2
0
        private void dataGridViewDistances_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 0)
                {
                    var value = e.FormattedValue.ToString();
                    var cell  = dataGridViewDistances[e.ColumnIndex, e.RowIndex];

                    if (value == "" && (cell.Value == null || cell.Value.ToString() == ""))
                    {
                        return;
                    }

                    var system         = SystemClassDB.GetSystem(value);
                    var enteredSystems = GetEnteredSystems();
                    if (cell.Value != null)
                    {
                        enteredSystems.RemoveAll(s => s.name == cell.Value.ToString());
                    }

                    if (system == null || (enteredSystems.Contains(system)))
                    {
                        return;
                    }
                }

                if (e.ColumnIndex == 1)
                {
                    var value = e.FormattedValue.ToString().Trim();
                    if (value == "")
                    {
                        dataGridViewDistances.Rows[e.RowIndex].ErrorText = null;
                        return;
                    }

                    var parsed = DistanceParser.ParseInterstellarDistance(value);
                    if (parsed.HasValue)
                    {
                        dataGridViewDistances.Rows[e.RowIndex].ErrorText = null;
                    }
                    else
                    {
                        e.Cancel = true;
                        dataGridViewDistances.Rows[e.RowIndex].ErrorText = "Invalid number";
                    }
                }
            }
            catch (Exception ex)
            {
                this.BeginInvoke(new MethodInvoker(() =>
                {
                    LogTextHighlight("Exception:" + ex.Message);
                    LogText(ex.StackTrace);
                }));
            }
        }
コード例 #3
0
        private void dataGridViewDistances_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                var cell  = dataGridViewDistances[e.ColumnIndex, e.RowIndex];
                var value = cell.Value as string;
                if (value == null)
                {
                    return;
                }

                var enteredSystems = GetEnteredSystems();

                if (enteredSystems.Count > e.RowIndex)                 //don't do the below if we're entering something that's not in enteredSystems yet (we need to set cell.tag lower down the first time through here)
                {
                    if (value.Equals(enteredSystems[e.RowIndex].name)) // If we change a row to same value as before dont do anything from doubleclick or pastinf same new for example
                    {
                        return;
                    }
                }
                if (enteredSystems.Where(es => es.name == value).Count() > 0)
                {
                    LogTextHighlight("Duplicate system entry is not allowed" + Environment.NewLine);
                    this.BeginInvoke(new MethodInvoker(() =>
                    {
                        dataGridViewDistances.Rows.Remove(dataGridViewDistances.Rows[e.RowIndex]);
                    }));
                    return;
                }

                var system = getSystemForTrilateration(value);
                if (system == null)
                {
                    this.BeginInvoke(new MethodInvoker(() =>
                    {
                        dataGridViewDistances.Rows.Remove(dataGridViewDistances.Rows[e.RowIndex]);
                    }));
                    return;
                }
                newSystemAdded(cell, system);
            }
            else if (e.ColumnIndex == 1)
            {
                if (dataGridViewDistances[1, e.RowIndex].Value != null && !string.IsNullOrEmpty(dataGridViewDistances[1, e.RowIndex].Value.ToString().Trim()))
                {
                    var value          = dataGridViewDistances[1, e.RowIndex].Value.ToString().Trim();
                    var parsedDistance = DistanceParser.ParseInterstellarDistance(value);
                    if (parsedDistance.HasValue)
                    {
                        dataGridViewDistances[1, e.RowIndex].Value = parsedDistance.Value.ToString("F2");
                    }
                }
            }
            /* skip to the next editable cell */
            skipReadOnlyCells = true;
        }
コード例 #4
0
        private void SubmitToEDSM()
        {
            try
            {
                edsm.apiKey        = EDCommander.Current.APIKey;
                edsm.commanderName = EDCommander.Current.EdsmName;

                var travelHistoryControl = _discoveryForm.TravelControl;
                if (string.IsNullOrEmpty(edsm.commanderName))
                {
                    string commanderName = EDCommander.Current.EdsmName;

                    if (string.IsNullOrEmpty(commanderName))
                    {
                        this.BeginInvoke(new MethodInvoker(() =>
                        {
                            ExtendedControls.MessageBoxTheme.Show("Please enter commander name before submitting the system!");
                            UnfreezeTrilaterationUI();
                        }));
                        return;
                    }
                    edsm.commanderName = commanderName;
                }
                var distances = new Dictionary <string, double>();
                for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
                {
                    var systemCell   = dataGridViewDistances[0, i];
                    var distanceCell = dataGridViewDistances[1, i];
                    if (systemCell.Value != null && distanceCell.Value != null)
                    {
                        var system = systemCell.Value.ToString();

                        var value          = distanceCell.Value.ToString().Trim();
                        var parsedDistance = DistanceParser.ParseInterstellarDistance(value);

                        if (parsedDistance.HasValue)
                        {
                            // can over-ride drop down now if it's a real system so you could add duplicates if you wanted (even once I've figured out issue #81 which makes it easy if not likely...)
                            if (!distances.Keys.Contains(system))
                            {
                                distances.Add(system, parsedDistance.Value);
                            }
                        }
                    }
                }

                bool trilatOk = false;
                bool respOk   = true;
                List <KeyValuePair <string, double> > distlist = distances.ToList();

                for (int i = 0; i < distances.Count; i += 20)
                {
                    var dists = new Dictionary <string, double>();
                    for (int j = i; j < i + 20 && j < distances.Count; j++)
                    {
                        dists[distlist[j].Key] = distlist[j].Value;
                    }

                    var responseM = edsm.SubmitDistances(edsm.commanderName, TargetSystem.name, dists);

                    Console.WriteLine(responseM);

                    string infoM;
                    bool   trilaterationOkM;
                    var    responseOkM = edsm.ShowDistanceResponse(responseM, out infoM, out trilaterationOkM);

                    if (trilaterationOkM)
                    {
                        trilatOk = true;
                    }

                    if (!responseOkM)
                    {
                        respOk = false;
                    }

                    Console.WriteLine(infoM);
                }

                BeginInvoke((MethodInvoker) delegate
                {
                    UnfreezeTrilaterationUI();

                    if (respOk && trilatOk)
                    {
                        LogTextSuccess("EDSM submission succeeded, trilateration successful." + Environment.NewLine);
                        _discoveryForm.RefreshHistoryAsync();
                        checkForUnknownSystemsNowKnown();
                    }
                    else if (respOk)
                    {
                        LogTextHighlight("EDSM submission succeeded, but trilateration failed. Try adding more distances." + Environment.NewLine);
                    }
                    else
                    {
                        LogTextHighlight("EDSM submission failed." + Environment.NewLine);
                    }
                });
            }
            catch (Exception ex)
            {
                this.BeginInvoke(new MethodInvoker(() =>
                {
                    LogTextHighlight("SubmitToEDSM Exception:" + ex.Message);
                    LogText(ex.StackTrace);
                }));
            }
        }