Ejemplo n.º 1
0
        private static string CheckWaggonNumber(string number)
        {
            if (number.Trim().Length != 8)
            {
                return("Ожидался 8-значный номер");
            }
            if (number.Any(ch => !char.IsDigit(ch)))
            {
                return("Номер содержит нечисловые символы");
            }
            // проверка на дублирование номера вагона в партии
            var list = Data.Tasks.ReadSections();

            foreach (var riserSection in list)
            {
                var lastEnteredNumber = Data.Tasks.ReadString(riserSection, "Number", "");
                if (!lastEnteredNumber.Equals(number))
                {
                    continue;
                }
                var overpass = Data.Tasks.ReadString(riserSection, "Overpass", "");
                var way      = Data.Tasks.ReadString(riserSection, "Way", "");
                var product  = Data.GetFineProductName(Data.Tasks.ReadString(riserSection, "Product", ""));
                var riser    = Data.Tasks.ReadString(riserSection, "Riser", "");
                return(string.Format("Номер цистерны {0} уже используется " +
                                     "в задании налива для стояка {1} эстакады {2}, путь {3}, продукт: {4}",
                                     number, riser, overpass, way, product));
            }
            // проверка на корректность номера по контрольной сумме
            var fp  = CultureInfo.GetCultureInfo("en-US");
            var sum = 0;
            var kf  = new[] { 2, 1, 2, 1, 2, 1, 2 };

            for (var i = 1; i <= 7; i++)
            {
                var val = kf[i - 1] * int.Parse(number[i - 1].ToString(fp));
                if (val > 9)
                {
                    val = 1 + (val - 10);
                }
                sum += val;
            }
            var lastDigit = int.Parse(number[7].ToString(fp));
            var text      = (sum + lastDigit).ToString("0");

            return(text.Length > 0 && text[text.Length - 1] == '0'
                ? string.Empty
                : "Некорректный номер (не сходится контрольная сумма)");
        }
Ejemplo n.º 2
0
        private void LoadLog(int pos, int count, bool print = false)
        {
            if (pos < 0)
            {
                return;
            }
            var dateBefore = DateTime.Now.AddYears(-1);

            CalcRowsCount(lvLogView);
            int linescount;
            var results = Data.GetChangeLogRecords(pos, count, dateBefore, out linescount, true);

            if (count <= 0)
            {
                return;
            }
            _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     = FineAddr(overpass, way, product, riser);
                item.SubItems.Add(addr);
                var param = rec[7];
                item.SubItems.Add(param);
                var oldstate = rec[8];
                item.SubItems.Add(oldstate);
                var newstate = rec[9];
                item.SubItems.Add(newstate);
                var user = rec[10];
                item.SubItems.Add(user);
                var desc = rec[11];
                item.SubItems.Add(desc);
                _reportrows.Add(item);
                row++;
            }
            UpdateColumnWidths(lvLogView);
            if (print)
            {
                return;
            }
            lvLogView.BeginUpdate();
            try
            {
                lvLogView.Items.Clear();
                lvLogView.Items.AddRange(_reportrows.ToArray());
            }
            finally
            {
                lvLogView.EndUpdate();
            }
        }
Ejemplo n.º 3
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();
                }
            });
        }
Ejemplo n.º 4
0
        private void LoadLog(int pos, int count, bool print = false)
        {
            if (pos < 0)
            {
                return;
            }
            var dateBefore = DateTime.Now.AddYears(-1);

            CalcRowsCount(lvLogView);
            int linescount;
            var results = Data.GetFillLogRecords(pos, count, dateBefore, out linescount, true);

            if (count <= 0)
            {
                return;
            }
            _reportrows.Clear();
            var row = 0;

            foreach (string[] rec in results)
            {
                if (rec.Length != 13)
                {
                    continue;
                }
                var item = new ListViewItem();
                if (row % 2 != 0)
                {
                    item.BackColor = Color.FromKnownColor(KnownColor.WhiteSmoke);
                }
                var startdatetime = rec[0];
                var enddatetime   = rec[1];
                item.Text = GetDateStr(enddatetime);
                var overpass = rec[3];
                var way      = rec[4];
                var product  = Data.GetFineProductName(rec[5]);
                var riser    = rec[6];
                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 waggon = rec[7];
                item.SubItems.Add(waggon);
                var type = rec[8];
                item.SubItems.Add(type);
                var setpoint = rec[9];
                item.SubItems.Add(setpoint);
                item.SubItems.Add(GetTimeStr(startdatetime));
                item.SubItems.Add(GetTimeStr(enddatetime));
                var filled = rec[10];
                item.SubItems.Add(filled);
                var user = rec[11];
                item.SubItems.Add(user);
                var mess = rec[12];
                item.SubItems.Add(mess.EndsWith("автоматически") ? "" : mess);
                _reportrows.Add(item);
                row++;
            }
            UpdateColumnWidths(lvLogView);
            if (print)
            {
                return;
            }
            lvLogView.BeginUpdate();
            try
            {
                lvLogView.Items.Clear();
                lvLogView.Items.AddRange(_reportrows.ToArray());
            }
            finally
            {
                lvLogView.EndUpdate();
            }
        }