/// <summary> /// /// </summary> /// <param name="startId"></param> private void DoResetTagId(int startId) { if (CurrentSelectTag != null) { var res = DevelopServiceHelper.Helper.ResetTagIds(GroupModel.Database, new List <int>() { CurrentSelectTag.Id }, startId); if (res != null && res.Count > 0) { CurrentSelectTag.Id = res.First().Value; } } else { var tags = SelectedCells.Select(e => (e.Item as TagViewModel).Id).ToList(); var res = DevelopServiceHelper.Helper.ResetTagIds(GroupModel.Database, new List <int>() { CurrentSelectTag.Id }, startId); if (res != null && res.Count > 0) { foreach (var vv in SelectedCells.Select(e => e.Item).Distinct().ToArray()) { var vvt = vv as TagViewModel; if (res.ContainsKey(vvt.Id)) { vvt.Id = res[vvt.Id]; } } } } }
private void SetSelection(object[] items, LiteRow[] rows, LiteColumn[] columns, UIElement[] cells) { if (_configuringSelection) { return; } _configuringSelection = true; items = items ?? new object[0]; rows = rows ?? new LiteRow[0]; columns = columns ?? new LiteColumn[0]; cells = cells ?? new UIElement[0]; cells = cells .Concat(rows.SelectMany(r => r.Cells)) .Concat(columns.SelectMany(c => c.Cells)) .Concat(_rows.Where(r => items.Contains(r.Item)).SelectMany(r => r.Cells)) .Distinct() .ToArray(); rows = rows .Concat(cells.Select(LiteRow.GetRow)) .Distinct() .ToArray(); columns = columns .Concat(cells.Select(LiteColumn.GetColumn)) .Distinct() .ToArray(); var selection = new List <DependencyObject>(); if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleCell)) { selection.AddRange(cells.Take(1)); } if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiCell)) { selection.AddRange(cells); } if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleRow)) { selection.AddRange(rows.Take(1)); } if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiRow)) { selection.AddRange(rows); } if (SelectionMode.HasFlag(DataGridLiteSelectionMode.SingleColumn)) { selection.AddRange(columns.Take(1)); } if (SelectionMode.HasFlag(DataGridLiteSelectionMode.MultiColumn)) { selection.AddRange(columns); } selection = selection.Distinct().ToList(); // Sync all selection types SelectedCells = selection.OfType <UIElement>().Where(s => cells.Contains(s)).ToArray(); SelectedRows = selection.OfType <LiteRow>().ToArray(); SelectedColumns = selection.OfType <LiteColumn>().ToArray(); SelectedItems = selection.OfType <LiteRow>() .Concat(SelectedCells.Select(LiteRow.GetRow)) .Select(r => r.Item) .ToArray(); SelectedItem = SelectedItems.FirstOrDefault(); var selected = selection.Concat(SelectedItems.OfType <DependencyObject>()).ToList(); selected.ForEach(i => SetIsSelected(i, true)); var deselected = Items.OfType <DependencyObject>() .Concat(_cells) .Concat(_rows) .Concat(_columns) .Where(i => !selected.Contains(i)) .ToList(); deselected.ForEach(i => SetIsSelected(i, false)); _configuringSelection = false; }
///// <summary> ///// ///// </summary> //private void QueryTags() //{ // var vtags = new System.Collections.ObjectModel.ObservableCollection<TagViewModel>(); // var vv = DevelopServiceHelper.Helper.QueryTagByGroup(this.GroupModel.Database, this.GroupModel.FullName); // if (vv != null) // { // foreach (var vvv in vv) // { // Application.Current.Dispatcher.BeginInvoke(new Action(() => { // TagViewModel model = new TagViewModel(vvv.Value.Item1, vvv.Value.Item2); // vtags.Add(model); // })); // } // } // SelectGroupTags = vtags; //} /// <summary> /// /// </summary> private void RemoveTag() { int icount = 0; if (CurrentSelectTag != null) { int ind = mSelectGroupTags.IndexOf(CurrentSelectTag); List <TagViewModel> ll = new List <TagViewModel>(); foreach (var vv in grid.SelectedItems) { ll.Add(vv as TagViewModel); } foreach (var vvv in ll) { if (DevelopServiceHelper.Helper.Remove(GroupModel.Database, vvv.RealTagMode.Id)) { SelectGroupTags.Remove(CurrentSelectTag); icount++; } } if (icount == 0) { if (DevelopServiceHelper.Helper.Remove(GroupModel.Database, CurrentSelectTag.RealTagMode.Id)) { SelectGroupTags.Remove(CurrentSelectTag); icount++; } } if (ind < mSelectGroupTags.Count) { CurrentSelectTag = mSelectGroupTags[ind]; } else { CurrentSelectTag = mSelectGroupTags.Last(); } //if (DevelopServiceHelper.Helper.Remove(GroupModel.Database, CurrentSelectTag.RealTagMode.Id)) //{ // SelectGroupTags.Remove(CurrentSelectTag); //} } else { foreach (var vv in SelectedCells.Select(e => e.Item).Distinct().ToArray()) { var vvt = vv as TagViewModel; if (DevelopServiceHelper.Helper.Remove(GroupModel.Database, vvt.RealTagMode.Id)) { SelectGroupTags.Remove(vvt); icount++; } } } TagCount -= icount; }