private void frmMain_Load(object sender, EventArgs e) { pnlWelcome.BringToFront(); Conexao.criar_Conexao(); LivrosDAO livrodao = new LivrosDAO(); dgSearch.DataSource = livrodao.SelectForSearch(); foreach (DataColumn item in (dgSearch.DataSource as DataTable).Columns) { cbSearchType.Items.Add(item.ColumnName); } cbSearchType.SelectedIndex = 1; if (!System.IO.Directory.Exists(EnderecoCadastro())) { System.IO.Directory.CreateDirectory(EnderecoCadastro()); } DAO dao = new DAO(); cmbType.DataSource = dao.Load_Table("SELECT * FROM tipoprod"); cmbType.ValueMember = "idTipoProd"; cmbType.DisplayMember = "TipoProd"; cmbTipo.DataSource = dao.Load_Table("SELECT * FROM tipoprod"); cmbTipo.ValueMember = "idTipoProd"; cmbTipo.DisplayMember = "TipoProd"; }
//----------------------// //----------------------// //----------------------// #region "BookSearch" private void ChamarOPainel() { switchPnl(pnlSearch); LivrosDAO dao = new LivrosDAO(); dgSearch.DataSource = dao.SelectForSearch(); }
private void btnAlt_Click(object sender, EventArgs e) { if (txtAutores.Text == string.Empty || txtEdição.Text == string.Empty || txtPreco.Text == string.Empty || txtSinopse.Text == string.Empty || txtTitulo.Text == string.Empty) { MessageBox.Show("Os campos Destacados são obrigatorios e devem ser preenchidos"); txtAutores.BackColor = Color.Salmon; txtEdição.BackColor = Color.Salmon; txtPreco.BackColor = Color.Salmon; txtSinopse.BackColor = Color.Salmon; txtTitulo.BackColor = Color.Salmon; } else { try { Livro book = new Livro(); LivrosDAO bookDAO = new LivrosDAO(); book.Id = idLivro; book.Title = txtTitulo.Text; book.Subtitle = txtSubtitulo.Text; book.Authors = txtAutores.Text; book.Publisher = txtEditora.Text; book.Sinopse = txtSinopse.Text; book.Gender = txtGenero.Text; book.Price = Convert.ToDouble(txtPreco.Text); book.Year = txtAno.Text; book.Edicao = Convert.ToInt32(txtEdição.Text); book.Type = Convert.ToInt32(cmbTipo.SelectedValue); //---- txtAutores.BackColor = Color.Empty; txtEdição.BackColor = Color.Empty; txtPreco.BackColor = Color.Empty; txtSinopse.BackColor = Color.Empty; txtTitulo.BackColor = Color.Empty; //---- bookDAO.alterar(book); MessageBox.Show("Dados alterados com sucesso!!"); switchPnl(pnlSearch); } catch (FormatException) { MessageBox.Show("Verificar as informações digitadas nos campos!!"); } } }
//----------------------// //----------------------// //----------------------// #region "BookEdit" private void btnExc_Click(object sender, EventArgs e) { DialogResult exc; exc = MessageBox.Show("Deseja realmente excluir o livro?", "Excluir", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (exc == DialogResult.Yes) { LivrosDAO bookDAO = new LivrosDAO(); Livro book = new Livro(); bookDAO.excluir(idLivro); MessageBox.Show("Livro excluido com sucesso!!"); } else { MessageBox.Show("Cancelado."); } }
private void open_Edit(int cod) { idLivro = cod; LivrosDAO dao = new LivrosDAO(); Livro livro = new Livro() { Id = cod }; switchPnl(pnlEdit); dao.Search(livro); txtAno.Text = livro.Year; txtAutores.Text = livro.Authors; txtEditora.Text = livro.Publisher.ToString(); txtEdição.Text = livro.Edicao.ToString(); txtGenero.Text = livro.Gender; txtPreco.Text = livro.Price.ToString("0.00"); txtSinopse.Text = livro.Sinopse; txtSubtitulo.Text = livro.Subtitle; txtTitulo.Text = livro.Title; cmbTipo.SelectedValue = livro.Type; }
private void btnCadProd_Click(object sender, EventArgs e) { if (txtFile.Text == string.Empty || txtTitle.Text == string.Empty || txtPrice.Text == string.Empty || txtAutors.Text == string.Empty || txtEdition.Text == string.Empty || txtAbs.Text == string.Empty) { if (txtFile.Text == string.Empty) { txtFile.BackColor = Color.Salmon; } if (txtTitle.Text == string.Empty) { txtTitle.BackColor = Color.Salmon; } if (txtPrice.Text == string.Empty) { txtPrice.BackColor = Color.Salmon; } if (txtAutors.Text == string.Empty) { txtAutors.BackColor = Color.Salmon; } if (txtEdition.Text == string.Empty) { txtEdition.BackColor = Color.Salmon; } if (txtAbs.Text == string.Empty) { txtAbs.BackColor = Color.Salmon; } MessageBox.Show("Preencha os campos em Rosa.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { try { string FileName = System.IO.Path.GetFileName(txtFile.Text); string newLocation = (EnderecoCadastro() + FileName).Replace("'".ToCharArray()[0], ' '); System.IO.File.Copy(txtFile.Text, newLocation, true); b.File = newLocation.ToString().Replace('\\', '/'); b.Title = txtTitle.Text; b.Price = Convert.ToDouble(txtPrice.Text); if (txtSubT.Text == string.Empty) { b.Subtitle = null; } else { b.Subtitle = txtSubT.Text; } b.Year = txtYear.Text; b.Authors = txtAutors.Text; b.Edicao = Convert.ToInt32(txtEdition.Text); b.Publisher = txtEditora.Text; b.Type = Convert.ToInt32(cmbType.SelectedValue); b.Gender = txtGenero.Text; b.Sinopse = txtSinopse.Text; bdao.inserir(b); txtAutors.Text = string.Empty; txtEdition.Text = string.Empty; txtEditora.Text = string.Empty; txtFile.Text = string.Empty; txtGenero.Text = string.Empty; txtPrice.Text = string.Empty; txtAbs.Text = string.Empty; txtSubT.Text = string.Empty; txtTitle.Text = string.Empty; txtYear.Text = string.Empty; cmbType.Text = string.Empty; MessageBox.Show("Cadastrado com sucesso"); LivrosDAO livrodao = new LivrosDAO(); dgSearch.DataSource = livrodao.selectAll(); //-- txtFile.BackColor = Color.Empty; txtTitle.BackColor = Color.Empty; txtPrice.BackColor = Color.Empty; txtAutors.BackColor = Color.Empty; txtEdition.BackColor = Color.Empty; txtAbs.BackColor = Color.Empty; } catch { MessageBox.Show("Reveja o endereço.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (FormatException) { MessageBox.Show("Reveja os Dados.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void pnlSearch_VisibleChanged_1(object sender, EventArgs e) { LivrosDAO dao = new LivrosDAO(); dgSearch.DataSource = dao.SelectForSearch(); }