protected void btn_AlterarStatus_Click(object sender, EventArgs e) { try { Button btn = sender as Button; using (DatabaseEntities context = new DatabaseEntities()) { int id = int.Parse(btn.CommandArgument); ServicosOrcamento servico = context.ServicosOrcamento.Where(so => so.idOrcamento == o.idOrcamento && so.idServico == id).FirstOrDefault(); if (servico.status.Equals("Pendente")) { servico.status = "Em execução"; } else if (servico.status.Equals("Em execução")) { servico.status = "Concluído"; } else if (servico.status.Equals("Concluído")) { servico.status = "Pendente"; } context.SaveChanges(); preencherTabela(); } } catch (Exception ex) { pnl_Alert.CssClass = "alert alert-danger"; lbl_Alert.Text = "Erro: " + ex.Message + Environment.NewLine + "Por favor entre em contato com o suporte"; pnl_Alert.Visible = true; } }
protected void btn_Cadastro_Click(object sender, EventArgs e) { if (servicosSelecionados.Count == 0) { pnl_Alert.CssClass = "alert alert-danger"; lbl_Alert.Text = "Insira no mínimo 1 serviço"; pnl_Alert.Visible = true; } else { if (txt_Veiculo.Enabled == false) { pnl_Alert.CssClass = "alert alert-danger"; lbl_Alert.Text = "Informe um cliente com no mínimo 1 veículo cadastrado"; pnl_Alert.Visible = true; } else { try { using (DatabaseEntities context = new DatabaseEntities()) { int id = int.Parse(txt_Veiculo.SelectedValue); Veiculo veiculo = context.Veiculo.Where(v => v.idVeiculo == id).FirstOrDefault(); Cliente cliente = veiculo.Cliente; Funcionario funcionario = context.Funcionario.Where(f => f.cpf.Equals(c.cpf)).FirstOrDefault(); Oficina oficina = funcionario.Oficina; DateTime data = DateTime.Now; Double total = atualizarTotal(); String status = "Aprovação da gerencia pendente"; Produto prod; if (total <= 0) { pnl_Alert.CssClass = "alert alert-danger"; lbl_Alert.Text = "Orçamento com valor inválido"; pnl_Alert.Visible = true; } else { Orcamento orcamento = new Orcamento() { valor = total, data = data, status = status, cpfFuncionario = funcionario.cpf, cnpjOficina = oficina.cnpj, idVeiculo = veiculo.idVeiculo, cpfCliente = cliente.cpf, }; context.Orcamento.Add(orcamento); context.SaveChanges(); ServicosOrcamento so; foreach (Servico s in servicosSelecionados) { so = new ServicosOrcamento() { idOrcamento = orcamento.idOrcamento, idServico = s.idServico, status = "Pendente" }; context.ServicosOrcamento.Add(so); context.SaveChanges(); } if (produtosSelecionados.Count > 0) { ProdutosOrcamento po; foreach (Produto p in produtosSelecionados.Keys) { po = new ProdutosOrcamento() { idOrcamento = orcamento.idOrcamento, idProduto = p.idProduto, quantidade = produtosSelecionados[p] }; context.ProdutosOrcamento.Add(po); context.SaveChanges(); prod = context.Produto.Where(produto => produto.idProduto == p.idProduto).FirstOrDefault(); prod.quantidade -= po.quantidade; context.SaveChanges(); } } clearForm(); pnl_Alert.CssClass = "alert alert-success"; lbl_Alert.Text = "Orçamento criado com sucesso"; pnl_Alert.Visible = true; } } } catch (Exception ex) { pnl_Alert.CssClass = "alert alert-danger"; lbl_Alert.Text = "Erro: " + ex.Message + Environment.NewLine + "Por favor entre em contato com o suporte"; pnl_Alert.Visible = true; } } } }