コード例 #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string          selectedText    = comboBoxAcSubs.SelectedItem.ToString().Trim();
            AcademicSubject academicSubject = allAcademicSubjects.Find(item => item.Name.Trim().Equals(selectedText));

            bool alreadyExist = false;
            var  x            = dataGridView1.Rows;

            for (int i = 0; i < x.Count; i++)
            {
                if (Convert.ToInt32(x[i].Cells["id"].Value) == academicSubject.id)
                {
                    alreadyExist = true;
                }
            }

            if (academicSubject == null || alreadyExist)
            {
                MessageBox.Show("Данная связь уже существует или предмет не выбран");
                return;
            }
            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                string query = @"Insert Into Test_AcademicSubject Values
                                (@idTest, @idAcademicSubject)";

                List <SqlParameter> sqlParameters = new List <SqlParameter>();
                sqlParameters.Add(new SqlParameter("@idAcademicSubject", academicSubject.id));
                sqlParameters.Add(new SqlParameter("@idTest", test.id));
                db.Database.ExecuteSqlCommand(query, sqlParameters.ToArray());
                LoadData();
            }
        }
コード例 #2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string          selectedText    = comboBox1.SelectedItem.ToString().Trim();
            AcademicSubject academicSubject = academicSubjects.Find(item => item.Name.Trim().Equals(selectedText));

            bool alreadyExist = false;
            var  x            = dataGridView1.Rows;

            for (int i = 0; i < x.Count; i++)
            {
                if (Convert.ToInt32(x[i].Cells["id"].Value) == academicSubject.id)
                {
                    alreadyExist = true;
                }
            }

            if (academicSubject == null || alreadyExist)
            {
                MessageBox.Show("Данная связь уже существует или предмет не выбран");
                return;
            }
            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                db.AddAcSubjects(idTeacher, academicSubject.id);
                LoadData();
            }
        }
コード例 #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("Предмет не задан!");
            }
        }
コード例 #4
0
        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int idAc = Int32.Parse(dataGridView1["id", e.RowIndex].Value.ToString());

            selectedAcademicSubject = allAcademicSubjects.Find(item => item.id.Equals(idAc));

            int index = comboBoxAcSubs.Items.IndexOf(selectedAcademicSubject.Name.Trim());

            comboBoxAcSubs.SelectedItem = comboBoxAcSubs.Items[index];

            buttonDelete.Enabled = true;
            buttonAdd.Enabled    = false;
        }
コード例 #5
0
        private void LoadTestWithAcSub()
        {
            string          selectedText    = comboBoxAcSubs.SelectedItem.ToString().Trim();
            AcademicSubject academicSubject = academicSubjects.Find(o => o.Name.Trim().Equals(selectedText));


            using (StudentTestingEntities1 db = new StudentTestingEntities1())
            {
                string       query     = @"Select t.id,t.Name,t.PassMark from test as t
                                JOIN Test_AcademicSubject as T_AS ON T_AS.idTest = t.id
                                Where T_AS.idAcademicSubject = @idAS;";
                SqlParameter parameter = new SqlParameter("@idAS", academicSubject.id);
                tests = db.Database.SqlQuery <Test>(query, parameter).ToList();
                dataGridView1.DataSource = tests;
                ConfigureDataGridView();
            }
        }