private void CrearParametros(OdbcCommand command, ProtectorEntity entidad) { OdbcParameter parameter = null; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Correo; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Nombre; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Apellido; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Organizacion; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Clave; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Direccion; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Telefono; parameter = command.Parameters.Add("?", OdbcType.VarChar); parameter.Value = entidad.Tipo; /* Validacion de campos no necesario en la entidad * if (entidad.TieneCorreoE()) * parameter.Value = entidad.CorreoE; * else * parameter.Value = System.DBNull.Value;*/ }
public void Insertar(ProtectorEntity entidad) { Validar(entidad); protector.Insertar(entidad); /* try * { * * Validar(entidad);//TODAVIA no implementado * * // TODO Si el usuario existe en la base de datos... * if (protector.BuscarPorClavePrimaria(entidad.Id_protector) != null) * { * // ...se lanza la excepción correspondiente. * throw new protectorExisteException(entidad.Id_protector); * } * * // Si no existe el empleado, se crea. * * } * catch (daException ex) * { * throw new boException(ex); * }*/ }
protected void btnAceptar_Click(object sender, System.EventArgs e) { // Se crea un objeto protector entidad y se le asignan los // datos ingresados por el usuario. ProtectorEntity entidad = new ProtectorEntity(); entidad.Correo = TextCorreo.Text; entidad.Nombre = TextNombre.Text; entidad.Apellido = TextApellido.Text; entidad.Organizacion = TextOrg.Text; entidad.Clave = TextBoxContrase.Text; entidad.Direccion = TextDireccion.Text; entidad.Telefono = TextTelefono.Text; //entidad.Tipo = TextTipo.Text; LblEstado.Text = "Ingreso correcto"; if (Convert.ToBoolean(ViewState["Nuevo"])) { protector.Insertar(entidad); } // Server.Transfer("EmpleadoOk.aspx"); TextCorreo.Text = ""; TextNombre.Text = ""; TextApellido.Text = ""; TextOrg.Text = ""; TextBoxContrase.Text = ""; TextDireccion.Text = ""; TextTelefono.Text = ""; }
private void Validar(ProtectorEntity entidad) { if (entidad.Organizacion == "" || entidad.Nombre == "" || entidad.Apellido == "" || entidad.Telefono == "") { throw new DatosObligatoriosException(); } }
private void CargarDatos() { ProtectorEntity entidad = (ProtectorEntity)Context.Items["Usuario"]; TextCorreo.Text = entidad.Correo; TextNombre.Text = entidad.Nombre; TextApellido.Text = entidad.Apellido; TextOrg.Text = entidad.Organizacion; TextBoxContrase.Text = entidad.Clave; TextDireccion.Text = entidad.Direccion; TextTelefono.Text = entidad.Telefono; TextTipo.Text = entidad.Tipo; }
private ProtectorEntity CrearEntidad(OdbcDataReader dr) { ProtectorEntity entidad = new ProtectorEntity(); entidad.Correo = dr["CORREO"].ToString(); entidad.Nombre = dr["NOMBRE"].ToString(); entidad.Apellido = dr["APELLIDO"].ToString(); entidad.Organizacion = dr["ORGANIZACION"].ToString(); entidad.Clave = dr["CLAVE"].ToString(); entidad.Direccion = dr["DIRECCION"].ToString(); entidad.Telefono = dr["TELEFONO"].ToString(); entidad.Tipo = dr["TIPO"].ToString(); return(entidad); }
public void Actualizar(ProtectorEntity entidad) { // TODO implementar metodo actualizar /* try * { * // Valida los datos cargados por el usuario. * Validar(entidad); * * // Si el empleado no existe en la base de datos... * if (protector.BuscarPorClavePrimaria(entidad.Id_protector) == null) * { * // ...se lanza la excepción correspondiente. * throw new protectorNoExisteException(entidad.Id_protector); * } * * // Si existe, se actualizan los datos. * protector.Actualizar(entidad); * } * catch (daException ex) * { * throw new boException(ex); * }*/ }
private void EjecutarComando(daComun.TipoComandoEnum sqlCommandType, ProtectorEntity entidad) { //asignando protectorID manual para prueba //entidad.Correo = ""; // Conexión a la base de datos. OdbcConnection connection = null; // Comando a ejecutar en la base de datos. OdbcCommand command = null; try { // Se obtiene una conexión abierta. connection = (OdbcConnection)connectionDA.GetOpenedConnection(); // Se crea el parámetro Legajo y se le asigna el valor. //IDataParameter paramProtectorId = new OdbcParameter("?", OdbcType.VarChar); //paramProtectorId.Value = entidad.Correo; // Dependiendo de la acción que se quiera realizar: switch (sqlCommandType) { case daComun.TipoComandoEnum.Insertar: // Se crea el comando con la sentendia Insert, // se le agrega el parámetro legajo y luego el resto de // los parámetros. command = new OdbcCommand(SQLInsert, connection); //command.Parameters.Add(paramProtectorId); CrearParametros(command, entidad); break; //TODO actualizar info del protector /*case daComun.TipoComandoEnum.Actualizar: * // Se crea el comando con la sentendia Update, * // se crean los parámetros comunes y luego se * // agrega el parámetro Legajo. * // Esto se hace en este orden porque si miramos la * // sentencia Update, veremos que el parámetro Legajo * // es el último. * command = new OdbcCommand(SQLUpdate, connection); * CrearParametros(command, entidad); * command.Parameters.Add(paramLegajo); * break;*/ // TODO borrar info de la DB /*case daComun.TipoComandoEnum.Eliminar: * // Se crea el comando con la sentendia Delete y * // se agrega el parámetro Legajo. * command = new OdbcCommand(SQLDelete, connection); * command.Parameters.Add(paramLegajo); * break;*/ } // Se ejecuta el comando en la base de datos. command.ExecuteNonQuery(); // Se cierra la conexión. connection.Close(); } catch (Exception ex) { // En caso de que se produzca un error, se lo lanza hacia la // capa superior. throw new daException(ex); } finally { // Esta parte del código se ejecuta siempre. if (command != null) { // Se libera el recurso. command.Dispose(); } if (connection != null) { // Se libera el recurso. connection.Dispose(); } } }
// TODO actualizar el usuario public void Actualizar(ProtectorEntity entidad) {/* * EjecutarComando(daComun.TipoComandoEnum.Actualizar, entidad);*/ }
public void Insertar(ProtectorEntity entidad) { EjecutarComando(daComun.TipoComandoEnum.Insertar, entidad); }