private List<Viaje> obtenerViajesIntervaloAeronave(int idAeronave, DateTime fechaReinicio) { List<Viaje> viajes = new List<Viaje>(); try { // // Open the SqlConnection. // con.Open(); // // The following code uses an SqlCommand based on the SqlConnection. // SqlCommand cmd = new SqlCommand(String.Format("SELECT [Id],[FechaSalida],[Fecha_Llegada_Estimada],[FechaLlegada],[Aeronave],[Ruta] FROM [GD2C2015].[JANADIAN_DATE].[Viaje] WHERE Aeronave={0} AND DATEDIFF(SECOND,'{1}',[FechaSalida]) >=0 AND DATEDIFF(SECOND,'{2}',ISNULL([FechaLlegada],[Fecha_Llegada_Estimada])) <= 0", idAeronave, this.fechaSistema, fechaReinicio), con); DataTable dt = new DataTable(); dt.TableName = "Tabla"; dt.Load(cmd.ExecuteReader()); if (dt.Rows.Count == 0) { con.Close(); return viajes; } foreach (DataRow Fila in dt.Rows) { Viaje viaje = new Viaje(Convert.ToInt32(Fila["Id"]), Convert.ToInt32(Fila["Aeronave"]), Convert.ToInt32(Fila["Ruta"]), Convert.ToDateTime(Fila["FechaSalida"]), Fila["FechaLlegada"].GetType().ToString().Contains("Null") ? new DateTime() : Convert.ToDateTime(Fila["FechaLlegada"]), Convert.ToDateTime(Fila["Fecha_Llegada_Estimada"])); viajes.Add(viaje); } con.Close(); } catch (Exception exAlta) { con.Close(); throw (new Exception(exAlta.ToString())); } return viajes; }
private void crearNuevaAeronaveParaSatisfacerViaje(int idAeronave, string matricula, Viaje v) { try { con.Open(); SqlCommand updateAeronave = new SqlCommand(String.Format("EXEC [GD2C2015].[JANADIAN_DATE].[crearNuevaAeronave] {0},'{1}',{2}", idAeronave, matricula, v.getId), con); updateAeronave.ExecuteNonQuery(); con.Close(); } catch (Exception eUpdate) { Console.WriteLine(eUpdate.ToString()); con.Close(); throw (new Exception()); } }
private void migrarViajeAOtraAeronave(int idAeronave, Viaje v, Aeronave otraNave) { try { con.Open(); SqlCommand updateAeronave = new SqlCommand(String.Format("EXEC [GD2C2015].[JANADIAN_DATE].[reemplazarAeronaveViaje] {0},{1},{2}", idAeronave, v.getId, otraNave.getId), con); updateAeronave.ExecuteNonQuery(); con.Close(); } catch (Exception eUpdate) { Console.WriteLine(eUpdate.ToString()); con.Close(); throw (new Exception()); } }
private double calcularPagoPaquete(Viaje v, Ruta r, decimal paquete) { double val = 0; if (paquete > 0) { val = (val + (Convert.ToDouble(paquete) * r.getPrecio_BaseKG)); } return val; }
private double calcularPagoPasaje(Viaje v, Ruta r, Butaca b) { double val = 0; if (b != null) { val = (val + (r.getPrecio_BasePasaje)); } return val; }
internal void registrarLlegada(Viaje viaje, DateTime llegada) { try { con.Open(); SqlCommand updateViaje = new SqlCommand(String.Format("UPDATE [GD2C2015].[JANADIAN_DATE].[Viaje] SET FechaLlegada='{0}' WHERE Id ={1}", llegada, viaje.getId), con); updateViaje.ExecuteNonQuery(); con.Close(); } catch (Exception eUpdate) { Console.WriteLine(eUpdate.ToString()); con.Close(); throw (new Exception()); } }
internal void insertarViaje(Viaje v, Aeronave a, Ruta r) { try { con.Open(); SqlCommand insertRol = new SqlCommand(String.Format("INSERT INTO [GD2C2015].[JANADIAN_DATE].[Viaje] (FechaSalida,Fecha_Llegada_Estimada,Aeronave,Ruta) VALUES ('{0}','{1}',{2},{3})", v.getFechaSalida, v.getFechaLlegadaEstimada, a.getId, r.getId), con); insertRol.ExecuteNonQuery(); con.Close(); } catch (Exception exAlta) { con.Close(); throw (new Exception(exAlta.ToString())); } }
internal List<int> insertarPasajes(List<Butaca> butacas, List<Cliente> clientes, int idCompra, Viaje v, Ruta r) { List<int> idPasajes = new List<int>(); try { con.Open(); for (int i = 0; i < butacas.Count; i++) { if (butacas[i] != null) { SqlCommand insertButacaViaje = new SqlCommand(String.Format("INSERT INTO [GD2C2015].[JANADIAN_DATE].[Butaca_Viaje] ([Butaca],[Viaje]) VALUES ({0},{1})", butacas[i].getId, v.getId), con); insertButacaViaje.ExecuteNonQuery(); SqlCommand insertPasaje = new SqlCommand(String.Format("INSERT INTO [GD2C2015].[JANADIAN_DATE].[Pasaje] ([Butaca],[Compra],[Cliente],[Precio]) VALUES ({0},{1},{2},{3:0.00})", butacas[i].getId, idCompra, clientes[i].getId, calcularPagoPasaje(v, r, butacas[i]).ToString().Replace(",", ".")), con); insertPasaje.ExecuteNonQuery(); SqlCommand cmd = new SqlCommand(String.Format("SELECT SCOPE_IDENTITY() as Cont "), con); DataTable dt = new DataTable(); dt.TableName = "Tabla"; dt.Load(cmd.ExecuteReader()); if (dt.Rows.Count == 0) { con.Close(); new Exception(); } foreach (DataRow Fila in dt.Rows) { idPasajes.Add(Convert.ToInt32(Fila["Cont"])); break; } } } con.Close(); } catch (Exception exAlta) { con.Close(); throw (new Exception(exAlta.ToString())); } return idPasajes; }
internal Viaje getViajeById(int viajeId) { Viaje viaje = null; try { // // Open the SqlConnection. // con.Open(); // // The following code uses an SqlCommand based on the SqlConnection. // SqlCommand cmd = new SqlCommand(String.Format("SELECT TOP 1 v.[Id],[FechaSalida],[Fecha_Llegada_Estimada],[FechaLlegada],[Aeronave],[Ruta] FROM [GD2C2015].[JANADIAN_DATE].[Viaje] v WHERE v.Id={0} ", viajeId), con); DataTable dt = new DataTable(); dt.TableName = "Tabla"; dt.Load(cmd.ExecuteReader()); if (dt.Rows.Count == 0) { con.Close(); return null; } foreach (DataRow Fila in dt.Rows) { viaje = new Viaje(Convert.ToInt32(Fila["Id"]), Convert.ToInt32(Fila["Aeronave"]), Convert.ToInt32(Fila["Ruta"]), Convert.ToDateTime(Fila["FechaSalida"]),Fila["FechaLlegada"].GetType().ToString().Contains("Null") ? new DateTime() : Convert.ToDateTime(Fila["FechaLlegada"]) , Convert.ToDateTime(Fila["Fecha_Llegada_Estimada"])); } con.Close(); } catch (Exception exAlta) { con.Close(); throw (new Exception(exAlta.ToString())); } return viaje; }
internal Viaje getViaje(Aeronave nave, object origen, object destino) { Viaje viaje = null; try { // // Open the SqlConnection. // con.Open(); // // The following code uses an SqlCommand based on the SqlConnection. // SqlCommand cmd = new SqlCommand(String.Format("SELECT TOP 1 v.[Id],[FechaSalida],[Fecha_Llegada_Estimada],[FechaLlegada],[Aeronave],[Ruta] FROM [GD2C2015].[JANADIAN_DATE].[Viaje] v INNER JOIN [GD2C2015].[JANADIAN_DATE].[Ruta] r ON (v.Ruta=r.Id) INNER JOIN [GD2C2015].[JANADIAN_DATE].[Ciudad] c ON (r.Ciudad_Origen=c.Id) INNER JOIN [GD2C2015].[JANADIAN_DATE].[Ciudad] c2 ON (r.Ciudad_Destino=c2.Id) WHERE v.Aeronave={0} AND c.Nombre='{1}' AND c2.Nombre='{2}' AND FechaLlegada IS NULL ", nave.getId, origen.ToString(), destino.ToString()), con); DataTable dt = new DataTable(); dt.TableName = "Tabla"; dt.Load(cmd.ExecuteReader()); if (dt.Rows.Count == 0) { con.Close(); return null; } foreach (DataRow Fila in dt.Rows) { viaje = new Viaje(Convert.ToInt32(Fila["Id"]), Convert.ToInt32(Fila["Aeronave"]), Convert.ToInt32(Fila["Ruta"]), Convert.ToDateTime(Fila["FechaSalida"]), Fila["FechaLlegada"].GetType().ToString().Contains("Null") ? new DateTime() : Convert.ToDateTime(Fila["FechaLlegada"]), Convert.ToDateTime(Fila["Fecha_Llegada_Estimada"])); } con.Close(); } catch (Exception exAlta) { con.Close(); throw (new Exception(exAlta.ToString())); } return viaje; }