Ejemplo n.º 1
0
        /// <summary>
        /// Odstranenie vsetkych taskov a nasledne samotnej activity
        /// </summary>

        private void RemoveActTempBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (AllActTempGrid.Rows.Count > 0 && MessageBox.Show("Naozaj chcete odstrániť šablónu?", "Odstrániť šablónu", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                    {
                        var selectedTaskTemp = con.TaskTemplates.Where(a => a.IdActivityTemplate == (int)AllActTempGrid.CurrentRow.Cells[2].Value);
                        var selectedAct      = con.ActivityTemplates.Where(a => a.Id == (int)AllActTempGrid.CurrentRow.Cells[2].Value);

                        foreach (var x in selectedTaskTemp)
                        {
                            con.TaskTemplates.DeleteOnSubmit(x);
                        }
                        con.ActivityTemplates.DeleteOnSubmit(selectedAct.FirstOrDefault());
                        con.SubmitChanges();
                    }
                    GetTableTemp();
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());
            }
        }
        private void GetEmailTemps(User user)
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    var allTemps  = con.GetTable <EmailTemplate>();
                    var userTemps = from temp in allTemps where temp.IdUser == currentUser.Id select new { temp.EmailTemplateName, temp.EmailContent, temp.Id, temp.EmailSubject };

                    TempGridView.DataSource = userTemps;
                    TempGridView.Columns["EmailContent"].Visible         = false;
                    TempGridView.Columns["Id"].Visible                   = false;
                    TempGridView.Columns["EmailSubject"].Visible         = false;
                    TempGridView.Columns["EmailTemplateName"].HeaderText = "Názov emailovej šablóny";
                    TempGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

                    TempGridView.MultiSelect         = false;
                    TempGridView.SelectionMode       = DataGridViewSelectionMode.FullRowSelect;
                    TempGridView.RowHeadersVisible   = false;
                    TempGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());
            }
        }
        private void GradeActivityForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    if (con.GetTable <Activity>().Where(x => x.Id == currActivity.Id && x.IdStudent == currStud.Id).FirstOrDefault().Hodnotene == false)
                    {
                        DialogResult dialogResult = MessageBox.Show("Aktivita nebola ohodnotená, chcete naozaj skončiť ?", "Skončiť bez hodnotenia? ", MessageBoxButtons.YesNo);

                        if (dialogResult == DialogResult.Yes)
                        {
                            e.Cancel = false;
                        }
                        else
                        {
                            e.Cancel = true;
                        }
                    }
                    else
                    {
                        e.Cancel = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());
            }
        }
        private void MaterialTabCOntrol_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.MaterialTabCOntrol.SelectedTab.Name == currActivity.ActivityName)
            {
                var labl = (Label)MaterialTabCOntrol.SelectedTab.Controls.Find("StudentPtsLabel", false).FirstOrDefault();

                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    var    act        = con.GetTable <Task>().Where(x => x.IdActivity == currActivity.Id && x.IdStudent == currStud.Id);
                    double?gradeTotal = 0;
                    foreach (var tsk in act)
                    {
                        gradeTotal += tsk.Hodnotenie;
                    }
                    if (MaterialTabCOntrol.SelectedIndex == 0)
                    {
                        MaterialTabCOntrol.SelectedTab.Controls.Find("StudentPtsLabel", false).FirstOrDefault().Text = "Získané: " + gradeTotal.ToString();
                    }
                }
            }
            else
            {
                return;
            }
        }
        //Najdenie najblizsieho datumu kde studen chybal na cviceni
        private Nullable <DateTime> GetClosestAbsentDate(int studentId, AttendanceStud attend)
        {
            try
            {
                using (var con = new StudentDBDataContext(conn_str))
                {
                    var attendance = con.AttendanceStuds.Where(a => a.IDSkupina == StudentSkup.Id && a.IDStudent == studentId && a.Type == "Cvičenie" && a.Status == "Neprítomný" || a.Status == "Ospravedlnené");

                    var date = attendance.Select(x => x.Date).OrderByDescending(x => x.Date);
                    if (date.Count() > 0)
                    {
                        if (DateInsideOneWeek(date.FirstOrDefault(), attend.Date))
                        {
                            var closestDate = date.FirstOrDefault();
                            return(closestDate);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show("Nastala chyba, viac informácii nájdete v logoch.", "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
        private void LoadComboBoxes(User user)
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    var activities = con.GetTable <ActivityTemplate>().Where(x => x.IdUser == currentUser.Id);

                    if (activities.Count() > 0)
                    {
                        foreach (var activity in activities)
                        {
                            comboBox1.Items.Add(activity.ActivityName);
                            comboBox2.Items.Add(activity.ActivityName);
                            activityId.Add(activity.ActivityName, activity.Id);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = new Logger();
                logger.LogError(ex);
            }
        }
Ejemplo n.º 7
0
        private IQueryable GetTableTemp()
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    var templ    = con.GetTable <ActivityTemplate>();
                    var dataTemp = from act in templ where act.IdUser == currUser.Id select new { Názov = act.ActivityName, Maximum = act.MaxPoints, act.Id };

                    AllActTempGrid.DataSource               = dataTemp;
                    AllActTempGrid.RowHeadersVisible        = false;
                    AllActTempGrid.AllowUserToAddRows       = false;
                    AllActTempGrid.AutoSizeColumnsMode      = DataGridViewAutoSizeColumnsMode.Fill;
                    AllActTempGrid.AllowUserToDeleteRows    = false;
                    AllActTempGrid.AllowUserToResizeColumns = false;
                    AllActTempGrid.ReadOnly = true;
                    AllActTempGrid.Columns["Id"].Visible = false;
                    AllActTempGrid.AutoSizeRowsMode      = DataGridViewAutoSizeRowsMode.AllCells;

                    return(dataTemp);
                }
            }
            catch (Exception ex)
            {
                Logger logger = new Logger();
                logger.LogError(ex);
                return(null);
            }
        }
Ejemplo n.º 8
0
        // Obnovenie údajov v datagridoch.
        private void IsClosed(object sender, EventArgs e)
        {
            try
            {
                using (var con = new StudentDBDataContext(conn_str))
                {
                    //Refresh
                    currentUser = con.Users.Where(x => x.Id == currentUser.Id).FirstOrDefault();
                }
                GetTable();
                //Vratenie vyberu na povodne miesto
                if (Student_Grid.Rows.Count > 0)
                {
                    Student_Grid.ClearSelection();
                    Student_Grid.Rows[currentRow].Selected = true;
                    Student_Grid.CurrentCell = Student_Grid[1, currentRow];

                    Student_Grid.Focus();
                }
                Activity_Grid.DataSource = null;

                GetActivities();
            }
            catch (Exception ex)
            {
                Logger logger = new Logger();
                logger.LogError(ex);
            }
        }
        protected List <FinalGrade> GetFinalGrades()
        {
            StudentDBDataContext con = new StudentDBDataContext(conn_str);
            var finalGrades          = con.GetTable <FinalGrade>().Where(x => x.IdSkupina == currentGroup.Id).ToList();

            return(finalGrades);
        }
        protected List <AttendanceStud> GetAttendances()
        {
            StudentDBDataContext con = new StudentDBDataContext(conn_str);
            var attendance           = con.GetTable <AttendanceStud>().Where(x => x.IDSkupina == currentGroup.Id).ToList();

            return(attendance);
        }
        protected List <TotalAttendance> GetTotalAttendances()
        {
            StudentDBDataContext con = new StudentDBDataContext(conn_str);
            var totalAttendance      = con.GetTable <TotalAttendance>().Where(x => x.Student.ID_stud_skupina == currentGroup.Id).ToList();

            return(totalAttendance);
        }
Ejemplo n.º 12
0
        private bool Validation()
        {
            try
            {
                if (!BoxValidation())
                {
                    return(false);
                }

                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    var exists = con.GetTable <User>().Where(x => x.Email == EmailBox.Text || x.Meno == NameBox.Text).Count();

                    if (exists > 0)
                    {
                        MessageBox.Show("Používateľ s týmto menom alebo emailom už existuje");
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = new Logger();
                logger.LogError(ex);
                MessageBox.Show("Počas registrácie nastala chyba", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
        protected List <Student> GetStudents()
        {
            StudentDBDataContext con = new StudentDBDataContext(conn_str);
            var students             = con.GetTable <Student>().Where(x => x.ID_stud_skupina == currentGroup.Id).ToList();

            return(students);
        }
Ejemplo n.º 14
0
        public FinalGradeForm(User user, StudentSkupina skup)
        {
            MaterialSkin.MaterialSkinManager skinManager = MaterialSkin.MaterialSkinManager.Instance;
            skinManager.EnforceBackcolorOnAllComponents = false;
            skinManager.AddFormToManage(this);
            skinManager.Theme       = MaterialSkin.MaterialSkinManager.Themes.LIGHT;
            skinManager.ColorScheme = new MaterialSkin.ColorScheme(MaterialSkin.Primary.BlueGrey500, MaterialSkin.Primary.BlueGrey500, MaterialSkin.Primary.BlueGrey500, MaterialSkin.Accent.Blue400,
                                                                   MaterialSkin.TextShade.WHITE);
            InitializeComponent();

            currentUser = user;
            group       = skup;

            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    if (con.GetTable <Student>().Where(x => x.ID_stud_skupina == skup.Id).Count() > 0)
                    {
                        CreateFinalGradeOnStart();
                        LoadGrid(skup);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Uistite sa, že existujú študenti");
                Logger logger = new Logger();
                logger.LogError(ex);
            }
        }
        /// <summary>
        /// Delete email template
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void materialFlatButton3_Click(object sender, EventArgs e)
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    DialogResult response = MessageBox.Show("Naozaj chcete odstrániť šablónu ?", "Upozornenie", MessageBoxButtons.YesNo);
                    if (response == DialogResult.Yes)
                    {
                        con.Attachments.DeleteAllOnSubmit(con.GetTable <Attachment>().Where(x => x.IdEmailTemplate == (int)TempGridView.CurrentRow.Cells[2].Value));

                        con.EmailTemplates.DeleteOnSubmit(con.GetTable <EmailTemplate>().
                                                          Where(x => x.IdUser == currentUser.Id && x.Id == (int)TempGridView.CurrentRow.Cells[2].Value).FirstOrDefault());
                        con.SubmitChanges();
                    }
                    else
                    {
                        return;
                    }
                }
                GetEmailTemps(currentUser);
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());
                return;
            }
        }
Ejemplo n.º 16
0
        private void odstrániťToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var result = MessageBox.Show("Naozaj chcete odstrániť aktivitu ?", "Odstrániť aktivitu", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    using (var con = new StudentDBDataContext(conn_str))
                    {
                        var stud = con.GetTable <Student>().Where(x => x.ID_stud_skupina == studentSkupina.Id && x.Id == (int)Student_Grid.CurrentRow.Cells[0].Value).FirstOrDefault();
                        var act  = con.GetTable <Activity>().Where(x => x.IdStudent == stud.Id && x.Id == (int)Activity_Grid.CurrentRow.Cells[3].Value).FirstOrDefault();

                        var tasks = con.GetTable <Task>().Where(x => x.IdStudent == (int)Student_Grid.CurrentRow.Cells[0].Value && x.IdActivity == act.Id);
                        con.Tasks.DeleteAllOnSubmit(tasks);
                        con.SubmitChanges();

                        con.Activities.DeleteOnSubmit(act);
                        con.SubmitChanges();
                    }
                }
                Activity_Grid.DataSource = null;
                GetActivities();
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
            }
        }
        private void GetTableTasks()
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    if (ActivityGridView.SelectedRows.Count > 0)
                    {
                        var selectedActivity = (int)ActivityGridView.CurrentRow.Cells["Id"].Value;
                        var acts             = con.GetTable <ActivityTemplate>().Where(x => x.IdUser == currUser.Id && x.Id == selectedActivity).FirstOrDefault();
                        var tasks            = con.GetTable <TaskTemplate>().Where(x => x.IdActivityTemplate == acts.Id).Select(x => new
                        {
                            x.ActivityTemplate,
                            x.Id,
                            x.IdActivityTemplate,
                            Maximum = x.MaxPts,
                            Názov   = x.TaskName
                        });
                        TaskGrid.DataSource = tasks;

                        TaskGrid.Columns["IdActivityTemplate"].Visible = false;
                        TaskGrid.Columns["Id"].Visible = false;
                        TaskGrid.Columns["ActivityTemplate"].Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());
                return;
            }
        }
