public List <EN.GastosVariables> GastosporAuto(string placa, DateTime inicio, DateTime final) { List <EN.GastosVariables> listaRetorno = new List <EN.GastosVariables>(); List <BR.GastosVariables> query = db.GastosVariables.Where(x => x.placa == placa && (x.fecha >= inicio.Date || x.fecha <= final.Date)).ToList(); //Group by query var resultado = from g in query group g by g.placa into gb select gb; //Recorrer la query foreach (var item in resultado) { EN.GastosVariables other = new EN.GastosVariables(); other.placa = item.Key; //Recorre el list de gastos porque es una clausua groupBy foreach (var gasto in item) { other.kilometraje = gasto.kilometraje; other.totalGastos += gasto.valor; other.numeroGastos = item.Count(); other.fecha = gasto.fecha; } this.totalGastos = other.totalGastos; listaRetorno.Add(other); } return(listaRetorno); }
public List <EN.GastosVariables> GastosporAutoRango(DateTime inicio, DateTime fin) { List <EN.GastosVariables> listaRetorno = new List <EN.GastosVariables>(); List <BR.GastosVariables> query = db.GastosVariables.Where(x => (x.fecha >= inicio && x.fecha <= fin)).ToList(); Console.WriteLine(query.Count()); //Group by query var resultado = from g in query group g by g.placa into gb select gb; //Recorrer la query foreach (var item in resultado) { EN.GastosVariables other = new EN.GastosVariables(); other.placa = item.Key; //Recorre el list de gastos porque es una clausua groupBy foreach (var gasto in item) { other.kilometraje = gasto.kilometraje; other.totalGastos += gasto.valor; other.numeroGastos = item.Count(); } listaRetorno.Add(other); } return(listaRetorno); }
public bool CrearGastoV(EN.GastosVariables other) { bool resultado = false; try { BR.GastosVariables gastoVariable = new BR.GastosVariables(other.placa, other.descripcion, other.fecha, other.kilometraje, other.valor); db.GastosVariables.Add(gastoVariable); db.SaveChanges(); resultado = true; } catch (Exception) { throw; } return(resultado); }
public bool ActualizarGastosV(EN.GastosVariables other) { bool resultado = false; try { var update = db.GastosVariables.Where(x => x.id == other.id).FirstOrDefault(); update.descripcion = other.descripcion; update.fecha = other.fecha; update.kilometraje = other.kilometraje; update.placa = other.placa; update.valor = other.valor; db.SaveChanges(); resultado = true; } catch (Exception) { throw; } return(resultado); }
private void btnCrear_Click(object sender, EventArgs e) { EN.GastosVariables gastosVariables = new EN.GastosVariables(); string[] DataTaxi = cmbTaxis.Text.Split(' '); string placa = DataTaxi[0].Trim(); if (richTextBox.Text.Length > 0 & dtpfecha.Value >= DateTime.Today & txtkilometraje.Text.Length > 0 & txtCosto.Text.Length > 0) { gastosVariables.placa = placa; gastosVariables.descripcion = richTextBox.Text; gastosVariables.fecha = dtpfecha.Value; gastosVariables.kilometraje = Convert.ToInt32(txtkilometraje.Text); gastosVariables.valor = Convert.ToInt32(txtCosto.Text); if (gastosVariablesController.CrearGastoV(gastosVariables)) { MessageBox.Show("Se Añadio el gasto con un valor de" + gastosVariables.valor); LlenarDTG(); llenarInfo(dateTimePickerDesde.Value); } } }