private double calcularPagoPasaje(Viaje v, Ruta r, Butaca b)
        {
            double val = 0;

            if (b != null)
            {
                val = (val + (r.getPrecio_BasePasaje));
            }

            return val;
        }
        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;
        }
        internal void modificarRuta(Ruta rutaSel)
        {
            try
            {
                con.Open();
                int origen = 0;
                int destino = 0;
                int tipoServ = 0;

                SqlCommand cmd = new SqlCommand(String.Format("SELECT TOP 1 Id FROM [GD2C2015].[JANADIAN_DATE].[Ciudad]  WHERE Nombre='{0}'  ", rutaSel.getOrigen), con);
                DataTable dt = new DataTable();

                dt.TableName = "Tabla1";
                dt.Load(cmd.ExecuteReader());
                if (dt.Rows.Count == 0)
                {
                    con.Close();
                    throw (new Exception("No existe la ciudad Origen"));
                }
                foreach (DataRow Fila in dt.Rows)
                {
                    origen = Convert.ToInt32(Fila["Id"]);
                }

                cmd = new SqlCommand(String.Format("SELECT TOP 1 Id FROM [GD2C2015].[JANADIAN_DATE].[Ciudad]  WHERE Nombre='{0}'  ", rutaSel.getDestino), con);
                dt = new DataTable();

                dt.TableName = "Tabla1";
                dt.Load(cmd.ExecuteReader());
                if (dt.Rows.Count == 0)
                {
                    con.Close();
                    throw (new Exception("No existe la ciudad Destino"));
                }
                foreach (DataRow Fila in dt.Rows)
                {
                    destino = Convert.ToInt32(Fila["Id"]);
                }

                cmd = new SqlCommand(String.Format("SELECT TOP 1 Id FROM [GD2C2015].[JANADIAN_DATE].[Tipo_Servicio]  WHERE Nombre='{0}'  ", rutaSel.getTipoServicio), con);
                dt = new DataTable();

                dt.TableName = "Tabla1";
                dt.Load(cmd.ExecuteReader());
                if (dt.Rows.Count == 0)
                {
                    con.Close();
                    throw (new Exception("No existe el tipo de servicio"));
                }
                foreach (DataRow Fila in dt.Rows)
                {
                    tipoServ = Convert.ToInt32(Fila["Id"]);
                }

                SqlCommand updateRol = new SqlCommand(String.Format("UPDATE [GD2C2015].[JANADIAN_DATE].[Ruta]  SET Codigo={0},Habilitado={1},Ciudad_Origen={2},Ciudad_Destino={3},Tipo_Servicio={4},Precio_BaseKG={6:0.00},Precio_BasePasaje={7:0.00} WHERE Id={5}", rutaSel.getCodigo, rutaSel.getHabilitado ? "1" : "0", origen, destino, tipoServ, rutaSel.getId, rutaSel.getPrecio_BaseKG.ToString().Replace(",", "."), rutaSel.getPrecio_BasePasaje.ToString().Replace(",", ".")), con);
                updateRol.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception exAlta)
            {
                con.Close();
                throw (new Exception(exAlta.ToString()));

            }
        }
        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 Ruta getRutaBySameConditions(string origen, string destino, string tipoServicio)
        {
            Ruta ruta = 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 r.Id, r.Codigo,r.Precio_BaseKG,r.Precio_BasePasaje,o.Nombre as Origen,d.Nombre as Destino,t.Nombre as Tipo_Servicio,r.Habilitado FROM [GD2C2015].[JANADIAN_DATE].[Ruta] r INNER JOIN [GD2C2015].[JANADIAN_DATE].[Ciudad] o on (r.Ciudad_Origen=o.Id) INNER JOIN [GD2C2015].[JANADIAN_DATE].[Ciudad] d on (r.Ciudad_Destino=d.Id) INNER JOIN [GD2C2015].[JANADIAN_DATE].[Tipo_Servicio] t on (r.Tipo_Servicio=t.Id) WHERE o.Nombre = '{0}' AND d.Nombre = '{1}' AND t.Nombre = '{2}'  ", origen, destino, tipoServicio), 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)
                {
                    ruta = new Ruta(Convert.ToInt32(Fila["Id"]), Convert.ToString(Fila["Origen"]), Convert.ToString(Fila["Destino"]), Convert.ToDecimal(Fila["Codigo"]), Convert.ToDouble(Fila["Precio_BaseKG"]), Convert.ToDouble(Fila["Precio_BasePasaje"]), Convert.ToString(Fila["Tipo_Servicio"]), Convert.ToBoolean(Fila["Habilitado"]));
                }
                con.Close();
            }
            catch (Exception exAlta)
            {
                con.Close();
                throw (new Exception(exAlta.ToString()));

            }
            return ruta;
        }