public RouteCardFabricRemChildWindow(RouteCardHeaderViewModel viewModel, int SearchCriteria = 0) { InitializeComponent(); DataContext = viewModel; if (SearchCriteria == 1) { viewModel.RouteCardFabricRemViewModelList = new ObservableCollection <RouteCardFabricViewModel>(); viewModel.SearchPagedCollection = new PagedCollectionView(viewModel.RouteCardFabricRemViewModelList); SearchCriteria = 0; } _client.GetRemRouteQuantityCompleted += (s, v) => { foreach (var item in v.Result) { viewModel.RouteCardFabricRemViewModelList.Add(RouteCardMappers.MapToViewModel(item)); } viewModel.SearchPagedCollection = new PagedCollectionView(viewModel.RouteCardFabricRemViewModelList); viewModel.SearchPagedCollection.GroupDescriptions.Add(new PropertyGroupDescription("TransID")); DgfabricIssue.SelectedIndex = viewModel.SearchPagedCollection == null ? -1 : viewModel.SearchPagedCollection.Count - 1; }; }
private void OKButton_Click(object sender, RoutedEventArgs e) { if (_inspection) { try { var selectedrow = MainGrid.SelectedItem as _proxy.RouteCardHeader; _routeCardHeader.RouteCardDetails.Clear(); _routeCardHeader.LinkIserial = selectedrow.Iserial; var objectindexlist = selectedrow.RouteCardDetails.Select(x => x.ObjectIndex); foreach (var variable in objectindexlist) { var savedrow = selectedrow.RouteCardDetails.FirstOrDefault(x => x.ObjectIndex == variable); var temp = (RouteCardViewModel) new RouteCardViewModel().InjectFrom(savedrow); if (savedrow != null) { temp.ColorPerRow = savedrow.TblColor1; temp.SalesOrderPerRow = savedrow.TblSalesOrder1; } foreach (var VARIABLE in _viewModel.Sizes.Where((x => x.TblSizeGroup == savedrow.TblSalesOrder1.TblStyle1.TblSizeGroup)).OrderBy(x => x.Id).Distinct()) { foreach (var item in selectedrow.RouteCardDetails.OrderBy(x => x.Iserial).Where(x => x.ObjectIndex == variable && x.Size == VARIABLE.SizeCode).ToList()) { if (item.SizeQuantity != null) { var newSize = new RoutCardSizeInfo { SizeCode = item.Size, SizeConsumption = (int)item.SizeQuantity, IsTextBoxEnabled = true }; temp.RoutCardSizes.Add(newSize); } } } temp.RowTotal = temp.RoutCardSizes.Sum(x => x.SizeConsumption); if (_routeCardHeader.RouteCardDetails.All(x => x.ObjectIndex != variable)) { _routeCardHeader.RouteCardDetails.Add(temp); } } } catch (Exception ex) { var err = new ErrorWindow(ex); err.Show(); } } else { RouteCardMappers.MapToViewModel(MainGrid.SelectedItem as RouteCardService.RouteCardHeader, _routeCardHeader); if (_viewModel.VendorList != null) { if (_viewModel.VendorList.Any(w => w.vendor_code == _routeCardHeader.VendorCode)) { _routeCardHeader.VendorPerRow = new _proxy.Vendor().InjectFrom(_viewModel.VendorList.FirstOrDefault(w => w.vendor_code == _routeCardHeader.VendorCode)) as _proxy.Vendor; } } _routeCardHeader.LoadRouteDetails(); } DialogResult = true; }
private void _proxy_GetMaxRouteCardTransactionIDCompleted(object sender, GetMaxRouteCardTransactionIDCompletedEventArgs e) { var rch = new RouteCardService.RouteCardHeader(); var routerCardFabricRow = new ObservableCollection <RouteCardService.RouteCardFabric>(); foreach (var routeFabricRow in MyViewModel.RouteCardFabricViewModelList) { routerCardFabricRow.Add(RouteCardMappers.MapToViewModel(routeFabricRow)); } var rcd = new ObservableCollection <RouteCardService.RouteCardDetail>(); try { switch (CmbDirection.SelectedIndex) { case 0: rch.Direction = 0; break; case 1: rch.Direction = 1; break; } MyViewModel.TransID = (e.Result + 1); RouteCardMappers.MapToViewModel(MyViewModel, rch); foreach (var item in MyViewModel.RouteCardDetails) { foreach (var sizeItem in item.RoutCardSizes.Where(x => x.SizeCode != "")) { rcd.Add(new RouteCardService.RouteCardDetail { TblColor = item.TblColor, Degree = item.Degree, TblSalesOrder = item.TblSalesOrder, Trans_TransactionHeader = rch.TransID, Size = sizeItem.SizeCode, SizeQuantity = sizeItem.SizeConsumption, RoutGroupID = rch.RoutGroupID, Direction = rch.Direction, ObjectIndex = item.ObjectIndex, Price = item.Price, Notes = item.Notes, Blocks = item.Blocks, TblWarehouse = item.TblWarehouse, }); } } MyViewModel.SaveRouteCard(rch, rcd, "add", PostOrNo); tBlockTransID.Text = rch.TransID.ToString(CultureInfo.InvariantCulture); // btnCancel_Click(null, null); btnEdit_Checked(null, null); } catch (Exception ex) { var err = new ErrorWindow(ex); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { if (sender == BtnSave) { PostOrNo = 0; } else if (sender == BtnPostToAx) { PostOrNo = 1; } if (MyViewModel.Iserial == 0) { var proxy = new RouteCardServiceClient(); proxy.GetMaxRouteCardTransactionIDAsync((int)CmbRouteGroup.SelectedValue, CmbDirection.SelectedIndex, MyViewModel.TransactionType); proxy.GetMaxRouteCardTransactionIDCompleted += _proxy_GetMaxRouteCardTransactionIDCompleted; } else { var proxy = new RouteCardServiceClient(); proxy.GetMaxRouteCardTransactionIDAsync((int)CmbRouteGroup.SelectedValue, CmbDirection.SelectedIndex, MyViewModel.TransactionType); proxy.GetMaxRouteCardTransactionIDCompleted += (s, ev) => { var myViewModel = (LayoutRoot.DataContext as RouteCardHeaderViewModel); var routerCardFabricRow = new ObservableCollection <RouteCardService.RouteCardFabric>(); if (myViewModel != null) { MyViewModel.TransID = (ev.Result + 1); foreach (var routeFabricRow in myViewModel.RouteCardFabricViewModelList) { routerCardFabricRow.Add(RouteCardMappers.MapToViewModel(routeFabricRow)); } var rch = new RouteCardService.RouteCardHeader(); var rcd = new ObservableCollection <RouteCardService.RouteCardDetail>(); try { RouteCardMappers.MapToViewModel(myViewModel, rch); foreach (var item in myViewModel.RouteCardDetails) { foreach (var sizeItem in item.RoutCardSizes.Where(x => x.SizeCode != "")) { rcd.Add(new RouteCardService.RouteCardDetail { TblColor = item.TblColor, Degree = item.Degree, TblSalesOrder = item.TblSalesOrder, Trans_TransactionHeader = rch.TransID, Size = sizeItem.SizeCode, SizeQuantity = sizeItem.SizeConsumption, RoutGroupID = rch.RoutGroupID, Direction = rch.Direction, ObjectIndex = item.ObjectIndex, Price = item.Price, Notes = item.Notes, Blocks = item.Blocks, TblWarehouse = item.TblWarehouse }); } } myViewModel.SaveRouteCard(rch, rcd, "update", PostOrNo); tBlockTransID.Text = rch.TransID.ToString(CultureInfo.InvariantCulture); //btnCancel_Click(null, null); } catch (Exception ex) { var err = new ErrorWindow(ex); } } }; } }