//--------------------------------------------- /// <summary> /// Retourne la date de début de la cellule correspondant à X /// </summary> /// <param name="nX"></param> /// <returns></returns> public DateTime GetDateCell(int nX) { DateTime dateDebut = ParametreAffichage.DateDebut; int nCell = nX / ParametreAffichage.CellWidth; return(ParametreAffichage.AddCells(dateDebut, nCell)); }
private void CTimeBar_Paint(object sender, PaintEventArgs e) { DateTime dateDebut = ParametreAffichage.DateDebut; if (m_bIsDragging) { dateDebut = m_dateDragEnCours; } SolidBrush brFond = new SolidBrush(BackColor); e.Graphics.FillRectangle(brFond, ClientRectangle); //Divise en 2 verticalement Pen pen = new Pen(ForeColor); int nYSeparation = ClientSize.Height / 2; e.Graphics.DrawLine(pen, 0, nYSeparation, ClientSize.Width, nYSeparation); int nX = 0; DateTime dt = dateDebut; DateTime lastDateEntete = dateDebut; Brush brTexte = new SolidBrush(ForeColor); while (nX < ClientSize.Width) { Rectangle rct = new Rectangle(nX, nYSeparation + 1, nX + ParametreAffichage.CellWidth, ClientSize.Height - nYSeparation - 2); e.Graphics.FillRectangle(brFond, rct); e.Graphics.DrawRectangle(pen, rct); string strTexteEntete = ""; string strTextCell = ""; DateTime oldDate = dt; switch (ParametreAffichage.Unit) { case EGanttTimeUnit.Hour: if (lastDateEntete.Day != dt.Day || nX == 0) { strTexteEntete = dt.ToShortDateString(); } strTextCell = dt.Hour.ToString("00") + ":00"; break; case EGanttTimeUnit.Day: if (lastDateEntete.Month != dt.Month || nX == 0) { strTexteEntete = dt.ToString("MMM yy"); } strTextCell = dt.ToString("ddd").Substring(0, 1).ToUpper() + " " + dt.ToString("dd"); break; case EGanttTimeUnit.Semaine: if (dt.Month != lastDateEntete.Month) { strTexteEntete = dt.ToString("MMM yyyy"); } strTextCell = CUtilDate.GetWeekNum(dt).ToString(); break; case EGanttTimeUnit.Mois: if (dt.Year != lastDateEntete.Year) { strTexteEntete = dt.Year.ToString(); } strTextCell = dt.ToString("MMM"); break; } if (strTexteEntete.Length > 0) { e.Graphics.FillRectangle(brFond, nX, 0, ClientSize.Width, nYSeparation - 1); e.Graphics.DrawLine(pen, new Point(nX, 0), new Point(nX, nYSeparation)); e.Graphics.DrawString(strTexteEntete, Font, brTexte, new Point(nX, 1)); lastDateEntete = oldDate; } if (dt < DateTime.Now && ParametreAffichage.AddCells(dt, 1) > DateTime.Now) { Brush brFondCell = new SolidBrush(Color.LightGray); e.Graphics.FillRectangle(brFondCell, new Rectangle(nX + 1, nYSeparation + 1, ParametreAffichage.CellWidth - 1, ClientSize.Height - 2)); brFondCell.Dispose(); } e.Graphics.DrawString(strTextCell, Font, brTexte, new Point(nX, nYSeparation + 1)); nX += ParametreAffichage.CellWidth; dt = ParametreAffichage.AddCells(dt, 1); } brTexte.Dispose(); pen.Dispose(); brFond.Dispose(); }
//--------------------------------------------- public DateTime AddCells(DateTime date, int nNbCells) { return(ParametreAffichage.AddCells(date, nNbCells)); }
//---------------------------------------------------------------- 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(); } }