protected override Student[,] distribute()
        {
            Student[,] classroom = new Student[_classRoomRows, _classRoomColumns];

            // Distribution phase
            int i = 0;
            for (int r = 0; r < _classRoomRows && i < students.Length; r++)
            {
                for (int c = 0; c < _classRoomColumns && i < students.Length; c++)
                {
                    classroom[r, c] = students[c + (r * _classRoomColumns)];
                    i++;
                }
            }

            // Swap phase
            for (int j = 0; j < _MaxSwaps; j++ )
            {
                for (int r = 0; r < _classRoomRows-1; r++)
                {
                    for (int c = 0; c < _classRoomColumns; c++)
                    {
                        if (classroom[r + 1, c] != null && classroom[r, c] != null && classroom[r, c].height > classroom[r + 1, c].height + _MinHeightDifference)
                        {
                            Student help = classroom[r, c];
                            classroom[r, c] = classroom[r + 1, c];
                            classroom[r + 1, c] = help;
                        }
                    }
                }
            }
            return classroom;
        }
Exemplo n.º 2
0
 public bool Add(Student newStudent)
 {
     string gradeString = newStudent.grade.ToString().Replace(',', '.');
     string sql = "INSERT INTO " + TBL_STUDENTS
         + " (" + STUD_NAME + ", " + STUD_GRADE + ", " + STUD_HEIGHT + ", " + CLASS_ID + ") "
         + "VALUES('" + newStudent.name + "', " + ConvertGrade(newStudent.grade) + ", " + newStudent.height + ", " + newStudent.class_id.id + ");";
     return _db.ExecuteInsertUpdateDelete(sql);
 }
Exemplo n.º 3
0
 public bool Edit(Student editStudent)
 {
     string sql = "UPDATE " + TBL_STUDENTS + " SET "
         + STUD_NAME + "='" + editStudent.name + "', "
         + STUD_HEIGHT + "=" + editStudent.height + ", "
         + STUD_GRADE + "=" + ConvertGrade(editStudent.grade) + ", "
         + CLASS_ID + "=" + editStudent.class_id.id
         + " WHERE " + STUD_ID + "=" + editStudent.id + ";";
     return _db.ExecuteInsertUpdateDelete(sql);
 }
