private void btn_AddFi_Click(object sender, RoutedEventArgs e)
        {
            int size;

            if (!this.fileid_select.Text.Equals("") &&
                this.format_select.SelectedIndex != -1 &&
                int.TryParse(this.filesize_select.Text, out size))
            {
                SqlTransaction trans = null;
                SqlCommand     comm  = null;
                try
                {
                    comm             = connection.CreateCommand();
                    trans            = connection.BeginTransaction("BookAdding");
                    comm.CommandText = "insert into Files(file_id, format, file_size) values ('" +
                                       this.fileid_select.Text + "', '" +
                                       ((ComboBoxItem)this.format_select.Items[this.format_select.SelectedIndex]).Content + "', " +
                                       size.ToString() + ")";
                    comm.Transaction = trans;
                    comm.ExecuteNonQuery();
                    trans.Commit();
                    FillForm();
                    this.datagrid.ItemsSource = GetTables.GetFiles(this.connection).DefaultView;
                }
                catch (Exception ex)
                {
                    this.errors.Text = ex.Message + '\n' + this.errors.Text;
                }
            }
            else
            {
                this.errors.Text = "Все поля заполни слыш" + '\n' + this.errors.Text;
            }
        }
 private void btn_AddAu_Click(object sender, RoutedEventArgs e)
 {
     if (!this.fio_select.Text.Equals("") && !this.country_select.Text.Equals(""))
     {
         SqlTransaction trans = null;
         SqlCommand     comm  = null;
         try
         {
             comm             = connection.CreateCommand();
             trans            = connection.BeginTransaction("AuthAdding");
             comm.CommandText = "insert into Authors(FIO, country) values ('" +
                                this.fio_select.Text + "', '" +
                                this.country_select.Text + "')";
             comm.Transaction = trans;
             comm.ExecuteNonQuery();
             trans.Commit();
             this.datagrid.ItemsSource = GetTables.GetAuthors(this.connection).DefaultView;
             FillForm();
         }
         catch (Exception ex)
         {
             this.errors.Text = ex.Message + '\n' + this.errors.Text;
         }
     }
 }
 private void search_field_TextChanged(object sender, TextChangedEventArgs e)
 {
     try
     {
         if (!this.search_field.Text.Equals(""))
         {
             this.datagrid.ItemsSource = GetTables.Search(((DataView)datagrid.ItemsSource).Table.TableName, this.search_field.Text, connection).DefaultView;
         }
     }
     catch (Exception ex)
     {
         this.errors.Text = ex.Message + '\n' + this.errors.Text;
     }
 }
 private void FillForm()
 {
     files   = GetTables.GetFiles(this.connection);
     authors = GetTables.GetAuthors(this.connection);
     for (int i = 0; i < files.Rows.Count; i++)
     {
         this.file_select.Items.Add(files.Rows[i][0]);
     }
     for (int i = 0; i < authors.Rows.Count; i++)
     {
         this.auth_select.Items.Add(authors.Rows[i][0]);
     }
     this.file_select.SelectedIndex = 0;
     this.auth_select.SelectedIndex = 0;
 }
        private void btn_delBook_Click(object sender, RoutedEventArgs e)
        {
            var selectedItem = datagrid.SelectedItem;

            if (selectedItem != null)
            {
                try
                {
                    if (((DataView)datagrid.ItemsSource).Table.TableName.Equals("Books"))
                    {
                        SqlCommand comm = connection.CreateCommand();
                        comm.CommandText = "delete Books where title like '" +
                                           ((DataRowView)selectedItem).Row.ItemArray[0] + "'";
                        comm.ExecuteNonQuery();
                        FillBookList();
                    }
                    else if (((DataView)datagrid.ItemsSource).Table.TableName.Equals("Files"))
                    {
                        SqlCommand comm = connection.CreateCommand();
                        comm.CommandText = "delete Files where file_id like '" +
                                           ((DataRowView)selectedItem).Row.ItemArray[0] + "'";
                        comm.ExecuteNonQuery();
                        this.datagrid.ItemsSource = GetTables.GetFiles(this.connection).DefaultView;
                        FillForm();
                    }
                    else
                    {
                        SqlCommand comm = connection.CreateCommand();
                        comm.CommandText = "delete Authors where FIO like '" +
                                           ((DataRowView)selectedItem).Row.ItemArray[0] + "'";
                        comm.ExecuteNonQuery();
                        this.datagrid.ItemsSource = GetTables.GetAuthors(this.connection).DefaultView;
                        FillForm();
                    }
                }
                catch (Exception ex)
                {
                    this.errors.Text = ex.Message + '\n' + this.errors.Text;
                }
            }
        }
 private void btn_showAuthors_Click(object sender, RoutedEventArgs e)
 {
     this.datagrid.ItemsSource = GetTables.GetAuthors(this.connection).DefaultView;
 }