Esempio n. 1
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            GRCEntities db = new GRCEntities();

            try
            {
                CLIENTE cliente = new CLIENTE();
                cliente.NOME = txtNome.Text;
                cliente.CPF = Convert.ToInt64(txtCPF.Text.Replace(".", String.Empty).Replace("-", String.Empty));
                cliente.EMAIL = txtEmail.Text;
                cliente.TELEFONE = txtTelefone.Text;

                //endereco
                ENDERECO endereco = new ENDERECO();
                endereco.LOGRADOURO = cbLogradouro.SelectedItem + " " + txtEndereco.Text;
                endereco.NUMERO = Convert.ToInt32(txtNumero.Text);
                endereco.BAIRRO = txtBairro.Text;
                endereco.CIDADE = txtCidade.Text;
                endereco.ESTADO = cbUF.SelectedItem.ToString();

                db.AddToENDERECO(endereco);
                cliente.ENDERECO = endereco;

                db.AddToCLIENTE(cliente);

                db.SaveChanges();

                MessageBox.Show("Cliente salvo com sucesso.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
        }
Esempio n. 2
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            GRCEntities db = new GRCEntities();

            if (txtDescricao.Text == "")
            {
                MessageBox.Show("Descrição não pode ser vazia.");
                return;
            }
            if (txtValor.Text == String.Empty)
            {
                MessageBox.Show("Valor não pode ser vazio.");
                return;
            }

            PRODUTO prod = new PRODUTO();
            try
            {
                prod.DESCRICAO = txtDescricao.Text;
                prod.VALOR = Convert.ToDecimal(txtValor.Text);
                prod.CODIGO = Convert.ToInt32(txtCodigo.Text);

                db.AddToPRODUTO(prod);
                db.SaveChanges();
                MessageBox.Show("Produto salvo com sucesso.");
                txtDescricao.Text = String.Empty;
                txtValor.Text = String.Empty;
                txtCodigo.Text = String.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show("erro: " + ex.Message);
            }
        }
Esempio n. 3
0
        private void btnEnviar_Click(object sender, EventArgs e)
        {
            GRCEntities db = new GRCEntities();

            if (lblCliente.Text == "Nenhum cliente selecionado")
            {
                MessageBox.Show("Necessário selecionar um cliente");
                return;
            }
            if (dtItems.Rows.Count == 0)
            {
                MessageBox.Show("Necessário adicionar pelo menos um produto ao pedido.");
                return;
            }

            try
            {
                PEDIDO p = new PEDIDO();
                p.CLIENTE = db.CLIENTE.First(c => c.CODIGO == this.codigoCliente);
                p.DATA = DateTime.Now;
                p.VALOR_TOTAL = Convert.ToDecimal(lblTotalPedido.Text);

                db.AddToPEDIDO(p);

                foreach (DataGridViewRow row in dtItems.Rows)
                {
                    PEDIDO_ITEM pedidoItem = new PEDIDO_ITEM();
                    pedidoItem.PEDIDO = p;
                    var codigoProd = Convert.ToInt32(row.Cells["Codigo"].Value);
                    pedidoItem.PRODUTO = db.PRODUTO.First(pr => pr.CODIGO == codigoProd);
                    pedidoItem.QUANTIDADE = Convert.ToInt32(row.Cells["Quantidade"].Value);
                    pedidoItem.PRECO_UNIT = Convert.ToDecimal(row.Cells["Preco"].Value);
                    pedidoItem.TOTAL = Convert.ToDecimal(row.Cells["Total"].Value);

                    db.AddToPEDIDO_ITEM(pedidoItem);
                }

                db.SaveChanges();

                //limpa os campos
                txtCPF.Text = String.Empty;
                txtCodigoProduto.Text = String.Empty;
                for (int i = 0; i < dtItems.Rows.Count; i++)
                {
                    dtItems.Rows.RemoveAt(i);
                }
                lblTotalPedido.Text = "0";

                MessageBox.Show("Pedido salvo com sucesso.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
        }