Ejemplo n.º 1
0
        public VisualizzaAmici(string email)
        {
            InitializeComponent();
            this.email = email;
            SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
            var friends1 = from a in db.AMICIZIEs join u in db.UTENTIs on a.emailUtente2 equals u.email
                           where a.emailUtente1 == this.email && a.dataFine == null
                           select new { u.nome, u.cognome, u.email };
            var friends2 = from a in db.AMICIZIEs
                           join u in db.UTENTIs on a.emailUtente1 equals u.email
                           where a.emailUtente2 == this.email && a.dataFine == null
                           select new { u.nome, u.cognome, u.email };

            foreach (var userInfo in friends1)
            {
                listBoxNome.Items.Add(userInfo.nome);
                listBoxCognome.Items.Add(userInfo.cognome);
                listBoxEmail.Items.Add(userInfo.email);
            }
            ;
            foreach (var userInfo in friends2)
            {
                listBoxNome.Items.Add(userInfo.nome);
                listBoxCognome.Items.Add(userInfo.cognome);
                listBoxEmail.Items.Add(userInfo.email);
            }
            ;
        }
        private void btnCrea_Click(object sender, EventArgs e)
        {
            SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
            var sezione = from s in db.SEZIONIs
                          where s.nome == txtNomeSezione.Text
                          select s;

            if (sezione.Count() != 0)
            {
                MessageBox.Show("Questo nome di sezione è già utilizzato!", "Errore sezione",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtNomeSezione.Text == "")
            {
                MessageBox.Show("La sezione deve avere un nome!", "Errore sezione",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtDescrizione.Text == "")
            {
                MessageBox.Show("Devi scegliere una descrizione!", "Errore descrizione",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                SEZIONI newSection = new SEZIONI
                {
                    nome          = txtNomeSezione.Text,
                    descrizione   = txtDescrizione.Text,
                    dataCreazione = DateTime.Now,
                    emailUtente   = this.email
                };
                if (!imageLocation.Equals(""))
                {
                    byte[]       bytesImage = null;
                    FileStream   Stream     = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
                    BinaryReader brs        = new BinaryReader(Stream);
                    bytesImage          = brs.ReadBytes((int)Stream.Length);
                    newSection.immagine = bytesImage;
                }
                db.SEZIONIs.InsertOnSubmit(newSection);
                try
                {
                    db.SubmitChanges();
                    txtNomeSezione.Text      = "";
                    txtDescrizione.Text      = "";
                    imageLocation            = "";
                    pictureBox.ImageLocation = "";
                    MessageBox.Show("Sezione creata con successo!", "Successo creazione sezione",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1);
                    MessageBox.Show("C'è stato qualche errore con la crezione della sessione!", "Errore creazione sessione",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 public VisualizzaProdottiComprati(string email)
 {
     InitializeComponent();
     this.email = email;
     SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
     var prodotti = from p in db.PRODOTTIs
                    where p.emailUtenteAcquisto == this.email
                    select new { p.emailUtenteVendita, p.nomeSezione, p.nomeCategoria, p.dataAcquisto, p.descrizione, p.prezzo };
     dataGridView.DataSource = prodotti;
 }
Ejemplo n.º 4
0
        public VisualizzaTuttiUtenti(string email)
        {
            InitializeComponent();
            this.email = email;
            SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
            var users = from u in db.UTENTIs
                        select u;

            dataGridView.DataSource = users;
        }
        private void btnCrea_Click(object sender, EventArgs e)
        {
            SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
            var categoria = from c in db.CATEGORIEs
                            where c.nome == txtNomeCategoria.Text
                            select c;

            if (categoria.Count() != 0)
            {
                MessageBox.Show("Questo nome di categoria è già utilizzato!", "Errore sezione",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtNomeCategoria.Text == "")
            {
                MessageBox.Show("La categoria deve avere un nome!", "Errore sezione",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtDescrizione.Text == "")
            {
                MessageBox.Show("Devi scegliere una descrizione!", "Errore descrizione",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                CATEGORIE newCategory = new CATEGORIE
                {
                    nome        = txtNomeCategoria.Text,
                    descrizione = txtDescrizione.Text,
                    emailUtente = this.email
                };
                db.CATEGORIEs.InsertOnSubmit(newCategory);
                try
                {
                    db.SubmitChanges();
                    txtNomeCategoria.Text = "";
                    txtDescrizione.Text   = "";
                    MessageBox.Show("Categoria creata con successo!", "Successo creazione categoria",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1);
                    MessageBox.Show("C'è stato qualche errore con la crezione della categoria!", "Errore creazione categoria",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 6
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
            var query = from u in db.UTENTIs
                        where u.email == txtEmail.Text && u.password == txtPassword.Text
                        select u.email;
            Boolean loginOk = query.Count() == 1 ? true : false;

            if (loginOk)
            {
                this.email = query.First();
                openForm("home");
            }
            else
            {
                MessageBox.Show("Email o password errati!", "Errore login",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 7
0
        private void btnInvia_Click(object sender, EventArgs e)
        {
            SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
            var friends = from a in db.AMICIZIEs
                          where (a.emailUtente1 == this.email && a.emailUtente2 == txtEmailUtente.Text) ||
                          (a.emailUtente1 == txtEmailUtente.Text && a.emailUtente2 == this.email)
                          select a;
            var r1 = from r in db.RICHIESTE_AMICIZIEs
                     where r.emailMittente == this.email && r.emailDestinatario == txtEmailUtente.Text && r.dataRisposta == null
                     select r;
            var r2 = from r in db.RICHIESTE_AMICIZIEs
                     where r.emailMittente == txtEmailUtente.Text && r.emailDestinatario == this.email && r.dataRisposta == null
                     select r;
            var searchUser = from u in db.UTENTIs
                             where u.email == txtEmailUtente.Text
                             select u;

            if (txtEmailUtente.Text == "")
            {
                MessageBox.Show("Devi inserire la email di un utente!", "Errore email utente",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (friends.Count() != 0)
            {
                MessageBox.Show("Sei già amico con questo utente!", "Errore richiesta amicizia",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (r1.Count() != 0)
            {
                MessageBox.Show("Hai già inviato la richiesta di amicizia a questo utente!", "Errore richiesta amicizia",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (r2.Count() != 0)
            {
                MessageBox.Show(txtEmailUtente.Text + " ti ha già inviato la richiesta di amicizia!", "Errore richiesta amicizia",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (searchUser.Count() == 0)
            {
                MessageBox.Show(txtEmailUtente.Text + " non trovata!", "Errore ricerca email",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                RICHIESTE_AMICIZIE newFriendRequest = new RICHIESTE_AMICIZIE
                {
                    emailMittente     = this.email,
                    emailDestinatario = txtEmailUtente.Text,
                    dataRichiesta     = DateTime.Now,
                    timeRichiesta     = DateTime.Now.TimeOfDay
                };
                db.RICHIESTE_AMICIZIEs.InsertOnSubmit(newFriendRequest);
                try
                {
                    db.SubmitChanges();
                    txtEmailUtente.Text = "";
                    MessageBox.Show("Richiesta amicizia inviata con successo!", "Successo invio richiesta amicizia",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1);
                    MessageBox.Show("C'è stato qualche errore con l'invio della richiesta di amicizia!",
                                    "Errore invio richiesta amicizia", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 8
0
        private void btnIscriviti_Click(object sender, EventArgs e)
        {
            SocialNetworkVenditeDbDataContext db = new SocialNetworkVenditeDbDataContext();
            long telephoneNumber;
            var  query = from u in db.UTENTIs
                         where u.email == txtEmail.Text
                         select u.email;
            Boolean emailOk = query.Count() == 0 ? true: false;

            if (!emailOk)
            {
                MessageBox.Show("La seguente email: " + txtEmail + "è già presente!", "Email esistente",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtNumeroTelefono.Text.Length != 10)
            {
                MessageBox.Show("Il numero di telefono deve essere composto da 10 numeri", "Numero di telefono errato",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!long.TryParse(txtNumeroTelefono.Text, out telephoneNumber))
            {
                MessageBox.Show("Il numero di telefono deve essere composto da soli numeri!", "Numero di telefono errato",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtEmail.Text == "" || txtPassword.Text == "" || txtNome.Text == "" || txtCognome.Text == "" ||
                     txtLuogoNascita.Text == "" || txtVia.Text == "" || txtCitta.Text == "" || cmbbxSesso.Text == "" ||
                     cmbbxDataGiorno.Text == "" || cmbbxDataMese.Text == "" || cmbbxDataAnno.Text == "" ||
                     cmbbxNumeroCivico.Text == "" || cmbbxAmministratore.Text == "")
            {
                MessageBox.Show("Ci sono uno o più campi non compilati!", "Campo/i non compilato/i",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ((cmbbxDataMese.Text == "4" || cmbbxDataMese.Text == "6" || cmbbxDataMese.Text == "9" || cmbbxDataMese.Text == "11") && cmbbxDataGiorno.Text == "31")
            {
                MessageBox.Show("Il giorno di nascita non può essere 31!", "Data Errata",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (cmbbxDataMese.Text == "2" && (cmbbxDataGiorno.Text == "29" || cmbbxDataGiorno.Text == "30" || cmbbxDataGiorno.Text == "31"))
            {
                MessageBox.Show("Il giorno di nascita non può essere maggiore di 28!", "Data Errata",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                UTENTI newUser;
                newUser = new UTENTI
                {
                    email                 = txtEmail.Text,
                    password              = txtPassword.Text,
                    nome                  = txtNome.Text,
                    cognome               = txtCognome.Text,
                    sesso                 = cmbbxSesso.Text.Equals("Maschio") ? "M" : "F",
                    dataNascita           = new DateTime(Int32.Parse(cmbbxDataAnno.Text), Int32.Parse(cmbbxDataMese.Text), Int32.Parse(cmbbxDataGiorno.Text)),
                    luogoNascita          = txtLuogoNascita.Text,
                    viaResidenza          = txtVia.Text,
                    numeroCivicoResidenza = Int16.Parse(cmbbxNumeroCivico.Text),
                    cittaResidenza        = txtCitta.Text,
                    numeroTelefono        = txtNumeroTelefono.Text,
                    amministratore        = cmbbxAmministratore.Text.Equals("True") ? true : false
                };
                if (!imageLocation.Equals(""))
                {
                    byte[]       bytesImage = null;
                    FileStream   Stream     = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
                    BinaryReader brs        = new BinaryReader(Stream);
                    bytesImage       = brs.ReadBytes((int)Stream.Length);
                    newUser.immagine = bytesImage;
                }
                db.UTENTIs.InsertOnSubmit(newUser);
                try
                {
                    db.SubmitChanges();
                    txtEmail.Text            = "";
                    txtPassword.Text         = "";
                    txtNome.Text             = "";
                    txtCognome.Text          = "";
                    cmbbxSesso.Text          = "";
                    cmbbxDataGiorno.Text     = "";
                    cmbbxDataMese.Text       = "";
                    cmbbxDataAnno.Text       = "";
                    txtLuogoNascita.Text     = "";
                    txtVia.Text              = "";
                    cmbbxNumeroCivico.Text   = "";
                    txtCitta.Text            = "";
                    txtNumeroTelefono.Text   = "";
                    cmbbxAmministratore.Text = "";
                    imageLocation            = "";
                    pictureBox.ImageLocation = "";
                    MessageBox.Show("Iscrizione avvenuta con successo!", "Successo iscrizione",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    returnLogin();
                }  catch (Exception e1) {
                    Console.WriteLine(e1);
                    MessageBox.Show("C'è stato qualche errore con l'iscrizione!", "Errore iscrizione",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }