/// <summary> /// Print /// </summary> /// <param name="adapterPosition">Adapter position.</param> void OnPrint(int adapterPosition) { var docket = _dockets[adapterPosition]; var profile = _repository.Profiles.First(); var device = _repository.MobileDevices.First(); if (device.PrinterAddress == null) { var message = Resources.GetString(Resource.String.message_setup_printer); UserDialogs.Instance.Alert(message); return; } var address = device.PrinterAddress; var title = Resources.GetString(Resource.String.message_printing); UserDialogs.Instance.ShowLoading(title); var lendingStatus = _repository.LendingStatus .Where(x => x.CustomerAccountNumber == docket.CustomerAccountNumber) .ToList(); var signaturePath = docket.SignaturePath; var docketItems = _repository.DeliveryDocketItems .Where(x => x.HasValue && x.DeliveryDocketID == docket.DocketID) .OrderBy(x => x.Description).ToList(); var label = LabelTemplates.GetDocketLabel(docket, docketItems, lendingStatus); Task.Run(() => { var result = PrinterUtils.Print(label, address, signaturePath); Activity.RunOnUiThread(() => { UserDialogs.Instance.HideLoading(); if (result.Status != PrintStatus.Success) { UserDialogs.Instance.Alert(result.Message); } }); }); }
/// <summary> /// Print docket /// </summary> bool PrintDocket() { Activity.RunOnUiThread(ShowPrintingMessage); using (var repository = new Repository()) { // check we have a printer set up var device = repository.MobileDevices.First(); var docket = repository.DeliveryDockets.Find(_docketId); // get lending status var lendingStatus = repository.LendingStatus .Where(x => x.CustomerAccountNumber == docket.CustomerAccountNumber) .ToList(); // get label var docketItems = repository.DeliveryDocketItems .Where(x => x.HasValue && x.DeliveryDocketID == docket.DocketID) .OrderBy(x => x.Description).ToList(); var label = LabelTemplates.GetDocketLabel(docket, docketItems, lendingStatus); // get the printer address var address = device.PrinterAddress; if (String.IsNullOrWhiteSpace(address)) { Activity.RunOnUiThread(UserDialogs.Instance.HideLoading); return(false); } // print var result = PrinterUtils.Print(label, address, docket.SignaturePath); // hide loading Activity.RunOnUiThread(UserDialogs.Instance.HideLoading); return(result.Status == PrintStatus.Success); } }