コード例 #1
0
        private bool UpdateStudent()
        {
            int affectedRows = 0;

            using (Modelss.AKADEMIYAEntities2 db = new Modelss.AKADEMIYAEntities2())
            {
                studentFounded.Id = Convert.ToInt32(dvgstudent.CurrentRow.Cells[0].Value);
                List <Modelss.Group> gr  = db.Groups.Where(g => g.Status == true).ToList();
                int             selected = cbStudentGroups.SelectedIndex;
                int             grId     = gr[selected].Id;
                Modelss.Student student  = db.Students.Where(s => s.Id == studentFounded.Id).FirstOrDefault();
                student.Name    = txtSName.Text;
                student.Surname = txtSSurname.Text;
                student.Email   = txtSEmail.Text;
                student.GroupId = grId;
                student.Phone   = txtSPhone.Text;
                student.Fee     = Convert.ToDouble(TxtSFee.Text);
                student.Status  = true;

                affectedRows = db.SaveChanges();
            }
            if (affectedRows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        private bool DeleteStudent()
        {
            int affectedRows = 0;

            using (Modelss.AKADEMIYAEntities2 db = new Modelss.AKADEMIYAEntities2())
            {
                studentFounded.Id = Convert.ToInt32(dvgstudent.CurrentRow.Cells[0].Value);
                Modelss.Student st = db.Students.Where(s => s.Id == studentFounded.Id).FirstOrDefault();
                db.Students.Remove(st);

                affectedRows = db.SaveChanges();
            }
            if (affectedRows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        private void BtnSTsave_Click(object sender, EventArgs e)
        {
            if (btnSdelete.Enabled)
            {
                if (!UpdateStudent())
                {
                    MessageBox.Show(" Not Submited");
                    return;
                }
                MessageBox.Show("  Submited");
                Refresh();


                return;
            }
            using (Modelss.AKADEMIYAEntities2 db = new Modelss.AKADEMIYAEntities2())
            {
                Modelss.Student      students = new Modelss.Student();
                List <Modelss.Group> gr       = db.Groups.ToList();
                int selected    = cbStudentGroups.SelectedIndex;
                int StudentGrId = gr[selected].Id;
                List <Modelss.Student> studentss = db.Students.ToList();

                dvgstudent.Rows.Add(ID, txtSName.Text, txtSSurname.Text, txtSEmail.Text, txtSPhone.Text, cbStudentGroups.Text, TxtSFee.Text);

                students.Name    = txtSName.Text;
                students.Surname = txtSSurname.Text;
                students.Email   = txtSEmail.Text;
                students.GroupId = StudentGrId;
                students.Phone   = txtSPhone.Text;
                students.Fee     = Convert.ToDouble(TxtSFee.Text);
                students.Status  = true;


                txtSName.Text = txtSSurname.Text = txtSEmail.Text = cbStudentGroups.Text = TxtSFee.Text = txtSPhone.Text = " ";
                db.Students.Add(students);
                db.SaveChanges();
            }
        }