Пример #1
0
 private void backToMain(string accountType)
 {                                                                                                                                     //check the user's accountType and use that to take them to the right main form
     if (accountType == "Student")
     {
         StudentMain g = new StudentMain(id);
         g.Show();
         this.Dispose();
     }
     else if (accountType == "Faculty")
     {
         FacultyMain g = new FacultyMain(id);
         g.Show();
         this.Dispose();
     }
     else if (accountType == "Administrator")
     {
         AdminMain g = new AdminMain();
         g.Show();
         this.Dispose();
     }
 }
Пример #2
0
        private void LogAndPassToDatabase()
        {
            sqlcon.DBase.ChangeTracker.DetectChanges();

            var s = (from g in sqlcon.DBase.Users where g.UserName == this.Login select g).ToList();

            string str  = GetHashString(Password);
            bool   flag = false;

            if (str.Equals(s[0].Password.ToString().Replace("-", String.Empty)))
            {
                flag = true;
            }
            if (flag)
            {
                switch (s[0].Acceslevel)
                {
                case 1: { AccesLevel = AccesLevels.User; StudNumber = _login; } break;

                case 2: AccesLevel = AccesLevels.Teacher; break;

                case 3: AccesLevel = AccesLevels.Dean; break;

                default: MessageBox.Show("Error in database"); Application.Current.MainWindow.Close(); break;
                }

                var NewWindow = new StudentMain();
                NewWindow.Show();
                Application.Current.MainWindow.Close();
                Application.Current.MainWindow = NewWindow;
            }
            else
            {
                MessageBox.Show("Неверный пароль");
            }
        }
Пример #3
0
        private void btnRequest_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(combCourseName.Text))                                                                         //check if anything necessary is null
            {
                MessageBox.Show("Please select a course for the session.");
            }
            else if (string.IsNullOrWhiteSpace(combHours.Text) || string.IsNullOrWhiteSpace(combMins.Text))
            {
                MessageBox.Show("Please input values for the hours and minutes dropdown boxes");
            }
            else if (((Convert.ToInt32(combHours.Text) * 4 + (Convert.ToInt32(combMins.Text) / 15)) == 0) ||                            //check that the appointment is between 15 minutes and 3 hours
                     ((Convert.ToInt32(combHours.Text) * 4 + (Convert.ToInt32(combMins.Text) / 15)) > 12))
            {
                MessageBox.Show("Please input values for the hours and minutes that are between a length of 15 minutes and 3 hours");
            }
            else
            {
                bool     weekly           = cbxWeekly.Checked;                                                                                 //get whether this is weekly
                DateTime start            = DateTime.Now;                                                                                      //set start to now
                TutorMasterDBEntities4 db = new TutorMasterDBEntities4();                                                                      //connect to database

                string classCode = (from row in db.Classes where combCourseName.Text == row.ClassName select row.ClassCode).First();           //get the class code

                var approvedTutorIds = (from row in db.StudentClasses.AsEnumerable() where classCode == row.ClassCode select row.ID).ToList(); //get all of the approved tutors
                if (approvedTutorIds.Count() == 0)
                {
                    MessageBox.Show("There are currently no tutors approved to tutor this course. Sorry.");
                }
                else
                {
                    List <Commitment> tuteeCommits = (from stucmt in db.StudentCommitments.AsEnumerable()                               //get the tutee commitments
                                                      where stucmt.ID == id
                                                      join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                                      select cmt).ToList();


                    int sessionLength = Convert.ToInt32(combHours.Text) * 4 + (Convert.ToInt32(combMins.Text) / 15);                   //get the number of 15 minute time blocks of the session

                    SortsAndSearches.QuickSort(ref tuteeCommits, tuteeCommits.Count());                                                //sort the tutee commit list

                    checkMax(ref tuteeCommits);                                                                                        //check if there are any 3 hour time blocks

                    removeNotOpens(ref tuteeCommits, start, weekly);                                                                   //remove the commitments that are not open

                    if (tuteeCommits.Count == 0)
                    {
                        MessageBox.Show("You currently have no available slots, please add some availability before attempting to schedule a session of this length");
                    }
                    else
                    {
                        List <string> tuteeValidSlots = getValidSlots(ref tuteeCommits, sessionLength);                                //get the tutee's valid time slots for the length of the session we're looking for

                        bool done = false;
                        for (int i = 0; i < approvedTutorIds.Count(); i++)                                                            //go through each tutor in the approved tutor list
                        {
                            if (approvedTutorIds[i] != id)                                                                            //don't let a tutor tutor him/herself
                            {
                                var tutorFirstName = (from row in db.Users.AsEnumerable() where row.ID == approvedTutorIds[i] select row.FirstName).First();
                                var tutorLastName  = (from row in db.Users.AsEnumerable() where row.ID == approvedTutorIds[i] select row.LastName).First();

                                List <TutorMaster.Commitment> tutorCommits = (from stucmt in db.StudentCommitments.AsEnumerable()     //get the tutor's commitments
                                                                              where stucmt.ID == approvedTutorIds[i]
                                                                              join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                                                              select cmt).ToList();

                                SortsAndSearches.QuickSort(ref tutorCommits, tutorCommits.Count());                                   //sort them

                                checkMax(ref tutorCommits);                                                                           //check for 3 tutoring blocks

                                removeNotOpens(ref tutorCommits, start, weekly);                                                      //remove the not opens

                                List <string> tutorValidSlots = getValidSlots(ref tutorCommits, sessionLength);                       //get the valid time slots for the tutors

                                for (int j = 0; j < tutorValidSlots.Count(); j++)                                                     //iterate through the valid tutor time slots
                                {
                                    if (SortsAndSearches.BinarySearch(tuteeValidSlots, tutorValidSlots[j]))                           //see if the tutorvalid slot is in the tutee list
                                    {                                                                                                 //if it is, ask the user if they'd this appointment
                                        DialogResult choice = MessageBox.Show("You have been matched with " + tutorFirstName + " " + tutorLastName +
                                                                              " for a time at: " + tutorValidSlots[j].Split(',')[0] + " - " + tutorValidSlots[j].Split(',')[1], "You've got a match!", MessageBoxButtons.YesNo);
                                        if (choice == DialogResult.Yes)                                                               //if they say yes, get their ids and add the commitments to their schedules
                                        {
                                            int tutorId = Convert.ToInt32(approvedTutorIds[i]);
                                            int tuteeId = Convert.ToInt32(id);
                                            addCommits(tutorValidSlots[j], tutorId, tuteeId, tutorCommits, tuteeCommits, classCode, db, weekly, sessionLength);
                                            done = true;
                                            break;
                                        }
                                        else if (choice == DialogResult.No)                                                           //if no, break out of this loop and repeat the same process with another approved tutor if there is one
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (done)                                                                                             //if they picked this tutor and we're done, break out of this large for loop
                                {
                                    break;
                                }
                            }
                        }
                        if (!done)                                                                                                    //if we go through every tutor and do not pick one, put the message up
                        {
                            MessageBox.Show("There are no more tutors that meet your request requirements.");
                        }
                    }
                    StudentMain g = new StudentMain(id);                                                                              //return to student main
                    g.Show();
                    this.Dispose();
                }
            }
        }