public TipoId FindById(char codigo) { TipoId tipoId = null; SqlConnection sqlConnection = new SqlConnection(Utilities.GetConnectionString()); SqlCommand sqlCommand = new SqlCommand(SpTipoId.FIND_BY_ID, sqlConnection) { CommandType = System.Data.CommandType.StoredProcedure }; sqlCommand.Parameters.Add(new SqlParameter("@TIDCODIGO", codigo)); try { sqlConnection.Open(); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { tipoId = new TipoId( sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), Convert.ToChar(sqlDataReader.GetString(3)) ); } } catch (SqlException exc) { Console.WriteLine(exc.ToString()); } finally { sqlConnection.Close(); } return(tipoId); }
public void Update(TipoId tipoId) { SqlConnection sqlConnection = new SqlConnection(Utilities.GetConnectionString()); SqlCommand sqlCommand = new SqlCommand(SpTipoId.RUD, sqlConnection) { CommandType = System.Data.CommandType.StoredProcedure }; sqlCommand.Parameters.Add(new SqlParameter("@TIDCODIGO", tipoId.Codigo)); sqlCommand.Parameters.Add(new SqlParameter("@DESCRIPCION", tipoId.Descripcion)); sqlCommand.Parameters.Add(new SqlParameter("@ESTADO", tipoId.Estado)); sqlCommand.Parameters.Add(new SqlParameter("@SECUENCIA", tipoId.Secuencia)); sqlCommand.Parameters.Add(new SqlParameter("@ACTION", 'U')); try { sqlConnection.Open(); sqlCommand.ExecuteNonQuery(); } catch (SqlException exc) { Console.WriteLine(exc.ToString()); } finally { sqlConnection.Close(); } }
public List <TipoPlan> FindByDescription(string description) { List <TipoPlan> tipoPlans = new List <TipoPlan>(); SqlConnection sqlConnection = new SqlConnection(Utilities.GetConnectionString()); SqlCommand sqlCommand = new SqlCommand(SpTipoPlan.FIND_BY_DESCRIPCION, sqlConnection) { CommandType = System.Data.CommandType.StoredProcedure }; sqlCommand.Parameters.Add(new SqlParameter("@DESCRIPCION", description)); try { sqlConnection.Open(); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { TipoId tipoId = new TipoId( sqlDataReader.GetInt32(12), sqlDataReader.GetString(13), sqlDataReader.GetString(14), Convert.ToChar(sqlDataReader.GetString(15)) ); TipoDescuento tipoDescuento = new TipoDescuento( sqlDataReader.GetInt32(6), sqlDataReader.GetString(7), tipoId, sqlDataReader.GetString(9), sqlDataReader.GetInt32(10), Convert.ToChar(sqlDataReader.GetString(11)) ); TipoPlan tipoPlan = new TipoPlan( sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), tipoDescuento, sqlDataReader.GetString(3), sqlDataReader.GetInt32(4), Convert.ToChar(sqlDataReader.GetString(5)) ); tipoPlans.Add(tipoPlan); } } catch (SqlException exc) { Console.WriteLine(exc.ToString()); } finally { sqlConnection.Close(); } return(tipoPlans); }
public List <Profesor> FindById(string cedula) { List <Profesor> profesors = new List <Profesor>(); SqlConnection sqlConnection = new SqlConnection(Utilities.GetConnectionString()); SqlCommand sqlCommand = new SqlCommand(SpProfesor.FIND_BY_ID, sqlConnection) { CommandType = System.Data.CommandType.StoredProcedure }; sqlCommand.Parameters.Add(new SqlParameter("@CEDULA", cedula)); try { sqlConnection.Open(); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { TipoId tipoId = new TipoId( sqlDataReader.GetInt32(10), sqlDataReader.GetString(11), sqlDataReader.GetString(12), Convert.ToChar(sqlDataReader.GetString(13)) ); Profesor profesor = new Profesor( sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), sqlDataReader.GetString(3), sqlDataReader.GetString(4), sqlDataReader.GetString(5), sqlDataReader.GetString(6), Convert.ToChar(sqlDataReader.GetString(8)), tipoId, Convert.ToChar(sqlDataReader.GetString(9)) ); profesors.Add(profesor); } } catch (SqlException exc) { Console.WriteLine(exc.ToString()); } finally { sqlConnection.Close(); } return(profesors); }
public List <Cliente> FindById(string cedula) { List <Cliente> clientes = new List <Cliente>(); SqlConnection sqlConnection = new SqlConnection(Utilities.GetConnectionString()); SqlCommand sqlCommand = new SqlCommand(SpCliente.FIND_BY_ID, sqlConnection) { CommandType = System.Data.CommandType.StoredProcedure }; sqlCommand.Parameters.Add(new SqlParameter("@CEDULA", cedula)); try { sqlConnection.Open(); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { TipoId tipoId = new TipoId( sqlDataReader.GetInt32(8), sqlDataReader.GetString(9), sqlDataReader.GetString(10), Convert.ToChar(sqlDataReader.GetString(11)) ); Cliente cliente = new Cliente( sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), sqlDataReader.GetString(3), sqlDataReader.GetString(4), sqlDataReader.GetString(5), tipoId, Convert.ToChar(sqlDataReader.GetString(7)) ); clientes.Add(cliente); } } catch (SqlException exc) { Console.WriteLine(exc.ToString()); } finally { sqlConnection.Close(); } return(clientes); }
public List <TipoDescuento> FindAll() { List <TipoDescuento> tipoDescuentos = new List <TipoDescuento>(); SqlConnection sqlConnection = new SqlConnection(Utilities.GetConnectionString()); SqlCommand sqlCommand = new SqlCommand(SpTipoDescuento.FIND_ALL, sqlConnection) { CommandType = System.Data.CommandType.StoredProcedure }; try { sqlConnection.Open(); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { TipoId tipoId = new TipoId( sqlDataReader.GetInt32(6), sqlDataReader.GetString(7), sqlDataReader.GetString(8), Convert.ToChar(sqlDataReader.GetString(9)) ); TipoDescuento tipoDescuento = new TipoDescuento( sqlDataReader.GetInt32(0), sqlDataReader.GetString(1), tipoId, sqlDataReader.GetString(3), sqlDataReader.GetInt32(4), Convert.ToChar(sqlDataReader.GetString(5)) ); tipoDescuentos.Add(tipoDescuento); } } catch (SqlException exc) { Console.WriteLine(exc.ToString()); } finally { sqlConnection.Close(); } return(tipoDescuentos); }
private void BotonCrear_Click(object sender, EventArgs e) { //Validaciones int verificacion = 1; DateTime fechaNacimientoCliente = FechaNacimiento.Value; string selectDateAsString = FechaNacimiento.Value.ToString("yyyy-MM-dd"); if (Nombre.Text == "") { MessageBox.Show("Debe completar el campo nombre", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (Apellido.Text == "") { MessageBox.Show("Debe completar el campo apellido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } String tipoIdCliente = TipoId.Text; if (tipoIdCliente == "" || tipoIdCliente == "Vacío") { MessageBox.Show("Seleccione el tipo de identificación.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (nroId.Text == "") { MessageBox.Show("Debe completar el número de identificación.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (Mail.Text == "") { MessageBox.Show("Debe insertar un mail.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } else { if (!validarEmail(Mail.Text)) { MessageBox.Show("El mail es inválido.", "Error"); verificacion = 0; } } if (utilizador.estaRepetidoMail(Mail.Text)) { MessageBox.Show("El mail está repetido.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (Telefono.Text == "") { MessageBox.Show("Debe insertar un telefono.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (cbPaises.Text == "" || cbPaises.SelectedItem.ToString() == "Vacío") { MessageBox.Show("Debe seleccionar un país.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (Localidad.Text == "") { MessageBox.Show("Debe insertar una localidad.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (Calle.Text == "") { MessageBox.Show("Debe insertar una calle.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (Nacionalidad.Text == "") { MessageBox.Show("Debe insertar una nacionalidad.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); verificacion = 0; } if (verificacion == 0) { return; } int nroCalleCliente = int.Parse(NroCalle.Text); int nroIdCliente = int.Parse(nroId.Text); //si un usuario intenta ingresar un tipo de identificación junto con un nro de identificacion que coincide con //el de otro cliente, no debe permitirse que lo ingrese if (utilizador.estaRepetidoIdentificacion(nroIdCliente, tipoIdCliente)) { MessageBox.Show("Ya existe un usuario con esa identificación."); return; } //comienzo del proceso de dar de alta en sí String cadenaAltaCliente = "PISOS_PICADOS.SPAltaCliente"; SqlCommand comandoAltaCliente = new SqlCommand(cadenaAltaCliente, Globals.conexionGlobal); comandoAltaCliente.CommandType = CommandType.StoredProcedure; //agregar parametros al sp que se encarga de dar de alta a un cliente comandoAltaCliente.Parameters.Add("@nombre", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@apellido", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@tipo", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@numeroI", SqlDbType.Int); comandoAltaCliente.Parameters.Add("@mail", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@telefono", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@calle", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@numeroC", SqlDbType.Int); comandoAltaCliente.Parameters.Add("@localidad", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@pais", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@nacionalidad", SqlDbType.VarChar); comandoAltaCliente.Parameters.Add("@fechaNacimiento", SqlDbType.DateTime); var retorno = comandoAltaCliente.Parameters.Add("@idCliente", SqlDbType.Int); retorno.Direction = ParameterDirection.ReturnValue; //cargar valores a los paramtros agregados en el paso anterior comandoAltaCliente.Parameters["@nombre"].Value = Nombre.Text; comandoAltaCliente.Parameters["@apellido"].Value = Apellido.Text; comandoAltaCliente.Parameters["@tipo"].Value = tipoIdCliente; comandoAltaCliente.Parameters["@numeroI"].Value = nroIdCliente; comandoAltaCliente.Parameters["@mail"].Value = Mail.Text; comandoAltaCliente.Parameters["@telefono"].Value = Telefono.Text; comandoAltaCliente.Parameters["@calle"].Value = Calle.Text; comandoAltaCliente.Parameters["@numeroC"].Value = nroCalleCliente; comandoAltaCliente.Parameters["@localidad"].Value = Localidad.Text; comandoAltaCliente.Parameters["@pais"].Value = cbPaises.Text; comandoAltaCliente.Parameters["@nacionalidad"].Value = Nacionalidad.Text; comandoAltaCliente.Parameters["@fechaNacimiento"].Value = fechaNacimientoCliente.ToString("yyyy-MM-dd"); int idCliente; //ejecuta el sp que da alta al cliente tomando los valores ingresados en el form try { comandoAltaCliente.ExecuteNonQuery(); idCliente = (int)retorno.Value; MessageBox.Show("Alta realizada correctamente"); } catch { MessageBox.Show("Error al crear cliente.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //reinicio de los textbox Nombre.ResetText(); Apellido.ResetText(); TipoId.ResetText(); nroId.ResetText(); Mail.ResetText(); Telefono.ResetText(); Calle.ResetText(); NroCalle.ResetText(); Localidad.ResetText(); Nacionalidad.ResetText(); FechaNacimiento.ResetText(); //volver a reserva luego de alta de cliente if (vueltaAReserva == 1) { MessageBox.Show(idCliente.ToString()); frmGenerarReservaInstance.setCliente(idCliente); frmGenerarReservaInstance.volver(this); } this.Close(); }