//---------------------------------------------------------------- void itemControlDates_OnValueChanged(object sender, EventArgs e) { if (!LockEdition && SelectedElement != null) { CToolStripDateTimePicker picker = sender as CToolStripDateTimePicker; if (picker != null) { DateTime dtStart = picker.StartDate; DateTime dtEnd = picker.EndDate; TimeSpan duree = dtEnd - dtStart; TimeSpan ecart = dtStart - SelectedElement.DateDebut; //SelectedElement.Move(ecart, duree, EModeDeplacementProjet.MoveAutoOnly, true); MoveElement(ecart, duree); picker.GetCurrentParent().Visible = false; Refresh(); if (SelectedElement.ElementParent != null) { SelectedElement.DatesAreDirty = true; } } } }
//---------------------------------------------------------------- private void CGanttBar_MouseUp(object sender, MouseEventArgs e) { Capture = false; Point ptMenu = new Point(e.X, e.Y); ptMenu = PointToScreen(ptMenu); if (!m_bDragEnCours) { IElementDeGantt eltSel = GetElementAt(new Point(e.X, e.Y)); if (eltSel == null) { KeyValuePair <IElementDeGantt, int[]>?sel = m_dicElementGanttToZoneY.FirstOrDefault(kv => kv.Value[0] < e.Y && kv.Value[1] > e.Y); if (sel != null) { eltSel = sel.Value.Key; } } if (eltSel != null) { if (!LockEdition) { if ((e.Button & MouseButtons.Left) == MouseButtons.Left && ModifierKeys == Keys.Control && SelectedElement != null) { if (eltSel is CElementDeGanttProjet && SelectedElement is CElementDeGanttProjet) { if (eltSel.Predecesseurs.Contains(SelectedElement)) { if (MessageBox.Show(I.T("Remove dependancy between @1 and @2 ?|20002", eltSel.Libelle, SelectedElement.Libelle), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { eltSel.RemovePredecesseur(SelectedElement); Refresh(); } } else { if (MessageBox.Show(I.T("Create dependancy between @1 and @2 ?|20003", eltSel.Libelle, SelectedElement.Libelle), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { CResultAErreur result = eltSel.AddPredecesseur(SelectedElement); if (!result) { CFormAfficheErreur.Show(result.Erreur); } else { Refresh(); } } } } } } //Acces direct ? Point pt = new Point(e.X, e.Y); KeyValuePair <IElementDeGantt, Rectangle>?kv = m_dicElementGanttToRectangleAccesDirect.FirstOrDefault ( k => k.Value.Contains(pt) ); if (kv != null && kv.Value.Key != null) { ParametreAffichage.DateDebut = ParametreAffichage.AddCells(kv.Value.Key.DateDebut, -1); } SelectedElement = eltSel; } else { SelectedElement = null; } // Gestion du menu contextuel if ((e.Button & MouseButtons.Right) == MouseButtons.Right) { ContextMenuStrip menuElementDeGantt = new ContextMenuStrip(); menuElementDeGantt.Opening += new CancelEventHandler(menuElementDeGantt_Opening); if (SelectedElement != null) { bool bEnableMenu = !LockEdition; // Ajoute les items sur l'élement de Gantt ToolStripMenuItem itemLabelElementDeGantt = new ToolStripMenuItem(SelectedElement.Libelle); itemLabelElementDeGantt.Enabled = false; CToolStripDateTimePicker itemControlDateDebut = new CToolStripDateTimePicker(); itemControlDateDebut.StartDate = SelectedElement.DateDebut; itemControlDateDebut.EndDate = SelectedElement.DateFin; itemControlDateDebut.OnValideDates += new EventHandler(itemControlDates_OnValueChanged); itemControlDateDebut.Enabled = bEnableMenu; menuElementDeGantt.Items.Add(itemLabelElementDeGantt); menuElementDeGantt.Items.Add(itemControlDateDebut); menuElementDeGantt.Items.Add(new ToolStripSeparator()); } else { ToolStripMenuItem itemTitre = new ToolStripMenuItem("-----------------"); // Juste pour permetre au menu de s'ouvrir même si Selectedelement est null itemTitre.Enabled = false; menuElementDeGantt.Items.Add(itemTitre); } // Affiche le menu contextuel sur elements de Gantt menuElementDeGantt.Show(ptMenu); } } else { DrawImageDragDrop(); if (m_imageDragEnCours != null) { m_imageDragEnCours.Dispose(); m_imageDragEnCours = null; } m_bDragEnCours = false; m_fournisseurX.Highlight(-1, -1); DateTime dateDebut = m_fournisseurX.AddCells(SelectedElement.DateDebut, (int)((e.X - m_nXStartDrag) / ParametreAffichage.CellWidth)); TimeSpan sp = dateDebut - SelectedElement.DateDebut; //SelectedElement.Move(sp, null, EModeDeplacementProjet.MoveAutoOnly, true); bool bDoMove = true; if (BeforeMoveBar != null) { MovingBar = SelectedElement; bDoMove = BeforeMoveBar("BeforeMoveBar", this); } if (bDoMove) { MoveElement(sp, null); } Refresh(); } }