protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { adoNet adoNet = new adoNet(); string sql = "SELECT COUNT(*) " + "FROM Genitori " + "WHERE email = '" + args.Value + "'"; string ris = adoNet.eseguiScalar(sql, CommandType.Text); if (Convert.ToInt32(ris) == 0) { sql = "SELECT COUNT(*) " + "FROM Personale " + "WHERE email = '" + args.Value + "'"; ris = adoNet.eseguiScalar(sql, CommandType.Text); if (Convert.ToInt32(ris) == 0) { sql = "SELECT COUNT(*) " + "FROM Centri " + "WHERE email = '" + args.Value + "'"; ris = adoNet.eseguiScalar(sql, CommandType.Text); if (Convert.ToInt32(ris) == 0) { args.IsValid = true; //ok } else { args.IsValid = false; //ko } } } else { args.IsValid = false; //ko } }
protected void btnModifica_Click(object sender, EventArgs e) { if (txtPassword.Text == "" || txtPasswordR.Text == "") { lblErrore.Text = "Password non valida"; } else if (txtPasswordR.Text != txtPassword.Text) { lblErrore.Text = "Password non corrispondenti"; } else { // Controllo campi di Input if (txtPassword.Text.Contains("'") || txtPassword.Text.Contains("\"") || txtPasswordR.Text.Contains("'") || txtPasswordR.Text.Contains("\"")) { lblErrore.Text = "Caratteri non validi."; return; } string value = Request.QueryString["url"]; if (value != null) { adoNet ado = new adoNet(); string sql = "SELECT idPersonale FROM LinkPasswordPersonale WHERE url = '" + value + "' AND DATEDIFF(hour, dataRichiesta, GETDATE()) <= 24"; string res = ado.eseguiScalar(sql, System.Data.CommandType.Text); if (res != "") { sql = "UPDATE Personale SET pwd = '" + SHA.GenerateSHA512String(txtPassword.Text) + "' WHERE id = " + res; ado.eseguiNonQuery(sql, System.Data.CommandType.Text); sql = "UPDATE LinkPasswordPersonale SET modifica = 1 WHERE idPersonale = " + res + " AND url = '" + value + "'"; ado.eseguiNonQuery(sql, System.Data.CommandType.Text); Response.Redirect("./Login.aspx"); } else { sql = "SELECT idGenitore FROM LinkPasswordGenitori WHERE url = '" + value + "' AND DATEDIFF(hour, dataRichiesta, GETDATE()) <= 24"; res = ado.eseguiScalar(sql, System.Data.CommandType.Text); if (res != "") { sql = "UPDATE Genitori SET pwd = '" + SHA.GenerateSHA512String(txtPassword.Text) + "' WHERE id = " + res; ado.eseguiNonQuery(sql, System.Data.CommandType.Text); sql = "UPDATE LinkPasswordGenitori SET modifica = 1 WHERE idGenitore = " + res + " AND url = '" + value + "'"; ado.eseguiNonQuery(sql, System.Data.CommandType.Text); Response.Redirect("./Login.aspx"); } else { Response.Redirect("./Login.aspx"); } } } else { Response.Redirect("./Login.aspx"); } } }
protected void btnRecupera_Click(object sender, EventArgs e) { adoNet.impostaConnessione(); adoNet ado = new adoNet(); string sql = "SELECT id FROM Personale WHERE email = '" + txtEmailUser.Text + "'"; string codice = ado.eseguiScalar(sql, System.Data.CommandType.Text); if (codice != "") { string rand = ""; bool newURL = false; do { rand = RandomString(49); sql = "SELECT COUNT(*) FROM LinkPasswordPersonale WHERE url = '" + rand + "'"; if (Convert.ToInt32(ado.eseguiScalar(sql, System.Data.CommandType.Text)) == 0) { newURL = true; } } while (!newURL); sql = "INSERT INTO LinkPasswordPersonale (idPersonale, url) VALUES(" + codice + ", '" + rand + "')"; ado.eseguiNonQuery(sql, System.Data.CommandType.Text); inviaEmail(txtEmailUser.Text, rand); divSucc.Visible = true; divForg.Visible = false; } else { sql = "SELECT id FROM Genitori WHERE email = '" + txtEmailUser.Text + "'"; codice = ado.eseguiScalar(sql, System.Data.CommandType.Text); if (codice != "") { string rand = ""; bool newURL = false; do { rand = RandomString(49); sql = "SELECT COUNT(*) FROM LinkPasswordGenitori WHERE url = '" + rand + "'"; if (Convert.ToInt32(ado.eseguiScalar(sql, System.Data.CommandType.Text)) == 0) { newURL = true; } } while (!newURL); sql = "INSERT INTO LinkPasswordGenitori (idGenitore, url) VALUES(" + codice + ", '" + rand + "')"; ado.eseguiNonQuery(sql, System.Data.CommandType.Text); inviaEmail(txtEmailUser.Text, rand); divSucc.Visible = true; divForg.Visible = false; } else { lblErrore.Text = "Email non trovata"; lblErrore.Visible = true; } } }
protected void salvaAnimatore_Click(object sender, EventArgs e) { adoNet ado = new adoNet(); string sql = ""; SqlCommand command = new SqlCommand(); switch (((Button)sender).Text) { case "Aggiungi": sql = "INSERT INTO Personale(nome, cognome, sesso, dataNascita, natoA, nazionalita, indirizzo, numeroCivico, idCitta, numeroTelefono, email) " + "OUTPUT Inserted.id " + "VALUES " + "(@nome, @cognome, @sesso, @dataNascita, @natoA, @nazionalita, @indirizzo, @numeroCivico, @idCitta, @numeroTelefono, @email)"; command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@nome", nomeAnimatore.Text); command.Parameters.AddWithValue("@cognome", cognomeAnimatore.Text); command.Parameters.AddWithValue("@sesso", sessoAnimatore.SelectedValue); command.Parameters.AddWithValue("@dataNascita", dataNascitaAnimatore.Text); command.Parameters.AddWithValue("@natoA", cittaNascitaAnimatore.SelectedValue); command.Parameters.AddWithValue("@nazionalita", nazionalitaAnimatore.SelectedValue); command.Parameters.AddWithValue("@indirizzo", indirizzoAnimatore.Text); command.Parameters.AddWithValue("@numeroCivico", numeroCivicoAnimatore.Text); command.Parameters.AddWithValue("@idCitta", cittaAnimatore.SelectedValue); command.Parameters.AddWithValue("@numeroTelefono", cellulareAnimatore.Text); command.Parameters.AddWithValue("@email", emailAnimatore.Text); string idAnimatore = ado.eseguiScalar(command); sql = "INSERT INTO Genitori(nome, cognome, numeroTelefono) " + "OUTPUT Inserted.id " + "VALUES " + "(@nome, @cognome, @numeroTelefono)"; command = new SqlCommand(); command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@nome", nomeAnimatore.Text); command.Parameters.AddWithValue("@cognome", cognomeAnimatore.Text); command.Parameters.AddWithValue("@numeroTelefono", cellulareAnimatore.Text); string idGenitore = ado.eseguiScalar(command); sql = "INSERT INTO ParenteleAnimatori(idAnimatore, idGenitore) VALUES(" + idAnimatore + ", " + idGenitore + ")"; ado.eseguiNonQuery(sql, CommandType.Text); Response.Redirect("./Visualizzazione.aspx"); break; case "Modifica": break; case "Chiudi": break; } }
private string addGenitore(Genitore genitore1) { string sql = "INSERT INTO Genitori(nome, cognome, sesso, indirizzo, numeroCivico, idCitta, numeroTelefono1, descrizioneNT1, numeroTelefono2, descrizioneNT2, numeroTelefono3, descrizioneNT3, email) " + "OUTPUT Inserted.id " + "VALUES (@nome, @cognome, @sesso, @indirizzo, @numeroCivico, @idCitta, @NT1, @DNT1, @NT2, @DNT2, @NT3, @DNT3, @email);"; SqlCommand command = new SqlCommand(); command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@nome", genitore1.nome); command.Parameters.AddWithValue("@cognome", genitore1.cognome); command.Parameters.AddWithValue("@sesso", genitore1.sesso); command.Parameters.AddWithValue("@indirizzo", genitore1.indirizzo); command.Parameters.AddWithValue("@numeroCivico", genitore1.numeroCivico); command.Parameters.AddWithValue("@idCitta", genitore1.citta); command.Parameters.AddWithValue("@NT1", genitore1.cellulare[0, 0]); command.Parameters.AddWithValue("@DNT1", genitore1.cellulare[0, 1]); command.Parameters.AddWithValue("@NT2", genitore1.cellulare[1, 0]); command.Parameters.AddWithValue("@DNT2", genitore1.cellulare[1, 1]); command.Parameters.AddWithValue("@NT3", genitore1.cellulare[2, 0]); command.Parameters.AddWithValue("@DNT3", genitore1.cellulare[2, 1]); command.Parameters.AddWithValue("@email", genitore1.email); adoNet adoNet = new adoNet(); return(adoNet.eseguiScalar(command)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string value = Request.QueryString["url"]; if (value != null) { adoNet ado = new adoNet(); string sql = "SELECT idPersonale FROM LinkPasswordPersonale WHERE url = '" + value + "' AND DATEDIFF(hour, dataRichiesta, GETDATE()) <= 24 AND modifica = 0"; string res = ado.eseguiScalar(sql, System.Data.CommandType.Text); if (res != "") { sql = "SELECT nome + ' ' + cognome AS NomeCognome FROM Personale WHERE id = " + res; res = ado.eseguiScalar(sql, System.Data.CommandType.Text); NomeCognome.Text = res; } else { sql = "SELECT idGenitore FROM LinkPasswordGenitori WHERE url = '" + value + "' AND DATEDIFF(hour, dataRichiesta, GETDATE()) <= 24 AND modifica = 0"; res = ado.eseguiScalar(sql, System.Data.CommandType.Text); if (res != "") { sql = "SELECT nome + ' ' + cognome AS NomeCognome FROM Genitori WHERE id = " + res; res = ado.eseguiScalar(sql, System.Data.CommandType.Text); NomeCognome.Text = res; } else { Response.Redirect("./Login.aspx"); } } } else { Response.Redirect("./Login.aspx"); } } }
private int verificaComune(Bambino newBambino, int p) { int ris = 0; string sql = "SELECT idCitta FROM Turni INNER JOIN Centri ON idCentro = Centri.id WHERE Turni.id = " + newBambino.turni[p, 0]; adoNet ado = new adoNet(); string txt = ado.eseguiScalar(sql, CommandType.Text); if (newBambino.citta == Convert.ToInt32(txt)) { ris = 1; } else { sql = "SELECT COUNT(*) FROM FuoriComune INNER JOIN Centri ON idCentro =Centri.id INNER JOIN Turni ON Turni.idCentro = Centri.id WHERE Turni.id = " + newBambino.turni[p, 0] + "" + " AND idCitta = " + newBambino.citta; string countCitta = ado.eseguiScalar(sql, CommandType.Text); if (Convert.ToInt32(countCitta) > 1) { sql = "SELECT COUNT(*) FROM FuoriComune INNER JOIN Centri ON idCentro =Centri.id INNER JOIN Turni ON Turni.idCentro = Centri.id WHERE Turni.id = " + newBambino.turni[p, 0] + "" + " AND idCitta = " + newBambino.citta + "" + " AND indirizzo = '" + newBambino.indirizzo + "'"; string countIndirizzo = ado.eseguiScalar(sql, CommandType.Text); if (Convert.ToInt32(countIndirizzo) == 1) { ris = 1; } } else if (Convert.ToInt32(countCitta) == 1) { ris = 1; } } return(ris); }
protected void Page_Load(object sender, EventArgs e) { if (Session["id"] == null) { Response.Redirect("~/Login.aspx"); } else if ((string)Session["ruolo"] == "G") { adoNet.impostaConnessione(); adoNet ado = new adoNet(); string sql = "SELECT nome + ' ' + cognome AS NomeCognome FROM Genitori WHERE id = " + Session["id"]; nomeCognome = ado.eseguiScalar(sql, System.Data.CommandType.Text); sceltaBambino.Visible = true; sql = @"select Turni.id, Turni.numero from Turni inner join FreqBambini on idTurno = Turni.id inner join ParenteleBambini on FreqBambini.idBambino = ParenteleBambini.idBambino inner join Genitori on Genitori.id = ParenteleBambini.idGenitore where Genitori.id = " + Session["id"] + " AND Turni.anno = " + DateTime.Now.Year; DataTable dt = ado.eseguiQuery(sql, System.Data.CommandType.Text); foreach (DataRow dr in dt.Rows) { sceltaTurno.Items.Add(new ListItem(dr.ItemArray[1] + "° turno", dr.ItemArray[0].ToString())); } } else { adoNet.impostaConnessione(); adoNet ado = new adoNet(); string sql = "SELECT nome + ' ' + cognome AS NomeCognome FROM Personale WHERE id = " + Session["id"]; nomeCognome = ado.eseguiScalar(sql, System.Data.CommandType.Text); sceltaBambino.Visible = false; sql = @"select Turni.id, Turni.numero from FreqPersonale inner join Personale on idPersonale = Personale.id inner join Turni on idTurno = Turni.id where Personale.id = " + Session["id"]; DataTable dt = ado.eseguiQuery(sql, System.Data.CommandType.Text); foreach (DataRow dr in dt.Rows) { sceltaTurno.Items.Add(new ListItem(dr.ItemArray[1] + "° turno", dr.ItemArray[0].ToString())); } } }
protected void btnLogin_Click(object sender, EventArgs e) { if (txtEmailUser.Text == "") { lblErrore.Text = "Utente non valido"; } else if (txtPasswordUser.Text == "") { lblErrore.Text = "Password non valida"; } else { // Controllo campi di Input if (txtEmailUser.Text.Contains("'") || txtEmailUser.Text.Contains("\"") || txtPasswordUser.Text.Contains("'") || txtPasswordUser.Text.Contains("\"")) { lblErrore.Text = "Caratteri non validi."; return; } // Crea stringa SQL per verificare validità Utente/password string sql = @"select ruolo, Personale.id, idCentro from FreqPersonale inner join Personale on idPersonale = Personale.id inner join Turni on idTurno = Turni.id where email = '" + txtEmailUser.Text + "' " + "and pwd = '" + txtPasswordUser.Text + "' " + "and anno = " + DateTime.Now.Year; adoNet adoWeb = new adoNet(); DataTable codice = adoWeb.eseguiQuery(sql, CommandType.Text); if (codice.Rows.Count == 0) { sql = @"select id from Genitori where email = '" + txtEmailUser.Text + "' " + "and pwd = '" + SHA.GenerateSHA512String(txtPasswordUser.Text) + "' "; string codiceG = adoWeb.eseguiScalar(sql, CommandType.Text); if (codiceG != string.Empty) { Session["ruolo"] = "G"; Session["id"] = codiceG; sql = @"select idCentro from Turni inner join FreqBambini on idTurno = Turni.id inner join ParenteleBambini on FreqBambini.idBambino = ParenteleBambini.idBambino inner join Genitori on Genitori.id = ParenteleBambini.idGenitore where Genitori.id = " + codiceG + " AND Turni.anno = " + DateTime.Now.Year; codiceG = adoWeb.eseguiScalar(sql, CommandType.Text); Session["idCentro"] = codiceG; Session.Timeout = 180; if (Request.UrlReferrer.ToString().Contains("Loggato")) { Response.Redirect(Request.UrlReferrer.ToString()); } else { Response.Redirect("./Loggato/Index.aspx"); } } else { lblErrore.Text = "ATTENZIONE!!! Utente e/o password non validi"; } } else { // creazione session Session["ruolo"] = codice.Rows[0]["ruolo"]; Session["id"] = codice.Rows[0]["Personale.id"]; Session["idCentro"] = codice.Rows[0]["idCentro"]; Session.Timeout = 180; if (Request.UrlReferrer.ToString().Contains("Loggato")) { Response.Redirect(Request.UrlReferrer.ToString()); } else { Response.Redirect("./Loggato/Index.aspx"); } } } }
protected void termineIscrizione_Click(object sender, EventArgs e) { string sql; SqlCommand command; adoNet adoNet = new adoNet(); string[] idGenitori = new string[2]; Genitore genitore1 = new Genitore(Request.Cookies["genitore1"].Value); idGenitori[0] = addGenitore(genitore1); Request.Cookies.Remove("genitore1"); Genitore genitore2; try { if (Request.Cookies["genitore2"].Value != null) { genitore2 = new Genitore(Request.Cookies["genitore2"].Value); idGenitori[1] = addGenitore(genitore2); Request.Cookies.Remove("genitore2"); } } catch (Exception ex) { } string idBambini = ""; for (int k = 0; k <= Request.Cookies.Count; k++) { try { if (Request.Cookies["bambino" + k].Value != null) { Bambino newBambino = new Bambino(); newBambino.readCookie(Request.Cookies["bambino" + k].Value); sql = "INSERT INTO Bambini(nome, cognome, sesso, dataNascita, natoA, CF, nazionalita, indirizzo, numeroCivico, idCitta) " + "OUTPUT Inserted.id " + "VALUES (@nome, @cognome, @sesso, @dataNascita, @natoA, @CF, @nazionalita, @indirizzo, @numeroCivico, @idCitta);"; command = new SqlCommand(); command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@nome", newBambino.nome); command.Parameters.AddWithValue("@cognome", newBambino.cognome); command.Parameters.AddWithValue("@sesso", newBambino.sesso); command.Parameters.AddWithValue("@dataNascita", newBambino.dataNascita); command.Parameters.AddWithValue("@natoA", newBambino.cittaNascita); command.Parameters.AddWithValue("@CF", newBambino.CF); command.Parameters.AddWithValue("@nazionalita", newBambino.nazionalita); command.Parameters.AddWithValue("@indirizzo", newBambino.indirizzo); command.Parameters.AddWithValue("@numeroCivico", newBambino.numeroCivico); command.Parameters.AddWithValue("@idCitta", newBambino.citta); adoNet = new adoNet(); string idBambino = adoNet.eseguiScalar(command); for (int j = 0; j < newBambino.turni.GetLength(0); j++) { if (Convert.ToInt32(newBambino.turni[j, 0]) != 0) { sql = "INSERT INTO FreqBambini(idTurno, idBambino, settimane, dataIscrizione, servizioMensa, scuola, idClasse, pagato) " + "OUTPUT Inserted.id" + "VALUES(@idTurno, @idBambino, @settimane, @dataIscrizione, @servizioMensa, @scuola, @idClasse, 0);"; command = new SqlCommand(); command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@idTurno", newBambino.turni[j, 0]); command.Parameters.AddWithValue("@idBambino", idBambino); command.Parameters.AddWithValue("@settimane", getStringTurno(newBambino.turni, j)); command.Parameters.AddWithValue("@dataIscrizione", DateTime.Now); command.Parameters.AddWithValue("@servizioMensa", newBambino.turni[j, 1]); command.Parameters.AddWithValue("@scuola", newBambino.scuola); command.Parameters.AddWithValue("@idClasse", newBambino.classe); string idIscrizione = adoNet.eseguiScalar(command); idBambini += idIscrizione + ","; } } addParentela(idBambino, idGenitori[0]); if (idGenitori[1] != null) { addParentela(idBambino, idGenitori[1]); } Request.Cookies.Remove("bambino" + k); } } catch (Exception ex) { } } sql = "INSERT INTO pagamentiQuote(totale, pagato, metodo, idIscrizioni) " + "VALUES(@totale, @pagato, @metodo, @idIscrizioni);"; command = new SqlCommand(); command.Parameters.AddWithValue("@totale", ((TableCell)tablePagamento.FindControl("totDaPagare")).Text.Split(' ')[0]); command.Parameters.AddWithValue("@pagato", false); command.Parameters.AddWithValue("@metodo", (tipoPagamento.SelectedValue == "cassa") ? "C" : "S"); command.Parameters.AddWithValue("@idIscrizioni", idBambini); adoNet.eseguiNonQuery(command); }