Example #1
0
        private void btnGravar_Click(object sender, EventArgs e)
        {
            if (cmbCliente.SelectedIndex == -1)
            {
                ErrErro.SetError(cmbCliente, "Selecione um Cliente");
                return;
            }
            else
            {
                ErrErro.SetError(cmbCliente, "");
            }
            // Grava Pedido
            PedidoTableAdapter taPedido = new PedidoTableAdapter();

            taPedido.Insert(int.Parse(cmbCliente.SelectedValue.ToString()),
                            dtpDataVenda.Value, decimal.Parse(vTotalDoPedido.ToString()), "V",
                            txtObservacao.Text);
            vld_VendaAtual = Convert.ToInt32(taPedido.UltimoPedido().Rows[0]["UltimoID"]);
            // —————————————————————————————————————————————————————————————————————

            // Gravando os itens
            ItemTableAdapter    taItem = new ItemTableAdapter();
            ProdutoTableAdapter taProduto = new ProdutoTableAdapter();
            int     vCodigoProduto, vQtdVendida;
            decimal vValorUnit;

            for (int i = 0; i <= dgvItem.RowCount - 1; i++)
            {
                vCodigoProduto = (int)dgvItem.Rows[i].Cells["Codigo"].Value;
                vQtdVendida    = (int)dgvItem.Rows[i].Cells["Quantidade"].Value;
                vValorUnit     = (decimal)dgvItem.Rows[i].Cells["Valor_Unit"].Value;

                taItem.Insert(vld_VendaAtual, vCodigoProduto, vQtdVendida, vValorUnit);

                taProduto.Acerta_Saldo_Saida(vCodigoProduto, vQtdVendida);
            }

            MessageBox.Show("Venda gravada com sucesso");
            Limpa_Campos_Pedido();
            // Limpa os itens da tabela temporária
            Item_TempTableAdapter taItem_Temp = new Item_TempTableAdapter();

            taItem_Temp.Limpa_Itens(vld_VendaAtual, vUsuario);
            CarregaGridItens();
            // Desabilita controles
            grbPedido.Enabled     = false;
            grbItens.Enabled      = false;
            btnGravar.Enabled     = false;
            cmbCliente.Enabled    = false;
            txtObservacao.Enabled = false;
            btnNovo.Enabled       = true;
            btnCancelar.Enabled   = false;
        }
Example #2
0
        private void btnInserir_Click(object sender, EventArgs e)
        {
            try {
                int estoque = int.Parse(txtQuantidadeEstoq.Text);
                if (txtQuantComp.Value <= estoque)
                {
                    string marca = txtMarca.Text;
                    //decimal precounit = Convert.ToDecimal(txtPrecounid.Text);
                    ////preco = preco.Replace("R$", "#######,##");
                    CultureInfo ci = new CultureInfo("pt-BR");
                    //txtPreco.Text= precounit.ToString("C2", ci);
                    //decimal total = Convert.ToDecimal(txtVtotal.Text);
                    //txtVtotal.Text = total.ToString("C2", ci);
                    //total = total.Replace("R$ ", "#######,##");
                    if (txtMarca.Text != "")
                    {
                        txtDesc.Text = txtDesc.Text + ", " + txtMarca.Text;
                    }
                    else if (txtMarca.Text == "")
                    {
                        txtDesc.Text = txtMarca.Text;
                    }

                    if (txtQuantComp.Value != 0)
                    {
                        decimal            totalvenda = 0;
                        string             pag        = "";
                        PedidoTableAdapter taPedido   = new PedidoTableAdapter();
                        taPedido.Insert(Convert.ToInt32(txtCodCli.Text), dateTimePicker1.Value, totalvenda, pag, 0);
                        ItemPedidoTableAdapter taItemPedido = new ItemPedidoTableAdapter();

                        string quantidadeprod = txtQuantComp.Value.ToString();
                        taItemPedido.Insert(Convert.ToInt32(txtNumPedido.Text), int.Parse(quantidadeprod), int.Parse(txtCodPro.Text));
                        dgvPedido.Rows.Add(txtCodigoB.Text, txtDesc.Text, txtPrecounid.Text, txtQuantComp.Value.ToString(), txtTotal.Text);
                        {
                            //decimal total2 = 0;
                            //int i = 0;
                            //for (i = 0; i < dgvPedido.Rows.Count; i++)
                            //{
                            //    total2 = total2 + Convert.ToDecimal(dgvPedido.Rows[i].Cells["Total"].Value);
                            //}

                            //txtVtotal.Text = total2.ToString("C2", ci);

                            string novoEstoque            = (Convert.ToDecimal(txtQuantidadeEstoq.Text) - Convert.ToDecimal(txtQuantComp.Text)).ToString();
                            ProdutoTableAdapter taProduto = new ProdutoTableAdapter();
                            taProduto.UpdateEstoque(int.Parse(novoEstoque), Convert.ToInt64(txtCodigoB.Text));
                        }
                        decimal valorTotal = 0;
                        foreach (DataGridViewRow col in dgvPedido.Rows)
                        {
                            valorTotal = valorTotal + Convert.ToDecimal(col.Cells[4].Value);
                        }

                        //decimal valorall = Convert.ToDecimal(txtValorall.Text);
                        txtValorfin2.Text = valorTotal.ToString();
                        txtValorall.Text  = valorTotal.ToString("C2", ci);
                        txtTotalFin.Text  = valorTotal.ToString("C2", ci);
                        //txtTotalFin.Text = valorTotal.ToString("C2", ci);

                        txtCodigoB.Focus();
                        txtQuantComp.Text       = "";
                        txtPreco.Text           = "";
                        txtDesc.Text            = "";
                        txtCodigoB.Text         = "";
                        txtQuantidadeEstoq.Text = "";
                        txtVtotal.Text          = "";
                    }
                    else
                    {
                        MessageBox.Show("Adicione um quantidade!");
                    }
                }
                else
                {
                    MessageBox.Show("A quantidade ultrapassa o estoque.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //MessageBox.Show("Favor completar os espaços em branco.");
            }
        }