public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (!LabelOperator.isObjectExistingFile(value)) { return(null); } string btwFileName = (string)value; try { System.Drawing.Image btwImage = LabelFormatThumbnail.Create(btwFileName, System.Drawing.Color.Gray, 500, 500); using (var ms = new MemoryStream()) { btwImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); ms.Position = 0; var bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.StreamSource = ms; bi.EndInit(); btwImage.Dispose(); //if bmp is not used further. return(bi); } } catch (Exception ex) { Log.Instance.Logger.Error($"获取缩略图错误:{ex.Message}"); return(null); } }
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}"; } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (!LabelOperator.isObjectExistingFile(value)) { return(""); } return(Path.GetFileNameWithoutExtension((string)value)); }
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}!"); } }); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return(LabelOperator.isObjectExistingFile(value)); }