private void button1_Click(object sender, EventArgs e)
        {
            proverka(textBox1);
            proverka(textBox2);
            var q = (from s in db.students
                     where s.name == comboBox1.SelectedItem.ToString()
                     select s.code_group).ToList();

            var      codde_stud = db.students.Max(r => r.code_stud) + 1;
            students studd      = new students {
                code_stud = codde_stud, surname = textBox1.Text.Replace(" ", ""), name = textBox2.Text.Replace(" ", ""), code_group = q[0]
            };

            db.students.Add(studd);
            db.SaveChanges();
            this.Close();
        }
Пример #2
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 == 2)
                {
                    students students = query.First(c => c.code_stud.ToString() == dataGridView1.SelectedCells[0]
                                                    .OwningRow.Cells[0].Value.ToString());
                    FormEditStudent formEditStudent = new FormEditStudent(students);
                    formEditStudent.Owner = this;
                    formEditStudent.Show();
                }
            }
        }
Пример #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];
        }