Beispiel #1
0
        public void Update_Control(Persons.Control oldControl, Persons.Control newControl)
        {
            try
            {
                var cmdText =
                    "UPDATE [UPP-1].[dbo].[Control] SET Дата =  @Дата, Урок = @Урок, Оценка = @Оценка, Присутствие = @Присутствие, ID_Ученика = @ID_Ученика WHERE ID = @ID";

                var cmd = new SqlCommand(cmdText, _connection);
                cmd.Parameters.AddWithValue("@Дата", newControl.Date);
                cmd.Parameters.AddWithValue("@Урок", newControl.Lesson);
                cmd.Parameters.AddWithValue("@Оценка", newControl.Mark);
                cmd.Parameters.AddWithValue("@Присутствие", newControl.Presence);
                cmd.Parameters.AddWithValue("@ID_Ученика", newControl.ID_student);
                cmd.Parameters.AddWithValue("@ID", oldControl.ID);

                _connection.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (_connection != null)
                {
                    _connection.Close();
                }
            }
        }
Beispiel #2
0
        public void Insert_Control(Persons.Control c)
        {
            try
            {
                var cmdText =
                    "INSERT INTO [UPP-1].[dbo].[Control](Дата, Урок, Оценка, Присутствие, ID_Ученика) VALUES(@Дата, @Урок, @Оценка, @Присутствие, @ID_Ученика)";


                var cmd = new SqlCommand(cmdText, _connection);
                cmd.Parameters.AddWithValue("@Дата", c.Date);
                cmd.Parameters.AddWithValue("@Урок", c.Lesson);
                cmd.Parameters.AddWithValue("@Оценка", c.Mark);
                cmd.Parameters.AddWithValue("@Присутствие", c.Presence);
                cmd.Parameters.AddWithValue("@ID_Ученика", c.ID_student);

                _connection.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (_connection != null)
                {
                    _connection.Close();
                }
            }
        }
Beispiel #3
0
        private void btn_Control_Delete_Click(object sender, EventArgs e)
        {
            Persons.Control c = new Persons.Control();
            c = cBox_ChooseControl.SelectedItem as Persons.Control;

            b.Delete_Control(c);

            Form_Main_Load(sender, e);
            personsDataGridView.Update();
            personsDataGridView.Refresh();
        }
Beispiel #4
0
        private void btn_InsertControl_Click(object sender, EventArgs e)
        {
            Persons.Control c = new Persons.Control();

            c.Date       = dTimePicker_Control.Value;
            c.Lesson     = tBox_Control_Lesson.Text;
            c.Mark       = Convert.ToInt32(UpDown_Control_Mark.Text);
            c.Presence   = cBox_Presence.Checked;
            c.ID_student = Convert.ToInt32(UpDown_Control_IDStudent.Text);

            b.Insert_Control(c);

            Form_Main_Load(sender, e);
            controlDataGridView.Update();
            controlDataGridView.Refresh();
        }
Beispiel #5
0
        private void btn_Control_Edit_Click(object sender, EventArgs e)
        {
            Persons.Control oldControl = new Persons.Control();
            Persons.Control newControl = new Persons.Control();

            oldControl = cBox_ChooseControl.SelectedItem as Persons.Control;

            newControl.Date       = dTimePicker_NewControl.Value;
            newControl.Lesson     = tBox_Control_NewLesson.Text;
            newControl.Mark       = Convert.ToInt32(UpDown_Control_NewMark.Text);
            newControl.Presence   = cBox_Control_NewPresense.Checked;
            newControl.ID_student = Convert.ToInt32(UpDown_Control_NewIDStudent.Text);

            b.Update_Control(oldControl, newControl);

            Form_Main_Load(sender, e);
            controlDataGridView.Update();
            personsDataGridView.Refresh();
        }
Beispiel #6
0
        public List <Persons.Control> Clear_Control()
        {
            var controlList = new List <Persons.Control>();

            try
            {
                var cmdText = "TRUNCATE TABLE [UPP-1].[dbo].[Control]";
                var cmd     = new SqlCommand(cmdText, _connection);
                _connection.Open();
                cmd.ExecuteNonQuery();

                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    var c = new Persons.Control();

                    c.ID         = int.Parse(reader["ID"].ToString());
                    c.Date       = Convert.ToDateTime(reader["Дата"].ToString());
                    c.Lesson     = reader["Урок"].ToString();
                    c.Mark       = Convert.ToInt32(reader["Оценка"].ToString());
                    c.Presence   = Convert.ToBoolean(reader["Присутствие"].ToString());
                    c.ID_student = Convert.ToInt32(reader["ID_Ученика"].ToString());
                    controlList.Add(c);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (_connection != null)
                {
                    _connection.Close();
                }
            }

            return(controlList);
        }
Beispiel #7
0
        public void Delete_Control(Persons.Control c)
        {
            try
            {
                var cmdText = "DELETE FROM  [UPP-1].[dbo].[Control] WHERE ID = @ID";
                var cmd     = new SqlCommand(cmdText, _connection);
                cmd.Parameters.AddWithValue("@ID", c.ID);

                _connection.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (_connection != null)
                {
                    _connection.Close();
                }
            }
        }