コード例 #1
0
        private void lineReceived(object obj, LineReceivedEventArgs ea)
        {
            string line = ea.line.TrimEnd('\r', '\n');

            this.Invoke((MethodInvoker) delegate {
                tbCluster.AppendText(line + Environment.NewLine);
            });
            string country = "";
            Match  mtchDX  = rgxDX.Match(line);

            if (mtchDX.Success)
            {
                string cs = mtchDX.Groups[3].Value;
                if (prefixes[1].ContainsKey(cs))
                {
                    country = prefixes[1][cs];
                }
                else
                {
                    for (int c = 1; c <= cs.Length; c++)
                    {
                        if (prefixes[0].ContainsKey(cs.Substring(0, c)))
                        {
                            country = prefixes[0][cs.Substring(0, c)];
                        }
                    }
                }
                double freq  = Convert.ToDouble(mtchDX.Groups[2].Value.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
                string mode  = "";
                string textU = mtchDX.Groups[4].Value.ToUpper();
                foreach (Mode modeI in DxConsts.Modes)
                {
                    if (!modeI.isCategory)
                    {
                        mode = testMode(textU, modeI);
                        if (mode != "")
                        {
                            break;
                        }
                    }
                }
                if (mode == "")
                {
                    mode = getDiap(modes, freq);
                }
                if (mode != "" && modesDict.ContainsKey(mode) && modesDict[mode].dxGridViewName != null)
                {
                    mode = modesDict[mode].dxGridViewName;
                }
                string band = getDiap(DxConsts.Bands, freq);
                try
                {
                    if (!closed)
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            if (!closed)
                            {
                                lock (dxDataLock)
                                {
                                    int pos     = dgvDxData.FirstDisplayedScrollingRowIndex;
                                    DxItem prev = blDxData.FirstOrDefault(x => x.cs == cs && (freq - x.nFreq < 0.3 && x.nFreq - freq < 0.3));
                                    if (prev != null)
                                    {
                                        int idx = blDxData.IndexOf(prev);
                                        blDxData.RemoveAt(idx);
                                        dgvDxData.ClearSelection();
                                        dgvDxData.CurrentCell = null;
                                        for (int c = idx; c >= 0; c--)
                                        {
                                            if (c < dgvDxData.RowCount)
                                            {
                                                dgvDxDrawRow(c);
                                            }
                                        }
                                    }
                                    blDxData.Insert(0, new DxItem
                                    {
                                        cs     = cs,
                                        l      = lotw1.Contains(cs) ? "+" : "",
                                        prefix = country,
                                        de     = mtchDX.Groups[1].Value,
                                        freq   = mtchDX.Groups[2].Value,
                                        mode   = mode,
                                        band   = band,
                                        text   = mtchDX.Groups[4].Value,
                                        time   = mtchDX.Groups[5].Value,
                                        dt     = DateTime.Now,
                                        nFreq  = freq
                                    });
                                    List <DxItem> old = blDxData.Where(x => x.dt < DateTime.Now.Subtract(new TimeSpan(0, 30, 0))).ToList();
                                    if (old.Count > 0)
                                    {
                                        old.ForEach(x => blDxData.Remove(x));
                                    }
                                    dgvDxData.ClearSelection();
                                    dgvDxData.CurrentCell = null;
                                    dgvDxDrawRow(0);
                                    int nPos = pos;
                                    if (nPos > dgvDxData.RowCount)
                                    {
                                        nPos--;
                                    }
                                    while (nPos > -1 && !dgvDxData.Rows[nPos].Visible)
                                    {
                                        nPos--;
                                    }
                                    if (nPos > -1)
                                    {
                                        dgvDxData.FirstDisplayedScrollingRowIndex = nPos;
                                        Trace.WriteLine("Scroll from " + pos.ToString() + " to " + nPos.ToString());
                                    }
                                    else
                                    {
                                        nPos = pos;
                                        if (nPos < 0)
                                        {
                                            nPos = 0;
                                        }
                                        while (nPos < dgvDxData.RowCount && !dgvDxData.Rows[nPos].Visible)
                                        {
                                            nPos++;
                                        }
                                        if (nPos < dgvDxData.RowCount)
                                        {
                                            dgvDxData.FirstDisplayedScrollingRowIndex = nPos;
                                            Trace.WriteLine("Scroll from " + pos.ToString() + " to " + nPos.ToString());
                                        }
                                        else
                                        {
                                            Trace.WriteLine("scroll canceled");
                                        }
                                    }
                                }
                            }
                        });
                    }
                } catch (Exception e)
                {
                    dxDataLock = false;
                    Debug.WriteLine(e.ToString());
                    Debug.WriteLine("line recived: " + line);
                }
            }
        }
