Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
DropAllowedHandler.cs
1using System.Collections;
4using GongSolutions.Wpf.DragDrop;
5
7{
11 public class DropAllowedHandler : DefaultDropHandler
12 {
13 #region Singleton
14
15 private static readonly DropAllowedHandler instance = new DropAllowedHandler();
16
17 // Explicit static constructor to tell C# compiler not to mark type as beforefieldinit
18 static DropAllowedHandler()
19 {
20 }
21
22 private DropAllowedHandler()
23 {
24 }
25
29 public static DropAllowedHandler Instance => instance;
30
31 #endregion
32
33 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
39 public int MaxItemsInTargetCollection { get; set; } = 3;
40
42 public override void DragOver(IDropInfo dropInfo)
43 {
44 dropInfo.DropTargetHintAdorner = DropTargetAdorners.Hint;
45
46 if (dropAllowed(dropInfo))
47 {
48 dropInfo.DropTargetHintState = DropHintState.Active;
49 dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
50 dropInfo.Effects = DragDropEffects.Move;
51 }
52 else
53 {
54 dropInfo.DropTargetHintState = DropHintState.Error;
56 dropInfo.Effects = DragDropEffects.None;
57 }
58 }
59
61 public override void Drop(IDropInfo dropInfo)
62 {
63 if (dropAllowed(dropInfo))
64 {
65 base.Drop(dropInfo);
66 }
67 }
68
69 // only allow drag and drop if the source and destination items have the same swimming style and distance and limit the number of items in the target collection to MaxItemsInTargetCollection
70 private bool dropAllowed(IDropInfo dropInfo)
71 {
72 ICollection sourceCollection = dropInfo.DragInfo.SourceCollection as ICollection;
73 ICollection targetCollection = dropInfo.TargetCollection as ICollection;
74
75 PersonStart dragItem = dropInfo.DragInfo.SourceItem as PersonStart;
76 PersonStart dropItem = dropInfo.TargetItem as PersonStart;
77
78 bool dropAllowed = (targetCollection == sourceCollection ||
79 targetCollection != sourceCollection && targetCollection.Count + 1 <= MaxItemsInTargetCollection);
80 if (!CanAcceptData(dropInfo))
81 {
82 return false;
83 }
84 else if (dragItem != null && dropItem != null)
85 {
86 return dropAllowed &&
87 dragItem.Style == dropItem.Style &&
88 dragItem.CompetitionObj?.Distance == dropItem.CompetitionObj?.Distance;
89 }
90 else if (dragItem != null && dropItem == null && targetCollection.Count == 0)
91 {
92 return dropAllowed;
93 }
94 else if (dragItem != null && dropItem == null && targetCollection.Count > 0)
95 {
96 PersonStart firstStart = (targetCollection as IList)?.Cast<PersonStart>().FirstOrDefault();
97
98 return dropAllowed &&
99 dragItem.Style == firstStart?.Style &&
100 dragItem.CompetitionObj?.Distance == firstStart?.CompetitionObj?.Distance;
101 }
102 return false;
103 }
104
105 }
106}
ushort Distance
Distance in meters for this competition (e.g.
Class describing a start of a person.
Definition PersonStart.cs:9
Competition CompetitionObj
Reference to the competition object to which the start belongs.
Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
static string PersonStartDragDropErrorString
Sucht eine lokalisierte Zeichenfolge, die No dropping allowed here (incompatible styles/distances or ...
static DropAllowedHandler Instance
Singleton instance for the DropAllowedHandler
int MaxItemsInTargetCollection
Maximum items that are allowed in the target collection.