示例#1
0
        /// <summary>
        /// OK Button Click - When a user clicks the OK button
        /// save any changes and rediret them to the main page
        /// </summary>
        protected void OK_Click(object sender, System.EventArgs e)
        {
            //
            //
            //	Get the client context from the session variables
            //
            IAzClientContext AzClient = ExpenseCommon.GetAzClientContext();

            //
            //	Check if the user has access to the administer
            //	operation and then save application settings
            //

            //
            //	Contains the scope of the access check request
            //	which is set to the application level (null)
            //
            object[] scope = new Object[1];
            scope[0] = (object)"";

            //
            //	Contains all the operations associated with
            //	changing the application settings
            //	In this case the administer operation
            //
            object[] operations = new Object[1];
            operations[0] = ExpenseCommon.AzopAdministrater;

            //
            //	Contains all the parameter names associated with
            //	application settings.  These are organized as
            //	name-value pairs and passed to the business rule
            //	if one is defined.
            //
            //	THEY MUST BE IN ALPHABETICAL ORDER (A-Z)
            //
            Object[] BRNames = new Object[3];
            BRNames[0] = (object)ExpenseCommon.ParamAmount;
            BRNames[1] = (object)ExpenseCommon.ParamDate;
            BRNames[2] = (object)ExpenseCommon.ParamUserName;

            //
            //	Contains all the paramenter values associted with
            //	the application settings.
            //
            Object[] BRValues = new Object[3];
            BRValues[0] = (object)0;
            BRValues[1] = (object)DateTime.Now.ToShortDateString();
            BRValues[2] = (object)ExpenseCommon.GetClientSamName();

            //
            //	Run the access check on the administer operation
            //	Passing the audit text, scope, operations and business rule parameters
            //
            object[] results = (object[])AzClient.AccessCheck("Change Application Settings", (object)scope, (object)operations, BRNames, BRValues, null, null, null);

            //
            //	Check for success of the access check
            //
            bool bAuthorized = true;

            foreach (int iResCode in results)
            {
                //
                //	Check for access denied
                //
                if (iResCode == ExpenseCommon.AccessDenied)
                {
                    string errorMessage = AzClient.GetBusinessRuleString();
                    if (errorMessage != "")
                    {
                        Message.Text = "Admin Denied. " + errorMessage;
                    }
                    else
                    {
                        Message.Text = "Access Denied.  You do not have sufficient permissions to perform this operation.";
                    }
                    bAuthorized = false;
                    break;
                }
                //
                //	Check for other error
                //
                else if (iResCode != ExpenseCommon.NoError)
                {
                    Win32Exception ex = new Win32Exception();
                    Message.Text = "There was an error performing the AccessCheck: " + ex.Message;
                }
            }

            if (bAuthorized == true)
            {
                //
                //	Save the Self Approval setting
                //
                ExpenseCommon.SetApproval(self_approval.Checked);

                //
                //	Save the Maximum Number of Tranascitons setting
                //
                ExpenseCommon.SetMaxTransaction(Convert.ToInt32(max_trans.Text));

                //
                //	Redirect the user to the main page
                //
                Response.Redirect("../index.aspx", false);
            }
            else
            {
                //
                //	Display reason for the access check failure
                //
                Message.Text = "Error Access Denied:" + AzClient.GetBusinessRuleString();
            }
        }
        /// <summary>
        /// OK Button Click - When a user clicks the OK button
        /// save any changes and rediret them to the main page
        /// </summary>
        protected void OK_Click(object sender, System.EventArgs e)
        {
            //
            //	Check if the user has access to the administer
            //	operation and then save application settings
            //

            //
            //
            //	Get the client context from the session variables
            //
            IAzClientContext3 AzClient = ExpenseCommon.GetAzClientContext();

            //
            // Set BizRule Parameters
            //
            IAzBizRuleParameters BizRuleParams = AzClient.BizRuleParameters;

            BizRuleParams.AddParameter("Amount", 0);
            BizRuleParams.AddParameter("Date", DateTime.Now.ToShortDateString());
            BizRuleParams.AddParameter("SubmitterName", "");
            BizRuleParams.AddParameter("UserName", ExpenseCommon.GetClientSamName());

            //
            //	Run the access check on the administer operation
            //	Passing the audit text, scope, operations
            //

            uint result = AzClient.AccessCheck2("Administration", "", ExpenseCommon.AzopAdministrater);

            //
            //	Check for success of the access check
            //
            bool bAuthorized = false;

            if (result == ExpenseCommon.NoError)
            {
                bAuthorized = true;
            }

            else if (result == ExpenseCommon.AccessDenied)
            {
                string errorMessage = AzClient.GetBusinessRuleString();
                if (errorMessage != "")
                {
                    Message.Text = "<font color=\"FF0000\">Access Denied. " + errorMessage + "</font>";
                }
                else
                {
                    Message.Text = "<font color=\"FF0000\">Access Denied.  You do not have sufficient permissions to perform this operation.</font>";
                }
                bAuthorized = false;
            }
            else
            {
                //
                //	Check for other error
                //
                if (result != ExpenseCommon.NoError)
                {
                    Win32Exception ex = new Win32Exception();
                    Message.Text = "<font color=\"FF0000\">There was an error performing the AccessCheck: " + ex.Message + "</font>";
                }
            }

            if (bAuthorized == true)
            {
                //
                //	Save the Self Approval setting
                //
                ExpenseCommon.SetApproval(self_approval.Checked);

                //
                //	Save the Maximum Number of Tranascitons setting
                //
                ExpenseCommon.SetMaxTransaction(Convert.ToInt32(max_trans.Text));

                //
                //	Redirect the user to the main page
                //
                Response.Redirect("../index.aspx", false);
            }
            else
            {
                //
                //	Display reason for the access check failure
                //
                Message.Text = "<font color=\"FF0000\">Error Access Denied. " + AzClient.GetBusinessRuleString() + "</font>";
            }
        }