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 salvaDatiGenitore_Click(object sender, EventArgs e) { Page.Validate(); if (Page.IsValid) { Genitore genitore1 = new Genitore(); genitore1.nome = nomeGenitore1.Text; genitore1.cognome = cognomeGenitore1.Text; genitore1.sesso = Convert.ToChar(sessoGenitore1.SelectedValue); genitore1.indirizzo = indirizzoGenitore1.Text; genitore1.numeroCivico = numeroCivicoGenitore1.Text; genitore1.provincia = provinciaGenitore1.SelectedValue; genitore1.citta = Convert.ToInt32(cittaGenitore1.SelectedValue); genitore1.cellulare[0, 0] = cellulare1Genitore1.Text; genitore1.cellulare[0, 1] = DescrCellulare1Genitore1.Text; if (cellulare2Genitore1.Text != String.Empty) { genitore1.cellulare[1, 0] = cellulare2Genitore1.Text; genitore1.cellulare[1, 1] = DescrCellulare2Genitore1.Text; } if (cellulare3Genitore1.Text != String.Empty) { genitore1.cellulare[2, 0] = cellulare3Genitore1.Text; genitore1.cellulare[2, 1] = DescrCellulare3Genitore1.Text; } genitore1.email = emailGenitore1.Text; Response.Cookies["genitore1"].Value = genitore1.writeCookie(); Response.Cookies["genitore1"].Expires = DateTime.Now.AddMinutes(30); if (datiGenitore2.Checked) { Genitore genitore2 = new Genitore(); genitore2.nome = nomeGenitore2.Text; genitore2.cognome = cognomeGenitore2.Text; genitore2.sesso = Convert.ToChar(sessoGenitore2.SelectedValue); genitore2.indirizzo = indirizzoGenitore2.Text; genitore2.numeroCivico = numeroCivicoGenitore2.Text; genitore2.provincia = provinciaGenitore2.SelectedValue; genitore2.citta = Convert.ToInt32(cittaGenitore2.SelectedValue); genitore2.cellulare[0, 0] = cellulare1Genitore2.Text; genitore2.cellulare[0, 1] = DescrCellulare1Genitore2.Text; if (cellulare2Genitore2.Text != String.Empty) { genitore2.cellulare[1, 0] = cellulare2Genitore2.Text; genitore2.cellulare[1, 1] = DescrCellulare2Genitore2.Text; } if (cellulare3Genitore2.Text != String.Empty) { genitore2.cellulare[2, 0] = cellulare3Genitore2.Text; genitore2.cellulare[2, 1] = DescrCellulare3Genitore2.Text; } genitore2.email = emailGenitore2.Text; Response.Cookies["genitore2"].Value = genitore2.writeCookie(); Response.Cookies["genitore2"].Expires = DateTime.Now.AddMinutes(30); } Response.Redirect("./DatiBambini.aspx"); } }
protected void sameIndirizzoGenitori_CheckedChanged(object sender, EventArgs e) { if (sameIndirizzoGenitori.Checked) { Genitore genitore = new Genitore(Request.Cookies["genitore1"].Value); indirizzoBambino.Text = genitore.indirizzo; numeroCivicoBambino.Text = genitore.numeroCivico; provinciaBambino.SelectedValue = genitore.provincia; cittaBambino.SelectedValue = genitore.citta.ToString(); } }
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) { } } } }
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); }