private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Length == 0 ||
         textBox2.Text.Length == 0 ||
         textBox3.Text.Length == 0 ||
         textBox4.Text.Length == 0 ||
         textBox5.Text.Length == 0)
     {
         MessageBox.Show("Please enter data.");
         return;
     }
     using (var ctx = new ContactContext())
     {
         var contact = new Contact(textBox1.Text,
                                   textBox2.Text,
                                   textBox3.Text,
                                   textBox4.Text,
                                   textBox5.Text);
         try
         {
             ctx.Contacts.Add(contact);
             GoogleSync gs = new GoogleSync();
             gs.Login();
             gs.CreateContact(contact);
             gs.WriteContactsToDatabase();
             ctx.SaveChanges();
         }catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     this.Close();
 }
Beispiel #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            //Login
            List <Contact> list;

            GoogleSync gs = new GoogleSync();

            gs.Login();
            using (var ctx = new ContactContext())
            {
                list = ctx.Contacts.ToList();
                foreach (var item in list)
                {
                    if (gs.Contacts == null)
                    {
                        return;
                    }
                    bool found = false;
                    for (int i = 0; i < gs.Contacts.Count; i++)
                    {
                        if (item.IsMatch(gs.Contacts[i]))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        gs.CreateContact(item);
                    }
                }
            }
            gs.GetContactsFromGoogle();
            gs.WriteContactsToDatabase();
            UpdateTable();
        }
Beispiel #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please select a row to delete.");
                return;
            }
            using (var ctx = new ContactContext())
            {
                var contact = new Contact()
                {
                    ContactId   = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()),
                    FirstName   = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(),
                    LastName    = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(),
                    CompanyName = dataGridView1.SelectedRows[0].Cells[3].Value.ToString(),
                    JobTitle    = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(),
                    PhoneNumber = dataGridView1.SelectedRows[0].Cells[5].Value.ToString()
                };

                ctx.Contacts.Attach(contact);
                ctx.Contacts.Remove(contact);

                GoogleSync gs = new GoogleSync();
                gs.Login();
                foreach (Google.Contacts.Contact c in gs.Contacts)
                {
                    if (contact.IsMatch(c))
                    {
                        gs.DeleteContact(c);
                        break;
                    }
                }
                ctx.SaveChanges();
                UpdateTable();
            }
        }