Exemplo n.º 4
0
 private void bAddStud_Click(object sender, EventArgs e)
 {
     if (checkAndGetValues())
     {
         _newStud = new Student(0, name, grade, height, studClass);
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     else
     {
         MessageBox.Show("Fill in all required fields");
     }
 }
        protected override Student[,] distribute()
        {
            Student[,] classroom = new Student[_classRoomRows, _classRoomColumns];

            int i = 0;
            for (int r = 0; r < _classRoomRows && i < students.Length; r++)
            {
                for (int c = 0; c < _classRoomColumns && i < students.Length; c++)
                {
                    classroom[r, c] = students[i];
                    i++;
                }
            }

            return classroom;
        }
Exemplo n.º 6
0
 private void bEditStud_Click(object sender, EventArgs e)
 {
     if (txtEditStudName.Text != ""
         && cmbEditStudClass.SelectedIndex>-1
         && cmbEditStudClass.SelectedItem!=null
         && cmbEditStudClass.Text!="")
     {
         _editStudent = new Student(
             selectedStud.id,
             txtEditStudName.Text,
             (double)nudEditStudGrade.Value,
             (int)nudEditStudHeight.Value,
             (Class)cmbEditStudClass.SelectedItem);
         this.DialogResult = System.Windows.Forms.DialogResult.OK;
         this.Close();
     }
     else
     {
         MessageBox.Show("Fill in all required fields.");
     }
 }
Exemplo n.º 7
0
        public bool Add(Student newStudent)
        {
            long newStudId = 1 + Convert.ToInt64(
                _doc.Root
                .Descendants(STUDINDEX_EL)
                .First()
                .Value);

            try
            {
                XElement newStudEl = GenerateXElement(newStudent, newStudId);
                _doc.Root
                    .Elements(CLASS_EL)
                    .Single(c => (string) c.Attribute(ID_ATT)==newStudent.class_id.id.ToString())
                    .Add(newStudEl);
                _doc.Root.Element(META_EL).SetElementValue(STUDINDEX_EL, newStudId);
                _doc.Save(_path);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
 public Student[,] createClassroom(Student[] array)
 {
     students = array;
     sort(0, students.Length - 1);
     return distribute();
 }
Exemplo n.º 9
0
 private XElement GenerateXElement(Student student)
 {
     XElement newStudEl = new XElement(STUD_EL);
     newStudEl.SetAttributeValue(STUD_NAME_ATT, student.name);
     newStudEl.SetAttributeValue(ID_ATT, student.id);
     newStudEl.SetElementValue(STUD_GRADE_EL, student.grade);
     newStudEl.SetElementValue(STUD_HEIGHT_EL, student.height);
     return newStudEl;
 }
Exemplo n.º 10
0
        public bool Edit(Student editStudent)
        {
            XElement oldStud = _doc.Root
                        .Descendants(STUD_EL)
                        .Single(s => (string)s.Attribute(ID_ATT).Value == editStudent.id.ToString());

            try
            {
                if (Convert.ToInt32(oldStud.Parent.Attribute(ID_ATT).Value) == editStudent.class_id.id)
                {
                    oldStud.SetAttributeValue(STUD_NAME_ATT, editStudent.name);
                    oldStud.SetElementValue(STUD_GRADE_EL, editStudent.grade);
                    oldStud.SetElementValue(STUD_HEIGHT_EL, editStudent.height);
                    _doc.Save(_path);
                }
                else
                {
                    XElement newStudEl = GenerateXElement(editStudent);
                    oldStud.Remove();
                    _doc.Root
                        .Elements(CLASS_EL)
                        .Single(c => (string)c.Attribute(ID_ATT).Value == editStudent.class_id.id.ToString())
                        .Add(newStudEl);
                    _doc.Save(_path);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemplo n.º 11
0
 public bool Delete(Student delStudent)
 {
     try
     {
         _doc.Root
                 .Descendants(STUD_EL)
                 .Single(s => (string)s.Attribute(ID_ATT).Value == delStudent.id.ToString())
                 .Remove();
         _doc.Save(_path);
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }
Exemplo n.º 12
0
        private void ShowClassroom(Student[,] classroom)
        {
            // Generate the lables to display the classroom.

            // Variables used to calculate the position and size of each label.
            int lineHeight = 15;
            int lblWidth = 150;
            int lblVerticalOffset = 180;
            int lblHorizontalOffset = 20;
            int lblMargin = 20;

            lblList = new List<Label>(); // The list of lalbels.

            // Iterate through the classroom.
            for (int r = 0; r < classRoomRows; r++)
            {
                for (int c = 0; c < classRoomColumns; c++)
                {
                    Student current = classroom[r, c]; // The currently selected student.
                    Label lblStudent = new Label(); // Create a new label.
                    lblStudent.Height = lineHeight * 3;                 // Set label height...
                    lblStudent.Width = lblWidth;                        // ,width...
                    lblStudent.BorderStyle = BorderStyle.FixedSingle;   // and border.

                    if (current != null)
                    { // Fill in te label with information from the Student.
                        lblStudent.Text = current.name + "\n" + current.grade + "/10\n" + current.height + "cm";
                    }
                    else
                    { // Fill in an Empty Seat.
                        lblStudent.Text = EMPTY_SEAT;
                    }

                    // Set th label's position.
                    lblStudent.Location = new Point(c * (lblWidth + lblMargin) + lblHorizontalOffset, r * lineHeight * 4 + lblVerticalOffset);

                    lblStudent.Click += new EventHandler(StudentLabel_Click); // Set the EventHandler for when the label is clicked.

                    lblList.Add(lblStudent);        // Add the label to the List...
                    this.Controls.Add(lblStudent);  // and to the Form.
                }
            }
        }
Exemplo n.º 13
0
 public bool Delete(Student editStudent)
 {
     string sql = "DELETE FROM " + TBL_STUDENTS
         + " WHERE " + STUD_ID + "=" + editStudent.id + ";";
     return _db.ExecuteInsertUpdateDelete(sql);
 }
Exemplo n.º 14
0
 public bool Edit(Student editStudent)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public bool Add(Student newStudent)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 private void cmbStudents_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedStud = (Student) ((ComboBox)sender).SelectedItem;
     txtEditStudName.Text = selectedStud.name;
     nudEditStudGrade.Value = Convert.ToDecimal(selectedStud.grade);
     nudEditStudHeight.Value = selectedStud.height;
     cmbEditStudClass.SelectedItem = selectedStud.class_id;
 }