protected void btnLogin_Click(object sender, EventArgs e) { KGManager.log("Login button was clicked"); //Log In as ADMIN if (tbLogin.Text.Equals("Admin") && tbPassword.Text.Equals("Admin")) { KGManager.userLogin = "******"; KGManager.userName = "******"; Response.Redirect("/Default.aspx"); Context.ApplicationInstance.CompleteRequest(); } //Log In as Parent else { Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("parentID", tbLogin.Text); //check if ID exists in parents table System.Data.DataTable dt = DBConnection.runProcWithResults("checkIfParentExists", data); if (dt.Rows.Count == 1) { //ID in parents table litLogin.Text = ""; data.Add("parentPass", tbPassword.Text); //check if entered correct password dt = DBConnection.runProcWithResults("checkLoginData", data); if (dt.Rows.Count == 1) { //password is correct litPass.Text = ""; KGManager.userLogin = tbLogin.Text; KGManager.userName = ""; if (dt.Rows[0]["gender"].ToString().Equals("M")) { KGManager.userName += "Mr "; } else { KGManager.userName += "Ms "; } KGManager.userName += dt.Rows[0]["surName"].ToString() + " " + dt.Rows[0]["firstName"].ToString(); Response.Redirect("/Default.aspx"); Context.ApplicationInstance.CompleteRequest(); } else { //incorect password litPass.Text = "Wrong password"; } } else { //ID not in parents table litLogin.Text = "Please register first!"; } } }
protected void btnAddKidToPublic_Click(object sender, EventArgs e) { afterAction = true; KGManager.log("add to public button was clicked"); //check if ID already exists in DB Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("parentID", tbID.Text); System.Data.DataTable dt = DBConnection.runProcWithResults("checkIfIDExists", data); if (dt.Rows.Count != 0) { //ID already in DB KGManager.log("ID " + tbID.Text + " already in DB\n\n"); alreadyIn = true; } else { //ID not in DB alreadyIn = false; data = new Dictionary <string, object>(); data.Add("kidID", tbID.Text); data.Add("firstName", tbFirstName.Text); data.Add("surName", tbLastName.Text); data.Add("dateOfBirth", tbDOB.Text); data.Add("street", tbStreet.Text); data.Add("houseNumber", tbHouseNumber.Text); data.Add("city", tbCity.Text); data.Add("latitude", tbLatitude.Text); data.Add("longitude", tbLongitude.Text); data.Add("kindergardenID", tbKgID.Text); data.Add("classNumber", tbClNum.Text); data.Add("parentID", KGManager.userLogin); dt = DBConnection.runProcWithResults("addKid", data); if (dt.Rows.Count == 1) { //Kid was added successfully KGManager.log("Kid " + tbID.Text + " was added to parent " + KGManager.userLogin); isSuccess = true; } else { //Kid wasn't added KGManager.log("Kid " + tbID.Text + " was NOT added to parent " + KGManager.userLogin); isSuccess = false; } } submitData(); clearAllFields(); }
protected void btnPrevActivity_Click(object sender, EventArgs e) { KGManager.log("PREV BUTTON WAS CLICKED: CURR ROW -> " + currRow + " TOTAL NUM OF ROWS -> " + act.Rows.Count); if (act.Rows.Count != 0) { if (currRow == 0) { currRow = act.Rows.Count - 1; } else { currRow--; } fillActivityInfo(currRow); } KGManager.log("==================: CURR ROW -> " + currRow + " TOTAL NUM OF ROWS -> " + act.Rows.Count); }
protected void btnPrevPrivate_Click(object sender, EventArgs e) { KGManager.log("PREV BUTTON WAS CLICKED: CURR ROW -> " + currRow + " TOTAL NUM OF ROWS -> " + privateKG.Rows.Count); if (privateKG.Rows.Count != 0) { if (currRow == 0) { currRow = privateKG.Rows.Count - 1; } else { currRow--; } fillPrivateKGInfo(currRow); } KGManager.log("==================: CURR ROW -> " + currRow + " TOTAL NUM OF ROWS -> " + privateKG.Rows.Count); }
protected void btnSignUp_Click(object sender, EventArgs e) { KGManager.log("Sugn Up button was clicked"); Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("parentID", tbLogin.Text); //check if ID alreadt in DB System.Data.DataTable dt = DBConnection.runProcWithResults("checkIfIDExists", data); KGManager.log("signUp after check -> " + dt.Rows.Count); if (dt.Rows.Count != 0) { litLogin.Text = "This ID is already exists"; } else { //ID not in DB litLogin.Text = ""; data.Add("firstName", tbFirstName.Text); data.Add("surName", tbLastName.Text); data.Add("DOB", tbDOB.Text); data.Add("gender", rblGender.SelectedIndex == 0 ? 'M' : 'F'); data.Add("pass", tbPassword.Text); //try to add parent dt = DBConnection.runProcWithResults("addParent", data); if (dt.Rows.Count == 1) { //parent added successfully KGManager.log("Parent was added successfully"); KGManager.userLogin = tbLogin.Text; KGManager.userName = (rblGender.SelectedIndex == 0 ? "Mr " : "Ms ") + tbLastName.Text + " " + tbFirstName.Text; Response.Redirect("/Default.aspx"); Context.ApplicationInstance.CompleteRequest(); } else { //parent wasn't added KGManager.log("Parent wasn't added"); litLogin.Text = "Something went wrong ;("; } } }
public static System.Data.DataTable runProcWithResults(string procName, Dictionary <String, Object> valMap) { KGManager.log("Received instruction to run procedure " + procName); System.Data.DataTable toReturn = new System.Data.DataTable(); comm = new SqlCommand(); KGConnection = new SqlConnection(connString); comm.CommandText = procName; comm.CommandType = System.Data.CommandType.StoredProcedure; comm.Connection = KGConnection; try { //Add values to the PROC Execution foreach (KeyValuePair <String, Object> entry in valMap) { comm.Parameters.AddWithValue("@" + entry.Key, entry.Value); KGManager.log("Adding parameter @" + entry.Key + "=" + entry.Value); } KGConnection.Open(); KGManager.log("Opened KGConnection"); SqlDataAdapter dr = new SqlDataAdapter(comm); KGManager.log("Sending SQL Statement: " + comm.CommandText + " with " + comm.Parameters.Count + " parameters."); KGManager.log("Returned #" + dr.Fill(toReturn) + " rows!!"); return(toReturn); } catch (Exception e) { KGManager.log("!!!Exception Occured!!!\n" + e.Message + "\n" + e.StackTrace); return(new System.Data.DataTable()); } finally { KGManager.log("Closing connection"); KGConnection.Close(); } }
protected void btnAddKidToActivity_Click(object sender, EventArgs e) { afterAction = true; KGManager.log("add to activity button was clicked"); //check if ID already exists in DB Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("kidID", rblKids.SelectedValue); data.Add("activityID", tbActID.Text); System.Data.DataTable dt = DBConnection.runProcWithResults("checkIfKidAlreadyInActivity", data); if (dt.Rows.Count != 0) { //kid already in activity KGManager.log("ID " + rblKids.SelectedValue + " already in activity " + tbActID.Text); alreadyIn = true; } else { //kid not in activity alreadyIn = false; dt = DBConnection.runProcWithResults("addKidToActivity", data); if (dt.Rows.Count == 1) { //Kid was added successfully KGManager.log("Kid " + rblKids.SelectedValue + " was added to activity " + tbActID.Text); isSuccess = true; } else { //Kid wasn't added KGManager.log("Kid " + rblKids.SelectedValue + " was NOT added to activity " + tbActID.Text); isSuccess = false; } } submitData(); clearAllCard(); }
protected void btnImport_Click(object sender, EventArgs e) { if (FileUpload1.PostedFile.ContentLength == 0) { KGManager.log("EMPTY FILE"); showMessage("Choose a file first.", "red", 200); } else { afterAction = true; using (System.IO.StreamReader inputStreamReader = new System.IO.StreamReader(FileUpload1.PostedFile.InputStream)) { //ADD ALL ROWS TO DB - insertUpdateT while (!inputStreamReader.EndOfStream) { string[] row = inputStreamReader.ReadLine().Split(','); Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("1", row[1]); data.Add("2", row[2]); if (row[0].Equals("TFA")) { data.Add("3", row[3]); } string ans = (DBConnection.runProcWithResults("insertUpdate" + row[0], data)).Rows[0]["ans"].ToString(); if (row[0].Equals("TFA")) { switch (ans) { case "0": failedTFA++; break; case "1": updatedTFA++; break; case "2": addedTFA++; break; } } else { switch (ans) { case "0": failedT++; break; case "1": updatedT++; break; case "2": addedT++; break; } } } } } showMessage(); }