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 TblAccountViewModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public void SaveOldRow(TblAccountViewModel 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 TblAccount(); saveRow.InjectFrom(oldRow); if (!Loading) { Loading = true; Glclient.UpdateOrInsertTblAccountsAsync(saveRow, save, MainRowList.IndexOf(oldRow), LoggedUserInfo.DatabasEname); } } } }
public AccountViewModel() { if (!IsDesignTime) { GetItemPermissions(PermissionItemName.Account.ToString()); Glclient = new GlServiceClient(); var currencyClient = new GlServiceClient(); currencyClient.GetGenericCompleted += (s, sv) => { CurrencyList = sv.Result; }; currencyClient.GetGenericAsync("TblCurrency", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); var journalAccountTypeClient = new GlServiceClient(); journalAccountTypeClient.GetGenericCompleted += (s, sv) => { JournalAccountTypeList = sv.Result; }; journalAccountTypeClient.GetGenericAsync("TblJournalAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); var accountTypeClient = new GlServiceClient(); accountTypeClient.GetGenericCompleted += (s, sv) => { AccountTypeList = sv.Result; }; accountTypeClient.GetGenericAsync("TblAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); MainRowList = new SortableCollectionView <TblAccountViewModel>(); SelectedMainRow = new TblAccountViewModel(); Glclient.GetTblAccountCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblAccountViewModel(); newrow.CurrencyPerRow = new GenericTable(); newrow.AccountTypePerRow = new GenericTable(); newrow.JournalAccountTypePerRow = new GenericTable(); newrow.InjectFrom(row); newrow.CurrencyPerRow.InjectFrom(row.TblCurrency1); newrow.AccountTypePerRow.InjectFrom(row.TblAccountType1); if (row.TblJournalAccountType1 != null) { newrow.JournalAccountTypePerRow.InjectFrom(row.TblJournalAccountType1); } newrow.EntityPerRow = sv.entityList.FirstOrDefault(x => x.TblJournalAccountType == row.TblJournalAccountType && x.Iserial == row.EntityAccount); 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.UpdateOrInsertTblAccountsCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } Loading = false; }; Glclient.DeleteTblAccountCompleted += (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.GetTblAccountIntervalCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblAccountIntervalViewModel(); newrow.InjectFrom(row); 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); } }; Glclient.UpdateOrInsertTblAccountIntervalsCompleted += (s, x) => { var savedRow = (TblAccountIntervalViewModel)SelectedMainRow.DetailsList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } Loading = false; }; Glclient.DeleteTblAccountIntervalCompleted += (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(); } }