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 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; }