示例#1
0
        private void btn_Accept_Click(object sender, EventArgs e)
        {
            if (!Check_Syntax())
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            TimetableDataContext context = new TimetableDataContext();

            try
            {
                Professor prof = (from p in context.Professors
                                  where p.ID == Prof_Id
                                  select p).First();

                prof.Name    = tbox_Name.Text;
                prof.Title   = tbox_Title.Text;
                prof.Details = tbox_Details.Text;
                prof.Phone   = tbox_Phone.Text;
                prof.Mail    = tbox_Mail.Text;
                prof.Salary  = int.Parse(tbox_Salary.Text);

                context.SubmitChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        private void btn_EditProf_Click(object sender, EventArgs e)
        {
            int id;

            if (string.IsNullOrWhiteSpace(tbox_ID.Text) || !int.TryParse(tbox_ID.Text, out id))
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            try
            {
                TimetableDataContext context   = new TimetableDataContext();
                Professor            professor = (from p in context.Professors
                                                  where p.ID == id
                                                  select p).First();

                form_EditProfessors feditprof = new form_EditProfessors(professor);
                feditprof.ShowDialog();

                lview_professors.Items.Clear();
                LoadProfessors();
                tbox_ID.Text = "";
            }
            catch
            {
                MessageBox.Show("Enter a valid ID!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btn_viewClasses_Click(object sender, EventArgs e)
        {
            int id;

            if (string.IsNullOrWhiteSpace(tbox_clsID.Text) || !int.TryParse(tbox_clsID.Text, out id))
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                TimetableDataContext context = new TimetableDataContext();
                Group gr = (from g in context.Groups
                            where g.ID == id
                            select g).First();

                form_ViewGroupClasses fvgc = new form_ViewGroupClasses(id);
                fvgc.ShowDialog();

                tbox_clsID.Text = "";
            }
            catch
            {
                MessageBox.Show("Enter a valid Group ID!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            int id;

            if (string.IsNullOrWhiteSpace(tbox_DeleteID.Text) || !int.TryParse(tbox_DeleteID.Text, out id))
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                TimetableDataContext context = new TimetableDataContext();
                Student std = (from p in context.Students
                               where p.ID == id
                               select p).First();

                context.Students.DeleteOnSubmit(std);
                context.SubmitChanges();

                lview_Students.Items.Clear();
                LoadStudents();
                tbox_DeleteID.Text = "";
            }
            catch
            {
                MessageBox.Show("Enter a valid ID!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#5
0
        private void btn_Login_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(tbox_User.Text) || string.IsNullOrWhiteSpace(tbox_Password.Text))
                {
                    MessageBox.Show("Wrong username or password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                TimetableDataContext context = new TimetableDataContext();
                User usr = (from u in context.Users
                            where u.Username == tbox_User.Text
                            select u).First();

                if (usr.PasswordHash == GenerateSHA256Hash(tbox_Password.Text))
                {
                    MessageBox.Show("Welcome to timetable app!", "Log in succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    tbox_User.Text     = "";
                    tbox_Password.Text = "";

                    gbox_Login.Enabled        = false;
                    gbox_Chooseoption.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Wrong username or password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch
            {
                MessageBox.Show("Wrong username or password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#6
0
        private void btn_Accept_Click(object sender, EventArgs e)
        {
            if (!Check_Syntax())
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                TimetableDataContext context = new TimetableDataContext();

                int Id = 1;
                if (context.ClassRooms.Count() != 0)
                {
                    Id = context.ClassRooms.Max(p => p.ID) + 1;
                }

                ClassRoom cls = new ClassRoom();
                cls.ID          = Id;
                cls.Name        = tbox_Name.Text;
                cls.Description = tbox_Description.Text;

                context.ClassRooms.InsertOnSubmit(cls);
                context.SubmitChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#7
0
        public void LoadProfessors()
        {
            TimetableDataContext context = new TimetableDataContext();

            IEnumerable <Professor> professor = from p in context.Professors
                                                select p;

            foreach (var prof in professor)
            {
                string[]     row  = { prof.ID.ToString(), prof.Name, prof.Title, prof.Details, prof.Phone, prof.Mail, prof.Salary.ToString() };
                ListViewItem item = new ListViewItem(row);
                lview_professors.Items.Add(item);
            }
        }
示例#8
0
        public void LoadClassrooms()
        {
            TimetableDataContext context = new TimetableDataContext();

            IEnumerable <ClassRoom> classRoom = from c in context.ClassRooms
                                                select c;

            foreach (var cls in classRoom)
            {
                string[]     row  = { cls.ID.ToString(), cls.Name, cls.Description };
                ListViewItem item = new ListViewItem(row);
                lview_Classrom.Items.Add(item);
            }
        }
        public void LoadGroups()
        {
            TimetableDataContext context = new TimetableDataContext();

            IEnumerable <Group> gr = from g in context.Groups
                                     select g;

            foreach (var s in gr)
            {
                string[]     row  = { s.ID.ToString(), s.Description, s.Faculty, s.Year.ToString(), s.Professor.Name };
                ListViewItem item = new ListViewItem(row);
                lview_Gruops.Items.Add(item);
            }
        }
        public void LoadClasses()
        {
            TimetableDataContext context = new TimetableDataContext();

            IEnumerable <Class> cls = from c in context.Classes
                                      select c;

            foreach (var s in cls)
            {
                string[]     row  = { s.ID.ToString(), s.Name, s.Professor.Name, s.Credits.ToString() };
                ListViewItem item = new ListViewItem(row);
                lview_Classes.Items.Add(item);
            }
        }
        public void LoadStudents()
        {
            TimetableDataContext context = new TimetableDataContext();

            IEnumerable <Student> stud = from c in context.Students
                                         select c;

            foreach (var s in stud)
            {
                string[]     row  = { s.ID.ToString(), s.Name, s.Group.Description, s.Mail, s.Phone };
                ListViewItem item = new ListViewItem(row);
                lview_Students.Items.Add(item);
            }
        }
        private void btn_Accept_Click(object sender, EventArgs e)
        {
            if (!Check_Syntax())
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                TimetableDataContext context = new TimetableDataContext();

                IEnumerable <Group> grup = from g in context.Groups
                                           where g.ID == int.Parse(tbox_GorupID.Text)
                                           select g;
                if (grup.Count() == 0)
                {
                    MessageBox.Show("This group don't exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int Id = 1;
                if (context.Students.Count() != 0)
                {
                    Id = context.Students.Max(p => p.ID) + 1;
                }

                Student std = new Student();
                std.ID       = Id;
                std.Name     = tbox_Name.Text;
                std.Group_ID = int.Parse(tbox_GorupID.Text);
                std.Phone    = tbox_Phone.Text;
                std.Mail     = tbox_Mail.Text;

                context.Students.InsertOnSubmit(std);
                context.SubmitChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#13
0
        private void GenerateInitialStateProfessorsTimetable()
        {
            TimetableDataContext context = new TimetableDataContext();

            IEnumerable <Professor> profs = from p in context.Professors
                                            select p;

            foreach (var prof in profs)
            {
                ProfessorTimetable pt = new ProfessorTimetable();
                pt.NumeProfesor = prof.Name;
                pt.Clasa        = new List <string>();
                pt.Zi           = new List <string>();
                pt.Modul        = new List <int>();
                pt.OraCurs      = new List <string>();
                pt.Grupa        = new List <string>();

                orarFinalProfessori.Add(pt);
            }
        }
        private void btn_Accept_Click(object sender, EventArgs e)
        {
            if (!Check_Syntax())
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                TimetableDataContext context = new TimetableDataContext();

                int count = (from u in context.Users
                             where u.Username == tbox_Username.Text
                             select u).Count();
                if (count == 1)
                {
                    MessageBox.Show("User already exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int Id = 1;
                if (context.Users.Count() != 0)
                {
                    Id = context.Users.Max(p => p.ID) + 1;
                }

                User usr = new User();
                usr.ID           = Id;
                usr.Username     = tbox_Username.Text;
                usr.PasswordHash = GenerateSHA256Hash(tbox_Password.Text);

                context.Users.InsertOnSubmit(usr);
                context.SubmitChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#15
0
        public void LoadClasses()
        {
            TimetableDataContext context = new TimetableDataContext();

            Group gr = (from g in context.Groups
                        where g.ID == ID_Group
                        select g).First();

            lbl_Group.Text = gr.Description + ":";

            IEnumerable <Attend> att = from a in context.Attends
                                       where a.Group_ID == ID_Group
                                       select a;

            foreach (var s in att)
            {
                string[]     row  = { s.Class.ID.ToString(), s.Class.Name, s.Class.Professor.Name, s.Class.Credits.ToString() };
                ListViewItem item = new ListViewItem(row);
                lview_Classes.Items.Add(item);
            }
        }
        private void form_Timetable_Load(object sender, EventArgs e)
        {
            rbtn_Professors.Checked = true;
            lbl_Group.Enabled       = false;
            cbox_Groups.Enabled     = false;

            TimetableDataContext context = new TimetableDataContext();
            IEnumerable <Group>  groups  = from g in context.Groups
                                           select g;
            IEnumerable <Professor> professors = from p in context.Professors
                                                 select p;

            foreach (var item in groups)
            {
                cbox_Groups.Items.Add(item.Description);
            }
            foreach (var item in professors)
            {
                cbox_Professors.Items.Add(item.Name);
            }
        }
示例#17
0
        public void LoadStudents()
        {
            TimetableDataContext context = new TimetableDataContext();

            Group gr = (from g in context.Groups
                        where g.ID == ID_Group
                        select g).First();

            lbl_Group.Text = gr.Description + ":";

            IEnumerable <Student> stud = from c in context.Students
                                         where c.Group_ID == ID_Group
                                         select c;

            foreach (var s in stud)
            {
                string[]     row  = { s.ID.ToString(), s.Name, s.Group.Description, s.Mail, s.Phone };
                ListViewItem item = new ListViewItem(row);
                lview_Students.Items.Add(item);
            }
        }
        private void btn_Accept_Click(object sender, EventArgs e)
        {
            if (!Check_Syntax())
            {
                MessageBox.Show("Enter valid data!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                TimetableDataContext context = new TimetableDataContext();

                int Id = 1;
                if (context.Professors.Count() != 0)
                {
                    Id = context.Professors.Max(p => p.ID) + 1;
                }

                Professor prof = new Professor();
                prof.ID      = Id;
                prof.Name    = tbox_Name.Text;
                prof.Title   = tbox_Details.Text;
                prof.Details = tbox_Details.Text;
                prof.Phone   = tbox_Phone.Text;
                prof.Mail    = tbox_Mail.Text;
                prof.Salary  = int.Parse(tbox_Salary.Text);

                context.Professors.InsertOnSubmit(prof);
                context.SubmitChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#19
0
        private void GenerateTimetable()
        {
            //Generam tabela de profesori goala
            GenerateInitialStateProfessorsTimetable();

            TimetableDataContext context = new TimetableDataContext();

            //Initializam toate clasele cu module si sunt toate libere
            List <bool> moduleLibere = new List <bool> {
                false, false, false, false, false
            };

            //Lista cu id-uri si zilele saptamanii
            List <int> classRooms_ID = (from c in context.ClassRooms
                                        select c.ID).ToList();
            List <string> zileSaptaman = new List <string> {
                "luni", "marti", "miercuri", "joi", "vineri"
            };

            //Dictionar final legaturi clasa->zile_saptamana->Module
            Dictionary <int, Dictionary <string, List <bool> > > classRooms_Zile_Module = new Dictionary <int, Dictionary <string, List <bool> > >();

            foreach (int index in classRooms_ID)
            {
                Dictionary <string, List <bool> > zileSaptaman_Module_temp = new Dictionary <string, List <bool> >();
                zileSaptaman_Module_temp.Add("luni", moduleLibere.ToList());
                zileSaptaman_Module_temp.Add("marti", moduleLibere.ToList());
                zileSaptaman_Module_temp.Add("miercuri", moduleLibere.ToList());
                zileSaptaman_Module_temp.Add("joi", moduleLibere.ToList());
                zileSaptaman_Module_temp.Add("vineri", moduleLibere.ToList());

                classRooms_Zile_Module.Add(index, zileSaptaman_Module_temp);
            }

            //Selectam toate grupele
            IEnumerable <Group> grupeStudenti = from g in context.Groups
                                                select g;

            Random rnd = new Random();

            //Parchurgem fiecare grupa
            foreach (Group grupa in grupeStudenti)
            {
                //Selectam orele de curs
                IEnumerable <Attend> oreCurs = from a in context.Attends
                                               where a.Group_ID == grupa.ID
                                               select a;

                GroupTimetable gt = new GroupTimetable();
                gt.NumeGrupa = grupa.Description;
                gt.Clasa     = new List <string>();
                gt.Zi        = new List <string>();
                gt.Modul     = new List <int>();
                gt.OraCurs   = new List <string>();

                //Parcurgem fiecare ora de Curs de 2 ori!
                for (int i = 0; i < 2; i++)
                {
                    foreach (var oraCurs in oreCurs)
                    {
                        bool clasaGasita = false;
                        int  contorEsec  = -1;

                        while (!clasaGasita)
                        {
                            int croom_rnd   = rnd.Next(0, classRooms_ID.Count());
                            int weekday_rnd = rnd.Next(0, 5);
                            int modul_rnd;
                            contorEsec++;
                            if (contorEsec >= 12)
                            {
                                modul_rnd = rnd.Next(0, 5);
                            }
                            else
                            {
                                modul_rnd = rnd.Next(0, 3);
                            }

                            if (classRooms_Zile_Module[classRooms_ID[croom_rnd]][zileSaptaman[weekday_rnd]][modul_rnd] == false)
                            {
                                string numeSala = (from sal in context.ClassRooms
                                                   where sal.ID == classRooms_ID[croom_rnd]
                                                   select sal.Name).First();

                                //Verificam daca nu avem deja modulul acela ocupat
                                bool checkOcupat = false;
                                for (int j = 0; j < gt.Zi.Count(); j++)
                                {
                                    if (zileSaptaman[weekday_rnd] == gt.Zi[j] && modul_rnd == gt.Modul[j])
                                    {
                                        checkOcupat = true;
                                        break;
                                    }
                                }
                                //Verificam daca nu se suprapun 2 profesori
                                if (CheckProfessorsSync(numeSala, zileSaptaman[weekday_rnd], modul_rnd, oraCurs.Class.Name, grupa.Description, oraCurs.Class.Professor.Name) == false)
                                {
                                    checkOcupat = true;
                                }

                                if (checkOcupat == true)
                                {
                                    continue;
                                }

                                //Adaugam in lista aici
                                gt.Clasa.Add(numeSala);
                                gt.Zi.Add(zileSaptaman[weekday_rnd]);
                                gt.Modul.Add(modul_rnd);
                                gt.OraCurs.Add(oraCurs.Class.Name);

                                classRooms_Zile_Module[classRooms_ID[croom_rnd]][zileSaptaman[weekday_rnd]][modul_rnd] = true;
                                clasaGasita = true;
                            }
                        }
                    }
                }
                orarFinalGrupe.Add(gt);
            }
        }