コード例 #1
0
ファイル: PrintController.cs プロジェクト: cxzhe/JunSheng
 private void PopulateJobCommandFields(JobCommand command, string qrContent)
 {
     command.Fields.Add(QrCodeFieldName, qrContent);
     command.Fields.Add(ModelFieldName, _batch.Model);
     command.Fields.Add(DateProducedFieldName, _batch.DateProduced);
     command.Fields.Add(DateExpiredFieldName, _batch.DateExpired);
     command.Fields.Add(BatchNoFieldName, _batch.BatchNo);
 }
コード例 #2
0
ファイル: X30Client.cs プロジェクト: cxzhe/JunSheng
        public async Task UpdateJob(JobCommand command)
        {
            var packet   = command.ToPacket();
            var response = await SendAsync(TcpClient, packet, Encoding);

            if (response != "{~JU0|}")
            {
                throw new InvalidOperationException();
            }
        }
コード例 #3
0
ファイル: PrintController.cs プロジェクト: cxzhe/JunSheng
        private async void Setup()
        {
            if (_isBusy)
            {
                OnLog("上次请求还未处理");
                return;
            }

            _isBusy = true;
            try
            {
                await X30Client.StateChangeAsync(StateChangeStatus.Producing);

                var jobUpdateCommand = new JobCommand();
                var bi = _batchsToPrint[_batch.StartIndex];

                PopulateJobCommandFields(jobUpdateCommand, bi.QRCodeContent);

                await X30Client.UpdateJob(jobUpdateCommand);

                //log sent batch info
                _initialized = true;
                _batchIndex  = _batch.StartIndex;

                bi.Status = BatchStatus.CodeSent;
                var message = $"成功初始化--{bi.SerinalNo} - {bi.QRCodeContent} 已赋码";
                OnLog(message);
            }
            catch (Exception e)
            {
                var message = $"初始化失败--{e.Message}";
                OnLog(message);
            }

            _isBusy = false;
        }
コード例 #4
0
ファイル: PrintController.cs プロジェクト: cxzhe/JunSheng
        private async void UpdateJob()
        {
            if (_isBusy)
            {
                OnLog("上次请求还未处理");
                return;
            }

            _isBusy = true;

            try
            {
                var status = await X30Client.GetClearSendStatusAsync();

                if (status == ClearSendStatus.Ready)
                {
                    if (IsComplete)
                    {
                        _timer.Stop();
                        await X30Client.StateChangeAsync(StateChangeStatus.Ready);

                        PrintCompleted?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        CurrentBatchItem.Status = BatchStatus.Printed;
                        AppContext.Instance.DB.Update(CurrentBatchItem);

                        if (IsFatalError)
                        {
                            _timer.Stop();
                            FatalError?.Invoke(this, EventArgs.Empty);
                            await X30Client.StateChangeAsync(StateChangeStatus.Ready);

                            return;
                        }
                        var jobUpdateCommand = new JobCommand();
                        var bi = _batchsToPrint[_batchIndex + 1];

                        PopulateJobCommandFields(jobUpdateCommand, bi.QRCodeContent);

                        await X30Client.UpdateJob(jobUpdateCommand);

                        _currentClearStatus = ClearSendStatus.NotReady;
                        _batchIndex++;
                        bi.Status = BatchStatus.CodeSent;
                        AppContext.Instance.DB.Update(bi);
                        var message = $"{bi.SerinalNo} - {bi.QRCodeContent} 已赋码";
                        OnLog(message);
                        Printed?.Invoke(this, EventArgs.Empty);
                    }
                }
                else
                {
                    CurrentBatchItem.Status = BatchStatus.Printing;
                }
            }
            catch (Exception e)
            {
                var message = $"错误--{e.Message}";
                OnLog(message);
            }

            _isBusy = false;
        }