Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = Properties.Settings.Default.DB_TCM_OutturnConnectionString;
            conexao.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conexao;
            cmd.CommandText = "SELECT COD_FUNC FROM TB_TURMA WHERE NOME_TURMA = \'" + cmbNome_Turma.Text + "\';";
            cmd.CommandType = CommandType.Text;
            SqlDataReader DR;

            DR = cmd.ExecuteReader();
            while (DR.Read())
            {
                codigo_func = DR.GetValue(0).ToString();
            }
            conexao.Close();
            try
            {
                conexao.Open();
                using (SqlCommand comando = new SqlCommand("INSERT INTO TB_BOLETIM (COD_ALUNO, COD_FUNC, NOTA_PROVA_ESCRITA_1, NOTA_PROVA_ESCRITA_2, NOTA_PROVA_ESCRITA_3, NOTA_PROVA_ESCRITA_4, NOTA_PROVA_ORAL_1, NOTA_PROVA_ORAL_2, NOTA_PROVA_ORAL_3, NOTA_PROVA_ORAL_4, NOTA_PARTICIPACAO_1, NOTA_PARTICIPACAO_2) VALUES (" + codigo_aluno + ", " + codigo_func + ", " + txtEscrita1_Nota.Text + ", " + txtEscrita2_Nota.Text + ", " + txtEscrita3_Nota.Text + ", " + txtEscrita4_Nota.Text + ", " + txtOral1_Nota.Text + ", " + txtOral2_Nota.Text + ", " + txtOral4_Nota.Text + ", " + txtOral4_Nota.Text + ", " + txtParticipacao1_Nota.Text + ", " + txtParticipacao2_Nota.Text + ");", conexao))
                {
                    comando.ExecuteReader();
                    conexao.Close();
                    MessageBox.Show("Boletim registrado com sucesso!", "Sucesso!", MessageBoxButtons.OK);
                    ClearScreen();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        private void frm_alterafunc_Load(object sender, EventArgs e)
        {
            string        pesq = "SELECT * FROM TB_DADOS_LOG";
            SqlCommand    cmd  = new SqlCommand(pesq, DataBase.obterConexao());
            SqlDataReader DR;

            try
            {
                DataBase.obterConexao();
                DR = cmd.ExecuteReader();

                if (DR.Read())
                {
                    txt_pesquisa.Text = DR.GetValue(2).ToString();
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DataBase.fecharConexao();
            }
        }
Пример #3
0
        //Quando formulario é iniciado é selecionado o ultimo protocolo que foi adicionado no banco
        private void frm_Cadastro_Load(object sender, EventArgs e)
        {
            string        pesquisa = "SELECT * FROM TB_PROTOCOLO";
            SqlCommand    cmd      = new SqlCommand(pesquisa, DataBase.obterConexao());
            SqlDataReader DR;

            try
            {
                DataBase.obterConexao();
                DR = cmd.ExecuteReader();

                if (DR.Read())
                {
                    lbl_prot_ocult.Text = DR.GetValue(0).ToString();
                }
                else
                {
                    MessageBox.Show("Erro");
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DataBase.fecharConexao();
            }
        }
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            string        read = "SELECT (SELECT SUM(Monto) FROM Ingresos WHERE Empleado='" + this.cbxEmpleado.Text + "') - (SELECT SUM(Monto) FROM Deducciones WHERE Empleado='" + this.cbxEmpleado.Text + "')";
            SqlCommand    cmd  = new SqlCommand(read, conexao);
            SqlDataReader DR;

            try
            {
                conexao.Open();
                DR = cmd.ExecuteReader();
                if (DR.Read())
                {
                    txtSalario.Text = DR.GetValue(0).ToString();
                }

                else
                {
                    MessageBox.Show("Registro no encontrado.");
                    txtSalario.Clear();
                    cbxEmpleado.Focus();
                }
                DR.Close();
                cmd.Dispose();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                conexao.Close();
            }
        }
Пример #5
0
        private void txt_senha_Leave(object sender, EventArgs e)
        {
            DataBase.obterConexao();
            string        pesq = "SELECT * FROM TB_FUNCIONARIO WHERE SENHA= '" + txt_senha.Text + "'";
            SqlCommand    cmd  = new SqlCommand(pesq, DataBase.obterConexao());
            SqlDataReader DR;

            try
            {
                DataBase.obterConexao();
                DR = cmd.ExecuteReader();

                if (DR.Read())
                {
                    lbl_nome_log.Text = DR.GetValue(1).ToString();
                    lbl_sbre.Text     = DR.GetValue(2).ToString();
                    lbl_rg.Text       = DR.GetValue(3).ToString();
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DataBase.fecharConexao();
            }
        }
Пример #6
0
        private void btnPesquisar_Click(object sender, EventArgs e)
        {
            //instrução sql responsável por pesquisar o banco de dados (CRUD - Read)
            string     pesquisa = "select * from tbContatos where idContatos = " + txbId.Text;
            SqlCommand cmd      = new SqlCommand(pesquisa, conexao); //objeto responsável pelos comandos(querys) no sql.
            //criando objeto de nome cmd tendo como modelo a classe OleDbCommand para execultar  a instução  sql
            // OleDbCommand cmd = new OleDbCommand(pesquisa, conexao);
            // Atravé da classe OleDbDataReader que faz parte do SqlCliente, criamos uma //variável chamada DR que será usada na leitura dos dados (instrução select)

            SqlDataReader DR;

            //OleDbDataReader DR;
            //tratamento de exeções: try - catch - finally (em caso de erro de erro capturamos o erro)


            try
            {
                //abrindo conexão com o bando de dados
                conexao.Open();
                cmd.ExecuteNonQuery();             //Executa o cmd e pega todos os dados que buscamos com o nosso comando

                DataSet        ds = new DataSet(); //setar dados
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;            //adapta o cmd ao projeto
                da.Fill(ds);                       // preenche todas as informações dentro do DataSet
                //executando a instrução e armazenando o resultado do reader DR
                DR = cmd.ExecuteReader();
                if (DR.Read())
                {
                    txbId.Text       = DR.GetValue(0).ToString();
                    txbNome.Text     = DR.GetValue(1).ToString();
                    txbTelefone.Text = DR.GetValue(2).ToString();
                    txbEmail.Text    = DR.GetValue(3).ToString();
                }
                //Exibe as Informações nas caisas de texto(textBox) correspondente (#)
                //nova pesquisa
                else
                {
                    MessageBox.Show("Registro não encontrado");
                    txbNome.Text     = "";
                    txbTelefone.Text = "";
                    txbEmail.Text    = "";
                    txbId.Focus();
                }
                //encerrando o uso do Reader DR
                DR.Close();
                //encerra o cmd
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                //exibe o erro
                MessageBox.Show(ex.Message);
            }
            // de qualquer forma sempre fechar a conexão com o banco ("lembrar da porta da //geladeira rsrsrs")
            finally
            {
                conexao.Close();
            }
        }
Пример #7
0
        public string TransaccionEstudiante(string _procedimiento, string _cuenta, string _estudiante, string _identidad, int _carrera, string _telefono, string _correo, string _usuario)
        {
            try
            {
                Conexiones.Conexion conex = new Conexiones.Conexion();
                SqlCommand          vComando;
                SqlDataReader       DR;

                vComando             = new SqlCommand(_procedimiento, conex.crearConexion());
                vComando.CommandType = CommandType.StoredProcedure;
                vComando.Parameters.Add("@Cuenta", SqlDbType.VarChar).Value     = _cuenta;
                vComando.Parameters.Add("@Usuario", SqlDbType.VarChar).Value    = _usuario;
                vComando.Parameters.Add("@Estudiante", SqlDbType.VarChar).Value = _estudiante;
                vComando.Parameters.Add("@Identidad", SqlDbType.VarChar).Value  = _identidad;
                vComando.Parameters.Add("@Carrera", SqlDbType.Int).Value        = _carrera;
                vComando.Parameters.Add("@Telefono", SqlDbType.VarChar).Value   = _telefono;
                vComando.Parameters.Add("@Correo", SqlDbType.VarChar).Value     = _correo;
                DR = vComando.ExecuteReader();
                DR.Read();
                return(DR.GetValue(0).ToString());
            }
            catch (Exception)
            {
                return("2");
            }
        }
Пример #8
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            string pesquisa = "select * from tbUsuarios where Id= " + txtId.Text;

            SqlCommand    cmd = new SqlCommand(pesquisa, conexao);
            SqlDataReader DR;

            try
            {
                conexao.Open();
                DR = cmd.ExecuteReader();
                if (DR.Read())
                {
                    txtId.Text             = DR.GetValue(0).ToString();
                    txtLogin.Text          = DR.GetValue(1).ToString();
                    txtSenha.Text          = DR.GetValue(2).ToString();
                    cboPerfil.SelectedText = DR.GetValue(3).ToString();
                }
                else
                {
                    MessageBox.Show("Usuário e/ou senha inválido(s)");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conexao.Close();
            }
        }
Пример #9
0
        public string RegistrarPAA <template>(string _procedimiento, template _paa, string _inicioPaa, string _finalPaa, string _inicioInscripcion, string _finalInscripcion, int _cupos, string _usuario)
        {
            try
            {
                SqlCommand          vComando;
                Conexiones.Conexion conex = new Conexiones.Conexion();
                SqlDataReader       DR;
                vComando             = new SqlCommand(_procedimiento, conex.crearConexion());
                vComando.CommandType = CommandType.StoredProcedure;

                vComando.Parameters.Add("@CodigoPAA", SqlDbType.VarChar).Value     = _paa;
                vComando.Parameters.Add("@codigoUsuario", SqlDbType.VarChar).Value = _usuario;
                vComando.Parameters.Add("@fechaInicio", SqlDbType.VarChar).Value   = _inicioPaa;

                vComando.Parameters.Add("@fechaFinal", SqlDbType.VarChar).Value = _finalPaa;
                vComando.Parameters.Add("@fechaInicioInscripcionPAA", SqlDbType.VarChar).Value = _inicioInscripcion;
                vComando.Parameters.Add("@fechaFinalInscripcionPAA", SqlDbType.VarChar).Value  = _finalInscripcion;
                vComando.Parameters.Add("@Cupos", SqlDbType.Int).Value = _cupos;
                DR = vComando.ExecuteReader();
                DR.Read();
                return(DR.GetValue(0).ToString());
            }
            catch (Exception)
            {
                return("2");
            }
        }
        public void UpdateQuyen()
        {
            SqlCommand    query = new SqlCommand("select * from PhanQuyen where IdNhanVien ='" + fl.LoginTenND + "'", Ket_noi.connect);
            SqlDataReader DR;

            Ket_noi.connect.Open();
            DR = query.ExecuteReader();
            while (DR.Read() == true)
            {
                if (Convert.ToInt32(DR.GetValue(1).ToString()) == 0)
                {
                    fm.TabItem_2.Visible = false;
                }
                if (Convert.ToInt32(DR.GetValue(2).ToString()) == 0)
                {
                    fm.TabItem_3.Visible = false;
                }
                if (Convert.ToInt32(DR.GetValue(3).ToString()) == 0)
                {
                    fm.TabItem_4.Visible = false;
                }
                if (Convert.ToInt32(DR.GetValue(4).ToString()) == 0)
                {
                    fm.TabItem_5.Visible = false;
                }
                if (Convert.ToInt32(DR.GetValue(5).ToString()) == 0)
                {
                    fm.TabItem_6.Visible = false;
                }
            }
            Ket_noi.connect.Close();
        }
Пример #11
0
        //Quando formulario é iniciado é selecionado o ultimo protocolo que foi adicionado no banco
        //Quando formulário é iniciado seleciona o usuario logado
        private void frm_Serviços_Load(object sender, EventArgs e)
        {
            //PROTOCOLO
            string        pesquisa = "SELECT * FROM TB_PROTOCOLO";
            SqlCommand    cmd      = new SqlCommand(pesquisa, DataBase.obterConexao());
            SqlDataReader DR;

            try
            {
                DataBase.obterConexao();
                DR = cmd.ExecuteReader();

                if (DR.Read())
                {
                    lbl_prot_ocult.Text = DR.GetValue(0).ToString();
                }
                else
                {
                    MessageBox.Show("Erro para pegar o valor do protocolo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DataBase.fecharConexao();
            }

            //USUARIO
            string        pesq = "SELECT * FROM TB_DADOS_LOG";
            SqlCommand    cmd2 = new SqlCommand(pesq, DataBase.obterConexao());
            SqlDataReader DR2;

            try
            {
                DataBase.obterConexao();
                DR2 = cmd2.ExecuteReader();

                if (DR2.Read())
                {
                    txt_rg_func.Text          = DR2.GetValue(2).ToString();
                    lbl_exp_nome_func.Text    = DR2.GetValue(0).ToString();
                    lbl_exp_sbrnome_func.Text = DR2.GetValue(1).ToString();
                }
                DR2.Close();
                cmd2.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DataBase.fecharConexao();
            }
        }
Пример #12
0
        private void btnPesquisar_Click(object sender, EventArgs e)
        {
            if (txtId.Text == "")
            {
                MessageBox.Show("Valor Nulo! Digite um Id para pesquisar");
            }
            //instrução sql responsável por pesquisar o banco de dados (CRUD - Read)
            string pesquisa = "select * from tbcontato where Id = " + txtId.Text;

            //criando um objeto de nome cmd tendo como modelo a classe OleDbCommand para executar a instrução sql
            OleDbCommand cmd = new OleDbCommand(pesquisa, conexao);

            // Atravé da classe OleDbDataReader que faz parte do SqlCliente, criamos uma //variável chamada DR que será usada na leitura dos dados (instrução select)
            OleDbDataReader DR;

            //tratamento de exceções: try - catch - finally (em caso de erro capturamos o //tipo do erro)

            try
            {
                // Abrindo a conexão com o banco
                conexao.Open();
                // Executando a instrução e armazenando o resultado no reader DR
                DR = cmd.ExecuteReader();
                // Se houver um registro correspondente ao Id
                if (DR.Read())
                {
                    // Exibe as informações nas caixas de texto (textBox) correspondentes (0) //corresponde ao Id, (1) ao Nome e assim sucessivamente
                    txtId.Text    = DR.GetValue(0).ToString();
                    txtNome.Text  = DR.GetValue(1).ToString();
                    txtFone.Text  = DR.GetValue(2).ToString();
                    txtEmail.Text = DR.GetValue(3).ToString();
                }
                // Senão, exibimos uma mensagem avisando e também limpamos os campos para uma //nova pesquisa
                else
                {
                    MessageBox.Show("Registro não encontrado");
                    txtNome.Clear();
                    txtFone.Clear();
                    txtEmail.Clear();
                    txtId.Focus();
                } // Encerrando o uso do reader DR
                DR.Close();

                // Encerrando o uso do cmd
                cmd.Dispose();
            }

            //caso ocorra algum erro

            catch (Exception ex)
            {
            }

            // de qualquer forma sempre fechar a conexão com o banco ("lembrar da porta da //geladeira rsrsrs")
            finally
            {
                conexao.Close();
            }
        }
Пример #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            if ((textBox1.Text == String.Empty) || (textBox2.Text == String.Empty))
            {
                MessageBox.Show("É obrigatório o preenchimento dos campos Usuário e Senha", "Atenção !", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Uso de Parâmetros para seleção de usuário e senha do banco de dados
                // @Nome do campo da tabela
                string pesquisa = "select * from tbUsuarios where Login=@Login and Senha=@Senha";

                SqlCommand cmd = new SqlCommand(pesquisa, conexao);
                // Captura dos parâmetros
                // @Login recebe o valor
                cmd.Parameters.AddWithValue("@Login", textBox1.Text);
                cmd.Parameters.AddWithValue("@Senha", textBox2.Text);
                SqlDataReader DR;
                try
                {
                    conexao.Open();
                    DR = cmd.ExecuteReader();
                    if (DR.Read())
                    {
                        string perfil = DR.GetValue(3).ToString();
                        if (perfil == "admin")
                        {
                            Form2 principal = new Form2();
                            principal.Show();
                            principal.label1.Text      = "Administrador";
                            principal.panel1.BackColor = Color.DarkRed;
                        }
                        else
                        {
                            Form2 principal = new Form2();
                            principal.Show();
                            principal.label1.Text      = "Usuário";
                            principal.button1.Enabled  = false;
                            principal.panel1.BackColor = Color.Blue;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Usuário e/ou Senha Inválido(s)");
                    }
                }
                //caso ocorra algum erro
                catch (Exception ex)
                {
                    //exiba qual é o erro
                    MessageBox.Show(ex.Message);
                }
                // de qualquer forma sempre fechar a conexão com o banco ("lembrar da porta da geladeira rsrsrs")
                finally
                {
                    conexao.Close();
                }
            }
        }
Пример #14
0
        private void pdc_imprimir_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            {
                int X = 50;
                int Y = 50;

                Font minhafonte = new Font("Arial", 14, FontStyle.Bold);
                e.Graphics.DrawString(this.Text, minhafonte, Brushes.Blue, X, Y);
                e.Graphics.DrawString(DateTime.Now.ToString(), minhafonte, Brushes.Blue, X + 500, Y);
                minhafonte = new Font("Arial", 12, FontStyle.Bold);

                Y = Y + 100;
                e.Graphics.DrawString("Numero de vendas", minhafonte, Brushes.Black, X, Y);
                e.Graphics.DrawString("Itens", minhafonte, Brushes.Black, X + 250, Y);
                e.Graphics.DrawString("Faturamento", minhafonte, Brushes.Black, X + 400, Y);
                e.Graphics.DrawString("Total", minhafonte, Brushes.Black, X + 650, Y);

                minhafonte = new Font("Arial", 12, FontStyle.Regular);

                string consulta = "SELECT * FROM tb_pedidos where status = 'Entregue'";

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = consulta;
                cmd.CommandType = CommandType.Text;
                cmd.Connection  = Conexao.abreConexao();

                MySqlDataReader DR;

                try
                {
                    DR = cmd.ExecuteReader();

                    while (DR.Read())
                    {
                        Y = Y + 30;
                        // decimal valorTotal = Convert.ToDecimal(DR.GetValue(7)) * Convert.ToDecimal(DR.GetValue(7));
                        e.Graphics.DrawString(DR.GetValue(3).ToString(), minhafonte, Brushes.Black, X, Y);
                        e.Graphics.DrawString(DR.GetValue(4).ToString(), minhafonte, Brushes.Black, X + 250, Y);
                        e.Graphics.DrawString(DR.GetValue(7).ToString(), minhafonte, Brushes.Black, X + 400, Y);
                        e.Graphics.DrawString(DR.GetValue(8).ToString(), minhafonte, Brushes.Black, X + 650, Y);
                        // e.Graphics.DrawString(valorTotal.ToString(), minhafonte, Brushes.Black, X + 650, Y);
                    }
                    DR.Close();
                    cmd.Dispose();
                }


                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    Conexao.fechaConexao();
                }
            }
        }
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            Con.Close();
            String Username = txtUsername.Text;
            String Password = GetEncryptionMd5.MD5Process(txtPassword.Password.Trim());

            Cmd = new SqlCommand("Select * From tblUsers Where EmailId='" + Username + "' " +
                                 "or ContactNumber='" + Username + "' and Password='******' ", Con);
            Con.Open();
            SqlDataReader DR;

            DR = Cmd.ExecuteReader();

            if (DR.HasRows)
            {
                DR.Read();
                if ((Username == DR.GetValue(3).ToString() && Password == DR.GetValue(6).ToString()) ||
                    (Username == DR.GetValue(4).ToString() && Password == DR.GetValue(6).ToString())
                    )
                {
                    txtUsername.Text       = "Email Or Contact No.";
                    txtUsername.Foreground = Brushes.DarkGray;
                    txtPassword.Password   = "";
                    string Role = "A=Admin, L= Librarian";
                    Role = DR.GetValue(5).ToString().Trim();

                    if (Role == "A" || Role == "a" || Role == "L" || Role == "l")
                    {
                        //User Is Admin
                        AdminHomePage adminHomePage = new AdminHomePage(int.Parse(DR.GetValue(0).ToString()), DR.GetValue(3).ToString());
                        adminHomePage.Show();
                        this.Close();
                    }
                    else
                    {
                        return;
                    }
                    lblInvalid.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblInvalid.Visibility = Visibility.Visible;
                    lblInvalid.Content    = "Invalid Password!";
                    txtPassword.Password  = "";
                }
            }
            else
            {
                //User Does Not Exists!
                lblInvalid.Content     = "User Does Not Exists!";
                lblInvalid.Visibility  = Visibility.Visible;
                txtUsername.Text       = "Email Or Contact No.";
                txtUsername.Foreground = Brushes.DarkGray;
                txtPassword.Password   = "";
            }
        }
Пример #16
0
        private void pdcImprimir_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            int X = 50;
            int Y = 50;

            Font minhafonte = new Font("Arial", 14, FontStyle.Bold);

            e.Graphics.DrawString(this.Text, minhafonte, Brushes.Blue, X, Y);
            e.Graphics.DrawString(DateTime.Now.ToString(), minhafonte, Brushes.Blue, X + 500, Y);
            minhafonte = new Font("Arial", 12, FontStyle.Bold);

            Y = Y + 100;
            e.Graphics.DrawString("Cliente dos Clientes", minhafonte, Brushes.Black, X, Y);
            e.Graphics.DrawString("Nome dos Clientes", minhafonte, Brushes.Black, X + 250, Y);
            e.Graphics.DrawString("Sexo dos Clientes", minhafonte, Brushes.Black, X + 500, Y);

            minhafonte = new Font("Arial", 12, FontStyle.Regular);

            string consulta = "SELECT * FROM Clientes";

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = consulta;
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = Conexao.abreConexao();

            MySqlDataReader DR;

            try
            {
                DR = cmd.ExecuteReader();

                while (DR.Read())
                {
                    Y = Y + 30;
                    e.Graphics.DrawString(DR.GetValue(0).ToString(), minhafonte, Brushes.Black, X, Y);
                    e.Graphics.DrawString(DR.GetValue(1).ToString(), minhafonte, Brushes.Black, X + 250, Y);
                    e.Graphics.DrawString(DR.GetValue(2).ToString(), minhafonte, Brushes.Black, X + 500, Y);
                }
                DR.Close();
                cmd.Dispose();
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Conexao.fechaConexao();
            }
        }
        private void LoadQuyen()
        {
            if (fl.LoginLoaiND == "Quan_Ly" || fl.LoginLoaiND == "Admin")
            {
                grb_PhanQuyen.Enabled = true;
            }
            else
            {
                grb_PhanQuyen.Enabled = false;
                btn_DongY.Enabled     = false;
            }
            txt_IdNhanVien.Text = fm.cbo_Username.Text;

            SqlCommand    query = new SqlCommand("select * from PhanQuyen where IdNhanVien ='" + fm.cbo_Username.Text + "'", Ket_noi.connect);
            SqlDataReader DR;

            try
            {
                Ket_noi.connect.Open();
                DR = query.ExecuteReader();
                while (DR.Read() == true)
                {
                    if (Convert.ToInt32(DR.GetValue(1).ToString()) == 1)
                    {
                        ckb_xe.Checked = true;
                    }
                    if (Convert.ToInt32(DR.GetValue(2).ToString()) == 1)
                    {
                        ckb_tuyen.Checked = true;
                    }
                    if (Convert.ToInt32(DR.GetValue(3).ToString()) == 1)
                    {
                        ckb_ThoiDiem.Checked = true;
                    }
                    if (Convert.ToInt32(DR.GetValue(4).ToString()) == 1)
                    {
                        ckb_chuyenXe.Checked = true;
                    }
                    if (Convert.ToInt32(DR.GetValue(5).ToString()) == 1)
                    {
                        ckb_banve.Checked = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Ket_noi.connect.Close();
            }
        }
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            string        read = "select * from Ingresos where Nombre='" + this.txtNombre.Text + "'";
            SqlCommand    cmd  = new SqlCommand(read, conexao);
            SqlDataReader DR;

            try
            {
                conexao.Open();
                DR = cmd.ExecuteReader();
                if (DR.Read())
                {
                    txtID.Text             = DR.GetValue(0).ToString();
                    txtNombre.Text         = DR.GetValue(1).ToString();
                    cbxEmpleado.Text       = DR.GetValue(2).ToString();
                    cbxIngreso.Text        = DR.GetValue(3).ToString();
                    cbxDependeSalario.Text = DR.GetValue(4).ToString();
                    cbxEstado.Text         = DR.GetValue(5).ToString();
                    txtFecha.Text          = DR.GetValue(6).ToString();
                    txtMonto.Text          = DR.GetValue(7).ToString();
                }
                else
                {
                    MessageBox.Show("Registro no encontrado.");
                    txtNombre.Clear();
                    cbxEmpleado.SelectedItem       = null;
                    cbxIngreso.SelectedItem        = null;
                    cbxDependeSalario.SelectedItem = null;
                    cbxEstado.SelectedItem         = null;
                    txtMonto.Clear();
                    txtNombre.Focus();
                }
                DR.Close();
                cmd.Dispose();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                conexao.Close();
            }
        }
Пример #19
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = Properties.Settings.Default.DB_TCM_OutturnConnectionString;
            try
            {
                conexao.Open();
                SqlCommand comando = new SqlCommand();
                comando.CommandText = "SELECT USUARIO, SENHA FROM TB_LOGAR WHERE USUARIO = \'" + txtUsuario.Text + "\'";
                comando.CommandType = CommandType.Text;
                comando.Connection  = conexao;
                SqlDataReader DR;
                DR = comando.ExecuteReader();
                if (DR.HasRows)
                {
                    while (DR.Read())
                    {
                        if (DR.GetValue(1).ToString() == txtSenha.Text)
                        {
                            this.Hide();
                            var tela_principal = new Tela_Principal(txtUsuario.Text);
                            tela_principal.Closed += (s, args) => this.Close();
                            tela_principal.Show();
                        }

                        if (DR.GetValue(1).ToString() != txtSenha.Text)
                        {
                            MessageBox.Show("Senha incorreta", "Aviso");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Usuario ou senha incorretos", "Aviso");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
        }
Пример #20
0
 public string RegistrarEmpleado(string _procedimiento, int _codigoEmpleado, string _nombreEmpleado, string _identidadEmpleado, string _usuario)
 {
     try
     {
         SqlCommand          vComando;
         Conexiones.Conexion conex = new Conexiones.Conexion();
         SqlDataReader       DR;
         vComando             = new SqlCommand(_procedimiento, conex.crearConexion());
         vComando.CommandType = CommandType.StoredProcedure;
         vComando.Parameters.Add("@CodigoEmpleado", SqlDbType.Int).Value    = _codigoEmpleado;
         vComando.Parameters.Add("@Nombre", SqlDbType.VarChar).Value        = _nombreEmpleado;
         vComando.Parameters.Add("@Identidad", SqlDbType.VarChar).Value     = _identidadEmpleado;
         vComando.Parameters.Add("@CodigoUsuario", SqlDbType.VarChar).Value = _usuario;
         DR = vComando.ExecuteReader();
         DR.Read();
         return(DR.GetValue(0).ToString());
     }
     catch (Exception)
     {
         return("2");
     }
 }
Пример #21
0
        public string RegistrarAsistencia <template>(string _procedimiento, template _cuenta, string _usuario)//Agregue instancia Usuario
        {
            try
            {
                SqlCommand          vComando;
                Conexiones.Conexion conex = new Conexiones.Conexion();
                SqlDataReader       DR;
                vComando             = new SqlCommand(_procedimiento, conex.crearConexion());
                vComando.CommandType = CommandType.StoredProcedure;

                vComando.Parameters.Add("@Cuenta", System.Data.SqlDbType.VarChar).Value = _cuenta;
                vComando.Parameters.Add("@Usuario", SqlDbType.VarChar).Value            = _usuario;
                DR = vComando.ExecuteReader();
                DR.Read();
                return(DR.GetValue(0).ToString());
            }

            catch (Exception)
            {
                return("3");
            }
        }
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            string        read = "select * from Riesgos where Nombre='" + this.txtNombre.Text + "'";
            SqlCommand    cmd  = new SqlCommand(read, conexao);
            SqlDataReader DR;

            try
            {
                conexao.Open();
                DR = cmd.ExecuteReader();
                if (DR.Read())
                {
                    txtID.Text          = DR.GetValue(0).ToString();
                    txtNombre.Text      = DR.GetValue(1).ToString();
                    txtDescripcion.Text = DR.GetValue(2).ToString();
                }
                else
                {
                    MessageBox.Show("Registro no encontrado.");
                    txtID.Clear();
                    txtNombre.Clear();
                    txtDescripcion.Clear();
                    txtID.Focus();
                }
                DR.Close();
                cmd.Dispose();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                conexao.Close();
            }
        }
Пример #23
0
        public string _Mtd_Correlativo(string _Pr_Str_Sql)
        {
            string _Str_R = "0";

            System.Data.SqlClient.SqlDataReader DR;
            DR = _Cls_Conexion._Mtd_Conexion_()._Mtd_RetornarDatareader(_Pr_Str_Sql);
            if (DR.HasRows)
            {
                while (DR.Read())
                {
                    if (DR.IsDBNull(0) == false)
                    {
                        _Str_R = Convert.ToString(Convert.ToInt32(DR.GetValue(0)) + 1);
                    }
                    else
                    {
                        _Str_R = "1";
                    }
                }
            }
            DR.Close();
            return(_Str_R);
        }
Пример #24
0
 public string RegistrarUsuario(string _procedimiento, string _codigoUsuario, string _password, int _codigoEmpleado, int _tipoAcceso, string _usuario)
 {
     try
     {
         SqlCommand          vComando;
         Conexiones.Conexion conex = new Conexiones.Conexion();
         SqlDataReader       DR;
         vComando             = new SqlCommand(_procedimiento, conex.crearConexion());
         vComando.CommandType = CommandType.StoredProcedure;
         vComando.Parameters.Add("@CodigoUsuario2", SqlDbType.VarChar).Value = _codigoUsuario;
         vComando.Parameters.Add("@Password", SqlDbType.VarChar).Value       = _password;
         vComando.Parameters.Add("@CodigoEmpleado", SqlDbType.Int).Value     = _codigoEmpleado;
         vComando.Parameters.Add("@TipoAcceso", SqlDbType.TinyInt).Value     = _tipoAcceso;
         vComando.Parameters.Add("@codigoUsuario", SqlDbType.VarChar).Value  = _usuario;
         DR = vComando.ExecuteReader();
         DR.Read();
         return(DR.GetValue(0).ToString());
     }
     catch (Exception)
     {
         return("2");
     }
 }
Пример #25
0
        private void btnPesquisa_Click(object sender, EventArgs e)
        {
            string        pesquisa = "select * from tbcontatos where Id = " + txtID.Text;
            SqlCommand    cmd      = new SqlCommand(pesquisa, conexao);
            SqlDataReader DR;

            try
            {
                conexao.Open();
                DR = cmd.ExecuteReader();
                if (DR.Read())
                {
                    txtID.Text       = DR.GetValue(0).ToString();
                    txtNome.Text     = DR.GetValue(1).ToString();
                    txtTelefone.Text = DR.GetValue(2).ToString();
                    txtEmail.Text    = DR.GetValue(3).ToString();
                }
                else
                {
                    MessageBox.Show("Registro não encontrado");
                    txtNome.Clear();
                    txtTelefone.Clear();
                    txtEmail.Clear();
                    txtID.Focus();
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conexao.Close();
            }
        }
Пример #26
0
        private void btnPesquisar_Click(object sender, EventArgs e)
        {
            string pesquisa = "select * from tb_AC_cliente_02 where cpf = @CPF";


            SqlCommand cmd = new SqlCommand(pesquisa, conexao);

            cmd.Parameters.AddWithValue("@CPF", txtCPF.Text.Replace(".", "").Replace("-", "").Trim());

            SqlDataReader DR;

            try
            {
                conexao.Open();

                DR = cmd.ExecuteReader();

                if (DR.Read())
                {
                    txtCPF.Text         = DR.GetValue(0).ToString();
                    txtNome.Text        = DR.GetValue(1).ToString();
                    txtTelefone.Text    = DR.GetValue(2).ToString();
                    txtEmail.Text       = DR.GetValue(3).ToString();
                    txtCEP.Text         = DR.GetValue(4).ToString();
                    txtLogradouro.Text  = DR.GetValue(5).ToString();
                    txtComplemento.Text = DR.GetValue(6).ToString();
                    txtBairro.Text      = DR.GetValue(7).ToString();
                    txtUF.Text          = DR.GetValue(8).ToString();
                    if (DR.GetValue(9).ToString() == "naotem")
                    {
                        pcbUsuario.Image = null;
                    }
                    else
                    {
                        pcbUsuario.Load(@"./images_db/" + DR.GetValue(9).ToString());
                    }
                }

                else
                {
                    MessageBox.Show("Cliente não encontrado.");
                    txtNome.Clear();
                    txtEmail.Clear();
                    txtTelefone.Clear();
                    txtBairro.Clear();
                    txtCEP.Clear();
                    txtUF.Clear();
                    txtLogradouro.Clear();
                    txtComplemento.Clear();
                    pcbUsuario.Image = null;
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                MessageBox.Show("Ocorreu um erro durante o processo. Tente novamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            finally
            {
                conexao.Close();
            }
        }
Пример #27
0
        private void btn_pesquisa_Click(object sender, EventArgs e)
        {
            DialogResult d1 = MessageBox.Show("Quer alterar a senha?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (d1 == DialogResult.Yes)
            {
                label12.Visible     = true;
                txt_confS.Text      = "";
                txt_confS.Visible   = true;
                label10.Visible     = true;
                txt_senha.Visible   = true;
                btn_trocSen.Enabled = true;
                txt_confS.Focus();
                MessageBox.Show("Confirme sua senha atual e pressione Trocar Senha", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Se desejar Trocar sua Senha, pesquise o RG novamente", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            string        pesquisa = "SELECT * FROM TB_FUNCIONARIO WHERE RG= " + txt_pesquisa.Text + "";
            SqlCommand    cmd      = new SqlCommand(pesquisa, conexao);
            SqlDataReader DR;

            try
            {
                conexao.Open();
                DR = cmd.ExecuteReader();
                if (DR.Read())
                {
                    txt_nome.Text     = DR.GetValue(1).ToString();
                    txt_sbr.Text      = DR.GetValue(2).ToString();
                    txt_rg.Text       = DR.GetValue(3).ToString();
                    txt_cpf.Text      = DR.GetValue(4).ToString();
                    txt_bairro.Text   = DR.GetValue(5).ToString();
                    txt_rua.Text      = DR.GetValue(6).ToString();
                    txt_num.Text      = DR.GetValue(7).ToString();
                    txt_compl.Text    = DR.GetValue(8).ToString();
                    txt_telefone.Text = DR.GetValue(9).ToString();
                    txt_login.Text    = DR.GetValue(10).ToString();
                    txt_senha.Text    = DR.GetValue(11).ToString();
                    if (d1 == DialogResult.Yes)
                    {
                        btn_alterar.Enabled = false;
                    }
                    else
                    {
                        btn_alterar.Enabled = true;
                    }
                    btn_limpar.Enabled = true;
                }

                else
                {
                    MessageBox.Show("Registro não encontrado");
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conexao.Close();
            }
        }
Пример #28
0
        private void btn_pesquisar_Click_1(object sender, EventArgs e)
        {
            //PESQUISA DO DONO PELO SEU RG
            if (txt_rgDono.Text != "")
            {
                //Pesquisando Dono
                string        pesquisa = "SELECT * FROM TB_DONO WHERE RG = '" + txt_rgDono.Text + "'";
                SqlCommand    cmd      = new SqlCommand(pesquisa, DataBase.obterConexao());
                SqlDataReader DR;

                try
                {
                    DataBase.obterConexao();
                    DR = cmd.ExecuteReader();

                    if (DR.Read())
                    {
                        //Campos do Dono
                        txt_nome_dono.Text   = DR.GetValue(1).ToString();
                        txt_sobrenome.Text   = DR.GetValue(2).ToString();
                        txt_bairro.Text      = DR.GetValue(3).ToString();
                        txt_rua.Text         = DR.GetValue(4).ToString();
                        txt_num.Text         = DR.GetValue(5).ToString();
                        txt_complemento.Text = DR.GetValue(6).ToString();
                        txt_rg.Text          = DR.GetValue(7).ToString();
                        txt_telefone.Text    = DR.GetValue(8).ToString();

                        //Exibições dos botões
                        btn_cadastrar.Visible = false;
                        btn_cna.Visible       = true;
                        btn_alterar.Enabled   = true;
                        btn_excluir.Enabled   = true;

                        //Limpando Dados do Animal caso tem ocorrido alguma pesquisa anteriormente pelo protocolo
                        txt_animal.Text           = "";
                        lbl_exp_protocolo.Text    = "";
                        lbl_exp_protocolo.Visible = false;
                        cbo_esp.Text             = "";
                        cbo_raca.Text            = "";
                        txt_data_nascimento.Text = "";
                        cbo_vacinado.Text        = "";
                        cbo_castrado.Text        = "";
                        cbo_port.Text            = "";
                    }
                    else
                    {
                        MessageBox.Show("Registros do Dono não encontrados", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        //Limpando o objeto da pesquisa (txt_rgDono)
                        txt_rgDono.Text = "";

                        //Voltanco ao foco incial (Objeto txt_nome_dono)
                        txt_nome_dono.Focus();
                    }
                    DR.Close();
                    cmd.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    DataBase.fecharConexao();
                }
            }

            //PESQUISA DO ANIMAL PELO SEU PROTOCOLO
            if (txt_protocolo.Text != "")
            {
                //Pesquisando Animal
                string        pesquisa = "SELECT * FROM TB_ANIMAL WHERE PROTOCOLO_ANIMAL = '" + txt_protocolo.Text + "'";
                SqlCommand    cmd2     = new SqlCommand(pesquisa, DataBase.obterConexao());
                SqlDataReader DR2;

                try
                {
                    DataBase.obterConexao();
                    DR2 = cmd2.ExecuteReader();

                    if (DR2.Read())
                    {
                        //Campos do Animal
                        txt_animal.Text          = DR2["NOME_ANIMAL"].ToString();
                        lbl_protocolo.Visible    = false;
                        cbo_esp.Text             = DR2["ESPECIE"].ToString();
                        cbo_raca.Text            = DR2["RACA"].ToString();
                        cbo_vacinado.Text        = DR2["VACINADO"].ToString();
                        cbo_castrado.Text        = DR2["CASTRADO"].ToString();
                        txt_data_nascimento.Text = DR2["DATA_NASCIMENTO"].ToString();
                        cbo_port.Text            = DR2["PORTE"].ToString();

                        //Exibições dos botões
                        btn_cadastrar.Visible = false;
                        btn_cna.Visible       = false;
                        btn_alterar.Enabled   = true;
                        btn_excluir.Enabled   = true;
                    }
                    else
                    {
                        MessageBox.Show("Registros do Animal não encontrados", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        //Limpando o objeto da pesquisa (txt_protocolo)
                        txt_protocolo.Text = "";

                        //Voltanco ao foco incial (Objeto txt_nome_dono)
                        txt_nome_dono.Focus();
                    }
                    DR2.Close();
                    cmd2.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    DataBase.fecharConexao();
                }
            }

            else if (txt_rgDono.Text == "" && txt_protocolo.Text == "")
            {
                txt_rgDono.Focus();
                MessageBox.Show("Por favor, informe o RG do Dono ou o Protocolo do Animal", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #29
0
        private void btn_pesquisa_Click_1(object sender, EventArgs e)
        {
            DialogResult d1 = MessageBox.Show("Quer alterar a senha?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (d1 == DialogResult.Yes)
            {
                //Deixando os demais objetos de Dados Invisiveis
                label1.Visible       = false;
                txt_nome.Visible     = false;
                label2.Visible       = false;
                txt_sbr.Visible      = false;
                label3.Visible       = false;
                txt_rg.Visible       = false;
                label4.Visible       = false;
                txt_cpf.Visible      = false;
                label5.Visible       = false;
                txt_bairro.Visible   = false;
                label6.Visible       = false;
                txt_rua.Visible      = false;
                label7.Visible       = false;
                txt_num.Visible      = false;
                label8.Visible       = false;
                txt_compl.Visible    = false;
                label9.Visible       = false;
                txt_login.Visible    = false;
                label13.Visible      = false;
                txt_telefone.Visible = false;
                label11.Visible      = true;

                //Deixando os objetos da Senha Visiveis
                label10.Visible   = true;
                txt_senha.Text    = ""; //Limpando o campo para não haver indicios da pesquisa anterior
                txt_senha.Visible = true;

                label12.Visible   = true;
                txt_confS.Text    = ""; //Limpando o campo para não haver indicios da pesquisa anterior
                txt_confS.Visible = true;

                btn_trocSen.Enabled = true;
                txt_confS.Focus();
                MessageBox.Show("Confirme sua senha atual e pressione Trocar Senha", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //Limpando os objetos (TextBox) caso ja tenha ocorrido uma pesquisa anteriormente
                txt_nome.Text     = "";
                txt_sbr.Text      = "";
                txt_rg.Text       = "";
                txt_cpf.Text      = "";
                txt_bairro.Text   = "";
                txt_rua.Text      = "";
                txt_num.Text      = "";
                txt_compl.Text    = "";
                txt_login.Text    = "";
                txt_telefone.Text = "";

                //Deixando os demais objetos de Dados Visiveis
                label1.Visible       = true;
                txt_nome.Visible     = true;
                label2.Visible       = true;
                txt_sbr.Visible      = true;
                label3.Visible       = true;
                txt_rg.Visible       = true;
                label4.Visible       = true;
                txt_cpf.Visible      = true;
                label5.Visible       = true;
                txt_bairro.Visible   = true;
                label6.Visible       = true;
                txt_rua.Visible      = true;
                label7.Visible       = true;
                txt_num.Visible      = true;
                label8.Visible       = true;
                txt_compl.Visible    = true;
                label9.Visible       = true;
                txt_login.Visible    = true;
                label13.Visible      = true;
                txt_telefone.Visible = true;
                label11.Visible      = true;

                //Deixando os objetos da Senha Invisiveis
                label12.Visible     = false;
                txt_confS.Visible   = false;
                label10.Visible     = false;
                txt_senha.Visible   = false;
                btn_trocSen.Enabled = false;
                txt_nome.Focus();
            }

            string        pesquisa = "SELECT * FROM TB_FUNCIONARIO WHERE RG= '" + txt_pesquisa.Text + "'";
            SqlCommand    cmd      = new SqlCommand(pesquisa, DataBase.obterConexao());
            SqlDataReader DR;

            try
            {
                DataBase.obterConexao();
                DR = cmd.ExecuteReader();

                if (DR.Read())
                {
                    txt_nome.Text     = DR.GetValue(1).ToString();
                    txt_sbr.Text      = DR.GetValue(2).ToString();
                    txt_rg.Text       = DR.GetValue(3).ToString();
                    txt_cpf.Text      = DR.GetValue(4).ToString();
                    txt_bairro.Text   = DR.GetValue(5).ToString();
                    txt_rua.Text      = DR.GetValue(6).ToString();
                    txt_num.Text      = DR.GetValue(7).ToString();
                    txt_compl.Text    = DR.GetValue(8).ToString();
                    txt_telefone.Text = DR.GetValue(9).ToString();
                    txt_login.Text    = DR.GetValue(10).ToString();
                    txt_senha.Text    = DR.GetValue(11).ToString();
                    if (d1 == DialogResult.Yes)
                    {
                        btn_alterar.Enabled = false;
                        btn_excluir.Enabled = false;
                    }
                    else
                    {
                        btn_alterar.Enabled = true;
                        btn_excluir.Enabled = true;
                    }
                    btn_limpar.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Registro não encontrado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    //Deixando os objetos invisiveis
                    label1.Visible       = false;
                    txt_nome.Visible     = false;
                    label2.Visible       = false;
                    txt_sbr.Visible      = false;
                    label3.Visible       = false;
                    txt_rg.Visible       = false;
                    label4.Visible       = false;
                    txt_cpf.Visible      = false;
                    label5.Visible       = false;
                    txt_bairro.Visible   = false;
                    label6.Visible       = false;
                    txt_rua.Visible      = false;
                    label7.Visible       = false;
                    txt_num.Visible      = false;
                    label8.Visible       = false;
                    txt_compl.Visible    = false;
                    label9.Visible       = false;
                    txt_login.Visible    = false;
                    label13.Visible      = false;
                    txt_telefone.Visible = false;
                    label11.Visible      = false;

                    //Deixando txt_pesquisa em branco
                    txt_pesquisa.Text = "";

                    //Dando faco no TextView pesqisar
                    txt_pesquisa.Focus();
                    btn_alterar.Enabled = false;
                    btn_excluir.Enabled = false;
                    btn_limpar.Enabled  = false;
                }
                DR.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DataBase.fecharConexao();
            }
        }
Пример #30
0
        private void btnPesquisar_Click(object sender, EventArgs e)
        {
            // instrução pesquisa
            string pesquisa = "select * from Clientes where Id = " + txbId.Text;

            // criando um objeto de nome cmd
            OleDbCommand cmd = new OleDbCommand(pesquisa, conexao);

            // Atravé da classe OleDbDataReader
            OleDbDataReader DR;

            // tratamento de excecões

            try
            {
                // Abrindo conexão
                conexao.Open();
                // Executando a instrução e armazenando o resultado no DR
                DR = cmd.ExecuteReader();
                // Se houver um registro corresponde ao Id
                if (DR.Read())
                {
                    // exibe  as informações nas caixar de texto
                    txbId.Text       = DR.GetValue(0).ToString();
                    txbNome.Text     = DR.GetValue(1).ToString();
                    txbEndereco.Text = DR.GetValue(2).ToString();
                    txbRg.Text       = DR.GetValue(3).ToString();
                    txbCPF.Text      = DR.GetValue(4).ToString();
                    txbCidade.Text   = DR.GetValue(5).ToString();
                    txbEstado.Text   = DR.GetValue(6).ToString();
                    txbSalario.Text  = DR.GetValue(7).ToString();

                    double salario = Convert.ToDouble(txbSalario.Text);
                    double salario_liq;

                    salario_liq = salario - ((salario * 26) / 100);
                    salario_liq = salario_liq + 450;


                    MessageBox.Show("Nome: " + txbNome.Text + "\n" + "Endereco: " + txbEndereco.Text + "\n" + "Rg: " + txbRg.Text + "\n" + "CPF: " + txbCPF.Text + "\n" + "Cidade: " + txbCidade.Text + "\n" + "Estado: " + txbEstado.Text + "\n" + "Salario bruto:R$ " + salario + "\n" + "Salario liquido:R$ " + salario_liq);
                }

                else
                {
                    MessageBox.Show("Registro não encontrado");
                    txbId.Clear();
                    txbNome.Clear();
                    txbEndereco.Clear();
                    txbRg.Clear();
                    txbCPF.Clear();
                    txbCidade.Clear();
                    txbEstado.Clear();
                    txbId.Focus();
                }
                // Encerrando o uso do reader
                DR.Close();
                // Encerrando o uso do cmd
                cmd.Dispose();
            }

            //caso ocorra algum erro
            catch (Exception ex)
            {
                //exiba qual é o erro
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conexao.Close();
            }
        }