private void btnAdicionar2_Click(object sender, EventArgs e) { Item_pedido ped = new Item_pedido(); DataGridViewSelectedRowCollection linha = dgvProduto.SelectedRows; ped.Cod_produto = Convert.ToInt32(linha[0].Cells[0].Value); ped.Valor_por_item = Convert.ToDecimal(linha[0].Cells[2].Value); ped.Quantidade_itens = Convert.ToInt32(nudQuantidade.Value); ped.Num_comanda = txtComanda.Text; dgvPedido.AutoResizeColumns(); ped.AdicionarItem(); Pedido pedido2 = new Pedido(); pedido2.Id_comanda = Convert.ToInt32(txtComanda.Text); dgvComanda.DataSource = pedido2.PesquisaComanda(); btnEnviar.Visible = false; decimal valor_total = 0; int qtd_total = 0; foreach (DataGridViewRow dataGridViewRow in dgvComanda.Rows) { valor_total = valor_total + Convert.ToDecimal(dataGridViewRow.Cells[1].Value) * Convert.ToDecimal(dataGridViewRow.Cells[2].Value); qtd_total = qtd_total + Convert.ToInt32(dataGridViewRow.Cells[1].Value); } txtTotal.Text = valor_total.ToString(); txtQuantidade.Text = qtd_total.ToString(); }
private void SalvaItemPedido() { foreach (DataGridViewRow dataGridViewRow in dgvPedido.Rows) { Item_pedido item = new Item_pedido(); if (dataGridViewRow.Cells[0].Value != null) { item.Cod_produto = Convert.ToInt32(dataGridViewRow.Cells[0].Value); item.Valor_por_item = Convert.ToDecimal(dataGridViewRow.Cells[2].Value); item.Quantidade_itens = Convert.ToInt32(dataGridViewRow.Cells[3].Value); item.Num_comanda = txtComanda.Text; item.AdicionarItem(); } } }