private void BindEstados() { var estados = DAOFactory.EstadoDAO.GetByPlanta(cbLinea.Selected); gridEstados.DataSource = estados; gridEstados.DataBind(); var delta = DeltaTime.Get(); delta.AddRange(from Estado estado in estados select TimeSpan.FromMinutes(estado.Deltatime)); if (delta.Count.Equals(0)) { return; } delta[0] = TimeSpan.Zero; DeltaTime.Set(delta); if (gridEstados.Rows.Count > 0) { if (gridEstados != null) { ((TextBox)gridEstados.Rows[0].FindControl("txtHoraEstado")).Text = StartDate.Get().ToString("HH:mm"); } } if (EditMode) { var dic = GetDiccionarioEstados(); if (gridEstados != null) { foreach (C1GridViewRow item in gridEstados.Rows) { var id = Convert.ToInt32(gridEstados.DataKeys[item.RowIndex].Value); if (!dic.ContainsKey(id)) { continue; } var est = dic[id]; var chk = item.FindControl("chkIncluirEstado") as CheckBox; var txt = item.FindControl("txtHoraEstado") as TextBox; var lbl = item.FindControl("lblDiaProgramado") as Label; if (est.Programado == null) { continue; } var programado = est.Programado.Value.ToDisplayDateTime(); if (chk != null) { chk.Checked = true; } if (txt != null) { txt.Text = programado.ToString("HH:mm"); } if (lbl != null) { lbl.Text = programado.ToString("dd-MM-yyyy"); } if (est.Manual.HasValue) { var manual = est.Manual.Value.ToDisplayDateTime(); item.Cells[3].Text = string.Format("{0} ({1}m)", manual.ToString("dd-MM-yyyy HH:mm"), programado.Subtract(manual).TotalMinutes.ToString("0")); } if (!est.Automatico.HasValue) { continue; } var auto = est.Automatico.Value.ToDisplayDateTime(); item.Cells[4].Text = string.Format("{0} ({1}m)", auto.ToString("dd-MM-yyyy HH:mm"), programado.Subtract(auto).TotalMinutes.ToString("0")); } } } if (!EditMode) { RecalcularHoras(0); } }
private void RecalcularHoras(int index) { var delta = GetDeltas(); DeltaTime.Set(delta); var d = StartDate.Get(); var saleDePlanta = DateTime.MinValue; var saleDeObra = DateTime.MinValue; var coche = cbMovil.Selected > 0 ? DAOFactory.CocheDAO.FindById(cbMovil.Selected) : null; var velocidadPromedio = coche != null ? (coche.VelocidadPromedio > 0 ? coche.VelocidadPromedio : (coche.TipoCoche.VelocidadPromedio > 0 ? coche.TipoCoche.VelocidadPromedio : 20)) : 20; var direccionLinea = GetDireccionLinea(); var direccionMapa = GetDireccionPuntoDeEntrega(); foreach (C1GridViewRow item in gridEstados.Rows) { var estadoId = (int)gridEstados.DataKeys[item.RowIndex].Value; var estado = DAOFactory.EstadoDAO.FindById(estadoId); if (estado.EsPuntoDeControl == 5) { saleDePlanta = d; //Sale de Planta } if (estado.EsPuntoDeControl == 7) { saleDeObra = d; //Sale de Obra } //if (item.RowIndex == 0) continue; if (item.RowIndex <= index) { var txt = item.FindControl("txtHoraEstado") as TextBox; if (txt != null) { d = GetHours(txt.Text, d); } continue; } if (estado.EsPuntoDeControl == 6 && saleDePlanta != DateTime.MinValue) { //Llega a Obra var distancia = direccionLinea != null && direccionMapa != null? GeocoderHelper.CalcularDistacia(direccionLinea.Latitude, direccionLinea.Longitude, direccionMapa.Latitude, direccionMapa.Longitude) : 0; var horas = distancia / velocidadPromedio; d = d.Add(horas > 0 ? TimeSpan.FromHours(horas) : delta[item.RowIndex]); var txt = item.FindControl("txtHoraEstado") as TextBox; var lbl = item.FindControl("lblDiaProgramado") as Label; if (txt != null) { txt.Text = d.ToString("HH:mm"); } if (lbl != null) { lbl.Text = d.ToString("dd-MM-yyyy"); } } else if (estado.EsPuntoDeControl == 8 && saleDeObra != DateTime.MinValue) { ////Llega a Planta var distancia = direccionLinea != null && direccionMapa != null? GeocoderHelper.CalcularDistacia(direccionMapa.Latitude, direccionMapa.Longitude, direccionLinea.Latitude, direccionLinea.Longitude) : 0; var horas = distancia / velocidadPromedio; d = d.Add(horas > 0 ? TimeSpan.FromHours(horas) : delta[item.RowIndex]); var txt = item.FindControl("txtHoraEstado") as TextBox; var lbl = item.FindControl("lblDiaProgramado") as Label; if (txt != null) { txt.Text = d.ToString("HH:mm"); } if (lbl != null) { lbl.Text = d.ToString("dd-MM-yyyy"); } } else { //Normal d = d.Add(delta[item.RowIndex]); var txt = item.FindControl("txtHoraEstado") as TextBox; var lbl = item.FindControl("lblDiaProgramado") as Label; if (txt != null) { txt.Text = d.ToString("HH:mm"); } if (lbl != null) { lbl.Text = d.ToString("dd-MM-yyyy"); } } } updGridEstados.Update(); }