public void AddNewMainRow(bool checkLastRow) { if (AllowAdd != true) { MessageBox.Show(strings.AllowAddMsg); return; } 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 TblColorViewModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; }
public ColorViewModel() { if (!DesignerProperties.IsInDesignTool) { GetItemPermissions(PermissionItemName.ColorCodeForm.ToString()); MainRowList = new SortableCollectionView <TblColorViewModel>(); SelectedMainRow = new TblColorViewModel(); Client.GetGenericCompleted += (s, sv) => { ColorGroupList = sv.Result; }; Client.GetGenericAsync("TblLkpColorGroup", "%%", "%%", "%%", "Iserial", "ASC"); Client.GetTblColorCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblColorViewModel { ColorGroupPerRow = new GenericTable() }; if (row.TblLkpColorGroup1 != null) { newrow.ColorGroupPerRow.InjectFrom(row.TblLkpColorGroup1); } newrow.InjectFrom(row); MainRowList.Add(newrow); } Loading = false; FullCount = sv.fullCount; if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } }; Client.UpdateOrInsertTblColorCompleted += (s, x) => { var savedRow = (TblColorViewModel)MainRowList.GetItemAt(x.outindex); Loading = false; if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblColorCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } Loading = false; var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { MainRowList.Remove(oldrow); } }; GetMaindata(); } }