private void NewDetails() { try { SelectedMainRow.LatestColor = SelectedMainRow.LatestColor + 1; //SelectedMainRow.LatestColor ; var temp = new AccessoryAttributesDetailsViewModel { Code = SelectedMainRow.FullCode, Descreption = SelectedMainRow.Descreption, Configuration = SelectedMainRow.LatestColor.ToString(), Size = SelectedMainRow.AccSizeProperty != null ? SelectedMainRow.AccSizeProperty.TblAccSize1.SizeCode : null, ObjStatus = { IsNew = true } }; AccDetailsList.Add(temp); SelectedDetail = temp; } catch { var err = new ErrorWindow("Error Adding Details" , "Please make sure that there is enough data in the header section!"); err.Show(); } }
public AccessoriesViewModel() { SelectedMainRow = new AccessoryAttributesViewModel(); AccDetailsList = new ObservableCollection <AccessoryAttributesDetailsViewModel>(); AccessoryTypesList = new ObservableCollection <GenericViewModel>(); AccessoryGroupList = new ObservableCollection <GenericViewModel>(); BrandList = new ObservableCollection <_Proxy.Brand>(); UoMList = new ObservableCollection <GenericViewModel>(); NewDetailsCommand = new CommandsExecuter(NewDetails) { IsEnabled = true }; SaveAccCommand = new CommandsExecuter(SaveAccessories) { IsEnabled = true }; FillGenericCollection("tbl_lkp_AccessoryItemType", AccessoryTypesList); FillGenericCollection("tbl_lkp_AccessoryGroup", AccessoryGroupList); FillGenericCollection("tbl_lkp_UoM", UoMList); Client.DeleteAccDetailCompleted += (s, sv) => { if (sv.Error != null) { throw sv.Error; } if (sv.Result != 0) { var oldrow = AccDetailsList.FirstOrDefault(x => x.Iserial == sv.Result); if (oldrow != null) { AccDetailsList.Remove(oldrow); } } else { MessageBox.Show("This Comination Has Transaction !!! It Cannot Be Deleted"); } }; Client.GetAllBrandsCompleted += (s, sv) => { BrandList = sv.Result; }; Client.GetAllBrandsAsync(0); SelectedMainRow.InitiatePermissionsMapper(); Client.GetAllAccessoriesHeaderCompleted += (s, e) => { if (e.Error == null) { if (e.Result == null) { return; } foreach (var row in e.Result) { var newrow = new AccessoryAttributesViewModel { ObjStatus = { IsSavedDBItem = true, IsNew = false } }; newrow.InjectFrom(row); newrow.BrandProperty = BrandList.SingleOrDefault(x => x.Brand_Code == newrow.Brand); newrow.AccessoryGroupProperty = AccessoryGroupList.SingleOrDefault(x => x.Iserial == newrow.AccGroup); newrow.AccessorySubGroupProperty = row.tbl_AccessoriesSubGroup; newrow.AccSubGrouplist.Add(row.tbl_AccessoriesSubGroup); newrow.UoMProperty = UoMList.SingleOrDefault(x => x.Iserial == newrow.UoMID); newrow.AccessoryTypesProperty = AccessoryTypesList.SingleOrDefault(x => x.Iserial == newrow.ItemType); newrow.LatestColor = e.TransactionExist.FirstOrDefault(x => x.Key == newrow.Code).Value + 1; MainRowList.Add(newrow); } } else { var err = new ErrorWindow(e.Error); err.Show(); } }; Client.GetAllAccessoriesAttributesDetailsCompleted += (s1, e1) => { foreach (var item in e1.Result) { var newItem = new AccessoryAttributesDetailsViewModel { ObjStatus = { IsSavedDBItem = true }, }; newItem.InjectFrom(item); AccDetailsList.Add(newItem); } Loading = false; }; }
private void SaveAccessories() { var client = new _Proxy.CRUD_ManagerServiceClient(); var headerRow = new _Proxy.tbl_AccessoryAttributesHeader(); headerRow.InjectFrom(SelectedMainRow); var detailsList = new ObservableCollection <_Proxy.tbl_AccessoryAttributesDetails>(); GenericMapper.InjectFromObCollection(detailsList, AccDetailsList); var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (!isvalid) { MessageBox.Show("Data IS not Valid"); return; } if (SelectedMainRow.ObjStatus.IsNew) { client.AddAllNewAccessoriesAttributesCompleted += (s, sv) => { MessageBox.Show(sv.Error == null ? strings.SavedMessage : strings.FailSavingMessage); SelectedMainRow.InjectFrom(sv.Result); SelectedMainRow.ObjStatus.IsNew = false; SelectedMainRow.ObjStatus.IsSavedDBItem = true; AccDetailsList = new SortableCollectionView <AccessoryAttributesDetailsViewModel>(); foreach (var row in sv.Result.tbl_AccessoryAttributesDetails) { var newrow = new AccessoryAttributesDetailsViewModel { ObjStatus = { IsNew = false, IsSavedDBItem = true } }; newrow.InjectFrom(row); AccDetailsList.Add(newrow); } }; // if (AllowAdd) // { client .AddAllNewAccessoriesAttributesAsync (headerRow , detailsList, SelectedMainRow.IsSizeIncludedInHeader, LoggedUserInfo.Iserial); // } // else // { // MessageBox.Show("You do not have the permission to add a new item!"); // } } else if (SelectedMainRow.ObjStatus.IsSavedDBItem) { client.UpdateAccessoriesAttributesCompleted += (s, e) => { MessageBox.Show(e.Error == null ? strings.SavedMessage : strings.FailSavingMessage); SelectedMainRow.InjectFrom(e.Result); SelectedMainRow.ObjStatus.IsNew = false; SelectedMainRow.ObjStatus.IsSavedDBItem = true; AccDetailsList = new SortableCollectionView <AccessoryAttributesDetailsViewModel>(); foreach (var row in e.Result.tbl_AccessoryAttributesDetails) { var newrow = new AccessoryAttributesDetailsViewModel { ObjStatus = { IsNew = false, IsSavedDBItem = true } }; newrow.InjectFrom(row); AccDetailsList.Add(newrow); } } ; // if (AllowUpdate) // { var detailsNewList = new ObservableCollection <_Proxy.tbl_AccessoryAttributesDetails>(); GenericMapper.InjectFromObCollection(detailsNewList, AccDetailsList.Where(x => x.ObjStatus.IsNew)); var detailsUpdatedList = new ObservableCollection <_Proxy.tbl_AccessoryAttributesDetails>(); GenericMapper.InjectFromObCollection(detailsUpdatedList, AccDetailsList.Where(x => x.ObjStatus.IsSavedDBItem)); client .UpdateAccessoriesAttributesAsync (headerRow, detailsNewList, detailsUpdatedList, LoggedUserInfo.Iserial); // } // else // { // MessageBox.Show("You do not have the update permission"); // } } }