protected void rdActividad_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { DBConn oConn = new DBConn(); if (oConn.Open()) { cAppRegActividad oAppRegActividad = new cAppRegActividad(ref oConn); oAppRegActividad.CodUsuario = hddcodusuario.Value; rdActividad.DataSource = oAppRegActividad.Get(); } oConn.Close(); }
protected void rdActividad_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { string ltorigen = string.Empty; string ltdestino = string.Empty; DataTable dt = null; DBConn oConn = new DBConn(); if (oConn.Open()) { cAppRegActividad oAppRegActividad = new cAppRegActividad(ref oConn); oAppRegActividad.IndFecha = hddfecha.Value; oAppRegActividad.CodUsuario = hddcodusuario.Value; dt = oAppRegActividad.GetRuta(); } oConn.Close(); rdActividad.DataSource = dt; if (dt != null) { if (dt.Rows.Count > 0) { StringBuilder js = new StringBuilder(); if (dt.Rows.Count == 1) { //ltorigen = dt.Rows[0]["localizacion"].ToString(); ltorigen = "{ lat: " + dt.Rows[0]["localizacion"].ToString().Substring(0, 10).Replace(",", ".") + ", lng: " + dt.Rows[0]["localizacion"].ToString().Substring(11, 10).Replace(",", ".") + " };"; js.Append(" var origen = ").Append(ltorigen); js.Append(" var destino = ").Append(ltdestino); // Set destination, origin and travel mode. js.Append(" var request = { "); js.Append(" destination: destino, "); js.Append(" origin: origen, "); js.Append(" travelMode: 'DRIVING' "); js.Append(" }; "); } else if (dt.Rows.Count == 2) { //ltorigen = dt.Rows[0]["localizacion"].ToString(); ltorigen = "{ lat: " + dt.Rows[0]["localizacion"].ToString().Substring(0, 10).Replace(",", ".") + ", lng: " + dt.Rows[0]["localizacion"].ToString().Substring(11, 10).Replace(",", ".") + " };"; //ltdestino = dt.Rows[dt.Rows.Count - 1]["localizacion"].ToString(); ltdestino = "{ lat: " + dt.Rows[dt.Rows.Count - 1]["localizacion"].ToString().Substring(0, 10).Replace(",", ".") + ", lng: " + dt.Rows[dt.Rows.Count - 1]["localizacion"].ToString().Substring(11, 10).Replace(",", ".") + " };"; js.Append(" var origen = ").Append(ltorigen); js.Append(" var destino = ").Append(ltdestino); // Set destination, origin and travel mode. js.Append(" var request = { "); js.Append(" destination: destino, "); js.Append(" origin: origen, "); js.Append(" travelMode: 'DRIVING' "); js.Append(" }; "); } else if (dt.Rows.Count > 2) { //ltorigen = dt.Rows[0]["localizacion"].ToString(); ltorigen = "{ lat: " + dt.Rows[0]["localizacion"].ToString().Substring(0, 10).Replace(",", ".") + ", lng: " + dt.Rows[0]["localizacion"].ToString().Substring(11, 10).Replace(",", ".") + " };"; string[] waypts = new string[dt.Rows.Count - 2]; for (int i = 0; i < dt.Rows.Count - 2; i++) { waypts[i] = "{ lat: " + dt.Rows[i + 1]["localizacion"].ToString().Substring(0, 10).Replace(",", ".") + ", lng: " + dt.Rows[i + 1]["localizacion"].ToString().Substring(11, 10).Replace(",", ".") + " }"; //waypts[i] = dt.Rows[i+1]["localizacion"].ToString(); } //ltdestino = dt.Rows[dt.Rows.Count - 1]["localizacion"].ToString(); ltdestino = "{ lat: " + dt.Rows[dt.Rows.Count - 1]["localizacion"].ToString().Substring(0, 10).Replace(",", ".") + ", lng: " + dt.Rows[dt.Rows.Count - 1]["localizacion"].ToString().Substring(11, 10).Replace(",", ".") + " };"; js.Append(" var origen = ").Append(ltorigen); js.Append(" var destino = ").Append(ltdestino); js.Append(" var waypts = [];"); foreach (string sWay in waypts) { js.Append(" waypts.push({"); js.Append(" location: ").Append(sWay).Append(","); js.Append(" stopover: true "); js.Append(" }); "); } // Set destination, origin and travel mode. js.Append(" var request = { "); js.Append(" destination: destino, "); js.Append(" origin: origen, "); js.Append(" waypoints: waypts, "); js.Append(" optimizeWaypoints: true, "); js.Append(" travelMode: 'DRIVING' "); js.Append(" }; "); } Page.ClientScript.RegisterStartupScript(this.GetType(), "fLoadMaps", js.ToString(), true); } } dt = null; }