public void SaveOldRow(TblAssetViewModel oldRow) { if (oldRow != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(oldRow, new ValidationContext(oldRow, null, null), valiationCollection, true); if (isvalid) { var save = oldRow.Iserial == 0; if (AllowUpdate != true && !save) { MessageBox.Show(strings.AllowUpdateMsg); return; } var saveRow = new TblAssetRetail(); saveRow.InjectFrom(oldRow); if (!Loading) { Loading = true; Glclient.UpdateOrInsertTblAssetRetailAsync(saveRow, save, MainRowList.IndexOf(oldRow), LoggedUserInfo.DatabasEname); } } } }
public void AddNewMainRow(bool checkLastRow) { var currentRowIndex = (MainRowList.IndexOf(SelectedMainRow)); if (checkLastRow) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (!isvalid) { return; } } if (AllowAdd != true) { MessageBox.Show(strings.AllowAddMsg); return; } var newrow = new TblAssetViewModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public AssetViewModel() { if (!IsDesignTime) { GetItemPermissions(PermissionItemName.Asset.ToString()); Glclient = new GlServiceClient(); var AssetClient = new GlServiceClient(); AssetClient.GetGenericCompleted += (s, sv) => { AssetGroupList = sv.Result; }; AssetClient.GetGenericAsync("TblAssetGroup", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); MainRowList = new SortableCollectionView <TblAssetViewModel>(); SelectedMainRow = new TblAssetViewModel(); Glclient.GetTblAssetRetailCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblAssetViewModel(); newrow.InjectFrom(row); newrow.AssetGroupPerRow = new GenericTable(); if (row.TblAssetGroup1 != null) { newrow.AssetGroupPerRow.InjectFrom(row.TblAssetGroup1); } newrow.AccountPerRow = new TblAccount(); if (row.TblAccount1 != null) { newrow.AccountPerRow = row.TblAccount1; } newrow.SumAccountPerRow = new TblAccount(); if (row.TblAccount2 != null) { newrow.SumAccountPerRow = row.TblAccount2; } MainRowList.Add(newrow); } Loading = false; FullCount = sv.fullCount; if (MainRowList.Any() && (SelectedMainRow == null)) { SelectedMainRow = MainRowList.FirstOrDefault(); } if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } if (Export) { Export = false; AllowExport = true; //ExportGrid.ExportExcel("Account"); } }; Glclient.UpdateOrInsertTblAssetRetailCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } Loading = false; }; Glclient.DeleteTblAssetRetailCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { MainRowList.Remove(oldrow); } if (!MainRowList.Any()) { AddNewMainRow(false); } }; GetMaindata(); } }