Using a Gantt Chart for Classroom Scheduling
Details
Date:10/16/2008 1:33:21 AM
Product:ActiveGanttCSN Gantt Chart / Scheduler Component
Framework:.Net Framework 1.0
Version:2.7.0.0
User's Development Environment:C# Visual Studio 2003
Subject:Classroom School Scheduler
Question

I'm doing a scheduler for a school. The school hour is 8 hrs per day and I don't need the full 24 hrs to be in my scheduler. Is it possible to limit the hours per day in the TimeLine Object? If yes, then please forward me some examples based on my problem. And again...in between school hours break hr is there. So how we can manage the break hrs?

I'm describing my problem a little broader.

I need the to show the time block from today(16th Oct, 2008) to 15th Oct, 2009 i.e. 1 year.

And the tier type should be customized.

I'm using the code below:


activeGanttCSNCtl1.Views.Add("30s", "15n", AGCSN.E_TIERTYPE.ST_CUSTOM, AGCSN.E_TIERTYPE.ST_CUSTOM, AGCSN.E_TIERTYPE.ST_CUSTOM, "");
activeGanttCSNCtl1.Views.Item("1").TimeLine.TierArea.UpperTier.Interval = "1m";
activeGanttCSNCtl1.Views.Item("1").TimeLine.TierArea.UpperTier.Height = 17;
activeGanttCSNCtl1.Views.Item("1").TimeLine.TierArea.LowerTier.Interval = "1d";
activeGanttCSNCtl1.Views.Item("1").TimeLine.TierArea.LowerTier.Height = 17;

I need to limit the day from 24 hrs to only 9 hrs (i.e. from 9.00 to 18.00 ) and rest times should not display in the scheduler.

Please forward me the code which will suitable for my application.

Answer

Answer:

Why are you using custom tier types, wouldn’t it be more useful, if you could see the hours?

You want to hide hours from 18:00 to 09:00 that’s OK but I imagine that you do not want to hide breaks right (by the way this cannot be done in ActiveGantt)?

In this new version I will be sending you there are two types of TimeBlock objects:

1. The ones that have the property GenerateConflict = True. In these timeblocks, tasks and milestones cannot be inside the TimeBlocks either partially or totally.

2. The ones that have the property GenerateConflict = False. In these you can include tasks and milestones either partially or totally.

