예제 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Deseja deletar " + lblNome.Text + " (" + lblCPF.Text + ")?", "Deletar cadastro", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                string          cpf   = lblCPF.Text;
                string          query = "delete from dbglap.t01_cadastroclientespf where cdCPF = '" + cpf + "'";
                MySqlConnection conn  = new MySqlConnection(ServDbConnection.GetStrConnection());
                MySqlCommand    cmd   = new MySqlCommand(query, conn);
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
                catch (Exception except)
                {
                    txtStatusBarConsultaPF.Text = except.Message;
                    conn.Close();
                }
                finally
                {
                    conn.Close();
                }
                LimpaTelaConsultaPF();
            }
            else
            {
                txtStatusBarConsultaPF.Text = "Operação cancelada";
            }
        }
예제 #2
0
        public AutoCompleteStringCollection AutoCompleteLoad()
        {
            AutoCompleteStringCollection acsc = new AutoCompleteStringCollection();
            MySqlConnection conn  = new MySqlConnection(ServDbConnection.GetStrConnection());
            string          query = "select cdNomeProduto, vlPreco from dbglap.t03_produtos";
            MySqlCommand    cmd   = new MySqlCommand(query, conn);

            try
            {
                conn.Open();
                MySqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    acsc.Add(dr["cdNomeProduto"].ToString());
                    acsc.Add(dr["vlPreco"].ToString());
                }
            }
            catch (Exception except)
            {
                statusBarInserirPedidos.Text = except.Message;
                conn.Close();
            }
            finally
            {
                conn.Close();
            }
            return(acsc);
        }
        public static ClientePF GetClientePFByCPF(string cpf)
        {
            MySqlConnection conn = new MySqlConnection(ServDbConnection.GetStrConnection());

            //MessageBox.Show("Objeto definido");
            try
            {
                List <ClientePF> listaClientes = new List <ClientePF>();
                string           query         = "select * from dbglap.t01_cadastroclientespf where cdCpf = '" + cpf + "'";
                //MessageBox.Show(query);
                conn.Open();
                MySqlCommand    cmd = new MySqlCommand(query, conn);
                MySqlDataReader dr  = cmd.ExecuteReader();
                //MessageBox.Show("Query executada");
                //dr.Read();
                //ClientePF cliente;
                while (dr.Read())
                {
                    listaClientes.Add(new ClientePF(dr));
                }

                conn.Close();
                return(listaClientes[0]);
            }
            catch (Exception except)
            {
                MessageBox.Show(except.Message);
                conn.Close();
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }
        public static HashSet <ClientePF> GetClientePFByTel(string tel, int col)
        {
            MySqlConnection conn = new MySqlConnection(ServDbConnection.GetStrConnection());

            try
            {
                string query = FuncoesAuxiliares.GetQueryBuscaPorTelefone(tel, col);
                HashSet <ClientePF> listaClientePF = new HashSet <ClientePF>();
                conn.Open();
                MySqlCommand    cmdTel = new MySqlCommand(query, conn);
                MySqlDataReader drRes  = cmdTel.ExecuteReader();
                while (drRes.Read())
                {
                    ClientePF cliente = new ClientePF(drRes);
                    if (!listaClientePF.Contains(cliente))
                    {
                        listaClientePF.Add(cliente);
                    }
                }
                return(listaClientePF);
            }
            catch (Exception except)
            {
                MessageBox.Show(except.Message);
                conn.Close();
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }
        public static void GetPedidoById(int id)
        {
            MySqlConnection conn  = new MySqlConnection(ServDbConnection.GetStrConnection());
            string          query = "select * from T03_CadastroPedido where idPedido = " + id;

            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(query, conn);

                conn.Close();
            }
            catch (Exception except)
            {
                MessageBox.Show(except.Message);
            }
            finally
            {
                conn.Close();
            }
        }
예제 #6
0
        private void dgvInserirPedidos_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            MySqlConnection conn = new MySqlConnection(ServDbConnection.GetStrConnection());

            try
            {
                // Trecho do código que implementa o cálculo automático do subtotal do item
                if (e.ColumnIndex == 1)
                {
                    double cell1 = Convert.ToDouble(dgvInserirPedidos.CurrentRow.Cells[1].Value, CultureInfo.InvariantCulture);
                    double cell2 = Convert.ToDouble(dgvInserirPedidos.CurrentRow.Cells[2].Value, CultureInfo.InvariantCulture);
                    if (cell1.ToString() != "" && cell2.ToString() != "")
                    {
                        dgvInserirPedidos.CurrentRow.Cells[3].Value = Convert.ToDouble(cell1 * cell2, CultureInfo.InvariantCulture);
                    }
                }
                double valorTotal = 0;
                string valor      = "";
                if (dgvInserirPedidos.CurrentRow.Cells[3].Value != null)
                {
                    valor = dgvInserirPedidos.CurrentRow.Cells[3].Value.ToString();
                    if (!valor.Equals(""))
                    {
                        for (int i = 0; i <= dgvInserirPedidos.RowCount - 1; i++)
                        {
                            if (dgvInserirPedidos.Rows[i].Cells[3].Value != null)
                            {
                                valorTotal += Convert.ToDouble(dgvInserirPedidos.Rows[i].Cells[3].Value, CultureInfo.InvariantCulture);
                            }
                        }
                        lblTotalPedido.Text = valorTotal.ToString("C");
                    }
                }


                // Trecho do código que implementa a busca automática do preço do produto
                if (e.ColumnIndex == 0)
                {
                    string       query = "select cdNomeProduto, vlPreco from dbglap.t03_produtos";
                    MySqlCommand cmd   = new MySqlCommand(query, conn);
                    conn.Open();
                    MySqlDataReader             dr             = cmd.ExecuteReader();
                    Dictionary <string, double> DictioProdutos = new Dictionary <string, double>();
                    //statusBarInserirPedidos.Text = "Entrou no código";
                    //MessageBox.Show("Entrou no código");
                    while (dr.Read())
                    {
                        string key   = dr["cdNomeProduto"].ToString();
                        double value = double.Parse(dr["vlPreco"].ToString());
                        //double value = Convert.ToDouble(dr["vlPreco"].ToString(),CultureInfo.InvariantCulture);
                        DictioProdutos[key] = value;
                        //MessageBox.Show("chave = " + key + ", valor = " + value + ", Valor * 10 = " + value*10);
                        //MessageBox.Show("chave = " + key + ", valor = " + DictioProdutos[key] + ", valor * 10 = " + DictioProdutos[key]*10);
                    }
                    conn.Close();

                    //MessageBox.Show(dgvInserirPedidos.CurrentRow.Cells[1].Value.ToString());
                    if (dgvInserirPedidos.CurrentRow.Cells[0].ToString() != "")
                    {
                        double value = DictioProdutos[dgvInserirPedidos.CurrentRow.Cells[0].Value.ToString()];
                        //MessageBox.Show("Preco = " + value);
                        dgvInserirPedidos.CurrentRow.Cells[2].Value = value;
                    }
                }
            }
            catch (Exception ex)
            {
                statusBarInserirPedidos.Text = ex.Message;
            }
            finally
            {
                conn.Close();
            }
        }
