private void hpladdProduct_Click(object sender, RoutedEventArgs e) { UCProductSearch uc = new UCProductSearch(); uc.SelectionMode = SelectionMode.Multiple; //uc.ProductC3SysNo = _c3SysNo; IDialog dialog = Window.ShowDialog("添加商品", uc, (obj, args) => { if (args.DialogResult == DialogResultType.OK) { List <ProductVM> products = args.Data as List <ProductVM>; if (products != null && products.Count > 0) { products.ForEach(p => { GiftVoucherProductRelationVM temp = this._voucherProductVM.RelationProducts.FirstOrDefault(item => { return(item.ProductSysNo == p.SysNo); }); if (temp == null) { GiftVoucherProductRelationVM vm = EntityConverter <ProductVM, GiftVoucherProductRelationVM> .Convert(p, (s, t) => { t.ProductSysNo = s.SysNo.Value; t.ProductStatus = s.Status; t.SysNo = null; }); vm.IsChecked = false; vm.Type = GVRReqType.Add; vm.SaleInWeb = true; _voucherProductVM.RelationProducts.Add(vm); } else { Window.Alert(string.Format("已存在编号为{0}的商品.", p.ProductID)); } }); this.productgd.ItemsSource = this._voucherProductVM.RelationProducts; } } }); uc.DialogHandler = dialog; }
/// <summary> /// 加载礼品券商品 /// </summary> /// <param name="sysNo"></param> /// <param name="callback"></param> public void GetGiftVoucherProductInfo(int sysNo, Action <GiftCardProductVM> callback) { string relativeUrl = string.Format("/IMService/GiftCardInfo/GetGiftVoucherProductInfo/{0}", sysNo); restClient.Query <GiftVoucherProduct>(relativeUrl, (obj, args) => { if (args.FaultsHandle()) { return; } GiftVoucherProduct entity = args.Result; var vm = entity.Convert <GiftVoucherProduct, GiftCardProductVM>((s, w) => { }); foreach (var item in vm.RelationProducts) { item.RelationStatus = entity.RelationProducts.Where(p => p.SysNo == item.SysNo).FirstOrDefault().Status; } int count = 0; if (vm != null && vm.RelationProducts != null && vm.RelationProducts.Count <= 0) { callback(vm); } if (vm != null && vm.RelationProducts.Count > 0) { // 根据商品编号获取商品信息 PagingInfo paging = new PagingInfo { PageIndex = 0, PageSize = 1, }; foreach (var item in vm.RelationProducts) { restClient.QueryDynamicData("/IMService/Product/QueryProduct", new ProductQueryFilter() { PagingInfo = paging, ProductSysNo = item.ProductSysNo }, (obj1, args1) => { if (args1.FaultsHandle()) { return; } List <ProductVM> productLst = DynamicConverter <ProductVM> .ConvertToVMList <List <ProductVM> >(args1.Result.Rows); ProductVM pvm = productLst.FirstOrDefault(); if (null != pvm) { GiftVoucherProductRelationVM vpvm = EntityConverter <ProductVM, GiftVoucherProductRelationVM> .Convert(pvm, (s, t) => { t.ProductSysNo = s.SysNo.Value; t.ProductStatus = s.Status; t.SaleInWeb = s.GiftVoucherType == 1 ? true : false; }); item.ProductID = vpvm.ProductID; item.ProductName = vpvm.ProductName; item.ProductType = vpvm.ProductType; item.ProductStatus = vpvm.ProductStatus; item.AvailableQty = vpvm.AvailableQty; item.InventoryType = vpvm.InventoryType; item.IsConsign = vpvm.IsConsign; item.SaleInWeb = vpvm.SaleInWeb; } count++; if (count == vm.RelationProducts.Count) { callback(vm); } }); } } }); }
/// <summary> /// 查询礼品券关联商品 /// </summary> /// <param name="vm"></param> /// <param name="PageSize"></param> /// <param name="PageIndex"></param> /// <param name="SortField"></param> /// <param name="callback"></param> public void QueryGiftVoucherProductRelation(GiftCardProductFilterVM vm, int PageSize, int PageIndex, string SortField, Action <ObservableCollection <GiftVoucherProductRelationVM>, int> callback) { GiftCardProductFilter filter = vm.ConvertVM <GiftCardProductFilterVM, GiftCardProductFilter>(); filter.PageInfo = new ECCentral.QueryFilter.Common.PagingInfo() { PageSize = PageSize, PageIndex = PageIndex, SortBy = SortField }; string relativeUrl = "/IMService/GiftCardInfo/QueryGiftVoucherProductRelation"; restClient.QueryDynamicData(relativeUrl, filter, (obj, args) => { if (args.FaultsHandle()) { return; } ObservableCollection <GiftVoucherProductRelationVM> result = DynamicConverter <GiftVoucherProductRelationVM> .ConvertToVMList <ObservableCollection <GiftVoucherProductRelationVM> >(args.Result.Rows); foreach (var item in result) { foreach (var source in args.Result.Rows.ToList()) { if (source.SysNo == item.SysNo) { item.RelationStatus = source.Status; //add by cesc 2013-10-30 //如果不将请求类型'删除'手动更改,每次点页面上的'保存'按钮时,会将未审核通过的请求加载出来 if (item.Type == GVRReqType.Delete) { item.Type = null; } } } } if (result.Count > 0) { // 根据商品编号获取商品信息 PagingInfo paging = new PagingInfo { PageIndex = 0, PageSize = 1, }; int count = 0; foreach (var item in result) { restClient.QueryDynamicData("/IMService/Product/QueryProduct", new ProductQueryFilter() { PagingInfo = paging, ProductSysNo = item.ProductSysNo }, (obj1, args1) => { if (args1.FaultsHandle()) { return; } List <ProductVM> productLst = DynamicConverter <ProductVM> .ConvertToVMList <List <ProductVM> >(args1.Result.Rows); ProductVM pvm = productLst.FirstOrDefault(); if (null != pvm) { GiftVoucherProductRelationVM vpvm = EntityConverter <ProductVM, GiftVoucherProductRelationVM> .Convert(pvm, (s, t) => { t.ProductSysNo = s.SysNo.Value; t.ProductStatus = s.Status; t.SaleInWeb = s.GiftVoucherType == 1 ? true : false; }); item.ProductID = vpvm.ProductID; item.ProductName = vpvm.ProductName; item.ProductType = vpvm.ProductType; item.ProductStatus = vpvm.ProductStatus; item.AvailableQty = vpvm.AvailableQty; item.InventoryType = vpvm.InventoryType; item.IsConsign = vpvm.IsConsign; item.SaleInWeb = vpvm.SaleInWeb; } count++; if (count == result.Count) { callback(result, args.Result.TotalCount); } }); } } }); }