Ejemplo n.º 18
0
        private IQueryable GetTableActivity()
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    var templ = con.GetTable <ActivityTemplate>();

                    var dataTemp = from act in templ where act.IdUser == currUser.Id select new { Názov = act.ActivityName, Maximum = act.MaxPoints, act.Id };
                    ActivityGridView.DataSource            = dataTemp;
                    ActivityGridView.RowHeadersVisible     = false;
                    ActivityGridView.AutoSizeColumnsMode   = DataGridViewAutoSizeColumnsMode.Fill;
                    ActivityGridView.Columns["Id"].Visible = false;
                    ActivityGridView.AutoSizeRowsMode      = DataGridViewAutoSizeRowsMode.AllCells;

                    var studs  = con.GetTable <Student>();
                    var kruzok = from stud in studs where stud.ID_stud_skupina == this.studentSkup.Id select(string) stud.ID_Kruzok;

                    kruzok.ToList <string>();
                    groupCmbo.Items.Add("Všetky");
                    foreach (var kruz in kruzok.Distinct())
                    {
                        groupCmbo.Items.Add(kruz);
                    }
                    return(dataTemp);
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());
                return(null);
            }
        }
Ejemplo n.º 19
0
        private Nullable <int> GetEmailTemps(ComboBox x)
        {
            try
            {
                StudentDBDataContext con = new StudentDBDataContext(conn_str);
                if (!string.IsNullOrEmpty(x.Text))
                {
                    var temps = con.GetTable <EmailTemplate>().Where(y => y.IdUser == currUser.Id);

                    var emailTmp = from email in temps where email.EmailTemplateName == x.Text select email.Id;
                    return(emailTmp.FirstOrDefault());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());

                return(null);
            }
        }
