コード例 #1
0
        private void txtPesquisa_TextChanged(object sender, EventArgs e)
        {
            try
            {
                Conexao.Conectar();

                string     sql = @"SELECT * FROM LEITORES
                    WHERE NOME LIKE '" + txtPesquisa.Text + "%'";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                DataTable  dt  = new DataTable();
                dt.Load(cmd.ExecuteReader());
                dgvLeitor.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }
コード例 #2
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (txtNome.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtNome, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtNome, "");
            }

            if (mskCelular.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskCelular, "Preencha o campo celular");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskCelular, "");
            }

            if (mskCEP.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskCEP, "Preencha o campo CEP");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskCEP, "");
            }

            if (cmbEstado.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(cmbEstado, "Preencha o campo estado");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(cmbEstado, "");
            }

            if (cmbCidade.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(cmbEstado, "Preencha o campo cidade");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(cmbCidade, "");
            }

            if (txtRua.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtRua, "Preencha o campo RUA");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtRua, "");
            }

            if (txtNumero.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtNumero, "Preencha o campo NÚMERO");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtNumero, "");
            }

            if (txtBairro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtBairro, "Preencha o campo BAIRRO");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtBairro, "");
            }

            try
            {
                Conexao.Conectar();
                string     sql = @"INSERT INTO LEITORES ([NOME]
           ,[EMAIL]
           ,[TELEFONE]
           ,[CELULAR]
           ,[PROFISSAO]
           ,[CEP]
           ,[ESTADO]
           ,[CIDADE]
           ,[RUA]
           ,[NUMERO]
           ,[COMPLEMENTO]
           ,[BAIRRO]
           ,[FOTO]) VALUES (@nome, @email,
                    @telefone, @celular, @profissao, @cep, @estado, @cidade, @rua,
                    @numero, @complemento, @bairro, @foto)";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                cmd.Parameters.AddWithValue("nome", txtNome.Text);
                cmd.Parameters.AddWithValue("email", txtEmail.Text);
                cmd.Parameters.AddWithValue("telefone", mskTelefone.Text);
                cmd.Parameters.AddWithValue("celular", mskCelular.Text);
                cmd.Parameters.AddWithValue("profissao", txtProfissao.Text);
                cmd.Parameters.AddWithValue("cep", mskCEP.Text);
                cmd.Parameters.AddWithValue("estado", cmbEstado.Text);
                cmd.Parameters.AddWithValue("cidade", cmbCidade.Text);
                cmd.Parameters.AddWithValue("rua", txtRua.Text);
                cmd.Parameters.AddWithValue("numero", txtNumero.Text);
                cmd.Parameters.AddWithValue("complemento", txtComplemento.Text);
                cmd.Parameters.AddWithValue("bairro", txtBairro.Text);
                // Adicionar imagem NULL ao banco de dados
                SqlParameter fotoParam = new SqlParameter("foto", SqlDbType.Image);
                if (ConectaWebCam.imagem != null)
                {
                    fotoParam.Value = ConectaWebCam.imagem;
                }
                else
                {
                    fotoParam.Value = DBNull.Value;
                }
                cmd.Parameters.Add(fotoParam);
                //cmd.Parameters.AddWithValue("data", DateTime.Now.ToShortDateString());

                cmd.ExecuteNonQuery();

                MessageBox.Show("Leitor cadastrado com sucesso!");

                Util.LimparCampos(this);
                txtNome.Focus();
                pcbFoto.Image = Properties.Resources.default_user_1;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }
