Example #1
0
        private void InsertToFilm()
        {
            string query = "INSERT INTO Film (Название, Жанр, Актёры, Режиссёр, Страна, Год, " +
                           "[Целевая аудитория 18+], [Кол-во копий], [Тип носителя], Описание, Продолжительность, Рейтинг, [Язык озвучки]) VALUES ('" + NameOfTheFilmTextBox.Text + "','" + CategoryOfFilmComboBox.Text +
                           "','" + ActorsTextBox.Text + "','" + DirectorTextBox.Text +
                           "','" + ProducingCountryComboBox.Text + "','" + int.Parse(YearOfIssueTextBox.Text) + "','" + FilmForAdultsComboBox.Text +
                           "','" + int.Parse(NumberOfCopiesTextBox.Text) + "','" + TheTypeOfMediaComboBox.Text + "','" + SummaryTextBox.Text +
                           "','" + int.Parse(LengthInMinutes.Text) + "','" + Rating.Text + "','" + LanguagesForVoiceComboBox.Text + "')";

            cmd.CommandText = query;
            cmd.Connection  = connection;

            try
            {
                connection.Open();
                addFlag = cmd.ExecuteNonQuery();
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (GetLastId() == -1)
            {
                return;
            }
            else
            {
                for (int i = 1; i <= Convert.ToInt16(NumberOfCopiesTextBox.Text); i++)
                {
                    InsertToBusyFilmCopy(GetLastId(), i);
                }
            }

            //Проходим по всему ComboBox и достаём FilmId, после этого заполняем таблицу предыдущих частей
            for (int i = 0; i < listBox.Items.Count; i++)
            {
                string [] subStr = listBox.Items[i].ToString().Split('=');
                int       id     = Convert.ToInt16(subStr[1]);
                FillTablePreviousPartsOfFilm(id);
                comboBox1.Items.Clear();
            }


            CategoryOfFilmComboBox.SelectedIndex = -1;
            CategoryOfFilmComboBox.Text          = "Выберите или введите новый";
            NameOfTheFilmTextBox.Clear();
            ActorsTextBox.Clear();
            DirectorTextBox.Clear();
            ProducingCountryComboBox.SelectedIndex = -1;
            ProducingCountryComboBox.Text          = "Выберите";
            YearOfIssueTextBox.Clear();
            FilmForAdultsComboBox.SelectedIndex = -1;
            FilmForAdultsComboBox.Text          = "Выберите";
            NumberOfCopiesTextBox.Clear();
            TheTypeOfMediaComboBox.SelectedIndex = -1;
            TheTypeOfMediaComboBox.Text          = "Выберите";
            SummaryTextBox.Clear();
            LengthInMinutes.Clear();
            Rating.Clear();
            LanguagesForVoiceComboBox.SelectedIndex = -1;
            LanguagesForVoiceComboBox.Text          = "Выберите";
            listBox.Items.Clear();
            pictureBox.Image  = null;
            pictureBox1.Image = null;
            pictureBox2.Image = null;
            pictureBox3.Image = null;
        }
        private void GetPreviousPartsOfFilm(int FilmId)
        {
            string query = "select * FROM Film WHERE Id like '" + FilmId + "%'";

            byte[] image  = null;
            byte[] image1 = null;
            byte[] image2 = null;
            byte[] image3 = null;

            try
            {
                connection.Open();
                SqlCeCommand cmd = new SqlCeCommand(query, connection);

                SqlCeDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    NameOfTheFilmTextBox.Text    = reader["Название"].ToString();
                    CategoryOfFilmTextBox.Text   = reader["Жанр"].ToString();
                    ActorsTextBox.Text           = reader["Актёры"].ToString();
                    DirectorTextBox.Text         = reader["Режиссёр"].ToString();
                    ProducingCountryTextBox.Text = reader["Страна"].ToString();
                    YearOfIssueTextBox.Text      = reader["Год"].ToString();
                    FilmForAdultsTextBox.Text    = reader["Целевая аудитория 18+"].ToString();
                    NumberOfCopiesTextBox.Text   = reader["Кол-во копий"].ToString();
                    TheTypeOfMediaTextBox.Text   = reader["Тип носителя"].ToString();
                    SummaryTextBox.Text          = reader["Описание"].ToString();
                    LengthInMinutes.Text         = reader["Продолжительность"].ToString();
                    Rating.Text = reader["Рейтинг"].ToString();
                    LangForVoiceTextBox.Text = reader["Язык озвучки"].ToString();

                    try
                    {
                        image  = (byte[])reader["Photo1"];
                        image1 = (byte[])reader["Photo2"];
                        image2 = (byte[])reader["Photo3"];
                        image3 = (byte[])reader["Photo4"];
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Отсутствует изображение.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    if (image == null)
                    {
                        pictureBox.Image = null;
                    }
                    else
                    {
                        MemoryStream memoryStream = new MemoryStream(image);
                        pictureBox.Image = Image.FromStream(memoryStream);
                    }

                    if (image1 == null)
                    {
                        pictureBox1.Image = null;
                    }
                    else
                    {
                        MemoryStream memoryStream = new MemoryStream(image1);
                        pictureBox1.Image = Image.FromStream(memoryStream);
                    }

                    if (image2 == null)
                    {
                        pictureBox2.Image = null;
                    }
                    else
                    {
                        MemoryStream memoryStream = new MemoryStream(image2);
                        pictureBox2.Image = Image.FromStream(memoryStream);
                    }

                    if (image3 == null)
                    {
                        pictureBox3.Image = null;
                    }
                    else
                    {
                        MemoryStream memoryStream = new MemoryStream(image3);
                        pictureBox3.Image = Image.FromStream(memoryStream);
                    }
                }
                else
                {
                    CategoryOfFilmTextBox.Clear();
                    NameOfTheFilmTextBox.Clear();
                    ActorsTextBox.Clear();
                    DirectorTextBox.Clear();
                    ProducingCountryTextBox.Clear();
                    YearOfIssueTextBox.Clear();
                    FilmForAdultsTextBox.Clear();
                    NumberOfCopiesTextBox.Clear();
                    TheTypeOfMediaTextBox.Clear();
                    SummaryTextBox.Clear();
                    LengthInMinutes.Clear();
                    Rating.Clear();
                    LangForVoiceTextBox.Clear();
                }


                reader.Close();
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Show();
        }