protected void BtnModificar_Click(object sender, EventArgs e) { try { //*ini*lrojas:05092016 validacion fecha retorno DB_VT_Solicitud sol = new DB_VT_Solicitud(); List <VT_SolicitudDestino> ColSD = new List <VT_SolicitudDestino>(); foreach (GridViewRow dgi in GVSolicitud.Rows) { VT_SolicitudDestino Objsd = new VT_SolicitudDestino(); DropDownList ddlZona = (DropDownList)dgi.Cells[3].Controls[1]; DropDownList ddlDestino = (DropDownList)dgi.Cells[4].Controls[1]; TextBox txLugar = (TextBox)dgi.Cells[5].Controls[1]; TextBox txObjetivo = (TextBox)dgi.Cells[6].Controls[1]; TextBox tx2 = (TextBox)dgi.Cells[7].Controls[1]; DropDownList ddlHora = (DropDownList)dgi.Cells[8].Controls[1]; DropDownList ddlMin = (DropDownList)dgi.Cells[9].Controls[1]; DropDownList ddlVia_Transporte = (DropDownList)dgi.Cells[10].Controls[1]; DropDownList ddlTipo_Transporte = (DropDownList)dgi.Cells[11].Controls[1]; TextBox txNombre_Transporte = (TextBox)dgi.Cells[12].Controls[1]; TextBox txIdentificador_Trasporte = (TextBox)dgi.Cells[13].Controls[1]; Objsd.Id_Solicitud = LblIdSolicitud.Text; Objsd.Cont = Convert.ToInt32(GVSolicitud.DataKeys[dgi.RowIndex].Values[0]); Objsd.Tramo = dgi.Cells[2].Text; Objsd.Zona = ddlZona.SelectedValue; Objsd.Destino = ddlDestino.SelectedValue; Objsd.Lugar = txLugar.Text; Objsd.Objetivo = txObjetivo.Text; Objsd.Fecha_Salida = Convert.ToDateTime(tx2.Text + " " + ddlHora.SelectedValue + ":" + ddlMin.SelectedValue); Objsd.Via_Transporte = ddlVia_Transporte.SelectedValue; Objsd.Tipo_Transporte = ddlTipo_Transporte.SelectedValue; Objsd.Nombre_Transporte = txNombre_Transporte.Text; Objsd.Identificador_Trasporte = txIdentificador_Trasporte.Text; ColSD.Add(Objsd); } if (ColSD.Count > 1) { DateTime datetime1 = ColSD.Where(x => x.Tramo == "Salida" && x.Cont > 0).ToList().OrderByDescending(ord => ord.Fecha_Salida).ToList().FirstOrDefault().Fecha_Salida; DateTime datetime2 = ColSD.Where(x => x.Tramo == "Retorno").ToList().OrderByDescending(ord => ord.Fecha_Salida).ToList().FirstOrDefault().Fecha_Salida; //TimeSpan ts = datetime2 - datetime1; //int tday = datetime2.Day - datetime1.Day; TimeSpan ts = Convert.ToDateTime(datetime2.ToShortDateString()) - Convert.ToDateTime(datetime1.ToShortDateString()); int tday = ts.Days; if (tday < 0) { string scriptf = @"<script type='text/javascript'>alert('{0}');</script>"; scriptf = string.Format(scriptf, "Observación en la fecha de Retorno a " + datetime1.ToShortDateString()); ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", scriptf, false); return; } int tHour = datetime2.Hour - datetime1.Hour; if (tHour <= 0 && tday <= 0) { string scripth = @"<script type='text/javascript'>alert('{0}');</script>"; scripth = string.Format(scripth, "La HORA de Retorno debe ser mayor a " + datetime1.Hour + ":" + datetime1.Minute); ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", scripth, false); return; } } //*fin* //DB_VT_Solicitud sol = new DB_VT_Solicitud(); VT_Solicitud s = new VT_Solicitud(); VT_SolicitudDestino sd = new VT_SolicitudDestino(); s.Id_Solicitud = LblIdSolicitud.Text; s.Tipo_Viaje = DDLTipViaje.SelectedValue; s.Motivo_Viaje = TxtMotiv.Text; sol.DB_Modificar_SOLICITUD(s); foreach (GridViewRow dgi in GVSolicitud.Rows) { DropDownList ddlZona = (DropDownList)dgi.Cells[3].Controls[1]; DropDownList ddlDestino = (DropDownList)dgi.Cells[4].Controls[1]; TextBox txLugar = (TextBox)dgi.Cells[5].Controls[1]; TextBox txObjetivo = (TextBox)dgi.Cells[6].Controls[1]; TextBox tx2 = (TextBox)dgi.Cells[7].Controls[1]; DropDownList ddlHora = (DropDownList)dgi.Cells[8].Controls[1]; DropDownList ddlMin = (DropDownList)dgi.Cells[9].Controls[1]; DropDownList ddlVia_Transporte = (DropDownList)dgi.Cells[10].Controls[1]; DropDownList ddlTipo_Transporte = (DropDownList)dgi.Cells[11].Controls[1]; TextBox txNombre_Transporte = (TextBox)dgi.Cells[12].Controls[1]; TextBox txIdentificador_Trasporte = (TextBox)dgi.Cells[13].Controls[1]; sd.Id_Solicitud = LblIdSolicitud.Text; sd.Cont = Convert.ToInt32(GVSolicitud.DataKeys[dgi.RowIndex].Values[0]); sd.Zona = ddlZona.SelectedValue; sd.Destino = ddlDestino.SelectedValue; sd.Lugar = txLugar.Text; sd.Objetivo = txObjetivo.Text; sd.Fecha_Salida = Convert.ToDateTime(tx2.Text + " " + ddlHora.SelectedValue + ":" + ddlMin.SelectedValue); sd.Via_Transporte = ddlVia_Transporte.SelectedValue; sd.Tipo_Transporte = ddlTipo_Transporte.SelectedValue; sd.Nombre_Transporte = txNombre_Transporte.Text; sd.Identificador_Trasporte = txIdentificador_Trasporte.Text; sol.DB_Modificar_SOLICITUD_DESTINO(sd); } if (LblEstado.Text == "OBSERVADO") { sol.DB_Cambiar_ESTADO(LblIdSolicitud.Text, "HABILITADO"); } //sol.DB_Eliminar_OBSERVACION(LblIdSolicitud.Text); string script = @"<script type='text/javascript'>alert('{0}');</script>"; script = string.Format(script, "- El registro fué modificado correctamente."); ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false); //Response.Redirect("frmListaSolicitUs.aspx"); } catch (Exception ex) { string script = @"<script type='text/javascript'>alert('{0}');</script>"; script = string.Format(script, ex.Message); ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false); return; } }