private void BtnSalvar_Click(object sender, RoutedEventArgs e) { if (txtNumero.Text != null && cboStatus.Text != null && txtProjeto.Text != "" && cboCliente.Text != null) { orcamento.servico = listaItensServicos; orcamento.material = listaItensMateriais; itensOrcamento io = new itensOrcamento { orcamento = orcamento }; listaItensOrcamentos.Add(io); int idCliente = Convert.ToInt32(cboCliente.SelectedValue); projetoNovo.NumeroProjeto = txtNumero.Text; projetoNovo.NomeProjeto = txtProjeto.Text.ToUpper(); projetoNovo.Status = cboStatus.SelectedIndex.ToString(); projetoNovo.Cliente = ClienteDao.BuscarClientePorId(idCliente); projetoNovo.listaOrcamento = listaItensOrcamentos; if (ProjetoDao.CadastrarProjeto(projetoNovo)) { MessageBox.Show("Projeto Cadastrado!", "Sistema Orcamento", MessageBoxButton.OK, MessageBoxImage.Information); btnSalvar.Visibility = Visibility.Hidden; btnCancelar.Visibility = Visibility.Hidden; btnNovo.IsEnabled = true; txtNumero.Text = ""; txtNumero.IsEnabled = true; txtNumero.Focus(); txtProjeto.Text = ""; txtProjeto.IsEnabled = false; cboStatus.SelectedIndex = -1; cboStatus.IsEnabled = false; cboCliente.SelectedIndex = -1; cboCliente.IsEnabled = false; } else { MessageBox.Show("Já Exite um Projeto com Este Número", "Sistema Orcamento", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Por favor Preencha todos os campos!"); } }
public static bool CadastrarOrcamento(Projeto projeto) { itensOrcamento io = new itensOrcamento { orcamento = orcamento1 }; projeto.listaOrcamento.Add(io); ctx.Projetos.Add(projeto); //ctx.Entry(projeto).State = EntityState.Modified; ctx.SaveChanges(); return(true); }