public void AddNewMainRow(bool checkLastRow) { if (AllowAdd != true) { MessageBox.Show(strings.AllowAddMsg); return; } var currentRowIndex = (MainRowList.IndexOf(SelectedMainRow)); if (!checkLastRow || currentRowIndex == (MainRowList.Count - 1)) { if (checkLastRow) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (!isvalid) { return; } } MainRowList.Insert(currentRowIndex + 1, new TblSalesOrderColorThemeViewModel()); var newrow = new TblSalesOrderColorThemeViewModel(); MainRowList.Insert(currentRowIndex + 1, newrow); SelectedMainRow = newrow; } }
public SalesOrderColorThemeViewModel() { if (!DesignerProperties.IsInDesignTool) { GetItemPermissions(PermissionItemName.ColorThemesForm.ToString()); lkpClient.GetTblBrandSectionLinkCompleted += (s, sv) => { BrandSectionList.Clear(); foreach (var row in sv.Result) { BrandSectionList.Add(new GenericTable().InjectFrom(row.TblLkpBrandSection1) as GenericTable); } }; var seasonClient = new CRUD_ManagerServiceClient(); seasonClient.GetGenericCompleted += (s, sv) => { SeasonList = sv.Result; }; seasonClient.GetGenericAsync("TblLkpSeason", "%%", "%%", "%%", "Iserial", "ASC"); MainRowList = new SortableCollectionView <TblSalesOrderColorThemeViewModel>(); MainRowList.CollectionChanged += MainRowList_CollectionChanged; SelectedMainRow = new TblSalesOrderColorThemeViewModel(); Client.GetAllBrandsCompleted += (s, sv) => { BrandList = sv.Result; }; Client.GetAllBrandsAsync(LoggedUserInfo.Iserial); Client.GetTblSalesOrderColorThemeCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblSalesOrderColorThemeViewModel(); newrow.InjectFrom(row); MainRowList.Add(newrow); } Loading = false; FullCount = sv.fullCount; if (MainRowList.Any() && (SelectedMainRow == null || SelectedMainRow.Iserial == 0)) { SelectedMainRow = MainRowList.FirstOrDefault(); } if (FullCount == 0 && MainRowList.Count == 0) { AddNewMainRow(false); } if (Export) { Export = false; ExportGrid.ExportExcel("Style"); } }; Client.UpdateOrInsertTblSalesOrderColorThemeCompleted += (s, x) => { var savedRow = (TblSalesOrderColorThemeViewModel)MainRowList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblSalesOrderColorThemeCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result.Iserial); if (oldrow != null) { MainRowList.Remove(oldrow); } if (!MainRowList.Any()) { AddNewMainRow(false); } }; // Client.GetSeasonalMasterListNotLinkedToSalesorder } }