Пример #1
0
 private void btnInserir_Click(object sender, EventArgs e)
 {
     if (txtNovQuant.Text == "")
     {
         MessageBox.Show("Insira uma quantidade!");
     }
     else if (txtNovQuant.Text == "0")
     {
         MessageBox.Show("Insira uma quantidade!");
     }
     else
     {
         int quantidadenova         = Convert.ToInt32(txtNovQuant.Text);
         int quantold               = Convert.ToInt32(txtquatold.Text);
         int quantidadetotal        = quantold + quantidadenova;
         ProdutoTableAdapter taProd = new ProdutoTableAdapter();
         taProd.UpdateEstoque(quantidadetotal, Convert.ToInt64(txtCodB.Text));
         MessageBox.Show("Quantidade Atualizada com Sucesso!");
         txtCodB.Text     = "";
         txtDesc.Text     = "";
         txtNovQuant.Text = "";
         txtquatold.Text  = "";
         txtValor.Text    = "";
     }
 }
Пример #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.");
            }
        }