Example #1
0
        private void EnableDetailUi(bool isEnabled)
        {
            isEnabled = isEnabled && !mainBackgroundWorker.IsBusy;

            DataGridViewSelectedRowCollection rows = mainDataGridView.SelectedRows;
            object item = rows.Count > 0 ? rows[0].DataBoundItem : null;

            object propertyItem = detailPropertyGrid.SelectedObject is TypeBroker broker ?
                                  broker.Actual : item;

            bool hasDetail = searcher?.CanGetDetail ?? false;

            bool lacksDetail = isEnabled && hasDetail && rows
                               .OfType <DataGridViewRow>()
                               .Any(row => row.DataBoundItem == propertyItem);

            viewFullDetailMenuItem.Enabled = lacksDetail;
            detailGetMenuItem.Enabled      = lacksDetail;
            viewDetailMenuItem.Enabled     = isEnabled;
        }
Example #2
0
        public void btnMerge_Click(object sender, EventArgs e)
        {
            if (!sortedByTime)
            {
                MessageBox.Show("Please sort by Time (in ascending order) before applying the Merge function.");
            }
            else if (dgv.SelectedRows.Count <= 1)
            {
                MessageBox.Show("Please ensure several rows are selected before applying the Merge function.");
            }
            else
            {
                PrepareBackup(dgv);

                DataGridViewSelectedRowCollection selected = dgv.SelectedRows;
                int selectedRowsNumber = selected.Count;

                IQueryable <DataGridViewRow> qRows = selected.OfType <DataGridViewRow>().AsQueryable();

                // We will be merging into the top-most record, let us find its index first...
                var minIndex = qRows.Min(i => i.Index);
                var maxIndex = qRows.Max(i => i.Index);

                //decimal totalMergedDuration = 0;
                //double maxSigStrength = 0;
                //var meanNoise = 0.0;
                //var meanFreq = 0.0;

                try
                {
                    // // See if any of these rows have been programmatically split before...
                    //var artificial = qRows.Where(i => i.Cells[(int)Index.Event].Value.ToString().Contains("."));

                    //if (artificial.ToList().Count == 0)
                    //{
                    //    // Calculate the required max and means.
                    //    // maxSigStrength = (double)decimal.Parse(qRows.Max(i => i.Cells[(int)Index.Signal].Value).ToString());

                    //    foreach (DataGridViewRow row in dgv.SelectedRows)
                    //    {
                    //        double tempStrength = 0;
                    //        double.TryParse(row.Cells[(int)Index.Signal].Value.ToString(), out tempStrength);
                    //        maxSigStrength += tempStrength;
                    //    }

                    //    //meanNoise = qRows.Average(i => (double)decimal.Parse(i.Cells[(int)Index.Noise].Value.ToString()));
                    //    //meanFreq = qRows.Average(i => (double)decimal.Parse(i.Cells[(int)Index.Freq].Value.ToString()));

                    //    // int totalMergedDuration = GetDescreteDuration(minIndex, maxIndex);
                    //    // int totalMergedDuration = (int)qRows.Sum(i => (decimal)i.Cells[(int)Index.Duration].Value);
                    //    // int totalMergedDuration = qRows.Sum(i => (int.Parse(i.Cells[(int)Index.Duration].Value.ToString())));

                    //    // This is a problematic calculation, do it "manually"...

                    //    foreach (DataGridViewRow row in dgv.SelectedRows)
                    //    {
                    //        decimal tempDuration = 0;
                    //        decimal.TryParse(row.Cells[(int)Index.Duration].Value.ToString(), out tempDuration);
                    //        totalMergedDuration += tempDuration;
                    //    }
                    //}

                    // Remove the remaining selected records...
                    for (int i = 0; i < selectedRowsNumber; i++)
                    {
                        DataGridViewRow row = selected[i];

                        if (row.Index != minIndex)
                        {
                            dgv.Rows.RemoveAt(row.Index);
                        }
                    }

                    DataGridViewRow rowToMergeInto = dgv.Rows[minIndex];

                    // Set the new total duration in the record we are keeping.
                    //rowToMergeInto.Cells[(int)Index.Duration].Value = totalMergedDuration;
                    //rowToMergeInto.Cells[(int)Index.Signal].Value = maxSigStrength;
                    //rowToMergeInto.Cells[(int)Index.Noise].Value = Math.Round((decimal)meanNoise, 1, MidpointRounding.AwayFromZero);
                    //rowToMergeInto.Cells[(int)Index.Freq].Value = Math.Round((decimal)meanFreq, 1, MidpointRounding.AwayFromZero);

                    rowToMergeInto.Cells[(int)Index.Duration].Value = "";
                    rowToMergeInto.Cells[(int)Index.Signal].Value   = "";
                    rowToMergeInto.Cells[(int)Index.Noise].Value    = "";
                    rowToMergeInto.Cells[(int)Index.Freq].Value     = "";

                    rowToMergeInto.Selected = true;
                    dgv.CurrentCell         = rowToMergeInto.Cells[0];
                    dgv.Focus();
                }
                catch (Exception ex)
                {
                    // Inspect the exception and decide what to do.
                    MessageBox.Show("Please ensure the format of selected rows is consistent with other log entries.");
                    MessageBox.Show(ex.Message);
                }
            }
        }