Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
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;
                }
            }
        }
Exemplo n.º 4
0
 private void btn_showFiles_Click(object sender, RoutedEventArgs e)
 {
     this.datagrid.ItemsSource = GetTables.GetFiles(this.connection).DefaultView;
 }