Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            List <students> query = (from stud in db.students
                                     select stud).ToList();

            if (dataGridView1.SelectedCells.Count == 1)
            {
                if (Application.OpenForms.Count == 1)
                {
                    students item = query.First(w => w.code_stud.ToString() == dataGridView1.SelectedCells[0].OwningRow.Cells[0].Value.ToString());

                    FormEditStudent editSt = new FormEditStudent(item);
                    editSt.Owner = this;
                    editSt.Show();
                }
                else
                {
                    Application.OpenForms[0].Focus();
                }
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var query = (from g in db.groups
                         where g.name_group == comboBox1.SelectedItem.ToString()
                         select g.code_group).ToList();

            int number_of_student = db.students.Max(n => n.code_stud) + 1;

            students new_student = new students
            {
                code_stud = number_of_student,
                surname = textBox1.Text.Replace(" ", ""),
                name = textBox2.Text.Replace(" ", ""),
                code_group = query[0]
            };

            db.students.Add(new_student);

            db.SaveChanges();
            this.Close();
        }
Exemple #3
0
        public FormEditStudent(students stud)
        {
            item = stud;
            InitializeComponent();

            var group_for_list = (from g in db.groups
                                  select g.name_group).Distinct();

            foreach (string it in group_for_list)
            {
                comboBox1.Items.Add(it);
            }

            textBox1.Text = item.surname.ToString();
            textBox2.Text = item.name.ToString();

            var query = (from g in db.groups
                         where g.code_group == item.code_group
                         select g.name_group).ToList();

            comboBox1.SelectedItem = query[0];
        }