Ejemplo n.º 1
0
        private void Button_save_Click(object sender, RoutedEventArgs e)
        {
            PhoneBookContext phoneBook = new PhoneBookContext();
            var people = phoneBook.phonebooks.Where(c => c.Name == textName.Text).FirstOrDefault();

            people.Name        = textName.Text;
            people.Departament = textDepartament.Text;
            people.Unit        = textUnit.Text;
            people.Position    = textPosition.Text;
            people.Number      = textNumber.Text;
            people.Building    = textBuilding.Text;
            people.Cabinet     = textCabinet.Text;

            BitmapImage bitmapImage = new BitmapImage();

            bitmapImage = image1.Source as BitmapImage;
            byte[]            imageData = null;
            JpegBitmapEncoder encoder   = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                imageData = ms.ToArray();
            }
            people.ImageData = imageData;

            phoneBook.SaveChanges();
        }
Ejemplo n.º 2
0
        private void Button1_Click_1(object sender, RoutedEventArgs e)
        {
            image1.Source = new BitmapImage(new Uri("noImage.png", UriKind.Relative));
            if (listBox1.SelectedItems.Count > 0)
            {
                listBox1.Items.Remove(listBox1.SelectedItems[0]);
            }
            listBox1.Items.Clear();
            textName.Text        = "ФИО";
            textDepartament.Text = "НИЦ";
            textUnit.Text        = "Отдел";
            textPosition.Text    = "Должность";
            textNumber.Text      = "Телефон";
            textBuilding.Text    = null;
            textCabinet.Text     = null;
            using (PhoneBookContext phoneBook = new PhoneBookContext())
            {
                if (textBox1.Text != "")
                {
                    string text   = textBox1.Text;
                    var    people = phoneBook.phonebooks;
                    foreach (Phonebook person in people)
                    {
                        if (person.Name.IndexOf(text, StringComparison.OrdinalIgnoreCase) != -1)
                        {
                            listBox1.Items.Add(person.Name);

                            Console.WriteLine("ФИО: {0}     Кабинет:{1}     Телефон:{2}", person.Name, person.Cabinet, person.Number);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private void GetParameters(string selectedName)
 {
     using (PhoneBookContext phoneBook = new PhoneBookContext())
     {
         var people = phoneBook.phonebooks;
         foreach (var person in people)
         {
             if (selectedName == person.Name)
             {
                 textName.Text        = person.Name;
                 textDepartament.Text = person.Departament;
                 textUnit.Text        = person.Unit;
                 textPosition.Text    = person.Position;
                 textNumber.Text      = person.Number;
                 textBuilding.Text    = person.Building;
                 textCabinet.Text     = person.Cabinet;
                 BitmapImage image = new BitmapImage();
                 if (person.ImageData != null)
                 {
                     using (MemoryStream ms = new MemoryStream(person.ImageData))
                     {
                         image.BeginInit();
                         image.CacheOption  = BitmapCacheOption.OnLoad;
                         image.StreamSource = ms;
                         image.EndInit();
                     }
                     image1.Source = image;
                 }
             }
         }
     }
 }