public ActionResult Delete(int id, AgendamentoVW model) { try { AgendamentosDAO dao = new AgendamentosDAO(); dao.DeleteAgendamento(id); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult FinalizarHorario(int id, AgendamentoVW model) { try { var vendaDAO = new VendaProdutoDAO(); vendaDAO.insertVenda(id, model); vendaDAO.updateAgenda(id); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Cancelar(int id, AgendamentoVW model) { try { AgendamentosDAO dao = new AgendamentosDAO(); var aganda = dao.GetAgendamento(id); var bean = model.GetAgenda(aganda); bean.dtUltAlteracao = DateTime.Now; dao.CancelarAgendamento(bean); return(RedirectToAction("Index")); } catch { return(View()); } }
private ActionResult GetView(int id) { AgendamentosDAO objAgenda = new AgendamentosDAO(); ClienteDAO DAOCliente = new ClienteDAO(); FuncionarioDAO DAOFuncionario = new FuncionarioDAO(); ServicoDAO DAOServico = new ServicoDAO(); var obj = objAgenda.GetAgendamento(id); var result = new AgendamentoVW { IdModelPai = obj.IdAgenda, //idAgenda = obj.IdAgenda, //dtNota = obj.dtAgendamento, dtAgendamento = obj.dtAgendamento, flhoraAgendamento = obj.flhoraAgendamento, flSituação = obj.flSituacao, IdCliente = obj.IdCliente, IdServico = obj.IdServico, IdFuncionario = obj.IdFuncionario, dtCadastro = obj.dtCadastro, dtUltAlteracao = obj.dtUltAlteracao }; var objFuncionario = DAOFuncionario.DAOGetFuncionario(result.IdFuncionario); result.Funcionario = new ViewModels.Funcionarios.SelectFuncionarioVM { IdFuncionario = objFuncionario.IdFuncionario, nmFuncionario = objFuncionario.nmFuncionario }; var objCliente = DAOCliente.DAOGetCliente(result.IdCliente); result.Cliente = new ViewModels.Clientes.SelectClienteVM { IdCliente = objCliente.IdCliente, nmCliente = objCliente.nmCliente }; var objServico = DAOServico.GetServico(result.IdServico); result.Servico = new ViewModels.Servicos.SelectServicoVM { IdServico = objServico.IdServico, dsServico = objServico.dsServico, vlServico = Convert.ToDecimal(objServico.vlServico) }; return(View(result)); }
public bool insertVenda(int id, AgendamentoVW venda) { int i = 0; Open(); SqlTransaction sqlTransaction = sqlconnection.BeginTransaction(); SqlCommand command; try { command = sqlconnection.CreateCommand(); command.Transaction = sqlTransaction; if (venda.VendaServico.nrModelo != null) { command.CommandText = "INSERT INTO Venda ( nrModelo, nrSerie, flSituacao, IdCliente, IdCondPag, dtEmissao, dtCadastro, vlTotal )" + "VALUES(@nrModelo, @nrSerie, @flSituacao, @IdCliente, @IdCondPag, @dtEmissao, @dtCadastro, @vlTotal );SELECT CAST(SCOPE_IDENTITY() AS int)"; command.Parameters.AddWithValue("@nrModelo", venda.VendaServico.nrModelo); command.Parameters.AddWithValue("@nrSerie", venda.VendaServico.nrSerie); command.Parameters.AddWithValue("@flSituacao", venda.flSituacao = "A"); command.Parameters.AddWithValue("@IdCliente", venda.Cliente.IdCliente); //command.Parameters.AddWithValue("@IdAgenda", id); command.Parameters.AddWithValue("@IdCondPag", venda.CondicaoPagamento.Id); command.Parameters.AddWithValue("@dtEmissao", venda.dtAgendamento = DateTime.Now); command.Parameters.AddWithValue("@vlTotal", venda.vlTotalProduto); command.Parameters.AddWithValue("@dtcadastro", venda.dtCadastro = DateTime.Now); command.Parameters.AddWithValue("@dtUltAlteracao", venda.dtUltAlteracao = DateTime.Now); Int32 idvendaServico = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "INSERT INTO ServicoVenda ( nrModelo , nrSerie , nrNota , IdServico , vlVenda)" + " VALUES( @nrModelo , @nrSerie , @nrNota , @IdServico , @vlVenda)"; command.Parameters.Clear(); command.Parameters.AddWithValue("@nrModelo", venda.VendaServico.nrModelo); command.Parameters.AddWithValue("@nrSerie", venda.VendaServico.nrSerie); command.Parameters.AddWithValue("@nrNota", idvendaServico); command.Parameters.AddWithValue("@IdServico", venda.Servico.IdServico); command.Parameters.AddWithValue("@vlVenda", venda.vlTotalServico); //i = command.ExecuteNonQuery(); foreach (var item in venda.ParcelasVenda) { command = sqlconnection.CreateCommand(); command.Transaction = sqlTransaction; command.CommandText = "INSERT INTO ContasReceber ( nrModelo, nrSerie, nrNota, IdCliente, IdFormaPagamento, nrparcela, vlParcela, flSituacao, dtVencimento )" + "VALUES(@nrModelo, @nrSerie, @nrNota, @IdCliente, @IdFormaPagamento, @nrparcela, @vlParcela, @flSituacao, @dtVencimento )"; command.Parameters.Clear(); command.Parameters.AddWithValue("@nrModelo", venda.VendaServico.nrModelo); command.Parameters.AddWithValue("@nrSerie", venda.VendaServico.nrSerie); command.Parameters.AddWithValue("@nrNota", idvendaServico); command.Parameters.AddWithValue("@IdCliente", venda.Cliente.IdCliente); command.Parameters.AddWithValue("@IdFormaPagamento", item.IdFormaPagamento); command.Parameters.AddWithValue("@vlParcela", item.vlParcela); command.Parameters.AddWithValue("@flSituacao", item.flSituacao = "A"); command.Parameters.AddWithValue("@dtVencimento", item.dtVencimento); command.Parameters.AddWithValue("@nrparcela", item.nrParcela); i = command.ExecuteNonQuery(); } } if (venda.VendaProduto.nrModelo != null) { command.CommandText = "INSERT INTO Venda ( nrModelo, nrSerie, flSituacao, IdCliente, IdCondPag, dtEmissao, dtCadastro, dtUltAlteracao, vlTotal)" + "VALUES(@nrModelo, @nrSerie, @flSituacao, @IdCliente,@IdCondPag, @dtEmissao, @dtCadastro, @dtUltAlteracao, @vlTotal);SELECT CAST(SCOPE_IDENTITY() AS int)"; command.Parameters.Clear(); command.Parameters.AddWithValue("@nrModelo", venda.VendaProduto.nrModelo); command.Parameters.AddWithValue("@nrSerie", venda.VendaProduto.nrSerie); command.Parameters.AddWithValue("@flSituacao", venda.flSituacao); command.Parameters.AddWithValue("@IdCliente", venda.Cliente.IdCliente); command.Parameters.AddWithValue("@IdCondPag", venda.CondicaoPagamento.Id); //command.Parameters.AddWithValue("@IdAgenda", id); command.Parameters.AddWithValue("@dtEmissao", venda.dtAgendamento); command.Parameters.AddWithValue("@vlTotal", venda.vlTotalServico); command.Parameters.AddWithValue("@dtcadastro", venda.dtCadastro = DateTime.Now); command.Parameters.AddWithValue("@dtUltAlteracao", venda.dtUltAlteracao = DateTime.Now); Int32 idvendaProduto = Convert.ToInt32(command.ExecuteScalar()); //i = command.ExecuteNonQuery(); foreach (var item in venda.ProdutosCompra) { command.CommandText = "INSERT INTO ProdutoVenda ( nrModelo, nrSerie, nrNota, IdProduto, nrQtd, vlVenda)" + " VALUES( @nrModelo, @nrSerie, @nrNota, @IdProduto, @nrQtd, @vlVenda)"; command.Parameters.Clear(); command.Parameters.AddWithValue("@nrModelo", venda.VendaProduto.nrModelo); command.Parameters.AddWithValue("@nrSerie", venda.VendaProduto.nrSerie); command.Parameters.AddWithValue("@nrNota", idvendaProduto); command.Parameters.AddWithValue("@IdProduto", item.IdProduto); command.Parameters.AddWithValue("@nrQtd", item.nrQtd); command.Parameters.AddWithValue("@vlVenda", item.vlVenda); i = command.ExecuteNonQuery(); } foreach (var item in venda.ParcelasVendaProduto) { command = sqlconnection.CreateCommand(); command.Transaction = sqlTransaction; command.CommandText = "INSERT INTO ContasReceber ( nrModelo , nrSerie , nrNota , IdCliente , IdFormaPagamento , nrparcela , vlParcela , flSituacao , dtVencimento)" + "VALUES(@nrModelo , @nrSerie , @nrNota , @IdCliente , @IdFormaPagamento , @nrparcela , @vlParcela , @flSituacao , @dtVencimento)"; command.Parameters.Clear(); command.Parameters.AddWithValue("@nrModelo", venda.VendaProduto.nrModelo); command.Parameters.AddWithValue("@nrSerie", venda.VendaProduto.nrSerie); command.Parameters.AddWithValue("@nrNota", idvendaProduto); command.Parameters.AddWithValue("@IdCliente", venda.Cliente.IdCliente); command.Parameters.AddWithValue("@IdFormaPagamento", item.IdFormaPagamento); command.Parameters.AddWithValue("@vlParcela", item.vlParcela); command.Parameters.AddWithValue("@flSituacao", item.flSituacao = "A"); command.Parameters.AddWithValue("@dtVencimento", item.dtVencimento); command.Parameters.AddWithValue("@nrparcela", item.nrParcela); i = command.ExecuteNonQuery(); } } sqlTransaction.Commit(); if (i >= 1) { return(true); } else { return(false); } } catch (Exception ex) { sqlTransaction.Rollback(); throw new Exception("Erro ao inserir o venda: " + ex.Message); } finally { Close(); } }