示例#1
0
        public void Load_DGV()
        {
            string usuario = "select  LOGIN_ID as ID,   LOGIN_CONSULTOR, LOGIN_NOME_FUNCIONARIO as NOME,LOGIN_USUARIO, LOGIN_PERFIL, LOGIN_EMAIL  from login";



            //usando a classe de conexao
            ConexaoBanco connection = new ConexaoBanco();

            connection.ConexaoString();

            DateTime   d1      = DateTime.Now;
            SqlCommand command = new SqlCommand(usuario);

            command.Connection = ConexaoBanco.conn;

            DataTable dt = new DataTable();

            //SqlDataReader reader = command.ExecuteReader();
            dt.Load(command.ExecuteReader());

            ConexaoBanco.conn.Close();

            dgvUsuarios.DataSource = dt.Rows.Cast <DataRow>().Take(100).CopyToDataTable();
        }
        public void alteraContato()
        {
            string ativo;

            if (chkInativo.Checked == true)
            {
                ativo = "1";
            }
            else
            {
                ativo = "0";
            }

            ConexaoBanco conexao2 = new ConexaoBanco();

            conexao2.ConexaoString();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = ConexaoBanco.conn;
                cmd.CommandText = "UPDATE CLIENTES_CONCORRENTE SET [CON_NOME] = '" + txtNome.Text + "',[CON_ATUALIZACAO] = GETDATE(),[CON_USUARIO] = 1 ,[CON_INATIVO] = " + ativo + " where CON_codigo = '" + txtID.Text + "'";
                cmd.ExecuteNonQuery();
                ConexaoBanco.conn.Close();

                Load_DGV();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public bool verificaNomeRepetido()
        {
            bool result;

            try
            {
                result = true;
                string usuario = "select * from CLIENTES_CONCORRENTE where rtrim(ltrim(CON_nome)) = '" + txtNome.Text + "'";

                ConexaoBanco novaConexao = new ConexaoBanco();
                novaConexao.ConexaoString();
                SqlCommand conn = new SqlCommand();
                conn.Connection  = ConexaoBanco.conn;
                conn.CommandText = usuario;
                DataTable resultado = new DataTable();
                resultado.Load(conn.ExecuteReader());
                SqlDataReader resuldado = conn.ExecuteReader();
                if (resultado.Rows.Count == 0)
                {
                    result = false;
                }
            }
            catch (SqlException mensagem)
            {
                throw new Exception(mensagem.Message);
            }
            finally
            {
            }

            ConexaoBanco.conn.Close();
            return(result);
        }
        //METODO 7
        public void alteraContato()
        {
            string ativo;

            if (chkInativo.Checked == true)
            {
                ativo = "1";
            }
            else
            {
                ativo = "0";
            }

            ConexaoBanco conexao2 = new ConexaoBanco();

            conexao2.ConexaoString();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = ConexaoBanco.conn;
                cmd.CommandText = "update usuarios set us_inativo = '" + ativo + "' , us_login = '******', us_nome = '" + txtNome.Text + "' , us_email = '" + txtEmail.Text + "' , us_senha = '" + txtSenha.Text + "' , us_perfil = '" + verificaTipoFuncionario() + "' where us_id = " + txtID.Text + "";

                cmd.ExecuteNonQuery();
                ConexaoBanco.conn.Close();

                Load_DGV();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void TranferenciaCliente()
        {
            if (VariaveisStaticas.codigoclienteStatico == null)
            {
                return;
            }
            string idCliente = VariaveisStaticas.codigoclienteStatico.Trim();
            // MessageBox.Show(dgvClientes.Rows[e.RowIndex].Cells[0].Value.ToString());
            //crias a query sql
            string query = "select CLI_CODIGO, CLI_NOME_FANTASIA, CLI_DDD, CLI_TELEFONE1, CLI_TELEFONE2, CLI_RESPONSAVEL, CLI_TELRESPONSAVEL, CLI_DECISOR, CLI_TELDECISOR, CLI_QTDPONTOS,CLI_EMAILS, CLI_CONCORRENTE, CLI_INDICACAO,  CLI_RAMOATUACAO, CLI_CADASTRO, CLI_ATUALIZACAO,  a.us_nome as usuarioatualiza, CLI_INATIVO ";

            query += " ,END_CEP,END_ENDERECO, END_NUMERO, END_COMPLEMENTO, END_BAIRRO, END_CIDADE, END_UF,  b.us_nome as usuarioacadastro , cli_consultor,CLI_DDD_DESCISOR ";
            query += " from clientes  ";
            query += " left join ENDERECO on CLIENTES.CLI_CODIGO = ENDERECO.END_CODIGO ";
            query += "  inner join usuarios a on  a.US_ID = CLI_USUARIO    inner join usuarios b on b.US_ID = CLI_USUARIOCADASTRO  ";
            query += " where cli_codigo = '" + idCliente + "'";

            ConexaoBanco novaConexao = new ConexaoBanco();

            novaConexao.ConexaoString();
            SqlCommand cmd = new SqlCommand(query, ConexaoBanco.conn);

            cmd.CommandType = System.Data.CommandType.Text;
            SqlDataReader reader = cmd.ExecuteReader();

            //usando sqlDataReader para ler os dados do banco de dados

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    txtId.Text          = idCliente;
                    txtNome.Text        = reader.GetString(1);
                    txtDecisor.Text     = reader.GetString(7);
                    txtTelDescisor.Text = reader.GetString(8);
                    string Cep         = reader.GetString(18);
                    string Rua         = reader.GetString(19);
                    string numero      = reader.GetString(20);
                    string complemento = reader.GetString(21);
                    string bairro      = reader.GetString(22);
                    string Cidade      = reader.GetString(23);
                    string Uf          = reader.GetString(24);
                    txtEndereco.Text = Rua + " ," + numero + "/" + complemento + " - " + bairro + " - " + Cidade + " - " + Uf;
                    //   lblUsuarioCadastro.Text = reader.GetString(25);
                    cmbConsultor.SelectedValue = reader.GetInt16(26);
                    txtDDDDecisor.Text         = reader.GetString(27);
                    //cli.ClienteAuditleituraCompara(idCliente);
                }
            }
        }
        public void Load_DGV()
        {
            //volta para acao incluir
            acao = Acoes.incluir;

            //desabilita o botao cancelar
            bntCancelar.Enabled        = false;
            bntSalvar.Enabled          = false;
            gbxDadosCadastrais.Enabled = false;
            txtNome.Enabled            = false;

            string usuarios = "SELECT [CON_CODIGO],[CON_NOME],[CON_CADASTRO],[CON_ATUALIZACAO],[CON_USUARIO],replace(replace([CON_INATIVO] ,'1','Inativo'),'0','Ativo') as CON_INATIVO  FROM [dbo].[CLIENTES_CONCORRENTE]  where CON_INATIVO = '0'";

            //usando a classe de conexao
            ConexaoBanco conexao = new ConexaoBanco();

            conexao.ConexaoString();

            int            i   = 0;
            SqlCommand     cmd = new SqlCommand(usuarios, ConexaoBanco.conn);
            SqlDataAdapter da  = new SqlDataAdapter(cmd);
            DataTable      dt  = new DataTable();

            da.Fill(dt);
            if (dt != null && dt.Rows.Count > 0)
            {
                if (dgvRegistros.Rows.Count > 0)
                {
                    dgvRegistros.Rows.Clear();
                }
                dgvRegistros.Rows.Add(dt.Rows.Count);
                foreach (DataRow rw in dt.Rows)
                {
                    dgvRegistros.Rows[i].Cells[0].Value = rw["CON_CODIGO"].ToString();
                    dgvRegistros.Rows[i].Cells[1].Value = rw["CON_NOME"].ToString();
                    dgvRegistros.Rows[i].Cells[2].Value = rw["CON_CADASTRO"].ToString();
                    dgvRegistros.Rows[i].Cells[3].Value = rw["CON_ATUALIZACAO"].ToString();
                    dgvRegistros.Rows[i].Cells[4].Value = rw["CON_USUARIO"].ToString();
                    dgvRegistros.Rows[i].Cells[5].Value = rw["CON_INATIVO"].ToString();


                    i = i + 1;
                }
            }

            ConexaoBanco.conn.Close();

            limpaCampos();
        }
        private void excluiRegistro()
        {
            if (acao == Acoes.incluir)
            {
                MessageBox.Show("Durante a inclusao de um Registro, não é possível usar o botão \"Inativar\" ", "Não é possivel Inativar");
                return;
            }


            int index;

            if (dgvRegistros.Rows[0].Cells[0].Value != null)
            {
                index = dgvRegistros.CurrentRow.Index;

                if ((MessageBox.Show("Tem certeza que deseja inativar o registro " + txtNome.Text.Trim() + " ?", "Tem Certeza?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) == DialogResult.No)
                {
                    return;
                }
            }
            else
            {
            }



            ConexaoBanco conexao2 = new ConexaoBanco();

            conexao2.ConexaoString();
            try
            {
                index = dgvRegistros.CurrentRow.Index;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = ConexaoBanco.conn;
                cmd.CommandText = "UPDATE CLIENTES_CONCORRENTE SET [CON_INATIVO] = '1' where CON_CODIGO =  " + txtID.Text + "";

                cmd.ExecuteNonQuery();
                ConexaoBanco.conn.Close();

                Load_DGV();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public int idUsuario()
        {
            ConexaoBanco conexao2 = new ConexaoBanco();

            conexao2.ConexaoString();
            try
            {
                SqlCommand sql = new SqlCommand("Select MAX(us_id) + 1 From usuarios", ConexaoBanco.conn);
                codigo = Convert.ToInt32(sql.ExecuteScalar());
                ConexaoBanco.conn.Close();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(codigo);
        }
        public int idUsuario()
        {
            ConexaoBanco conexao2 = new ConexaoBanco();

            conexao2.ConexaoString();
            try
            {
                SqlCommand sql = new SqlCommand("Select resultado = CASE WHEN MAX(CON_CODIGO) is null then '1' else MAX(CON_CODIGO) + 1 end From CLIENTES_CONCORRENTE", ConexaoBanco.conn);

                codigo = Convert.ToInt32(sql.ExecuteScalar());

                ConexaoBanco.conn.Close();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(codigo);
        }
示例#10
0
        //#################################
        public bool verificaLogin()
        {
            bool result;

            try
            {
                result = true;
                string usuario = "select * from usuarios where rtrim(ltrim(us_login)) = '" + txtUsuario.Text + "' and rtrim(ltrim(us_senha)) = '" + txtSenha.Text + "' and us_inativo = '0'";

                ConexaoBanco novaConexao = new ConexaoBanco();
                novaConexao.ConexaoString();
                SqlCommand conn = new SqlCommand();
                conn.Connection  = ConexaoBanco.conn;
                conn.CommandText = usuario;
                DataTable resultado = new DataTable();
                resultado.Load(conn.ExecuteReader());
                SqlDataReader resuldado = conn.ExecuteReader();
                if (resultado.Rows.Count != 1)
                {
                    result = false;
                }
                else
                {
                    while (resuldado.Read())
                    {
                        UsuariosSistema U = new UsuariosSistema();
                        UsuarioLogado.usuario = U.GetLogin(resuldado.GetString(1), resuldado.GetString(4));
                    }
                }
            }
            catch (SqlException mensagem)
            {
                throw new Exception(mensagem.Message);
            }
            finally
            {
            }
            return(result);
        }
        private void bntPesquisar_Click(object sender, EventArgs e)
        {
            if (dgvRegistros.Rows.Count > 0)
            {
                dgvRegistros.Rows.Clear();
            }

            //volta para acao incluir
            acao = Acoes.incluir;

            //desabilita o botao cancelar
            txtNome.Enabled            = false;
            bntCancelar.Enabled        = false;
            bntSalvar.Enabled          = false;
            bntInativar.Enabled        = false;
            gbxDadosCadastrais.Enabled = false;


            //define ativo e inativo
            string ativo;

            if (chkPesqInativo.Checked == true)
            {
                ativo = "'1'";
            }
            else
            {
                ativo = "'0'";
            }


            string pesquisarRegistro;

            if (txtNomePesquisar.Text.Length > 0 && chkQualquerParte.Checked == true)
            {
                pesquisarRegistro = " and CON_nome like '%" + txtNomePesquisar.Text + "%'";
            }
            else if (txtNomePesquisar.Text.Length > 0)
            {
                pesquisarRegistro = " and CON_nome like '" + txtNomePesquisar.Text + "%'";
            }
            else
            {
                pesquisarRegistro = " ";
            }

            string usuarios = "SELECT [CON_CODIGO],[CON_NOME],[CON_CADASTRO],[CON_ATUALIZACAO],[CON_USUARIO], replace(replace([CON_INATIVO],'1','Inativo'),'0','Ativo') AS CON_INATIVO FROM [dbo].[CLIENTES_CONCORRENTE]  where CON_inativo = " + ativo + pesquisarRegistro + "  ";

            //MessageBox.Show(usuarios);

            //usando a classe de conexao
            ConexaoBanco conexao = new ConexaoBanco();

            conexao.ConexaoString();

            int            i   = 0;
            SqlCommand     cmd = new SqlCommand(usuarios, ConexaoBanco.conn);
            SqlDataAdapter da  = new SqlDataAdapter(cmd);
            DataTable      dt  = new DataTable();

            da.Fill(dt);
            if (dt != null && dt.Rows.Count > 0)
            {
                if (dgvRegistros.Rows.Count > 0)
                {
                    dgvRegistros.Rows.Clear();
                }
                dgvRegistros.Rows.Add(dt.Rows.Count);
                foreach (DataRow rw in dt.Rows)
                {
                    dgvRegistros.Rows[i].Cells[0].Value = rw["CON_CODIGO"].ToString();
                    dgvRegistros.Rows[i].Cells[1].Value = rw["CON_NOME"].ToString();
                    dgvRegistros.Rows[i].Cells[2].Value = rw["CON_CADASTRO"].ToString();
                    dgvRegistros.Rows[i].Cells[3].Value = rw["CON_ATUALIZACAO"].ToString();
                    dgvRegistros.Rows[i].Cells[4].Value = rw["CON_USUARIO"].ToString();
                    dgvRegistros.Rows[i].Cells[5].Value = rw["CON_INATIVO"].ToString();

                    i = i + 1;
                }
            }

            ConexaoBanco.conn.Close();

            limpaCampos();
        }
示例#12
0
        //tranfere o cliente de um combobox pra outro
        public void TranferenciaCliente()
        {
            string idCliente = VariaveisStaticas.codigoclienteStatico.Trim();

            txtId.Text = idCliente;
            // MessageBox.Show(dgvClientes.Rows[e.RowIndex].Cells[0].Value.ToString());
            //crias a query sql
            string query = "select CLI_CODIGO, CLI_NOME_FANTASIA, CLI_DDD, CLI_TELEFONE1, CLI_TELEFONE2, CLI_RESPONSAVEL, CLI_TELRESPONSAVEL, CLI_DECISOR, CLI_TELDECISOR, CLI_QTDPONTOS,CLI_EMAILS, CLI_CONCORRENTE, CLI_INDICACAO,  CLI_RAMOATUACAO, CLI_CADASTRO, CLI_ATUALIZACAO,  a.us_nome as usuarioatualiza, CLI_INATIVO ";

            query += " ,END_CEP,END_ENDERECO, END_NUMERO, END_COMPLEMENTO, END_BAIRRO, END_CIDADE, END_UF,  b.us_nome as usuarioacadastro , cli_consultor,CLI_DDD_DESCISOR, CLI_DDD_RESPONSAVEL, FAS_DESCRICAO ";
            query += " from clientes  ";
            query += " left join ENDERECO on CLIENTES.CLI_CODIGO = ENDERECO.END_CODIGO ";
            query += "  inner join usuarios a on  a.US_ID = CLI_USUARIO INNER JOIN FASES ON FAS_CODIGO = CLI_FASE    inner join usuarios b on b.US_ID = CLI_USUARIOCADASTRO  ";
            query += " where cli_codigo = '" + idCliente + "'";

            ConexaoBanco novaConexao = new ConexaoBanco();

            novaConexao.ConexaoString();
            SqlCommand cmd = new SqlCommand(query, ConexaoBanco.conn);

            cmd.CommandType = System.Data.CommandType.Text;
            SqlDataReader reader = cmd.ExecuteReader();

            //usando sqlDataReader para ler os dados do banco de dados

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    txtNome.Text                 = reader.GetString(1);
                    txtDDD.Text                  = reader.GetString(2);
                    txtTel1.Text                 = reader.GetString(3);
                    txtTel2.Text                 = reader.GetString(4);
                    txtResponsavel.Text          = reader.GetString(5);
                    txtTelResponsavel.Text       = reader.GetString(6);
                    txtDecisor.Text              = reader.GetString(7);
                    txtTelDescisor.Text          = reader.GetString(8);
                    numPontos.Value              = reader.GetInt16(9);
                    txtEmail.Text                = reader.GetString(10);
                    cmbConcorrente.SelectedValue = reader.GetInt16(11);
                    cmbIndicacao.SelectedValue   = reader.GetInt16(12);
                    cmbRamoAtuacao.SelectedValue = reader.GetInt16(13);
                    dtpCadastro.Value            = reader.GetDateTime(14);
                    dtpAtualizacao.Value         = reader.GetDateTime(15);
                    lblUsuario.Text              = reader.GetString(16); //usuario que alterou

                    if (reader.GetString(17).Trim() == "0")
                    {
                        chkInativo.Checked = false;
                    }
                    else
                    {
                        chkInativo.Checked = true;
                    }

                    txtCep.Text                = reader.GetString(18);
                    txtEndereco.Text           = reader.GetString(19);
                    txtNumero.Text             = reader.GetString(20);
                    txtComplemento.Text        = reader.GetString(21);
                    txtBairro.Text             = reader.GetString(22);
                    cmbCidade.Text             = reader.GetString(23);
                    cmbUf.Text                 = reader.GetString(24);
                    lblUsuarioCadastro.Text    = reader.GetString(25);
                    cmbConsultor.SelectedValue = reader.GetInt16(26);
                    txtDDDDescisor.Text        = reader.GetString(27);
                    txtDDDresponsavel.Text     = reader.GetString(28);
                    lblFases.Text              = reader.GetString(29);
                }
            }
        }