Example #1
0
        public bool InsertarUsuario(objNuevoUsuario Usuario)
        {
            MySql.Data.MySqlClient.MySqlConnection dbConn = new MySql.Data.MySqlClient.MySqlConnection("Persist Security Info=False;server=localhost;database=hotel_bd;uid=conexion;password=pruebas1.");
            bool         idnumber = false;
            MySqlCommand cmd      = dbConn.CreateCommand();

            cmd.CommandText = @" INSERT INTO usuario(username, password, email, dni, nombre, apellidos, direccion, tlf, enabled)  
                                VALUES('" + Usuario.strUser + "', '" + Usuario.strPass + "', '" + Usuario.strCorreo + "', " + Usuario.int64Dni + "," +
                              " '" + Usuario.strNombre + "', '" + Usuario.strApellidos + "', '" + Usuario.strDireccion + "', " + Usuario.strTelefono + ", 1)";

            try
            {
                dbConn.Open();
            }
            catch (Exception erro)
            {
                strMensajeError = erro.Message;
                dbConn.Close();
            }
            try
            {
                int reader = cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                strMensajeError = e.Message;
                return(false);
            }
            return(idnumber);
        }
Example #2
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            if (txtNombreUsuario.Text.Trim() != "" && TxtPass.Text.Trim() != "" && txtNombre.Text.Trim() != "" &&
                txtApellidos.Text.Trim() != "" && txtId.Text.Trim() != "")
            {
                objNuevoUsuario objUsuario = new objNuevoUsuario()
                {
                    strUser      = txtNombreUsuario.Text,
                    strPass      = TxtPass.Text,
                    strCorreo    = txtEmail.Text,
                    strDireccion = txtDireccion.Text,
                    strNombre    = txtNombre.Text,
                    strApellidos = txtApellidos.Text,
                    strTelefono  = txtTelefono.Text,
                    int64Dni     = Convert.ToInt64(txtId.Text),
                };

                CtrlHotel objHotel = new CtrlHotel();

                if (objHotel.insertarUsuario(objUsuario))
                {
                    dvCorrecto.Visible = true;
                    dvError.Visible    = false;
                }
                else
                {
                    dvCorrecto.Visible = false;
                    dvError.Visible    = true;
                    lblError.Text      = objHotel.strReturnMessage;
                }
            }
            else
            {
                if (txtNombreUsuario.Text == "")
                {
                    lblError1.Visible = true;
                }
                if (TxtPass.Text == "")
                {
                    lblError2.Visible = true;
                }
                if (txtNombre.Text == "")
                {
                    lblError3.Visible = true;
                }
                if (txtApellidos.Text == "")
                {
                    lblError4.Visible = true;
                }
                if (txtId.Text == "")
                {
                    lblError5.Visible = true;
                }

                dvCorrecto.Visible = false;
                dvError.Visible    = true;
                lblError.Text      = "Debe ingresar los campos obligatorios!";
            }
        }
Example #3
0
        public bool InsertarUsuario(objNuevoUsuario Usuario)
        {
            if (this.OpenConnection())
            {
                bool         idnumber = false;
                MySqlCommand cmd      = Conexion.CreateCommand();
                cmd.CommandText = @" INSERT INTO usuario(username, password, email, dni, nombre, apellidos, direccion, tlf, enabled)  
                                VALUES(@usuario, @contra, @mail, @dpi," +
                                  " @nombreb, @apellido, @direccion, @telefono, 1)";

                cmd.Parameters.AddWithValue("@usuario", Usuario.strUser);
                cmd.Parameters.AddWithValue("@contra", Usuario.strPass);
                cmd.Parameters.AddWithValue("@mail", Usuario.strCorreo);
                cmd.Parameters.AddWithValue("@dpi", Usuario.int64Dni);
                cmd.Parameters.AddWithValue("@nombreb", Usuario.strNombre);
                cmd.Parameters.AddWithValue("@apellido", Usuario.strApellidos);
                cmd.Parameters.AddWithValue("@direccion", Usuario.strDireccion);
                cmd.Parameters.AddWithValue("@telefono", Usuario.strTelefono);


                try
                {
                    int reader = cmd.ExecuteNonQuery();
                    idnumber = true;
                }
                catch (Exception e)
                {
                    strMensajeError = e.Message;
                    return(false);
                }
                this.CloseConnection();
                return(idnumber);
            }
            else
            {
                strMensajeError = "Error al iniciar la conexion";
                return(false);
            }
        }