/// <summary> /// Submit Decision Click - When the user clicks the Submit button, /// this submits the descision of the user, approve or reject, /// to the application data store. /// </summary> protected void SubmitDecision_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", ExpenseData["Amount"]); BizRuleParams.AddParameter("Date", ExpenseData["Date"]); BizRuleParams.AddParameter("SubmitterName", (object)ExpenseData["User"]); BizRuleParams.AddParameter("UserName", ExpenseCommon.GetClientSamName()); // // Run the access check on the submit operation // Passing the audit text, scope, operations and business rule parameters // uint result = AzClient.AccessCheck2("Approve Expense Report", "", ExpenseCommon.AzopApprove); // // 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) { // // Check for the user has added comments // if (Comment.Text.Length > 0) { // // Attach the comment to the transaction // ExpenseData["Comment"] = string.Concat(ExpenseData["Comment"], "<p><b>Approver Comment: </b></p>", Comment.Text); ExpenseCommon.SaveTransaction(transID, ExpenseData); } // // Check for the user approved or rejected the expense // if (Decision.SelectedValue == "approve") { // // Approve the expense // ExpenseCommon.ApproveTransaction(transID); } else { // // Reject the expense // ExpenseCommon.RejectTransaction(transID); } // // Redirect the user to pending expenses list // Response.Redirect("List.aspx", true); } else { // // If the access check failed, display an error message to the user // Message.Text = "Error Access Denied: " + AzClient.GetBusinessRuleString(); return; } }
/// <summary> /// Page Load - This is executed when the page is first requested /// by the user and additionally when the user clicks a button on /// the form /// </summary> protected void Page_Load(object sender, System.EventArgs e) { // // To prevent users from by-passing the portal page (index.aspx) // and going directly to this page, use URL Authorization // See <url> for details. // // // Get the transaction ID from the posted variables // if no transaction ID was posted, i.e. the user // went directly to this page and not from the List.aspx page, // show an error message // try { transID = Convert.ToInt32(Request.QueryString["transactionId"]); } catch (System.ArgumentNullException) { Message.Text = "There was an error retrieving the transaction ID."; return; } // // Get the expense report data from the transaction ID // and check that the transaction exists // ExpenseData = ExpenseCommon.GetTransData(transID); if (ExpenseData == null) { Message.Text = "There was an error retrieving the transaction data. <br>The specified transaction does not exist."; return; } // // Check for this is the first time the page is being loaded // only fill in the form if this is the first time otherwise // any user changes will be lost // if (!Page.IsPostBack) { // // Check if the approver is also the owner of the // expense report and either display the report // or a message depending on the Self Approval setting // of the application // // // Get the status of the transaction // string transStatus = string.Concat(ExpenseCommon.GetTransactionStatus(transID), ""); // // Check for the transaction has not been approved // if (transStatus == "") { // // Check if the current user is the owner of the expense report // if ((ExpenseCommon.GetClientSamName() == ExpenseData["SamName"])) { // // Check for Self Approval is allowed // if (ExpenseCommon.GetSelfApproval() == false) { // // Self approval is not allowed so do not display the // decision buttons and show an error message // Status.Text = string.Concat(Status.Text, "PENDING", "<P>You are not authorized to approve your own expense.</p>"); DecisionGroup.Visible = false; } else { // // Self Approval is allowed so display the // decision buttons and it's status // Status.Text = string.Concat(Status.Text, "PENDING"); DecisionGroup.Visible = true; } } else { // // The current user is not the owner of the expense report so // display the decision buttons // Status.Text = string.Concat(Status.Text, "PENDING"); DecisionGroup.Visible = true; } } else { // // The expense report has been reviewed already // Display it's status and do not show the decision buttons // Status.Text = string.Concat(Status.Text, transStatus); DecisionGroup.Visible = false; } // // Check if the user has permission to list expenses // // // // Get the client context from the session variables // IAzClientContext3 AzClient = ExpenseCommon.GetAzClientContext(); // // Set BizRule Parameters // IAzBizRuleParameters BizRuleParams = AzClient.BizRuleParameters; BizRuleParams.AddParameter("Amount", ExpenseData["Amount"]); BizRuleParams.AddParameter("Date", DateTime.Now.ToShortDateString()); BizRuleParams.AddParameter("SubmitterName", (object)ExpenseData["User"]); BizRuleParams.AddParameter("UserName", ExpenseCommon.GetClientSamName()); // // Run the access check on the submit operation // Passing the audit text, scope, operations and business rule parameters // uint result = AzClient.AccessCheck2("Read Expense Report", "", ExpenseCommon.AzopRead); // // 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) { // // Display the expense report // DisplayExpense(); } else { // // Access Check failed so display an error message to the user // Message.Text = "Error Access Denied: " + AzClient.GetBusinessRuleString(); return; } } }
/// <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>"; } }
/// <summary> /// Comment TextBox - Allows a user to attach a comment /// to the expense report /// </summary> /// <summary> /// Date TextBox - Date the expense was incurred /// </summary> /// <summary> /// Amount TextBox - Amount of the expense /// </summary> /// <summary> /// Description TextBox - Descriptiong of the expense /// </summary> /// <summary> /// Message Label - Displays any messages to the user /// </summary> /// <summary> /// Submit Group Panel - Contains the UI controls to submit /// an expense /// </summary> /// <summary> /// Logo Link - Displays the company logo and links back to /// the main page of the application /// </summary> /// <summary> /// Title Label - Displays the title of the page /// </summary> /// <summary> /// Description Label - Identifies the description textbox /// </summary> /// <summary> /// Amount Label - Identifies the amount textbox /// </summary> /// <summary> /// Date Label - Identifies the date textbox /// </summary> /// <summary> /// Comment Label - Identifies the comment textbox /// </summary> /// <summary> /// Submit Button - The user clicks this button to submit the expense /// </summary> /// <summary> /// Return Link - Link back to the main page of the application /// </summary> /// <summary> /// Description Validator - Requires that a description is entered /// A description cannot be longer than 50 characters /// </summary> /// <summary> /// Date Validator - Checks that the user entered a valid date between /// the range of 01/01/1900 and 12/31/2999 /// </summary> /// <summary> /// Amount Validator - Checks that the user entered an amount /// </summary> /// <summary> /// Date Validator - Checks that the user entered a date /// </summary> /// <summary> /// Amount Validator - Checks that the user entered a valid amount /// The amount must be between 1 and 99999999999 /// </summary> #endregion /// <summary> /// Submit Button Click - When the user clicks the submit button /// this saves the expense report in the application data store /// </summary> protected void SubmitBtn_Click(object sender, System.EventArgs e) { // // Check if the user has access to the submit // operation and then save the expense report // // // // Get the client context from the session variables // IAzClientContext3 AzClient = ExpenseCommon.GetAzClientContext(); // // Set BizRule Parameters // IAzBizRuleParameters BizRuleParams = AzClient.BizRuleParameters; BizRuleParams.AddParameter("Amount", (object)Amount.Text); BizRuleParams.AddParameter("Date", (object)Date.Text); BizRuleParams.AddParameter("SubmitterName", ExpenseCommon.GetClientSamName()); BizRuleParams.AddParameter("UserName", ExpenseCommon.GetClientSamName()); // // Run the access check on the submit operation // Passing the audit text, scope, operations and business rule parameters // uint result = AzClient.AccessCheck2("Submit Expense Report", "", ExpenseCommon.AzopSubmit); // // 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 != "") { MSG.Text = "<font color=\"FF0000\">Submission Denied." + errorMessage + "</font>"; } else { MSG.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(); MSG.Text = "<font color=\"FF0000\">There was an error performing the AccessCheck: " + ex.Message + "</font>"; } } if (bAuthorized) { // // AccessCheck passed so submit the expense report // // // Store the expense report in a name-value collection // StringDictionary ExpenseData = new StringDictionary(); // // Save the user SAM name (\\domain\username) // string name = ExpenseCommon.GetClientSamName(); ExpenseData.Add("SamName", name); // // Save the user Friendly Name // name = name.Substring((name.IndexOf(@"\") + 1)); ExpenseData.Add("User", name); // // Save the transaction date // ExpenseData.Add("Date", Date.Text); // // Save the expense description // ExpenseData.Add("Description", Description.Text); // // Save the expense amount // ExpenseData.Add("Amount", Amount.Text); // // Attach any comments to the expense report // ExpenseData.Add("Comment", Comment.Text); // // Save the transaction // ExpenseCommon.SaveTransaction(ExpenseCommon.AssignNextTransaction(), ExpenseData); // // Show link to submit a new expense or // to return to the main page // MSG.Text = "Submission Sucessful.<p><a href='Submit.aspx'>Submit new expense</a> | <a href='../index.aspx'>Return to Main Menu</a></p>"; // // Clear form for new entry // Description.Text = ""; Amount.Text = ""; Date.Text = ""; Comment.Text = ""; SubmitGroup.Visible = false; } }
/// <summary> /// Logo Image - Displays the logo of the company /// </summary> /// <summary> /// Message Label - Displays messages to the user /// </summary> /// <summary> /// Approve Link - Link to a page which lists all expense /// reports which need to be approved /// </summary> /// <summary> /// Submit Link - Link to a page which allows a user /// to create a new expense report to submit /// </summary> /// <summary> /// Administration Link - Link to a page which allows an /// administrator to change application settings /// </summary> /// <summary> /// Approve Image - Display an icon that links to a page /// which lists all expense reports which need to be approved /// </summary> /// <summary> /// Administration Image - Displays an icon that links /// to a page which allows an administrator to change /// application settings /// </summary> /// <summary> /// Submit Image - Displays an icon that links /// to a page which allows a user to create a new expense /// report to submit /// </summary> /// <summary> /// Title Label - Displays the application title /// </summary> #endregion /// <summary> /// Page Load - This is executed when the page is first requested /// by the user and additionally when the user clicks a button on /// the form /// </summary> protected void Page_Load(object sender, System.EventArgs e) { // // Check for this is the first time the page is being loaded // only fill in the form if this is the first time otherwise // any user changes will be lost // if (!Page.IsPostBack) { ExpenseCommon.Initialize(); // // Get the client context // IAzClientContext3 AzClient = ExpenseCommon.GetAzClientContext(); IAzBizRuleParameters BizRuleParams = AzClient.BizRuleParameters; BizRuleParams.AddParameter("Amount", 0); BizRuleParams.AddParameter("Date", "NA"); BizRuleParams.AddParameter("SubmitterName", "NA"); BizRuleParams.AddParameter("UserName", ExpenseCommon.GetClientSamName()); // // Use the client SAM name (\\domain\username) // to display the username // string AccountName = ExpenseCommon.GetClientSamName(); AccountName = AccountName.Substring((AccountName.IndexOf(@"\") + 1)); MSG.Text = string.Concat("Welcome ", AccountName, ":"); // // Get the user's task assigments from the // client context // IAzTasks Tasks = AzClient.GetTasks(null); // // Check for the user has no roles // if (Tasks.Count == 0) { MSG.Text = string.Concat(MSG.Text, "<P>Sorry ", AccountName, " you do not have permission to use this application. <Br> Please contact your manager <Br></P>"); } else { // // Display links to the various actions the user // can perform depending on the user's role memberships and the tasks // assigned to those roles. // string Task; foreach (IAzTask AzTask in Tasks) { Task = (string)AzTask.Name; switch (Task) { case "View Pending Expenses": // // User is an approver // Show link to the approval page // ApproveLink.Visible = true; break; case "Administer Settings": // // User is an administrator // Show link to the administration page // AdminLink.Visible = true; break; case "Submit Expense": // // User is an submitter // Show link to the expense submission page // SubmitLink.Visible = true; break; } } } } }
/// <summary> /// Message Label - Displays any messages for the user /// </summary> /// <summary> /// Transaction List - Displays the transactions /// filtered by the ModeSelect drop down listbox /// </summary> /// <summary> /// Mode Select Drop Down ListBox - Filters which /// expense transactions are displayed in the transaction list /// </summary> /// <summary> /// Mode Label - Displays the filter on the transaction list /// </summary> /// <summary> /// Logo Link - Displays the company logo and links /// back to the main page of the application /// </summary> /// <summary> /// Title Label - Displays the page title /// </summary> /// <summary> /// Return Link - Displays a link back to the main /// page of the application /// </summary> #endregion /// <summary> /// Page Load - This is executed when the page is first requested /// by the user and additionally when the user clicks a button on /// the form /// </summary> protected void Page_Load(object sender, System.EventArgs e) { // // To prevent users from by-passing the portal page (index.aspx) // and going directly to this page, use URL Authorization // See <url> for details. // // // Check for this is the first time the page is being loaded // only fill in the form if this is the first time otherwise // any user changes will be lost // if (!Page.IsPostBack) { // // Check if the user has permission to list expenses // // // // 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 submit operation // Passing the audit text, scope, operations and business rule parameters // uint result = AzClient.AccessCheck2("List Expense Reports", "", ExpenseCommon.AzopList); // // 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 != "") { MSG.Text = "<font color=\"FF0000\">Access Denied." + errorMessage + "</font>"; } else { MSG.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(); MSG.Text = "<font color=\"FF0000\">There was an error performing the AccessCheck: " + ex.Message + "</font>"; } } if (bAuthorized) { // // List the expense reports // ListTransactions(); } else { // // Access Check failed so display an error message to the user // MSG.Text = "Error Access Denied: " + AzClient.GetBusinessRuleString(); return; } } }