public void BajaViajeNacionales(Viajes V) { SqlConnection DBCS = Conexion.CrearCnn(); Nacionales N = (Nacionales)V; SqlCommand comando = new SqlCommand("BajaViajeNacional", DBCS); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.Add(new SqlParameter("@Numero", N.numero)); SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int); retorno.Direction = ParameterDirection.ReturnValue; comando.Parameters.Add(retorno); try { DBCS.Open(); comando.ExecuteNonQuery(); int r = Convert.ToInt32(retorno.Value); if (r == -1) { throw new Exception("ExcepcionEX:Error al eliminar el viaje.FinExcepcionEX"); } } catch (Exception ex) { throw ex; } finally { DBCS.Close(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { Viajes v = (Viajes)Session["viajeElegido"]; lblNumero.Text = v.numero.ToString(); lblPartida.Text = v.partida.ToString(); lblArribo.Text = v.arribo.ToString(); lblCantAsientos.Text = v.cantAsientos.ToString(); lblEmpleado.Text = v.e.nombreCompleto; if (v is Internacionales) { Internacionales i = (Internacionales)v; lblDocumentacion.Text = i.documentacion; if (i.servAbordo == true) { lblServAbordo.Text = "Si"; } else { lblServAbordo.Text = "No"; } lblParadas.Text = "Valór no admitido."; } else { Nacionales n = (Nacionales)v; lblParadas.Text = n.paradas.ToString(); lblServAbordo.Text = "Valór no admitido."; lblDocumentacion.Text = "Valór no admitido."; } lblNombre.Text = v.c.nombre; lblDireccion.Text = v.c.direccion; lblTelefono.Text = v.c.telefono.ToString(); lblCodigo.Text = v.t.codigo; lblCiudad.Text = v.t.ciudad; lblPais.Text = v.t.pais; GDVFacilidades.DataSource = v.t.facilidades; GDVFacilidades.ShowHeader = false; GDVFacilidades.DataBind(); } catch (Exception ex) { lblError.Text = ex.Message; } } }
//Operaciones public Nacionales Buscar_Viaje(int pCodViaje) { SqlConnection oConexion = new SqlConnection(Conexion.STR); SqlCommand oComando = new SqlCommand("Buscar_ViajeNacional", oConexion); oComando.CommandType = CommandType.StoredProcedure; oComando.Parameters.AddWithValue("@numero", pCodViaje); Nacionales unNac = null; try { oConexion.Open(); SqlDataReader _Reader = oComando.ExecuteReader(); if (_Reader.HasRows) { _Reader.Read(); int _numero = (int)_Reader["numero"]; Companias _compania = PersistenciaCompania.GetInstancia().BuscarTodos_Compania((string)_Reader["compania"]); Terminales _terminal = PersistenciaTerminales.GetInstancia().BuscarTodos_Terminal((string)_Reader["destino"]); DateTime _fechapartida = (DateTime)_Reader["fecha_partida"]; DateTime _fechaarribo = (DateTime)_Reader["fecha_arribo"]; int _asientos = (int)_Reader["asientos"]; Empleados _empleado = PersistenciaEmpleado.GetInstancia().BuscarTodos_Empleado((string)_Reader["empleado"]); int _paradas = (int)_Reader["paradas"]; unNac = new Nacionales(_numero, _compania, _terminal, _fechapartida, _fechaarribo, _asientos, _empleado, _paradas); _Reader.Close(); } } catch (SqlException) { throw new Exception("La base de datos no se encuantra disponible. Contacte al administrador."); } catch (Exception ex) { throw new Exception(ex.Message); } finally { oConexion.Close(); } return(unNac); }
protected void BtnModificar_Click(object sender, EventArgs e) { try { int _Numero = Convert.ToInt16(TBNumero.Text); Terminales _Terminal = (from unaTerminal in (List <Terminales>)Session["Terminales"] where unaTerminal.Codigo == DDLTerminal.SelectedValue select unaTerminal).First(); Companias _Compania = (from unaCompania in (List <Companias>)Session["Companias"] where unaCompania.Nombre == DDLCompania.SelectedValue select unaCompania).First(); int diapartida = Convert.ToDateTime(TBFechaPartida.Text).Day; int mespartida = Convert.ToDateTime(TBFechaPartida.Text).Month; int aniopartida = Convert.ToDateTime(TBFechaPartida.Text).Year; int horapartida = Convert.ToInt16(DDLHoraPartida.Text); int minutospartida = Convert.ToInt16(DDLMinutosPartida.Text); int diaarribo = Convert.ToDateTime(TBFechaArribo.Text).Day; int mesarribo = Convert.ToDateTime(TBFechaArribo.Text).Month; int anioarribo = Convert.ToDateTime(TBFechaArribo.Text).Year; int horaarribo = Convert.ToInt16(DDLHoraArribo.Text); int minutosarribo = Convert.ToInt16(DDLMinutosArribo.Text); DateTime _Fechapartida = new DateTime(aniopartida, mespartida, diapartida, horapartida, minutospartida, 0); DateTime _Fechaarribo = new DateTime(anioarribo, mesarribo, diaarribo, horaarribo, minutosarribo, 0); int _CantAsientos = Convert.ToInt16(TBCantAsientos.Text); Empleados _Empleado = (Empleados)Session["Empleado"]; int _Paradas = Convert.ToInt16(TBParadas.Text); Nacionales unNac = new Nacionales(_Numero, _Compania, _Terminal, _Fechapartida, _Fechaarribo, _CantAsientos, _Empleado, _Paradas); ILogicaViajes FViaje = FabricaLogica.getLogicaViaje(); FViaje.Modificar_Viaje(unNac); LblError.ForeColor = System.Drawing.Color.Blue; LblError.Text = "El Viaje " + Convert.ToString(unNac.Numero) + " ha sido modificado correctamente."; LimpioFormulario(); } catch (Exception ex) { LblError.ForeColor = System.Drawing.Color.Red; LblError.Text = ex.Message; } }
protected void btnBuscar_Click(object sender, EventArgs e) { try { Viajes v = FabricaLogica.GetLogicaViajes().BuscarViaje(Convert.ToInt32(txtBusqueda.Text)); txtBusqueda.Enabled = false; txtEmpleado.Enabled = false; Panel2.Enabled = true; lblError.Text = ""; if (v is Nacionales) { Nacionales n = (Nacionales)v; Panel2.Visible = true; Session["ViajeNacional"] = n; FechaYHora3.Fecha = n.partida; FechaYHora4.Fecha = n.arribo; txtAsiento.Text = n.cantAsientos.ToString(); txtParadas.Text = n.paradas.ToString(); txtEmpleado.Text = n.e.ci.ToString(); txtDestino.Text = n.t.codigo.ToString(); txtCompania.Text = n.c.nombre; BtnEliminar.Enabled = true; btnAgregar.Enabled = false; btnModificar.Enabled = true; } else if (v is Internacionales) { txtBusqueda.Enabled = true; Panel2.Enabled = false; throw new Exception("El numero ingresado corresponde a un viaje Internacional."); } else { Empleado E = (Empleado)Session["Empleado"]; txtEmpleado.Text = E.ci.ToString(); txtAsiento.Text = ""; txtParadas.Text = ""; txtDestino.Text = ""; txtCompania.Text = ""; btnModificar.Enabled = false; btnAgregar.Enabled = true; } } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void BtnEliminar_Click(object sender, EventArgs e) { try { Nacionales n = (Nacionales)Session["ViajeNacional"]; FabricaLogica.GetLogicaViajes().BajaViaje(n); Panel2.Visible = false; BtnEliminar.Visible = false; lblError.Text = "Viaje eliminado con éxito."; } catch (Exception ex) { lblError.Text = ex.Message; } }
public void Eliminar_Nacional(Nacionales unNac) { SqlConnection oConexion = new SqlConnection(Conexion.STR); SqlCommand oComando = new SqlCommand("Eliminar_ViajeNacional", oConexion); oComando.CommandType = CommandType.StoredProcedure; oComando.Parameters.AddWithValue("@numero", unNac.Numero); SqlParameter oRetorno = new SqlParameter("@Retorno", SqlDbType.Int); oRetorno.Direction = ParameterDirection.ReturnValue; oComando.Parameters.Add(oRetorno); int oAfectados = -1; try { oConexion.Open(); oComando.ExecuteNonQuery(); oAfectados = (int)oComando.Parameters["@Retorno"].Value; if (oAfectados == -1) { throw new Exception("El viaje ingresado no existe en la base de datos"); } if (oAfectados == -2 || oAfectados == -3) { throw new Exception("Error al eliminar el viaje en la base de datos. Inténtelo nuevamente "); } } catch (SqlException) { throw new Exception("La base de datos no se encuantra disponible. Contacte al administrador."); } catch (Exception ex) { throw new Exception("Problemas con la base de datos: " + ex.Message); } finally { oConexion.Close(); } }
public List <Nacionales> Listar_Viajes_Nac() { SqlConnection oConexion = new SqlConnection(Conexion.STR); SqlCommand oComando = new SqlCommand("Listar_Viajes_Nacionales", oConexion); oComando.CommandType = CommandType.StoredProcedure; List <Nacionales> _Lista = new List <Nacionales>(); try { oConexion.Open(); SqlDataReader _Reader = oComando.ExecuteReader(); while (_Reader.Read()) { int _numero = (int)_Reader["numero"]; Companias _compania = PersistenciaCompania.GetInstancia().BuscarTodos_Compania((string)_Reader["compania"]); Terminales _terminal = PersistenciaTerminales.GetInstancia().BuscarTodos_Terminal((string)_Reader["destino"]); DateTime _fechapartida = (DateTime)_Reader["fecha_partida"]; DateTime _fechaarribo = (DateTime)_Reader["fecha_arribo"]; int _asientos = (int)_Reader["asientos"]; Empleados _empleado = PersistenciaEmpleado.GetInstancia().BuscarTodos_Empleado((string)_Reader["empleado"]); int _paradas = (int)_Reader["paradas"]; Nacionales viaje = new Nacionales(_numero, _compania, _terminal, _fechapartida, _fechaarribo, _asientos, _empleado, _paradas); _Lista.Add(viaje); } _Reader.Close(); } catch (SqlException) { throw new Exception("La base de datos no se encuantra disponible. Contacte al administrador."); } catch (Exception ex) { throw new Exception(ex.Message); } finally { oConexion.Close(); } return(_Lista); }
private void BtnAlta_Click(object sender, EventArgs e) { try { Nacionales _unNacional = new Nacionales(); _unNacional.Numero = Convert.ToInt32(TBNumero.Text); _unNacional.Compania = (Companias)CBCompania.SelectedItem; _unNacional.Terminal = (Terminales)CBTerminal.SelectedItem; _unNacional.Asientos = Convert.ToInt32(TBAsientos.Text); _unNacional.Paradas = Convert.ToInt32(TBParadas.Text); DateTime _Fechapartida = new DateTime(DTPFechaPartida.Value.Year, DTPFechaPartida.Value.Month, DTPFechaPartida.Value.Day, CBHoraPartida.SelectedIndex, CBMinutosPartida.SelectedIndex, 0); DateTime _Fechaarribo = new DateTime(DTPFechaArribo.Value.Year, DTPFechaArribo.Value.Month, DTPFechaArribo.Value.Day, CBHoraArribo.SelectedIndex, CBMinutosArribo.SelectedIndex, 0); _unNacional.Fecha_partida = _Fechapartida; _unNacional.Fecha_arribo = _Fechaarribo; _unNacional.Empleado = _EmpLogueado; new AppWinAdministracion.WSTerminalRef.WSTerminal().Alta_Viaje(_unNacional); LblError.Text = "Viaje Nacional dado de alta con éxito"; this.ActivoPorDefecto(); } catch (System.Web.Services.Protocols.SoapException ex) { int aux = ex.Message.IndexOf("ERROR: "); LblError.Text = ex.Message.Substring(aux, 80); } catch (Exception ex) { if (ex.Message.Length > 80) { LblError.Text = ex.Message.Substring(0, 80); } else { LblError.Text = ex.Message; } } }
public List <Viajes> ListarNacionalesTodos() { List <Viajes> lista = new List <Viajes>(); SqlConnection DBCS = Conexion.CrearCnn(); Nacionales N = null; SqlCommand comando = new SqlCommand("ListarNacionalesTodos", DBCS); comando.CommandType = CommandType.StoredProcedure; SqlDataReader r; try { DBCS.Open(); r = comando.ExecuteReader(); if (r.HasRows) { while (r.Read()) { N = new Nacionales(Convert.ToInt32(r.GetValue(0)), Convert.ToInt32(r.GetValue(1)), Convert.ToDateTime(r.GetValue(2)), Convert.ToDateTime(r.GetValue(3)), PersistenciaEmpleado.GetInstancia().BuscarEmpleadosTodos(Convert.ToInt32(r.GetValue(4))), PersistenciaTerminal.GetInstancia().BuscarTerminalTodos(r.GetValue(5).ToString()), PersistenciaCompania.GetInstancia().BuscarCompaniaTodas(r.GetValue(6).ToString()), Convert.ToInt32(r.GetValue(7)) ); lista.Add(N); } } r.Close(); } catch (Exception ex) { throw ex; } finally { DBCS.Close(); } return(lista); }
public Nacionales BuscarViajeNacional(int numero) { SqlConnection DBCS = Conexion.CrearCnn(); Nacionales n = null; SqlCommand comando = new SqlCommand("BuscarViajeNacional", DBCS); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.Add(new SqlParameter("@Numero", numero)); try { DBCS.Open(); SqlDataReader r; r = comando.ExecuteReader(); if (r.HasRows) { r.Read(); n = new Nacionales(Convert.ToInt32(r.GetValue(0)), Convert.ToInt32(r.GetValue(1)), Convert.ToDateTime(r.GetValue(2)), Convert.ToDateTime(r.GetValue(3)), PersistenciaEmpleado.GetInstancia().BuscarEmpleadosTodos(Convert.ToInt32(r.GetValue(4))), PersistenciaTerminal.GetInstancia().BuscarTerminalTodos(r.GetValue(5).ToString()), PersistenciaCompania.GetInstancia().BuscarCompaniaTodas(r.GetValue(6).ToString()), Convert.ToInt32(r.GetValue(7)) ); } r.Close(); return(n); } catch (Exception ex) { throw ex; } finally { DBCS.Close(); } }
private void TBNumero_Validating(object sender, CancelEventArgs e) { try { Viajes _unNacional = null; _unNacional = new AppWinAdministracion.WSTerminalRef.WSTerminal().Buscar_Viaje(Convert.ToInt32(TBNumero.Text)); if (_unNacional == null) { this.ActivoAgregar(); } else if (_unNacional is Internacionales) { LblError.Text = "El viaje ingresado corresponde a un viaje internacional"; } else { _objNacional = (Nacionales)_unNacional; this.ActivoActualizacion(); } } catch (System.Web.Services.Protocols.SoapException ex) { int aux = ex.Message.IndexOf("ERROR: "); LblError.Text = ex.Message.Substring(aux, 80); } catch (Exception ex) { if (ex.Message.Length > 80) { LblError.Text = ex.Message.Substring(0, 80); } else { LblError.Text = ex.Message; } } }
private void txtNumero_Validating(object sender, CancelEventArgs e) { try { int salida = 0; WebService WS = new WebService(); if (Int32.TryParse(txtNumero.Text, out salida)) { errorProvider1.Clear(); Viajes viaje = WS.BuscarViaje(Convert.ToInt32(txtNumero.Text)); if (viaje is Internacionales) { errorProvider1.SetError(txtNumero, "Este viaje es de tipo Internacional."); } else { objNacionales = (Nacionales)viaje; if (objNacionales == null) { this.ActivoAgregar(); } else { this.ActivoActualizacion(); } } } else { errorProvider1.SetError(txtNumero, "Ingrese un número válido."); } } catch (System.Web.Services.Protocols.SoapException ex) { manejoErrorWS(ex.Message); } catch (Exception ex) { lblError.Text = ex.Message; } }
private void txtNumero_Validating(object sender, CancelEventArgs e) { try { WebService WS = new WebService(); if (txtNumero.Text.Length != 0) { errorProvider1.Clear(); Viajes viaje = WS.BuscarViaje(Convert.ToInt32(txtNumero.Text)); if (viaje is Internacionales) { errorProvider1.SetError(txtNumero, "Este viaje es de tipo Internacional."); } else { objNacionales = (Nacionales)viaje; if (objNacionales == null) { this.ActivoAgregar(); } else { this.ActivoActualizacion(); } } } else { errorProvider1.SetError(txtNumero, "Debe rellenar este campo."); } } catch (System.Web.Services.Protocols.SoapException ex) { lblError.Text = ex.Message; } catch (Exception ex) { lblError.Text = ex.Message; } }
private void btnAgregar_Click(object sender, EventArgs e) { try { WebService WS = new WebService(); objNacionales = new Nacionales(); objNacionales.numero = Convert.ToInt32(txtNumero); objNacionales.cantAsientos = Convert.ToInt32(txtCantAsientos.Text); objNacionales.partida = dtpPartida.Value; objNacionales.arribo = dtpArribo.Value; objNacionales.e = empLogueado; foreach (Terminal t in listaT) { if (t.ciudad == cbTerminal.SelectedItem.ToString()) { objNacionales.t = t; } } foreach (Compania c in listaC) { if (c.nombre == cbCompañia.SelectedItem.ToString()) { objNacionales.c = c; } } objNacionales.cantAsientos = Convert.ToInt32(txtCantAsientos.Text); WS.AltaViaje(objNacionales); lblError.Text = "Alta con éxito."; this.ActivoPorDefecto(); } catch (System.Web.Services.Protocols.SoapException ex) { lblError.Text = ex.Message; } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void BtnEliminar_Click(object sender, EventArgs e) { try { Nacionales unNac = (Nacionales)Session["Nacional"]; ILogicaViajes FViaje = FabricaLogica.getLogicaViaje(); FViaje.Eliminar_Viaje(unNac); LblError.ForeColor = System.Drawing.Color.Blue; LblError.Text = "El Viaje " + Convert.ToString(unNac.Numero) + " ha sido eliminado correctamente."; LimpioFormulario(); } catch (Exception ex) { LblError.ForeColor = System.Drawing.Color.Red; LblError.Text = ex.Message; } }
private void ActivoPorDefecto() { BtnAlta.Enabled = false; BtnBaja.Enabled = false; BtnModificar.Enabled = false; TBNumero.Text = ""; CBCompania.SelectedIndex = -1; CBTerminal.SelectedIndex = -1; TBAsientos.Text = ""; TBParadas.Text = ""; DTPFechaPartida.Value = DateTime.Today; CBHoraPartida.SelectedIndex = -1; CBMinutosPartida.SelectedIndex = -1; DTPFechaArribo.Value = DateTime.Today; CBHoraArribo.SelectedIndex = -1; CBMinutosArribo.SelectedIndex = -1; TBNumero.Focus(); TBNumero.Enabled = true; CBCompania.Enabled = false; CBTerminal.Enabled = false; TBAsientos.Enabled = false; TBParadas.Enabled = false; DTPFechaPartida.Enabled = false; CBHoraPartida.Enabled = false; CBMinutosPartida.Enabled = false; DTPFechaArribo.Enabled = false; CBHoraArribo.Enabled = false; //CBMinutosArribo.Enabled = false; TBNumero.Focus(); _objNacional = null; }
protected void btnModificar_Click(object sender, EventArgs e) { try { Nacionales n = (Nacionales)Session["ViajeNacional"]; if (n.c.nombre != txtCompania.Text) { n.c = FabricaLogica.GetLogicaCompania().BuscarCompaniaActivas(txtCompania.Text); } if (n.t.codigo != txtDestino.Text) { n.t = FabricaLogica.GetLogicaTerminal().BuscarTerminalActiva(txtDestino.Text); } n.e = (Empleado)Session["Empleado"]; n.cantAsientos = Convert.ToInt32(txtAsiento.Text); n.paradas = Convert.ToInt32(txtParadas.Text); n.partida = FechaYHora3.Fecha; n.arribo = FechaYHora4.Fecha; Panel2.Enabled = false; txtBusqueda.Enabled = true; txtBusqueda.Text = ""; txtAsiento.Text = ""; txtParadas.Text = ""; txtDestino.Text = ""; txtCompania.Text = ""; BtnEliminar.Enabled = false; FabricaLogica.GetLogicaViajes().ModificarViaje(n); lblError.Text = "Viaje modificado con éxito"; } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void btnAgregar_Click(object sender, EventArgs e) { try { Compania C = FabricaLogica.GetLogicaCompania().BuscarCompaniaActivas(txtCompania.Text); Empleado E = (Empleado)Session["Empleado"]; Terminal T = FabricaLogica.GetLogicaTerminal().BuscarTerminalActiva(txtDestino.Text); Nacionales N = new Nacionales(Convert.ToInt32(txtBusqueda.Text), Convert.ToInt32(txtAsiento.Text), FechaYHora3.Fecha, FechaYHora4.Fecha, E, T, C, Convert.ToInt32(txtParadas.Text)); FabricaLogica.GetLogicaViajes().AltaViaje(N); Panel2.Enabled = false; txtBusqueda.Enabled = true; txtBusqueda.Text = ""; txtAsiento.Text = ""; txtParadas.Text = ""; txtDestino.Text = ""; txtCompania.Text = ""; lblError.Text = "Viaje registrado con éxito."; } catch (Exception ex) { lblError.Text = ex.Message; } }
public void Alta_Nacional(Nacionales unNac) { SqlConnection oConexion = new SqlConnection(Conexion.STR); SqlCommand oComando = new SqlCommand("Alta_ViajeNacional", oConexion); oComando.CommandType = CommandType.StoredProcedure; oComando.Parameters.AddWithValue("@numero", unNac.Numero); oComando.Parameters.AddWithValue("@compania", unNac.Compania.Nombre); oComando.Parameters.AddWithValue("@destino", unNac.Terminal.Codigo); oComando.Parameters.AddWithValue("@fecha_partida", unNac.Fecha_partida); oComando.Parameters.AddWithValue("@fecha_arribo", unNac.Fecha_arribo); oComando.Parameters.AddWithValue("@asientos", unNac.Asientos); oComando.Parameters.AddWithValue("@empleado", unNac.Empleado.Cedula); oComando.Parameters.AddWithValue("@paradas", unNac.Paradas); SqlParameter oRetorno = new SqlParameter("@Retorno", SqlDbType.Int); oRetorno.Direction = ParameterDirection.ReturnValue; oComando.Parameters.Add(oRetorno); try { oConexion.Open(); oComando.ExecuteNonQuery(); if (Convert.ToInt32(oRetorno.Value) == -1) { throw new Exception("El número de viaje ingresado ya existe en la base de datos"); } if (Convert.ToInt32(oRetorno.Value) == -2) { throw new Exception("Ya existe un viaje al destino indicado en ese horario. Los viajes al mismo destino deben tener un mínimo de 2 horas de diferencia entre ellos."); } if (Convert.ToInt32(oRetorno.Value) == -3) { throw new Exception("La compañía ingresada no existe en la base de datos o está dada de baja."); } if (Convert.ToInt32(oRetorno.Value) == -4) { throw new Exception("La terminal ingresada no existe en la base de datos o está dada de baja."); } if (Convert.ToInt32(oRetorno.Value) == -5) { throw new Exception("El empleado logueado no existe en la base de datos o está dado de baja."); } if (Convert.ToInt32(oRetorno.Value) == -6 || Convert.ToInt32(oRetorno.Value) == -7) { throw new Exception("Se produjo un error al intentar dar de alta el viaje. Inténtelo nuevamente."); } } catch (SqlException) { throw new Exception("La base de datos no se encuantra disponible. Contacte al administrador."); } catch (Exception ex) { throw new Exception("Problemas con la base de datos: " + ex.Message); } finally { oConexion.Close(); } }
private void BtnDeshacer_Click(object sender, EventArgs e) { _objNacional = null; this.ActivoPorDefecto(); }
public void ParaPoderSerializar(Nacionales unNac, Internacionales unInter) { }
public Nacionales DeclaroVNacional(Nacionales N) { return(N); }
public void AltaViajeNacionales(Viajes V) { SqlConnection DBCS = Conexion.CrearCnn(); Nacionales N = (Nacionales)V; SqlCommand comando = new SqlCommand("AltaViajeNacional", DBCS); comando.CommandType = CommandType.StoredProcedure; comando.Parameters.Add(new SqlParameter("@Numero", N.numero)); comando.Parameters.Add(new SqlParameter("@CantAsientos", N.cantAsientos)); comando.Parameters.Add(new SqlParameter("@Partida", N.partida)); comando.Parameters.Add(new SqlParameter("@Arribo", N.arribo.ToString("yyyyMMdd HH:mm"))); comando.Parameters.Add(new SqlParameter("@CIEmpleado", N.e.ci)); comando.Parameters.Add(new SqlParameter("@NomCompania", N.c.nombre)); comando.Parameters.Add(new SqlParameter("@CodTerminal", N.t.codigo)); comando.Parameters.Add(new SqlParameter("@Paradas", N.paradas)); SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int); retorno.Direction = ParameterDirection.ReturnValue; comando.Parameters.Add(retorno); try { DBCS.Open(); comando.ExecuteNonQuery(); int r = Convert.ToInt32(retorno.Value); if (r == -1) { throw new Exception("ExcepcionEX:Ya existe un viaje con ese número.FinExcepcionEX"); } if (r == -2) { throw new Exception("ExcepcionEX:El empleado ingresado no es correcto.FinExcepcionEX"); } if (r == -3) { throw new Exception("ExcepcionEX:La terminal ingresada no es correcta.FinExcepcionEX"); } if (r == -4) { throw new Exception("ExcepcionEX:La compañía ingresada no es correcta.FinExcepcionEX"); } if (r == -5) { throw new Exception("ExcepcionEX:No pueden existir viajes con menos de dos horas de diferencia al mismo destino.FinExcepcionEX"); } if (r == -6) { throw new Exception("ExcepcionEX:Error al dar de alta el viaje.FinExcepcionEX"); } } catch (Exception ex) { throw ex; } finally { DBCS.Close(); } }
private void btnModificar_Click(object sender, EventArgs e) { try { int salida = 0; bool bandera = true; WebService WS = new WebService(); objNacionales = new Nacionales(); objNacionales.numero = Convert.ToInt32(txtNumero.Text); objNacionales.partida = dtpPartida.Value; objNacionales.arribo = dtpArribo.Value; objNacionales.e = empLogueado; if (Int32.TryParse(txtCantAsientos.Text, out salida)) { objNacionales.cantAsientos = salida; bandera = true; } else { lblError.Text = "Ingrese una cantidad de asientos válida."; bandera = false; } foreach (Terminal t in listaT) { if (t.codigo == cbTerminal.SelectedItem.ToString()) { objNacionales.t = t; } } foreach (Compania c in listaC) { if (c.nombre == cbCompañia.SelectedItem.ToString()) { objNacionales.c = c; } } if (Int32.TryParse(txtCantParadas.Text, out salida)) { objNacionales.paradas = salida; bandera = true; } else { lblError.Text = "Ingrese una cantidad de paradas válida."; bandera = false; } if (bandera == true) { WS.ModificarViaje(objNacionales); this.ActivoPorDefecto(); lblError.Text = "Modificacion con éxito."; errorProvider1.Clear(); } } catch (System.Web.Services.Protocols.SoapException ex) { manejoErrorWS(ex.Message); } catch (Exception ex) { lblError.Text = ex.Message; } }