コード例 #1
0
 private void detach_Waitlists(Waitlist entity)
 {
     this.SendPropertyChanging();
     entity.Course = null;
 }
コード例 #2
0
 private void attach_Waitlists(Waitlist entity)
 {
     this.SendPropertyChanging();
     entity.Course = this;
 }
コード例 #3
0
 partial void DeleteWaitlist(Waitlist instance);
コード例 #4
0
 partial void UpdateWaitlist(Waitlist instance);
コード例 #5
0
 partial void InsertWaitlist(Waitlist instance);
コード例 #6
0
ファイル: Form1.cs プロジェクト: hplewa/Coursemo
        //Get the selected student and course
        //Try to enroll the student in the course
        //If the course is full, put students on waitlist
        private void enrollButton_Click(object sender, EventArgs e)
        {
            if (this.studentsLB.SelectedItem == null)
            {
                MessageBox.Show("Select a student to enroll.");
                return;
            }
            Student student = getSelectedStudent();

            //MessageBox.Show(student.ToString());

            if (this.coursesLB.SelectedItem == null)
            {
                MessageBox.Show("Select a course to enroll in.");
                return;
            }
            Course course = getSelectedCourse();
            //MessageBox.Show(course.ToString());
            string msg = null;

            using (var db = new CoursemoDataContext())
            {
                var TxOptions = new System.Transactions.TransactionOptions();
                TxOptions.IsolationLevel = System.Transactions.IsolationLevel.Serializable;

                using (var Tx = new System.Transactions.TransactionScope(
                           System.Transactions.TransactionScopeOption.Required, TxOptions))
                {
                    try {
                        if (delay_flag)
                        {
                            Delay();
                        }
                        var enrolled = from r in db.Registrations
                                       where r.Netid == student.netid
                                       where r.CRN == course.crn
                                       select r;

                        if (delay_flag)
                        {
                            Delay();
                        }
                        var waiting = from w in db.Waitlists
                                      where w.Netid == student.netid
                                      where w.CRN == course.crn
                                      select w;
                        //Is the student already enrolled in this class?
                        if (enrolled.Any())
                        {
                            //MessageBox.Show(student.netid + " is already enrolled in course " + course.crn);
                            msg = student.netid + " is already enrolled in course " + course.crn;
                        }
                        //Is the student on the waitlist for this class?
                        else if (waiting.Any())
                        {
                            //MessageBox.Show(student.netid + " is already on the waitlist for course " + course.crn);
                            msg = student.netid + " is already on the waitlist for course " + course.crn;
                        }
                        //Student not enrolled or waiting for this course
                        else
                        {
                            //Get number of registrations for this course
                            if (delay_flag)
                            {
                                Delay();
                            }
                            var query = (from r in db.Registrations
                                         where r.CRN == course.crn
                                         select r.RID).ToList();

                            //Is this class full?
                            if (query.Count == course.capacity)
                            {
                                //MessageBox.Show(course.crn + " is full, putting " + student.netid + " on the waitlist for this course.");
                                //Put on waitlist
                                if (delay_flag)
                                {
                                    Delay();
                                }
                                Waitlist wait = new Waitlist
                                {
                                    Netid   = student.netid,
                                    CRN     = course.crn,
                                    RegTime = DateTime.Now
                                };
                                db.Waitlists.InsertOnSubmit(wait);

                                if (delay_flag)
                                {
                                    Delay();
                                }
                                var placeInLine = from w in db.Waitlists
                                                  where w.CRN == course.crn
                                                  orderby w.RegTime
                                                  select w.WID;

                                //MessageBox.Show(student.netid + " put on waitlist for " + course.crn + ". Place in line: " + (placeInLine.Count() + 1).ToString());
                                msg = student.netid + " put on waitlist for " + course.crn + ". Place in line: " + (placeInLine.Count() + 1).ToString();
                            }
                            else
                            {
                                //Enroll
                                if (delay_flag)
                                {
                                    Delay();
                                }
                                Registration r = new Registration
                                {
                                    Netid = student.netid,
                                    CRN   = course.crn
                                };
                                db.Registrations.InsertOnSubmit(r);
                                //MessageBox.Show(student.netid + " enrolled in " + course.crn);
                                msg = student.netid + " enrolled in " + course.crn;
                            }
                        }
                        db.SubmitChanges();
                        Tx.Complete();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        //msg = "Enrollment failed. Try again.";
                        //Tx.Dispose();
                    }
                }
                MessageBox.Show(msg);
            }
        }