コード例 #1
0
        private void btnAddMarks_Click(object sender, EventArgs e)
        {
            string mark = val.valMark(txtMarkAdd.Text);

            if (!(mark == ""))
            {
                MessageBox.Show(mark);
            }

            using (SchoolEntities db = new SchoolEntities())
            {
                int sno = Convert.ToInt32(cboSIDAdd.Text);
                int cno = Convert.ToInt32(cboCIDAdd.Text);

                Student_Course course = (from c in db.Student_Course where sno == c.SID && cno == c.CID select c).FirstOrDefault();

                if (course != null)
                {
                    MessageBox.Show("Mark Exists Already. Cannot Add Marks.");
                }
                else
                {
                    course      = new Student_Course();
                    course.SID  = sno;
                    course.CID  = cno;
                    course.Mark = Convert.ToInt32(txtMarkAdd.Text);
                    db.Student_Course.Add(course);
                    db.SaveChanges();
                    MessageBox.Show("Mark Added.");
                }

                updateMarks();
            }
        }
コード例 #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            using (SchoolEntities db = new SchoolEntities())
            {
                int   cno = Convert.ToInt32(cboCIDEdit.Text);
                int[] sid = (from c in db.Student_Course where c.CID == cno select c.SID).ToArray();
                int   sct = sid.Length;
                for (int i = 0; i < sct; i++)
                {
                    int            studentid = sid[i];
                    Student_Course cou       = (from c in db.Student_Course where c.CID == cno && c.SID == studentid select c).FirstOrDefault();

                    string markInput = dGVMarks.Rows[i].Cells[MarkCol].Value.ToString();
                    string output    = val.valMark(markInput);
                    int    markEd    = Convert.ToInt32(markInput);

                    if (!(output == ""))
                    {
                        MessageBox.Show(output);
                    }
                    cou.Mark = markEd;
                    db.SaveChanges();
                }
            }

            updateMarks();
        }