コード例 #2
0
        private bool[] confirmContact(DxItem dx)
        {
            bool[] r = { false, false };


            Predicate <ADIFHeader> adifFilter = new Predicate <ADIFHeader>(delegate(ADIFHeader x) { return(false); });

            if (miSelectPrefix.Checked)
            {
                adifFilter = new Predicate <ADIFHeader>(delegate(ADIFHeader x)
                {
                    return(x.prefix == dx.prefix);
                });
            }
            else if (miSelectBand.Checked)
            {
                adifFilter = new Predicate <ADIFHeader>(delegate(ADIFHeader x)
                {
                    return(x.prefix == dx.prefix && x.band == dx.band);
                });
            }
            else
            {
                bool any = false;
                if (modesMenuItems.ContainsKey(dx.mode) && modesMenuItems[dx.mode].OwnerItem != miModes)
                {
                    ToolStripMenuItem miOwner = (ToolStripMenuItem)modesMenuItems[dx.mode].OwnerItem;
                    any = modesMenuItems[miOwner.Text + "_ANY"].Checked;
                    if (any)
                    {
                        List <string> modes = new List <string>();
                        foreach (ToolStripMenuItem mi in miOwner.DropDownItems)
                        {
                            if (!mi.Text.Contains("_ANY") && mi.Checked)
                            {
                                modes.Add(mi.Text);
                            }
                        }
                        adifFilter = new Predicate <ADIFHeader>(delegate(ADIFHeader x)
                        {
                            return(x.prefix == dx.prefix && x.band == dx.band && modes.Contains(x.mode));
                        });
                    }
                }
                if (!any)
                {
                    adifFilter = new Predicate <ADIFHeader>(delegate(ADIFHeader x)
                    {
                        return(x.prefix == dx.prefix && x.band == dx.band && x.mode == dx.mode);
                    });
                }
            }
            foreach (KeyValuePair <ADIFHeader, ADIFState> hs in adifData.Where(x => adifFilter(x.Key)))
            {
                if (!r[0])
                {
                    r[0] = true;
                }
                int co = 0;
                foreach (string ct in DxConsts.ConfirmationTypes)
                {
                    if (hs.Value.confirmation[co++] && confirmMenuItems[ct].Checked)
                    {
                        r[1] = true;
                        break;
                    }
                }
                if (r[1])
                {
                    break;
                }
            }

            return(r);
        }
コード例 #3
0
        private void dgvDxDrawRow(int c)
        {
            DxItem          dx = blDxData[c];
            DataGridViewRow r  = dgvDxData.Rows[c];

            bool[] cc = { true, true };
            if (adifData != null && dx.prefix != "" &&
                bandsMenuItems.ContainsKey(dx.band) && bandsMenuItems[dx.band].Checked &&
                modesMenuItems.ContainsKey(dx.mode) && modesMenuItems[dx.mode].Enabled && modesMenuItems[dx.mode].Checked)
            {
                cc = confirmContact(dx);
            }

            if (dxDataBandFilterButtons.ContainsKey(dx.band))
            {
                r.Visible = dxDataBandFilterButtons[dx.band].Checked;
                if (!r.Visible)
                {
                    return;
                }
            }
            if (tsbNoCfm.Checked)
            {
                r.Visible = !dx.isBeacon() && !cc[1];
                if (!r.Visible)
                {
                    return;
                }
            }
            else
            {
                r.Visible = true;
            }

            int visCount = 0;

            for (int co = c + 1; co < dgvDxData.RowCount; co++)
            {
                if (dgvDxData.Rows[co].Visible)
                {
                    visCount++;
                }
            }
            bool odd = visCount % 2 == 1;

            for (int co = 0; co < dgvDxData.ColumnCount; co++)
            {
                r.Cells[co].Style.BackColor = odd ? Color.LightGray : Color.White;
            }

            if (!dx.isBeacon())
            {
                if (cc[1])
                {
                    return;
                }
                else if (cc[0])
                {
                    r.Cells["prefix"].Style.BackColor = Color.SteelBlue;
                    r.Cells["prefix"].Style.ForeColor = Color.White;
                }
                else
                {
                    r.Cells["prefix"].Style.BackColor = Color.Tomato;
                    r.Cells["prefix"].Style.ForeColor = Color.White;
                }
            }
        }