Пример #1
0
        private void ButtonEdit_Click(object sender, RoutedEventArgs e)
        {
            object item = DatagridList.SelectedItem;

            if (item == null)
            {
                return;
            }
            int id = Convert.ToInt32((DatagridList.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text);

            try
            {
                using (PhonebookContext context = new PhonebookContext())
                {
                    Table person = context.Tables.FirstOrDefault(x => x.Id == id);
                    if (person == null)
                    {
                        return;
                    }
                    ID = person.Id;
                    WindowEdit winEdit = new WindowEdit();
                    winEdit.ShowDialog();
                    ReadPhoneBook();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error message: " + exc);
            }
        }
Пример #2
0
        private void ReadPhoneBook()
        {
            DatagridList.ItemsSource = null;
            DatagridList.Items.Clear();
            DatagridList.Items.Refresh();
            Table.Persons.Clear();
            PhonebookContext context = new PhonebookContext();

            context.Tables.Load();
            foreach (Table table in from Table person in context.Tables.ToList()
                     let table = new Table
            {
                Id = person.Id,
                Name = person.Name,
                Phone = person.Phone,
                Mobile = person.Mobile,
                Email = person.Email,
                Address = person.Address
            }
                     select table)
            {
                Table.Persons.Add(table);
            }
            DatagridList.ItemsSource = Table.Persons.ToList();
        }
Пример #3
0
        private void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var contex = new PhonebookContext())
                {
                    Table table = new Table()
                    {
                        Name    = TextBoxName.Text,
                        Phone   = TextBoxPhone.Text,
                        Mobile  = TextBoxMobile.Text,
                        Email   = TextBoxEmail.Text,
                        Address = TextBoxAddress.Text
                    };
                    contex.Tables.Add(table);
                    contex.SaveChanges();
                    Table.Persons.Add(table);

                    this.Close();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error message: " + exc);
            }
        }
Пример #4
0
        public WindowEdit()
        {
            InitializeComponent();

            try
            {
                using (PhonebookContext context = new PhonebookContext())
                {
                    Table person = new Table();
                    person = context.Tables.FirstOrDefault(x => x.Id == MainWindow.ID);
                    if (person == null)
                    {
                        this.Close();
                    }
                    TextBoxName.Text    = person.Name;
                    TextBoxPhone.Text   = person.Phone;
                    TextBoxMobile.Text  = person.Mobile;
                    TextBoxEmail.Text   = person.Email;
                    TextBoxAddress.Text = person.Address;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error message: " + exc);
            }
        }
Пример #5
0
        private void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var contex = new PhonebookContext())
                {
                    Table table = (from t in contex.Tables where t.Id == MainWindow.ID select t).First();

                    table.Name    = TextBoxName.Text;
                    table.Phone   = TextBoxPhone.Text;
                    table.Mobile  = TextBoxMobile.Text;
                    table.Email   = TextBoxEmail.Text;
                    table.Address = TextBoxAddress.Text;
                    contex.SaveChanges();

                    this.Close();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error message: " + exc);
            }
        }