コード例 #3
0
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            if (txtNome.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtNome, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtNome, "");
            }

            if (mskCelular.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskCelular, "Preencha o campo celular");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskCelular, "");
            }

            if (mskCEP.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskCEP, "Preencha o campo CEP");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskCEP, "");
            }

            if (cmbEstado.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(cmbEstado, "Preencha o campo estado");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(cmbEstado, "");
            }

            if (cmbCidade.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(cmbEstado, "Preencha o campo cidade");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(cmbCidade, "");
            }

            if (txtRua.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtRua, "Preencha o campo RUA");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtRua, "");
            }

            if (txtNumero.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtNumero, "Preencha o campo NÚMERO");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtNumero, "");
            }

            if (txtBairro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtBairro, "Preencha o campo BAIRRO");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtBairro, "");
            }

            try
            {
                Conexao.Conectar();

                string     sql = @"UPDATE LEITORES SET NOME = @NOME,
                    EMAIL = @EMAIL, TELEFONE = @TELEFONE,
                    CELULAR = @CELULAR, PROFISSAO = @PROFISSAO, CEP = @CEP,
                    ESTADO = @ESTADO, CIDADE = @CIDADE, RUA = @RUA, 
                    NUMERO = @NUMERO, COMPLEMENTO = @COMPLEMENTO,
                    BAIRRO = @BAIRRO, FOTO = @FOTO
                    WHERE CODIGO = @CODIGO";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                cmd.Parameters.AddWithValue("nome", txtNome.Text);
                cmd.Parameters.AddWithValue("email", txtEmail.Text);
                cmd.Parameters.AddWithValue("telefone", mskTelefone.Text);
                cmd.Parameters.AddWithValue("celular", mskCelular.Text);
                cmd.Parameters.AddWithValue("profissao", txtProfissao.Text);
                cmd.Parameters.AddWithValue("cep", mskCEP.Text);
                cmd.Parameters.AddWithValue("estado", cmbEstado.Text);
                cmd.Parameters.AddWithValue("cidade", cmbCidade.Text);
                cmd.Parameters.AddWithValue("rua", txtRua.Text);
                cmd.Parameters.AddWithValue("numero", txtNumero.Text);
                cmd.Parameters.AddWithValue("complemento", txtComplemento.Text);
                cmd.Parameters.AddWithValue("bairro", txtBairro.Text);
                // Adicionar imagem NULL ao banco de dados
                SqlParameter fotoParam = new SqlParameter("foto", SqlDbType.Image);
                if (ConectaWebCam.imagem != null)
                {
                    fotoParam.Value = ConectaWebCam.imagem;
                }
                else
                {
                    fotoParam.Value = DBNull.Value;
                }
                cmd.Parameters.Add(fotoParam);
                //cmd.Parameters.AddWithValue("data", DateTime.Now.ToShortDateString());
                cmd.Parameters.AddWithValue("codigo", Leitores.codigo);

                cmd.ExecuteNonQuery();

                MessageBox.Show("Leitor alterado com sucesso!");

                Util.LimparCampos(this);
                mskDataCadastro.Text = DateTime.Now.ToShortDateString();
                txtNome.Focus();

                btnCadastrar.Enabled = true;

                btnAlterar.Enabled = false;
                btnExcluir.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }
コード例 #4
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (txtTituloLivro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtTituloLivro, "Preencha o campo Titulo do livro!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtTituloLivro, "");
            }

            if (txtAutor.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtAutor, "Preencha o campo Autor!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtAutor, "");
            }

            if (txtTombo.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtTombo, "Preencha o campo Tombo!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtTombo, "");
            }

            if (txtEditora.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtEditora, "Preencha o campo Editora!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtEditora, "");
            }

            if (mskAnoLivro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskAnoLivro, "Preencha o campo Ano de Lançamento!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskAnoLivro, "");
            }

            if (txtExemplar.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtExemplar, "Preencha o campo Exemplar!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtExemplar, "");
            }

            if (mskDataCadastro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskDataCadastro, "Preencha o campo Data de Cadastro!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskDataCadastro, "");
            }

            if (txtCodigoBarras.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtCodigoBarras, "Preencha o campo Código de Barras!");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtCodigoBarras, "");
            }

            try
            {
                Conexao.Conectar();
                string sql = @"INSERT INTO LIVROS VALUES (@tombo, @titulo, @autor, @data_cadastro, @editora, @exemplar, @foto, @ano_lancamento, @cod_barras)";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                cmd.Parameters.AddWithValue("tombo", txtTombo.Text);
                cmd.Parameters.AddWithValue("titulo", txtTituloLivro.Text);
                cmd.Parameters.AddWithValue("autor", txtAutor.Text);
                cmd.Parameters.AddWithValue("data_cadastro", mskDataCadastro.Text);
                cmd.Parameters.AddWithValue("editora", txtEditora.Text);
                cmd.Parameters.AddWithValue("exemplar", txtExemplar.Text);
                cmd.Parameters.AddWithValue("ano_lancamento", mskAnoLivro.Text);
                cmd.Parameters.AddWithValue("cod_barras", txtCodigoBarras.Text);
                SqlParameter fotoParam = new SqlParameter("foto", SqlDbType.Image);
                if (ConectaWebCam.imagem != null)
                {
                    fotoParam.Value = ConectaWebCam.imagem;
                }
                else
                {
                    fotoParam.Value = DBNull.Value;
                }
                cmd.Parameters.Add(fotoParam);

                cmd.ExecuteNonQuery();

                MessageBox.Show("Livro cadastrado com sucesso!");

                Util.LimparCampos(this);
                txtTituloLivro.Focus();
                pcbFoto.Image = Properties.Resources.open_book_menu;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }
