Пример #1
0
        public void PopulateItems()
        {
            if ((MetroManager.Current.RailwayIds == null) || !MetroManager.Current.RailwayIds.Any())
            {
                return;
            }

            foreach (var railwayId in MetroManager.Current.RailwayIds)
            {
                var existingItem = SourceItems
                                   .FirstOrDefault(x => x.RailwayIds
                                                   .Select(y => y.Replace("Branch", String.Empty))
                                                   .Contains(railwayId.Replace("Branch", String.Empty))); // For MarunouchiBranch

                if (existingItem != null)
                {
                    existingItem.RailwayIds.Add(railwayId);
                }
                else
                {
                    var newItem = new RailwayItemViewModel {
                        RailwayIds = new List <string> {
                            railwayId
                        }
                    };
                    SourceItems.Add(newItem);
                }
            }

            if ((Settings.Current.RailwayIdPriority == null) || !Settings.Current.RailwayIdPriority.Any())
            {
                SelectedIndices = Enumerable.Range(0, SourceItems.Count).ToArray();
            }
            else
            {
                var indices = new List <int>();

                int order = 0;
                foreach (var railwayId in Settings.Current.RailwayIdPriority)
                {
                    int index = 0;
                    foreach (var item in SourceItems)
                    {
                        if (item.RailwayIds[0] == railwayId)
                        {
                            item.IsSelected = true;
                            item.Order      = order;
                            indices.Add(index);
                            break;
                        }
                        index++;
                    }
                    order++;
                }

                SelectedIndices = indices.ToArray();
            }
        }
        private async void Delete()
        {
            if (HIOStaticValues.CheckSyncingData())
            {
                return;
            }

            if (TMessageBox.Show("Are you sure you want to delete these accounts?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                Commands cmd = new Backend.Commands();
                while (true)
                {
                    var res = cmd.AmISync();
                    if (res == SyncronizingStateEnum.Synced)
                    {
                        break;
                    }
                    else
                    {
                        HIOStaticValues.SyncOpration();
                    }
                }


                await UIService.Execute(async() =>
                {
                    DataBase db = new DataBase();
                    foreach (var item in SourceItems.Where(t => t.IsChecked).ToArray())
                    {
                        Commands ic = new Commands();
                        if (ic.Delete(item.UserID))
                        {
                            App.Current.Dispatcher.BeginInvoke((Action)(() =>
                            {
                                SourceItems.Remove(SourceItems.FirstOrDefault(i => i.UserID == item.UserID));
                                OnPropertyChanged(nameof(Items));
                            }));
                        }
                    }
                    await LoadData();
                });

                OnPropertyChanged(nameof(IsAllChecked));
            }
        }
Пример #3
0
        private void ChangeSelectedItems()
        {
            int index = 0;

            foreach (var item in SourceItems)
            {
                if ((SelectedIndices != null) && SelectedIndices.Contains(index))
                {
                    if (!item.IsSelected)
                    {
                        item.IsSelected = true;
                    }
                }
                else
                {
                    item.IsSelected = false;
                    item.Order      = 0;
                }
                index++;
            }

            var sortedItems = SourceItems
                              .Where(x => x.IsSelected)
                              .OrderBy(x => x.SelectedDate)
                              .ThenBy(x => x.Order)
                              .ToArray();

            int order = 0;

            foreach (var item in sortedItems)
            {
                var matchingItem = SourceItems.FirstOrDefault(x => x.RailwayIds[0] == item.RailwayIds[0]);
                if (matchingItem != null)
                {
                    matchingItem.Order = ++order;
                }
            }

            RaiseCanExecuteChanged();
        }