Ejemplo n.º 20
0
        //Nacitanie uloh aktivity do datagridview
        private void GetTableTasks()
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    if (ActivityGridView.Rows.Count > 0)
                    {
                        var selectedActivity = (int)ActivityGridView.CurrentRow.Cells["Id"].Value;
                        var acts             = con.GetTable <ActivityTemplate>().Where(x => x.IdUser == currUser.Id && x.Id == selectedActivity).FirstOrDefault();
                        var tasks            = con.GetTable <TaskTemplate>().Where(x => x.IdActivityTemplate == acts.Id);
                        TaskGrid.DataSource = tasks;

                        TaskGrid.Columns["TaskName"].HeaderText = "Názov úlohy";
                        TaskGrid.Columns["MaxPts"].HeaderText   = "Maximum";

                        TaskGrid.Columns["TaskName"].AutoSizeMode      = DataGridViewAutoSizeColumnMode.AllCells;
                        TaskGrid.Columns["IdActivityTemplate"].Visible = false;
                        TaskGrid.Columns["Id"].Visible = false;
                        TaskGrid.Columns["ActivityTemplate"].Visible = false;
                        TaskGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
                MessageBox.Show(ex.ToString());
                return;
            }
        }
        // Change user to get from login
        public string SetEnvironmentVar(User currentUser)
        {
            try
            {
                StudentDBDataContext con = new StudentDBDataContext(conn_str);
                var users  = con.GetTable <User>();
                var apikey = from user in users where user.Id == currentUser.Id select(string) user.ApiKey;

                if (apikey.Count() <= 0)
                {
                    System.Windows.Forms.MessageBox.Show("Je nutné pridať ApiKey v nastaveniach používateľa");
                    return(null);
                }
                var key = apikey.FirstOrDefault();

                if (Environment.GetEnvironmentVariable("SENDGRID_API_KEY") == null ||
                    Environment.GetEnvironmentVariable("SENDGRID_API_KEY") != key)
                {
                    Environment.SetEnvironmentVariable("SENDGRID_API_KEY", key);
                }

                return(key);
            }
            catch (InvalidDataException)
            {
                System.Windows.Forms.MessageBox.Show("Nie je nastavený kľúč");
                return(null);
            }
        }