コード例 #5
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (txtNome.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtNome, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtNome, "");
            }
            if (mskCelular.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskCelular, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskCelular, "");
            }
            if (mskCEP.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskCEP, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskCEP, "");
            }
            if (cmbEstado.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(cmbEstado, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(cmbEstado, "");
            }
            if (cmbCidade.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(cmbCidade, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(cmbCidade, "");
            }
            if (txtRua.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtRua, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtRua, "");
            }
            if (txtNumero.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtNumero, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtNumero, "");
            }
            if (txtBairro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtBairro, "Preencha o campo nome");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtBairro, "");
            }
            try
            {
                Conexao.Conectar();
                string     sql = @"INSERT INTO LEITORES VALUES (@nome, @email,
            @telefone, @celular, @profissao, @cep, @estado, @cidade, @rua,
            @numero, @complemento, @bairro, @foto, @data)";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                cmd.Parameters.AddWithValue("nome", txtNome.Text);
                cmd.Parameters.AddWithValue("email", txtEmail.Text);
                cmd.Parameters.AddWithValue("telefone", mskResidencial.Text);
                cmd.Parameters.AddWithValue("celular", mskCelular.Text);
                cmd.Parameters.AddWithValue("profissao", txtProfissao.Text);
                cmd.Parameters.AddWithValue("cep", mskCEP.Text);
                cmd.Parameters.AddWithValue("estado", cmbEstado.Text);
                cmd.Parameters.AddWithValue("cidade", cmbCidade.Text);
                cmd.Parameters.AddWithValue("rua", txtRua.Text);
                cmd.Parameters.AddWithValue("numero", txtNumero.Text);
                cmd.Parameters.AddWithValue("complemento", txtComplemento.Text);
                cmd.Parameters.AddWithValue("bairro", txtBairro.Text);
                //Adicionar imagem NULL ao banco de dados
                SqlParameter fotoParam = new SqlParameter("foto", SqlDbType.Image);
                if (ConectaWebcam.imagem != null)
                {
                    fotoParam.Value = ConectaWebcam.imagem;
                }
                else
                {
                    fotoParam.Value = DBNull.Value;
                }
                cmd.Parameters.Add(fotoParam);
                cmd.Parameters.AddWithValue("data", mskDataCadastro.Text);

                cmd.ExecuteNonQuery();

                MessageBox.Show("Leitor cadastrado!");
                Util.LimparCampos(this);
                txtNome.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }
コード例 #6
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (txtTombo.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtTombo, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtTombo, "");
            }
            if (mskDataCadastro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskDataCadastro, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskDataCadastro, "");
            }
            if (mskLancamento.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskLancamento, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskLancamento, "");
            }
            if (txtTitulo.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtTitulo, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtTitulo, "");
            }
            if (txtAutor.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtAutor, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtAutor, "");
            }
            if (txtEditora.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtEditora, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtEditora, "");
            }
            if (txtExemplar.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtExemplar, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtExemplar, "");
            }
            if (txtCodigoBarras.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtCodigoBarras, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtCodigoBarras, "");
            }
            try
            {
                Conexao.Conectar();
                string     sql = @"INSERT INTO LIVROS VALUES (@tombo, @titulo,
            @autor, @data_cadastro, @editora, @exemplar, @ano_lancamento, @cod_barras)";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                cmd.Parameters.AddWithValue("tombo", txtTombo.Text);
                cmd.Parameters.AddWithValue("titulo", txtTitulo.Text);
                cmd.Parameters.AddWithValue("autor", txtAutor.Text);
                cmd.Parameters.AddWithValue("data_cadastro", mskDataCadastro.Text);
                cmd.Parameters.AddWithValue("editora", txtEditora.Text);
                cmd.Parameters.AddWithValue("exemplar", txtExemplar.Text);
                cmd.Parameters.AddWithValue("ano_lancamento", mskLancamento.Text);
                cmd.Parameters.AddWithValue("cod_barras", txtCodigoBarras.Text);
                cmd.ExecuteNonQuery();

                MessageBox.Show("Livro cadastrado!");
                Util.LimparCampos(this);
                txtTombo.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }
