Exemplo n.º 1
0
        public CoursePanel(Course course)
        {
            CheckBox enabledCheckBox = new CheckBox();
            ComboBox groupComboBox = course.HasGroups ? new ComboBox() : null;
            ComboBox levelComboBox = course.HasLevels ? new ComboBox() : null;
            IntegerTextBox scoreTextBox = new IntegerTextBox();
            CoursePanel panel = new CoursePanel(course, enabledCheckBox, groupComboBox, levelComboBox, scoreTextBox);

            panel.SuspendLayout();
            panel.Location = new Point(3, 3);
            panel.Size = new Size(346, 27);

            enabledCheckBox.AutoSize = true;
            enabledCheckBox.Location = new Point(3, 3);
            enabledCheckBox.TabStop = false;
            enabledCheckBox.UseVisualStyleBackColor = true;
            panel.Controls.Add(enabledCheckBox);

            if (groupComboBox != null)
            {
                groupComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                groupComboBox.Location = new Point(106, 3);
                groupComboBox.Size = new Size(100, 21);
                groupComboBox.TabStop = false;
                panel.Controls.Add(groupComboBox);
            }

            if (levelComboBox != null)
            {
                levelComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                levelComboBox.Location = new Point(212, 3);
                levelComboBox.Size = new Size(100, 21);
                levelComboBox.TabStop = false;
                panel.Controls.Add(levelComboBox);
            }

            scoreTextBox.Location = new Point(318, 3);
            scoreTextBox.Size = new Size(25, 20);
            scoreTextBox.TabStop = true;
            scoreTextBox.TextAlign = HorizontalAlignment.Center;
            scoreTextBox.AutoClear = true;
            scoreTextBox.MinValue = 0;
            scoreTextBox.MaxValue = 100;
            panel.Controls.Add(scoreTextBox);

            panel.ResumeLayout(false);
            panel.PerformLayout();

            _course = new CourseWrapper(course);
            _nameControl = enabledCheckBox;
            _groupComboBox = groupComboBox;
            _levelComboBox = levelComboBox;
            _scoreTextBox = scoreTextBox;

            // ReSharper disable once CoVariantArrayConversion
            if (course.HasGroups) _groupComboBox.Items.AddRange(_course.Groups);

            enabledCheckBox.CheckedChanged += OnEnabledUpdated;
            if (groupComboBox != null) groupComboBox.SelectedIndexChanged += OnGroupUpdated;
            if (levelComboBox != null) levelComboBox.SelectedIndexChanged += OnLevelUpdated;
            scoreTextBox.TextChanged += OnScoreUpdated;

            //Now we can load the dataz!
            _suppressUpdate = true;

            enabledCheckBox.Checked = _course.Enabled;
            scoreTextBox.Text = _course.Score.ToString();

            if (groupComboBox != null)
            {
                if (_course.SelectedGroup == null)
                {
                    //Default to first group if there is no group selected 
                    //and there are groups available
                    _course.SelectedGroup = _course.Groups[0];
                }
                groupComboBox.SelectedItem = _course.SelectedGroup;
            }
            else if (levelComboBox != null)
            {
                _course.SelectedGroup = _course.Groups[0];
            }

            if (levelComboBox != null)
            {
                _levelComboBox.Items.Clear();
                // ReSharper disable once CoVariantArrayConversion
                _levelComboBox.Items.AddRange(_course.SelectedGroup.Levels);
                if (_course.SelectedLevel == null)
                {
                    _course.SelectedLevel = _course.SelectedGroup.Levels[0];
                }
                levelComboBox.SelectedItem = _course.SelectedLevel;
            }

            _suppressUpdate = false;
        }
Exemplo n.º 2
0
        public CoursePanel(Course course)
        {
            CheckBox       enabledCheckBox = new CheckBox();
            ComboBox       groupComboBox   = course.HasGroups ? new ComboBox() : null;
            ComboBox       levelComboBox   = course.HasLevels ? new ComboBox() : null;
            IntegerTextBox scoreTextBox    = new IntegerTextBox();
            CoursePanel    panel           = new CoursePanel(course, enabledCheckBox, groupComboBox, levelComboBox, scoreTextBox);

            panel.SuspendLayout();
            panel.Location = new Point(3, 3);
            panel.Size     = new Size(346, 27);

            enabledCheckBox.AutoSize = true;
            enabledCheckBox.Location = new Point(3, 3);
            enabledCheckBox.TabStop  = false;
            enabledCheckBox.UseVisualStyleBackColor = true;
            panel.Controls.Add(enabledCheckBox);

            if (groupComboBox != null)
            {
                groupComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                groupComboBox.Location      = new Point(106, 3);
                groupComboBox.Size          = new Size(100, 21);
                groupComboBox.TabStop       = false;
                panel.Controls.Add(groupComboBox);
            }

            if (levelComboBox != null)
            {
                levelComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                levelComboBox.Location      = new Point(212, 3);
                levelComboBox.Size          = new Size(100, 21);
                levelComboBox.TabStop       = false;
                panel.Controls.Add(levelComboBox);
            }

            scoreTextBox.Location  = new Point(318, 3);
            scoreTextBox.Size      = new Size(25, 20);
            scoreTextBox.TabStop   = true;
            scoreTextBox.TextAlign = HorizontalAlignment.Center;
            scoreTextBox.AutoClear = true;
            scoreTextBox.MinValue  = 0;
            scoreTextBox.MaxValue  = 100;
            panel.Controls.Add(scoreTextBox);

            panel.ResumeLayout(false);
            panel.PerformLayout();

            _course        = new CourseWrapper(course);
            _nameControl   = enabledCheckBox;
            _groupComboBox = groupComboBox;
            _levelComboBox = levelComboBox;
            _scoreTextBox  = scoreTextBox;

            // ReSharper disable once CoVariantArrayConversion
            if (course.HasGroups)
            {
                _groupComboBox.Items.AddRange(_course.Groups);
            }

            enabledCheckBox.CheckedChanged += OnEnabledUpdated;
            if (groupComboBox != null)
            {
                groupComboBox.SelectedIndexChanged += OnGroupUpdated;
            }
            if (levelComboBox != null)
            {
                levelComboBox.SelectedIndexChanged += OnLevelUpdated;
            }
            scoreTextBox.TextChanged += OnScoreUpdated;

            //Now we can load the dataz!
            _suppressUpdate = true;

            enabledCheckBox.Checked = _course.Enabled;
            scoreTextBox.Text       = _course.Score.ToString();

            if (groupComboBox != null)
            {
                if (_course.SelectedGroup == null)
                {
                    //Default to first group if there is no group selected
                    //and there are groups available
                    _course.SelectedGroup = _course.Groups[0];
                }
                groupComboBox.SelectedItem = _course.SelectedGroup;
            }
            else if (levelComboBox != null)
            {
                _course.SelectedGroup = _course.Groups[0];
            }

            if (levelComboBox != null)
            {
                _levelComboBox.Items.Clear();
                // ReSharper disable once CoVariantArrayConversion
                _levelComboBox.Items.AddRange(_course.SelectedGroup.Levels);
                if (_course.SelectedLevel == null)
                {
                    _course.SelectedLevel = _course.SelectedGroup.Levels[0];
                }
                levelComboBox.SelectedItem = _course.SelectedLevel;
            }

            _suppressUpdate = false;
        }