コード例 #1
0
        /// <summary>
        /// Constructor for the RegisterEventWindow form.
        /// </summary>
        /// <param name="selectedDate">The date selected by the user.</param>
        /// <param name="use24Hour">Whether 24 hour time will be used.</param>
        /// <param name="username">The name provided by the user.</param>
        public RegisterEventWindow(DateTime selectedDate, bool use24Hour, string username)
        {
            InitializeComponent();
            userName       = username;
            dateLabel.Text = "Adding event for: " + selectedDate.ToShortDateString();

            //int local_hrs;

            ComboBoxDateTime currentTime = new ComboBoxDateTime(selectedDate, use24Hour);


            /*
            ** To show only valid time slots. For today, don't show time slots for time that has passed.
            */
            //If the selected date is after today, show all 48 time slots. That is, let the loop run 48 times.
            //if ( selectedDate.Date > DateTime.Now)
            //{
            //    currentTime = new ComboBoxDateTime(selectedDate.Date, use24Hour);
            //    local_hrs = -1;
            //}

            ////If the selected date is today, round off to the nearest next half hour using the Round method. Pass that to ComboBoxDateTime
            ////Loop should run such that only slots till midnight are displayed. Should not run 48 times.
            //else
            //{
            //    DateTime test = Round(DateTime.Now); //Get current time rounded to the next hour
            //    currentTime = new ComboBoxDateTime(test, use24Hour);
            //    local_hrs = DateTime.Now.Hour*2;
            //}

            for (int i = 0; i < 48; i++)
            {
                if (currentTime.inner >= DateTime.Now)
                {
                    halfHourDateTimes.Add(currentTime);
                    halfHourDateTimesForEnd.Add(currentTime);
                }
                currentTime = new ComboBoxDateTime(currentTime.inner.AddMinutes(30), use24Hour);
            }
            DateTime midnight = selectedDate.AddDays(1);

            halfHourDateTimesForEnd.Add(new ComboBoxDateTime(midnight, use24Hour));
            //use the list of times as the list of options for our time boxes
            startTimeBox.DataSource    = halfHourDateTimes;
            startTimeBox.DisplayMember = "shortTimeString";

            endTimeBox.BindingContext = new BindingContext();
            endTimeBox.DataSource     = halfHourDateTimesForEnd;
            endTimeBox.DisplayMember  = "shortTimeStringForEndBoxes";

            //put the time boxes in a tuple to associate them and put it in a list to keep track of it
            timeBoxes.Add(new Tuple <ComboBox, ComboBox>(startTimeBox, endTimeBox));
        }
コード例 #2
0
        /// <summary>
        /// Constructor for the RegisterEventWindow form.
        /// </summary>
        /// <param name="selectedDate">The date selected by the user.</param>
        /// <param name="use24Hour">Whether 24 hour time will be used.</param>
        /// <param name="username">The name provided by the user.</param>
        public RegisterEventWindow(DateTime selectedDate, bool use24Hour, string username)
        {
            InitializeComponent();
            userName       = username;
            dateLabel.Text = "Adding event";

            ComboBoxDateTime currentTime = new ComboBoxDateTime(selectedDate, use24Hour);


            /*
            ** To show only valid time slots. For today, don't show time slots for time that has passed.
            */
            //If the selected date is after today, show all 48 time slots. That is, let the loop run 48 times.
            //if ( selectedDate.Date > DateTime.Now)
            //{
            //    currentTime = new ComboBoxDateTime(selectedDate.Date, use24Hour);
            //    local_hrs = -1;
            //}

            ////If the selected date is today, round off to the nearest next half hour using the Round method. Pass that to ComboBoxDateTime
            ////Loop should run such that only slots till midnight are displayed. Should not run 48 times.
            //else
            //{
            //    DateTime test = Round(DateTime.Now); //Get current time rounded to the next hour
            //    currentTime = new ComboBoxDateTime(test, use24Hour);
            //    local_hrs = DateTime.Now.Hour*2;
            //}

            for (int i = 0; i < 48; i++)
            {
                halfHourDateTimes.Add(currentTime);
                halfHourDateTimesForEnd.Add(currentTime);
                currentTime = new ComboBoxDateTime(currentTime.inner.AddMinutes(30), use24Hour);
            }
            DateTime midnight = selectedDate.AddDays(1);

            halfHourDateTimesForEnd.Add(new ComboBoxDateTime(midnight, use24Hour));

            // add label for the initial day
            Label newDateLabel = new Label();

            // add stuff to new label
            newDateLabel.Text      = selectedDate.ToShortDateString();
            newDateLabel.Size      = new System.Drawing.Size(150, 24);
            newDateLabel.TextAlign = ContentAlignment.MiddleCenter;

            // add set time button for initial day
            Button newDateButton = new Button();

            // add stuff to new button
            newDateButton.Text   = "Set Times from Below";
            newDateButton.Size   = new System.Drawing.Size(150, 24);
            newDateButton.Tag    = selectedDate;
            newDateButton.Click += new EventHandler(this.setDayTimes);

            // add to the list of the combos
            dateBox.Add(new Tuple <Label, Button>(newDateLabel, newDateButton));

            // add them to the flowchart
            flowLayoutPanel3.Controls.Add(newDateButton);
            flowLayoutPanel3.Controls.Add(newDateLabel);
            flowLayoutPanel3.SetFlowBreak(newDateLabel, true);
        }