Example #1
0
        private void btnAddClass_Click(object sender, EventArgs e)
        {
            Comboitem subject = cmbSubjects.SelectedItem as Comboitem;
            Comboitem teacher = cmbTeachers.SelectedItem as Comboitem;
            Comboitem group   = cmbGroups.SelectedItem as Comboitem;

            STG stg = db.STGs.FirstOrDefault(s => s.SubjectID == subject.Value &&
                                             s.GroupID == group.Value);

            if (stg != null)
            {
                MessageBox.Show($"Class with this properties has already exists", "Creation Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            STG newstg = new STG
            {
                SubjectID = subject.Value,
                TeacherID = teacher.Value,
                GroupID   = group.Value
            };

            db.STGs.Add(newstg);
            db.SaveChanges();
            updateClassesDataGrid();
            MessageBox.Show($"Class created successfully", "Creation Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
 public Exam(int userID, Comboitem subject)
 {
     InitializeComponent();
     db        = new UniversityEntities();
     userId    = userID;
     mySubject = subject;
 }
Example #3
0
        private void btnEditStudent_Click(object sender, EventArgs e)
        {
            string    newStudentName    = txtFirstname.Text.Trim();
            string    newStudentSurname = txtLastname.Text.Trim();
            string    newPassword       = txtPAssword.Text.Trim();
            DateTime  newBirthdate      = dtBirthdate.Value;
            Comboitem newGroup          = cmbGroups.SelectedItem as Comboitem;



            if (String.IsNullOrEmpty(newStudentName) ||
                String.IsNullOrEmpty(newStudentSurname) ||
                String.IsNullOrEmpty(newPassword))
            {
                MessageBox.Show("Please edit inputs correctly", "Edit Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            selectedStudent.Firstname = newStudentName;
            selectedStudent.Lastname  = newStudentSurname;
            selectedStudent.Password  = Extension.HashPassword(newPassword);
            selectedStudent.Birthdate = newBirthdate;
            selectedStudent.Group.ID  = newGroup.Value;

            MessageBox.Show($"Student edited successfully", "Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            db.SaveChanges();
            updateStudentsDataGrid();
            txtFirstname.Text        = txtLastname.Text = txtPAssword.Text = "";
            dtBirthdate.Value        = dtBirthdate.MaxDate;
            btnCreateStudent.Enabled = true;
            btnEditStudent.Enabled   = false;
            btnDeleteStudent.Enabled = false;
        }
        private void cmbx_faculty_SelectedIndexChanged(object sender, EventArgs e)
        {
            string facValue = cmbx_faculty.SelectedValue.ToString();
            string sesValue = cmbx_session.SelectedValue.ToString();

            List <ProfessionModel> professionModels = new List <ProfessionModel>();

            List <GroupsAVGModel> groupsAVGModels = new List <GroupsAVGModel>();

            string connection = "Data Source= DESKTOP-A4JVK6F\\SQLEXPRESS; Initial Catalog=AZTU; Integrated Security=true;";

            //Filling combo query
            string query = @"SELECT PR.ID AS PrID, PR.Name AS PrName FROM Professions AS PR
                        INNER JOIN Departments AS DP
                        ON PR.DepartmentID = DP.ID
                        INNER JOIN Faculties AS F
                        ON F.ID = DP.FacultyID
                        WHERE F.ID = " + facValue;


            using (SqlConnection sqlConnection = new SqlConnection(connection))
            {
                sqlConnection.Open();


                using (SqlCommand sqlCommand = new SqlCommand(query, sqlConnection))
                {
                    using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                    {
                        using (DataTable dataTable = new DataTable())
                        {
                            while (sqlDataReader.Read())
                            {
                                ProfessionModel professionModel = new ProfessionModel()
                                {
                                    ID   = int.Parse(sqlDataReader["PrID"].ToString()),
                                    Name = sqlDataReader["PrName"].ToString()
                                };
                                professionModels.Add(professionModel);
                            }
                        }
                    }
                }
            }
            List <Comboitem> comboitems = new List <Comboitem>();

            for (int i = 0; i < professionModels.Count; i++)
            {
                Comboitem comboitem = new Comboitem()
                {
                    Id   = professionModels[i].ID,
                    Name = professionModels[i].Name
                };
                comboitems.Add(comboitem);
            }
            cmbx_profession.ValueMember   = "ID";
            cmbx_profession.DisplayMember = "Name";
            cmbx_profession.DataSource    = comboitems;
        }
        private void btnEditQuestion_Click(object sender, EventArgs e)
        {
            string    newContent        = txtQuestionContent.Text.Trim();
            string    newVariantA       = txtVariantA.Text.Trim();
            string    newVariantB       = txtVariantB.Text.Trim();
            string    newVariantC       = txtVariantC.Text.Trim();
            bool      correctVariantA   = rbCorrectA.Checked;
            bool      correctVariantB   = rbCorrectB.Checked;
            bool      correctVariantC   = rbCorrectC.Checked;
            string    newCorrectVariant = "";
            Comboitem newSubject        = cmbSubjects.SelectedItem as Comboitem;



            if (String.IsNullOrEmpty(newContent) ||
                String.IsNullOrEmpty(newVariantA) ||
                String.IsNullOrEmpty(newVariantB) ||
                String.IsNullOrEmpty(newVariantC) ||
                String.IsNullOrEmpty(newContent))
            {
                MessageBox.Show("Please edit inputs correctly", "Edit Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (correctVariantA)
            {
                newCorrectVariant = newVariantA;
            }
            else if (correctVariantB)
            {
                newCorrectVariant = newVariantB;
            }
            else if (correctVariantC)
            {
                newCorrectVariant = newVariantC;
            }
            else
            {
                MessageBox.Show("Please choose  correct variant", "Edit Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            selectedQuestion.Content        = newContent;
            selectedQuestion.VarianA        = newVariantA;
            selectedQuestion.VariantB       = newVariantB;
            selectedQuestion.VarianC        = newVariantC;
            selectedQuestion.CorrectVariant = newCorrectVariant;
            selectedQuestion.SubjectID      = newSubject.Value;

            MessageBox.Show($"Student edited successfully", "Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            db.SaveChanges();
            updateQuestionsDataGrid();
            txtQuestionContent.Text = txtVariantA.Text = txtVariantB.Text = txtVariantC.Text = "";
            btnAddQuestion.Enabled  = true;
            btnEditQuestion.Enabled = false;
        }
        private void cmbGroups_SelectedIndexChanged(object sender, EventArgs e)
        {
            Comboitem selectedGroup = cmbGroups.SelectedItem as Comboitem;

            cmbStudents.DataSource = db.Students.Where(s => s.GroupID == selectedGroup.Value && s.Status == true).Select(s => new Comboitem
            {
                Text  = s.Firstname + " " + s.Lastname,
                Value = s.Group.ID
            }).ToList();
        }
        private void cmbSubjects_SelectedIndexChanged(object sender, EventArgs e)
        {
            Comboitem selectedSubject = cmbSubjects.SelectedItem as Comboitem;

            cmbGroups.DataSource = db.STGs.Where(s => s.Teacher.Identifikator == myUserID && s.SubjectID == selectedSubject.Value && s.Teacher.Status == true).Select(s => new Comboitem
            {
                Text  = s.Group.Name,
                Value = s.Group.ID
            }).Distinct().ToList();
        }
        private void cmbx_faculty_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sesValue = cmbx_session.SelectedValue.ToString();
            string facValue = cmbx_faculty.SelectedValue.ToString();
            List <ProfessionModel> professionModels = new List <ProfessionModel>();

            List <FinishResult> allFinishResults = new List <FinishResult>();

            string query = @"SELECT PR.ID AS PrID, PR.Name AS PrName FROM Professions AS PR
                        INNER JOIN Departments AS DP
                        ON PR.DepartmentID = DP.ID
                        INNER JOIN Faculties AS F
                        ON F.ID = DP.FacultyID
                        WHERE F.ID = " + facValue;

            using (SqlConnection sqlConnection = new SqlConnection(Extension.ConnectToDb()))
            {
                sqlConnection.Open();
                using (SqlCommand sqlCommand = new SqlCommand(query, sqlConnection))
                {
                    using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                    {
                        using (DataTable dataTable = new DataTable())
                        {
                            while (sqlDataReader.Read())
                            {
                                ProfessionModel professionModel = new ProfessionModel()
                                {
                                    ID   = int.Parse(sqlDataReader["PrID"].ToString()),
                                    Name = sqlDataReader["PrName"].ToString()
                                };
                                professionModels.Add(professionModel);
                            }
                        }
                    }
                }
            }
            List <Comboitem> comboitems = new List <Comboitem>();

            for (int i = 0; i < professionModels.Count; i++)
            {
                Comboitem comboitem = new Comboitem()
                {
                    Id   = professionModels[i].ID,
                    Name = professionModels[i].Name
                };
                comboitems.Add(comboitem);
            }
            cmbx_profession.ValueMember   = "ID";
            cmbx_profession.DisplayMember = "Name";
            cmbx_profession.DataSource    = comboitems;
        }
Example #9
0
        private void cmbx_profession_SelectedIndexChanged(object sender, EventArgs e)
        {
            string       PrValue   = cmbx_profession.SelectedValue.ToString();
            List <Group> groups    = new List <Group>();
            string       conString = "Data Source= DESKTOP-A4JVK6F\\SQLEXPRESS;Initial Catalog=AZTU;Integrated Security=SSPI";

            using (SqlConnection connection = new SqlConnection(conString))
            {
                connection.Open();


                string query = @"SELECT GR.ID AS [GroupID], GR.Name AS [GroupName], GR.ProfessionID AS [GroupProfessionName] FROM Professions AS PR
                            INNER JOIN Groups AS GR ON GR.ProfessionID = PR.ID WHERE GR.ProfessionID = " + PrValue;
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    using (SqlDataReader sqlDataReader = command.ExecuteReader())
                    {
                        using (DataTable dataTable = new DataTable())
                        {
                            while (sqlDataReader.Read())
                            {
                                //cmbx_group.DataSource = null;
                                //cmbx_group.Items.Clear();

                                Group group = new Group()
                                {
                                    ID   = int.Parse(sqlDataReader["GroupID"].ToString()),
                                    Name = sqlDataReader["GroupName"].ToString(),
                                    //ProfessionID = int.Parse(sqlDataReader["GroupProfessionName"].ToString())
                                };
                                groups.Add(group);
                            }
                        }
                    }
                }
            }
            List <Comboitem> comboitems = new List <Comboitem>();

            for (int i = 0; i < groups.Count; i++)
            {
                Comboitem comboitem = new Comboitem();
                comboitem.Id   = groups[i].ID;
                comboitem.Name = groups[i].Name;
                comboitems.Add(comboitem);
            }

            cmbx_group.DataSource    = comboitems;
            cmbx_group.DisplayMember = "Name";

            grbx_subjects.Hide();
        }
Example #10
0
        private void btnCreateStudent_Click_1(object sender, EventArgs e)
        {
            string    firstname = txtFirstname.Text;
            string    lastname  = txtLastname.Text;
            DateTime  birthdate = dtBirthdate.Value;
            int       userID    = (int)nmUserID.Value;
            string    password  = txtPAssword.Text;
            Comboitem groupName = cmbGroups.SelectedItem as Comboitem;

            Student student = db.Students.FirstOrDefault(s => s.Identifikator == userID);

            if (student != null)
            {
                MessageBox.Show("Student with this User ID is already exists", "Creation Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(firstname) ||
                string.IsNullOrEmpty(lastname) ||
                string.IsNullOrEmpty(password) ||
                userID < 100000)
            {
                MessageBox.Show("Please fill inputs correctly", "Creation Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Student newStudent = new Student
            {
                Firstname     = firstname,
                Lastname      = lastname,
                Birthdate     = birthdate,
                Identifikator = userID,
                Password      = Extension.HashPassword(password),
                Status        = true,
                GroupID       = groupName.Value
            };

            db.Students.Add(newStudent);
            db.SaveChanges();
            txtFirstname.Clear();
            txtLastname.Clear();
            txtPAssword.Clear();
            nmUserID.Value    = 100000;
            dtBirthdate.Value = dtBirthdate.MaxDate;

            MessageBox.Show($"Student {firstname} {lastname} created successfully!", "Creation Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            updateStudentsDataGrid();
        }
        private void cmbx_profession_SelectedIndexChanged(object sender, EventArgs e)
        {
            string       PrValue = cmbx_profession.SelectedValue.ToString();
            List <Group> groups  = new List <Group>();

            using (SqlConnection connection = new SqlConnection(Extension.ConnectToDb()))
            {
                connection.Open();


                string query = @"SELECT GR.ID AS [GroupID], GR.Name AS [GroupName], GR.ProfessionID AS [GroupProfessionName] FROM Professions AS PR
                            INNER JOIN Groups AS GR ON GR.ProfessionID = PR.ID WHERE GR.ProfessionID = " + PrValue;
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    using (SqlDataReader sqlDataReader = command.ExecuteReader())
                    {
                        using (DataTable dataTable = new DataTable())
                        {
                            while (sqlDataReader.Read())
                            {
                                Group group = new Group()
                                {
                                    ID   = int.Parse(sqlDataReader["GroupID"].ToString()),
                                    Name = sqlDataReader["GroupName"].ToString(),
                                };
                                groups.Add(group);
                            }
                        }
                    }
                }
            }
            List <Comboitem> comboitems = new List <Comboitem>();

            for (int i = 0; i < groups.Count; i++)
            {
                Comboitem comboitem = new Comboitem();
                comboitem.Id   = groups[i].ID;
                comboitem.Name = groups[i].Name;
                comboitems.Add(comboitem);
            }

            cmbx_group.ValueMember   = "ID";
            cmbx_group.DisplayMember = "Name";
            cmbx_group.DataSource    = comboitems;
        }
        private void btnAddTag_Click(object sender, EventArgs e)
        {
            Comboitem comboitem = cmbTags.SelectedItem as Comboitem;


            if (_medicineTags.FirstOrDefault(t => t.Name == comboitem.Text) != null)
            {
                return;
            }


            Tag newTag = new Tag
            {
                ID   = comboitem.Value,
                Name = comboitem.Text
            };

            _medicineTags.Add(newTag);
            UpdateTagsPanelUI();
        }
        private void btnAddPoint_Click(object sender, EventArgs e)
        {
            int       point = (int)nmPoint.Value;
            Comboitem selectedStudentName = cmbStudents.SelectedItem as Comboitem;
            Comboitem selectedSubjectName = cmbSubjects.SelectedItem as Comboitem;
            DateTime  pointDate           = dtPointDate.Value;

            BeforeExamGrade newGrade = new BeforeExamGrade
            {
                DailyPoint = point,
                PointDate  = pointDate,
                StudentID  = selectedStudentName.Value,
                SubjectID  = selectedSubjectName.Value
            };

            db.BeforeExamGrades.Add(newGrade);
            db.SaveChanges();
            MessageBox.Show($"Point created successfully!", "Creation Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            nmPoint.Value = nmPoint.Minimum;
        }
Example #14
0
        private void cmbSubjects_SelectedIndexChanged(object sender, EventArgs e)
        {
            int yourBeforeExamGrade = 0;
            int grade = 0;

            subject = cmbSubjects.SelectedItem as Comboitem;
            foreach (var item in db.BeforeExamGrades.Where(s => s.Student.Identifikator == UserId && s.SubjectID == subject.Value))
            {
                gradeList.Add((int)item.DailyPoint);
                grade = grade + (int)item.DailyPoint;
            }
            int gradeCount = gradeList.Count();

            if (gradeCount == 0)
            {
                lblCanPass.Text           = "Your before exam grade is less than 17,So you can not enter the exam";
                this.lblCanPass.ForeColor = System.Drawing.Color.Red;
                return;
            }
            yourBeforeExamGrade = (grade / gradeCount) * 5;

            if (yourBeforeExamGrade < 17)
            {
                lblCanPass.Text           = "Your before exam grade is less than 17,So you can not enter the exam";
                this.lblCanPass.ForeColor = System.Drawing.Color.Red;
            }
            else if (yourBeforeExamGrade > 17)
            {
                lblCanPass.Text           = $"Your before exam grade is {yourBeforeExamGrade} , You can enter the exam.Good Luck";
                this.lblCanPass.ForeColor = System.Drawing.Color.Green;
            }
            grade = 0;
            yourBeforeExamGrade = 0;
            gradeCount          = 0;
            gradeList.Clear();
        }
        private void btnAddQuestion_Click(object sender, EventArgs e)
        {
            string questionContent = txtQuestionContent.Text.Trim();
            string variantA        = txtVariantA.Text.Trim();
            string variantB        = txtVariantB.Text.Trim();
            string variantC        = txtVariantC.Text.Trim();
            string correctVariant  = "";
            bool   correctA        = rbCorrectA.Checked;
            bool   correctB        = rbCorrectB.Checked;
            bool   correctC        = rbCorrectC.Checked;

            Comboitem subject = cmbSubjects.SelectedItem as Comboitem;

            if (String.IsNullOrEmpty(questionContent) ||
                String.IsNullOrEmpty(variantA) ||
                String.IsNullOrEmpty(variantB) ||
                String.IsNullOrEmpty(variantC))
            {
                MessageBox.Show("All inputs must be filled", "Creation Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!(correctA || correctB || correctC))
            {
                MessageBox.Show("Please choose correct variant", "Creation Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Question question = db.Questions.FirstOrDefault(q => q.Content.ToLower() == questionContent);

            if (question != null)
            {
                MessageBox.Show("This question has already exists,Please create new one", "Creation Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (subject == null)
            {
                MessageBox.Show("Please choose subject", "Creation Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (correctA)
            {
                correctVariant = variantA;
            }
            else if (correctB)
            {
                correctVariant = variantB;
            }
            else if (correctC)
            {
                correctVariant = variantC;
            }

            Question newQuestion = new Question
            {
                Content        = questionContent,
                VarianA        = variantA,
                VariantB       = variantB,
                VarianC        = variantC,
                CorrectVariant = correctVariant,
                Status         = true,
                SubjectID      = subject.Value
            };

            db.Questions.Add(newQuestion);
            db.SaveChanges();
            updateQuestionsDataGrid();
            MessageBox.Show("New Question created successfully", "Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);

            txtQuestionContent.Text = txtVariantA.Text = txtVariantB.Text = txtVariantC.Text = "";
            rbCorrectA.Checked      = rbCorrectB.Checked = rbCorrectC.Checked = false;
        }
        private async void btnAddMedicine_Click(object sender, EventArgs e)
        {
            string medicine = txtName.Text.Trim();
            string barcode  = txtBarcode.Text.Trim();

            decimal   price      = nmPrice.Value;
            int       count      = (int)nmCount.Value;
            bool      HasReceipt = chReceipt.Checked;
            int       volume     = (int)nmVolume.Value;
            Comboitem unit       = cmbUnit.SelectedItem as Comboitem;

            Medicine med = new Medicine
            {
                Name       = medicine,
                Barcode    = barcode,
                Price      = price,
                Count      = count,
                HasReceipt = HasReceipt,
                Volume     = volume,
                UnitID     = unit.Value
            };

            if (!CheckMedInput(med))
            {
                MessageBox.Show("Inputs are not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtBarcode.Enabled && CheckMedBarcode(txtBarcode.Text))
            {
                MessageBox.Show("This barcode was used by another medicine", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtBarcode.Enabled)
            {
                //add new medicine

                Medicine addedMedicine = null;

                Task newTask = Task.Run(() =>
                {
                    addedMedicine = _db.Medicines.Add(med);
                    _db.SaveChanges();
                });

                await newTask;

                foreach (var tag in _medicineTags)
                {
                    _db.MedicineToTags.Add(new MedicineToTag
                    {
                        MedicineID = addedMedicine.ID,
                        TagID      = tag.ID
                    });
                }
                _db.SaveChanges();

                MessageBox.Show("New product was successfully added", "Success",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //update count of existing medicine
                _db.Medicines.First(m => m.Barcode == txtBarcode.Text).Count += count;
                _db.SaveChanges();

                MessageBox.Show("Product count was successfully updated", "Success",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            UpdateMedicineDataGrid();
            ClearInputs();
        }