Esempio n. 1
0
        public void ModifyClockItem(int Id, ClockItem clockForModify)
        {
            ClockItem tmpItem = AllClockItems[Id];
            tmpItem.ClockName = clockForModify.ClockName;
            tmpItem.ClockTime = clockForModify.ClockTime;
            tmpItem.IsRepeat = clockForModify.IsRepeat;
            tmpItem.RepeatTime = clockForModify.RepeatTime;
            tmpItem.MusicId = clockForModify.MusicId;
            tmpItem.IsScheduled = clockForModify.IsScheduled;
            IQueryable<ClockItem> clockQuery = from ClockItem clk in clockDB.Items where clk.ClockItemId == tmpItem.ClockItemId
                                               select clk;
            ClockItem tmpItem1 = clockQuery.FirstOrDefault();
            tmpItem1.ClockName = clockForModify.ClockName;
            tmpItem1.ClockTime = clockForModify.ClockTime;
            tmpItem1.IsRepeat = clockForModify.IsRepeat;
            tmpItem1.RepeatTime = clockForModify.RepeatTime;
            tmpItem1.MusicId = clockForModify.MusicId;
            tmpItem1.IsScheduled = clockForModify.IsScheduled;
            clockDB.SubmitChanges();

        }
Esempio n. 2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)//确认闹铃创建,处理数据存储,并且更新defaultPage
        {
            string clockName = this.clockName.Text;
            DateTime clockTime = (DateTime)this.clockTime.Value;
            bool isRepeat =(bool)this.isRepeat.IsChecked;
            int repeatTime = this.DayPicker.SelectedIndex;
            int musicId = this.musicId.SelectedIndex;
            bool isScheduled = this.alarmSwitch.IsChecked.Value;

            int size = 0;
            for (int i = 0; i < App.ClViewModel.AllClockItems.Count; i++)
            {
                ClockItem maxItem = App.ClViewModel.AllClockItems[i];
                if (size < maxItem.ClockItemId)
                {
                    size = maxItem.ClockItemId;
                }
            }
            ClockItem newClockItem = new ClockItem
            {
                ClockItemId = size+1,
                ClockName = clockName,
                ClockTime = clockTime,
                IsRepeat = isRepeat,
                RepeatTime = repeatTime,
                MusicId = musicId,
                IsScheduled = isScheduled
            };

            if (App.selectedIndex == -1)
            {
                App.ClViewModel.AddClockItem(newClockItem);
                if (this.alarmSwitch.IsChecked.Value)
                {

                    string name = "clock" + newClockItem.ClockItemId.ToString();
                    Alarm alarm = new Alarm(name);
                    alarm.Content = newClockItem.ClockName;
                    string[] soundArray = { "/Ringtones/takeMe.mp3", "/Ringtones/littleApple.mp3", "/Ringtones/yiYongJun.mp3" };
                    alarm.Sound = new Uri(soundArray[newClockItem.MusicId], UriKind.Relative);
                    if (newClockItem.RepeatTime != 7)
                    {
                        DateTime tmpDate = newClockItem.ClockTime;
                        int dayWeek = (int)tmpDate.DayOfWeek;
                        int realDay = 0;
                        if (newClockItem.RepeatTime == 0)
                        {
                            realDay = 7;
                        }
                        else
                        {
                            realDay = newClockItem.RepeatTime;
                        }
                        int distance = realDay - dayWeek;
                        if (distance < 0)
                        {
                            distance = distance + 7;
                        }
                        DateTime tmpDate1 = tmpDate.AddDays(distance);
                        alarm.BeginTime = tmpDate1;
                        alarm.ExpirationTime = tmpDate1;
                        if (newClockItem.IsRepeat)
                        {
                            alarm.RecurrenceType = RecurrenceInterval.Weekly;
                        }
                        else
                        {
                            alarm.RecurrenceType = RecurrenceInterval.None;
                        }

                    }
                    else
                    {
                        alarm.BeginTime = newClockItem.ClockTime;
                        alarm.ExpirationTime = newClockItem.ClockTime;
                        alarm.RecurrenceType = RecurrenceInterval.Daily;
                    }
                    if (alarm.ExpirationTime < DateTime.Now)
                    {
                        MessageBox.Show("闹钟时间不能小于当前时间!");
                        return;
                    }
                    ScheduledActionService.Add(alarm);
                }

                this.NavigationService.Navigate(new Uri("/DefaultPage.xaml", UriKind.Relative));
                MessageBox.Show("闹铃创建成功!");
            }
            else 
            {

                string name1 = "clock" + App.ClViewModel.AllClockItems[App.selectedIndex].ClockItemId.ToString();
                ScheduledAction tmpAction = ScheduledActionService.Find(name1);
                if (tmpAction != null)
                {

                    ScheduledActionService.Remove(name1);
                }
                if (newClockItem.IsScheduled)
                {

                    Alarm alarm = new Alarm(name1);
                    alarm.Content = newClockItem.ClockName;
                    string[] soundArray = { "/Ringtones/TakeMe.mp3", "/Ringtones/PianAi.mp3", "/Ringtones/SweetThanFiction.mp3" };
                    alarm.Sound = new Uri(soundArray[newClockItem.MusicId], UriKind.Relative);
                    if (newClockItem.RepeatTime != 7)
                    {
                        DateTime tmpDate = newClockItem.ClockTime;
                        int dayWeek = (int)tmpDate.DayOfWeek;
                        int realDay = 0;
                        if (newClockItem.RepeatTime == 0)
                        {
                            realDay = 7;
                        }
                        else
                        {
                            realDay = newClockItem.RepeatTime;
                        }
                        int distance = realDay - dayWeek;
                        if (distance < 0)
                        {
                            distance = distance + 7;
                        }
                        DateTime tmpDate1 = tmpDate.AddDays(distance);
                        alarm.BeginTime = tmpDate1;
                        alarm.ExpirationTime = tmpDate1;
                        if (newClockItem.IsRepeat)
                        {
                            alarm.RecurrenceType = RecurrenceInterval.Weekly;
                        }
                        else
                        {
                            alarm.RecurrenceType = RecurrenceInterval.None;
                        }

                    }
                    else
                    {
                        alarm.ExpirationTime = newClockItem.ClockTime;
                        alarm.BeginTime = newClockItem.ClockTime;
                        alarm.RecurrenceType = RecurrenceInterval.Daily;
                    }
                    if (alarm.ExpirationTime < DateTime.Now)
                    {
                        MessageBox.Show("闹钟时间不能小于当前时间!");
                        return;
                    }
                    ScheduledActionService.Add(alarm);
                }


                App.ClViewModel.ModifyClockItem(App.selectedIndex, newClockItem);
                this.NavigationService.Navigate(new Uri("/DefaultPage.xaml", UriKind.Relative));
                MessageBox.Show("闹铃修改成功!");
            }
        }
Esempio n. 3
0
 public void AddClockItem(ClockItem newClockItem)
 {
     clockDB.Items.InsertOnSubmit(newClockItem);
     clockDB.SubmitChanges();
     AllClockItems.Add(newClockItem);
 }