示例#1
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                string qtdCancelada = dgvPedido.CurrentRow.Cells[3].Value.ToString();
                txtCancelado.Text = qtdCancelada;
                string codPro = dgvPedido.CurrentRow.Cells[0].Value.ToString();
                txtCodBarra2.Text = codPro;
                dgvPedido.Rows.Remove(dgvPedido.CurrentRow);
                decimal total = 0;
                int     i     = 0;
                for (i = 0; i < dgvPedido.Rows.Count; i++)
                {
                    total = total + Convert.ToDecimal(dgvPedido.Rows[i].Cells["Total"].Value);
                }
                txtVtotal.Text = "R$" + (total).ToString();
                ProdutoTableAdapter taProduto = new ProdutoTableAdapter();
                DataTable           dt;
                dt = taProduto.PesquisaCodBarra(Convert.ToInt64(txtCodBarra2.Text));
                txtQuantestoq.Text = dt.Rows[0]["Quantidade_Produto"].ToString();
                int voltestoq = Convert.ToInt32(txtQuantestoq.Text) + Convert.ToInt32(txtCancelado.Text);
                taProduto.RetornarEstoque(voltestoq, Convert.ToInt64(txtCodBarra2.Text));

                CultureInfo ci         = new CultureInfo("pt-BR");
                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);
                ItemPedidoTableAdapter taitem = new ItemPedidoTableAdapter();
                taitem.DeleteQuery(int.Parse(txtNumPedido.Text));


                txtCodigoB.Focus();
                txtQuantComp.Text       = "";
                txtPreco.Text           = "";
                txtDesc.Text            = "";
                txtCodigoB.Text         = "";
                txtQuantidadeEstoq.Text = "";
                txtVtotal.Text          = "";
            }
            catch
            {
                MessageBox.Show("Favor selecionar uma linha para ser cancelada.");
            }
        }