private void buttonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         sts = null;
         int student, subject;
         student = Int32.Parse(this.textBoxStudentId.Text);
         subject = Int32.Parse(this.textBoxSubjectId.Text);
         sts     = new StudentToSubject {
             subject_id = subject, student_id = student
         };
     }
     catch (Exception ex)
     {
         //do nothing
     }
     finally
     {
         this.Close();
     }
 }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "")
            {
                MessageBox.Show("Nie wybrano tabeli");
            }
            else
            {
                if (comboBox1.Text == "administrators")
                {
                    Administrator administrator =
                        new Administrator {
                        password = "******",
                        username = "******"
                    };
                    context.Administrators.Add(administrator);
                    context.SaveChanges();
                    dataGridView1.DataSource = context.Administrators.ToList();
                }
                else if (comboBox1.Text == "tutors")
                {
                    Tutor tutor = new Tutor {
                        username = "******", password = "******"
                    };
                    context.Tutors.Add(tutor);
                    context.SaveChanges();
                    dataGridView1.DataSource = context.Tutors.ToList();
                }

                else if (comboBox1.Text == "students")
                {
                    Student student = new Student
                    {
                        password       = "******",
                        s_name         = "(wpisz imie)",
                        surname        = "(wpisz nazwisko)",
                        field_of_study = "1",
                        degree         = "inz",
                        mode           = "dzienne",
                        semester       = 1
                    };
                    context.Students.Add(student);
                    context.SaveChanges();
                    dataGridView1.DataSource = context.Students.ToList();
                }
                else if (comboBox1.Text == "marks")
                {
                    Mark mark = new Mark();
                    context.Marks.Add(mark);
                    context.SaveChanges();
                    dataGridView1.DataSource = context.Marks.ToList();
                }
                else if (comboBox1.Text == "subjects")
                {
                    Subject subject = new Subject {
                        subject_name = "(wpisz nazwe)"
                    };
                    context.Subjects.Add(subject);
                    context.SaveChanges();
                    dataGridView1.DataSource = context.Subjects.ToList();
                }
                else if (comboBox1.Text == "faculties")
                {
                    Faculty faculty = new Faculty {
                        faculty_name = "(zmien nazwe)"
                    };
                    context.Faculties.Add(faculty);
                    context.SaveChanges();
                    dataGridView1.DataSource = context.Faculties.ToList();
                }
                else if (comboBox1.Text == "studenttosubjects")
                {
                    new AddStudentToSubjectForm().ShowDialog();
                    StudentToSubject studentToSubject = AddStudentToSubjectForm.sts;
                    if (studentToSubject == null)
                    {
                        MessageBox.Show("Podano zle wartosci");
                    }
                    else
                    {
                        context.StudentToSubjects.Add(studentToSubject);
                        context.SaveChanges();
                        dataGridView1.DataSource = context.StudentToSubjects.ToList();
                    }
                }
            }
            dataGridView1.Refresh();
            //context.SaveChanges();
        }