Ejemplo n.º 22
0
        private bool CreateUser()
        {
            try
            {
                if (Validation())
                {
                    using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                    {
                        User user = new User
                        {
                            Meno  = NameBox.Text,
                            Email = EmailBox.Text,
                            Heslo = SHA512(FirstPssBox.Text)
                        };

                        con.Users.InsertOnSubmit(user);
                        con.SubmitChanges();

                        MessageBox.Show("Registrácia bola úspešná");
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
        protected List <Activity> GetActivities()
        {
            StudentDBDataContext con = new StudentDBDataContext(conn_str);
            var activity             = con.GetTable <Activity>().Where(x => x.IdSkupina == currentGroup.Id).ToList();

            return(activity);
        }
 private void CreateBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (!string.IsNullOrEmpty(GroupNameBox.Text) && GroupNameBox.Text.Length > 3)
         {
             using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
             {
                 var existingGroups = con.GetTable <StudentSkupina>().Where(x => x.Nazov == GroupNameBox.Text && x.Id_User == currentUser.Id);
                 if (existingGroups.Count() > 0)
                 {
                     MessageBox.Show("Skupina s týmto názvom už existuje, prosím zvoľte iný názov skupiny", "Upozornenie", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     return;
                 }
                 var newGroup = new StudentSkupina()
                 {
                     Id_User = currentUser.Id,
                     Nazov   = GroupNameBox.Text,
                     Forma   = (string)FormCombo.SelectedItem
                 };
                 con.StudentSkupinas.InsertOnSubmit(newGroup);
                 con.SubmitChanges();
             }
         }
         else
         {
             MessageBox.Show("Názov skupiny musí obsahovať viac ako 3 znaky");
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 25
0
 //Nacitavanie studentov do datagridu
 private void LoadGrid(StudentSkupina skupina)
 {
     try
     {
         using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
         {
             var students = con.GetTable <Student>().Where(x => x.ID_stud_skupina == skupina.Id).Select(y => new { y.Id, y.Meno, y.Priezvisko, y.ISIC });
             if (students.Count() > 0)
             {
                 StudentGrid.DataSource            = students;
                 StudentGrid.Columns["Id"].Visible = false;
                 StudentGrid.AutoSizeRowsMode      = DataGridViewAutoSizeRowsMode.AllCells;
             }
             else
             {
                 this.Close();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         Logger newLog = new Logger();
         newLog.LogError(ex);
     }
 }
        protected void StudentAttendanceLecture()
        {
            StudentDBDataContext con = new StudentDBDataContext(conn_str);

            var students             = GetStudents();
            ChartValues <int> values = new ChartValues <int>();
            List <String>     lables = new List <string>();

            ChartValues <int> val3 = new ChartValues <int>();
            ChartValues <int> val4 = new ChartValues <int>();


            foreach (var item in GetTotalAttendances())
            {
                val3.Add(item.TotalPresentLecture);
                val4.Add(item.TotalAbsentLecture);
                lables.Add(item.Student.Meno + " " + item.Student.Priezvisko);
            }

            cartesianChart1.Series = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title      = "Prítomný",
                    Values     = val3,
                    DataLabels = true,
                    Fill       = System.Windows.Media.Brushes.Green
                },
                new ColumnSeries
                {
                    Title      = "Neprítomný",
                    Values     = val4,
                    DataLabels = true,
                    Fill       = System.Windows.Media.Brushes.Red
                }
            };


            //x axis labels
            cartesianChart1.LegendLocation = LegendLocation.Right;
            Separator sep = new Separator();

            sep.Step = 0.7;
            cartesianChart1.AxisX.Add(new Axis
            {
                Title          = "Študent",
                Labels         = lables,
                LabelsRotation = 45,
                Separator      = sep,
                Unit           = 1,
            });
            //y axis label
            cartesianChart1.AxisY.Add(new Axis
            {
                Title          = "Dochádzka - Prednáška",
                LabelFormatter = value => value.ToString()
            });
        }
        // public User LoggedUser { get; set; }

        // Prihlásenie používateľa a validácia ním zadaných údajov
        private User Login()
        {
            var userDict = new Dictionary <string, int?>();

            if (string.IsNullOrEmpty(NameBox.Text) || string.IsNullOrWhiteSpace(NameBox.Text) ||
                string.IsNullOrEmpty(FirstPssBox.Text) || string.IsNullOrWhiteSpace(FirstPssBox.Text))
            {
                MessageBox.Show("Meno ani heslo nemôžu byť prázdne");
                return(null);
            }
            else
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    IQueryable <User> user = con.GetTable <User>().Where(x => x.Meno == NameBox.Text);
                    // SQL nie je CaseSensitive tak musíme iným spôsobom validovať správnosť údajov
                    foreach (var us in user)
                    {
                        userDict.Add(us.Meno, us.Id);
                    }
                    var userId = userDict.Where(x => x.Key.Equals(NameBox.Text, StringComparison.CurrentCulture)).Select(x => x.Value).FirstOrDefault();
                    if (userId == null)
                    {
                        MessageBox.Show("Nesprávne meno alebo heslo");
                        FirstPssBox.Text = string.Empty;
                        return(null);
                    }
                    else
                    {
                        User currUser = con.GetTable <User>().SingleOrDefault(x => x.Id == userId.Value);

                        var pss = SHA512(FirstPssBox.Text);

                        //Porovnávanie hashu z databázy s hashom od používateľa
                        if (currUser.Heslo.Length == pss.Length)
                        {
                            for (int i = 0; i < currUser.Heslo.Length; i++)
                            {
                                if (currUser.Heslo[i] != pss[i])
                                {
                                    MessageBox.Show("Nesprávne heslo");
                                    FirstPssBox.Text = string.Empty;
                                    return(null);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Nesprávne heslo");
                            FirstPssBox.Text = string.Empty;
                            return(null);
                        }
                        // Ak sa program dostal až sem, tak používateľ zadal správne prihlasovacie údaje
                        return(currUser);
                    }
                }
            }
        }
        protected void StudentAttendanceSeminar()
        {
            StudentDBDataContext con = new StudentDBDataContext(conn_str);

            var students             = GetStudents();
            ChartValues <int> values = new ChartValues <int>();
            List <String>     lables = new List <string>();

            ChartValues <int> presentSem = new ChartValues <int>();
            ChartValues <int> absentSem  = new ChartValues <int>();

            foreach (var item in GetTotalAttendances())
            {
                presentSem.Add(item.TotalPresentSeminar);
                absentSem.Add(item.TotalAbsentSeminar);
                lables.Add(item.Student.Meno + "\n" + item.Student.Priezvisko);
            }

            cartesianChart1.Series = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title      = "Prítomný",
                    Values     = presentSem,
                    DataLabels = true,
                    Fill       = System.Windows.Media.Brushes.Green
                },
                new ColumnSeries
                {
                    Title      = "Neprítomný",
                    Values     = absentSem,
                    DataLabels = true,
                    Fill       = System.Windows.Media.Brushes.Red
                }
            };

            //x axis labels
            Separator sep = new Separator();

            sep.Step = 1;
            cartesianChart1.LegendLocation = LegendLocation.Right;
            cartesianChart1.AxisX.Add(new Axis
            {
                Labels         = lables,
                LabelsRotation = 45,
                Unit           = 0.7,
                Separator      = sep,
                ShowLabels     = true
            });
            //y axis label
            cartesianChart1.AxisY.Add(new Axis
            {
                Title          = "Dochádzka - Cvičenie",
                LabelFormatter = value => value.ToString()
            });
        }
Ejemplo n.º 29
0
        private void odstrániťToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                var result = MessageBox.Show("Naozaj chcete odstrániť študenta?", "Odstrániť študenta", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    this.UseWaitCursor = true;

                    using (var con = new StudentDBDataContext(conn_str))
                    {
                        var studentId = (int)Student_Grid.CurrentRow.Cells[0].Value;

                        var stud = con.GetTable <Student>().First(x => x.Id == studentId);

                        var totalAttendance = con.GetTable <TotalAttendance>().Where(x => x.IdStudent == studentId).FirstOrDefault();
                        con.TotalAttendances.DeleteOnSubmit(totalAttendance);
                        con.SubmitChanges();

                        var attendance = con.GetTable <AttendanceStud>().Where(x => x.IDStudent == studentId);
                        if (attendance.Count() > 0)
                        {
                            con.AttendanceStuds.DeleteAllOnSubmit(attendance);
                            con.SubmitChanges();
                        }

                        var tasks = con.GetTable <Task>().Where(x => x.IdStudent == studentId);
                        if (tasks.Count() > 0)
                        {
                            con.Tasks.DeleteAllOnSubmit(tasks);
                            con.SubmitChanges();

                            var activity = con.GetTable <Activity>().Where(x => x.IdStudent == studentId);
                            con.Activities.DeleteAllOnSubmit(activity);
                            con.SubmitChanges();
                        }
                        var finalGrade = con.GetTable <FinalGrade>().Where(x => x.IdStudent == studentId);
                        if (finalGrade.Count() > 0)
                        {
                            con.FinalGrades.DeleteAllOnSubmit(finalGrade);
                            con.SubmitChanges();
                        }

                        con.Students.DeleteOnSubmit(stud);
                        con.SubmitChanges();
                    }
                    this.UseWaitCursor = false;
                }
                GetTable();
            }
            catch (Exception ex)
            {
                Logger newLog = new Logger();
                newLog.LogError(ex);
            }
        }
Ejemplo n.º 30
0
        // Pri prvom zapnuti okna sa vytvori finalne hodnotenie pre kazdeho studenta
        // Aby bol mozny export finalneho hodnotenia
        private void CreateFinalGradeOnStart()
        {
            try
            {
                using (StudentDBDataContext con = new StudentDBDataContext(conn_str))
                {
                    var  allStudents    = con.GetTable <Student>().Where(x => x.ID_stud_skupina == group.Id);
                    var  allFinalGrades = con.GetTable <FinalGrade>().Where(x => x.IdSkupina == group.Id);
                    bool isAdded        = false;

                    if (allStudents.Count() <= 0 || allStudents == null)
                    {
                        return;
                    }
                    foreach (var student in allStudents)
                    {
                        var exists = allFinalGrades.Where(x => x.IdSkupina == group.Id && x.IdStudent == student.Id);

                        if (exists.Count() > 0)
                        {
                            continue;
                        }

                        FinalGrade finalGrade = new FinalGrade()
                        {
                            IdSkupina          = group.Id,
                            IdStudent          = student.Id,
                            ActivityLectPoints = 0,
                            ActivitySemPoints  = 0,
                            GotPoints          = 0,
                            Grade          = "Fx",
                            MaxPts         = 0,
                            MissedLectures = 0,
                            MissedSeminars = 0,
                        };
                        con.FinalGrades.InsertOnSubmit(finalGrade);
                        isAdded = true;
                    }
                    if (isAdded)
                    {
                        con.SubmitChanges();
                    }
                    else
                    {
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Logger newLog = new Logger();
                newLog.LogError(ex);
            }
        }