public string[] getStudentInfoById(string id) { string[] toReturn = new string[4]; try { SqlConnection mySqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "SELECT name, school, grade FROM student WHERE student_id =" + id + ";"; SqlCommand Command = new SqlCommand(sqlQuery, mySqlConnection); SqlDataReader mySqlDataReader; mySqlConnection.Open(); mySqlDataReader = Command.ExecuteReader(); while (mySqlDataReader.Read()) { toReturn[0] = mySqlDataReader.GetString(0); //name toReturn[1] = mySqlDataReader.GetString(1); //school toReturn[3] = mySqlDataReader.GetString(2); //grade } mySqlDataReader.Dispose(); mySqlConnection.Close(); } catch (Exception ex) { this.LabelOutput.Text = "Get Student Info Error: " + ex.Message; } toReturn[2] = "1"; //one person return(toReturn); }
protected void ButtonSubmit_Click(object sender, EventArgs e) { int id = 0; if (!int.TryParse(this.TextBoxID.Text, out id)) { this.LabelOutput.Text = "invaild ID"; return; } if (id < 5000) { this.LabelOutput.Text = "Participant ID has to be a team ID."; return; } int marbles_num = 0; if (this.DropDownListSurvival.SelectedValue == "Yes") { int.TryParse(this.TextBoxMarbleNum.Text, out marbles_num); } string[] info = this.getTeamInfoById(this.TextBoxID.Text); //insert record try { SqlConnection mySqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "INSERT INTO floatable_moatable_report (participant_id, student_names, school, " + "grade_group, marbles_num, people_num) VALUES " + "('" + this.TextBoxID.Text + "','" + info[0] + "','" + info[1] + "','" + info[3] + "','" + marbles_num + "','" + info[2] + "');"; SqlCommand Command = new SqlCommand(sqlQuery, mySqlConnection); SqlDataReader mySqlDataReader; mySqlConnection.Open(); mySqlDataReader = Command.ExecuteReader(); while (mySqlDataReader.Read()) { } mySqlDataReader.Dispose(); mySqlConnection.Close(); this.LabelOutput.Text = "ID: " + this.TextBoxID.Text + ", Your record was inserted."; } catch (Exception ex) { this.LabelDebug.Text = "Inserting Record Error: " + ex.Message; } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string[] info; int id = 0; if (!int.TryParse(this.TextBoxID.Text, out id)) { this.LabelOutput.Text = "invaild ID"; return; } if (id >= 5000) { this.LabelOutput.Text = "Participant ID has to be a student ID."; return; } info = this.getStudentInfoById(this.TextBoxID.Text); try { SqlConnection SqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "INSERT INTO paper_airplanes_report (participant_id, student_names, school," + "grade_group, Plane_num, dist1_ft, dist1_in, offset1_ft, offset1_in, score1, " + "dist2_ft, dist2_in, offset2_ft, offset2_in, score2, max_dist) VALUES " + "('" + this.TextBoxID.Text + "','" + info[0] + "','" + info[1] + "','" + info[3] + "','" + this.TextBoxPlaneNum.Text + "','" + this.TextBoxDist_ft.Text + "','" + this.TextBoxDist_in.Text + "','" + this.TextBoxOffset_ft.Text + "','" + this.TextBoxOffset_in.Text + "','" + this.TextBoxScore.Text + "','" + this.TextBoxDist2_ft.Text + "','" + this.TextBoxDist2_in.Text + "','" + this.TextBoxOffset2_ft.Text + "','" + this.TextBoxOffset2_in.Text + "','" + this.TextBoxScore2.Text + "','" + this.TextBoxMaxDist.Text + "');"; SqlCommand Command = new SqlCommand(sqlQuery, SqlConnection); SqlDataReader SqlDataReader; SqlConnection.Open(); SqlDataReader = Command.ExecuteReader(); while (SqlDataReader.Read()) { } SqlDataReader.Dispose(); SqlConnection.Close(); this.LabelOutput.Text = "ID: " + this.TextBoxID.Text + ", Your record was inserted. Your max distance is " + this.TextBoxMaxDist.Text; } catch (Exception ex) { this.LabelOutput.Text = "Inserting Record Error: " + ex.Message; } }
public string[] getTeamInfoById(string id) { string[] toReturn = new string[4]; string studentRep = ""; try { SqlConnection mySqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "select member_names, team_size, representative_id " + "from team where team_id =" + id + ";"; SqlCommand Command = new SqlCommand(sqlQuery, mySqlConnection); SqlDataReader mySqlDataReader; mySqlConnection.Open(); mySqlDataReader = Command.ExecuteReader(); while (mySqlDataReader.Read()) { toReturn[0] = mySqlDataReader.GetString(0); // member names toReturn[2] = mySqlDataReader.GetInt32(1).ToString(); // team size studentRep = mySqlDataReader.GetInt32(2).ToString(); // rep id } mySqlDataReader.Close(); sqlQuery = "select school, grade from student where student_id =" + studentRep + ";"; Command = new SqlCommand(sqlQuery, mySqlConnection); mySqlDataReader = Command.ExecuteReader(); while (mySqlDataReader.Read()) { toReturn[1] = mySqlDataReader.GetString(0); // school toReturn[3] = mySqlDataReader.GetString(1); // grade } mySqlDataReader.Dispose(); mySqlConnection.Close(); } catch (Exception ex) { this.LabelOutput.Text = "Get Team Info Error: " + ex.Message; } return(toReturn); }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string[] info; double idValue; string totalPoint = ""; double dist = 0; double const_time = 0; double allowed_time = 30; if (!Double.TryParse(this.TextBoxID.Text, out idValue)) { this.LabelOutput.Text = "Invaild Id number!"; return; } if (idValue >= 5000) { //get info from team table by id info = this.getTeamInfoById(this.TextBoxID.Text); } else { //get info from student table by id info = this.getStudentInfoById(this.TextBoxID.Text); } if (!Double.TryParse(this.TextBoxDist.Text, out dist)) { this.LabelOutput.Text = "Invaild Distance!"; return; } if (!Double.TryParse(this.TextBoxConstrutTime.Text, out const_time)) { this.LabelOutput.Text = "Invaild construction time!"; return; } //Distance from target+[Construction time (if over limit) - construction time allowed]*1in/min=Total distance //check first char in grade group (e.g '7 to 12' -> '7') if (int.Parse(info[3][0].ToString()) > 6) { allowed_time = 15; } if (const_time > allowed_time) { totalPoint = (dist + const_time - allowed_time).ToString(); } else { totalPoint = dist.ToString(); } try { SqlConnection mySqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "INSERT INTO egg_toss_report (participant_id, student_names, school," + "grade_group, dist_from_target, construt_time, total_points) VALUES " + "('" + this.TextBoxID.Text + "','" + info[0] + "','" + info[1] + "','" + info[3] + "','" + this.TextBoxDist.Text + "','" + this.TextBoxConstrutTime.Text + "','" + totalPoint + "');"; SqlCommand Command = new SqlCommand(sqlQuery, mySqlConnection); SqlDataReader mySqlDataReader; mySqlConnection.Open(); mySqlDataReader = Command.ExecuteReader(); while (mySqlDataReader.Read()) { } mySqlDataReader.Dispose(); mySqlConnection.Close(); this.LabelOutput.Text = "ID: " + this.TextBoxID.Text + ", Your record was inserted. Your total point is " + totalPoint; } catch (Exception ex) { this.LabelOutput.Text = "Inserting Record Error: " + ex.Message; } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string[] info; double idValue; if (!Double.TryParse(this.TextBoxID.Text, out idValue)) { this.LabelOutput.Text = "Invaild Id number!"; return; } if (idValue >= 5000) { // team this.LabelOutput.Text = "ID has to be student ID."; return; } else { //get info from student table by id info = this.getStudentInfoById(this.TextBoxID.Text); } double time_1 = 0.0; double time_2 = 0.0; if (!Double.TryParse(this.TextBoxTime1.Text, out time_1)) { this.LabelOutput.Text = "Invaild time!"; return; } if (!Double.TryParse(this.TextBoxTime2.Text, out time_2)) { this.LabelOutput.Text = "Invaild time!"; return; } double score = (time_1 < time_2) ? time_1 : time_2; try { SqlConnection mySqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "INSERT INTO geomatics (participant_id, student_names, school," + "grade_group, time_1, time_2, score) VALUES " + "('" + this.TextBoxID.Text + "','" + info[0] + "','" + info[1] + "','" + info[3] + "','" + this.TextBoxTime1.Text + "','" + this.TextBoxTime2.Text + "','" + score + "');"; SqlCommand Command = new SqlCommand(sqlQuery, mySqlConnection); SqlDataReader mySqlDataReader; mySqlConnection.Open(); mySqlDataReader = Command.ExecuteReader(); while (mySqlDataReader.Read()) { } mySqlDataReader.Dispose(); mySqlConnection.Close(); this.LabelOutput.Text = "ID: " + this.TextBoxID.Text + ", Your record was inserted. Your score is " + score; } catch (Exception ex) { this.LabelOutput.Text = "Inserting Record Error: " + ex.Message; } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string[] info; double idValue; if (!Double.TryParse(this.TextBoxID.Text, out idValue)) { this.LabelOutput.Text = "Invaild Id number!"; return; } if (idValue >= 5000) { //get info from team table by id info = this.getTeamInfoById(this.TextBoxID.Text); } else { //get info from student table by id info = this.getStudentInfoById(this.TextBoxID.Text); } double max_dist = 0.0; String selected_val_2 = "Yes"; if (TextBox1Length.Text != "" && TextBox2Length.Text != "") //two attempts { double second_attempt = 0.0; if (!Double.TryParse(this.TextBox1Length.Text, out max_dist)) // set max to first attempt { this.LabelOutput.Text = "Invaild Length Input in first attempt!"; return; } if (!Double.TryParse(this.TextBox2Length.Text, out second_attempt)) { this.LabelOutput.Text = "Invaild Length Input in second attempt!"; return; } if (DropDownList1Survival.SelectedValue != "Yes") //if first attempt did not survive { max_dist = 0.0; } if (DropDownList2Survival.SelectedValue == "Yes")// if second attempt survived { max_dist = (max_dist > second_attempt) ? max_dist : second_attempt; } else { selected_val_2 = "No"; } } else { if (TextBox1Length.Text != "") // only first attempt { selected_val_2 = ""; if (!Double.TryParse(this.TextBox1Length.Text, out max_dist)) { this.LabelOutput.Text = "Invaild Length Input in first attempt!"; return; } if (DropDownList1Survival.SelectedValue != "Yes") { max_dist = 0.0; } //first attempt did not survive } else // 0 attempt { this.LabelOutput.Text = "Length Input is required"; return; } } try { SqlConnection mySqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "INSERT INTO lego_longo_report (participant_id, student_names, school, " + "grade_group, length1, weight1, survive1, length2," + "weight2, survive2, max_distance) VALUES " + "('" + this.TextBoxID.Text + "','" + info[0] + "','" + info[1] + "','" + info[3] + "','" + this.TextBox1Length.Text + "','" + this.TextBox1Weight.Text + "','" + this.DropDownList1Survival.Text + "','" + this.TextBox2Length.Text + "','" + this.TextBox2Weight.Text + "','" + selected_val_2 + "','" + max_dist + "');"; SqlCommand Command = new SqlCommand(sqlQuery, mySqlConnection); SqlDataReader mySqlDataReader; mySqlConnection.Open(); mySqlDataReader = Command.ExecuteReader(); while (mySqlDataReader.Read()) { } mySqlDataReader.Dispose(); mySqlConnection.Close(); this.LabelOutput.Text = "ID: " + this.TextBoxID.Text + ", Your record was inserted. Your max distance is " + max_dist; } catch (Exception ex) { this.LabelOutput.Text = "Inserting Record Error: " + ex.Message; } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string[] info; double idValue; if (!Double.TryParse(this.TextBoxID.Text, out idValue)) { this.LabelOutput.Text = "Invaild Id number!"; return; } if (idValue >= 5000) { //get info from team table by id info = this.getTeamInfoById(this.TextBoxID.Text); } else { //get info from student table by id info = this.getStudentInfoById(this.TextBoxID.Text); } double total_points = 0.0; double time = 0.0; double stories_num = 0.0; if (!Double.TryParse(this.TextBoxSurvivalTime.Text, out time)) { this.LabelOutput.Text = "Invaild Time!"; return; } if (!Double.TryParse(this.TextBoxStoriesNum.Text, out stories_num)) { this.LabelOutput.Text = "Invaild Stories Number!"; return; } // If<10 seconds, (seconds survived)+ (if >10 stories survived, 2*(Stories survived-10)) //if >10 seconds, 10+(seconds survived-10)*2++if >10 stories survived, 2*(Stories survived-10) if (time < 10) { if (stories_num > 10) { total_points = time + 2 * (stories_num - 10); } else { total_points = time; } } else //time >10 { if (stories_num > 10) { total_points = 10 + 2 * (time - 10) + 2 * (stories_num - 10); } else { total_points = 10 + 2 * (time - 10); } } try { SqlConnection SqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "INSERT INTO shake_and_break_report (participant_id, student_names, school," + "grade_group, survival_time, stories_num, total_points) VALUES " + "('" + this.TextBoxID.Text + "','" + info[0] + "','" + info[1] + "','" + info[3] + "','" + this.TextBoxSurvivalTime.Text + "','" + this.TextBoxStoriesNum.Text + "','" + total_points + "');"; SqlCommand Command = new SqlCommand(sqlQuery, SqlConnection); SqlDataReader SqlDataReader; SqlConnection.Open(); SqlDataReader = Command.ExecuteReader(); while (SqlDataReader.Read()) { } SqlDataReader.Dispose(); SqlConnection.Close(); this.LabelOutput.Text = "ID: " + this.TextBoxID.Text + ", Your record was inserted. Your total point is " + total_points; } catch (Exception ex) { this.LabelOutput.Text = "Inserting Record Error: " + ex.Message; } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string[] info; double idValue; if (!Double.TryParse(this.TextBoxID.Text, out idValue)) { this.LabelEggDropOutput.Text = "Invaild Id number!"; return; } if (idValue >= 5000) { // team this.LabelEggDropOutput.Text = "ID has to be student ID"; return; } else { //get info from student table by id info = this.getStudentInfoById(this.TextBoxID.Text); } double mass = 0.0; double contest_mass = 0.0; double ratio = 0.0; double load = 0.0; if (!Double.TryParse(this.TextBoxMass.Text, out mass)) { this.LabelEggDropOutput.Text = "Invaild mass number!"; return; } if (!Double.TryParse(this.TextBoxLoad.Text, out load)) { this.LabelEggDropOutput.Text = "Invaild load number!"; return; } if (mass > 100) { contest_mass = 100 + Math.Pow((mass - 100), 1.5); } else { contest_mass = mass; } ratio = load / contest_mass; if (this.DropDownListPasses.SelectedValue != "Yes") { ratio = 0.0; } try { SqlConnection SqlConnection = new SqlConnection(SqlTool.GetConnectionString()); string sqlQuery = "INSERT INTO tower_of_power (participant_id, student_name, school," + "grade_group, passes_inspection, mass, contest_mass, peak_load, ratio) VALUES " + "('" + this.TextBoxID.Text + "','" + info[0] + "','" + info[1] + "','" + info[3] + "','" + this.DropDownListPasses.Text + "','" + this.TextBoxMass.Text + "','" + contest_mass.ToString("#.##") + "','" + this.TextBoxLoad.Text + "','" + ratio.ToString("#.##") + "');"; SqlCommand Command = new SqlCommand(sqlQuery, SqlConnection); SqlDataReader SqlDataReader; SqlConnection.Open(); SqlDataReader = Command.ExecuteReader(); while (SqlDataReader.Read()) { } SqlDataReader.Dispose(); SqlConnection.Close(); this.LabelEggDropOutput.Text = "ID: " + this.TextBoxID.Text + ", Your record was inserted. Your final ratio is " + ratio.ToString("#.##"); } catch (Exception ex) { this.LabelEggDropOutput.Text = "Inserting Record Error: " + ex.Message; } }