private void Session(object sender, RoutedEventArgs e) { try { if (Validator.ValidTextBoxes(this.Movie.Text, this.Cinema.Text, this.Hall.Text, this.Cost.Text, this.Time.Text)) { using (SqlConnection cn = Connector.GetConnection()) { cn.Open(); SqlCommand cmd = new SqlCommand("InsertSession", cn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter movie = new SqlParameter(); movie.ParameterName = "@movie"; movie.Value = this.Movie.Text; SqlParameter cinema = new SqlParameter(); cinema.ParameterName = "@cinema"; cinema.Value = this.Cinema.Text; SqlParameter hall = new SqlParameter(); hall.ParameterName = "@hall"; hall.Value = this.Hall.Text; SqlParameter date = new SqlParameter(); date.ParameterName = "@date"; date.Value = this.Date.SelectedDate; SqlParameter cost = new SqlParameter(); cost.ParameterName = "@cost"; cost.Value = this.Cost.Text; SqlParameter time = new SqlParameter(); time.ParameterName = "@time"; time.Value = TimeSpan.Parse(Time.Text); cmd.Parameters.Add(movie); cmd.Parameters.Add(cinema); cmd.Parameters.Add(hall); cmd.Parameters.Add(date); cmd.Parameters.Add(cost); cmd.Parameters.Add(time); SqlParameter rc = new SqlParameter(); rc.ParameterName = "@rc"; rc.SqlDbType = SqlDbType.Bit; rc.Direction = ParameterDirection.Output; cmd.Parameters.Add(rc); cmd.ExecuteNonQuery(); cn.Close(); if ((bool)cmd.Parameters["@rc"].Value) { MessageBox.Show("Добавление произошло успешно!"); MainWindow mainWnd = new MainWindow(); mainWnd.Show(); this.Close(); } else { MessageBox.Show("Ошибка добавления!"); } } } else { MessageBox.Show("Введите данные!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Actor(object sender, RoutedEventArgs e) { try { if (Validator.ValidTextBoxes(this.Name.Text, this.Surname.Text, this.Country.Text, this.Age.Text)) { if (imageName != "") { //Initialize a file stream to read the image file FileStream fs = new FileStream(imageName, FileMode.Open, FileAccess.Read); //Initialize a byte array with size of stream byte[] imgByteArr = new byte[fs.Length]; //Read data from the file stream and put into the byte array fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length)); //Close a file stream fs.Close(); using (SqlConnection cn = Connector.GetConnection()) { cn.Open(); SqlCommand cmd = new SqlCommand("InsertActor", cn); cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter name = new SqlParameter(); name.ParameterName = "@name"; name.Value = this.Name.Text; SqlParameter surname = new SqlParameter(); surname.ParameterName = "@surname"; surname.Value = this.Surname.Text; SqlParameter country = new SqlParameter(); country.ParameterName = "@country"; country.Value = this.Country.Text; SqlParameter age = new SqlParameter(); age.ParameterName = "@age"; age.Value = this.Age.Text; cmd.Parameters.Add(name); cmd.Parameters.Add(surname); cmd.Parameters.Add(country); cmd.Parameters.Add(age); cmd.Parameters.Add(new SqlParameter("image", imgByteArr)); SqlParameter rc = new SqlParameter(); rc.ParameterName = "@rc"; rc.SqlDbType = System.Data.SqlDbType.Bit; rc.Direction = System.Data.ParameterDirection.Output; cmd.Parameters.Add(rc); cmd.ExecuteNonQuery(); cn.Close(); if ((bool)cmd.Parameters["@rc"].Value) { MessageBox.Show("Добавление произошло успешно!"); MainWindow mainWnd = new MainWindow(); mainWnd.Show(); this.Close(); } else { MessageBox.Show("Ошибка добавления!"); } } } } else { MessageBox.Show("Введите данные!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }