protected void submitBtn_Click(object sender, EventArgs e) { using (SqlConnection connection = DBUtility.ConnectToSQLDB()) { SqlCommand command = new SqlCommand("SELECT * FROM Admin", connection); //RUN command and dump results into reader SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { //Gets username from table string username = reader["username"].ToString(); //Gets password from table string password = reader["password"].ToString(); if (usernameTxtbox.Text.Equals(username) && passwordTxtbox.Text.Equals(password)) { AdminAppSession.setUsername(usernameTxtbox.Text); Response.Redirect("Admin.aspx"); } else { message.Text = "Invalid User"; } } } }
public MasterProcessCmdHandler(HttpClient httpClient, AdminAppSession appSession) { p_HttpClient = httpClient; p_AppSession = appSession; }
protected void Page_Load(object sender, EventArgs e) { if (!AdminAppSession.isLoggedIn()) { Response.Redirect("AdminLogin.aspx"); return; } titleAdminPage.Text = "Welcome " + AdminAppSession.getUsername(); try { using (SqlConnection connection = DBUtility.ConnectToSQLDB()) { //numbers of questionId for SQL purposes int questionIdState = 3; int questionIdBank = 6; int questionIdBankCommbank = 8; int questionIdBankNAB = 11; int questionIdBankANZ = 12; int questionIdNewspaper = 7; int questionIdGender = 1; int questionIdSports = 9; int questionIdTravel = 10; //checking whether the page has been render before, if no then do so. if (!IsPostBack) { //State SqlCommand optionCommandState = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdState, connection); SqlDataReader optionReaderState = optionCommandState.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderState.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderState["optionText"], optionReaderState["optionId"].ToString()); CheckBoxListInputState.Items.Add(item); } //Bank SqlCommand optionCommandBank = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdBank, connection); SqlDataReader optionReaderBank = optionCommandBank.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderBank.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderBank["optionText"], optionReaderBank["optionId"].ToString()); CheckBoxListBank.Items.Add(item); } //-----Bank Services---- //Bank Services Commbank SqlCommand optionCommandBankServicesCommbank = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdBankCommbank, connection); SqlDataReader optionReaderBankServicesCommbank = optionCommandBankServicesCommbank.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderBankServicesCommbank.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderBankServicesCommbank["optionText"], optionReaderBankServicesCommbank["optionId"].ToString()); CheckBoxListBankServicesCommbank.Items.Add(item); } //Bank Services NAB SqlCommand optionCommandBankServicesNAB = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdBankNAB, connection); SqlDataReader optionReaderBankServicesNAB = optionCommandBankServicesNAB.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderBankServicesNAB.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderBankServicesNAB["optionText"], optionReaderBankServicesNAB["optionId"].ToString()); CheckBoxListBankServicesNAB.Items.Add(item); } //Bank Services ANZ SqlCommand optionCommandBankServicesANZ = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdBankANZ, connection); SqlDataReader optionReaderBankServicesANZ = optionCommandBankServicesANZ.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderBankServicesANZ.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderBankServicesANZ["optionText"], optionReaderBankServicesANZ["optionId"].ToString()); CheckBoxListBankServicesANZ.Items.Add(item); } //-----Newspaper related----- //Newspaper SqlCommand optionCommandNewspaper = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdNewspaper, connection); SqlDataReader optionReaderNewspaper = optionCommandNewspaper.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderNewspaper.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderNewspaper["optionText"], optionReaderNewspaper["optionId"].ToString()); CheckBoxListNewspaper.Items.Add(item); } //Gender SqlCommand optionCommandGender = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdGender, connection); SqlDataReader optionReaderGender = optionCommandGender.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderGender.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderGender["optionText"], optionReaderGender["optionId"].ToString()); CheckBoxListGender.Items.Add(item); } //Sports SqlCommand optionCommandSports = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdSports, connection); SqlDataReader optionReaderSports = optionCommandSports.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderSports.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderSports["optionText"], optionReaderSports["optionId"].ToString()); CheckBoxListSports.Items.Add(item); } //Travel SqlCommand optionCommandTravel = new SqlCommand("SELECT * FROM Options WHERE questionId = " + questionIdTravel, connection); SqlDataReader optionReaderTravel = optionCommandTravel.ExecuteReader(); //loop through all the question option results and chuck into the checkBox while (optionReaderTravel.Read()) { //takes the text value from database as first input and id as last input ListItem item = new ListItem((string)optionReaderTravel["optionText"], optionReaderTravel["optionId"].ToString()); CheckBoxListTravel.Items.Add(item); } } } } catch (Exception ex) { Console.WriteLine(ex); } }
public DataService(HttpClient httpClient, AdminAppSession appSession) { p_HttpClient = httpClient; p_AppSession = appSession; }