Esempio n. 1
0
        public TimeViewModel(IEnumerable <TestStopwatch> times)
        {
            Watches = times.OrderBy(t => t.Ticks).ToArray();
            var ts    = Watches.Select(t => t.Ticks).ToList();
            var count = ts.Count;

            foreach (var w in Watches)
            {
                w.Time = new TimeSpan(w.Ticks);
            }

            var ticks =
                count == 1 ? ts[0] :
                count == 2 ? (long)ts.Average(t => t) :
                count <= 5 ? (long)ts.Skip(1).Take(count - 2).Average(t => t) :
                count <= 10 ? (long)ts.Skip(2).Take(count - 4).Average(t => t) :
                (long)ts.Skip(count / 5).Take(count - count / 5 * 2).Average(t => t);

            Time = new TimeSpan(ticks);
        }
        private void RamWatchNewWatch_Load(object sender, EventArgs e)
        {
            if (InitialLocation.X > 0 || InitialLocation.Y > 0)
            {
                Location = InitialLocation;
            }

            _loading = false;
            SetAddressBoxProperties();

            switch (_mode)
            {
            default:
            case Mode.New:
                SizeDropDown.SelectedItem = MemoryDomains.First().WordSize switch
                {
                    1 => SizeDropDown.Items[0],
                    2 => SizeDropDown.Items[1],
                    4 => SizeDropDown.Items[2],
                    _ => SizeDropDown.Items[0]
                };
                break;

            case Mode.Duplicate:
            case Mode.Edit:
                SizeDropDown.SelectedItem = Watches[0].Size switch
                {
                    WatchSize.Byte => SizeDropDown.Items[0],
                    WatchSize.Word => SizeDropDown.Items[1],
                    WatchSize.DWord => SizeDropDown.Items[2],
                    _ => SizeDropDown.SelectedItem
                };

                var index = DisplayTypeDropDown.Items.IndexOf(Watch.DisplayTypeToString(Watches[0].Type));
                DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[index];

                if (Watches.Count > 1)
                {
                    NotesBox.Enabled = false;
                    NotesBox.Text    = "";

                    AddressBox.Enabled = false;
                    AddressBox.Text    = Watches.Select(a => a.AddressString).Aggregate((addrStr, nextStr) => $"{addrStr},{nextStr}");

                    BigEndianCheckBox.ThreeState = true;

                    if (Watches.Select(s => s.Size).Distinct().Count() > 1)
                    {
                        DisplayTypeDropDown.Enabled = false;
                    }
                }
                else
                {
                    NotesBox.Text = Watches[0].Notes;
                    AddressBox.SetFromLong(Watches[0].Address);
                }

                SetBigEndianCheckBox();
                DomainDropDown.Enabled = false;
                break;
            }
        }
        public void Initialization()
        {
            WatchDates.Clear();
            PeriodValues.Clear();
            WatchesList.Clear();


            Watches = db.Watches
                      .Include(w => w.Exam)
                      .Include(w => w.WatcherWatches).ThenInclude(ww => ww.Room)
                      .Include(w => w.WatcherWatches).ThenInclude(ww => ww.Watcher)
                      .Where(
                w => w.ExamId == CurrentExamId
                )
                      .OrderByDescending(w => w.WatchDate).ToList();

            SelectedWatch = Watches.FirstOrDefault();

            foreach (DateTime?d in Watches.Select(x => x.WatchDate).Distinct().ToList())
            {
                WatchDates.Add(d);
            }
            foreach (short?p in Watches.Select(x => x.PeriodId).Distinct().ToList())
            {
                PeriodValues.Add(p);
            }
            //WatcherWatchesList = new List<WatcherWatch>();

            WatchTableViewModel row;

            foreach (DateTime date in WatchDates)
            {
                foreach (short p in PeriodValues)
                {
                    foreach (Watch w in Watches)
                    {
                        if (w.PeriodId.Equals(p) && w.WatchDate.Equals(date))
                        {
                            var RoomsWatches =
                                w.WatcherWatches.GroupBy(ww => ww.RoomId)
                                .Select(grp => grp.ToList());

                            foreach (var r in RoomsWatches)
                            {
                                row = new WatchTableViewModel()
                                {
                                    Room  = db.Rooms.Find(r.FirstOrDefault().RoomId),
                                    Watch = w
                                };
                                foreach (var ww in r)
                                {
                                    row.WatcherWatchesList.Add(ww);

                                    if (ww.WatcherType.Equals("1"))
                                    {
                                        row.RoomChiefsList.Add(ww.Watcher.FullName);
                                    }
                                    else if (ww.WatcherType.Equals("2"))
                                    {
                                        row.RoomSecretariesList.Add(ww.Watcher.FullName);
                                    }
                                    else if (ww.WatcherType.Equals("3"))
                                    {
                                        row.RoomWatchersList.Add(ww.Watcher.FullName);
                                    }
                                }

                                row.RoomChiefs      = string.Join(", ", row.RoomChiefsList.ToArray());
                                row.RoomSecretaries = string.Join(", ", row.RoomSecretariesList.ToArray());
                                row.RoomWatchers    = string.Join(", ", row.RoomWatchersList.ToArray());

                                WatchesList.Add(row);
                            }
                        }
                    }
                }
            }
        }