public void SaveOldRow(TblBankViewModel 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 TblBank(); saveRow.InjectFrom(oldRow); if (!Loading) { Loading = true; Glclient.UpdateOrInsertTblBanksAsync(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 TblBankViewModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public BankViewModel() { if (!IsDesignTime) { GetItemPermissions(PermissionItemName.Bank.ToString()); Glclient = new GlServiceClient(); var currencyClient = new GlServiceClient(); currencyClient.GetGenericCompleted += (s, sv) => { CurrencyList = sv.Result; }; currencyClient.GetGenericAsync("TblCurrency", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); var BankAccountTypeClient = new GlServiceClient(); BankAccountTypeClient.GetGenericCompleted += (s, sv) => { BankAccountTypeList = sv.Result; }; BankAccountTypeClient.GetGenericAsync("TblBankAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); var bankClient = new GlServiceClient(); bankClient.GetGenericCompleted += (s, sv) => { BankGroupList = sv.Result; }; bankClient.GetGenericAsync("TblBankGroup", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); MainRowList = new SortableCollectionView <TblBankViewModel>(); SelectedMainRow = new TblBankViewModel(); Glclient.GetTblBankChequeCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblBankChequeViewModel(); newrow.InjectFrom(row); if (row.TblCurrency1 != null) { newrow.CurrencyPerRow.InjectFrom(row.TblCurrency1); } if (row.TblBank1 != null) { newrow.BankPerRow.InjectFrom(row.TblBank1); } if (row.TblJournalAccountType1 != null) { newrow.JournalAccountTypePerRow.InjectFrom(row.TblJournalAccountType1); } newrow.EntityPerRow = sv.entityList.FirstOrDefault(x => x.TblJournalAccountType == row.TblJournalAccountType && x.Iserial == row.EntityAccount); SelectedMainRow.DetailsList.Add(newrow); } Loading = false; FullCount = sv.fullCount; } ; Glclient.GetTblBankCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblBankViewModel(); newrow.CurrencyPerRow = new GenericTable(); newrow.BankAccountTypePerRow = new GenericTable(); newrow.BankGroupPerRow = new GenericTable(); newrow.InjectFrom(row); if (row.TblCurrency1 != null) { newrow.CurrencyPerRow.InjectFrom(row.TblCurrency1); } if (row.TblBankAccountType1 != null) { newrow.BankAccountTypePerRow.InjectFrom(row.TblBankAccountType1); } if (row.TblBankGroup1 != null) { newrow.BankGroupPerRow.InjectFrom(row.TblBankGroup1); } 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.UpdateOrInsertTblBanksCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } Loading = false; }; Glclient.DeleteTblBankCompleted += (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.CreateChequeCompleted += (s, sv) => MessageBox.Show("Cheques Generated"); Glclient.DeleteTblBankChequeCompleted += (s, sv) => { MessageBox.Show("Cheques Deleted"); SelectedMainRow.DetailsList.Clear(); GetDetailRow(); }; GetMaindata(); } }