Esempio n. 1
0
        public void BtnTelefonClick(string btName)
        {
            telefon t = new telefon();

            switch (btName)
            {
            case "addTelefon":
                t.telefon1   = telefonTelefon1;
                t.tipus      = telefonTipus;
                t.contacteId = SelectedContacte.contacteId;

                db.telefons.Add(t);
                db.SaveChanges();

                if (TableChoice.Equals("Telefons"))
                {
                    telefonsPopulate();
                }
                else
                {
                    telefonsContacte();
                }
                break;

            case "removeTelefon":
                t = db.telefons.Find(SelectedTelefon.telId);

                db.telefons.Remove(t);
                db.SaveChanges();

                if (TableChoice.Equals("Telefons"))
                {
                    telefonsPopulate();
                }
                else
                {
                    telefonsContacte();
                }
                break;

            case "modifyTelefon":
                t = db.telefons.Find(SelectedTelefon.telId);

                t.telefon1 = telefonTelefon1;
                t.tipus    = telefonTipus;

                db.SaveChanges();

                if (TableChoice.Equals("Telefons"))
                {
                    telefonsPopulate();
                }
                else
                {
                    telefonsContacte();
                }
                break;

            default:
                Console.WriteLine("Error");
                break;
            }
        }
Esempio n. 2
0
        public void BtnContacteClick(string btName)
        {
            contacte c = new contacte();

            switch (btName)
            {
            case "addContacte":
                c.nom     = contacteNom;
                c.cognoms = contacteCognoms;
                db.contactes.Add(c);
                db.SaveChanges();
                TableChoice = "Contacts";
                break;

            case "removeContacte":
                OnNewModalDialog();
                if (Ok == 1)
                {
                    foreach (contacte co in contactes.Where(x => x.IsSelected))
                    {
                        foreach (telefon t in db.telefons.Where(x => x.contacteId == co.contacteId))
                        {
                            db.telefons.Remove(t);
                        }
                        foreach (email e in db.emails.Where(x => x.contacteId == co.contacteId))
                        {
                            db.emails.Remove(e);
                        }

                        db.contactes.Remove(co);
                    }

                    multipleSel = false;

                    db.SaveChanges();

                    if (TableChoice.Equals("Telefons"))
                    {
                        telefonsPopulate();
                    }
                    else if (TableChoice.Equals("Emails"))
                    {
                        emailsPopulate();
                    }
                    else
                    {
                        contactesPopulate();
                    }
                }
                break;

            case "modifyContacte":
                OnNewModalDialog();
                if (Ok == 1)
                {
                    c         = db.contactes.Find(SelectedContacte.contacteId);
                    c.nom     = contacteNom;
                    c.cognoms = contacteCognoms;
                    db.SaveChanges();
                    if (TableChoice.Equals("Telefons"))
                    {
                        contacteTelefons();
                    }
                    else if (TableChoice.Equals("Emails"))
                    {
                        contacteEmails();
                    }
                    else
                    {
                        contactesPopulate();
                    }
                }
                break;

            case "duplicateContacte":
                foreach (contacte co in contactes.Where(x => x.IsSelected))
                {
                    contacte c0 = new contacte();

                    c0.nom     = co.nom;
                    c0.cognoms = co.cognoms;

                    foreach (email e in co.emails)
                    {
                        email email0 = new email();
                        email0.email1 = e.email1;
                        email0.tipus  = e.tipus;
                        c0.emails.Add(email0);
                    }

                    foreach (telefon t in co.telefons)
                    {
                        telefon telefon0 = new telefon();
                        telefon0.telefon1 = t.telefon1;
                        telefon0.tipus    = t.tipus;
                        c0.telefons.Add(telefon0);
                    }

                    db.contactes.Add(c0);
                }

                multipleSel = false;

                db.SaveChanges();
                TableChoice = "Contacts";
                break;

            default:
                Console.WriteLine("Error");
                break;
            }
        }
Esempio n. 3
0
        public void BtnEmailClick(string btName)
        {
            email e = new email();

            switch (btName)
            {
            case "addEmail":
                e.email1     = emailEmail1;
                e.tipus      = emailTipus;
                e.contacteId = SelectedContacte.contacteId;

                db.emails.Add(e);
                db.SaveChanges();

                if (TableChoice.Equals("Emails"))
                {
                    emailsPopulate();
                }
                else
                {
                    emailsContacte();
                }
                break;

            case "removeEmail":
                e = db.emails.Find(SelectedEmail.emailId);

                db.emails.Remove(e);
                db.SaveChanges();

                if (TableChoice.Equals("Emails"))
                {
                    emailsPopulate();
                }
                else
                {
                    emailsContacte();
                }
                break;

            case "modifyEmail":
                e = db.emails.Find(SelectedEmail.emailId);

                e.email1 = emailEmail1;
                e.tipus  = emailTipus;

                db.SaveChanges();

                if (TableChoice.Equals("Emails"))
                {
                    emailsPopulate();
                }
                else
                {
                    emailsContacte();
                }
                break;

            default:
                Console.WriteLine("Error");
                break;
            }
        }