Ejemplo n.º 1
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
Ejemplo n.º 2
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
            }
        }
Ejemplo n.º 3
0
 private void detach_Enrolleds(Enrolled entity)
 {
     this.SendPropertyChanging();
     entity.Student = null;
 }
Ejemplo n.º 4
0
 private void attach_Enrolleds(Enrolled entity)
 {
     this.SendPropertyChanging();
     entity.Student = this;
 }
Ejemplo n.º 5
0
 partial void DeleteEnrolled(Enrolled instance);
Ejemplo n.º 6
0
 partial void UpdateEnrolled(Enrolled instance);
Ejemplo n.º 7
0
 partial void InsertEnrolled(Enrolled instance);