Ejemplo n.º 1
0
        private async void FiscalAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _log.Debug($"{nameof(FiscalAllToolStripMenuItem)} clicked");
            _processing = true;


            for (var i = 0; i < gridSource.RowCount - 1; i++)
            {
                var currentRow = gridSource.Rows[i];
                _log.Debug(
                    $"Current row: {nameof(gridSource)}.Rows[{i}]: {currentRow.Cells[3].Value}, {currentRow.Cells[2].Value}");

                Utils.ChangeBackground(currentRow, Color.PaleGoldenrod);

                try
                {
                    _conn.RegisterCheck(currentRow.Cells[0].Value.ToString(), currentRow.Cells[3].Value.ToString(),
                                        currentRow.Cells[2].Value.ToString(), string.Empty);

                    await Task.Delay(1500);

                    Utils.ChangeBackground(currentRow, Color.YellowGreen);
                }
                catch
                {
                    Utils.ChangeBackground(currentRow, Color.Salmon);
                }
            }

            _processing = false;
            _log.Info("Фискализация позиций завершена");
        }
Ejemplo n.º 2
0
        private async void FiscalAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _log.Debug($"{nameof(FiscalAllToolStripMenuItem)} clicked");
            _processing = true;

            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;

            for (var i = 0; i < gridSource.RowCount - 1; i++)
            {
                var currentRow = gridSource.Rows[i];
                _log.Debug(
                    $"Current row: {nameof(gridSource)}.Rows[{i}]: {currentRow.Cells[3].Value}, {currentRow.Cells[2].Value}");

                Utils.ChangeBackground(currentRow, Color.PaleGoldenrod);

                try
                {
                    var response = await _conn.RegisterCheck(currentRow.Cells[0].Value.ToString(),
                                                             currentRow.Cells[3].Value.ToString(),
                                                             currentRow.Cells[2].Value.ToString(), string.Empty, currentRow.ToString(), token);

                    if (response != null)
                    {
                        switch (response.ResponseTaskStatus)
                        {
                        case ResponseTaskStatus.Failed:
                            _log.Debug($"{response.ErrorMessage}");
                            Utils.ChangeBackground(currentRow, Color.Salmon);
                            tokenSource.Cancel();
                            break;

                        case ResponseTaskStatus.Complete:
                            Utils.ChangeBackground(currentRow, Color.YellowGreen);
                            break;

                        case ResponseTaskStatus.TaskCancelled:
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }
                catch
                {
                    Utils.ChangeBackground(currentRow, Color.Salmon);
                }
            }

            _processing = false;
            _log.Info("Фискализация позиций завершена");
        }