public void SaveOldRow(TblMethodOfPaymentViewModel 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 TblMethodOfPayment(); saveRow.InjectFrom(oldRow); Glclient.UpdateOrInsertTblMethodOfPaymentsAsync(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 TblMethodOfPaymentViewModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public MethodOfPaymentViewModel() { if (!IsDesignTime) { GetItemPermissions(PermissionItemName.MethodOfPayment.ToString()); Glclient = new GlServiceClient(); MainRowList = new SortableCollectionView <TblMethodOfPaymentViewModel>(); SelectedMainRow = new TblMethodOfPaymentViewModel(); var bankTransactionTypeClient = new GlServiceClient(); bankTransactionTypeClient.GetGenericCompleted += (s, sv) => { BankTransactionTypeList = sv.Result; }; bankTransactionTypeClient.GetGenericAsync("TblBankTransactionType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); var journalAccountTypeClient = new GlServiceClient(); journalAccountTypeClient.GetGenericCompleted += (s, sv) => { JournalAccountTypeList = sv.Result; }; journalAccountTypeClient.GetGenericAsync("TblJournalAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname); Glclient.GetTblMethodOfPaymentCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblMethodOfPaymentViewModel(); if (row.TblBankTransactionType1 != null) { newrow.BankTransactionTypePerRow = new GenericTable(); newrow.BankTransactionTypePerRow.InjectFrom(row.TblBankTransactionType1); } if (row.TblJournalAccountType1 != null) { newrow.JournalAccountTypePerRow = new GenericTable(); newrow.JournalAccountTypePerRow.InjectFrom(row.TblJournalAccountType1); } newrow.EntityAccountPerRow = sv.entityList.FirstOrDefault(x => x.TblJournalAccountType == row.TblJournalAccountType && x.Iserial == row.Entity); newrow.AccountPerRow = row.TblAccount; 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.UpdateOrInsertTblMethodOfPaymentsCompleted += (s, ev) => { if (ev.Error != null) { MessageBox.Show(ev.Error.Message); } try { MainRowList.ElementAt(ev.outindex).InjectFrom(ev.Result); } catch (Exception) { } }; Glclient.DeleteTblMethodOfPaymentCompleted += (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(); } }