コード例 #7
0
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            if (txtTombo.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtTombo, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtTombo, "");
            }
            if (mskDataCadastro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskDataCadastro, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskDataCadastro, "");
            }
            if (mskLancamento.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskLancamento, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskLancamento, "");
            }
            if (txtTitulo.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtTitulo, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtTitulo, "");
            }
            if (txtAutor.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtAutor, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtAutor, "");
            }
            if (txtEditora.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtEditora, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtEditora, "");
            }
            if (txtExemplar.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtExemplar, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtExemplar, "");
            }
            if (txtCodigoBarras.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtCodigoBarras, "Preencha o campo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtCodigoBarras, "");
            }
            try
            {
                Conexao.Conectar();
                string     sql = @"UPDATE LIVROS SET TOMBO = @TOMBO,
                        TITULO = @TITULO, AUTOR = @AUTOR, DATA_CADASTRO = @DATA_CADASTRO,
                        EDITORA = @EDITORA, EXEMPLAR = @EXEMPLAR, 
                        ANO_LANCAMENTO = @ANO_LANCAMENTO, COD_BARRAS = @COD_BARRAS
                        WHERE CODIGO = @CODIGO";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                cmd.Parameters.AddWithValue("codigo", Livros.codigo);
                cmd.Parameters.AddWithValue("tombo", txtTombo.Text);
                cmd.Parameters.AddWithValue("titulo", txtTitulo.Text);
                cmd.Parameters.AddWithValue("autor", txtAutor.Text);
                cmd.Parameters.AddWithValue("data_cadastro", mskDataCadastro.Text);
                cmd.Parameters.AddWithValue("editora", txtEditora.Text);
                cmd.Parameters.AddWithValue("exemplar", txtExemplar.Text);
                cmd.Parameters.AddWithValue("ano_lancamento", mskLancamento.Text);
                cmd.Parameters.AddWithValue("cod_barras", txtCodigoBarras.Text);
                cmd.ExecuteNonQuery();

                MessageBox.Show("Livro cadastrado!");
                Util.LimparCampos(this);
                txtTombo.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }
コード例 #8
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (txtTombo.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtTombo, "Preencha o campo tombo");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtTitulo, "");
            }

            if (txtAutor.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtAutor, "Preencha o campo autor");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtAutor, "");
            }

            if (mskDataCadastro.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskDataCadastro, "Preencha o campo Data de Cadastro");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskDataCadastro, "");
            }

            if (txtEditora.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtEditora, "Preencha o campo editora");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtEditora, "");
            }

            if (txtExemplar.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtExemplar, "Preencha o campo Exemplar");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtExemplar, "");
            }

            if (mskDataLancamento.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(mskDataLancamento, "Preencha o campo Data de Lançamento");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(mskDataLancamento, "");
            }

            if (txtCodigoDeBarras.Text.Trim().Length == 0)
            {
                erpPreencherCampos.SetError(txtCodigoDeBarras, "Preencha o campo Código de Barras");
                return;
            }
            else
            {
                erpPreencherCampos.SetError(txtCodigoDeBarras, "");
            }

            try
            {
                Conexao.Conectar();
                string     sql = @"INSERT INTO LIVROS ([TOMBO]
           ,[TITULO]
           ,[AUTOR]
           ,[DATA_CADASTRO]
           ,[EDITORA]
           ,[EXEMPLAR]
           ,[ANO_LANCAMENTO]
           ,[COD_BARRAS]
            ) VALUES (@tombo, @titulo,
                    @autor, @data_cadastro, @editora, @exemplar, @ano_lancamento, @cod_barras)";
                SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
                cmd.Parameters.AddWithValue("tombo", txtTombo.Text);
                cmd.Parameters.AddWithValue("titulo", txtTitulo.Text);
                cmd.Parameters.AddWithValue("autor", txtAutor.Text);
                cmd.Parameters.AddWithValue("data_cadastro", mskDataCadastro.Text);
                cmd.Parameters.AddWithValue("editora", txtEditora.Text);
                cmd.Parameters.AddWithValue("exemplar", txtExemplar.Text);
                cmd.Parameters.AddWithValue("ano_lancamento", mskDataLancamento.Text);
                cmd.Parameters.AddWithValue("cod_barras", txtCodigoDeBarras.Text);

                cmd.ExecuteNonQuery();

                MessageBox.Show("Livro cadastrado com sucesso!");

                Util.LimparCampos(this);
                txtTombo.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            finally
            {
                Conexao.Desconectar();
            }
        }