public override DragDropEffects GetDragDropEffect(DragEventArgs eventArgs) { m_nIdBesoinLinkingSatisfaction = null; IDataObject data = eventArgs.Data; DragDropEffects e = DragDropEffects.None; if (!LockEdition) { e = base.GetDragDropEffect(eventArgs); } if (e != DragDropEffects.None) { return(e); } if (m_phaseSpecifications == null) { return(e); } if (m_satisfactionEnCoursDragDrop != null) { //Regarde si la satisfaction peut satisfaire le besoin sous la souris Point pt = m_panelDessin.PointToClient(new Point(eventArgs.X, eventArgs.Y)); int? nItemIndex = GetItemIndexAtPosition(pt.Y); if (nItemIndex != null) { CItemBesoin item = Items[nItemIndex.Value] as CItemBesoin; if (item != null && item.Besoin != null && m_satisfactionEnCoursDragDrop.CanSatisfaire(item.Besoin)) { m_nIdBesoinLinkingSatisfaction = item.Index; return(DragDropEffects.Link); } } else { CBesoin besoinDrag = m_satisfactionEnCoursDragDrop as CBesoin; if (besoinDrag != null && besoinDrag.PhaseSpecifications != m_phaseSpecifications && !LockEdition) { return(DragDropEffects.Copy); } } } return(e); }
//------------------------------------------ private void m_picBox_DragDrop(object sender, DragEventArgs e) { CReferenceObjetDonnee[] refs = e.Data.GetData(typeof(CReferenceObjetDonnee[])) as CReferenceObjetDonnee[]; if (refs == null) { CReferenceObjetDonnee refe = e.Data.GetData(typeof(CReferenceObjetDonnee)) as CReferenceObjetDonnee; if (refe != null) { refs = new CReferenceObjetDonnee[] { refe }; } } if (refs != null) { List <CBesoin> lstBesoins = new List <CBesoin>(); StringBuilder blListe = new StringBuilder(); foreach (CReferenceObjetDonnee refO in refs) { if (typeof(CBesoin).IsAssignableFrom(refO.TypeObjet)) { CBesoin besoin = refO.GetObjet(m_satisfaction.ContexteDonnee) as CBesoin; if (besoin != null) { if (m_satisfaction.CanSatisfaire(besoin)) { lstBesoins.Add(besoin); blListe.Append(besoin.Libelle); blListe.Append(" ,"); } } } } if (lstBesoins.Count > 0) { blListe.Remove(blListe.Length - 2, 2); if (MessageBox.Show(I.T("@1 will be considered as a solution of @2. Continue ?|20631", m_satisfaction.Libelle, blListe.ToString()), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { CContexteDonnee ctx = m_satisfaction.ContexteDonnee; if (!m_bIsEnEdition) { ctx = ctx.GetContexteEdition(); } foreach (CBesoin besoin in lstBesoins) { CBesoin besoinEdit = besoin.GetObjetInContexte(ctx) as CBesoin; besoinEdit.AddSatisfaction(m_satisfaction, null); } if (!m_bIsEnEdition) { CResultAErreur result = ctx.CommitEdit(); if (!result) { CFormAlerte.Afficher(result.Erreur); ctx.CancelEdit(); } ctx.Dispose(); } } } } }