Пример #1
0
 private void InitComponents()
 {
     if (!Directory.Exists(Constants.btwTopDir))
     {
         Directory.CreateDirectory(Constants.btwTopDir);
     }
     this.ListBtwDirs();
     this.StartingNumberMaxLength = 7;
     this.ObsPrintHistoryVMs      = new ObservableCollection <PrintHistoryViewModel>();
     this.SelectedDate            = DateTime.Today;
     this.StartingNumber          = 1;
     this.ReadFieldsAliasXml();
     SqliteHistory.CreateDb();
     this.labelOperator = new LabelOperator(this.BtEngine);
     try
     {
         this.serialPort = new SerialPort(Constants.SerialPortComName, 9600);
         this.serialPort.DataReceived += SerialPort_DataReceived;
         this.serialPort.Open();
     }
     catch (Exception ex)
     {
         Log.Instance.Logger.Error($"初始化串口出错{ex.Message}");
         this.Message = $"初始化串口出错{ex.Message}";
     }
 }
Пример #2
0
        private async Task Print()
        {
            await Task.Run(() =>
            {
                Log.Instance.Logger.Info($"触发打印!");
                if (this.SelectedBtwFile == null)
                {
                    Log.Instance.Logger.Error($"未选择任何文件,退出打印!");
                    return;
                }
                if (LabelOperator.isObjectExistingFile(this.SelectedBtwFile))
                {
                    if (this.BtEngine == null)
                    {
                        Log.Instance.Logger.Error($"bartender未正确初始化,无法打印!");
                        return;
                    }
                    Log.Instance.Logger.Info($"准备打印{this.SelectedBtwFile}!");

                    string obarcodeHistroySuffix;
                    LabelFormatDocument label =
                        this.SetLabelValues(this.SelectedBtwFile, out obarcodeHistroySuffix);
                    if (this.SelectedBtwFile == null)
                    {
                        Log.Instance.Logger.Error($"未选择任何文件,退出打印!");
                        return;
                    }
                    string BtwTemplate = this.SelectedBtwFile.Replace(
                        Constants.btwTopDir, "");
                    SqliteHistory.InsertPrintHistroy(
                        BtwTemplate,
                        obarcodeHistroySuffix);
#if DEBUG
                    this.Message = "DEBUG跳过真实打印";
#else
                    string msg = BtwPrintWrapper.PrintBtwFile(label, this.BtEngine);
                    //BtwPrintWrapper.PrintPreviewLabel2File(label, this.BtEngine);
                    this.Message = msg.Trim();
#endif
                }
                else
                {
                    Log.Instance.Logger.Error($"无法打印,文件不存在:{this.SelectedBtwFile}!");
                }
            });
        }