/EventHandling Secret
Last active
August 29, 2015 14:10
StudentQuestions.exe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
namespace Questioner | |
{ | |
public static class EventHandling | |
{ | |
// | |
// Static Methods | |
// | |
public static void btnClicked_Click (object sender, EventArgs e) | |
{ | |
MessageBox.Show ("button clicked"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data.SqlClient; | |
using System.Drawing; | |
using System.Security.Principal; | |
using System.Windows.Forms; | |
namespace Questioner | |
{ | |
public class frmQuestioner : Form | |
{ | |
// | |
// Constructors | |
// | |
public frmQuestioner () | |
{ | |
this._currentUser = WindowsIdentity.GetCurrent ().get_Name ().ToString (); | |
this._computerName = Environment.MachineName; | |
this._response = string.Empty; | |
this._DBInfo = "Server=192.168.10.38;Database=StudentQuestionnaire;User ID=ClassroomManager;Password=Dinosaur2010;Trusted_Connection=False;"; | |
this.Exiting = false; | |
this.ShowingQuestion = false; | |
this.rnd = new Random (); | |
this.Questions = new Dictionary<int, Question> (); | |
this.components = null; | |
base..ctor (); | |
this.InitializeComponent (); | |
} | |
// | |
// Methods | |
// | |
private void CheckForQuestions () | |
{ | |
SqlDataReader sqlDataReader = MSSQL.FunctionSqlDataReader (this._DBInfo, "SELECT * FROM StudentQuestions"); | |
if (sqlDataReader != null && sqlDataReader.HasRows) { | |
while (sqlDataReader.Read ()) { | |
int iD = Convert.ToInt32 (sqlDataReader ["QuestionID"]); | |
string content = sqlDataReader ["Question"].ToString (); | |
string responses = sqlDataReader ["Responses"].ToString (); | |
DateTime dateTime = Convert.ToDateTime (sqlDataReader ["StartDate"]); | |
DateTime dateTime2 = Convert.ToDateTime (sqlDataReader ["EndDate"]); | |
if (DateTime.Today >= dateTime && DateTime.Today <= dateTime2) { | |
Question question = new Question (iD, content, responses, dateTime, dateTime2); | |
if (!this.Questions.ContainsKey (question.ID)) { | |
this.Questions.Add (question.ID, question); | |
} | |
} | |
} | |
} | |
foreach (Question question in this.Questions.Values) { | |
Question question; | |
bool flag = this.QuestionCheck (question.ID); | |
if (flag) { | |
question.Answered = true; | |
} | |
} | |
} | |
private void CreateConfig () | |
{ | |
} | |
protected override void Dispose (bool disposing) | |
{ | |
if (disposing && this.components != null) { | |
this.components.Dispose (); | |
} | |
base.Dispose (disposing); | |
} | |
private void frmQuestioner_Load (object sender, EventArgs e) | |
{ | |
base.Hide (); | |
base.ShowInTaskbar = false; | |
this.tmrQuestionPopup.Start (); | |
} | |
private void InitializeComponent () | |
{ | |
this.components = new Container (); | |
this.tmrQuestionPopup = new Timer (this.components); | |
base.SuspendLayout (); | |
this.tmrQuestionPopup.Enabled = true; | |
this.tmrQuestionPopup.Interval = 5000; | |
this.tmrQuestionPopup.Tick += new EventHandler (this.tmrQuestionPopup_Tick); | |
base.AutoScaleDimensions = new SizeF (6, 13); | |
base.AutoScaleMode = AutoScaleMode.Font; | |
base.ClientSize = new Size (909, 302); | |
base.FormBorderStyle = FormBorderStyle.FixedToolWindow; | |
base.Name = "frmQuestioner"; | |
base.StartPosition = FormStartPosition.CenterScreen; | |
this.Text = "Questioner"; | |
base.Load += new EventHandler (this.frmQuestioner_Load); | |
base.ResumeLayout (false); | |
} | |
private void LoadConfig () | |
{ | |
} | |
private void popQuestion_FormClosed (object sender, FormClosedEventArgs e) | |
{ | |
this.ShowingQuestion = false; | |
} | |
private bool QuestionCheck (int questionID) | |
{ | |
SqlDataReader sqlDataReader = MSSQL.FunctionSqlDataReader (this._DBInfo, string.Concat (new object[] { | |
"SELECT * FROM StudentAnswers WHERE UserID = '", | |
this._currentUser, | |
"' AND QuestionID = '", | |
questionID, | |
"'" | |
})); | |
return sqlDataReader.HasRows; | |
} | |
private void tmrQuestionPopup_Tick (object sender, EventArgs e) | |
{ | |
this.CheckForQuestions (); | |
if (!this.ShowingQuestion) { | |
if (this.Questions.Count >= 1) { | |
int num = this.rnd.Next (1, this.Questions.Count + 1); | |
foreach (Question current in this.Questions.Values) { | |
if (!current.Answered) { | |
PopUpQuestion popUpQuestion = new PopUpQuestion (current); | |
this.ShowingQuestion = true; | |
DialogResult dialogResult = popUpQuestion.ShowDialog (); | |
if (dialogResult == DialogResult.OK) { | |
this.ShowingQuestion = false; | |
current.Answered = true; | |
} | |
else { | |
this.ShowingQuestion = false; | |
current.Answered = false; | |
} | |
popUpQuestion.FormClosed += new FormClosedEventHandler (this.popQuestion_FormClosed); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data.SqlClient; | |
using System.Windows.Forms; | |
namespace Questioner | |
{ | |
internal class MSSQL | |
{ | |
// | |
// Static Fields | |
// | |
private static string _DBInfo = "Server=192.168.10.38;Database=StudentQuestionnaire;User ID=ClassroomManager;Password=Dinosaur2010;Trusted_Connection=False;"; | |
// | |
// Static Methods | |
// | |
public static SqlDataReader FunctionSqlDataReader (string Connection, string _SQL) | |
{ | |
SqlDataReader sqlDataReader = null; | |
SqlConnection sqlConnection = new SqlConnection (); | |
sqlConnection.ConnectionString = Connection; | |
SqlDataReader result; | |
if (Util.Netup ()) { | |
try { | |
sqlConnection.Open (); | |
} | |
catch (Exception ex) { | |
string message = ex.Message; | |
result = null; | |
return result; | |
} | |
try { | |
SqlCommand sqlCommand = new SqlCommand (_SQL, sqlConnection); | |
sqlDataReader = sqlCommand.ExecuteReader (); | |
} | |
catch (Exception ex) { | |
string message = ex.Message; | |
result = null; | |
return result; | |
} | |
} | |
result = sqlDataReader; | |
return result; | |
} | |
public static int FunctionSqlDataWriter (string Connection, string _SQL) | |
{ | |
int num = 0; | |
SqlConnection sqlConnection = new SqlConnection (); | |
sqlConnection.ConnectionString = Connection; | |
int result; | |
if (Util.Netup ()) { | |
try { | |
sqlConnection.Open (); | |
} | |
catch (Exception ex) { | |
string message = ex.Message; | |
result = 0; | |
return result; | |
} | |
try { | |
SqlCommand sqlCommand = new SqlCommand (_SQL, sqlConnection); | |
num = sqlCommand.ExecuteNonQuery (); | |
} | |
catch (Exception ex) { | |
string message = ex.Message; | |
result = 0; | |
return result; | |
} | |
} | |
result = num; | |
return result; | |
} | |
public static List<byte[]> GetQuestionPictures (string Connection, int QuestionID) | |
{ | |
List<byte[]> result = new List<byte[]> (); | |
SqlDataReader sqlDataReader = MSSQL.FunctionSqlDataReader (Connection, "SELECT * FROM StudentQuestions"); | |
if (sqlDataReader != null && sqlDataReader.HasRows) { | |
while (sqlDataReader.Read ()) { | |
} | |
} | |
return result; | |
} | |
public static int SubmitAnswer (string Answer, int QuestionID, string Username, string Computername) | |
{ | |
int result; | |
if (MSSQL.FunctionSqlDataWriter (MSSQL._DBInfo, string.Concat (new object[] { | |
"INSERT INTO StudentAnswers (UserID, QuestionID, Response, DateResponded, ComputerID) VALUES ('", | |
Username, | |
"','", | |
QuestionID, | |
"','", | |
Answer, | |
"','", | |
DateTime.Now, | |
"','", | |
Computername, | |
"')" | |
})) > 0) { | |
MessageBox.Show ("Thank you for your time and answer."); | |
result = 1; | |
} | |
else { | |
MessageBox.Show ("There was an error accessing the server your answer was not saved."); | |
result = 0; | |
} | |
return result; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Drawing; | |
using System.Security.Principal; | |
using System.Windows.Forms; | |
namespace Questioner | |
{ | |
public class PopUpQuestion : Form | |
{ | |
// | |
// Constructors | |
// | |
public PopUpQuestion (Question question) | |
{ | |
this._answer = new List<string> (); | |
this._currentUser = WindowsIdentity.GetCurrent ().get_Name ().ToString (); | |
this._computerName = Environment.MachineName; | |
this.components = null; | |
base..ctor (); | |
this.InitializeComponent (); | |
this.question = question; | |
} | |
// | |
// Methods | |
// | |
private void btnClicked_Click (object sender, MouseEventArgs e) | |
{ | |
this._answer.Clear (); | |
Button button = (Button)sender; | |
foreach (Button button2 in this.flpResponses.Controls) { | |
button2.BackColor = Color.FromKnownColor (KnownColor.Control); | |
} | |
button.BackColor = Color.Green; | |
this._answer.Add (button.Text); | |
} | |
private void btnNoAnswer_Click (object sender, EventArgs e) | |
{ | |
DialogResult dialogResult = MessageBox.Show ("Are you sure you do not want to answer this question?", "Are you sure.", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); | |
if (dialogResult == DialogResult.Yes) { | |
base.DialogResult = DialogResult.OK; | |
} | |
} | |
private void btnSubmit_Click (object sender, EventArgs e) | |
{ | |
foreach (Control control in this.flpResponses.Controls) { | |
if (control.GetType () == typeof(TextBox)) { | |
foreach (TextBox textBox in this.flpResponses.Controls) { | |
this._answer.Add (textBox.Text); | |
} | |
break; | |
} | |
} | |
if (this._answer.Count > 0) { | |
base.DialogResult = DialogResult.OK; | |
string answer = string.Join ("@", this._answer.ToArray ()); | |
MSSQL.SubmitAnswer (answer, this.question.ID, this._currentUser, this._computerName); | |
} | |
else { | |
MessageBox.Show ("Please select an answer or click No Answer."); | |
} | |
} | |
private void chbxClicked_Click (object sender, EventArgs e) | |
{ | |
CheckBox checkBox = (CheckBox)sender; | |
if (checkBox.Checked) { | |
if (!this._answer.Contains (checkBox.Text)) { | |
this._answer.Add (checkBox.Text); | |
} | |
} | |
else { | |
if (this._answer.Contains (checkBox.Text)) { | |
this._answer.Remove (checkBox.Text); | |
} | |
} | |
} | |
private void ctrl_MouseClick (object sender, MouseEventArgs e) | |
{ | |
this._answer.Clear (); | |
PictureBox pictureBox = (PictureBox)sender; | |
foreach (PictureBox pictureBox2 in this.flpResponses.Controls) { | |
pictureBox2.BackColor = Color.Red; | |
} | |
pictureBox.BackColor = Color.Green; | |
this._answer.Add (pictureBox.Name); | |
} | |
protected override void Dispose (bool disposing) | |
{ | |
if (disposing && this.components != null) { | |
this.components.Dispose (); | |
} | |
base.Dispose (disposing); | |
} | |
private void InitializeComponent () | |
{ | |
this.bgwProcessor = new BackgroundWorker (); | |
this.btnNoAnswer = new Button (); | |
this.flpResponses = new FlowLayoutPanel (); | |
this.rtxtbxQuestion = new RichTextBox (); | |
this.btnSubmit = new Button (); | |
base.SuspendLayout (); | |
this.btnNoAnswer.Location = new Point (769, 160); | |
this.btnNoAnswer.Name = "btnNoAnswer"; | |
this.btnNoAnswer.Size = new Size (128, 49); | |
this.btnNoAnswer.TabIndex = 8; | |
this.btnNoAnswer.Text = "No Answer"; | |
this.btnNoAnswer.UseVisualStyleBackColor = true; | |
this.btnNoAnswer.Click += new EventHandler (this.btnNoAnswer_Click); | |
this.flpResponses.Anchor = (AnchorStyles.Left | AnchorStyles.Right); | |
this.flpResponses.AutoScroll = true; | |
this.flpResponses.Location = new Point (11, 156); | |
this.flpResponses.Name = "flpResponses"; | |
this.flpResponses.Size = new Size (752, 146); | |
this.flpResponses.TabIndex = 7; | |
this.rtxtbxQuestion.BackColor = SystemColors.Control; | |
this.rtxtbxQuestion.BorderStyle = BorderStyle.None; | |
this.rtxtbxQuestion.Font = new Font ("Microsoft Sans Serif", 30, FontStyle.Regular, GraphicsUnit.Point, 0); | |
this.rtxtbxQuestion.Location = new Point (11, 11); | |
this.rtxtbxQuestion.Name = "rtxtbxQuestion"; | |
this.rtxtbxQuestion.ReadOnly = true; | |
this.rtxtbxQuestion.Size = new Size (886, 143); | |
this.rtxtbxQuestion.TabIndex = 6; | |
this.rtxtbxQuestion.Text = "How would you rate your recent enrolment and induction to <snip> college? Please answer in single words."; | |
this.btnSubmit.Location = new Point (769, 216); | |
this.btnSubmit.Name = "btnSubmit"; | |
this.btnSubmit.Size = new Size (128, 75); | |
this.btnSubmit.TabIndex = 9; | |
this.btnSubmit.Text = "Submit Answer"; | |
this.btnSubmit.UseVisualStyleBackColor = true; | |
this.btnSubmit.Click += new EventHandler (this.btnSubmit_Click); | |
base.AutoScaleDimensions = new SizeF (6, 13); | |
base.AutoScaleMode = AutoScaleMode.Font; | |
base.ClientSize = new Size (909, 302); | |
base.Controls.Add (this.btnSubmit); | |
base.Controls.Add (this.btnNoAnswer); | |
base.Controls.Add (this.flpResponses); | |
base.Controls.Add (this.rtxtbxQuestion); | |
base.FormBorderStyle = FormBorderStyle.FixedToolWindow; | |
base.Name = "PopUpQuestion"; | |
base.StartPosition = FormStartPosition.CenterScreen; | |
this.Text = "PopUpQuestion"; | |
base.TopMost = true; | |
base.FormClosed += new FormClosedEventHandler (this.PopUpQuestion_FormClosed); | |
base.Load += new EventHandler (this.PopUpQuestion_Load); | |
base.ResumeLayout (false); | |
} | |
private void PopUpQuestion_FormClosed (object sender, FormClosedEventArgs e) | |
{ | |
} | |
private void PopUpQuestion_Load (object sender, EventArgs e) | |
{ | |
this.Text = "Question."; | |
this.rtxtbxQuestion.Text = this.question.Content; | |
foreach (Control current in this.question.Responses) { | |
if (current.GetType () == typeof(Button)) { | |
current.MouseClick += new MouseEventHandler (this.btnClicked_Click); | |
} | |
else { | |
if (current.GetType () == typeof(RadioButton)) { | |
current.MouseClick += new MouseEventHandler (this.radbtnClicked_Click); | |
} | |
else { | |
if (current.GetType () == typeof(CheckBox)) { | |
current.MouseClick += new MouseEventHandler (this.chbxClicked_Click); | |
} | |
else { | |
if (!(current.GetType () == typeof(TextBox))) { | |
if (current.GetType () == typeof(PictureBox)) { | |
current.MouseClick += new MouseEventHandler (this.ctrl_MouseClick); | |
} | |
} | |
} | |
} | |
} | |
this.flpResponses.Controls.Add (current); | |
} | |
} | |
private void radbtnClicked_Click (object sender, EventArgs e) | |
{ | |
RadioButton radioButton = (RadioButton)sender; | |
this._answer.Add (radioButton.Text); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
namespace Questioner | |
{ | |
internal static class Program | |
{ | |
// | |
// Static Methods | |
// | |
[STAThread] | |
private static void Main () | |
{ | |
Application.EnableVisualStyles (); | |
Application.SetCompatibleTextRenderingDefault (false); | |
Application.Run (new frmQuestioner ()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Linq; | |
using System.Windows.Forms; | |
namespace Questioner | |
{ | |
public class Question | |
{ | |
// | |
// Properties | |
// | |
public bool Answered { | |
get; | |
set; | |
} | |
public string Content { | |
get; | |
set; | |
} | |
public DateTime EndDate { | |
get; | |
set; | |
} | |
public int ID { | |
get; | |
set; | |
} | |
public List<Control> Responses { | |
get; | |
set; | |
} | |
public DateTime StartDate { | |
get; | |
set; | |
} | |
// | |
// Constructors | |
// | |
public Question (int ID, string Content, string Responses, DateTime StartDate, DateTime EndDate) | |
{ | |
this.ID = ID; | |
this.Content = Content; | |
this.Answered = false; | |
this.Responses = this.ParseResponses (Responses); | |
this.StartDate = StartDate; | |
this.EndDate = EndDate; | |
} | |
// | |
// Methods | |
// | |
private List<Control> ParseResponses (string responses) | |
{ | |
List<Control> list = new List<Control> (); | |
if (!string.IsNullOrEmpty (responses)) { | |
if (responses.Contains ('@')) { | |
if (responses.Contains (':')) { | |
try { | |
string[] array = responses.Split (new char[] { | |
'@' | |
}); | |
string[] array2 = array; | |
for (int i = 0; i < array2.Length; i++) { | |
string text = array2 [i]; | |
string[] array3 = text.Split (new char[] { | |
':' | |
}); | |
string a = array3 [0].ToLower (); | |
if (a == "radiobutton") { | |
RadioButton radioButton = new RadioButton (); | |
radioButton.AutoSize = true; | |
radioButton.Font = new Font (radioButton.Font.Name, 15); | |
radioButton.Text = array3 [1]; | |
list.Add (radioButton); | |
} | |
else { | |
if (a == "button") { | |
Button button = new Button (); | |
button.AutoSize = true; | |
button.Width = 200; | |
button.Height = 100; | |
button.Text = array3 [1]; | |
button.Font = new Font (button.Font.Name, 20); | |
list.Add (button); | |
} | |
else { | |
if (a == "checkbox") { | |
CheckBox checkBox = new CheckBox (); | |
checkBox.AutoSize = true; | |
checkBox.Font = new Font (checkBox.Font.Name, 15); | |
checkBox.Text = array3 [1]; | |
list.Add (checkBox); | |
} | |
else { | |
if (a == "picture") { | |
list.Add (new PictureBox { | |
SizeMode = PictureBoxSizeMode.StretchImage, | |
BackColor = Color.Red, | |
Width = 90, | |
Height = 140, | |
Name = array3 [1] | |
}); | |
} | |
else { | |
if (a == "textbox") { | |
TextBox textBox = new TextBox (); | |
textBox.Width = 200; | |
textBox.Height = 50; | |
textBox.Font = new Font (textBox.Font.Name, 30); | |
list.Add (textBox); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
catch (Exception ex) { | |
string message = ex.Message; | |
} | |
} | |
} | |
} | |
return list; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.NetworkInformation; | |
namespace Questioner | |
{ | |
internal class Util | |
{ | |
// | |
// Static Methods | |
// | |
public static bool Netup () | |
{ | |
return NetworkInterface.GetIsNetworkAvailable (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment