/// <summary> /// 获取公司配置 /// </summary> /// <returns></returns> public void GetCompanySettingAsync(CancellationToken calToken = default) { var model = new CompanySettingModel(); try { int storeId = Settings.StoreId; int userId = Settings.UserId; var api = RefitServiceBuilder.Build <ISettingApi>(URL); var cacheKey = RefitServiceBuilder.Cacher("GetCompanySettingAsync", storeId, userId); _makeRequest.StartUseCache_Rx(api.GetCompanySettingAsync(storeId, calToken), cacheKey, calToken)?.Subscribe((results) => { if (results != null && results?.Code >= 0) { model = results?.Data; if (model != null) { Settings.CompanySetting = JsonConvert.SerializeObject(model); if (string.IsNullOrEmpty(Settings.DefaultPricePlan) || Settings.DefaultPricePlan == "0_0") { Settings.DefaultPricePlan = model.DefaultPricePlan; } } } }); } catch (Exception e) { e.HandleException(); } }
/// <summary> /// Updates the asynchronous. /// </summary> /// <param name="companysetting">The category.</param> /// <returns> /// UpdateAsync /// </returns> /// <exception cref="ArgumentNullException">category</exception> public async Task <int> UpdateAsync(CompanySettingModel companysetting) { if (companysetting == null) { throw new ArgumentNullException("companysetting"); } return(await this.companysettingRepository.UpdateAsync(companysetting)); }
// POST api/<controller> public void Post([FromBody] CompanySettingModel model) { model.CreatedDate = DateTime.Now; model.CompanyID = base.CompanyId; if (model.UploadLogoBase64 != null) { model.UploadLogo = System.Convert.FromBase64String(model.UploadLogoBase64); } _companySettingService.SaveCompanySetting(model); }
public void UpdateCompanySetting(CompanySettingModel companySetting) { MQUESTSYSEntities ent = new MQUESTSYSEntities(); var query = from i in ent.CompanySetting select i; var obj = query.FirstOrDefault(); ObjectHelper.CopyProperties(companySetting, obj); ent.SaveChanges(); }
/// <summary> /// Inserts the asynchronous. /// </summary> /// <param name="companysetting">The model.</param> /// <returns>Insert Company Setting</returns> public async Task <int> InsertAsync(CompanySettingModel companysetting) { try { return(await this.companysettingRepository.InsertAsync(companysetting)); } catch (Exception ex) { Console.WriteLine(ex); } return(0); }
public int SaveCompanySetting(CompanySettingModel model) { var companySettingEntity = _companySettingRepository.Find(x => x.CompanyID == model.CompanyID).FirstOrDefault(); if (companySettingEntity == null) { var companySetting = Mapper.DynamicMap <tblCompanySetting>(model); _companySettingRepository.Add(companySetting); return(_companySettingRepository.SaveChanges()); } else { return(Update(model)); } }
public int Update(CompanySettingModel model) { var companySetting = _companySettingRepository.Find(x => x.CompanyID == model.CompanyID).FirstOrDefault(); if (companySetting != null) { model.UpdateDate = DateTime.Now; Mapper.CreateMap <CompanySettingModel, tblCompanySetting>() .ForMember(dest => dest.CompanySettingID, opt => opt.Ignore()); // ignore primary key while update/delete tblCompanySetting tblCompanySetting = (tblCompanySetting)Mapper.Map(model, companySetting); return(_companySettingRepository.SaveChanges()); } return(0); }
public CompanySettingModel RetrieveCompanySetting() { MQUESTSYSEntities ent = new MQUESTSYSEntities(); var query = from i in ent.CompanySetting select i; CompanySettingModel obj = new CompanySettingModel(); if (query.FirstOrDefault() != null) { ObjectHelper.CopyProperties(query.FirstOrDefault(), obj); } else { return(null); } return(obj); }
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 EditProductPageViewModel(INavigationService navigationService, IDialogService dialogService ) : base(navigationService, dialogService) { Title = "修改商品信息"; _navigationService = navigationService; _dialogService = dialogService; CompanySetting = JsonConvert.DeserializeObject <CompanySettingModel>(Settings.CompanySetting); //保存 this.SaveCommand = ReactiveCommand.CreateFromTask(async() => { if (this.OldProductQuantity < Product.Quantity && Product.IsDispatchProduct) { this.Alert("已调度商品,数量不能大于原来单据商品量。"); return; } await _navigationService.GoBackAsync(("UpdateProduct", Product)); }); //重算 this.EntryUnfocused = ReactiveCommand.Create <string>((t) => { CalcPrice(); }); //删除商品 this.DeleteCommand = ReactiveCommand.CreateFromTask(async() => { await _navigationService.GoBackAsync(("DelProduct", Product)); }); //单位选择 this.UnitSelected = ReactiveCommand.CreateFromTask <int>(async(r) => { try { int porductId = r; var product = this.Product; var tempUnitAlisa = product.UnitAlias = ""; var result = await CrossDiaglogKit.Current.GetRadioButtonResultAsync("单位选择", "", (() => { var popDatas = new List <PopData>(); if (product.Units != null) { var unt = product.Units.ToList(); if (unt[0].Key != "SMALL") { if (unt[0].Value == product.UnitId) { tempUnitAlisa = product.UnitAlias = "SMALL"; } popDatas.Add(new PopData() { Id = unt[0].Value, Column = unt[0].Key, Column1 = "SMALL", Column1Enable = false, Data = unt[0].Value, Selected = this.Product.UnitAlias == "SMALL" }); } if (unt[1].Key != "STROK") { if (unt[1].Value == product.UnitId) { tempUnitAlisa = product.UnitAlias = "STROK"; } popDatas.Add(new PopData() { Id = unt[1].Value, Column = unt[1].Key, Column1 = "STROK", Column1Enable = false, Data = unt[1].Value, Selected = this.Product.UnitAlias == "STROK" }); } if (unt[2].Key != "BIG") { if (unt[2].Value == product.UnitId) { tempUnitAlisa = product.UnitAlias = "BIG"; } popDatas.Add(new PopData() { Id = unt[2].Value, Column = unt[2].Key, Column1 = "BIG", Column1Enable = false, Data = unt[2].Value, Selected = this.Product.UnitAlias == "BIG" }); } } return(Task.FromResult(popDatas)); })); if (result != null) { Product.UnitId = (int)result.Data; Product.UnitName = result.Column; product.UnitAlias = result.Column1; //重算 CalcPrice(tempUnitAlisa); } } catch (Exception ex) { Crashes.TrackError(ex); } }); //单价选择 this.PriceSelected = ReactiveCommand.CreateFromTask <int>(async(r) => { try { int porductId = r; var product = this.Product; var result = await CrossDiaglogKit.Current.GetRadioButtonResultAsync("选择价格", "", (() => { var popDatas = new List <PopData>(); if (product != null) { var tierprices = product.ProductTierPrices; if (tierprices != null) { //默认条件 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]; } if (product.UnitAlias == "SMALL") { #region 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 } else if (product.UnitAlias == "STROK") { #region 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?.StrokeUnitPrice.ToString(), Column1Enable = true, Data = price?.StrokeUnitPrice ?? 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?.StrokeUnitPrice.ToString(), Column1Enable = true, Data = price?.StrokeUnitPrice ?? 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?.StrokeUnitPrice.ToString(), Column1Enable = true, Data = price?.StrokeUnitPrice ?? 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?.StrokeUnitPrice.ToString(), Column1Enable = true, Data = price?.StrokeUnitPrice ?? 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?.StrokeUnitPrice.ToString(), Column1Enable = true, Data = price?.StrokeUnitPrice ?? 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?.StrokeUnitPrice.ToString(), Column1Enable = true, Data = price?.StrokeUnitPrice ?? 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?.StrokeUnitPrice.ToString(), Column1Enable = true, Data = price?.StrokeUnitPrice ?? 0 }); } } break; } #endregion } else if (product.UnitAlias == "BIG") { #region 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?.BigUnitPrice.ToString(), Column1Enable = true, Data = price?.BigUnitPrice ?? 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?.BigUnitPrice.ToString(), Column1Enable = true, Data = price?.BigUnitPrice ?? 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?.BigUnitPrice.ToString(), Column1Enable = true, Data = price?.BigUnitPrice ?? 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?.BigUnitPrice.ToString(), Column1Enable = true, Data = price?.BigUnitPrice ?? 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?.BigUnitPrice.ToString(), Column1Enable = true, Data = price?.BigUnitPrice ?? 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?.BigUnitPrice.ToString(), Column1Enable = true, Data = price?.BigUnitPrice ?? 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?.BigUnitPrice.ToString(), Column1Enable = true, Data = price?.BigUnitPrice ?? 0 }); } } break; } #endregion } } } return(Task.FromResult(popDatas)); })); if (result != null) { Product.Price = (decimal)result.Data; Product.IsShowGiveEnabled = true; //重算 CalcPrice(); } } catch (Exception ex) { Crashes.TrackError(ex); } }); }