public List <Abastecimento> BuscarTodos(long cnpj) { List <Abastecimento> abastecimentos = new List <Abastecimento>(); string query = "SELECT [ABS_ID], [ABS_VCL_PLACA], [ABS_SERVEXT_CNPJ], [ABS_TIPO], [ABS_LITROS], [ABS_VALOR], [ABS_DATA]" + "FROM[TB_ABASTECIMENTO] WHERE [ABS_SERVEXT_CNPJ] = " + cnpj; try { DataTable dt = _banco.BuscarRegistro(query); Abastecimento abastecimento = null; DataRow[] dataRows = dt.Select("[ABS_SERVEXT_CNPJ] = " + cnpj); foreach (DataRow dr in dataRows) { AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), dr["ABS_TIPO"].ToString()); long cNPJ = long.Parse(dr["ABS_SERVEXT_CNPJ"].ToString()); DateTime dataAbastecimento = Convert.ToDateTime(dr["ABS_DATA"].ToString()); double litros = double.Parse(dr["ABS_LITROS"].ToString()); double valor = double.Parse(dr["ABS_VALOR"].ToString()); abastecimento = new Abastecimento(abastecimentoTipo, valor, litros, dataAbastecimento, dr["ABS_VCL_PLACA"].ToString(), cNPJ); abastecimentos.Add(abastecimento); } return(abastecimentos); } catch (Exception) { throw new ConcorrenciaBancoException("Erro de concorrência de banco!"); } }
public List <Abastecimento> BuscarTodos(DateTime dtinicio, DateTime dtfim) { List <Abastecimento> abastecimentos = new List <Abastecimento>(); string query = "SELECT * FROM [dbo].[TB_ABASTECIMENTO] WHERE" + "((YEAR([ABS_DATAREGISTRO]) >= '" + dtinicio.Year + "' AND YEAR([ABS_DATAREGISTRO]) <= '" + dtfim.Year + "')" + "AND MONTH([ABS_DATAREGISTRO]) >= '" + dtinicio.Month + "' AND MONTH([ABS_DATAREGISTRO]) <= '" + dtfim.Month + "')"; try { DataTable dt = _banco.BuscarRegistro(query); Abastecimento abastecimento = null; DataRow[] dataRows = dt.Select(); foreach (DataRow dr in dataRows) { AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), dr["ABS_TIPO"].ToString()); long cNPJ = long.Parse(dr["ABS_SERVEXT_CNPJ"].ToString()); DateTime dataAbastecimento = Convert.ToDateTime(dr["ABS_DATA"].ToString()); double litros = double.Parse(dr["ABS_LITROS"].ToString()); double valor = double.Parse(dr["ABS_VALOR"].ToString()); abastecimento = new Abastecimento(abastecimentoTipo, valor, litros, dataAbastecimento, dr["ABS_VCL_PLACA"].ToString(), cNPJ); abastecimentos.Add(abastecimento); } return(abastecimentos); } catch (Exception) { throw new ConcorrenciaBancoException("Erro de concorrência de banco!"); } }
public Abastecimento BuscarAbastecimento(string placa, AbastecimentoTipo tipo, DateTime data) { int tipoAbastecimento = tipo.GetHashCode(); string query = "SELECT [ABS_ID], [ABS_VCL_PLACA], [ABS_SERVEXT_CNPJ], [ABS_TIPO], [ABS_LITROS], [ABS_VALOR], [ABS_DATA]" + "FROM[TB_ABASTECIMENTO] WHERE [ABS_VCL_PLACA] = '" + placa + "' AND [ABS_TIPO] = " + tipoAbastecimento + " AND [ABS_DATA] = '" + data.ToShortDateString() + "'"; try { DataTable dt = _banco.BuscarRegistro(query); Abastecimento abastecimento = null; DataRow[] dataRows = dt.Select("[ABS_VCL_PLACA] = '" + placa + "' AND [ABS_TIPO] = " + tipoAbastecimento + " AND [ABS_DATA] = '" + data.ToShortDateString() + "'"); foreach (DataRow dr in dataRows) { AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), dr["ABS_TIPO"].ToString()); long cNPJ = long.Parse(dr["ABS_SERVEXT_CNPJ"].ToString()); DateTime dataAbastecimento = Convert.ToDateTime(dr["ABS_DATA"].ToString()); double litros = double.Parse(dr["ABS_LITROS"].ToString()); double valor = double.Parse(dr["ABS_VALOR"].ToString()); abastecimento = new Abastecimento(abastecimentoTipo, valor, litros, dataAbastecimento, dr["ABS_VCL_PLACA"].ToString(), cNPJ); } return(abastecimento); } catch (Exception) { throw new ConcorrenciaBancoException("Erro de concorrência de banco!"); } }
public Abastecimento(AbastecimentoTipo tipo, double valor, double litros, DateTime data, string placa, long cNPJ) { Tipo = tipo; Valor = valor; Litros = litros; Data = data; Placa = placa; CNPJ = cNPJ; }
public Abastecimento BuscarAbastecimento(string placa, AbastecimentoTipo tipo, DateTime data) { try { return(_abastecimentoService.BuscarAbastecimento(placa, tipo, data)); } catch (ConcorrenciaBancoException) { throw new ConcorrenciaBancoException("Favor tentar novamente mais tarde."); } }
public Abastecimento BuscarAbastecimento(string placa, AbastecimentoTipo tipo, DateTime data) { try { return(_abastecimentoDAL.BuscarAbastecimento(placa, tipo, data)); } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
private void BtnCadastrarAbast_Click(object sender, EventArgs e) { if (cbPlaca.Items.Count < 1) { MessageBox.Show("Cadastre um veículo antes de realizar esta operação!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (cbServicoExterno.Items.Count < 1) { MessageBox.Show("Cadastre uma oficina antes de realizar esta operação!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (txtValor.Text == "" || txtQuantidadeLitros.Text == " . ") { MessageBox.Show("Preencha os campos corretamente!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), cbTipo.SelectedItem.ToString()); double valor = double.Parse(txtValor.Text); double quantidadeLitros = double.Parse(txtQuantidadeLitros.Text); string placa = cbPlaca.SelectedValue.ToString(); long cNPJ = Convert.ToInt64(cbServicoExterno.SelectedValue); Abastecimento abastecimento = new Abastecimento(abastecimentoTipo, valor, quantidadeLitros, dtDataAbast.Value, placa, cNPJ); try { if (_abastecimentoController.Cadastrar(abastecimento, abastecimento.Placa, abastecimento.Tipo, abastecimento.Data)) { MessageBox.Show("Cadastro realizado com Sucesso!"); cbTipo.Text = ""; dtDataAbast.Value = DateTime.Now; txtValor.Text = ""; txtQuantidadeLitros.Text = ""; cbPlaca.Text = ""; cbServicoExterno.Text = ""; } } catch (RegistroExisteException ex) { MessageBox.Show(ex.Message); } catch (TipoCombustivelException ex) { MessageBox.Show(ex.Message); } catch (ConcorrenciaBancoException ex) { MessageBox.Show(ex.Message); } } }
public bool Deletar(string placa, AbastecimentoTipo tipo, DateTime data) //Modificado { int tipoAbastecimento = tipo.GetHashCode(); string Query = "DELETE [TB_ABASTECIMENTO] WHERE [ABS_VCL_PLACA] = '" + placa + "' AND [ABS_TIPO] = " + tipoAbastecimento + " AND [ABS_DATA] = '" + data + "'"; try { return(_banco.ExecutarInstrucao(Query)); } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
public bool Alterar(Abastecimento abastecimento, string placa, AbastecimentoTipo tipo, DateTime data) { try { return(_abastecimentoService.Alterar(abastecimento, placa, tipo, data)); } catch (NaoEncontradoException e) { throw new NaoEncontradoException(e.Message); } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
public bool Deletar(string placa, AbastecimentoTipo tipo, DateTime data) { try { return(_abastecimentoService.Deletar(placa, tipo, data)); } catch (IntegridadeException e) { throw new IntegridadeException(e.Message); } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
public bool Cadastrar(Abastecimento abastecimento, string placa, AbastecimentoTipo tipo, DateTime data) { try { return(_abastecimentoService.Cadastrar(abastecimento, placa, tipo, data)); } catch (RegistroExisteException e) { throw new RegistroExisteException(e.Message); } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
private void BtnExcluirAbast_Click(object sender, EventArgs e) { if (cbPlaca.Items.Count < 1) { MessageBox.Show("Cadastre um veículo antes de realizar esta operação!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (cbServicoExterno.Items.Count < 1) { MessageBox.Show("Cadastre uma oficina antes de realizar esta operação!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), cbTipo.SelectedItem.ToString()); string placa = cbPlaca.SelectedValue.ToString(); try { if (MessageBox.Show("Deseja realmente excluir?", "Sair", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (_abastecimentoController.Deletar(placa, abastecimentoTipo, dtDataAbast.Value)) { MessageBox.Show("Exclusão realizada com Sucesso!"); cbTipo.SelectedItem = cbTipo.Items[0]; dtDataAbast.Value = DateTime.Now; txtValor.Text = ""; txtQuantidadeLitros.Text = ""; cbPlaca.SelectedItem = cbPlaca.Items[0]; cbServicoExterno.SelectedItem = cbServicoExterno.Items[0]; btnCadastrarAbast.Visible = true; lblCancelar.Visible = false; btnAlterarAbast.Enabled = false; btnExcluirAbast.Enabled = false; } } } catch (IntegridadeException ex) { MessageBox.Show(ex.Message); } catch (ConcorrenciaBancoException ex) { MessageBox.Show(ex.Message); } } }
private void BtnConsultarAbast_Click(object sender, EventArgs e) { if (cbPlacaAbastConsulta.Items.Count < 1) { MessageBox.Show("Cadastre um veículo antes de realizar esta operação!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { try { AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), cbTipoAbastConsulta.SelectedItem.ToString()); string placa = cbPlacaAbastConsulta.SelectedValue.ToString(); Abastecimento abastecimento = _abastecimentoController.BuscarAbastecimento(placa, abastecimentoTipo, dtDataAbastConsulta.Value); if (abastecimento == null) { dgVeiculoAbast.DataSource = null; } else { DataTable dt = new DataTable(); dt.Columns.Add("Placa", typeof(string)); dt.Columns.Add("CNPJ", typeof(long)); dt.Columns.Add("Tipo Combustível", typeof(string)); dt.Columns.Add("Quantidade (Litros)", typeof(double)); dt.Columns.Add("Valor (Total)", typeof(double)); dt.Columns.Add("Data", typeof(DateTime)); dt.Rows.Add(abastecimento.Placa, abastecimento.CNPJ, abastecimento.Tipo.ToString(), abastecimento.Litros, abastecimento.Valor , abastecimento.Data); dgVeiculoAbast.DataSource = dt; Abastecimento = abastecimento; ListaAbastecimentos = new List <Abastecimento>(); ListaAbastecimentos.Add(abastecimento); abastecimento = null; } } catch (ConcorrenciaBancoException ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
public bool Alterar(Abastecimento abastecimento, string placa, AbastecimentoTipo tipo, DateTime data) { try { Abastecimento obj = _abastecimentoDAL.BuscarAbastecimento(placa, tipo, data); if (obj != null) { Veiculo veiculo = _veiculoDAL.BuscarPlaca(placa); AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), veiculo.Combustivel.ToString()); if (abastecimentoTipo == AbastecimentoTipo.Flex) { if (abastecimento.Tipo == AbastecimentoTipo.Gasolina || abastecimento.Tipo == AbastecimentoTipo.Etanol || abastecimento.Tipo == AbastecimentoTipo.Gasolina_Aditivada) { return(_abastecimentoDAL.Alterar(abastecimento, placa, tipo, data)); } else { throw new TipoCombustivelException("Combustível escolhido é incompatível com o veículo!"); } } else if (abastecimentoTipo == abastecimento.Tipo) { return(_abastecimentoDAL.Alterar(abastecimento, placa, tipo, data)); } else { throw new TipoCombustivelException("Combustível escolhido é incompatível com o veículo!"); } } else { throw new NaoEncontradoException("Abastecimento não encontrado."); } } catch (TransacaoException e) { throw new TransacaoException(e.Message); } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
public bool Alterar(Abastecimento abastecimento, string placa, AbastecimentoTipo tipo, DateTime data) // Modificado { int tipoAbastecimento = abastecimento.Tipo.GetHashCode(); int tipoAbastecimentoAntigo = tipo.GetHashCode(); string Query = "UPDATE TB_ABASTECIMENTO SET [ABS_VCL_PLACA] = '" + abastecimento.Placa + "', [ABS_SERVEXT_CNPJ] = " + abastecimento.CNPJ + " ,[ABS_TIPO] = " + tipoAbastecimento + ",[ABS_LITROS] = " + abastecimento.Litros + ",[ABS_VALOR] = " + abastecimento.Valor + ",[ABS_DATA] = '" + abastecimento.Data + "' WHERE [ABS_VCL_PLACA] = '" + placa + "' AND [ABS_TIPO] = " + tipoAbastecimentoAntigo + " AND [ABS_DATA] = '" + data + "'"; try { return(_banco.ExecutarInstrucao(Query)); } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
public bool Deletar(string placa, AbastecimentoTipo tipo, DateTime data) { try { if (_abastecimentoDAL.Deletar(placa, tipo, data)) { return(true); } else { throw new IntegridadeException("Abastecimento não pode ser deletado, pois ainda está vinculado à outros serviços."); } } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
public IHttpActionResult Get(string placa, AbastecimentoTipo tipo, DateTime data) { try { var result = _abastecimentoService.BuscarAbastecimento(placa, tipo, data); if (result == null) { return(BadRequest("Abastecimento não encontrado!")); } else { return(Ok(result)); } } catch (ConcorrenciaBancoException) { return(BadRequest("Favor tentar novamente mais tarde.")); } }
public bool Cadastrar(Abastecimento abastecimento, string placa, AbastecimentoTipo tipo, DateTime data) //Mudança na Query, Verificar { try { Abastecimento obj = _abastecimentoDAL.BuscarAbastecimento(placa, tipo, data); if (obj != null) { throw new RegistroExisteException("Já existe uma Manutenção com esses dados no sistema!"); } else { Veiculo veiculo = _veiculoDAL.BuscarPlaca(placa); AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), veiculo.Combustivel.ToString()); if (abastecimentoTipo == AbastecimentoTipo.Flex) { if (abastecimento.Tipo == AbastecimentoTipo.Gasolina || abastecimento.Tipo == AbastecimentoTipo.Etanol || abastecimento.Tipo == AbastecimentoTipo.Gasolina_Aditivada) { return(_abastecimentoDAL.Cadastrar(abastecimento)); } else { throw new TipoCombustivelException("Combustível escolhido é incompatível com o veículo!"); } } else if (abastecimentoTipo == abastecimento.Tipo) { return(_abastecimentoDAL.Cadastrar(abastecimento)); } else { throw new TipoCombustivelException("Combustível escolhido é incompatível com o veículo!"); } } } catch (ConcorrenciaBancoException e) { throw new ConcorrenciaBancoException(e.Message); } }
private void BtnAlterarAbast_Click(object sender, EventArgs e) { if (cbPlaca.Items.Count < 1) { MessageBox.Show("Cadastre um veículo antes de realizar esta operação!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (cbServicoExterno.Items.Count < 1) { MessageBox.Show("Cadastre uma oficina antes de realizar esta operação!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (txtValor.Text == "" || txtQuantidadeLitros.Text == "") { MessageBox.Show("Preencha os campos corretamente!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { AbastecimentoTipo abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), cbTipo.SelectedItem.ToString()); double valor = double.Parse(txtValor.Text); double quantidadeLitros = double.Parse(txtQuantidadeLitros.Text); string placa = cbPlaca.SelectedValue.ToString(); long cNPJ = Convert.ToInt64(cbServicoExterno.SelectedValue); Abastecimento abastecimento = new Abastecimento(abastecimentoTipo, valor, quantidadeLitros, dtDataAbast.Value, placa, cNPJ); try { if (PlacaAntiga == "") { PlacaAntiga = abastecimento.Placa; } if (dataAntiga == new DateTime(2000, 01, 01)) { dataAntiga = abastecimento.Data; } if (TipoAntigo == "") { abastecimentoTipo = abastecimento.Tipo; TipoAntigo = abastecimentoTipo.ToString(); } else { abastecimentoTipo = (AbastecimentoTipo)Enum.Parse(typeof(AbastecimentoTipo), TipoAntigo); } if (_abastecimentoController.Alterar(abastecimento, PlacaAntiga, abastecimentoTipo, dataAntiga)) { MessageBox.Show("Alteração realizada com Sucesso!"); PlacaAntiga = ""; TipoAntigo = ""; dataAntiga = new DateTime(2000, 01, 01); cbTipo.SelectedItem = cbTipo.Items[0]; dtDataAbast.Value = DateTime.Now; txtValor.Text = ""; txtQuantidadeLitros.Text = ""; cbPlaca.SelectedItem = cbPlaca.Items[0]; cbServicoExterno.SelectedItem = cbServicoExterno.Items[0]; btnCadastrarAbast.Visible = true; lblCancelar.Visible = false; btnAlterarAbast.Enabled = false; btnExcluirAbast.Enabled = false; } } catch (NaoEncontradoException ex) { MessageBox.Show(ex.Message); } catch (TipoCombustivelException ex) { MessageBox.Show(ex.Message); } catch (ConcorrenciaBancoException ex) { MessageBox.Show(ex.Message); } } }