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
private void detach_Waitlists(Waitlist entity) { this.SendPropertyChanging(); entity.Student = null; }
private void attach_Waitlists(Waitlist entity) { this.SendPropertyChanging(); entity.Student = this; }
partial void DeleteWaitlist(Waitlist instance);
partial void UpdateWaitlist(Waitlist instance);
partial void InsertWaitlist(Waitlist instance);