public List <ViajesInternacionales> Listar() { List <ViajesInternacionales> resp = new List <ViajesInternacionales>(); ViajesInternacionales viajeInter; SqlConnection cnn = new SqlConnection(Conexion.CONEXION); SqlCommand cmd = new SqlCommand("ListarViajesInter", cnn); cmd.CommandType = CommandType.StoredProcedure; try { cnn.Open(); SqlDataReader lector = cmd.ExecuteReader(); while (lector.Read()) { Compania compania = FabricaPersistencia.GetPersistenciaCompania().BuscarParaViaje((string)lector["nomCompania"]); Terminal terminal = FabricaPersistencia.GetPersistenciaTerminal().BuscarParaViaje((string)lector["codTerminal"]); Empleado empleado = FabricaPersistencia.GetPersistenciaEmpleado().BuscarParaViaje((string)lector["cedulaEmpleado"]); viajeInter = new ViajesInternacionales((int)lector["numViaje"], compania, terminal, (DateTime)lector["fechaHoraPartida"], (DateTime)lector["fechaHoraArribo"], (int)lector["cantidadAsientos"], empleado, (bool)lector["servicioAbordo"], (string)lector["documentacion"]); resp.Add(viajeInter); } lector.Close(); } catch (Exception ex) { throw ex; } finally { cnn.Close(); } return(resp); }
protected void btnAgregar_Click(object sender, EventArgs e) { try { if (ControlVacio()) { throw new Exception("Debe completar todos los campos"); } Compania compania = Logica.FabricaLogica.GetLogicaCompania().Buscar(txtCompania.Text); if (compania == null) { throw new Exception("La compañia ingresada no se encuentra registrada"); } Terminal terminal = Logica.FabricaLogica.GetLogicaTerminales().Buscar(txtTerminal.Text); if (terminal == null) { throw new Exception("La terminal ingresada no se encuentra registrada"); } ViajesInternacionales viajeInter = new ViajesInternacionales(Convert.ToInt32(txtNum.Text), compania, terminal, Convert.ToDateTime(txtFechaPartida.Text), Convert.ToDateTime(txtFechaArribo.Text), Convert.ToInt32(txtCantidadAsientos.Text), (Empleado)Session["Usuario"], chkServicioBordo.Checked, txtDocumentacion.Text); LimpiarTodo(); Logica.FabricaLogica.GetLogicaViajes().Agregar(viajeInter); } catch (Exception ex) { lblMsj.Text = ex.Message; } }
public void Agregar(ViajesInternacionales pViaje) { List <Viaje> viajes = new List <Viaje>(); viajes.AddRange(Listar()); viajes.AddRange(ListarViaje()); TimeSpan dif; if (pViaje._FechaArribo < DateTime.Now || pViaje._FechaPartida < DateTime.Now) { throw new Exception("La fecha de arribo y de partida deben ser posteriores a la fecha actual"); } if (pViaje._FechaArribo <= pViaje._FechaPartida) { throw new Exception("La fecha de arribo debe ser posterior a la fecha de partida"); } foreach (Viaje vi in viajes) { if (vi._Ter._Codigo == pViaje._Ter._Codigo && vi._FechaPartida.Date == pViaje._FechaPartida.Date) { dif = vi._FechaPartida.TimeOfDay.Subtract(pViaje._FechaPartida.TimeOfDay); if (dif.TotalHours < 2 && dif.TotalHours > -2) { throw new Exception("No puede haber un viaje al mismo destino con la misma hora de salida, al menos 2 hrs de diferencia."); } } } FabricaPersistencia.GetPersistenciaViajeInternacional().Agregar(pViaje); }
private void txtNumero_Validating(object sender, CancelEventArgs e) { try { lblError.Text = ""; ServicioTURU Sweb = new ServicioTURU(); Viaje = Sweb.BuscarViaje(Convert.ToInt32(txtNumero.Text)); if (Viaje is ViajesNacionales) { throw new Exception("Ese numero corresponde a un Viaje Nacional."); } Vinter = (ViajesInternacionales)Viaje; if (Vinter == null) { HabilitarAgregar(); } else { HabilitarBajaModificar(); txtAsientos.Text = Vinter._CantidadAsientos.ToString(); txtDocumentacion.Text = Vinter._Documentacion; txtHoraArribo.Text = Vinter._FechaArribo.ToShortTimeString(); txtHoraPartida.Text = Vinter._FechaPartida.ToShortTimeString(); dtFechaArribo.Text = Vinter._FechaArribo.ToShortDateString(); dtFechaPartida.Text = Vinter._FechaPartida.ToShortDateString(); cbTerminales.Text = Vinter._Ter._Codigo; cbCompanias.Text = Vinter._Com._Nombre; chkServicioaBordo.Checked = Vinter._ServicioBordo; } } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText.Length > 100) { lblError.Text = ex.Detail.InnerText.Substring(0, 100); } else { lblError.Text = ex.Detail.InnerText; } } catch (Exception ex) { lblError.Text = ex.Message; } }
private void btnAgregar_Click(object sender, EventArgs e) { try { if (ControlVacio()) { throw new Exception("Debe completar todos los campos"); } ServicioTURU Sweb = new ServicioTURU(); Compania _Comp = Sweb.BuscarCompania(cbCompanias.SelectedItem.ToString()); Terminal _Term = Sweb.BuscarTerminal(cbTerminales.SelectedItem.ToString()); DateTime fechaPartida = Convert.ToDateTime(dtFechaPartida.Value.ToShortDateString() + " " + txtHoraPartida.Text); DateTime fechaArribo = Convert.ToDateTime(dtFechaArribo.Value.ToShortDateString() + " " + txtHoraArribo.Text); Vinter = new ViajesInternacionales(); Vinter._NumViaje = Convert.ToInt32(txtNumero.Text); Vinter._Documentacion = txtDocumentacion.Text; Vinter._Emp = _Emp; Vinter._CantidadAsientos = Convert.ToInt32(txtAsientos.Text); Vinter._FechaArribo = fechaArribo; Vinter._FechaPartida = fechaPartida; Vinter._ServicioBordo = chkServicioaBordo.Checked; Vinter._Ter = _Term; Vinter._Com = _Comp; Sweb.AgregarViaje(Vinter); lblError.Text = "Viaje agregado correctamente"; LimpiarForm(); } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText.Length > 100) { lblError.Text = ex.Detail.InnerText.Substring(0, 100); } else { lblError.Text = ex.Detail.InnerText; } } catch (Exception ex) { lblError.Text = ex.Message; } }
/*ELIMINAR*/ public void Eliminar(ViajesInternacionales pViaje) { SqlConnection cnn = new SqlConnection(Conexion.CONEXION); SqlCommand cmd = new SqlCommand("eliminarViajeInter", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@numero", pViaje._NumViaje); SqlParameter resSQL = new SqlParameter(); resSQL.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(resSQL); try { cnn.Open(); cmd.ExecuteNonQuery(); int res = (int)resSQL.Value; if (res == -1) { throw new Exception("No existe el viaje"); } if (res == -2) { throw new Exception("ERROR al eliminar el viaje"); } if (res == -3) { throw new Exception("ERROR al eliminar viaje internacional"); } if (res == 1) { throw new Exception("Viaje eliminado correctamente"); } } catch (Exception ex) { throw ex; } finally { cnn.Close(); } }
/*AGREGAR*/ public void Agregar(ViajesInternacionales pViaje) { SqlConnection cnn = new SqlConnection(Conexion.CONEXION); SqlCommand cmd = new SqlCommand("agregarViajeInter", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@numero", pViaje._NumViaje); cmd.Parameters.AddWithValue("@nombreCompania", pViaje._Com._Nombre); cmd.Parameters.AddWithValue("@codTerminal", pViaje._Ter._Codigo); cmd.Parameters.AddWithValue("@fechaHoraPartida", pViaje._FechaPartida); cmd.Parameters.AddWithValue("@fechaHoraArribo", pViaje._FechaArribo); cmd.Parameters.AddWithValue("@cantidadAsientos", pViaje._CantidadAsientos); cmd.Parameters.AddWithValue("@cedulaEmpleado", pViaje._Emp._Cedula); cmd.Parameters.AddWithValue("@servicioAbordo", pViaje._ServicioBordo); cmd.Parameters.AddWithValue("@documentacion", pViaje._Documentacion); SqlParameter resSQL = new SqlParameter(); resSQL.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(resSQL); int respuesta; try { cnn.Open(); cmd.ExecuteNonQuery(); respuesta = (int)resSQL.Value; if (respuesta == -1) { throw new Exception("Ya existe el viaje ingresado"); } if (respuesta == -2) { throw new Exception("No existe la compañia ingresada"); } if (respuesta == -3) { throw new Exception("No existe la terminal ingresada"); } if (respuesta == -4) { throw new Exception("No existe el empleado ingresado"); } if (respuesta == -5) { throw new Exception("ERROR al agregar el viaje"); } if (respuesta == -6) { throw new Exception("ERROR al agregar el viaje internacional"); } if (respuesta == -7) { throw new Exception("No puede haber un viaje al mismo destino con la misma hora de salida, al menos 2 hrs de diferencia.."); } if (respuesta == -8) { throw new Exception("Las fechas deben ser posteriores a la actual"); } if (respuesta == -9) { throw new Exception("La fecha de arribo debe ser posterior a la de partida.."); } } catch (Exception ex) { throw ex; } finally { cnn.Close(); } }
public ViajesInternacionales HerenciaInternacionales(ViajesInternacionales pViaje) { return(pViaje); }
public void Eliminar(ViajesInternacionales pViaje) { FabricaPersistencia.GetPersistenciaViajeInternacional().Eliminar(pViaje); }