public AnaliseView() { InitializeComponent(); this.viewModel = new AnaliseViewModel(); this.BindingContext = viewModel; micService = DependencyService.Resolve <IMicrophoneService>(); }
public MainPageViewModel(INavigationService navigationService, IPageDialogService dialogService) : base(navigationService) { _dialogService = dialogService; _navigationService = navigationService; SettingsPageCommand = new DelegateCommand(NavToSettings); RecordCommand = new DelegateCommand(TranscribeSent); Title = "Record Page"; _recBtnText = "Transcribe"; _buttonEnabled = true; _btnColor = Color.FromHex("#43a047"); //recorder = new AudioRecorderService //{ // StopRecordingOnSilence = true, // StopRecordingAfterTimeout = true, // TotalAudioTimeout = TimeSpan.FromSeconds(15) // Speech REST API has 15 sec max //}; //if (Keys.Speech.SubscriptionKey == Keys.Speech.BadSubscriptionKey) >>> NEU constanrts //{ // throw new Exception("Get a Speech API key here: https://azure.microsoft.com/en-us/pricing/details/cognitive-services/speech-api/"); //} //speechClient = new SpeechApiClient(Keys.Speech.SubscriptionKey, SpeechRegion); micService = Xamarin.Forms.DependencyService.Resolve <IMicrophoneService>(); firsttime = true; _language = Settings.SpeechLanguage; }
private BingSpeech() { #if !PORTABLE this.MicrophoneService = new MicrophoneService(); #endif this.BingSpeechService = new BingSpeechService(); }
protected override void OnCreate(Bundle savedInstanceState) { Instance = this; base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); micService = DependencyService.Resolve <IMicrophoneService>(); }
protected override void OnCreate(Bundle savedInstanceState) { Instance = this; TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); Xamarin.Forms.DependencyService.Register <IMicrophoneService, MicrophoneService>(); micService = Xamarin.Forms.DependencyService.Get <IMicrophoneService>(); }
protected override void OnCreate(Bundle savedInstanceState) { Instance = this; TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); Forms.Init(this, savedInstanceState); LoadApplication(new App()); _micService = DependencyService.Resolve <IMicrophoneService>(); }
public AnaliseViewModel() { using (var conexao = DependencyService.Get <ISQLite>().PegarConnection()) { CanalTelegramDAO dao = new CanalTelegramDAO(conexao); var canal = dao.CanalTelegram; if (canal.Count > 0) { canalTelegram = canal[0]; } } micServico = DependencyService.Resolve <IMicrophoneService>(); Comandos(); }
protected override void OnCreate(Bundle bundle) { Instance = this; TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); Xamarin.Essentials.Platform.Init(this, bundle); global::Xamarin.Forms.Forms.Init(this, bundle); global::Xamarin.Forms.FormsMaterial.Init(this, bundle); // Material LoadApplication(new App(new AndroidInitializer())); // ??? micService = DependencyService.Resolve <IMicrophoneService>(); }
protected override void OnCreate(Bundle savedInstanceState) { Instance = this; TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); micService = DependencyService.Resolve <IMicrophoneService>(); this.RequestPermissions(new[] { Manifest.Permission.AccessCoarseLocation, Manifest.Permission.BluetoothPrivileged }, 0); }
public VRHandler(Label label, ActivityIndicator indicator) { micService = DependencyService.Resolve <IMicrophoneService>(); this.bleHandler = BLEHandler.GetHandler(); this.drivingHandler = DrivingHandler.GetHandler(); this.lText = label; this.indicator = indicator; // initialize speech recognizer if (recognizer == null) { var config = SpeechConfig.FromSubscription(Constants.CognitiveServicesApiKey, Constants.CognitiveServicesRegion); //string[] languages = { "cs-CZ", "en-US", "en-GB" }; AutoDetectSourceLanguageConfig lang_config = AutoDetectSourceLanguageConfig.FromLanguages(Constants.GetLanguages); recognizer = new SpeechRecognizer(config, lang_config); recognizer.Recognized += (obj, args) => { Process(args.Result.Text); }; } }
public ExchangeBillPageViewModel(INavigationService navigationService, IExchangeBillService exchangeBillService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IMicrophoneService microphoneService, ISaleBillService saleBillService, //IMapper mapper, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "换货单"; _saleBillService = saleBillService; _exchangeBillService = exchangeBillService; _microphoneService = microphoneService; //_mapper = mapper; InitBill(); #region //配送日期指定 var weekDays = new List <WeekDay>(); var startTime = DateTime.Now; var endTime = DateTime.Now.AddDays(7); while (endTime.Subtract(startTime).Days > 0) { var wd = new WeekDay { Wname = $"{startTime:MM-dd} - {GlobalSettings.GetWeek(startTime.DayOfWeek.ToString())}", Date = startTime, AMTimeRange = $"09:00-12:00", PMTimeRange = $"15:00-21:00", SelectedCommand = ReactiveCommand.Create <WeekDay>(r => { this.WeekDays.ForEach(s => { s.Selected = false; }); r.Selected = !r.Selected; this.DeliverDate = r; this.AMTimeRange = r.AMTimeRange; this.PMTimeRange = r.PMTimeRange; }) }; weekDays.Add(wd); startTime = startTime.AddDays(1); } var defaultWd = weekDays.FirstOrDefault(); if (defaultWd != null) { defaultWd.Selected = true; this.AMTimeRange = defaultWd.AMTimeRange; this.PMTimeRange = defaultWd.PMTimeRange; } this.WeekDays = new ObservableCollection <WeekDay>(weekDays); #endregion //验证 var valid_IsReversed = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作"); var valid_IsAudited = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_TerminalId = this.ValidationRule(x => x.Bill.TerminalId, _isZero, "客户未指定"); var valid_BusinessUserId = this.ValidationRule(x => x.Bill.DeliveryUserId, _isZero, "配送员未指定"); var valid_WareHouseId = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定"); var valid_ProductCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目"); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (this.Bill.AuditedStatus && !this.ReferencePage.Equals("UnDeliveryPage")) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (!valid_TerminalId.IsValid) { _dialogService.ShortAlert(valid_TerminalId.Message[0]); ((ICommand)CustomSelected)?.Execute(null); return; } if (!valid_WareHouseId.IsValid) { _dialogService.ShortAlert(valid_WareHouseId.Message[0]); ((ICommand)StockSelected)?.Execute(null); return; } if (!valid_BusinessUserId.IsValid) { _dialogService.ShortAlert(valid_BusinessUserId.Message[0]); ((ICommand)DeliverSelected)?.Execute(null); return; } //转向商品选择 await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("TerminalId", Bill.TerminalId), ("Terminaler", this.Terminal), ("SerchKey", Filter.SerchKey)); }); //编辑商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (this.Bill.IsSubmitBill) { _dialogService.ShortAlert("已提交的单据不能编辑"); return; } if (item != null) { var product = ProductSeries.Select(p => p).Where(p => p.Id == item.ProductId).FirstOrDefault(); if (product != null) { product.UnitId = item.UnitId; product.Quantity = item.Quantity; product.Price = item.Price; product.Amount = item.Amount; product.Remark = item.Remark; product.Subtotal = item.Subtotal; product.UnitName = item.UnitName; if (item.BigUnitId > 0) { product.bigOption.Name = item.UnitName; product.BigPriceUnit.Quantity = item.Quantity; product.BigPriceUnit.UnitId = item.BigUnitId; product.BigPriceUnit.Amount = item.Amount; product.BigPriceUnit.Remark = item.Remark; } if (item.SmallUnitId > 0) { product.bigOption.Name = item.UnitName; product.SmallPriceUnit.Quantity = item.Quantity; product.SmallPriceUnit.UnitId = item.SmallUnitId; product.SmallPriceUnit.Amount = item.Amount; product.SmallPriceUnit.Remark = item.Remark; } await this.NavigateAsync("EditProductPage", ("Product", product), ("Reference", PageName), ("Item", item), ("WareHouse", WareHouse)); } } this.Selecter = null; }) .DisposeWith(DeactivateWith); //提交表单 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { return(await this.Access(AccessGranularityEnum.ExchangeBillsSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } if (this.Bill.AuditedStatus || DispatchItem != null) { _dialogService.ShortAlert("已审核单据不能操作"); return Unit.Default; } //结算方式 Bill.PayTypeId = 0; Bill.PayTypeName = ""; if (Bill.BusinessUserId == 0) { Bill.BusinessUserId = Settings.UserId; } var postMData = new ExchangeBillUpdateModel() { BillNumber = this.Bill.BillNumber, //客户 TerminalId = Bill.TerminalId, //业务员 BusinessUserId = Bill.BusinessUserId, //送货员 DeliveryUserId = Bill.DeliveryUserId, //仓库 WareHouseId = Bill.WareHouseId, //交易日期 TransactionDate = DateTime.Now, //默认售价方式 DefaultAmountId = Settings.DefaultPricePlan, //备注 Remark = Bill.Remark, //优惠金额 PreferentialAmount = 0, //优惠后金额 PreferentialEndAmount = 0, //欠款金额 OweCash = 0, //商品项目 Items = Bill.Items, //收款账户 //预收款 AdvanceAmount = 0, //预收款余额 AdvanceAmountBalance = 0, //配送时间 DeliverDate = this.DeliverDate?.Date ?? DateTime.Now, AMTimeRange = this.DeliverDate?.AMTimeRange, PMTimeRange = this.DeliverDate?.PMTimeRange }; return await SubmitAsync(postMData, Bill.Id, _exchangeBillService.CreateOrUpdateAsync, async(result) => { BillId = result.Code; //清空单据 Bill = new ExchangeBillModel(); if (IsVisit) //拜访时开单 { //转向拜访界面 await this.NavigateAsync("VisitStorePage", ("BillTypeId", BillTypeEnum.ExchangeBill), ("BillId", BillId), ("Amount", Bill.SumAmount)); } }, !IsVisit, token: new System.Threading.CancellationToken()); })); },
public AllocationBillPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IDialogService dialogService, IMicrophoneService microphoneService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "调拨单"; _microphoneService = microphoneService; InitBill(); //验证 var valid_IsReversed = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作"); var valid_IsAudited = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_ShipmentWareHouseId = this.ValidationRule(x => x.Bill.ShipmentWareHouseId, _isZero, "出货仓库未指定"); var valid_IncomeWareHouseId = this.ValidationRule(x => x.Bill.IncomeWareHouseId, _isZero, "入货仓库未指定"); var valid_ProductCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目"); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { try { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作!"); return; } if (!valid_ShipmentWareHouseId.IsValid) { _dialogService.ShortAlert(valid_ShipmentWareHouseId.Message[0]); return; } if (!valid_IncomeWareHouseId.IsValid) { _dialogService.ShortAlert(valid_IncomeWareHouseId.Message[0]); return; } if (Bill.ShipmentWareHouseId == Bill.IncomeWareHouseId) { _dialogService.ShortAlert("出入库不能相同!"); return; } //传入当前主库 this.WareHouse.Id = Bill.ShipmentWareHouseId; this.WareHouse.Name = Bill.ShipmentWareHouseName; this.Filter.WareHouseId = Bill.ShipmentWareHouseId; this.Filter.WareHouseName = Bill.ShipmentWareHouseName; //ShipmentWareHouseId //IncomeWareHouseId await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("Bill", Bill), ("Filter", Filter), ("WareHouse", WareHouse), ("SerchKey", Filter.SerchKey)); } catch (Exception ex) { Crashes.TrackError(ex); } }); //编辑商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { try { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (this.Bill.IsSubmitBill) { _dialogService.ShortAlert("已提交的单据不能编辑"); return; } if (item != null) { var product = ProductSeries.Select(p => p).Where(p => p.Id == item.ProductId).FirstOrDefault(); if (product != null) { product.UnitId = item.UnitId; product.Quantity = item.Quantity; product.Remark = item.Remark; product.Subtotal = item.Subtotal; product.UnitName = item.UnitName; product.GUID = item.GUID; if (item.BigUnitId > 0) { product.bigOption.Name = item.UnitName; product.BigPriceUnit.Quantity = item.Quantity; product.BigPriceUnit.UnitId = item.BigUnitId ?? 0; product.BigPriceUnit.Remark = item.Remark; } if (item.SmallUnitId > 0) { product.bigOption.Name = item.UnitName; product.SmallPriceUnit.Quantity = item.Quantity; product.SmallPriceUnit.UnitId = item.SmallUnitId; product.SmallPriceUnit.Remark = item.Remark; } await this.NavigateAsync("EditAllocationProductPage", ("Product", product)); } } } catch (Exception ex) { Crashes.TrackError(ex); } this.Selecter = null; }, ex => _dialogService.ShortAlert(ex.ToString())) .DisposeWith(DeactivateWith); //提交单据 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { return(await this.Access(AccessGranularityEnum.AllocationFormSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return Unit.Default; } if (!valid_ShipmentWareHouseId.IsValid) { this.Alert(valid_ShipmentWareHouseId.Message[0]); return Unit.Default; } if (!valid_IncomeWareHouseId.IsValid) { this.Alert(valid_IncomeWareHouseId.Message[0]); return Unit.Default; } if (!valid_ProductCount.IsValid) { this.Alert(valid_ProductCount.Message[0]); return Unit.Default; } var zero = Bill.Items?.Where(s => s.Quantity == 0).Count() > 0; if (zero) { this.Alert("存在数量为空的调拨商品!"); return Unit.Default; } var postMData = new AllocationUpdateModel() { BillNumber = Bill.BillNumber, ShipmentWareHouseId = Bill.ShipmentWareHouseId, IncomeWareHouseId = Bill.IncomeWareHouseId, CreatedOnUtc = Bill.CreatedOnUtc, AllocationByMinUnit = false, Remark = Bill.Remark, //商品项目 Items = Bill.Items?.ToList(), }; ShowPrintBtn = true; if (IsNeedShowPrompt) { var ok = await _dialogService.ShowConfirmAsync("是否保存并提交吗?", "", "确定", "取消"); if (!ok) { return Unit.Default; } } IsNeedShowPrompt = true; var gr = Bill.AuditedStatus; return await SubmitAsync(postMData, Bill.Id, _wareHousesService.CreateOrUpdateAllocationbillAsync, async(result) => { if (IsNeedPrint) { Bill.BillType = BillTypeEnum.AllocationBill; await SelectPrint((AllocationBillModel)Bill.Clone()); } IsNeedPrint = false; Bill = new AllocationBillModel(); InitBill(); }, gr, token: new System.Threading.CancellationToken()); })); }, this.IsValid()); //存储记录 this.SaveCommand = ReactiveCommand.Create <object>(async e => { if (!this.Bill.AuditedStatus && this.Bill.ShipmentWareHouseId != 0 && this.Bill.ShipmentWareHouseId != Settings.AllocationBill?.ShipmentWareHouseId) { var ok = await _dialogService.ShowConfirmAsync("你是否要保存单据?", "提示", "确定", "取消"); if (ok) { if (!this.Bill.AuditedStatus) { Settings.AllocationBill = this.Bill; } } } await _navigationService.GoBackAsync(); }); //审核 this.AuditingDataCommand = ReactiveCommand.CreateFromTask <object>(async _ => { //是否具有审核权限 await this.Access(AccessGranularityEnum.AllocationFormApproved); await SubmitAsync(Bill.Id, _wareHousesService.AuditingAsync, async(result) => { //红冲审核水印 this.Bill.AuditedStatus = true; var _conn = App.Resolve <ILiteDbService <MessageInfo> >(); var ms = await _conn.Table.FindByIdAsync(SelecterMessage.Id); if (ms != null) { ms.IsRead = true; await _conn.UpsertAsync(ms); } }, token: new System.Threading.CancellationToken()); }, this.WhenAny(x => x.Bill.Id, (x) => x.GetValue() > 0)); //启用麦克风 this.WhenAnyValue(x => x.EnableMicrophone) .Subscribe(async x => { var micAccessGranted = await _microphoneService.GetPermissionsAsync(); if (!micAccessGranted) { this.Alert("请打开麦克风"); } }) .DisposeWith(this.DeactivateWith); //匹配声音 this.RecognitionCommand = ReactiveCommand.Create(() => { RecognitionSpeech((key) => { Filter.SerchKey = key; ((ICommand)this.AddProductCommand)?.Execute(null); }); }); //切换语音助手 this.SpeechCommand = ReactiveCommand.Create(() => { if (IsFooterVisible) { IsVisible = true; IsExpanded = true; IsFooterVisible = false; } else { IsVisible = false; IsExpanded = false; IsFooterVisible = true; } }); //工具栏打印 this.PrintCommand = ReactiveCommand.Create(async() => { await Print(); }); //绑定页面菜单 _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> > { //整单备注 { MenuEnum.REMARK, (m, vm) => { AllRemak((result) => { Bill.Remark = result; }, Bill.Remark); } },
public MainPage() { InitializeComponent(); micService = DependencyService.Resolve <IMicrophoneService>(); }
public ReturnOrderBillPageViewModel(INavigationService navigationService, IReturnReservationBillService returnReservationBillService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IMicrophoneService microphoneService, IDialogService dialogService) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "退货订单"; _returnReservationBillService = returnReservationBillService; //_saleBillService = saleBillService; _microphoneService = microphoneService; InitBill(); //验证 var valid_IsReversed = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作"); var valid_IsAudited = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_TerminalId = this.ValidationRule(x => x.Bill.TerminalId, _isZero, "客户未指定"); var valid_BusinessUserId = this.ValidationRule(x => x.Bill.DeliveryUserId, _isZero, "配送员未指定"); var valid_WareHouseId = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定"); var valid_ProductCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目"); var valid_SelectesCount = this.ValidationRule(x => x.PaymentMethods.Selectes.Count, _isZero, "请选择支付方式"); //初始化 this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { var whs = await _wareHousesService.GetWareHousesAsync(this.BillType, force: true); if (whs != null && whs.FirstOrDefault() != null) { var wh = whs.FirstOrDefault(); if (Bill.WareHouseId == 0) { WareHouse = wh; Bill.WareHouseId = wh.Id; } if (string.IsNullOrEmpty(Bill.WareHouseName)) { Bill.WareHouseName = wh.Name; } if (Bill.Id == 0 && Bill.DeliveryUserId == 0) { Bill.DeliveryUserId = Settings.UserId; Bill.DeliveryUserName = Settings.UserRealName; } } InitPayment(); })); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (!valid_TerminalId.IsValid) { _dialogService.ShortAlert(valid_TerminalId.Message[0]); ((ICommand)CustomSelected)?.Execute(null); return; } if (!valid_WareHouseId.IsValid || WareHouse == null) { _dialogService.ShortAlert(valid_WareHouseId.Message[0]); ((ICommand)StockSelected)?.Execute(null); return; } if (!valid_BusinessUserId.IsValid) { _dialogService.ShortAlert(valid_BusinessUserId.Message[0]); ((ICommand)DeliverSelected)?.Execute(null); return; } await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("TerminalId", Bill.TerminalId), ("Terminaler", this.Terminal), ("SerchKey", Filter.SerchKey)); }); //编辑商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return; } if (this.Bill.AuditedStatus && !this.ReferencePage.Equals("UnDeliveryPage")) { _dialogService.ShortAlert("已审核单据不能操作"); return; } //已提交未审核的可以编辑 if (this.Bill.IsSubmitBill && !this.Bill.AuditedStatus) { _dialogService.ShortAlert("已提交的单据不能编辑"); return; } if (item != null) { var product = ProductSeries.Select(p => p).Where(p => p.Id == item.ProductId).FirstOrDefault(); if (product != null) { product.UnitId = item.UnitId; product.Quantity = item.Quantity; product.Price = item.Price; product.Amount = item.Amount; product.Remark = item.Remark; product.Subtotal = item.Subtotal; product.UnitName = item.UnitName; if (item.BigUnitId > 0) { product.bigOption.Name = item.UnitName; product.BigPriceUnit.Quantity = item.Quantity; product.BigPriceUnit.UnitId = item.BigUnitId; product.BigPriceUnit.Amount = item.Amount; product.BigPriceUnit.Remark = item.Remark; } if (item.SmallUnitId > 0) { product.bigOption.Name = item.UnitName; product.SmallPriceUnit.Quantity = item.Quantity; product.SmallPriceUnit.UnitId = item.SmallUnitId; product.SmallPriceUnit.Amount = item.Amount; product.SmallPriceUnit.Remark = item.Remark; } await this.NavigateAsync("EditProductPage", ("Product", product), ("Reference", PageName), ("Item", item), ("WareHouse", WareHouse)); } } this.Selecter = null; }) .DisposeWith(DeactivateWith); //提交单据 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { return(await this.Access(AccessGranularityEnum.ReturnOrderSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return Unit.Default; } if (IsNeedShowPrompt) { var ok = await _dialogService.ShowConfirmAsync("是否保存并提交吗?", "", "确定", "取消"); if (!ok) { return Unit.Default; } } IsNeedShowPrompt = true; if (Bill.BusinessUserId == 0) { Bill.BusinessUserId = Settings.UserId; } var postMData = new ReturnReservationBillUpdateModel() { BillNumber = this.Bill.BillNumber, //客户 TerminalId = Bill.TerminalId, //业务员 BusinessUserId = Bill.BusinessUserId, //仓库 WareHouseId = Bill.WareHouseId, //交易日期 TransactionDate = DateTime.Now, //默认售价方式 DefaultAmountId = Settings.DefaultPricePlan, //备注 Remark = Bill.Remark, //优惠金额 PreferentialAmount = Bill.PreferentialAmount, //优惠后金额 PreferentialEndAmount = Bill.SumAmount - Bill.PreferentialAmount, //欠款金额 OweCash = Bill.OweCash, //商品项目 Items = Bill.Items?.Where(i => i.Quantity > 0).ToList(), //收款账户 Accounting = PaymentMethods.Selectes.Select(a => { return new AccountMaping() { AccountingOptionId = a.AccountingOptionId, CollectionAmount = a.CollectionAmount, Name = a.Name, BillId = 0, }; }).ToList() }; return await SubmitAsync(postMData, Bill.Id, _returnReservationBillService.CreateOrUpdateAsync, async(result) => { if (IsNeedPrint) { Bill.BillType = BillTypeEnum.SaleBill; await SelectPrint((ReturnReservationBillModel)Bill.Clone()); } IsNeedPrint = false; BillId = result.Code; ClearBillCache(); PaymentMethods.Selectes.Clear(); InitPayment(); if (IsVisit) { //转向拜访界面 //await this.NavigateAsync("VisitStorePage", ("BillTypeId",BillTypeEnum.ReturnReservationBill),("BillId", BillId),("Amount", Bill.SumAmount)); await _navigationService.GoBackAsync(("BillTypeId", BillTypeEnum.ReturnReservationBill), ("BillId", BillId), ("Amount", Bill.SumAmount)); } }, token: new System.Threading.CancellationToken()); })); },
public PurchaseOrderBillPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IPurchaseBillService purchaseBillService, IManufacturerService manufacturerService, IMicrophoneService microphoneService, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "采购单"; _purchaseBillService = purchaseBillService; _manufacturerService = manufacturerService; _microphoneService = microphoneService; InitBill(); //验证 var valid_IsReversed = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作"); var valid_IsAudited = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_ManufacturerId = this.ValidationRule(x => x.Bill.ManufacturerId, _isZero, "供应商未指定"); var valid_WareHouseId = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定"); var valid_ProductCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目"); var valid_SelectesCount = this.ValidationRule(x => x.PaymentMethods.Selectes.Count, _isZero, "请选择支付方式"); //初始化 this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { var whs = await _wareHousesService.GetWareHousesAsync(this.BillType, force: true); if (whs != null && whs.FirstOrDefault() != null) { var wh = whs.FirstOrDefault(); if (Bill.WareHouseId == 0) { WareHouse = wh; Bill.WareHouseId = wh.Id; } if (string.IsNullOrEmpty(Bill.WareHouseName)) { Bill.WareHouseName = wh.Name; } } var result = await _purchaseBillService.GetInitDataAsync(calToken: new System.Threading.CancellationToken()); if (result != null) { var defaultAccs = result.PurchaseBillAccountings.Select(s => new AccountingModel() { Default = true, AccountingOptionId = s.AccountingOptionId, AccountingOptionName = s.AccountingOptionName, AccountCodeTypeId = s.AccountCodeTypeId, Name = s.Name }).ToList(); PaymentMethods.Selectes = new ObservableCollection <AccountingModel>(defaultAccs); } })); //提交单据 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { //await this.Access(AccessGranularityEnum.PurchaseBillsSave); return(await this.Access(AccessGranularityEnum.PurchaseBillsSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return Unit.Default; } var dateTime = UtcHelper.ConvertDateTimeInt(DateTime.Now.ToUniversalTime()); if (Bill.BusinessUserId == 0) { Bill.BusinessUserId = Settings.UserId; } var postMData = new PurchaseItemUpdateModel() { BillNumber = this.Bill.BillNumber, //供应商 ManufacturerId = Bill.ManufacturerId, //业务员 BusinessUserId = Bill.BusinessUserId, //仓库 WareHouseId = Bill.WareHouseId, //交易日期 //TransactionDate = DateTime.Now, TransactionDate = dateTime, //按最小单位采购 IsMinUnitPurchase = true, //备注 Remark = Bill.Remark, //优惠金额 PreferentialAmount = Bill.PreferentialAmount, //优惠后金额 PreferentialEndAmount = Bill.SumAmount - Bill.PreferentialAmount, //欠款金额 OweCash = Bill.OweCash, //商品项目(保存量大于零的商品) Items = Bill.Items?.Where(i => i.Quantity > 0).ToList(), //收款账户 Accounting = PaymentMethods.Selectes.Select(a => { return new AccountMaping() { AccountingOptionId = a.AccountingOptionId, CollectionAmount = a.CollectionAmount, Name = a.Name, BillId = 0, }; }).ToList() }; return await SubmitAsync(postMData, Bill.Id, _purchaseBillService.CreateOrUpdateAsync, (result) => { Bill = new PurchaseBillModel(); }, token: new System.Threading.CancellationToken()); })); }, this.IsValid()); //存储记录 this.SaveCommand = ReactiveCommand.Create <object>(async e => { var c1 = this.Bill.ManufacturerId != 0 && this.Bill.ManufacturerId != (Settings.PurchaseBill?.ManufacturerId ?? 0); var c3 = this.Bill.WareHouseId != 0 && this.Bill.WareHouseId != (Settings.PurchaseBill?.WareHouseId ?? 0); var c4 = this.Bill.Items?.Count != (Settings.PurchaseBill?.Items?.Count ?? 0); if (!this.Bill.AuditedStatus && (c1 || c3 || c4)) { if (!this.Bill.AuditedStatus && !this.Bill.IsSubmitBill) { var ok = await _dialogService.ShowConfirmAsync("你是否要保存单据?", "提示", "确定", "取消"); if (ok) { Settings.PurchaseBill = this.Bill; } else { await _navigationService.GoBackAsync(); } } } else { await _navigationService.GoBackAsync(); } }); //商品编辑 this.ItemSelectedCommand = ReactiveCommand.Create <CollectionView>(async e => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (this.Bill.IsSubmitBill) { _dialogService.ShortAlert("已提交的单据不能编辑"); return; } if (e.SelectedItem != null) { var item = Selecter; if (item != null) { var product = ProductSeries.Select(p => p).Where(p => p.Id == item.ProductId).FirstOrDefault(); if (product != null) { product.UnitId = item.UnitId; product.Quantity = item.Quantity; product.Price = item.Price; product.Amount = item.Amount; product.Remark = item.Remark; product.Subtotal = item.Subtotal; product.UnitName = item.UnitName; product.GUID = item.GUID; if (item.BigUnitId > 0) { product.bigOption.Name = item.UnitName; product.BigPriceUnit.Quantity = item.Quantity; product.BigPriceUnit.UnitId = item.BigUnitId ?? 0; product.BigPriceUnit.Amount = item.Amount; product.BigPriceUnit.Remark = item.Remark; } if (item.SmallUnitId > 0) { product.bigOption.Name = item.UnitName; product.SmallPriceUnit.Quantity = item.Quantity; product.SmallPriceUnit.UnitId = item.SmallUnitId ?? 0; product.SmallPriceUnit.Amount = item.Amount; product.SmallPriceUnit.Remark = item.Remark; } await this.NavigateAsync("EditProductPage", ("Product", product), ("Reference", PageName), ("Item", item), ("WareHouse", WareHouse)); } } } }); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (!valid_IsAudited.IsValid) { _dialogService.ShortAlert("已审核单据不能操作!"); return; } if (!valid_ManufacturerId.IsValid) { _dialogService.ShortAlert("请选择供应商!"); ((ICommand)ManufacturerSelected)?.Execute(null); return; } if (!valid_WareHouseId.IsValid || WareHouse == null) { _dialogService.ShortAlert("请选择仓库!"); ((ICommand)StockSelected)?.Execute(null); return; } await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("ManufacturerId", Bill.ManufacturerId), ("SerchKey", Filter.SerchKey)); }); //审核 this.AuditingDataCommand = ReactiveCommand.CreateFromTask <object>(async _ => { //是否具有审核权限 await this.Access(AccessGranularityEnum.PurchaseBillsApproved); await SubmitAsync(Bill.Id, _purchaseBillService.AuditingAsync, async(result) => { //红冲审核水印 this.Bill.AuditedStatus = true; var _conn = App.Resolve <ILiteDbService <MessageInfo> >(); var ms = await _conn.Table.FindByIdAsync(SelecterMessage.Id); if (ms != null) { ms.IsRead = true; await _conn.UpsertAsync(ms); } }); }, this.WhenAny(x => x.Bill.Id, (x) => x.GetValue() > 0)); //启用麦克风 this.WhenAnyValue(x => x.EnableMicrophone) .Subscribe(async x => { var micAccessGranted = await _microphoneService.GetPermissionsAsync(); if (!micAccessGranted) { this.Alert("请打开麦克风"); } }).DisposeWith(DeactivateWith); //匹配声音 this.RecognitionCommand = ReactiveCommand.Create(() => { if (!valid_ManufacturerId.IsValid) { _dialogService.ShortAlert("请选择供应商!"); return; } if (!valid_WareHouseId.IsValid) { _dialogService.ShortAlert("请选择仓库!"); return; } RecognitionSpeech((key) => { Filter.SerchKey = key; ((ICommand)this.AddProductCommand)?.Execute(null); }); }); //切换语音助手 this.SpeechCommand = ReactiveCommand.Create(() => { if (IsFooterVisible) { IsVisible = true; IsExpanded = true; IsFooterVisible = false; } else { IsVisible = false; IsExpanded = false; IsFooterVisible = true; } }); //工具栏打印 this.PrintCommand = ReactiveCommand.Create(async() => { if (Bill.Items.Count == 0) { Alert("请添加商品项目"); return; } Bill.BillType = BillTypeEnum.PurchaseBill; await SelectPrint(Bill); }); //绑定页面菜单 _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> > { //支付方式 { MenuEnum.PAY, (m, vm) => { if (Bill.SumAmount == 0) { this.Alert("请添加商品项目!"); return; } PaymentMethodBaseModel payments = this.PaymentMethods; SelectPaymentMethods(("PaymentMethods", payments), ("TBalance", this.TBalance), ("BillType", this.BillType), ("Reference", PageName)); } },