コード例 #1
0
ファイル: AddCourse.cs プロジェクト: Aakashbist/Aspire2
        // Add Course Module
        private void Addcoursebtn_Click(object sender, EventArgs e)
        {
            if (ValidateChildren())
            {
                AspireDB db = new AspireDB();

                Course cs   = new Course();
                byte[] hash = HelpMe.Md5toBinary(course_name.Text.ToString());
                Course got  = db.Courses.SingleOrDefault(Course => Course.CourseID == hash);
                if (got != null)
                {
                    new MsgBox("Duplicate entry");
                    return;
                }
                cs.Name     = course_name.Text.ToString();
                cs.CourseID = hash;
                cs.Level    = course_level.Text;
                cs.Nos      = Convert.ToInt32(course_strength.Text);
                db.Courses.Add(cs);
                db.SaveChanges();

                message.Text         = "Done";
                course_strength.Text = "";
                course_name.Text     = "";
                course_level.Text    = "";
                CourseControl.Instance.CreateList();
                CourseControl.Instance.FooterMessage("Course Added");
            }
        }
コード例 #2
0
 // Add Students
 private void addstudentbtn_Click(object sender, EventArgs e)
 {
     if (ValidateChildren())
     {
         byte[]         hash  = HelpMe.Md5toBinary(course_name.Text.ToString());
         Course         cou   = db.Courses.SingleOrDefault(Course => Course.CourseID == hash);
         List <Student> sd    = db.Students.ToList();
         int            count = 0;
         foreach (Student ed in studs)
         {
             ed.Course = cou;
             bool skip = false;
             foreach (Student d in sd)
             {
                 if (ed.StudentID == d.StudentID)
                 {
                     skip = true;
                     break;
                 }
             }
             if (!skip)
             {
                 db.Students.Add(ed);
                 count++;
             }
         }
         db.SaveChanges();
         message.Text = "Done";
         StudentControl.Instance.CreateList();
         StudentControl.Instance.FooterMessage(count + " Records Added");
     }
 }