The windows forms code (C#) would be the following:


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace AGCSNCON
{
    /// <summary>
    /// Summary description for fProjectManagement02.
    /// </summary>
    public class fProjectManagement02Copy : System.Windows.Forms.Form
    {
        private AGCSN.ActiveGanttCSNCtl activeGanttCSNCtl1;
        internal System.Windows.Forms.ImageList imglstColumns;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.ComponentModel.IContainer components;

        static void Main()
        {
            Application.Run(new fProjectManagement02Copy());
        }

        public fProjectManagement02Copy()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(fProjectManagement02));
            this.activeGanttCSNCtl1 = new AGCSN.ActiveGanttCSNCtl();
            this.imglstColumns = new System.Windows.Forms.ImageList(this.components);
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // activeGanttCSNCtl1
            // 
            this.activeGanttCSNCtl1.AddMode = AGCSN.E_ADDMODE.AT_TASKADD;
            this.activeGanttCSNCtl1.AllowAdd = true;
            this.activeGanttCSNCtl1.AllowColumnSize = true;
            this.activeGanttCSNCtl1.AllowColumnSwap = true;
            this.activeGanttCSNCtl1.AllowEdit = true;
            this.activeGanttCSNCtl1.AllowRowSize = true;
            this.activeGanttCSNCtl1.AllowRowSwap = true;
            this.activeGanttCSNCtl1.AllowSplitterMove = true;
            this.activeGanttCSNCtl1.AllowTimeLineScroll = true;
            this.activeGanttCSNCtl1.BorderStyle = AGCSN.E_BORDERSTYLE.TLB_3D;
            this.activeGanttCSNCtl1.CurrentLayer = "0";
            this.activeGanttCSNCtl1.CurrentView = "0";
            this.activeGanttCSNCtl1.EditMode = AGCSN.E_EDITMODE.ET_TASKMILESTONE;
            this.activeGanttCSNCtl1.EnableObjects = AGCSN.E_ENABLEOBJECTS.EO_CURRENTLAYERONLY;
            this.activeGanttCSNCtl1.ErrorReports = AGCSN.E_REPORTERRORS.RE_MSGBOX;
            this.activeGanttCSNCtl1.FlickerFree = true;
            this.activeGanttCSNCtl1.Location = new System.Drawing.Point(8, 16);
            this.activeGanttCSNCtl1.MinColumnWidth = 5;
            this.activeGanttCSNCtl1.MinRowHeight = 5;
            this.activeGanttCSNCtl1.Name = "activeGanttCSNCtl1";
            this.activeGanttCSNCtl1.ScrollBarBehaviour = AGCSN.E_SCROLLBEHAVIOUR.SB_HIDE;
            this.activeGanttCSNCtl1.SelectedCellIndex = 0;
            this.activeGanttCSNCtl1.SelectedColumnIndex = 0;
            this.activeGanttCSNCtl1.SelectedMilestoneIndex = 0;
            this.activeGanttCSNCtl1.SelectedRowIndex = 0;
            this.activeGanttCSNCtl1.SelectedTaskIndex = 0;
            this.activeGanttCSNCtl1.Size = new System.Drawing.Size(760, 536);
            this.activeGanttCSNCtl1.TabIndex = 1;
            this.activeGanttCSNCtl1.TimeBlockBehaviour = AGCSN.E_TIMEBLOCKBEHAVIOUR.TBB_ROWEXTENTS;
            this.activeGanttCSNCtl1.TP_Caption = null;
            this.activeGanttCSNCtl1.TP_DisplayToolTip = false;
            // 
            // imglstColumns
            // 
            this.imglstColumns.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.imglstColumns.ImageSize = new System.Drawing.Size(16, 16);
            this.imglstColumns.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imglstColumns.ImageStream")));
            this.imglstColumns.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                    this.activeGanttCSNCtl1});
            this.groupBox1.Location = new System.Drawing.Point(8, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(776, 560);
            this.groupBox1.TabIndex = 2;
            this.groupBox1.TabStop = false;
            // 
            // fProjectManagement02
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(792, 573);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.groupBox1});
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Name = "fProjectManagement02";
            this.Text = "fProjectManagement02";
            this.Load += new System.EventHandler(this.fProjectManagement02_Load);
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        

        

        private void fProjectManagement02_Load(object sender, System.EventArgs e)
        {
            this.Text = "The Source Code Store - ActiveGantt Scheduler Control Version " + activeGanttCSNCtl1.Version + " - Project Management Example";


            activeGanttCSNCtl1.DefaultValues.RowHeight = 20;
            activeGanttCSNCtl1.TimeBlockBehaviour = AGCSN.E_TIMEBLOCKBEHAVIOUR.TBB_CONTROLEXTENTS;

            activeGanttCSNCtl1.Styles.Add("Title");
            activeGanttCSNCtl1.Styles.Item("Title").CaptionAlignmentHorizontal = AGCSN.GRE_HORIZONTALALIGNMENT.HAL_LEFT;
            activeGanttCSNCtl1.Styles.Item("Title").CaptionXMargin = 5;
            activeGanttCSNCtl1.Styles.Item("Title").Font = new System.Drawing.Font("Microsoft Sans Serif", 8, FontStyle.Bold);

            activeGanttCSNCtl1.Styles.Add("Task");
            activeGanttCSNCtl1.Styles.Item("Task").CaptionAlignmentHorizontal = AGCSN.GRE_HORIZONTALALIGNMENT.HAL_LEFT;
            activeGanttCSNCtl1.Styles.Item("Task").CaptionXMargin = 25;
            activeGanttCSNCtl1.Styles.Item("Task").Font = new System.Drawing.Font("Microsoft Sans Serif", 7);
            activeGanttCSNCtl1.Styles.Item("Task").BorderStyle = AGCSN.E_STYLEBORDER.SBR_NONE;
            activeGanttCSNCtl1.Styles.Item("Task").Appearance = AGCSN.E_STYLEAPPEARANCE.SA_CELL;
            activeGanttCSNCtl1.Styles.Item("Task").BackColor = System.Drawing.Color.White;
            activeGanttCSNCtl1.Styles.Item("Task").BorderColor = System.Drawing.Color.LightGray;

            activeGanttCSNCtl1.Styles.Add("Columns");
            activeGanttCSNCtl1.Styles.Item("Columns").CaptionAlignmentVertical = AGCSN.GRE_VERTICALALIGNMENT.VAL_BOTTOM;
            activeGanttCSNCtl1.Styles.Item("Columns").CaptionYMargin = 5;
            activeGanttCSNCtl1.Styles.Item("Columns").Font = new System.Drawing.Font("Microsoft Sans Serif", 8, FontStyle.Bold);
            activeGanttCSNCtl1.Styles.Item("Columns").PictureAlignmentVertical = AGCSN.GRE_VERTICALALIGNMENT.VAL_BOTTOM;



            activeGanttCSNCtl1.Styles.Add("TimeBlocks");
            activeGanttCSNCtl1.Styles.Item("TimeBlocks").Appearance = AGCSN.E_STYLEAPPEARANCE.SA_FLAT;
            activeGanttCSNCtl1.Styles.Item("TimeBlocks").BackColor = System.Drawing.Color.LightGray;
            activeGanttCSNCtl1.Styles.Item("TimeBlocks").BackgroundPattern = AGCSN.GRE_BACKGROUNDPATTERN.FP_SOLID;




            activeGanttCSNCtl1.Columns.Add("", 25, "0");
            activeGanttCSNCtl1.Columns.Item("1").Caption = "ID";
            activeGanttCSNCtl1.Columns.Item("1").Width = 25;
            activeGanttCSNCtl1.Columns.Item("1").StyleIndex = "Columns";

            activeGanttCSNCtl1.Columns.Add("", 25, "0");
            activeGanttCSNCtl1.Columns.Item("2").Width = 30;
            activeGanttCSNCtl1.Columns.Item("2").StyleIndex = "Columns";
            activeGanttCSNCtl1.Columns.Item("2").Picture = imglstColumns.Images[0];

            activeGanttCSNCtl1.Columns.Add("Task Name", 25, "");
            activeGanttCSNCtl1.Columns.Item("3").Width = 200;
            activeGanttCSNCtl1.Columns.Item("3").StyleIndex = "Columns";

            AddRowTitle("K1", "General Classroom Building", true);
            AddRowItem("K2", "Room 101");
            AddRowItem("K3", "Room 102");
            AddRowItem("K4", "Room 103");
            AddRowItem("K5", "Room 104");
            AddRowItem("K6", "Room 105");
            AddRowItem("K7", "Room 106");
            AddRowItem("K8", "Room 201");
            AddRowItem("K9", "Room 202");
            AddRowTitle("K10", "Science Building", false);
            AddRowItem("K11", "Lab 101");
            AddRowItem("K12", "Lab 102");
            AddRowItem("K13", "Lab 103");
            AddRowItem("K14", "Lab 104");
            AddRowItem("K15", "Lab 201");
            AddRowItem("K16", "Lab 202");
            AddRowItem("K17", "Lab 203");
            AddRowItem("K18", "Lab 204");
            AddRowItem("K19", "Lab 205");
            AddRowTitle("K20", "Music Classroom Building", false);
            AddRowItem("K21", "Room 101");
            AddRowItem("K22", "Room 102");
            AddRowItem("K23", "Room 103");
            AddRowItem("K24", "Auditorium");

            activeGanttCSNCtl1.TimeBlocks.Add(NewDate(12, 1, 2002, 12, 0), NewDate(12, 1, 2002, 13, 30), "Lunch", "TimeBlocks");
            activeGanttCSNCtl1.TimeBlocks.Item("Lunch").GenerateConflict = true;

            activeGanttCSNCtl1.TimeBlocks.Add(NewDate(12, 1, 2002, 18, 0), NewDate(12, 1, 2002, 20, 0), "AfterSchool", "TimeBlocks");





            
            activeGanttCSNCtl1.Views.Add("30s", "1h", AGCSN.E_TIERTYPE.ST_MONTH, AGCSN.E_TIERTYPE.ST_DAYOFWEEK, AGCSN.E_TIERTYPE.ST_HOUR, "");
            activeGanttCSNCtl1.Views.Item("1").TimeLine.TickMarkArea.Visible = false;




            activeGanttCSNCtl1.Views.Item("1").TimeLine.TierArea.MiddleTier.Visible = true;

            activeGanttCSNCtl1.Views.Item("1").TimeLine.ScrollBar.StartDate = NewDate(12, 1, 2002, 9, 0);
            activeGanttCSNCtl1.Views.Item("1").TimeLine.ScrollBar.Interval = "10n";
            activeGanttCSNCtl1.Views.Item("1").TimeLine.ScrollBar.SmallChange = 10;
            activeGanttCSNCtl1.Views.Item("1").TimeLine.ScrollBar.LargeChange = 10;
            activeGanttCSNCtl1.Views.Item("1").TimeLine.ScrollBar.Max = 42;
            activeGanttCSNCtl1.Views.Item("1").TimeLine.ScrollBar.Enabled = true;
            activeGanttCSNCtl1.Views.Item("1").TimeLine.ScrollBar.Visible = true;
            activeGanttCSNCtl1.Views.Item("1").ClientArea.Grid.Interval = "15n";
            activeGanttCSNCtl1.Views.Item("1").ClientArea.Grid.SnapToGrid = true;
            activeGanttCSNCtl1.Views.Item("1").ClientArea.Grid.VerticalLines = true;







            activeGanttCSNCtl1.CurrentView = "1";
            activeGanttCSNCtl1.Splitter.Position = 255;
            activeGanttCSNCtl1.Redraw();
        }

        private DateTime NewDate(int Month, int Day, int Year, int Hour, int Minute)
        {
            return new DateTime(Year, Month, Day, Hour, Minute, 0, 0);
        }

        private void AddRowTitle(String Key, String Caption, bool Container)
        {
            activeGanttCSNCtl1.Rows.Add(Key, Key, false, false, "");
            activeGanttCSNCtl1.Rows.Item(Key).Cells.Item("3").Caption = Caption;
            activeGanttCSNCtl1.Rows.Item(Key).Cells.Item("3").StyleIndex = "Title";
            if (Container == false)
            {
                activeGanttCSNCtl1.Rows.Item(Key).Container = false;
                activeGanttCSNCtl1.Rows.Item(Key).ClientAreaStyleIndex = "0";
            }
            else
            {
                activeGanttCSNCtl1.Rows.Item(Key).Container = true;
            }
            activeGanttCSNCtl1.Rows.Item(Key).Cells.Item("1").Caption = System.Text.RegularExpressions.Regex.Replace(Key, "K", "");
        }

        private void AddRowItem(String Key, String Caption)
        {
            activeGanttCSNCtl1.Rows.Add(Key, Key, false, true, "");
            activeGanttCSNCtl1.Rows.Item(Key).Cells.Item("3").Caption = Caption;
            activeGanttCSNCtl1.Rows.Item(Key).Cells.Item("3").StyleIndex = "Task";
            activeGanttCSNCtl1.Rows.Item(Key).Cells.Item("1").Caption = System.Text.RegularExpressions.Regex.Replace(Key, "K", "");
        }

        private void AddTaskStyle(String Key, Color BackColor, Color BorderColor)
        {
            activeGanttCSNCtl1.Styles.Add(Key);
            activeGanttCSNCtl1.Styles.Item(Key).Appearance = AGCSN.E_STYLEAPPEARANCE.SA_FLAT;
            activeGanttCSNCtl1.Styles.Item(Key).BackgroundPattern = AGCSN.GRE_BACKGROUNDPATTERN.FP_DOWNWARDDIAGONAL;
            activeGanttCSNCtl1.Styles.Item(Key).Placement = AGCSN.E_PLACEMENT.PLC_OFFSETPLACEMENT;
            activeGanttCSNCtl1.Styles.Item(Key).BackColor = BackColor;
            activeGanttCSNCtl1.Styles.Item(Key).BorderColor = BorderColor;
            activeGanttCSNCtl1.Styles.Item(Key).BorderStyle = AGCSN.E_STYLEBORDER.SBR_SINGLE;
            activeGanttCSNCtl1.Styles.Item(Key).OffsetTop = 5;
            activeGanttCSNCtl1.Styles.Item(Key).OffsetBottom = 10;
            activeGanttCSNCtl1.Styles.Item(Key).SelectionRectangleVisible = true;
            activeGanttCSNCtl1.Styles.Item(Key).SelectionRectangleOffsetTop = 0;
            activeGanttCSNCtl1.Styles.Item(Key).SelectionRectangleOffsetLeft = 0;
            activeGanttCSNCtl1.Styles.Item(Key).SelectionRectangleOffsetRight = 0;
            activeGanttCSNCtl1.Styles.Item(Key).SelectionRectangleOffsetBottom = 0;
        }












    }
}


this code will produce an output like the following:

The timeblock in grey will generate conflicts with tasks or milestones.

You will need version 2.7.5.0 or higher in order for this code to work.

The ActiveGantt and XTTreeview Dlls plus the code for the windows forms control

can be downloaded here in .zip format

 

All trademarks are property of their respective holders, and are only used to directly describe the products and services being provided. Their use in no way indicates any relationship or endorsement between The Source Code Store LLC and the holders of said trademarks.