// Save student
        private void button1_Click(object sender, EventArgs e)
        {
            using (var db = new AcademyDB())
            {
                if (isValid())
                {
                    Group group = comboBox2.SelectedItem as Group;

                    Task task = new Task()
                    {
                        Name    = textBox1.Text,
                        Dedline = dateTimePicker2.Value,
                        GroupID = group.id,
                        Deleted = false,
                    };

                    db.Task.Add(task);

                    if (db.SaveChanges() != 0)
                    {
                        MessageBox.Show("Task added");
                        ClearInputs();
                    }
                    else
                    {
                        MessageBox.Show("Error: Task did not added");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //Selected classroom statistic
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string groupInCls   = "";
            string selectedCls  = "";
            int    studentCount = 0;

            if (e.RowIndex != -1 && e.RowIndex != dataGridView1.Rows.Count - 1)
            {
                int clsID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);

                using (var db = new AcademyDB())
                {
                    Classroom cls   = db.Classroom.FirstOrDefault(c => c.id == clsID);
                    Group     group = db.Group.FirstOrDefault(g => g.ClassroomID == clsID);

                    selectedCls = cls.Name;
                    if (group != null)
                    {
                        studentCount = db.Student.Where(s => s.GroupID == group.id).Count();
                        groupInCls   = " ( Group: " + group.Name + " Students: " + studentCount + " )";
                    }
                    else
                    {
                        groupInCls = " ( Empty )";
                    }

                    lblSelectedClassRoom.Text = selectedCls + groupInCls;
                }
            }
        }
        // Updating Task from datagridView
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (formLoaded && e.RowIndex != dataGridView1.Rows.Count - 1)
            {
                int taskID = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                using (var db = new AcademyDB())
                {
                    if (CheckRow(e.RowIndex)) // checking cells validation
                    {
                        Model.Task task = db.Task.Where(t => t.id == taskID).FirstOrDefault();

                        task.Name    = row.Cells[1].Value.ToString();
                        task.Dedline = Convert.ToDateTime(row.Cells[2].Value);
                        task.GroupID = (int)row.Cells[3].Value;


                        if (db.SaveChanges() != 0)
                        {
                            MessageBox.Show("Task updated");
                            fillGrid(db.Task.ToList());
                        }
                        else
                        {
                            MessageBox.Show("Warning: Task did not updated!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        // Updating Group from datagridView
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (formLoaded && e.RowIndex != dataGridView1.Rows.Count - 1)
            {
                int groupID = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                using (var db = new AcademyDB())
                {
                    if (CheckRow(e.RowIndex)) // checking cells validation
                    {
                        Group grp = db.Group.FirstOrDefault(gr => gr.id == groupID);

                        grp.Name        = row.Cells[1].Value.ToString();
                        grp.ClassroomID = Convert.ToInt32(row.Cells[2].Value);
                        grp.TeacherID   = Convert.ToInt32(row.Cells[3].Value);
                        grp.MentorID    = Convert.ToInt32(row.Cells[4].Value);
                        grp.Capacity    = Convert.ToInt32(row.Cells[5].Value);
                        grp.ProgramID   = Convert.ToInt32(row.Cells[6].Value);

                        if (db.SaveChanges() != 0)
                        {
                            fillGrid(db.Group.Where(gr => gr.Deleted == false).ToList());
                            dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.FromArgb(224, 255, 224);
                        }
                        else
                        {
                            MessageBox.Show("Error: Student is not updated!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        // Updating Student from datagridView
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (formLoaded && e.RowIndex != dataGridView1.Rows.Count - 1)
            {
                int stdID = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                using (var db = new AcademyDB())
                {
                    if (CheckRow(e.RowIndex)) // checking cells validation
                    {
                        Student std = db.Student.Where(s => s.id == stdID).FirstOrDefault();

                        std.Name      = row.Cells[1].Value.ToString();
                        std.Surname   = row.Cells[2].Value.ToString();
                        std.Email     = row.Cells[3].Value.ToString();
                        std.Phone     = row.Cells[4].Value.ToString();
                        std.Fee       = Convert.ToDouble(row.Cells[5].Value);
                        std.GroupID   = Convert.ToInt32(row.Cells[6].Value);
                        std.StartDate = Convert.ToDateTime(row.Cells[7].Value);

                        if (db.SaveChanges() != 0)
                        {
                            fillGrid(db.Student.ToList());
                            dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.FromArgb(224, 255, 224);
                        }
                        else
                        {
                            MessageBox.Show("Error: Student is not updated!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void FormRefresh()
 {
     using (var db = new AcademyDB())
     {
         fillgrid(db.Students.ToList());
     }
 }
Ejemplo n.º 7
0
        private void Button2_Click(object sender, EventArgs e)
        {
            using (var db = new AcademyDB())
            {
                Task  task  = db.Tasks.Where(t => t.id == selectedtaskId).FirstOrDefault();
                Group group = comboBox1.SelectedItem as Group;


                task.Name    = textBox1.Text;
                task.Dedline = dateTimePicker1.Value;
                task.GroupID = group.id;



                if (db.SaveChanges() != 0)
                {
                    MessageBox.Show("Task updated");
                    FormRefresh();
                }
                else
                {
                    MessageBox.Show("Task didn't update!");
                }
            }
        }
        // Updating Program from datagridView
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (formLoaded && e.RowIndex != dataGridView1.Rows.Count - 1)
            {
                int progID = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                using (var db = new AcademyDB())
                {
                    if (CheckRow(e.RowIndex)) // checking cells validation
                    {
                        Model.Program prog = db.Program.FirstOrDefault(c => c.id == progID);

                        prog.Name   = row.Cells[1].Value.ToString();
                        prog.Price  = Convert.ToInt32(row.Cells[2].Value);
                        prog.Period = Convert.ToInt32(row.Cells[3].Value);

                        if (db.SaveChanges() != 0)
                        {
                            fillGrid(db.Program.ToList());
                            dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.FromArgb(224, 255, 224);
                        }
                        else
                        {
                            MessageBox.Show("Warning: Program did not updated!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void Btnsave_Click(object sender, EventArgs e)
        {
            Group grp = new Group();

            Model.Classroom cls   = comboBox1.SelectedItem as Model.Classroom;
            Employee        empl1 = comboBox2.SelectedItem as Employee;
            Employee        empl2 = comboBox3.SelectedItem as Employee;

            Model.Program pr = comboBox4.SelectedItem as Model.Program;

            grp.Name        = textBox1.Text;
            grp.ClassroomID = cls.id;
            grp.TeacherID   = empl1.id;
            grp.MentorID    = empl2.id;
            grp.Capacity    = Convert.ToInt32(textBox2.Text);
            grp.ProgramID   = pr.id;

            grp.Deleted = false;
            using (var db = new AcademyDB())
            {
                db.Groups.Add(grp);
                if (db.SaveChanges() != 0)
                {
                    MessageBox.Show("Group added");
                    FormRefresh();
                }
                else
                {
                    MessageBox.Show("Group didn't add.Fill all inputs!");
                }
            }
        }
        // Fill grid Method
        public void fillGrid(List <Position> list)
        {
            dataGridView1.Rows.Clear();
            getStatistic();
            using (var db = new AcademyDB())
            {
                foreach (Position pos in list)
                {
                    if (pos.Deleted == false)
                    {
                        DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                        row.Cells[0].Value = pos.id;
                        row.Cells[1].Value = pos.Name;

                        // if no one in this position than set orange color
                        Employee emp = db.Employee.FirstOrDefault(em => em.PositionID == pos.id);
                        if (emp == null)
                        {
                            row.DefaultCellStyle.BackColor = Color.FromArgb(241, 196, 15);
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.White;
                        }

                        dataGridView1.Rows.Add(row);
                    }
                }
            }
        }
        // Search only width evaluations
        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            checkBox4.Checked = false;
            checkBox4.Enabled = false;
            if (checkBox3.Checked == true)
            {
                Task           currentTask = comboBox1.SelectedItem as Task;
                List <Student> PointList   = new List <Student>();

                using (var db = new AcademyDB())
                {
                    foreach (Student student in SearchList)
                    {
                        Exam exam = db.Exam.FirstOrDefault(ex => ex.StudentID == student.id && ex.TaskID == currentTask.id);

                        if (exam != null)
                        {
                            PointList.Add(student);
                        }
                    }
                }
                fillSearchList(PointList);
            }
            else
            {
                checkBox4.Enabled = true;
                fillSearchList(SearchList);
            }
        }
Ejemplo n.º 12
0
        //adding

        private void Btnadd_Click(object sender, EventArgs e)
        {
            Employee employee = new Employee();
            Position posid    = comboBox1.SelectedItem as Position;

            Model.Program program = comboBox2.SelectedItem as Model.Program;

            employee.Name         = textBox1.Text;
            employee.Surname      = textBox2.Text;
            employee.SpecialityID = program.id;
            employee.Email        = textBox4.Text;
            employee.Phone        = textBox5.Text;
            employee.StartTime    = dateTimePicker1.Value;
            employee.Salary       = Convert.ToDouble(textBox6.Text);
            employee.PositionID   = posid.id;
            employee.Deleted      = false;
            using (var db = new AcademyDB())
            {
                db.Employees.Add(employee);
                if (db.SaveChanges() != 0)
                {
                    MessageBox.Show("Employee added");
                    FormRefresh();
                }
                else
                {
                    MessageBox.Show("Employee didn't add.Fill all inputs!");
                }
            }
        }
Ejemplo n.º 13
0
 public void FormRefresh()
 {
     using (var db = new AcademyDB())
     {
         fillgrid(db.Classrooms.ToList());
     }
 }
Ejemplo n.º 14
0
 public void FormRefresh()
 {
     using (var db = new AcademyDB())
     {
         fillgrid(db.Employees.ToList());
     }
 }
Ejemplo n.º 15
0
        private void Button1_Click(object sender, EventArgs e)
        {
            using (var db = new AcademyDB())
            {
                Employee      employee = db.Employees.Where(emp => emp.id == selectedemployerId).FirstOrDefault();
                Model.Program program  = comboBox2.SelectedItem as Model.Program;
                Position      position = comboBox1.SelectedItem as Position;

                employee.Name         = textBox1.Text;
                employee.Surname      = textBox2.Text;
                employee.Email        = textBox4.Text;
                employee.Phone        = textBox5.Text;
                employee.SpecialityID = program.id;
                employee.StartTime    = dateTimePicker1.Value;
                employee.Salary       = Convert.ToDouble(textBox6.Text);
                employee.PositionID   = position.id;


                if (db.SaveChanges() != 0)
                {
                    MessageBox.Show("Employee updated");
                    FormRefresh();
                }
                else
                {
                    MessageBox.Show("Employee didn't update!");
                }
            }
        }
Ejemplo n.º 16
0
        // When selecting program fill teacher
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <Employee> TeacherList = new List <Employee>();

            Model.Program program = comboBox1.SelectedItem as Model.Program;
            if (formLoaded && comboBox1.SelectedIndex != -1)
            {
                using (var db = new AcademyDB())
                {
                    foreach (Employee employee in db.Employee.ToList())
                    {
                        // get only Free Teachers from employers
                        Group grup = db.Group.FirstOrDefault(gr => gr.TeacherID == employee.id);
                        if (grup == null && employee.SpecialityID == program.id)
                        {
                            TeacherList.Add(employee);
                        }
                    }
                    comboBox2.DataSource    = null;
                    comboBox2.DataSource    = TeacherList;
                    comboBox2.DisplayMember = "Name";
                    comboBox2.ValueMember   = "id";
                }
            }
            comboBox2.Enabled = true;
        }
Ejemplo n.º 17
0
        // DatagridView Delete Button Click
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            // if column is Delete button column
            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0 && e.RowIndex != dataGridView1.Rows.Count - 1)
            {
                DataGridViewRow row    = dataGridView1.Rows[e.RowIndex];
                DialogResult    result = MessageBox.Show(row.Cells[1].Value + " " + row.Cells[2].Value, "Are you sure to delete?", MessageBoxButtons.OKCancel);

                if (result == DialogResult.OK)
                {
                    using (var db = new AcademyDB())
                    {
                        int     stdID = (int)row.Cells[0].Value;
                        Student std   = db.Student.Where(s => s.id == stdID).FirstOrDefault();
                        std.Deleted = true;

                        if (db.SaveChanges() != 0)
                        {
                            //Control frm = new Controls.Notification(row.Cells[2].Value + " " + row.Cells[3].Value + " Deleted", "success");
                            //GridPanel.Controls.Add(frm);
                            MessageBox.Show("Deleted");
                            fillGrid(db.Student.ToList());
                        }
                        else
                        {
                            MessageBox.Show("Error");
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
        // Get Statistic
        public void getStatistic()
        {
            using (var db = new AcademyDB())
            {
                int empCount    = 0;
                int freeTeacher = 0;
                lblEmployers.Text = db.Employee.Where(em => em.Deleted == false).Count().ToString();

                foreach (Employee emp in db.Employee.Where(em => em.Deleted == false).ToList())
                {
                    Group grp = db.Group.FirstOrDefault(gr => gr.Deleted == false && gr.TeacherID == emp.id);
                    if (grp == null && emp.SpecialityID != null)
                    {
                        freeTeacher++;
                    }
                }

                lblFreeTeacher.Text = freeTeacher.ToString();

                if (comboBox1.SelectedIndex != -1)
                {
                    Position pos = comboBox1.SelectedItem as Position;
                    empCount = db.Employee.Where(emp => emp.PositionID == pos.id && emp.Deleted == false).Count();

                    lblSelectedPosition.Text = pos.Name + " ( " + empCount + " employers )";
                }
            }
        }
Ejemplo n.º 19
0
        public void fillgrid(List <Student> list)
        {
            dataGridView1.Rows.Clear();
            using (var db = new AcademyDB())
            {
                foreach (Student st in list)
                {
                    if (st.Deleted == false && st.GroupID != null)
                    {
                        DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                        row.Cells[0].Value = st.id.ToString();
                        row.Cells[1].Value = st.Name;
                        row.Cells[2].Value = st.Surname;
                        row.Cells[3].Value = st.Email;
                        row.Cells[4].Value = st.Phone;
                        row.Cells[5].Value = st.Fee;
                        row.Cells[6].Value = st.Group.Name;
                        row.Cells[7].Value = st.StartDate;

                        dataGridView1.Rows.Add(row);
                    }
                }
                comboBox1.DataSource    = db.Groups.ToList();
                comboBox1.DisplayMember = "Name";
                comboBox1.ValueMember   = "id";
            }
        }
Ejemplo n.º 20
0
        // When selecting position filtering grid
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (formLoaded && comboBox1.SelectedIndex != -1)
            {
                getStatistic();
                using (var db = new AcademyDB())
                {
                    Position position = comboBox1.SelectedItem as Position;

                    fillGrid(db.Employee.Where(emp => emp.PositionID == position.id).ToList());

                    if (position.Name == "Teacher")
                    {
                        comboBox2.Enabled       = true;
                        comboBox2.DataSource    = db.Program.Where(p => p.Deleted == false).ToList();
                        comboBox2.DisplayMember = "Name";
                        comboBox2.ValueMember   = "id";
                        comboBox2.SelectedIndex = -1;
                    }
                    else
                    {
                        comboBox2.DataSource    = null;
                        comboBox2.SelectedIndex = -1;
                        comboBox2.Enabled       = false;
                    }
                }
            }
        }
 // Refresh form
 public void refreshForm()
 {
     using (var db = new AcademyDB())
     {
         fillGrid(db.Program.ToList());
     }
 }
Ejemplo n.º 22
0
        private void Button2_Click(object sender, EventArgs e)
        {
            Student st  = new Student();
            Group   grp = comboBox1.SelectedItem as Group;


            st.Name      = textBox1.Text;
            st.Surname   = textBox2.Text;
            st.Email     = textBox3.Text;
            st.Phone     = textBox4.Text;
            st.Fee       = Convert.ToDouble(textBox5.Text);
            st.GroupID   = grp.id;
            st.StartDate = dateTimePicker1.Value;
            st.Deleted   = false;


            using (var db = new AcademyDB())
            {
                db.Students.Add(st);
                if (db.SaveChanges() != 0)
                {
                    MessageBox.Show("Student added");
                    FormRefresh();
                }
                else
                {
                    MessageBox.Show("Student didn't add.Fill all inputs!");
                }
            }
        }
Ejemplo n.º 23
0
        private void Btnupdate_Click(object sender, EventArgs e)
        {
            using (var db = new AcademyDB())
            {
                Group           group = db.Groups.Where(std => std.id == selectgrpId).FirstOrDefault();
                Group           st    = new Group();
                Model.Classroom cls   = comboBox1.SelectedItem as Model.Classroom;
                Employee        empl1 = comboBox2.SelectedItem as Employee;
                Employee        empl2 = comboBox3.SelectedItem as Employee;
                Model.Program   pr    = comboBox4.SelectedItem as Model.Program;

                group.Name        = textBox1.Text;
                group.ClassroomID = cls.id;
                group.TeacherID   = empl1.id;
                group.MentorID    = empl2.id;
                group.Capacity    = Convert.ToInt32(textBox2.Text);
                group.ProgramID   = pr.id;


                if (db.SaveChanges() != 0)
                {
                    MessageBox.Show("Group updated");
                    FormRefresh();
                }
                else
                {
                    MessageBox.Show("Group didn't update!");
                }
            }
        }
Ejemplo n.º 24
0
        // Updating Classroom from datagridView
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (formLoaded && e.RowIndex != dataGridView1.Rows.Count - 1)
            {
                int clsID = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                using (var db = new AcademyDB())
                {
                    if (CheckRow(e.RowIndex)) // checking cells validation
                    {
                        Classroom cls = db.Classroom.FirstOrDefault(c => c.id == clsID);

                        cls.Name     = row.Cells[1].Value.ToString();
                        cls.Capacity = Convert.ToInt32(row.Cells[2].Value);

                        if (db.SaveChanges() != 0)
                        {
                            fillGrid(db.Classroom.ToList());
                            dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.FromArgb(224, 255, 224);
                        }
                        else
                        {
                            MessageBox.Show("Error: Student is not updated!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 25
0
        private void Button3_Click(object sender, EventArgs e)
        {
            using (var db = new AcademyDB())
            {
                Student student = db.Students.Where(std => std.id == selectstudentId).FirstOrDefault();
                Student st      = new Student();
                Group   grp     = comboBox1.SelectedItem as Group;

                st.Name      = textBox1.Text;
                st.Surname   = textBox2.Text;
                st.Email     = textBox3.Text;
                st.Phone     = textBox4.Text;
                st.Fee       = Convert.ToDouble(textBox5.Text);
                st.GroupID   = grp.id;
                st.StartDate = dateTimePicker1.Value;



                if (db.SaveChanges() != 0)
                {
                    MessageBox.Show("Student updated");
                    FormRefresh();
                }
                else
                {
                    MessageBox.Show("Student updated!");
                }
            }
        }
Ejemplo n.º 26
0
        // Fill grid Method
        public void fillGrid(List <Classroom> list)
        {
            dataGridView1.Rows.Clear();
            getStatistic();
            using (var db = new AcademyDB())
            {
                foreach (Classroom cls in list)
                {
                    if (cls.Deleted == false)
                    {
                        DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                        row.Cells[0].Value = cls.id;
                        row.Cells[1].Value = cls.Name;
                        row.Cells[2].Value = cls.Capacity;

                        // if group is free then set different color
                        Group grup = db.Group.FirstOrDefault(gr => gr.ClassroomID == cls.id);
                        if (grup == null)
                        {
                            row.DefaultCellStyle.BackColor = Color.FromArgb(186, 252, 186);
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.White;
                        }
                        dataGridView1.Rows.Add(row);
                    }
                }
            }
        }
Ejemplo n.º 27
0
 //Clear filters
 private void button1_Click(object sender, EventArgs e)
 {
     comboBox1.SelectedIndex = -1;
     using (var db = new AcademyDB())
     {
         fillGrid(db.Group.ToList());
     }
 }
Ejemplo n.º 28
0
        // Fill grid Method
        public void fillGrid(List <Employee> list)
        {
            dataGridView1.Rows.Clear();
            using (var db = new AcademyDB())
            {
                // Fill comboboxes in datagridview
                dgvCombobox.DataSource    = db.Position.Where(p => p.Deleted == false).ToList();
                dgvCombobox.DisplayMember = "Name";
                dgvCombobox.ValueMember   = "id";

                foreach (Employee emp in list)
                {
                    if (emp.Deleted == false && emp.Position.Deleted == false)
                    {
                        DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();

                        // if employer not teacher then set readonly to speciality
                        if (emp.SpecialityID != null)
                        {
                            dgvComboboxSp.DataSource    = db.Program.Where(p => p.Deleted == false).ToList();
                            dgvComboboxSp.DisplayMember = "Name";
                            dgvComboboxSp.ValueMember   = "id";
                            dgvComboboxSp.ReadOnly      = false;
                        }
                        else
                        {
                            row.Cells[8].Value    = null;
                            row.Cells[8].ReadOnly = true;
                        }

                        row.Cells[0].Value = emp.id;
                        row.Cells[1].Value = emp.Name;
                        row.Cells[2].Value = emp.Surname;
                        row.Cells[3].Value = emp.Email;
                        row.Cells[4].Value = emp.Phone;
                        row.Cells[5].Value = emp.PositionID; // set selected position to combobox
                        row.Cells[6].Value = emp.Salary;
                        row.Cells[7].Value = emp.StartTime;
                        row.Cells[8].Value = emp.SpecialityID; // set selected speciality to combobox2

                        // if teacher is not in any group
                        Group grp = db.Group.FirstOrDefault(g => g.TeacherID == emp.id);
                        if (grp == null && emp.SpecialityID != null)
                        {
                            row.DefaultCellStyle.BackColor = Color.FromArgb(241, 196, 15);
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.White;
                        }

                        dataGridView1.Rows.Add(row);
                    }
                }
            }
        }
Ejemplo n.º 29
0
        // Fill grid Method
        public void fillGrid(List <Student> list)
        {
            dataGridView1.Rows.Clear();
            getStatistic();
            using (var db = new AcademyDB())
            {
                // Fill comboboxes in datagridview
                dgvComboboxGroup.DataSource    = db.Group.Where(p => p.Deleted == false).ToList();
                dgvComboboxGroup.DisplayMember = "Name";
                dgvComboboxGroup.ValueMember   = "id";

                foreach (Student std in list)
                {
                    if (std.Deleted == false && std.Group.Deleted == false)
                    {
                        DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                        row.Cells[0].Value = std.id;
                        row.Cells[1].Value = std.Name;
                        row.Cells[2].Value = std.Surname;
                        row.Cells[3].Value = std.Email;
                        row.Cells[4].Value = std.Phone;
                        row.Cells[5].Value = std.Fee;
                        row.Cells[6].Value = std.GroupID; // set selected group to combobox
                        row.Cells[7].Value = std.StartDate;

                        Group gr = db.Group.Where(g => g.id == std.GroupID).FirstOrDefault();

                        // if period of program end. then row will be red
                        if (gr.Program.Period != null)
                        {
                            int      periodMonths  = (int)gr.Program.Period;
                            DateTime programPeriod = std.StartDate.AddMonths(periodMonths);

                            if (programPeriod < DateTime.Now)
                            {
                                row.DefaultCellStyle.BackColor = Color.FromArgb(255, 118, 117);
                            }
                            else
                            {
                                row.DefaultCellStyle.BackColor = Color.White;
                                // if student has dept then cell color will be different color
                                if (std.Fee < gr.Program.Price)
                                {
                                    row.Cells[5].Style.BackColor = Color.FromArgb(241, 196, 15);
                                }
                                else
                                {
                                    row.Cells[5].Style.BackColor = Color.White;
                                }
                            }
                        }
                        dataGridView1.Rows.Add(row);
                    }
                }
            }
        }
 // fill comboboxes
 public void fillCombobox()
 {
     using (var db = new AcademyDB())
     {
         comboBox2.DataSource    = db.Group.Where(g => g.Deleted == false).ToList();
         comboBox2.DisplayMember = "Name";
         comboBox2.ValueMember   = "id";
         comboBox2.SelectedIndex = -1;
     }
 }