Exemplo n.º 1
0
        public void CreateUI(object sender, EventArgs e)
        {
            if (IsolatedStorageHelper.ReadFromTimeZoneFile() == null)
            {
                SavedTimeInstance defaultInstance2 = new SavedTimeInstance();
                defaultInstance2.Description = "The Big Apple & Bob lives here.";
                defaultInstance2.Location = "New York City, NY, US";
                defaultInstance2.UTCOffset = -5;
                defaultInstance2.Id = Guid.NewGuid();

                SavedTimeInstance defaultInstance = new SavedTimeInstance();
                defaultInstance.Description = "Asakusa Shrine & Jiro's Sushi!";
                defaultInstance.Location = "Tokyo, JP";
                defaultInstance.UTCOffset = 9;
                defaultInstance.Hearted = true;
                defaultInstance.Id = Guid.NewGuid();

                IsolatedStorageHelper.AddToTimeZoneFile(defaultInstance);
                IsolatedStorageHelper.AddToTimeZoneFile(defaultInstance2);
            }

            this.instances =
                IsolatedStorageHelper.ReadFromTimeZoneFile();

            // clean out children
            while (this.ListOfZones.Items.Count > 0)
            {
                this.ListOfZones.Items.RemoveAt(0);
            }

            // add new children
            for (int i = 0; i < this.instances.Count; i++)
            {
                TimeInstance timeInstance = new TimeInstance();
                timeInstance.SetTimerTime(
                    (Style)this.Resources["TimerTimeStyle"],
                    "12:34 PM");
                timeInstance.SetTimerDate(
                    (Style)this.Resources["TimerDateStyle"],
                    "12/12/12");
                timeInstance.SetTimerLabel(
                    (Style)this.Resources["TimerLabelStyle"],
                    this.instances[i].Description);
                timeInstance.SetTimerLabelLoc(
                    (Style)this.Resources["TimerLabelLocStyle"],
                    this.instances[i].Location);
                timeInstance.SetDividerStyles(
                    (Style)this.Resources["DividerStyle"],
                    (Style)this.Resources["DividerTopStyle"]);
                timeInstance.SetGridStyles(
                    (Style)this.Resources["DayNightGridStyle"],
                    (Style)this.Resources["HeartGridStyle"]);
                timeInstance.EnableHeart(this.instances[i].Hearted);
                timeInstance.militaryTime = this.instances[i].Military;
                timeInstance.Id = this.instances[i].Id;

                Thickness prevThick = timeInstance.Margin;
                prevThick.Bottom = 25;
                timeInstance.Margin = prevThick;
                timeInstance.UTCOffset = this.instances[i].UTCOffset;

                ContextMenu contextMenu = new ContextMenu();
                MenuItem removeMenuItem = new MenuItem()
                    { Header = "Remove", Tag = "Remove"};
                removeMenuItem.Click += new RoutedEventHandler(ConMenuRemove_Click);

                contextMenu.Items.Add(removeMenuItem);
                contextMenu.Tag = timeInstance.Id;
                ContextMenuService.SetContextMenu(timeInstance,contextMenu);
                this.ListOfZones.Items.Add(timeInstance);
            }

            RefreshUI(this, null);
        }
Exemplo n.º 2
0
        private void RefreshOneTimeInstance(TimeInstance timer)
        {
            double offset = timer.UTCOffset;
            DateTime thisDate = DateTime.UtcNow.AddHours(offset);
            if (timer.ifCurrentDayLight())
            {
                thisDate = thisDate.AddHours(timer.ObserveDayLightSavings());
            }

            string currentTime;
            string dayofWeek =
                thisDate.DayOfWeek.ToString();
            dayofWeek += '\n' + thisDate.Date.ToString().Substring(
                0,
                thisDate.Date.ToString().IndexOf(" "));
            if (timer.militaryTime)
            {
                currentTime = thisDate.ToString("HH:mm");
            }
            else
            {
                currentTime = thisDate.ToString("hh:mm tt");
            }

            timer.UpdateTimerTimeText(currentTime);
            timer.UpdateTimerDateText(dayofWeek);
            bool isNight = (thisDate.Hour < 7 || (thisDate.Hour > (12+7)));
            timer.UpdateDayNightIcon(isNight);
        }