Exemple #1
0
        private void NewBtn_Click(object sender, RoutedEventArgs e)
        {
            Abonent  abonent = new Abonent();
            Address  ad      = new Address();
            Category cat     = new Category();

            Company company = new Company();

            try {
                if (tb.SelectedItem == abonentos)
                {
                    ad.address1 = textBox8.Text;

                    abonent.surname    = textBox1.Text;
                    abonent.name       = textBox2.Text;
                    abonent.otchestvo  = otchestvo.Text;
                    abonent.Id_address = ad.Id_address;
                    abonent.phone      = tel.Text;
                    ad.address1        = textBox8.Text;
                    abonent.surname    = textBox1.Text;
                    abonent.name       = textBox2.Text;
                    abonent.otchestvo  = otchestvo.Text;
                    abonent.Id_address = ad.Id_address;



                    ad.Id_category = (cmboxcity.SelectedValue as Category).Id_category;
                    db.Address.Add(ad);
                    db.Abonent.Add(abonent);

                    db.SaveChanges();
                }
                else if (tb.SelectedItem == pred)
                {
                    ad.address1 = textBox8.Text;

                    company.name_company = textBox1pred.Text;
                    company.department   = textBox2preddep.Text;
                    company.Id_address   = ad.Id_address;
                    company.phone        = textBox2pred.Text;
                    ad.address1          = textBox8pred.Text;

                    company.Id_address = ad.Id_address;



                    ad.Id_category = (cmboxcitypred.SelectedValue as Category).Id_category;
                    db.Address.Add(ad);
                    db.Company.Add(company);

                    db.SaveChanges();
                }



                MessageBox.Show("Новый объект добавлен");
            }
            catch { }
        }
Exemple #2
0
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (tb.SelectedItem == abonentos)
                {
                    if (dataGrid1.SelectedItems.Count > 0)
                    {
                        for (int i = 0; i < dataGrid1.SelectedItems.Count; i++)
                        {
                            Abonent abonent = dataGrid1.SelectedItems[i] as Abonent;

                            if (abonent != null)
                            {
                                db.Abonent.Remove(abonent);
                            }
                        }
                    }

                    db.SaveChanges();
                }
                else if (tb.SelectedItem == pred)
                {
                }

                if (dataGrid1pred.SelectedItems.Count > 0)
                {
                    for (int i = 0; i < dataGrid1pred.SelectedItems.Count; i++)
                    {
                        Company company = dataGrid1pred.SelectedItems[i] as Company;

                        if (company != null)
                        {
                            db.Company.Remove(company);
                        }
                    }
                }

                db.SaveChanges();
            }

            catch { }
        }