Ejemplo n.º 1
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if (selectedTest == null)
            {
                MessageBox.Show("Элемент не выбран");
                return;
            }
            selectedTest.Name     = tbName.Text;
            selectedTest.PassMark = Convert.ToInt16(tbPassMark.Text);

            var updateTest = new Test()
            {
                id       = (int)selectedTest.id,
                Name     = selectedTest.Name,
                PassMark = (short)selectedTest.PassMark
            };

            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                db.Test.Add(updateTest);
                db.Entry(updateTest).State = EntityState.Modified;
                db.SaveChanges();
            }
            Clear();
            LoadData();
        }
Ejemplo n.º 2
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            bool allDataDontInserted = tbSurname.Text == null
                                       & tbName.Text == null
                                       & tbPatronymic.Text == null
                                       & tbLogin.Text == null
                                       & tbPassword.Text == null;


            if (allDataDontInserted)
            {
                return;
            }

            DialogResult result = MessageBox.Show("Вы уверены, что хотите сохранить изменения?",
                                                  "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result != DialogResult.Yes)
            {
                return;
            }

            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                using (SqlConnection connection = new SqlConnection(db.Database.Connection.ConnectionString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(
                               "sp_addlogin @Login, @Password, @DBNAME", connection))
                    {
                        command.Parameters.Add(new SqlParameter("@Login", tbLogin.Text));
                        command.Parameters.Add(new SqlParameter("@Password", tbPassword.Text));
                        command.Parameters.Add(new SqlParameter("@DBNAME", Properties.Settings.Default.DataBase));

                        SqlDataReader reader = command.ExecuteReader();
                    }

                    using (SqlCommand command = new SqlCommand(
                               "sp_adduser @Login, @Login, @Role", connection))
                    {
                        command.Parameters.Add(new SqlParameter("@Login", tbLogin.Text));
                        command.Parameters.Add(new SqlParameter("@Role", "teacher"));

                        SqlDataReader reader = command.ExecuteReader();
                    }
                }

                db.Teacher.Add(new Teacher()
                {
                    Surname    = tbSurname.Text,
                    Name       = tbName.Text,
                    Patronymic = tbPatronymic.Text,
                    Login      = tbLogin.Text,
                });
                db.SaveChanges();
            }

            LoadData();
        }
Ejemplo n.º 3
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            short passMark;

            bool text   = tbName.Text.Equals("");
            bool number = !Int16.TryParse(tbPassMark.Text, out passMark);
            bool acsub  = comboBoxAcSubs.SelectedItem != null;

            if (text | number)
            {
                return;
            }

            if (acsub)
            {
                string          selectedText    = comboBoxAcSubs.SelectedItem.ToString().Trim();
                AcademicSubject academicSubject = academicSubjects.Find(item => item.Name.Trim().Equals(selectedText));

                using (StudentTestingEntities1 db = new StudentTestingEntities1())
                {
                    string query = @"exec dbo.addtest @TextName, @PassMark, @IdAcSub";

                    List <SqlParameter> sqlParameters = new List <SqlParameter>();
                    sqlParameters.Add(new SqlParameter("@TextName", tbName.Name));
                    sqlParameters.Add(new SqlParameter("@PassMark", passMark));
                    sqlParameters.Add(new SqlParameter("@IdAcSub", academicSubject.id));
                    db.Database.ExecuteSqlCommand(query, sqlParameters.ToArray());
                }
                Clear();
                LoadData();
            }
            else if (user.Role.Equals(UserRole.Admin))
            {
                DialogResult result = MessageBox.Show("Предмет не задан! Тест не будет виден, пока ему его не присовоят.", "Предупреждение", MessageBoxButtons.OKCancel);
                if (result.Equals(DialogResult.OK))
                {
                    using (StudentTestingEntities1 db = new StudentTestingEntities1())
                    {
                        db.Test.Add(new Test()
                        {
                            Name     = tbName.Text,
                            PassMark = passMark
                        });
                        db.SaveChanges();
                    }
                    Clear();
                    LoadData();
                }
                else
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show("Предмет не задан!");
            }
        }
 private void Save(List <Answer> saveList)
 {
     using (StudentTestingEntities1 db = new StudentTestingEntities1())
     {
         saveList.ForEach(o =>
         {
             o.idQuestion = Question.id;
             db.Answer.Add(o);
         });
         db.SaveChanges();
     }
 }
 private void Delete(List <Answer> deleteList)
 {
     using (StudentTestingEntities1 db = new StudentTestingEntities1())
     {
         deleteList.ForEach(o =>
         {
             db.Answer.Attach(o);
             db.Answer.Remove(o);
         });
         db.SaveChanges();
     }
 }
 private static void Delete(List <Question> deleteList)
 {
     using (StudentTestingEntities1 db = new StudentTestingEntities1())
     {
         deleteList.ForEach(o =>
         {
             db.Question.Attach(o);
             db.Question.Remove(o);
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 7
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (selectedTest == null)
            {
                MessageBox.Show("Элемент не выбран");
                return;
            }
            var deleteTest = new Test()
            {
                id       = (int)selectedTest.id,
                Name     = selectedTest.Name,
                PassMark = (short)selectedTest.PassMark
            };

            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                db.Entry(deleteTest).State = EntityState.Deleted;
                db.SaveChanges();
            }
            Clear();
            LoadData();
        }
 private void Update(List <Answer> updateList)
 {
     using (StudentTestingEntities1 db = new StudentTestingEntities1())
     {
         try
         {
             updateList.ForEach(o =>
             {
                 var p        = db.Answer.Where(z => z.Id == o.Id).FirstOrDefault();
                 p.isCorrect  = o.isCorrect;
                 p.idQuestion = o.idQuestion;
                 p.Text       = o.Text;
                 //db.Entry(p).State = EntityState.Modified;
             });
             db.SaveChanges();
         }
         catch (Exception j)
         {
             Console.Write(j.ToString());
         }
     }
 }
        private void Save(Subjects subject, List <Question> saveList)
        {
            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                saveList.ForEach(o =>
                {
                    o.idSubjects = subject.id;
                    db.Question.Add(o);
                });
                db.SaveChanges();

                saveList.ForEach(o =>
                {
                    o            = db.Question.Where(z => o.idSubjects == z.idSubjects & o.Mark == z.Mark & o.Text == z.Text).FirstOrDefault();
                    string query = @"INSERT into Question_Test(idQuestion,idTest) VALUES
                                    (@idQuestion, @idTest)";
                    List <SqlParameter> sqlParameters = new List <SqlParameter>();
                    sqlParameters.Add(new SqlParameter("@idQuestion", o.id));
                    sqlParameters.Add(new SqlParameter("@idTest", test.id));
                    db.Database.ExecuteSqlCommand(query, sqlParameters.ToArray());
                });
            }
        }
        private void Update(List <Question> updateList)
        {
            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                try
                {
                    updateList.ForEach(o =>
                    {
                        var entity = db.Question.Where(z => z.id == o.id).FirstOrDefault();
                        if (entity == null)
                        {
                            return;
                        }

                        db.Entry(entity).CurrentValues.SetValues(o);
                    });
                    db.SaveChanges();
                }
                catch (Exception j)
                {
                    Console.Write(j.ToString());
                }
            }
        }