示例#1
0
        public bool atualizarCliente(tb_clientes_farmacia objCliente)
        {
            var db = new FarmaciaEntities();

            db.Entry <tb_clientes_farmacia>(objCliente).State = System.Data.Entity.EntityState.Modified;

            #region .: db.SaveChanges :.

            try
            {
                db.SaveChanges();
                return(true);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                var raise = (from validationErrors in dbEx.EntityValidationErrors
                             from validationError in validationErrors.ValidationErrors
                             select string.Format("{0}:{1}", validationErrors.Entry.Entity, validationError.ErrorMessage))
                            .Aggregate <string, Exception>(dbEx,
                                                           (current, message) => new InvalidOperationException(message, current));
                throw raise;
            }

            #endregion
        }
示例#2
0
        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);
            }
        }
示例#3
0
        public formEditarCliente(tb_clientes_farmacia objCliente)
        {
            InitializeComponent();

            txtNome.Text          = objCliente.tx_nome;
            txtEmail.Text         = objCliente.email;
            txtBairro.Text        = objCliente.bairro ?? string.Empty;
            txtCep.Text           = objCliente.cep ?? string.Empty;
            txtTelefone.Text      = objCliente.telefone ?? string.Empty;
            txtCodigoCliente.Text = objCliente.id_cliente.ToString();
            txtCidade.Text        = objCliente.cidade ?? string.Empty;
            nmCpf.Value           = objCliente.in_cpf ?? 0;
            txtEndereco.Text      = objCliente.endereco ?? string.Empty;
        }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        private void btnBuscarRemedio_Click(object sender, EventArgs e)
        {
            if (rbCpf.Checked)
            {
                var cpf = Convert.ToDecimal(txtBuscaCliente.Text.Replace("-", "").Replace(".", ""));
                clienteEscolhido = lstCliente.Where(x => x.in_cpf == cpf).FirstOrDefault();
                if (clienteEscolhido != null)
                {
                    this.Visible = false;
                    formEditarCliente frmEditarCliente = new formEditarCliente(clienteEscolhido);
                    frmEditarCliente.ShowDialog();
                    this.Visible = true;
                }
                else
                {
                    MessageBox.Show("Cliente não encontrado", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (rbCodigo.Checked)
            {
                var codigo_cliente = Convert.ToInt32(txtBuscaCliente.Text);
                clienteEscolhido = lstCliente.Where(x => x.id_cliente == codigo_cliente).FirstOrDefault();

                if (clienteEscolhido != null)
                {
                    this.Visible = false;
                    formEditarCliente frmEditarCliente = new formEditarCliente(clienteEscolhido);
                    frmEditarCliente.ShowDialog();
                    this.Visible = true;
                }
                else
                {
                    MessageBox.Show("Cliente não encontrado", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }