private async void EditClass3Btn_Click(object sender, RoutedEventArgs e) { try { ActiveProgressRing(); if (null == firstCategory.SelectedValue || null == secondCategory.SelectedValue) { return; } var secondCategoryList = CategoryList.Where(x => x.Name == firstCategory.SelectedValue.ToString()).FirstOrDefault().Children; var thirdCategoryList = secondCategoryList.Where(x => x.Name == secondCategory.SelectedValue.ToString()).FirstOrDefault().Children; var currentExists = thirdCategoryList.Select(x => x.Name).ToList(); var text = String.Join(Environment.NewLine, thirdCategory.Items.Select(x => (x as BlockQueryCategory).Name)); CategoryContentDialog dialog = new CategoryContentDialog(text, "三级分类"); var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { var keywordsList = dialog.TextString.Trim('\r').Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); keywordsList.ForEach(item => { if (!currentExists.Contains(item)) { thirdCategoryList.Add(new BlockQueryCategory() { Name = item, Children = null }); } }); var deleteList = currentExists.Except(keywordsList); var removeList = thirdCategoryList.Where(x => deleteList.Contains(x.Name)).ToList(); removeList.ForEach(item => { thirdCategoryList.Remove(item); }); thirdCategory.ItemsSource = null; Class3List.Clear(); thirdCategoryList.ToList().ForEach(item => { Class3List.Add(item); }); thirdCategory.ItemsSource = Class3List; // Thread.Sleep(1000* thirdCategoryList.Count); // thirdCategory.SelectedItem = thirdCategory.Items?.FirstOrDefault(); //thirdCategory.ItemsSource = thirdCategoryList; } } catch (Exception ex) { await MainPage.ShowErrorMessage(ex.Message); } finally { InActiveProgressRing(); } }
public async void EditClass1Btn_Click(object sender, RoutedEventArgs e) { try { if (null == deleteIds) { deleteIds = new List <string>(); } ActiveProgressRing(); var text = String.Join(Environment.NewLine, firstCategory.Items.Select(x => (x as BlockQueryCategory).Name)); CategoryContentDialog dialog = new CategoryContentDialog(text, "一级分类"); var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { var currentExists = CategoryList.Select(x => x.Name).ToList(); var keywordsList = dialog.TextString.Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); keywordsList.ForEach(item => { if (!currentExists.Contains(item)) { CategoryList.Add(new BlockQueryCategory() { Name = item, Children = new List <BlockQueryCategory>() }); } }); var deleteList = currentExists.Except(keywordsList); var removeList = CategoryList.Where(x => deleteList.Contains(x.Name)).ToList(); for (int i = 0; i < removeList.Count; i++) { var isDelete = await WarningTip(removeList[i]); if (isDelete) { deleteIds.Add(removeList[i].Id); if (removeList[i].Children != null && removeList[i].Children.Count > 0) { Class2List.Clear(); Class3List.Clear(); } CategoryList.Remove(removeList[i]); } } Class1List.Clear(); CategoryList.ToList().ForEach(item => { Class1List.Add(item); }); // firstCategory.ItemsSource = CategoryList; //Parallel.ForEach(removeList, async item => //{ // var isDelete = await WarningTip(item); // await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher // .RunAsync(CoreDispatcherPriority.Normal, () => // { // if (isDelete) // { // deleteIds.Add(item._id); // CategoryList.Remove(item); // } // }); //}); // Thread.Sleep(1000 * CategoryList.Count); // firstCategory.SelectedItem = firstCategory.Items?.FirstOrDefault(); } } catch (Exception ex) { await MainPage.ShowErrorMessage(ex.Message); } finally { InActiveProgressRing(); } }