예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox_Group.Text == "Выберите группу" || comboBox_Predmet.Text == "Выберите предмет")
            {
                MessageBox.Show("Выберите группу и предмет!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            DateTime date = DateTime.Now;
            Predmets pr   = new Predmets();

            pr.OpenConnection(connectionString);
            int idprd = pr.GetIdByName(comboBox_Predmet.Text);

            pr.CloseConnection();
            Marks m = new Marks();
            int   j = 1;

            m.OpenConnection(connectionString);
            foreach (var item in d)
            {
                if (this.Controls["t" + j].Text == "")
                {
                    continue;
                }
                int  nzach = item.Key;
                char mark  = this.Controls["t" + j].Text[0];
                m.InsertMark(nzach, id, idprd, mark, date);
                j++;
            }
            m.CloseConnection();
            MessageBox.Show("Оценки были успешно сохранены!");
            this.Close();
        }
예제 #2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grups g = new Grups();

            g.OpenConnection(connectionString);
            int idgr = g.GetIdByNzach(nzach);

            g.CloseConnection();
            Predmets p = new Predmets();

            p.OpenConnection(connectionString);
            int idprd = p.GetIdByName(comboBox1.Text);

            p.CloseConnection();
            Marks m = new Marks();

            m.OpenConnection(connectionString);
            dataGridView1.DataSource = m.GetMarksByGroupAndPredmet(idgr, idprd);
            m.CloseConnection();
        }
예제 #3
0
        private void button_Delete_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "Выберите предмет")
            {
                MessageBox.Show("Вы не предмет!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Predmets p     = new Predmets();
            int      idprd = -1;

            try
            {
                p.OpenConnection(connectionString);
                idprd = p.GetIdByName(comboBox1.Text);
                p.DeletePredmet(comboBox1.Text);
                p.CloseConnection();
            }
            catch (SqlException ex)
            {
                DialogResult result = MessageBox.Show("Невозможно удалить предмет!\nВ журнале присутствуют оценки!\nУдалить все оценки?", "Error!", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (result == DialogResult.Yes)
                {
                    Marks m = new Marks();
                    m.OpenConnection(connectionString);
                    m.DeleteMarksByPredmetId(idprd);
                    m.CloseConnection();
                    p.DeletePredmet(comboBox1.Text);
                    MessageBox.Show("Предмет был успешно удален!");
                }
                p.CloseConnection();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            MessageBox.Show("Предмет был успешно удален!");
            this.Close();
        }