Пример #1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     Entities.BusinessEntity.Select().ForEach(x => BusinessEntity.Items.Add(Entities.BusinessEntity.ToTextBlock(x)));
     Entities.Activity.Select().ForEach(x => Activity.Items.Add(Entities.Activity.ToTextBlock(x)));
     Entities.ActivityDirection.Select().ForEach(x => ActivityDirection.Items.Add(Entities.ActivityDirection.ToTextBlock(x)));
     Entities.Region.Select().ForEach(x => Region.Items.Add(Entities.Region.ToTextBlock(x)));
     if (Dealer == null)
     {
         Dealer = new Dealer();
         BusinessEntity.SelectItem();
         Activity.SelectItem();
         ActivityDirection.SelectItem();
         Region.SelectItem();
         Title = "Добавление дилера";
     }
     else
     {
         BusinessEntity.SelectItem(BusinessEntity.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.BusinessEntityId));
         _Name.Text = Dealer.Name;
         Activity.SelectItem(Activity.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.ActivityId));
         ActivityDirection.SelectItem(ActivityDirection.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.ActivityDirectionId));
         Rating.SelectItem(selectedIndex: 5 - (int)Dealer.Rating);
         Relevance.SelectItem(selectedIndex: Dealer.IsRelevant ? 0 : 1);
         Region.SelectItem(Region.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.RegionId));
         City.Text   = Dealer.City;
         Street.Text = Dealer.Street;
         House.Text  = Dealer.House;
         Block.Text  = Dealer.Block;
         Room.Text   = Dealer.Room;
         UpdateContacts();
         Contacts.SelectItem();
         Note.Text       = Dealer.Note;
         Conditions.Text = Dealer.Conditions;
         UpdateEvents();
         Events.SelectItem(selectedIndex: 1);
         Title = "Правка дилера";
     }
 }
        public void UpdateDealers()
        {
            long selectedRegionId            = (long)(Region.SelectedItem as TextBlock).Tag;
            long selectedActivityId          = (long)(Activity.SelectedItem as TextBlock).Tag;
            long selectedActivityDirectionId = (long)(ActivityDirection.SelectedItem as TextBlock).Tag;

            Region.Items.RemoveRange(1, Region.Items.Count - 1);
            Entities.Region.Select().ForEach(x => Region.Items.Add(Entities.Region.ToTextBlock(x)));
            Region.SelectItem(Region.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedRegionId));
            Activity.Items.RemoveRange(1, Activity.Items.Count - 1);
            Entities.Activity.Select().ForEach(x => Activity.Items.Add(Entities.Activity.ToTextBlock(x)));
            Activity.SelectItem(Activity.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedActivityId));
            ActivityDirection.Items.RemoveRange(1, ActivityDirection.Items.Count - 1);
            Entities.ActivityDirection.Select().ForEach(x => ActivityDirection.Items.Add(Entities.ActivityDirection.ToTextBlock(x)));
            ActivityDirection.SelectItem(ActivityDirection.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedActivityDirectionId));
            Region.Tag            = (Region.SelectedItem as TextBlock).Tag;
            Activity.Tag          = (Activity.SelectedItem as TextBlock).Tag;
            ActivityDirection.Tag = (ActivityDirection.SelectedItem as TextBlock).Tag;
            Relevance.Tag         = (long)Relevance.SelectedIndex;
            Sort.Tag = (long)Sort.SelectedIndex;
            Dealers.Items.Clear();
            Dealer.Select(new Filter(true)).ForEach(x => Dealers.Items.Add(Dealer.ToTextBlock(x)));
        }