Example #1
0
        private void LoadLog(int pos, int count, GoalRecord goal, bool print = false)
        {
            if (_busy)
            {
                return;
            }
            if (pos < 0)
            {
                return;
            }
            var dateBefore = DateTime.Now.AddYears(-1);

            CalcRowsCount(lvLogView);
            if (count <= 0)
            {
                return;
            }
            _busy                 = true;
            tsbAnchor.Enabled     = false;
            tsbBackward.Enabled   = false;
            tsbFilterEdit.Enabled = false;
            _lastForwardState     = tsbForward.Enabled;
            tsbForward.Enabled    = false;
            tsbEnd.Enabled        = false;
            ThreadPool.QueueUserWorkItem(arg =>
            {
                int linescount;
                var results = Data.GetSysLogRecords(pos, count, dateBefore, out linescount, true);
                var method  = new MethodInvoker(() =>
                {
                    _reportrows.Clear();
                    var row = 0;
                    foreach (string[] rec in results)
                    {
                        if (rec.Length != 12)
                        {
                            continue;
                        }
                        var item = new ListViewItem(rec[0]);
                        if (row % 2 != 0)
                        {
                            item.BackColor = Color.FromKnownColor(KnownColor.WhiteSmoke);
                        }
                        var overpass = rec[2];
                        var way      = rec[3];
                        var product  = Data.GetFineProductName(rec[4]);
                        var riser    = rec[5];
                        var addr     = string.Join("", rec, 1, 5).Trim().Length > 0
                                               ? string.Format("Эстакада {0}. Путь {1}. {2}. Стояк {3}",
                                                               overpass, way, product, riser)
                                               : "";
                        item.SubItems.Add(addr);
                        var mess = rec[6];
                        item.SubItems.Add(mess);
                        var waggon = rec[7];
                        item.SubItems.Add(waggon);
                        var type = rec[8];
                        item.SubItems.Add(type);
                        var maxheight = rec[9];
                        item.SubItems.Add(maxheight);
                        var setpoint = rec[10];
                        item.SubItems.Add(setpoint);
                        var filled = rec[11];
                        item.SubItems.Add(filled);
                        _reportrows.Add(item);
                        row++;
                    }
                    UpdateColumnWidths(lvLogView);
                    if (print)
                    {
                        return;
                    }
                    lvLogView.BeginUpdate();
                    try
                    {
                        lvLogView.Items.Clear();
                        lvLogView.Items.AddRange(_reportrows.ToArray());
                    }
                    finally
                    {
                        lvLogView.EndUpdate();
                    }
                    tsbForward.Enabled = _lastForwardState;
                    switch (goal)
                    {
                    case GoalRecord.FirstRecord:
                        GotoRecord(GoalRecord.FirstRecord);
                        tsbBackward.Enabled = lvLogView.Items.Count >= _viewCount;
                        tsbForward.Enabled  = true;
                        tsbEnd.Enabled      = true;
                        break;

                    case GoalRecord.NextRecord:
                        GotoRecord(GoalRecord.LastRecord);
                        tsbEnd.Enabled      = tsbForward.Enabled;
                        tsbBackward.Enabled = lvLogView.Items.Count >= _viewCount;
                        break;

                    default:
                        GotoRecord(GoalRecord.LastRecord);
                        tsbForward.Enabled  = false;
                        tsbEnd.Enabled      = false;
                        tsbBackward.Enabled = lvLogView.Items.Count >= _viewCount;
                        break;
                    }
                    _busy                 = false;
                    tsbAnchor.Enabled     = true;
                    tsbFilterEdit.Enabled = true;
                }
                                                );
                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method();
                }
            });
        }