예제 #7
0
        private void btnConsultaCadastroPF_Click(object sender, EventArgs e)
        {
            // Lê os dados de entrada

            string nome       = txtNomeBusca.Text;
            string cpf        = txtCPFBusca.Text;
            string logradouro = txtLogradouroBusca.Text;
            string telefone   = txtTelBusca.Text;
            int    contador   = 0;
            HashSet <ClientePF> listaClientes         = new HashSet <ClientePF>();
            HashSet <ClientePF> listaClientesAux      = new HashSet <ClientePF>();
            HashSet <ClientePF> listaClientesTelefone = new HashSet <ClientePF>();

            cboxResBuscaPF.Items.Clear();
            LimpaTelaConsultaPF();
            MySqlConnection conn = new MySqlConnection(ServDbConnection.GetStrConnection());

            try
            {
                // Monta o conjunto de criterios satisfeitos
                if ((nome != "") || (cpf != "") || (logradouro != ""))
                {
                    contador++;
                    string query = FuncoesAuxiliares.fConsultaCLientePF(nome, cpf, logradouro);
                    //MessageBox.Show(query);
                    txtStatusBarConsultaPF.Text = query;
                    conn.Open();
                    MySqlCommand    cmd    = new MySqlCommand(query, conn);
                    MySqlDataReader msqlDR = cmd.ExecuteReader();
                    while (msqlDR.Read())
                    {
                        ClientePF cliente = new ClientePF(msqlDR);
                        if (!listaClientes.Contains(cliente))
                        {
                            listaClientes.Add(cliente);
                        }
                    }
                }

                //Monta o conjunto de telefones encontrados
                if (telefone != "")
                {
                    contador++;
                    listaClientesAux = FuncoesDB.GetClientePFByTel(telefone, 1);
                    foreach (ClientePF cliente in listaClientesAux)
                    {
                        if (!listaClientesTelefone.Contains(cliente))
                        {
                            listaClientesTelefone.Add(cliente);
                        }
                    }
                    listaClientesAux = FuncoesDB.GetClientePFByTel(telefone, 2);
                    foreach (ClientePF cliente in listaClientesAux)
                    {
                        if (!listaClientesTelefone.Contains(cliente))
                        {
                            listaClientesTelefone.Add(cliente);
                        }
                    }
                    listaClientesAux = FuncoesDB.GetClientePFByTel(telefone, 3);
                    foreach (ClientePF cliente in listaClientesAux)
                    {
                        if (!listaClientesTelefone.Contains(cliente))
                        {
                            listaClientesTelefone.Add(cliente);
                        }
                    }
                }
                conn.Close();
                if (contador == 0)
                {
                    lblResultadoPesquisa.Text = "Preencha algum dos campos para buscar";
                }
                else
                {
                    if (contador == 2)
                    {
                        listaClientes.IntersectWith(listaClientesTelefone);
                    }
                    else
                    {
                        if (listaClientesTelefone.Count > 0)
                        {
                            listaClientes = listaClientesTelefone;
                        }
                    }

                    if (listaClientes.Count == 0)
                    {
                        lblResultadoPesquisa.Text = "Nenhum cliente encontrado";
                    }
                    else if (listaClientes.Count == 1)
                    {
                        lblResultadoPesquisa.Text = "1 cliente encontrado";
                        foreach (ClientePF cliente in listaClientes)
                        {
                            ImprimeClienteTela(cliente);
                        }
                    }
                    else
                    {
                        lblResultadoPesquisa.Text = listaClientes.Count + " clientes encontrados";
                        foreach (ClientePF cliente in listaClientes)
                        {
                            cboxResBuscaPF.Items.Add(cliente.ToString());
                        }
                    }
                }
            }
            catch (Exception except)
            {
                MessageBox.Show(except.Message);
                conn.Close();
            }
            finally
            {
                conn.Close();
            }
        }
