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));
        }
Example #2
0
        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
            }
        }
Example #3
0
        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 provinciaBambino_SelectedIndexChanged(object sender, EventArgs e)
        {
            string    sql    = @"select * 
                        from Citta where prov = '" + provinciaBambino.SelectedValue + "'";
            adoNet    adoWeb = new adoNet();
            DataTable codice = adoWeb.eseguiQuery(sql, CommandType.Text);

            cittaBambino.DataSource     = codice;
            cittaBambino.DataTextField  = "descri";
            cittaBambino.DataValueField = "IdCitta";
            cittaBambino.DataBind();
        }
Example #6
0
        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;
            }
        }
Example #7
0
 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()));
         }
     }
 }
Example #8
0
 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");
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Response.Redirect("../../Login.aspx");
            }
            else
            {
                emailGenitore1C.SetFocusOnError    = true;
                emailGenitore1C.ValidateEmptyText  = false; //esegue il controllo anche se campo vuoto
                emailGenitore1C.EnableClientScript = false;
                emailGenitore1C.ForeColor          = System.Drawing.Color.Red;
                if (!Page.IsPostBack)
                {
                    datiGenitore2_CheckedChanged(new object(), new EventArgs());
                    //adoNet.impostaConnessione();


                    string    sql    = @"select * 
                        from Province";
                    adoNet    adoWeb = new adoNet();
                    DataTable codice = adoWeb.eseguiQuery(sql, CommandType.Text);
                    provinciaGenitore1.DataSource     = codice;
                    provinciaGenitore1.DataTextField  = "DescProvincia";
                    provinciaGenitore1.DataValueField = "CodProvincia";
                    provinciaGenitore1.DataBind();
                    provinciaGenitore1.SelectedIndex = -1;

                    provinciaGenitore2.DataSource     = codice;
                    provinciaGenitore2.DataTextField  = "DescProvincia";
                    provinciaGenitore2.DataValueField = "CodProvincia";
                    provinciaGenitore2.DataBind();
                    provinciaGenitore2.SelectedIndex = -1;
                }
            }
        }
        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 salvaBambino_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                datiBambino.Visible       = false;
                termineIscrizione.Visible = true;
                Bambino newBambino = new Bambino();
                newBambino.nome         = nomeBambino.Text;
                newBambino.cognome      = cognomeBambino.Text;
                newBambino.sesso        = Convert.ToChar(sessoBambino.SelectedValue);
                newBambino.nazionalita  = Convert.ToInt32(nazionalitaBambino.SelectedValue);
                newBambino.dataNascita  = Convert.ToDateTime(dataNascitaBambino.Text);
                newBambino.cittaNascita = Convert.ToInt32(cittaNascitaBambino.SelectedValue);
                newBambino.CF           = codiceFiscaleBambino.Text;
                newBambino.indirizzo    = indirizzoBambino.Text;
                newBambino.numeroCivico = numeroCivicoBambino.Text;
                newBambino.provincia    = provinciaBambino.SelectedValue;
                newBambino.citta        = Convert.ToInt32(cittaBambino.SelectedValue);
                newBambino.classe       = Convert.ToInt32(classeBambino.SelectedValue);
                newBambino.scuola       = scuolaBambino.Text;


                newBambino.turni = new object[idTurni.Length, 17];
                int i = 0;
                foreach (int turno in idTurni)
                {
                    if (((CheckBox)tableTurni.FindControl(turno.ToString())).Checked)
                    {
                        newBambino.turni[i, 0] = turno;
                        try
                        {
                            newBambino.turni[i, 1] = ((RadioButtonList)tableTurni.FindControl("mensa" + turno.ToString())).SelectedValue == "No" ? 0 : 1;
                        }
                        catch (Exception ex)
                        {
                            newBambino.turni[i, 1] = 0;
                        }
                        for (int y = 0; y < ((CheckBoxList)tableTurni.FindControl("settimane" + turno.ToString())).Items.Count; y++)
                        {
                            newBambino.turni[i, y + 2] = Convert.ToInt32(((CheckBoxList)tableTurni.FindControl("settimane" + turno.ToString())).Items[y].Selected);
                        }
                        i++;
                    }
                }
                int n = 0;
                for (int k = 0; k <= Request.Cookies.Count; k++)
                {
                    try
                    {
                        if (Request.Cookies["bambino" + k].Value != null)
                        {
                            n++;
                        }
                    }
                    catch { }
                }
                Response.Cookies["bambino" + (n + 1)].Value  += newBambino.writeCookie();
                Response.Cookies["bambino" + (n + 1)].Expires = DateTime.Now.AddMinutes(30);
                //bambini.Add(newBambino);
                TableRow  tr = new TableRow();
                TableCell tc = new TableCell();
                tc.Text = newBambino.nome;
                tr.Cells.Add(tc);
                tc      = new TableCell();
                tc.Text = newBambino.cognome;
                tr.Cells.Add(tc);
                tc      = new TableCell();
                tc.Text = newBambino.dataNascita.ToShortDateString();
                tr.Cells.Add(tc);
                tc = new TableCell();
                for (int p = 0; p < newBambino.turni.GetLength(0); p++)
                {
                    if (Convert.ToInt32(newBambino.turni[p, 0]) != 0)
                    {
                        string    sql            = @"select * 
                        from Turni WHERE id = " + newBambino.turni[p, 0];
                        adoNet    adoWeb         = new adoNet();
                        DataTable dettaglioTurno = adoWeb.eseguiQuery(sql, CommandType.Text);
                        tc.Text += " ♦ Turno " + dettaglioTurno.Rows[0].Field <int>("numero").ToString() + ": " + dettaglioTurno.Rows[0].Field <DateTime>("dataInizio").ToShortDateString() + " - " + dettaglioTurno.Rows[0].Field <DateTime>("dataFine").ToShortDateString() + " ";
                        if (Convert.ToBoolean(dettaglioTurno.Rows[0].Field <bool>("servizioMensa")))
                        {
                            tc.Text += "- Mensa: " + (Convert.ToInt32(newBambino.turni[p, 1]) == 1 ? "Sì" : "No");
                        }
                        tc.Text += "<br/>";
                    }
                }
                tr.Cells.Add(tc);
                tableDettagli.Rows.Add(tr);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Response.Redirect("../../Login.aspx");
            }
            else
            {
                adoNet adoWeb = new adoNet();

                try
                {
                    if (Request.Cookies["genitore1"].Value == null)
                    {
                        Response.Redirect("./DatiGenitori.aspx");
                    }
                    else if (!IsPostBack)
                    {
                        adoNet.impostaConnessione();

                        bambini = new List <Bambino>();
                        Genitore genitore1 = new Genitore(Request.Cookies["genitore1"].Value);
                        Genitore genitore2;
                        try
                        {
                            if (Request.Cookies["genitore2"].Value != null)
                            {
                                genitore2 = new Genitore(Request.Cookies["genitore2"].Value);
                                if (genitore1.indirizzo == genitore2.indirizzo &&
                                    genitore1.numeroCivico == genitore2.numeroCivico &&
                                    genitore1.citta == genitore2.citta &&
                                    genitore1.provincia == genitore2.provincia)
                                {
                                    indirizzoUguale.Visible = true;
                                }
                                else
                                {
                                    indirizzoUguale.Visible = false;
                                }
                            }
                            else
                            {
                                indirizzoUguale.Visible = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            indirizzoUguale.Visible = false;
                        }
                        string    sql    = @"select * 
                        from Nazioni ORDER BY DescNazione";
                        DataTable codice = adoWeb.eseguiQuery(sql, CommandType.Text);
                        nazionalitaBambino.DataSource     = codice;
                        nazionalitaBambino.DataTextField  = "DescNazione";
                        nazionalitaBambino.DataValueField = "IdNazione";
                        nazionalitaBambino.DataBind();

                        sql    = @"select * 
                        from Province ORDER BY DescProvincia";
                        codice = adoWeb.eseguiQuery(sql, CommandType.Text);
                        provinciaBambino.DataSource     = codice;
                        provinciaBambino.DataTextField  = "DescProvincia";
                        provinciaBambino.DataValueField = "CodProvincia";
                        provinciaBambino.DataBind();
                        provinciaBambino.SelectedIndex = -1;

                        sql    = @"select *, descri + ' (' + prov + ')' AS text
                        from Citta ORDER BY descri";
                        codice = adoWeb.eseguiQuery(sql, CommandType.Text);
                        cittaNascitaBambino.DataSource     = codice;
                        cittaNascitaBambino.DataTextField  = "text";
                        cittaNascitaBambino.DataValueField = "IdCitta";
                        cittaNascitaBambino.DataBind();

                        sql = @"select * 
                        from Classi";
                        DataTable classi = adoWeb.eseguiQuery(sql, CommandType.Text);
                        foreach (DataRow dr in classi.Rows)
                        {
                            ListItem ls = new ListItem(dr.Field <int>("anno").ToString() + "° " + ((dr.Field <string>("ME") == "M") ? "Media" : "Elementare"), dr.Field <int>("id").ToString());
                            classeBambino.Items.Add(ls);
                        }
                    }
                    else
                    {
                        string    sql   = @"select * 
                        from Turni WHERE idCentro = " + Session["idCentro"];
                        DataTable turni = adoWeb.eseguiQuery(sql, CommandType.Text);
                        int       y     = 0;
                        idTurni = new int[turni.Rows.Count];
                        foreach (DataRow turno in turni.Rows)
                        {
                            TableRow  tr       = new TableRow();
                            TableCell tc       = new TableCell();
                            CheckBox  checkBox = new CheckBox();
                            checkBox.ID = turno["id"].ToString();
                            idTurni[y]  = (int)(turno["id"]);
                            y++;
                            checkBox.CheckedChanged += turnoEvent;
                            checkBox.AutoPostBack    = true;
                            tc.Controls.Add(checkBox);
                            tr.Cells.Add(tc);
                            tc      = new TableCell();
                            tc.Text = (Convert.ToDateTime(turno["dataInizio"].ToString())).ToShortDateString();
                            tr.Cells.Add(tc);
                            tc      = new TableCell();
                            tc.Text = (Convert.ToDateTime(turno["dataFine"].ToString())).ToShortDateString();
                            tr.Cells.Add(tc);
                            int colSpan = 2;
                            if (Convert.ToBoolean(turno["servizioMensa"].ToString()))
                            {
                                tc = new TableCell();
                                //tr.Cells.Add(tc);
                                //tc = new TableCell();
                                //tc.ColumnSpan = 2;
                                RadioButtonList radio = new RadioButtonList();
                                radio.ID       = "mensa" + turno["id"].ToString();
                                radio.Enabled  = false;
                                radio.CssClass = "table-borderless";
                                radio.Items.Add("Sì");
                                radio.Items.Add("No");
                                tc.Controls.Add(radio);
                                tr.Cells.Add(tc);
                                colSpan += 3;
                            }
                            tableTurni.Rows.Add(tr);
                            tr = new TableRow();
                            tr.Cells.Add(new TableCell());
                            tc            = new TableCell();
                            tc.ColumnSpan = colSpan;
                            CheckBoxList checkBoxList = new CheckBoxList();
                            checkBoxList.ID      = "settimane" + turno["id"].ToString();
                            checkBoxList.Enabled = false;
                            checkBoxList.Visible = false;

                            DateTime data = new DateTime();
                            data = Convert.ToDateTime(turno["dataInizio"]);
                            checkBoxList.CssClass = "table-borderless";

                            for (int i = 0; i < Convert.ToInt32(turno["numeroSettimane"].ToString()); i++)
                            {
                                checkBoxList.Items.Add("Settimana " + (i + 1) + ": " + data.ToShortDateString() + " - " + data.AddDays(7).ToShortDateString());
                                data = data.AddDays(7);
                            }
                            tc.Controls.Add(checkBoxList);
                            tr.Cells.Add(tc);
                            tableTurni.Rows.Add(tr);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Redirect("./DatiGenitori.aspx");
                }
                termineIscrizione.Enabled = false;

                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);
                            TableRow  tr = new TableRow();
                            TableCell tc = new TableCell();
                            tc.Text = newBambino.nome;
                            tr.Cells.Add(tc);
                            tc      = new TableCell();
                            tc.Text = newBambino.cognome;
                            tr.Cells.Add(tc);
                            tc      = new TableCell();
                            tc.Text = newBambino.dataNascita.ToShortDateString();
                            tr.Cells.Add(tc);
                            tc = new TableCell();
                            for (int p = 0; p < newBambino.turni.GetLength(0); p++)
                            {
                                if (Convert.ToInt32(newBambino.turni[p, 0]) != 0)
                                {
                                    string    sql            = @"select * 
                        from Turni WHERE id = " + newBambino.turni[p, 0];
                                    DataTable dettaglioTurno = adoWeb.eseguiQuery(sql, CommandType.Text);
                                    tc.Text += " ♦ Turno " + dettaglioTurno.Rows[0].Field <int>("numero").ToString() + ": " + dettaglioTurno.Rows[0].Field <DateTime>("dataInizio").ToShortDateString() + " - " + dettaglioTurno.Rows[0].Field <DateTime>("dataFine").ToShortDateString() + " ";
                                    if (Convert.ToBoolean(dettaglioTurno.Rows[0].Field <bool>("servizioMensa")))
                                    {
                                        tc.Text += "- Mensa: " + (Convert.ToInt32(newBambino.turni[p, 1]) == 1 ? "Sì" : "No");
                                    }
                                    tc.Text += "<br/>";
                                }
                            }
                            tr.Cells.Add(tc);
                            tc = new TableCell();
                            Button btn = new Button();
                            btn.CssClass = "btn btn-circle btn-danger";
                            Label lbl = new Label();
                            lbl.CssClass = "fas fa-trash";
                            btn.Controls.Add(lbl);
                            btn.Click += EliminaBambino_click;
                            btn.ID     = "bambino" + k;
                            tc.Controls.Add(btn);
                            tr.Cells.Add(tc);
                            tableDettagli.Rows.Add(tr);
                            termineIscrizione.Enabled = true;
                        }
                    }
                    catch (Exception ex) { }
                }
            }
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["type"] == "0")
                {
                    //Aggiungi
                    Page.Title               = "Aggiungi Animatore";
                    salvaAnimatore.Text      = "Aggiungi";
                    annullaAnimatore.Visible = true;
                }
                else if (Request.Params["type"] == "1")
                {
                    //Modifica
                    Page.Title               = "Modifica Animatore";
                    salvaAnimatore.Text      = "Modifica";
                    annullaAnimatore.Visible = true;
                }
                else if (Request.Params["type"] == "2")
                {
                    //Visualizza
                    Page.Title = "Visualizza Animatore";
                    annullaAnimatore.Visible = false;
                    salvaAnimatore.Text      = "Chiudi";
                }
                else
                {
                    //ERRORE: Redirect to pagina precedente
                    Response.Redirect(Request.UrlReferrer.ToString());
                }


                string    sql    = @"select * 
                        from Province ORDER BY DescProvincia";
                adoNet    adoWeb = new adoNet();
                DataTable codice = adoWeb.eseguiQuery(sql, CommandType.Text);
                provinciaAnimatore.DataSource     = codice;
                provinciaAnimatore.DataTextField  = "DescProvincia";
                provinciaAnimatore.DataValueField = "CodProvincia";
                provinciaAnimatore.DataBind();
                provinciaAnimatore.SelectedIndex = -1;

                sql    = @"select * 
                        from Citta ORDER BY descri";
                adoWeb = new adoNet();
                codice = adoWeb.eseguiQuery(sql, CommandType.Text);
                cittaNascitaAnimatore.DataSource     = codice;
                cittaNascitaAnimatore.DataTextField  = "descri";
                cittaNascitaAnimatore.DataValueField = "IdCitta";
                cittaNascitaAnimatore.DataBind();
                cittaNascitaAnimatore.SelectedIndex = -1;

                sql    = @"select * 
                        from Nazioni ORDER BY DescNazione";
                adoWeb = new adoNet();
                codice = adoWeb.eseguiQuery(sql, CommandType.Text);
                nazionalitaAnimatore.DataSource     = codice;
                nazionalitaAnimatore.DataTextField  = "DescNazione";
                nazionalitaAnimatore.DataValueField = "IdNazione";
                nazionalitaAnimatore.DataBind();
                nazionalitaAnimatore.SelectedIndex = -1;
            }
        }
        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);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Response.Redirect("../../Login.aspx");
            }
            else
            {
                adoNet adoWeb = new adoNet();
                try
                {
                    if (Request.Cookies["genitore1"].Value == null)
                    {
                        Response.Redirect("./DatiGenitori.aspx");
                    }
                    else
                    if (!IsPostBack)
                    {
                        adoNet.impostaConnessione();

                        TableRow  tr = new TableRow();
                        TableCell tc = new TableCell();

                        // 0 - idTurno; 1 - nBambini; 2 - settimane; 3 - fuoriComune
                        int[,] v = new int[20, 3];

                        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);
                                    tr      = new TableRow();
                                    tc      = new TableCell();
                                    tc.Text = newBambino.nome;
                                    tr.Cells.Add(tc);
                                    tc      = new TableCell();
                                    tc.Text = newBambino.cognome;
                                    tr.Cells.Add(tc);
                                    tc      = new TableCell();
                                    tc.Text = newBambino.dataNascita.ToShortDateString();
                                    tr.Cells.Add(tc);
                                    tc = new TableCell();
                                    for (int p = 0; p < newBambino.turni.GetLength(0); p++)
                                    {
                                        if (Convert.ToInt32(newBambino.turni[p, 0]) != 0)
                                        {
                                            string    sql            = @"select * 
                                                            from Turni WHERE id = " + newBambino.turni[p, 0];
                                            DataTable dettaglioTurno = adoWeb.eseguiQuery(sql, CommandType.Text);
                                            tc.Text += " ♦ Turno " + dettaglioTurno.Rows[0].Field <int>("numero").ToString() + ": " + dettaglioTurno.Rows[0].Field <DateTime>("dataInizio").ToShortDateString() + " - " + dettaglioTurno.Rows[0].Field <DateTime>("dataFine").ToShortDateString() + " ";
                                            if (Convert.ToBoolean(dettaglioTurno.Rows[0].Field <bool>("servizioMensa")))
                                            {
                                                tc.Text += "- Mensa: " + (Convert.ToInt32(newBambino.turni[p, 1]) == 1 ? "Sì" : "No");
                                            }
                                            tc.Text += "<br/>";
                                        }
                                    }
                                    tr.Cells.Add(tc);
                                    tableDettagli.Rows.Add(tr);

                                    for (int p = 0; p < newBambino.turni.GetLength(0); p++)
                                    {
                                        if (Convert.ToInt32(newBambino.turni[p, 0]) != 0)
                                        {
                                            for (int o = 0; o < v.GetLength(0); o++)
                                            {
                                                if (v[o, 0] == Convert.ToInt32(newBambino.turni[p, 0]) &&
                                                    v[o, 2] == calcoloSettimane(newBambino.turni, p) &&
                                                    v[o, 3] == verificaComune(newBambino, p))
                                                {
                                                    v[o, 1]++;
                                                    break;
                                                }
                                                else
                                                {
                                                    for (int t = 0; t < v.GetLength(0); t++)
                                                    {
                                                        if (v[t, 0] == 0)
                                                        {
                                                            v[t, 0] = Convert.ToInt32(newBambino.turni[p, 0]);
                                                            v[t, 1] = 1;
                                                            v[t, 2] = calcoloSettimane(newBambino.turni, p);
                                                            v[t, 3] = verificaComune(newBambino, p);
                                                            break;
                                                        }
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception ex) { }
                        }


                        decimal totale = 0;

                        for (int o = 0; o < v.GetLength(0); o++)
                        {
                            if (v[o, 0] != 0)
                            {
                                tr = new TableRow();
                                tc = new TableCell();
                                string    sql            = @"select * 
                        from Turni WHERE id = " + v[o, 0];
                                DataTable dettaglioTurno = adoWeb.eseguiQuery(sql, CommandType.Text);
                                tc.Text += dettaglioTurno.Rows[0].Field <int>("numero").ToString() + "° Turno: " + dettaglioTurno.Rows[0].Field <DateTime>("dataInizio").ToShortDateString() + " - " + dettaglioTurno.Rows[0].Field <DateTime>("dataFine").ToShortDateString() + " ";
                                tr.Cells.Add(tc);
                                tc      = new TableCell();
                                tc.Text = v[o, 1].ToString();
                                tr.Cells.Add(tc);
                                tc      = new TableCell();
                                tc.Text = v[o, 2].ToString();
                                tr.Cells.Add(tc);
                                tc = new TableCell();
                                if (v[o, 2] <= dettaglioTurno.Rows[0].Field <int>("p1"))
                                {
                                    if (v[o, 1] < 3)
                                    {
                                        tc.Text = dettaglioTurno.Rows[0].Field <decimal>("p1quotaBamb" + v[o, 1]).ToString("F") + " €";
                                        totale += dettaglioTurno.Rows[0].Field <decimal>("p1quotaBamb" + v[o, 1]);
                                    }
                                    else
                                    {
                                        decimal calc = dettaglioTurno.Rows[0].Field <decimal>("p1quotaBamb3");
                                        for (int y = 3; y <= v[o, 1]; y++)
                                        {
                                            calc += dettaglioTurno.Rows[0].Field <decimal>("p1quotaBamb1");
                                        }
                                        tc.Text = calc.ToString("F") + " €";
                                        totale += calc;
                                    }
                                }
                                else
                                {
                                    if (v[o, 1] < 3)
                                    {
                                        tc.Text = dettaglioTurno.Rows[0].Field <decimal>("p2quotaBamb" + v[o, 1]).ToString("F") + " €";
                                        totale += dettaglioTurno.Rows[0].Field <decimal>("p2quotaBamb" + v[o, 1]);
                                    }
                                    else
                                    {
                                        decimal calc = dettaglioTurno.Rows[0].Field <decimal>("p2quotaBamb3");
                                        for (int y = 3; y <= v[o, 1]; y++)
                                        {
                                            calc += dettaglioTurno.Rows[0].Field <decimal>("p2quotaBamb1");
                                        }
                                        tc.Text = calc.ToString("F") + " €";
                                        totale += calc;
                                    }
                                }
                                if (v[o, 3] == 1)
                                {
                                    tc.Text += "<br/>   + " + (dettaglioTurno.Rows[0].Field <decimal>("quotaFuoriComune") * v[o, 1]).ToString("F") + " €";
                                    totale  += dettaglioTurno.Rows[0].Field <decimal>("quotaFuoriComune") * v[o, 1];
                                }
                                tr.Cells.Add(tc);
                                tablePagamento.Rows.Add(tr);
                            }
                        }
                        tr                 = new TableRow();
                        tc                 = new TableCell();
                        tc.ColumnSpan      = 3;
                        tc.Text            = "TOTALE:";
                        tc.Font.Bold       = true;
                        tc.HorizontalAlign = HorizontalAlign.Right;
                        tr.Cells.Add(tc);
                        tc           = new TableCell();
                        tc.Font.Bold = true;
                        tc.ID        = "totDaPagare";
                        tc.Text      = totale.ToString("F") + " €";
                        tr.Cells.Add(tc);
                        Response.Cookies["totDaPagare"].Value   = totale.ToString("F");
                        Response.Cookies["totDaPagare"].Expires = DateTime.Now.AddMinutes(30);
                        tablePagamento.Rows.Add(tr);
                    }
                    else
                    {
                    }
                }
                catch (Exception ex)
                {
                    Response.Redirect("./DatiGenitori.aspx");
                }
            }
        }