public override int GetHashCode() { int hashCode = ProductSeries.GetHashCode(); hashCode ^= Model; // Xor (eXclusive OR) hashCode ^= Id.GetHashCode(); // Xor (eXclusive OR) return(hashCode); }
public ActionResult Product(int id) { ProductSeries ps = new ProductSeries(); using (SqlConnection conn = DB.GetConnection()) ps = conn.Query <ProductSeries>("MVCProductSeries", new { SeriesID = id }, commandType: System.Data.CommandType.StoredProcedure).FirstOrDefault(); ps.GetProducts(); return(View(ps)); }
private InvoiceXmlSeries Map(ProductSeries entity) { return(new InvoiceXmlSeries { SerijaTovara = entity.Code, NomerSertif = entity.CertificateCode, OrganSertif = entity.CertificateAuthority, DataVydachiSertif = entity.CertificateIssueDate, SrokDejstvijaSertif = entity.CertificateExpireDate, SrokGodnostiTovara = entity.ShelfLifeDate, RegNomer = "_", RegNomerSertif = entity.RegionalCertificateCode, RegDataSertif = entity.RegionalCertificateIssueDate, RegOrganSertif = entity.RegionalCertificateAuthority }); }
public override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); try { if (parameters.ContainsKey("Bill")) { if (ReferencePage.Equals("AllocationBillPage")) { this.ShowGift = false; parameters.TryGetValue("Bill", out AllocationBillModel bill); if (bill != null) { this.Bill = bill; } } } if (ReferencePage == "InventoryOPBillPage") { ShowStockQty = false; ShowGift = false; } if (ReferencePage == "PurchaseOrderBillPage") { ShowStockQty = true; ShowGift = false; } //盘点单 if (ReferencePage == "InventoryOPBillPage") { ProductSeries.ToList().ForEach(p => { TempProductSeries.Add(p); }); } } catch (Exception ex) { Crashes.TrackError(ex); } }
public override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); try { if (parameters.ContainsKey("InventoryReportItemModel")) { parameters.TryGetValue <InventoryReportItemModel>("InventoryReportItemModel", out InventoryReportItemModel storeReporting); if (storeReporting != null) { StoreReporting = storeReporting; ReportStoreQuantities = storeReporting.InventoryReportStoreQuantities; } } if (parameters.ContainsKey("Products")) { parameters.TryGetValue <List <ProductModel> >("Products", out List <ProductModel> products); if (products != null) { ProductSeries = new ObservableCollection <ProductModel>(products); } } var product = ProductSeries.FirstOrDefault(); if (product != null) { StoreReporting = new InventoryReportItemModel() { ProductId = product.Id, ProductName = product.Name, BigUnitId = product.BigPriceUnit.UnitId, BigUnitName = product.BigPriceUnit.UnitName, SmallUnitId = product.SmallPriceUnit.UnitId, SmallUnitName = product.SmallPriceUnit.UnitName }; } } catch (Exception ex) { Crashes.TrackError(ex); } }
public override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); try { if (parameters.ContainsKey("Products")) { parameters.TryGetValue("Products", out List <ProductModel> products); if (products != null) { ProductSeries = new ObservableCollection <ProductModel>(products); } } if (parameters.ContainsKey("Bill")) { if (ReferencePage.Equals("AllocationBillPage")) { parameters.TryGetValue("Bill", out AllocationBillModel Bill); if (Bill != null) { foreach (var p in ProductSeries.ToList()) { var outs = p.StockQuantities.Where(q => q.WareHouseId == Bill.ShipmentWareHouseId).FirstOrDefault(); var ins = p.StockQuantities.Where(q => q.WareHouseId == Bill.IncomeWareHouseId).FirstOrDefault(); p.ShipmentUsableQuantity = outs != null ? outs.UsableQuantity : 0; p.IncomeUsableQuantity = ins != null ? ins.UsableQuantity : 0; } } } } } catch (Exception ex) { Crashes.TrackError(ex); } }
public void MonthProductChange(string item) { int index = MonthRevenueLabels.IndexOf(item); ObservableCollection <string[]> result = AdvancedQuery.GetProductRevenue(revenue_month[index], revenue_year[index]); ProductSeries.Clear(); // Debug log for (int i = 0; i < result.Count; i++) { ProductSeries.Add ( new PieSeries { Title = result[i][1] + " (" + result[i][2] + ")", Values = new ChartValues <ObservableValue> { new ObservableValue(Double.Parse(result[i][3])) }, DataLabels = true } ); } }
public TrackAllocationBillPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "装车调拨"; InitBill(); //验证 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, "请添加商品项目"); var valid_IsVieweBill = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (Bill.ShipmentWareHouseId == 0) { _dialogService.ShortAlert(valid_ShipmentWareHouseId.Message[0]); return; } if (Bill.IncomeWareHouseId == 0) { _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; await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("Bill", Bill), ("Filter", Filter), ("WareHouse", WareHouse), ("SerchKey", Filter.SerchKey)); }); //编辑商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { 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; 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)); } } this.Selecter = null; }, ex => _dialogService.ShortAlert(ex.ToString())) .DisposeWith(DeactivateWith); //提交单据 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { //await this.Access(AccessGranularityEnum.TrackSchedulingScheduling); return(await this.Access(AccessGranularityEnum.TrackSchedulingScheduling, async() => { 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 postMData = new AllocationUpdateModel() { BillNumber = this.Bill.BillNumber, ShipmentWareHouseId = Bill.ShipmentWareHouseId, IncomeWareHouseId = Bill.IncomeWareHouseId, CreatedOnUtc = Bill.CreatedOnUtc, AllocationByMinUnit = false, Remark = Bill.Remark, //商品项目 Items = Bill.Items?.Where(i => i.Quantity > 0).ToList(), }; return await SubmitAsync(postMData, Bill.Id, _wareHousesService.CreateOrUpdateAllocationbillAsync, (result) => { Bill = new AllocationBillModel(); }); })); }, this.IsValid()); //绑定页面菜单 _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> > { //整单备注 { MenuEnum.REMARK, (m, vm) => { AllRemak((result) => { Bill.Remark = result; }, Bill.Remark); } },
public AddProductPageViewModel( INavigationService navigationService, IDialogService dialogService ) : base(navigationService, dialogService) { Title = "添加商品"; CompanySetting = JsonConvert.DeserializeObject <CompanySettingModel>(Settings.CompanySetting); //更改重算 this.BigEntryUnfocused = ReactiveCommand.Create <ProductModel>((p) => { CalcChanged(p, 0); }); this.SmallEntryUnfocused = ReactiveCommand.Create <ProductModel>((p) => { CalcChanged(p, 1); }); //选择价格 this.SmallPriceSelected = ReactiveCommand.Create <int>((pid) => { CalcSmallPrice(pid); }); this.BigPriceSelected = ReactiveCommand.Create <int>((pid) => { CalcBigPrice(pid); }); //保存 this.SaveCommand = ReactiveCommand.Create(async() => { try { bool vaildQuantity = false; bool vaildBigPrice = false; bool vaildSmallPrice = false; bool vaildBigQuantity = false; bool vaildSmallQuantity = false; bool vaildGiftQuantity = false; if (!string.IsNullOrEmpty(ReferencePage)) { //数量 ProductSeries.ToList().ForEach(p => { vaildQuantity = (p.BigPriceUnit.Quantity == 0 || p.SmallPriceUnit.Quantity == 0); if (vaildQuantity) { return; } }); //赠送 ProductSeries.ToList().ForEach(p => { vaildGiftQuantity = (p.GiveProduct.BigUnitQuantity == 0 && p.GiveProduct.SmallUnitQuantity == 0); if (vaildGiftQuantity) { return; } }); //大单位 ProductSeries.ToList().ForEach(p => { vaildBigPrice = (p.BigPriceUnit.Quantity > 0 && (p.BigPriceUnit?.Price == null || p.BigPriceUnit?.Price < 0)); if (vaildBigPrice) { return; } }); ProductSeries.ToList().ForEach(p => { vaildBigQuantity = (p.BigPriceUnit.Quantity <= 0); if (vaildBigQuantity) { return; } }); //小单位 ProductSeries.ToList().ForEach(p => { vaildSmallPrice = (p.SmallPriceUnit.Quantity > 0 && (p.SmallPriceUnit?.Price == null || p.SmallPriceUnit?.Price < 0)); if (vaildSmallPrice) { return; } }); ProductSeries.ToList().ForEach(p => { vaildSmallQuantity = (p.SmallPriceUnit.Quantity <= 0); if (vaildSmallQuantity) { return; } }); if (vaildGiftQuantity) { if (vaildBigQuantity && vaildSmallQuantity) { this.Alert("商品数量不能为空"); return; } } if (vaildBigQuantity && !vaildBigPrice && !vaildQuantity) { this.Alert("商品大单位数量不能为空"); return; } if (vaildBigPrice && !vaildBigQuantity && !vaildQuantity) { this.Alert("商品大单位价格不能为空"); return; } if (vaildSmallQuantity && !vaildSmallPrice && !vaildQuantity) { this.Alert("商品小单位数量不能为空"); return; } if (vaildSmallPrice && !vaildSmallQuantity && !vaildQuantity) { this.Alert("商品小单位价格不能为空"); return; } var products = ProductSeries.Where(s => s.BigPriceUnit.Quantity > 0 && s.BigPriceUnit.Price >= 0 || s.SmallPriceUnit.Quantity > 0 && s.SmallPriceUnit.Price >= 0 || s.GiveProduct.BigUnitQuantity > 0 || s.GiveProduct.SmallUnitQuantity >= 0).ToList(); //转向引用页 var redirectPage = $"../../"; await this.NavigateAsync(redirectPage, ("ProductSeries", products)); } } catch (Exception ex) { Crashes.TrackError(ex); } }); //移除商品 this.RemoveCommend = ReactiveCommand.Create <int>(async(pid) => { try { var porductId = pid; var products = ProductSeries; var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); if (product != null) { products.Remove(product); } ProductSeries = new ObservableCollection <ProductModel>(products); if (products.Count == 0) { await _navigationService.GoBackAsync(); } } catch (Exception ex) { Crashes.TrackError(ex); } }); //拷贝商品 this.CopyCommend = ReactiveCommand.Create <int>((pid) => { try { var porductId = pid; var products = ProductSeries; var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); if (product != null) { var newModel = new ProductModel { Id = product.Id, ProductId = product.Id, ProductName = product.ProductName, Name = product.Name, UnitId = product.UnitId, Quantity = product.Quantity, Price = product.Price, Amount = product.Amount, Remark = product.Remark, Subtotal = product.Subtotal, StockQty = product.StockQty, UnitConversion = product.UnitConversion, UnitName = product.UnitName, Units = product.Units, BigPriceUnit = new PriceUnit() { Amount = product.BigPriceUnit.Amount, Price = product.BigPriceUnit.Price, Quantity = product.BigPriceUnit.Quantity, Remark = product.BigPriceUnit.Remark, UnitId = product.BigPriceUnit.UnitId, UnitName = product.BigPriceUnit.UnitName }, SmallPriceUnit = new PriceUnit() { Amount = product.SmallPriceUnit.Amount, Price = product.SmallPriceUnit.Price, Quantity = product.SmallPriceUnit.Quantity, Remark = product.SmallPriceUnit.Remark, UnitId = product.SmallPriceUnit.UnitId, UnitName = product.SmallPriceUnit.UnitName } }; newModel.BigPriceUnit.UnitId = product.BigUnitId ?? 0; newModel.SmallPriceUnit.UnitId = product.SmallUnitId ?? 0; products.Add(newModel); } ProductSeries = new ObservableCollection <ProductModel>(products); } catch (Exception ex) { Crashes.TrackError(ex); } }); }
public async void CalcSmallPrice(int porductId) { try { var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); var _dialogView = new PopRadioButtonPage("选择价格", "", () => { var popDatas = new List <PopData>(); if (product != null) { var tierprices = product.ProductTierPrices; if (tierprices != null) { #region //默认条件 int pId = 0; int pTId = 0; var pArry = Settings.DefaultPricePlan.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList(); if (pArry.Count > 0) { pId = pArry[0]; pTId = pArry[1]; } switch (pTId) { case (int)PriceType.ProductCost: { var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 0); popDatas.Add(new PopData() { Id = (int)PriceType.ProductCost, Column = "进价", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.CostPrice: { //成本价 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 5); popDatas.Add(new PopData() { Id = (int)PriceType.CostPrice, Column = "成本价", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.WholesalePrice: { //批发价格 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 1); popDatas.Add(new PopData() { Id = (int)PriceType.WholesalePrice, Column = "批发价格", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.RetailPrice: { //零售价格 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 2); popDatas.Add(new PopData() { Id = (int)PriceType.RetailPrice, Column = "零售价格", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.LowestPrice: { //最低售价 var price = tierprices.FirstOrDefault(s => s.PriceTypeId == 3); popDatas.Add(new PopData() { Id = (int)PriceType.LowestPrice, Column = "最低售价", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } break; case (int)PriceType.CustomPlan: { //方案价格 int i = 0; foreach (var price in tierprices.Where(s => new int[] { (int)PriceType.CustomPlan }.Contains(s.PriceTypeId)).ToList()) { popDatas.Add(new PopData() { Id = (int)PriceType.CustomPlan + i, Column = price?.PriceTypeName, Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); i++; } } break; case (int)PriceType.LastedPrice: { //上次价格 var price = product.ProductTierPrices.Where(s => s.PriceTypeId == (int)PriceType.LastedPrice).FirstOrDefault(); if (price != null) { popDatas.Add(new PopData() { Id = (int)PriceType.CustomPlan, Column = "上次价格", Column1 = price?.SmallUnitPrice.ToString(), Column1Enable = true, Data = price?.SmallUnitPrice ?? 0 }); } } break; } #endregion } } return(Task.FromResult(popDatas)); }); _dialogView.Completed += (sender, result) => { if (result != null) { product.SmallPriceUnit.Price = (decimal)(result?.Data ?? decimal.Zero); product.SmallPriceUnit.Amount = (decimal)(result?.Data ?? decimal.Zero) * product?.SmallPriceUnit?.Quantity ?? 0; } }; await PopupNavigation.Instance.PushAsync(_dialogView); } catch (Exception ex) { Crashes.TrackError(ex); } }
/// <summary> /// 输入值更改时 /// </summary> public void CalcChanged(ProductModel curProduct, int type) { try { var pid = curProduct?.Id ?? 0; if (curProduct != null) { var bigPrice = curProduct?.BigPriceUnit?.Price ?? 0; var smallPrice = curProduct?.SmallPriceUnit?.Price ?? 0; if (type == 0) { var bp = curProduct?.BigQuantity ?? 0; if (bp > 0) { var sp = bigPrice / bp; curProduct.SmallPriceUnit.Price = decimal.Round(sp, 4, MidpointRounding.AwayFromZero); } } else if (type == 1) { var bp = curProduct?.BigQuantity ?? 0; var sp = smallPrice * bp; curProduct.BigPriceUnit.Price = decimal.Round(sp, 4, MidpointRounding.AwayFromZero); } } ProductSeries.ForEach(product => { if (product != null) { //采购单时 if (ReferencePage.Equals("PurchaseOrderBillPage")) { //大单位价格 product.BigPriceUnit.Amount = product.BigPriceUnit.Quantity * product.BigPriceUnit.Price; if ((product.BigQuantity ?? 0) == 0) { product.BigQuantity = 1; } var price = (product.BigQuantity ?? 0) != 0 ? (product.BigPriceUnit.Price / product.BigQuantity == 0 ? 1 : product.BigQuantity) : 0; var amount = product.SmallPriceUnit.Quantity * product.SmallPriceUnit.Price; //小单位价格 product.SmallPriceUnit.Price = decimal.Round((price ?? 0), 4, MidpointRounding.AwayFromZero); product.SmallPriceUnit.Amount = decimal.Round((amount != 0 ? amount : 0), 4, MidpointRounding.AwayFromZero); } else { var ba = product.BigPriceUnit.Quantity * product.BigPriceUnit.Price; var sa = product.SmallPriceUnit.Quantity * product.SmallPriceUnit.Price; //大单位价格 product.BigPriceUnit.Amount = decimal.Round((ba != 0 ? ba : 0), 4, MidpointRounding.AwayFromZero); //小单位价格 product.SmallPriceUnit.Amount = decimal.Round((sa != 0 ? sa : 0), 4, MidpointRounding.AwayFromZero); } } }); } catch (Exception ex) { Crashes.TrackError(ex); } }
public CostContractBillPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, ICostContractService costContractService, IDialogService dialogService) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "费用合同"; _costContractService = costContractService; this.BillType = BillTypeEnum.CostContractBill; 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.CustomerId, _isZero, "客户未指定"); var valid_AccountingOptionId = this.ValidationRule(x => x.Bill.AccountingOptionId, _isZero, "费用类型未指定"); var valid_ItemCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "合同项目为空,请先添加"); //编辑 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async x => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return; } if (x != null) { var product = ProductSeries.Select(p => p).Where(p => p.ProductId == x.ProductId).FirstOrDefault(); if (product != null) { product.UnitId = x.UnitId ?? 0; product.Quantity = x.TotalQuantity; product.Remark = x.Remark; product.UnitName = x.UnitName; if (x.BigUnitId > 0) { product.Id = x.Id; product.bigOption.Name = x.UnitName; product.BigPriceUnit.Quantity = x.TotalQuantity; product.BigPriceUnit.Remark = x.Remark; product.BigPriceUnit.UnitId = x.BigUnitId ?? 0; } if (x.SmallUnitId > 0) { product.Id = x.Id; product.bigOption.Name = x.UnitName; product.SmallPriceUnit.Quantity = x.TotalQuantity; product.SmallPriceUnit.Remark = x.Remark; product.SmallPriceUnit.UnitId = x.SmallUnitId ?? 0; } await this.NavigateAsync("EditAllocationProductPage", ("Product", product)); } } this.Selecter = null; }, ex => _dialogService.ShortAlert(ex.ToString())) .DisposeWith(DeactivateWith); //提交单据 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { return(await this.Access(AccessGranularityEnum.CostContractSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作"); return Unit.Default; } if (Bill.CustomerId == 0) { Bill.CustomerId = Settings.UserId; } var postData = new CostContractUpdateModel() { BillNumber = this.Bill.BillNumber, EmployeeId = Settings.UserId, CustomerId = Bill.CustomerId, AccountingOptionId = Bill.AccountingOptionId, Year = DateTime.Now.Year, Month = DateTime.Now.Month, ContractType = 1, //按单位量总计兑付 SaleRemark = Bill.SaleRemark, Remark = Bill.Remark, Items = Bill.Items }; return await SubmitAsync(postData, Bill.Id, _costContractService.CreateOrUpdateAsync, (result) => { Bill = new CostContractBillModel(); }, token: new System.Threading.CancellationToken()); })); }, this.IsValid()); //存储记录 this.SaveCommand = ReactiveCommand.Create <object>(async e => { if (!this.Bill.AuditedStatus && this.Bill.CustomerId != 0 && this.Bill.CustomerId != Settings.CostContractBill?.CustomerId) { var ok = await _dialogService.ShowConfirmAsync("你是否要保存单据?", "提示", "确定", "取消"); if (ok) { if (!this.Bill.AuditedStatus) { Settings.CostContractBill = this.Bill; } } } await _navigationService.GoBackAsync(); }); //费用选择 this.AccountingSelected = ReactiveCommand.Create <object>(async e => { if (!valid_TerminalId.IsValid) { this.Alert(valid_TerminalId.Message[0]); return; } await SelectCostAccounting((data) => { Bill.AccountingOptionId = data.AccountingOptionId; Bill.AccountingOptionName = data.Name; }, BillTypeEnum.CostContractBill); }); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (!valid_TerminalId.IsValid) { this.Alert(valid_TerminalId.Message[0]); return; } if (!valid_AccountingOptionId.IsValid) { this.Alert(valid_AccountingOptionId.Message[0]); return; } if (!valid_IsAudited.IsValid) { this.Alert(valid_IsAudited.Message[0]); return; } await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("SerchKey", Filter.SerchKey)); }); //审核 this.AuditingDataCommand = ReactiveCommand.Create <object>(async _ => { //是否具有审核权限 await this.Access(AccessGranularityEnum.CostContractApproved); await SubmitAsync(Bill.Id, _costContractService.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)); //绑定页面菜单 _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> > { //整单备注 { MenuEnum.REMARK, (m, vm) => { AllRemak((result) => { Bill.Remark = result; }, Bill.Remark); } }, //清空单据 { MenuEnum.CLEAR, (m, vm) => { ClearBill <CostContractBillModel, CostContractItemModel>(Bill, DoClear); } }, //销售备注 { MenuEnum.SALEREMARK, (m, vm) => { AllRemak((result) => { Bill.SaleRemark = result; }, Bill.SaleRemark); } } }); }
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 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)); } },
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 ProductArchivesPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "商品档案"; _navigationService = navigationService; _dialogService = dialogService; _terminalService = terminalService; _productService = productService; _userService = userService; _wareHousesService = wareHousesService; _accountingService = accountingService; //搜索 this.WhenAnyValue(x => x.Filter.SerchKey) .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s) .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler) .Subscribe(s => { ((ICommand)SerchCommand)?.Execute(s); }).DisposeWith(DeactivateWith); this.SerchCommand = ReactiveCommand.Create <string>(e => { if (string.IsNullOrEmpty(Filter.SerchKey)) { this.Alert("请输入关键字!"); return; } ((ICommand)Load)?.Execute(null); }); this.Load = ProductSeriesLoader.Load(async() => { //重载时排它 ItemTreshold = 1; var items = await GetProductsPage(0, PageSize); //清除列表 ProductSeries?.Clear(); if (items != null && items.Any()) { foreach (var item in items) { if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0) { ProductSeries.Add(item); } } } if (ProductSeries.Count > 0) { this.ProductSeries = new System.Collections.ObjectModel.ObservableCollection <ProductModel>(ProductSeries); } return(ProductSeries); }); //以增量方式加载数据 this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() => { int pageIdex = ProductSeries.Count / PageSize; using (var dig = UserDialogs.Instance.Loading("加载中...")) { try { var items = await GetProductsPage(pageIdex, PageSize); var previousLastItem = ProductSeries.Last(); if (items != null) { foreach (var item in items) { if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0) { ProductSeries.Add(item); } } if (items.Count() == 0 || items.Count() == ProductSeries.Count) { ItemTreshold = -1; //return this.ProductSeries; } } } catch (Exception ex) { Crashes.TrackError(ex); ItemTreshold = -1; } } }, this.WhenAny(x => x.ProductSeries, x => x.GetValue().Count > 0)); //选择商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { await this.NavigateAsync("AddProductArchivePage", ("Product", item)); Selecter = null; }).DisposeWith(DeactivateWith); this.AddCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("AddProductArchivePage")); this.CatagorySelected = ReactiveCommand.Create <object>(async e => { await SelectCatagory((data) => { Filter.CatagoryId = data.Id; Filter.CatagoryName = data.Name; Filter.CatagoryIds = new int[] { data.Id }; }); }); this.BindBusyCommand(Load); this.Load.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.SerchCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.ItemTresholdReachedCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.AddCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.CatagorySelected.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); }
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 InventoryOPBillPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IInventoryService inventoryService, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "盘点单"; _inventoryService = inventoryService; this.BillType = BillTypeEnum.InventoryPartTaskBill; this.Bill = new InventoryPartTaskBillModel() { BillTypeId = (int)this.BillType, InventoryPerson = Settings.UserId, BillNumber = CommonHelper.GetBillNumber(CommonHelper.GetEnumDescription(BillType).Split(',')[1], Settings.StoreId) }; //验证 var valid_IsReversed = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作"); var valid_IsAudited = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_WareHouseId = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定"); var valid_InventoryPerson = this.ValidationRule(x => x.Bill.InventoryPerson, _isZero, "盘点人未指定"); var valid_IsVieweBill = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_ProductCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目"); //初始化 this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { var result = await _inventoryService.GetInventoryPartTaskBillAsync(Bill.Id, calToken: new System.Threading.CancellationToken()); if (result != null) { UpdateUI(result); } })); //删除选择 this.DeleteCommand = ReactiveCommand.Create <object>(e => { int productId = (int)e; var product = Bill.Items?.Select(p => p).Where(p => p.ProductId == productId).FirstOrDefault(); if (product != null) { Bill.Items?.Remove(product); var lists = Bill.Items; Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (!valid_WareHouseId.IsValid) { this.Alert(valid_WareHouseId.Message[0]); return; } if (!valid_InventoryPerson.IsValid) { this.Alert(valid_InventoryPerson.Message[0]); return; } if (!valid_IsVieweBill.IsValid) { this.Alert(valid_IsVieweBill.Message[0]); return; } await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("Products", ProductSeries.ToList())); }); //选择仓库 this.StockSelected = ReactiveCommand.Create <object>(async e => { await SelectStock(async(result) => { if (result != null && WareHouse != null && Bill != null) { WareHouse.Id = result.Id; WareHouse.Name = result.Column; Bill.WareHouseId = result.Id; Bill.WareHouseName = result.Column; var pendings = await _inventoryService.CheckInventoryAsync(result.Id, new System.Threading.CancellationToken()); if (pendings != null && pendings.Any()) { WareHouse.Id = 0; WareHouse.Name = ""; Bill.WareHouseId = 0; Bill.WareHouseName = ""; this.Alert("库存正在盘点中,不能在生成盘点单!"); return; } } }, BillTypeEnum.InventoryAllTaskBill); }); //保存盘点 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { return(await this.Access(AccessGranularityEnum.InventoryAllSave, async() => { if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return Unit.Default; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return Unit.Default; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return Unit.Default; } var postMData = new InventoryPartTaskUpdateModel() { BillNumber = this.Bill.BillNumber, InventoryPerson = Bill.InventoryPerson, WareHouseId = Bill.WareHouseId, InventoryDate = DateTime.Now, Items = Bill.Items }; var confirm = await _dialogService.ShowConfirmAsync("确认保存盘点吗?", okText: "确定", cancelText: "取消"); if (confirm) { return await SubmitAsync(postMData, Bill.Id, _inventoryService.CreateOrUpdateAsync, (result) => { Bill.Id = result.Return; Bill.InventoryPerson = postMData.InventoryPerson; Bill.WareHouseId = postMData.WareHouseId; }, false, token: new System.Threading.CancellationToken()); } else { return Unit.Default; } })); }, this.IsValid()); //放弃盘点 this.CancelCommand = ReactiveCommand.CreateFromTask <object>(async e => { if (Bill.Id == 0) { this.Alert("操作失败,你需要先保存盘点!"); return; } if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return; } var confirm = await _dialogService.ShowConfirmAsync("确认放弃盘点吗?", okText: "确定", cancelText: "取消"); if (confirm) { await _inventoryService.CancelTakeInventoryAsync(Bill.Id, new System.Threading.CancellationToken()); } }); //完成确认 this.CompletedCommand = ReactiveCommand.CreateFromTask <object>(async e => { if (Bill.Id == 0) { this.Alert("操作失败,你需要先保存盘点!"); return; } if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return; } var confirm = await _dialogService.ShowConfirmAsync("确认完成盘点吗?", okText: "确定", cancelText: "取消"); if (confirm) { if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return; } var result = await _inventoryService.SetInventoryCompletedAsync(Bill.Id, new System.Threading.CancellationToken()); if (!result) { this.Alert("抱歉,系统错误,请反馈技术支持!"); } } }); //编辑商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { if (this.Bill.IsSubmitBill) { _dialogService.ShortAlert("已提交的单据不能编辑"); return; } if (item != null) { List <ProductModel> products = null; var product = new ProductModel() { Name = item.ProductName, ProductName = item.ProductName, ProductId = item.ProductId, BigPriceUnit = new PriceUnit() { UnitId = item.BigUnitId ?? 0, Quantity = item.BigQuantity ?? 0, UnitName = item.bigOption.Name }, SmallPriceUnit = new PriceUnit() { UnitId = item.SmallUnitId, Quantity = item.SmallUnitQuantity ?? 0, UnitName = item.smallOption.Name }, StockQty = item.StockQty, UnitConversion = item.UnitConversion }; products.Add(product); await this.NavigateAsync("AddInventoryProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("Products", products)); } }) .DisposeWith(DeactivateWith); //扫码商品 this.ScanBarCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("ScanBarcodePage", ("action", "add"))); //绑定页面菜单 _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> > { //全部 { Enums.MenuEnum.ALL, (m, vm) => { var lists = Bill.Items?.ToList(); Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }, //未盘点 { MenuEnum.WART, (m, vm) => { var lists = Bill.Items?.Where(s => string.IsNullOrEmpty(s.StatusName)).ToList(); Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }, //已盘点 { MenuEnum.YPD, (m, vm) => { var lists = Bill.Items?.Where(s => !string.IsNullOrEmpty(s.StatusName)).ToList(); Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }, //整单备注 { MenuEnum.REMARK, (m, vm) => { AllRemak((result) => { Bill.Remark = result; }, Bill.Remark); } }, //历史单据 { MenuEnum.HISTORY, async(m, vm) => { await SelectHistory(); } } }); this.BindBusyCommand(Load); }
public SelectProductPageViewModel(INavigationService navigationService, IProductService productService, IDialogService dialogService) : base(navigationService, dialogService) { Title = "选择商品"; _navigationService = navigationService; _dialogService = dialogService; _productService = productService; //只显库存商品 this.WhenAnyValue(x => x.UsableQuantity) .Skip(1) .Subscribe(s => { ((ICommand)Load)?.Execute(null); this.ForceRefresh = true; }).DisposeWith(DeactivateWith); //我的收藏 this.WhenAnyValue(x => x.UsableFavorite) .Skip(1) .Subscribe(s => { ((ICommand)Load)?.Execute(null); this.ForceRefresh = true; }).DisposeWith(DeactivateWith); //搜索 this.WhenAnyValue(x => x.Filter.SerchKey) .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s) .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler) .Subscribe(s => { ((ICommand)SerchCommand)?.Execute(s); }).DisposeWith(DeactivateWith); this.SerchCommand = ReactiveCommand.Create <string>(e => { if (string.IsNullOrEmpty(Filter.SerchKey)) { this.Alert("请输入关键字!"); return; } ((ICommand)Load)?.Execute(null); }); //Load this.Load = ReactiveCommand.Create(async() => { try { ItemTreshold = 1; DataVewEnable = false; NullViewEnable = true; var items = await GetProductsPage(0, 50); if (items != null && items.Any()) { //清除列表 ProductSeries?.Clear(); foreach (var item in items) { if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0) { ProductSeries.Add(item); } } } } catch (Exception ex) { Crashes.TrackError(ex); } finally { DataVewEnable = true; NullViewEnable = false; } }); //以增量方式加载数据 this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() => { using (var dig = UserDialogs.Instance.Loading("加载中...")) { try { int pageIdex = ProductSeries.Count / 50; var items = await GetProductsPage(pageIdex, PageSize); var previousLastItem = ProductSeries.Last(); if (items != null) { foreach (var item in items) { if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0) { ProductSeries.Add(item); } } if (items.Count() == 0 || items.Count() == ProductSeries.Count) { ItemTreshold = -1; } } } catch (Exception ex) { Crashes.TrackError(ex); ItemTreshold = -1; } } }, this.WhenAny(x => x.ProductSeries, x => x.GetValue().Count > 0)); //初始类别 this.InitCatagory = ReactiveCommand.CreateFromTask(async() => { try { var result = await _productService.GetAllCategoriesAsync(true, new System.Threading.CancellationToken()); if (result != null && result.Any()) { var categories = result.ToList(); if (categories != null && categories.Any()) { foreach (var op in categories) { op.SelectedCommand = ReactiveCommand.Create <int>(r => { op.Selected = !op.Selected; }); } this.BindCategories = new ObservableCollection <CategoryModel>(categories); } } } catch (Exception ex) { Crashes.TrackError(ex); } }); //选择类别 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(x => { if (x != null) { Filter.CatagoryIds = new int[] { x.Id }; this.ForceRefresh = true; foreach (var op in this.BindCategories) { op.Selected = false; } x.Selected = !x.Selected; ((ICommand)Load)?.Execute(null); } Selecter = null; }) .DisposeWith(DeactivateWith); this.WhenAnyValue(x => x.ReferencePage) .Where(x => !string.IsNullOrEmpty(x)) .Subscribe(x => { this.ShowStockQty = !(x.Equals("InventoryOPBillPage") || x.Equals("InventoryBillPage")); }).DisposeWith(DeactivateWith); //选择礼品 this.SelectGiftsCommand = ReactiveCommand.Create(async() => { await this.NavigateAsync("SelectGiftsPage", ("WareHouse", WareHouse), ("Terminaler", this.Terminal)); }); //保存选择商品 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object>(async e => { if (string.IsNullOrEmpty(ReferencePage)) { await _navigationService.GoBackAsync(); return; } var products = ProductSeries.Select(p => p).Where(p => p.Selected == true).ToList(); if (products.Count == 0) { this.Alert("请选择商品项目"); return; } if (ReferencePage == nameof(InventoryReportPage)) { //添加上报商品 await this.NavigateAsync(nameof(AddReportProductPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(AllocationBillPage)) { if (this.Bill == null) { this.Alert("单据不能关联,请确保参数"); return; } //添加调拨商品 await this.NavigateAsync(nameof(AddAllocationProductPage), ("Bill", Bill), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(BackStockBillPage)) { //添加回库调拨单商品 await this.NavigateAsync(nameof(AddBackStockBillPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(TrackAllocationBillPage)) { //添加回库调拨单商品 await this.NavigateAsync(nameof(AddAllocationProductPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(CostContractBillPage)) { //添加合同商品 await this.NavigateAsync(nameof(AddCostContractProductPage), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(InventoryOPBillPage) || ReferencePage == nameof(InventoryBillPage)) { //追加商品 if (TempProductSeries.Any()) { var temps = TempProductSeries.ToList(); foreach (var tp in temps) { if (products.Where(s => s.ProductId == tp.ProductId).Count() == 0) { products.Add(tp); } } } //添加盘点商品 await this.NavigateAsync(nameof(AddInventoryProductPage), ("Reference", ReferencePage), ("WareHouse", WareHouse), ("Products", products)); } else if (ReferencePage == nameof(FilterPage)) { //过滤 await _navigationService.GoBackAsync( ("Filter", Filter), ("Reference", ReferencePage), ("Products", products)); } else if (ReferencePage == nameof(PurchaseOrderBillPage)) { //添加采购商品 await this.NavigateAsync(nameof(AddPurchaseProductPage), ("WareHouse", WareHouse), ("Reference", ReferencePage), ("Products", products) ); } else if (ReferencePage == nameof(ExchangeBillPage)) { //添加换货商品 await this.NavigateAsync(nameof(AddExchangeProductPage), ("WareHouse", WareHouse), ("Reference", ReferencePage), ("Products", products) ); } else { //添加单据商品 await this.NavigateAsync($"{nameof(AddProductPage)}", ("WareHouse", WareHouse), ("Reference", ReferencePage), ("Products", products) ); } }); //收藏 this.FavoriteCommand = ReactiveCommand.Create <ProductModel>(p => { try { var ps = Settings.FavoriteProducts; this.Filter.SerchKey = ""; if (!p.Favorited) { if (!ps.Select(s => s.ProductId).Contains(p.ProductId)) { p.Favorited = true; ps.Add(p); Settings.FavoriteProducts = ps; _dialogService.ShortAlert("收藏成功!"); } } else { var cur = ps.Where(s => s.ProductId == p.ProductId).FirstOrDefault(); if (cur != null) { cur.Favorited = false; p.Favorited = false; ps.Remove(cur); Settings.FavoriteProducts = ps; _dialogService.ShortAlert("收藏已移除!"); } } if (UsableFavorite) { if (ProductSeries != null && ProductSeries.Any()) { var reload = ProductSeries.Where(s => s.Favorited == true).ToList(); if (reload != null && reload.Any()) { this.ProductSeries = new ObservableCollection <ProductModel>(reload); } else { this.UsableFavorite = false; } } } } catch (Exception ex) { Crashes.TrackError(ex); } }); this.BindBusyCommand(Load); this.Load.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.ItemTresholdReachedCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.InitCatagory.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.SelectGiftsCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.SubmitDataCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); this.FavoriteCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith); }