public async void PrintCommand(string printerName, string printText) { try { await _blueToothService.Print(printerName, printText); } catch (Exception ex) { } }
public void Imprimir(string Men) { blueToothService.Print(SelectedDevice, Men); }
/// <summary> /// Print text-message /// </summary> public Task Print() { return(_blueToothService.Print(SelectedDevice, PrintMessage)); }
async void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem != null) { var action = DisplayAlert("Edit Order ", "ต้องการชำระเงินรายการนี้", "Yes", "No"); if (await action) { ListView listView = (ListView)sender; FoodMini mini = (FoodMini)listView.SelectedItem; List <FoodMini> listFood1 = await firebaseHelper.GetAllFood(date_str, mini.QuequNo, "P"); decimal totalAmount = 0; StringBuilder sb = new StringBuilder(); sb.Append("--------------r\n"); for (int i = 0; i < listFood1.Count; i++) { FoodMini mini2 = listFood1[i]; mini2.Status = "Y"; await firebaseHelper.UpdateFood(mini2.ID, mini2.Name, mini2.NameEn, mini2.Location, mini2.Details, mini2.Quantity, mini2.OrderDate, mini2.QuequNo, mini2.Status, date_str, mini2.LevelSpicy); sb.Append(" Order No = " + (i + 1) + "r\n"); sb.Append(" Food = " + mini2.Name + "r\n"); sb.Append(" จำนวน = " + mini2.Quantity + "r\n"); sb.Append(" ราคา = " + mini2.CostPerUnit + "r\n"); totalAmount = totalAmount + (mini2.CostPerUnit * mini2.Quantity); } sb.Append("-------------"); sb.Append("รวมราคา " + totalAmount); sb.Append("\r\n "); sb.Append("\r\n "); sb.Append("-------------"); sb.Append("Order By " + Application.Current.Properties["UserLogin"] + ""); sb.Append("\r\n "); sb.Append("\r\n "); sb.Append("\r\n "); totalAmount = 0; decimal totalQuan = 0; for (int i = 0; i < listFood1.Count; i++) { FoodMini mini2 = listFood1[i]; sb.Append(" Order No = " + (i + 1) + "r\n"); sb.Append(" Food = " + mini2.Name + "r\n"); sb.Append(" จำนวน = " + mini2.Quantity + "r\n"); sb.Append(" ราคา = " + mini2.CostPerUnit + "r\n"); totalAmount = totalAmount + (mini2.CostPerUnit * mini2.Quantity); totalQuan = totalQuan + mini2.Quantity; } sb.Append("-------------"); sb.Append("รวมราคา " + totalAmount); sb.Append("\r\n "); sb.Append("\r\n "); sb.Append("-------------"); sb.Append("Order By " + Application.Current.Properties["UserLogin"] + ""); sb.Append("\r\n "); sb.Append("\r\n "); sb.Append("\r\n "); message = sb.ToString(); await _blueToothService.Print(SelectedDevice, message); } //end if } //end if }
public PrintSettingPageViewModel(INavigationService navigationService, IDialogService dialogService ) : base(navigationService, dialogService) { _blueToothService = DependencyService.Get <IBlueToothService>(); Title = "蓝牙打印机"; this.PrintData = null; this.EnableBluetooth = Settings.EnableBluetooth; this.WhenAnyValue(x => x.PrintStyleSelected).Subscribe(x => { Settings.PrintStyleSelected = x; }) .DisposeWith(this.DeactivateWith); //启用蓝牙 this.WhenAnyValue(x => x.EnableBluetooth) .Subscribe(async x => { try { if (x) { this.Drives.Clear(); Settings.EnableBluetooth = true; var micAccessGranted = await _blueToothService.GetPermissionsAsync(); if (!micAccessGranted) { this.EnableBluetooth = false; this.Alert("请打先启用手机蓝牙功能"); return; } Device.BeginInvokeOnMainThread(async() => { using (var dig = UserDialogs.Instance.Loading("扫描中...")) { long timeOutTime = 8000; long curRunTime = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; long tempTime = curRunTime; while (this.Drives.Count == 0 && (curRunTime - tempTime) <= timeOutTime) { curRunTime = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; var results = _blueToothService.PairedDevices(); if (results != null && results.Any()) { this.DrivesHeight = results.Count() * 40.7; this.Drives = new ObservableRangeCollection <Printer>(results); } await Task.Delay(1000); } } if (this.Drives.Count == 0) { _dialogService.LongAlert("没有扫描蓝牙到设备!"); this.EnableBluetooth = false; Settings.EnableBluetooth = false; } }); } else { Settings.EnableBluetooth = false; this.EnableBluetooth = false; this.Drives.Clear(); } } catch (NullReferenceException) { this.EnableBluetooth = false; Settings.EnableBluetooth = false; _dialogService.LongAlert("没有找到蓝牙设备!"); } }) .DisposeWith(this.DeactivateWith); //适配 this.AdaptationCmd = ReactiveCommand.CreateFromTask <Printer>(async(item) => { if (!item.Status && Drives != null && Drives.Where(s => s.Status).Count() > 0) { _dialogService.LongAlert("请先断开当前适配"); return; } using (var dig = UserDialogs.Instance.Loading("请稍等...")) { try { await Task.Delay(500); await Task.Run(() => { Device.BeginInvokeOnMainThread(async() => { if (!item.Status) { var connected = await _blueToothService.ConnectDevice(item); if (connected) { item.Status = true; } } else { _blueToothService.PrintStop(); App.BtAddress = ""; item.Status = false; } }); }); } catch (Exception) { _dialogService.LongAlert("适配不到设备,请确保打印机开启"); } } }); //打印测试 this.PrintCommand = ReactiveCommand.Create(() => { try { if (!string.IsNullOrEmpty(App.BtAddress)) { _blueToothService.Print(this.PrintData, Settings.PrintStyleSelected, this.RepeatPrintNum); } else { _dialogService.LongAlert("请选择匹配设备!"); } } catch (Exception ex) { _dialogService.LongAlert(ex.Message); } }); }