Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- /* Social Planner V2.0
- * Aaron Moss
- * 28/08/14
- */
- namespace SocialPlanner
- {
- public partial class frmSocialPlanner : Form
- {
- int user = 0; // Stores User Number
- Button[] btnArray = new Button[6]; // Array of Option Buttons
- List<int> inputtedValues = new List<int> { }; // List of Inputted Values (Mutable Array)
- public frmSocialPlanner()
- {
- InitializeComponent();
- }
- private void txtEventName_TextChanged(object sender, EventArgs e)
- {
- if (txtEventName.Text.Length > 4) // Once user inputs characters...
- {
- btnDone.Enabled = true; // Done becomes enabled, guides user
- }
- }
- private void btnDone_Click(object sender, EventArgs e) // Once done clicked...
- {
- txtEventName.ReadOnly = true; // Event Name Becomes Final
- txtEventName.TextAlign = HorizontalAlignment.Center; // Centered
- btnDone.Visible = false;
- lblTutorialText.Text = "Please Rate Your Interest in the Event Below from 0-5";
- foreach (Button b in btnArray)
- {
- b.Enabled = true; // Enables the option buttons in fast enumeration
- }
- }
- private void frmSocialPlanner_Load(object sender, EventArgs e)
- {
- /* This code runs on loadtime, takes care of boring processes, adding buttons
- * to the array, giving them properties */
- btnArray[0] = btnRate0;
- btnArray[1] = btnRate1;
- btnArray[2] = btnRate2;
- btnArray[3] = btnRate3;
- btnArray[4] = btnRate4;
- btnArray[5] = btnRate5;
- foreach ( Button b in btnArray)
- {
- b.Click += new EventHandler(anyButton_Click);
- /* This gives the buttons special events on hover and dehover which can
- * be used for visual feedback ; see below */
- b.MouseHover += new EventHandler(anyButton_Hover);
- b.MouseLeave += new EventHandler(anyButton_Unhover);
- }
- }
- void anyButton_Click(object sender, EventArgs e)
- {
- user += 1; // Once option button is clicked, new user
- if (user > 1) // Once the program has 2 values...
- {
- btnFinish.Enabled = true; // The program can average
- }
- lblPerson.Text = "Friend " + user; // Friend Number x using program
- /* More boring code that was simply faster to do manually than programatically.
- * In this case it checks which button is being pressed, and changes an input
- * variable to that balue */
- int inputtedValue = 9; // Error Code
- if ( sender == btnArray[0] )
- {
- inputtedValue = 0;
- MessageBox.Show("You Selected Option 0. You don't want to go at all.");
- }
- else if ( sender == btnArray[1] )
- {
- inputtedValue = 1;
- MessageBox.Show("You Selected Option 1.");
- }
- else if (sender == btnArray[2])
- {
- inputtedValue = 2;
- MessageBox.Show("You Selected Option 2.");
- }
- else if (sender == btnArray[3])
- {
- inputtedValue = 3;
- MessageBox.Show("You Selected Option 3.");
- }
- else if (sender == btnArray[4])
- {
- inputtedValue = 4;
- MessageBox.Show("You Selected Option 4.");
- }
- else
- {
- inputtedValue = 5;
- MessageBox.Show("You Selected Option 5. You absolutely want to go!");
- }
- if ( inputtedValue == 9) // If Error Code Comes Through
- {
- MessageBox.Show("Critical Error."); // Display Error Message
- }
- inputtedValues.Add(inputtedValue); // Add the Value of the Button to Array of Values
- }
- void anyButton_Hover(object sender, EventArgs e) // On Hover
- {
- foreach (Button b in btnArray)
- {
- if (b == sender)
- {
- b.BackColor = Color.LightGreen; // Make Button Green
- }
- }
- }
- void anyButton_Unhover(object sender, EventArgs e) // And revert on unhover
- {
- foreach (Button b in btnArray)
- {
- if (b == sender)
- {
- b.BackColor = SystemColors.Control;
- }
- }
- }
- /* Aethetic change gives user some feedback */
- private void btnFinish_Click(object sender, EventArgs e)
- {
- /* Averaging will be done here */
- foreach (Button b in btnArray)
- {
- b.Enabled = false; // Disables option buttons
- }
- btnFinish.Enabled = false;
- /* Averaging */
- double average = inputtedValues.Average();
- int roundedAverage = Convert.ToInt32(average);
- bool lowerBoundPresence = false;
- MessageBox.Show("Average Answer was " + roundedAverage);
- /* Checks for the cases that will evaluate to true or false */
- foreach (int i in inputtedValues) // check values for 0 or 1
- {
- if (i == 1 || i == 0)
- {
- lowerBoundPresence = true;
- }
- }
- if ( roundedAverage >= 3 && !lowerBoundPresence)
- {
- MessageBox.Show("You will be going to the " + txtEventName.Text + " this weekend as the average is higher than 3!");
- }
- else if ( lowerBoundPresence )
- {
- MessageBox.Show("You will not be going to the " + txtEventName.Text + " this weekend as there are some people do not wish to go at all!");
- }
- else
- {
- MessageBox.Show("You will not be going to the " + txtEventName.Text + " this weekend because the average is lower than 3!");
- }
- btnReset.Enabled = true;
- }
- private void btnReset_Click(object sender, EventArgs e)
- {
- Application.Restart();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement