private void btnAtualizar_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtNome.Text) && nmCpf.Value != 0 && !string.IsNullOrEmpty(txtEmail.Text) && !string.IsNullOrEmpty(txtTelefone.Text)) { tb_clientes_farmacia novoCliente = new tb_clientes_farmacia { id_cliente = Convert.ToInt32(txtCodigoCliente.Text), tx_nome = txtNome.Text, in_cpf = Convert.ToDecimal(nmCpf.Value), endereco = txtEndereco.Text ?? string.Empty, bairro = txtBairro.Text ?? string.Empty, cidade = txtCidade.Text ?? string.Empty, cep = txtCep.Text ?? string.Empty, email = txtEmail.Text ?? string.Empty, telefone = txtTelefone.Text }; clienteDAO clientedao = new clienteDAO(); if (clientedao.atualizarCliente(novoCliente)) { MessageBox.Show("Cliente atualizado com sucesso", "Dados atualizados", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } else { MessageBox.Show("Erro ao atualizar cliente, tente novamente ou contate o suporte do sistema", "Erro interno", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Nome, cpf, telefone e e-mail não podem estar em branco", "Dados inválidos", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CarregaCliente() { clienteDAO clientedao = new clienteDAO(); Cliente cliente = new Cliente(); cliente = clientedao.BuscaId(Convert.ToInt32(txtIdCliente.Value)); txtIdCliente.Value = cliente.id.ToString(); txtNome.Text = cliente.nome; if (cliente.tipo == "F") { cboTipo.SelectedIndex = 0; txtCpf.Text = cliente.cpf_cnpj; txtCpf.Enabled = true; txtCnpj.Enabled = false; } else { cboTipo.SelectedIndex = 1; txtCnpj.Text = cliente.cpf_cnpj; txtCpf.Enabled = false; txtCnpj.Enabled = true; } CarregaGridViewFone(cliente.id); CarregaGridViewEndereco(cliente.id); }
private void btnBuscar_Click(object sender, EventArgs e) { if (txtCpfCliente.Text.Where(x => char.IsNumber(x)).Count() > 0) { cbOferecerRecorrente.Enabled = false; cbOferecerRecorrente.Visible = false; lbDescontoRecorrente.Visible = false; txtNomeCliente.Text = string.Empty; txtEmailCliente.Text = string.Empty; txtTelefoneCliente.Text = string.Empty; clienteDAO clientedao = new clienteDAO(); var cpf = Convert.ToDecimal(txtCpfCliente.Text); clienteVenda = clientedao.pegarClientePorCpf(cpf); if (clienteVenda != null) { if (clientedao.temCompraRecorrente(clienteVenda.id_cliente, objProduto.id_produto) && objProduto.porcentagem_desconto_recorrente > 0) { cbOferecerRecorrente.Enabled = true; cbOferecerRecorrente.Visible = true; lbDescontoRecorrente.Visible = true; } btnVender.Enabled = true; txtNomeCliente.Text = clienteVenda.tx_nome; txtEmailCliente.Text = clienteVenda.email; txtTelefoneCliente.Text = clienteVenda.telefone; } else { MessageBox.Show("Cpf não encontrado", "Dados inválidos", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
protected void btnSalvar_Click(object sender, EventArgs e) { if (!ValidaCampos()) { return; } clienteDAO clientedao = new clienteDAO(); Cliente cliente = new Cliente(); cliente.id = Convert.ToInt32(txtIdCliente.Value); cliente.nome = txtNome.Text; cliente.tipo = cboTipo.SelectedValue; if (cboTipo.SelectedValue == "F") { cliente.cpf_cnpj = txtCpf.Text; } else { cliente.cpf_cnpj = txtCnpj.Text; } if (txtIdCliente.Value == "0") { novoId = clientedao.InserirCliente(cliente); txtIdCliente.Value = novoId.ToString(); Session["id"] = novoId; AdicionarTelefone(); AdicionarEndereco(); } else { clientedao.AlterarCliente(cliente); Response.Redirect("Cliente_Listar.aspx", false); } }