예제 #8
0
        private void btnCadastrarCliente_Click(object sender, EventArgs e)
        {
            List <string> listaInputExcept = new List <string>();
            // Lê os dados digitados pelo usuário na tela de CadastroPF
            string cdNome           = ExceptInput.ValidaInputString(txtNomePF.Text, "Nome", listaInputExcept);
            string cdCpf            = ExceptInput.ValidaInputString(txtCPF.Text, "CPF", listaInputExcept);
            string cdLogradouro     = txtEndereco.Text;
            string cdEndNum         = txtEndNumPF.Text;
            string cdEndComplemento = txtEnderecoComplemento.Text;
            string cdBairro         = txtBairro.Text;
            string cdCEP            = txtCEP.Text;
            string cdCidade         = txtCidade.Text;
            string cdEstado         = cmbEstado.Text;
            string TelRes           = ExceptInput.ValidaInputTelefone(txtTelResidencial.Text);
            string TelCom           = ExceptInput.ValidaInputTelefone(txtTelComercial.Text);
            string TelCel           = ExceptInput.ValidaInputTelefone(txtTelCelular.Text);
            string Email            = txtEmail.Text;
            string Observacao       = txtObservacaoPF.Text;

            MySqlConnection conn = new MySqlConnection(ServDbConnection.GetStrConnection());

            try
            {
                if (listaInputExcept.Count > 0)
                {
                    throw new FormException(listaInputExcept[0]);
                }
                //Monta a query de inserção
                string query = "insert into T01_CadastroClientesPF "
                               + "(cdCpf,cdNome,cdLogradouro,cdEndNum,cdEndComplemento,cdBairro,cdCEP,cdCidade,cdEstado,TelRes,TelCel,TelCom,Email,Observacao) values "
                               + "('"
                               + cdCpf.ToString() + "','"
                               + cdNome + "','"
                               + cdLogradouro + "','"
                               + cdEndNum + "','"
                               + cdEndComplemento + "','"
                               + cdBairro + "','"
                               + cdCEP + "','"
                               + cdCidade + "','"
                               + cdEstado + "','"
                               + TelRes + "','"
                               + TelCel + "','"
                               + TelCom + "','"
                               + Email + "','"
                               + Observacao + "')";

                conn.Open();
                MySqlCommand cmdObj = new MySqlCommand(query, conn);
                cmdObj.ExecuteNonQuery();
                conn.Close();
                stripStatLabelCadastroPF.Text = "Novo cliente cadastrado";
            }
            catch (MySqlException except)
            {
                //MessageBox.Show(except.Message);
                conn.Close();
                stripStatLabelCadastroPF.Text = "Erro no cadastro: " + except.Message;
            }
            catch (FormException except)
            {
                stripStatLabelCadastroPF.Text = "Erro nos dados digitados: " + except.Message;
            }
            finally
            {
                conn.Close();
            }
        }