public void AddNewDetailRow(bool checkLastRow) { var currentRowIndex = (SelectedMainRow.DetailsList.IndexOf(SelectedDetailRow)); if (checkLastRow) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedDetailRow, new ValidationContext(SelectedDetailRow, null, null), valiationCollection, true); if (!isvalid) { return; } } if (AllowAdd != true) { MessageBox.Show(strings.AllowAddMsg); return; } var newrow = new TblPostingProfileDetailViewModel { TblPostingProfileHeader = SelectedMainRow.Iserial, JournalAccountTypePerRow = JournalAccountTypeList.FirstOrDefault() }; SelectedMainRow.DetailsList.Insert(currentRowIndex + 1, newrow); SelectedDetailRow = newrow; }
public void SaveOldDetailRow(TblPostingProfileDetailViewModel 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 TblPostingProfileDetail(); saveRow.InjectFrom(oldRow); if (!Loading) { Loading = true; Glclient.UpdateOrInsertTblPostingProfileDetailsAsync(saveRow, save, SelectedMainRow.DetailsList.IndexOf(oldRow), LoggedUserInfo.DatabasEname); } } } }
public PostingProfileHeaderViewModel() { if (!IsDesignTime) { GetItemPermissions(PermissionItemName.PostingProfile.ToString()); Glclient = new GlServiceClient(); MainRowList = new SortableCollectionView <TblPostingProfileHeaderViewModel>(); SelectedMainRow = new TblPostingProfileHeaderViewModel(); var journalAccountTypeClient = new GlServiceClient(); journalAccountTypeClient.GetGenericCompleted += (s, sv) => { JournalAccountTypeList = sv.Result; }; journalAccountTypeClient.GetGenericAsync("TblJournalAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); Glclient.GetTblPostingProfileHeaderCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblPostingProfileHeaderViewModel(); newrow.InjectFrom(row); MainRowList.Add(newrow); } Loading = false; FullCount = sv.fullCount; if (MainRowList.Any() && (SelectedMainRow == null)) { SelectedMainRow = MainRowList.FirstOrDefault(); } if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } }; Glclient.UpdateOrInsertTblPostingProfileHeadersCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } }; Glclient.DeleteTblPostingProfileHeaderCompleted += (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); } }; Glclient.GetTblPostingProfileDetailCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblPostingProfileDetailViewModel { AccountPerRow = row.TblAccount1, JournalAccountTypePerRow = new GenericTable() }; newrow.JournalAccountTypePerRow.InjectFrom(row.TblJournalAccountType); newrow.InjectFrom(row); newrow.EntityAccountPerRow = sv.entityList.FirstOrDefault(x => x.TblJournalAccountType == newrow.Type && x.scope == newrow.Scope && x.Iserial == newrow.Entity); SelectedMainRow.DetailsList.Add(newrow); } Loading = false; DetailFullCount = sv.fullCount; if (SelectedMainRow.DetailsList.Any() && (SelectedDetailRow == null)) { SelectedDetailRow = SelectedMainRow.DetailsList.FirstOrDefault(); } if (DetailFullCount == 0 && SelectedMainRow.DetailsList.Count == 0) { AddNewDetailRow(false); } if (Export) { Export = false; ExportGrid.ExportExcel("Users"); } }; Glclient.UpdateOrInsertTblPostingProfileDetailsCompleted += (s, x) => { var savedRow = (TblPostingProfileDetailViewModel)SelectedMainRow.DetailsList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } Loading = false; }; Glclient.DeleteTblPostingProfileDetailCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } Loading = false; var oldrow = SelectedMainRow.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { SelectedMainRow.DetailsList.Remove(oldrow); } if (!SelectedMainRow.DetailsList.Any()) { AddNewDetailRow(false); } }; GetMaindata(); } }