예제 #1
0
파일: Rol.cs 프로젝트: JSalazr/Teoria
        private void Delete_Click(object sender, EventArgs e)
        {
            IngresConnection con = new IngresConnection(Login.myConnectionString);

            con.Open();
            IngresCommand cmd = new IngresCommand();

            cmd.Connection  = con;
            cmd.CommandText = "rol_delete";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new IngresParameter("t_id_rol", IngresType.Decimal));
            cmd.Parameters["t_id_rol"].Value = int.Parse(this.metroTextBox1.Text);
            IngresTransaction trans = con.BeginTransaction();

            cmd.Transaction = trans;
            try
            {
                cmd.ExecuteNonQuery();
                trans.Commit();
                MetroMessageBox.Show(this, "Elemento eliminado correctamente.", "Nota", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
            catch (IngresException c)
            {
                MetroMessageBox.Show(this, c.ErrorCode + c.Message, "Error");
            }
            con.Close();
            this.read();
        }
        /// <summary>
        /// This method takes a role name and determines whether the role exists.
        /// </summary>
        /// <remarks>
        /// This method overrides a method from the <c>System.Web.Security.RoleProvider</c> class to provide an Ingres
        /// specific implementation.
        /// </remarks>
        /// <param name="roleName">Role name to check the existence of.</param>
        /// <returns>Whether the given role exists.</returns>
        public override bool RoleExists(string roleName)
        {
            bool result = false;

            IngresTransaction tran = null;

            try
            {
                using (IngresConnection conn = new IngresConnection(this.config.ConnectionString))
                {
                    // Open the connection and start a new transaction
                    conn.Open();

                    tran = conn.BeginTransaction();

                    // Call the implementation of the method
                    result = this.GetHandler(conn, tran).RoleExists(roleName);

                    // Commit the transaction
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                // Attempt to rollback
                try
                {
                    if (tran != null && tran.Connection != null)
                    {
                        tran.Rollback();
                    }
                }
                catch
                {
                    // Add the rollback error.
                    ExceptionHandler.LogRollbackWarning(RoleProviderMethod.RoleExists);
                }

                // Handle the exception appropriately
                ExceptionHandler.HandleException(ex, RoleProviderMethod.RoleExists);
            }

            return(result);
        }
        /// <summary>
        /// Takes an array of user names and an array of role names and removes the specified users
        /// from the specified roles.
        /// </summary>
        /// <remarks>
        /// <para>
        /// <c>RemoveUsersFromRoles</c> throws a <c>ProviderException</c> if any of the users or roles do not
        /// exist, or if any user specified in the call does not belong to the role from which he
        /// or she is being removed.
        /// </para>
        /// <para>
        /// This method overrides a method from the <c>System.Web.Security.RoleProvider</c> class to provide an Ingres
        /// specific implementation.
        /// </para>
        /// </remarks>
        /// <param name="usernames">The array of usernames.</param>
        /// <param name="roleNames">The array of roles.</param>
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            IngresTransaction tran = null;

            try
            {
                using (IngresConnection conn = new IngresConnection(this.config.ConnectionString))
                {
                    // Open the connection and start a new transaction
                    conn.Open();

                    tran = conn.BeginTransaction();

                    // Call the implementation of the method
                    this.GetHandler(conn, tran).RemoveUsersFromRoles(usernames, roleNames);

                    // Commit the transaction
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                // Attempt to rollback
                try
                {
                    if (tran != null && tran.Connection != null)
                    {
                        tran.Rollback();
                    }
                }
                catch
                {
                    // Add the rollback error.
                    ExceptionHandler.LogRollbackWarning(RoleProviderMethod.RemoveUsersFromRoles);
                }

                // Handle the exception appropriately
                ExceptionHandler.HandleException(ex, RoleProviderMethod.RemoveUsersFromRoles);
            }
        }