Beispiel #1
0
        private void DropButton_Click(object sender, EventArgs e)
        {
            Student student = (Student)this.StudentListBox.SelectedItem;
            Course  course  = (Course)this.CourseListBox.SelectedItem;



            try
            {
                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))
                    {
                        var queryEnroll = from en in db.Enrolleds
                                          where en.CRN == course.CRN && en.NetID == student.NetID && en.Active == true
                                          select en;

                        System.Threading.Thread.Sleep(timeInMs);
                        //if found to be enrolled
                        if (queryEnroll.Any())
                        {
                            foreach (Enrolled en in queryEnroll)
                            {
                                en.Active = false;
                            }

                            //next, put waitlist individual in class
                            Waitlist temp;

                            var queryWait = from w in db.Waitlists
                                            where w.CRN == course.CRN && w.Active == true
                                            select w;
                            temp = queryWait.First();

                            Enrolled enroll = new Enrolled();
                            enroll.CRN    = course.CRN;
                            enroll.NetID  = temp.NetID;
                            enroll.Active = true;

                            db.Enrolleds.InsertOnSubmit(enroll);

                            queryWait.First().Active = false;

                            db.SubmitChanges();
                            Tx.Complete();
                            MessageBox.Show("Dropped: " + student.NetID + " from " + course.CRN);
                        }//end to be enrolled block

                        //else drop from waitlist
                        else
                        {
                            var queryWait = from w in db.Waitlists
                                            where w.CRN == course.CRN && w.NetID == student.NetID && w.Active == true
                                            select w;

                            if (queryWait.Any())
                            {
                                foreach (Waitlist w in queryWait)
                                {
                                    w.Active = false;
                                }
                                db.SubmitChanges();
                                Tx.Complete();
                                MessageBox.Show("Dropped: " + student.NetID + " from waitlist for " + course.CRN);
                            }
                            else
                            {
                                MessageBox.Show("Invalid, student not enrolled in class nor on waitlist");
                            }
                        }

                        //MessageBox.Show("Should not reach here...");

                        //db.SubmitChanges();

                        //Tx.Complete();
                    } //Using tx
                }     //Using db
            }

            catch (Exception ex)
            {
                MessageBox.Show("Enroll failed: " + ex.Message);
            }

            finally
            {
                StudentListBox_SelectedIndexChanged(sender, e);
                CourseListBox_SelectedIndexChanged(sender, e);
                //course list
            }
        }
Beispiel #2
0
        private void SwapButton_Click(object sender, EventArgs e)
        {
            try
            {
                Student studentOne = (Student)this.StudentListBox.SelectedItem;
                Course  courseOne  = (Course)this.CourseListBox.SelectedItem;

                Student studentTwo = (Student)this.StudentTwoList.SelectedItem;
                Course  courseTwo  = (Course)this.CourseTwoList.SelectedItem;



                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))
                    {
                        var queryOne = from en in db.Enrolleds
                                       where en.CRN == courseOne.CRN && en.NetID == studentOne.NetID && en.Active == true
                                       select en;

                        System.Threading.Thread.Sleep(timeInMs);

                        //if found to be enrolled
                        if (!queryOne.Any())
                        {
                            MessageBox.Show("Student: " + studentOne.NetID + "is not enrolled in this class");
                            return;
                        }

                        var queryTwo = from en in db.Enrolleds
                                       where en.CRN == courseTwo.CRN && en.NetID == studentTwo.NetID && en.Active == true
                                       select en;

                        if (!queryTwo.Any())
                        {
                            MessageBox.Show("Student: " + studentTwo.NetID + "is not enrolled in this class");
                            return;
                        }

                        //else, both are enrolled in their selected class, proceed to swap
                        foreach (Enrolled en in queryOne)
                        {
                            en.CRN = courseTwo.CRN;
                        }

                        foreach (Enrolled en in queryTwo)
                        {
                            en.CRN = courseOne.CRN;
                        }

                        db.SubmitChanges();
                        Tx.Complete();


                        MessageBox.Show("Two students successfully swapped");
                    } //Using tx
                }     //Using db
            }

            catch (Exception ex)
            {
                MessageBox.Show("Swap failed: " + ex.Message);
            }

            finally
            {
                StudentListBox_SelectedIndexChanged(sender, e);
                CourseListBox_SelectedIndexChanged(sender, e);
            }
        }
Beispiel #3
0
        private void EnrollButton_Click(object sender, EventArgs e)
        {
            Student student = (Student)this.StudentListBox.SelectedItem;
            Course  course  = (Course)this.CourseListBox.SelectedItem;



            try
            {
                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))
                    {
                        var queryEnroll = from en in db.Enrolleds
                                          where en.CRN == course.CRN && en.Active == true
                                          select en;


                        System.Threading.Thread.Sleep(timeInMs);
                        //int count = 0;
                        bool studentFound = false;
                        int  priorityKey  = 0;

                        foreach (Enrolled en in queryEnroll)
                        {
                            //count++;
                            if (en.NetID == student.NetID)
                            {
                                studentFound = true;
                            }
                            priorityKey = en.Priority;
                        }

                        if (studentFound)
                        {
                            MessageBox.Show("Student is already enrolled");
                            return;
                        }

                        //else, check numbers
                        if (queryEnroll.Count() < course.ClassSize)
                        {
                            //can be enrolled
                            priorityKey++;
                            Enrolled enroll = new Enrolled();
                            //enroll.Priority = priorityKey;
                            enroll.CRN    = course.CRN;
                            enroll.NetID  = student.NetID;
                            enroll.Active = true;

                            db.Enrolleds.InsertOnSubmit(enroll);
                            db.SubmitChanges();
                            Tx.Complete();
                            MessageBox.Show("Enrolled: " + enroll.NetID + " into " + enroll.CRN);

                            //return;
                        }

                        else
                        {
                            //class full, go to wait list
                            var queryWait = from w in db.Waitlists
                                            where w.CRN == course.CRN && w.Active == true && w.NetID == student.NetID
                                            select w;

                            //if already on waitlist
                            if (queryWait.Any())
                            {
                                MessageBox.Show("Already on waitlist");
                                return;
                            }
                            //Adding to waitlist
                            else
                            {
                                foreach (Waitlist w in queryWait)
                                {
                                    w.Priority = priorityKey;
                                }
                                priorityKey++;

                                Waitlist wait = new Waitlist();
                                //wait.Priority = priorityKey;
                                wait.CRN    = course.CRN;
                                wait.NetID  = student.NetID;
                                wait.Active = true;

                                db.Waitlists.InsertOnSubmit(wait);

                                db.SubmitChanges();
                                Tx.Complete();
                                MessageBox.Show("Adding to waitlist:  " + wait.NetID + " for " + wait.CRN);
                            }
                        }//end else



                        //MessageBox.Show("Should not reach here...");

                        //db.SubmitChanges();

                        //Tx.Complete();
                    } //Using tx
                }     //Using db
            }

            catch (Exception ex)
            {
                MessageBox.Show("Enroll failed: " + ex.Message);
            }

            finally
            {
                StudentListBox_SelectedIndexChanged(sender, e);
                CourseListBox_SelectedIndexChanged(sender, e);
                //course list
            }
        }//end enroll button