Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            RepEntities db = new RepEntities();

            if (comboBox1.SelectedIndex == 0)
            {
                Tutor Tutor = new Tutor
                {
                    Surname    = textBox1.Text,
                    Name       = textBox2.Text,
                    Patronymic = textBox3.Text
                };
                db.Tutor.Add(Tutor);
                db.SaveChanges();
                TutorDataGridFill();
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                Student Student = new Student
                {
                    Surname    = textBox1.Text,
                    Name       = textBox2.Text,
                    Patronymic = textBox3.Text
                };
                db.Student.Add(Student);
                db.SaveChanges();
                manufactureDataGridFill();
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                Lesson Lesson = new Lesson
                {
                    Duration = textBox1.Text,
                    Tutor    = tutorReturn(Convert.ToInt32(textBox2.Text)),
                    Student  = studentReturn(Convert.ToInt32(textBox3.Text)),
                    Subject  = subjectReturn(Convert.ToInt32(textBox4.Text))
                };

                LessonDataGridFill();
            }
            else if (comboBox1.SelectedIndex == 3)
            {
                Subject Subject = new Subject
                {
                    Name  = textBox1.Text,
                    Price = Convert.ToInt32(textBox2.Text),
                };
                db.Subject.Add(Subject);
                db.SaveChanges();
                SubjectDataGridFill();
            }
        }
Esempio n. 2
0
        private void Grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            RepEntities db = new RepEntities();

            if (e.ColumnIndex == 0)
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    int   i     = 0;
                    Tutor Tutor = new Tutor();
                    foreach (var a in db.Tutor)
                    {
                        if (i == e.RowIndex - 1)
                        {
                            Tutor = a;
                        }
                        i++;
                    }
                    db.Tutor.Remove(Tutor);
                    db.SaveChanges();
                    TutorDataGridFill();
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    int     i       = 0;
                    Student Student = new Student();
                    foreach (var a in db.Student)
                    {
                        if (i == e.RowIndex - 1)
                        {
                            Student = a;
                        }
                        i++;
                    }
                    db.Student.Remove(Student);
                    db.SaveChanges();
                    manufactureDataGridFill();
                }
                else if (comboBox1.SelectedIndex == 2)
                {
                    int    i      = 0;
                    Lesson Lesson = new Lesson();
                    foreach (var a in db.Lesson)
                    {
                        if (i == e.RowIndex - 1)
                        {
                            Lesson = a;
                        }
                        i++;
                    }
                    db.Lesson.Remove(Lesson);
                    db.SaveChanges();
                    LessonDataGridFill();
                }
                else if (comboBox1.SelectedIndex == 3)
                {
                    int     i       = 0;
                    Subject Subject = new Subject();
                    foreach (var a in db.Subject)
                    {
                        if (i == e.RowIndex - 1)
                        {
                            Subject = a;
                        }
                        i++;
                    }
                    db.Subject.Remove(Subject);
                    db.SaveChanges();
                    SubjectDataGridFill();
                }
            }
        }
Esempio n. 3
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            RepEntities db = new RepEntities();

            if (checkBox1.Checked)
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    if (e.ColumnIndex == 1)
                    {
                        int i = 0;
                        foreach (var a in db.Tutor)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Surname = Grid[1, e.RowIndex].Value.ToString();
                            }
                            i++;
                        }
                        db.SaveChanges();
                        manufactureDataGridFill();
                    }
                    else if (e.ColumnIndex == 2)
                    {
                        int i = 0;
                        foreach (var a in db.Tutor)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Name = Grid[1, e.RowIndex].Value.ToString();
                            }
                            i++;
                        }
                        db.SaveChanges();
                        manufactureDataGridFill();
                    }
                    else if (e.ColumnIndex == 3)
                    {
                        int i = 0;
                        foreach (var a in db.Tutor)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Patronymic = Grid[1, e.RowIndex].Value.ToString();
                            }
                            i++;
                        }
                        db.SaveChanges();
                        TutorDataGridFill();
                    }
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    if (e.ColumnIndex == 1)
                    {
                        int i = 0;
                        foreach (var a in db.Student)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Surname = Grid[1, e.RowIndex].Value.ToString();
                            }
                            i++;
                        }
                        db.SaveChanges();
                        manufactureDataGridFill();
                    }
                    else if (e.ColumnIndex == 2)
                    {
                        int i = 0;
                        foreach (var a in db.Student)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Name = Grid[1, e.RowIndex].Value.ToString();
                            }
                            i++;
                        }
                        db.SaveChanges();
                        manufactureDataGridFill();
                    }
                    else if (e.ColumnIndex == 3)
                    {
                        int i = 0;
                        foreach (var a in db.Student)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Patronymic = Grid[1, e.RowIndex].Value.ToString();
                            }
                            i++;
                        }
                        db.SaveChanges();
                        manufactureDataGridFill();
                    }
                }
                else if (comboBox1.SelectedIndex == 3)
                {
                    if (e.ColumnIndex == 1)
                    {
                        int i = 0;
                        foreach (var a in db.Subject)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Name = Grid[1, e.RowIndex].Value.ToString();
                            }
                            i++;
                        }
                        db.SaveChanges();
                        SubjectDataGridFill();
                    }
                    else if (e.ColumnIndex == 2)
                    {
                        int i = 0;
                        foreach (var a in db.Subject)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                a.Price = Convert.ToInt32(Grid[1, e.RowIndex].Value.ToString());
                            }
                            i++;
                        }
                        db.SaveChanges();
                        SubjectDataGridFill();
                    }
                }
                else if (comboBox1.SelectedIndex == 2)
                {
                    if (e.ColumnIndex == 1)
                    {
                        int i = 0;
                        foreach (var a in db.Lesson)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                foreach (var b in db.Tutor)
                                {
                                    if (b.Id == Convert.ToInt32(Grid[1, e.RowIndex].Value.ToString()))
                                    {
                                        a.Tutor = b;
                                    }
                                }
                            }
                            i++;
                        }
                        db.SaveChanges();
                        LessonDataGridFill();
                    }
                    else if (e.ColumnIndex == 2)
                    {
                        int i = 0;
                        foreach (var a in db.Lesson)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                foreach (var b in db.Student)
                                {
                                    if (b.Id == Convert.ToInt32(Grid[1, e.RowIndex].Value.ToString()))
                                    {
                                        a.Student = b;
                                    }
                                }
                            }
                            i++;
                        }
                        db.SaveChanges();
                        LessonDataGridFill();
                    }
                    else if (e.ColumnIndex == 3)
                    {
                        int i = 0;
                        foreach (var a in db.Lesson)
                        {
                            if (i == e.RowIndex - 1)
                            {
                                foreach (var b in db.Subject)
                                {
                                    if (b.Id == Convert.ToInt32(Grid[1, e.RowIndex].Value.ToString()))
                                    {
                                        a.Subject = b;
                                    }
                                }
                            }
                            i++;
                        }
                        db.SaveChanges();
                        LessonDataGridFill();
                    }
                }
            }
        }