Exemple #1
0
        private void Calc(ReportType type)
        {
            var tCalc = new Thread(() =>
            {
                Lock = true;
                lock (this)
                {
                    _timeCalcBegin = DateTime.Now;
                }
                if (!CalcData(type))
                {
                    return;
                }
                SetStatusText("Идет подготовка к выгрузке файлов.");

                if (new [] { ReportType.Route, ReportType.Terminal, ReportType.TransportVehicle, ReportType.TransportCard, ReportType.Organisation }.Contains(type))
                {
                    var query  = ReportUtils.GetReaderQuery(type);
                    var reader = (type == ReportType.TransportCard)
                        ? DatabaseUtils.GetReader(_connection, query, new[]
                    {
                        new OracleParameter
                        {
                            ParameterName = "pActivationBeginDate",
                            OracleDbType  = OracleDbType.Date,
                            Value         = dtActivePassActivationBeginDate.Value
                        },
                        new OracleParameter
                        {
                            ParameterName = "pActivationEndDate",
                            OracleDbType  = OracleDbType.Date,
                            Value         = dtActivePassActivationEndDate.Value
                        }
                    })
                        : DatabaseUtils.GetReader(_connection, query);
                    if ((reader == null) || (!reader.HasRows))
                    {
                        return;
                    }
                    _timeOutputBegin = DateTime.Now;
                    ClearThreadVars();

                    while (reader.Read())
                    {
                        var id   = Routines.GetLong(reader["id_element"]);
                        var name = Routines.GetString(reader["name_element"]);
                        var t    = new Thread(() =>
                        {
                            lock (this)
                            {
                                _threadWaitingCount++;
                                _threadFullCount++;
                            }
                            while (true)
                            {
                                lock (this)
                                {
                                    if (_threadActiveCount < ((new List <ReportType> {
                                        ReportType.TransportVehicle
                                    }.Contains(type)) ? 4 : 16))
                                    {
                                        _threadActiveCount++;
                                        _threadWaitingCount--;
                                        UpdateStatusProgressText();
                                        break;
                                    }
                                }
                                Thread.Sleep(50);
                            }
                            CalcOutput(type, id, name);
                            lock (this)
                            {
                                _threadActiveCount--;
                                _threadFinishedCount++;
                                UpdateStatusProgressText();
                            }
                            if ((_threadActiveCount != 0) || (_threadWaitingCount != 0))
                            {
                                return;
                            }
                            //Если это последний поток
                            Lock = false;
                            MessageBox.Show(
                                $"Выгрузилось {_threadFullCount} отчетов за {(DateTime.Now - _timeCalcBegin).ToString(@"dd\.hh\:mm\:ss")}!");
                            SetStatusText("");
                        })
                        {
                            IsBackground = true
                        };
                        if (_threadWaitingCount < 500)
                        {
                            t.Start();
                        }
                        else
                        {
                            while (true)
                            {
                                if (_threadWaitingCount < 50)
                                {
                                    t.Start();
                                    break;
                                }
                                Thread.Sleep(50);
                            }
                        }
                    }
                }
                else
                {
                    CalcOutput(type);
                    Lock = false;
                    MessageBox.Show(
                        $"Выгрузился за {(DateTime.Now - _timeCalcBegin).ToString(@"dd\.hh\:mm\:ss")}!");
                    SetStatusText("");
                }
            });

            tCalc.Start();
        }
Exemple #2
0
 private void Main_Load(object sender, EventArgs e)
 {
     Text += $" ({Application.ProductVersion})";
     SetDefaultValues();
     ReportUtils.LoadReportList(tvReports);
 }