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; } } var newrow = new TblUserCheckListViewModel { TblAuthUser = LoggedUserInfo.Iserial }; MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public UserCheckListViewModel() { if (!DesignerProperties.IsInDesignTool) { MainRowList = new SortableCollectionView <TblUserCheckListViewModel>(); SelectedMainRow = new TblUserCheckListViewModel(); Client.GetGenericAsync("TblCheckListGroup", "%%", "%%", "%%", "Iserial", "ASC"); Client.GetGenericCompleted += (s, sv) => { CheckListGroupList = new ObservableCollection <GenericTable>(); foreach (var variable in sv.Result) { CheckListGroupList.Add(variable); } }; Client.GetTblUserCheckListCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblUserCheckListViewModel(); newrow.InjectFrom(row); newrow.CheckListGroupPerRow = new GenericTable(); newrow.CheckListGroupPerRow.InjectFrom(row.TblCheckListGroup1); MainRowList.Add(newrow); } Loading = false; if (MainRowList.Any() && (SelectedMainRow == null || SelectedMainRow.Iserial == 0)) { SelectedMainRow = MainRowList.FirstOrDefault(); } if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } if (Export) { Export = false; //var handler = ExportCompleted; //if (handler != null) handler(this, EventArgs.Empty); //ExportGrid.ExportExcel("Style"); } }; Client.UpdateOrInsertTblUserCheckListCompleted += (s, x) => { var savedRow = (TblUserCheckListViewModel)MainRowList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblUserCheckListCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { MainRowList.Remove(oldrow); } if (!MainRowList.Any()) { AddNewMainRow(false); } }; } }