private void FinalizarOrcamento(object o, EventArgs e) { try { BLL.Orcamento or = new BLL.Orcamento(); or.CodigoCliente = Codigo; or.CodigoFuncionario = CodigoVendedor; or.DataOrcamento = DateTime.Today; foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>() .Where(t => !string.IsNullOrEmpty(t.Cells["ValorTot"].Value?.ToString()))) { totalOrcamento += Convert.ToDecimal(row.Cells["ValorTot"].Value); } or.ValorTotal = Convert.ToDouble(totalOrcamento); or.IncluirComParametro(); SalvarProdutosOrcamento(); MessageBox.Show("Orçamento finalizado com sucesso"); GerarPDF3(o, e); Close(); } catch (Exception ex) { throw ex; } }
private void SalvarProdutosOrcamento() { BLL.Orcamento v = new BLL.Orcamento(); int CodigoUltimoOrcamento = v.RetornarOrcamento(); int CodigoProdutoGrid = 0; //foreachzinho para pegar linha por linha e depois ir inserindo na tabela linha por linha foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>() .Where(t => !string.IsNullOrEmpty(t.Cells["CodProd"].Value?.ToString()))) { try { CodigoProdutoGrid = Convert.ToInt32(row.Cells["CodProd"].Value); TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados(); string comando; SqlParameter[] listaComParametros = { new SqlParameter("@CodigoOrcamento", SqlDbType.Int) { Value = CodigoUltimoOrcamento }, new SqlParameter("@CodigoProduto", SqlDbType.Int) { Value = CodigoProdutoGrid }, }; comando = "INSERT INTO tbItem_Orcamento(CodigoOrcamento,CodigoProduto) Values (@CodigoOrcamento,@CodigoProduto)"; c.ExecutarComandoParametro(comando, listaComParametros); } catch (Exception ex) { throw ex; } } }