예제 #1
0
 public AlarmClockRingViewModel(AlarmClockModel time)
 {
     try
     {
         IsRepetition = time.IsRepetition;
         string[] times = Convert.ToDateTime(time.AlarmTime).ToShortTimeString().Split(' ');
         if (times[0].Contains("午"))
         {
             if (times[0].Equals("上午"))
             {
                 AlarmTime = times[1] + "am";
             }
             else
             {
                 AlarmTime = times[1] + "pm";
             }
         }
         else
         {
             AlarmTime = times[0];
         }
         _alarmTimeRing = time.AlarmTime;
         Label          = time.Label;
         TimeTick();
         _player.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Media/Music/" + time.Ring, UriKind.RelativeOrAbsolute));
         _player.Play();
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
예제 #2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            AlarmClockModel ob = new AlarmClockModel();

            ob.code     = Guid.NewGuid().ToString();
            ob.CityName = cbCity.SelectedItem.ToString();
            ob.TimeZone = cbCity.SelectedValue.ToString();
            ob.Week     = Convert.ToInt32(cbWeek.Text);

            double   timeZone = 0;
            DateTime now      = Convert.ToDateTime(tpTime.Value);

            if (ob.TimeZone.Contains("+"))
            {
                timeZone = -8 + Convert.ToDouble(ob.TimeZone.Replace("+", ""));
            }
            else
            {
                timeZone = -8 - Convert.ToDouble(ob.TimeZone.Replace("-", ""));
            }
            now = now.AddHours(timeZone * -1);

            ob.Time   = now.ToString("HH:mm");
            ob.Remark = tbRemark.Text;

            AlarmClockCore.Add(ob);
            InitList();

            //DialogWindow dialog = new DialogWindow();
            //dialog.DealogContent = "mmmm";
            //dialog.Show();
        }
예제 #3
0
 public AlarmClockAddItemViewModel(AlarmClockModel model)
 {
     try
     {
         _lastAlarmClock = model;
         TitleContent    = "编辑闹钟";
         GuiD            = model.GuiD;
         string[] times = Convert.ToDateTime(model.AlarmTime).ToShortTimeString().Split(' ');
         if (times[0].Contains("午"))
         {
             Format = times[0];
             string[] time = times[1].Split(':');
             Hours   = time[0];
             Minutes = time[1];
         }
         else
         {
             string[] time = times[0].Split(':');
             Hours   = time[0];
             Minutes = time[1];
         }
         Days         = model.AlarmDate == "" ? "永不" : model.AlarmDate;
         Label        = model.Label;
         Ring         = model.Ring;
         IsRepetition = model.IsRepetition == "1" ? "True" : "False";
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
예제 #4
0
 /// <summary>
 /// 取数据
 /// </summary>
 /// <param name="model"></param>
 public void FetchData(AlarmClockModel model)
 {
     try
     {
         GuiD      = model.GuiD;
         AlarmTime = model.AlarmTime;
         AlarmDate = model.AlarmDate;
         string[] times = Convert.ToDateTime(model.AlarmTime).ToShortTimeString().Split(' ');
         if (times[0].Contains("午"))
         {
             Format    = times[0];
             AlarmTime = times[1];
         }
         else
         {
             AlarmTime = times[0];
         }
         Label        = model.Label;
         Ring         = model.Ring;
         RingPath     = model.RingPath;
         IsRepetition = model.IsRepetition;
         IsOpen       = model.IsOpen == "1" ? "True" : "False";
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
        /// <summary>
        /// 编辑闹钟
        /// </summary>
        /// <param name="model"></param>
        private void EditAlarmClock(AlarmClockModel model)
        {
            _temp          = model;
            _lastUIElement = _mainBorder.Child;
            DoubleAnimation dLoginFadeOut = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.2)));

            dLoginFadeOut.Completed += DLoginFadeIn_Completed;
            _mainBorder.Child.BeginAnimation(UIElement.OpacityProperty, dLoginFadeOut);
        }
 /// <summary>
 /// 响铃
 /// </summary>
 /// <param name="clockModel"></param>
 private void AlarmClockRing(AlarmClockModel clockModel)
 {
     DispatcherHelper.CheckBeginInvokeOnUI(
         () =>
     {
         AlarmClockRingView view = new AlarmClockRingView();
         view.DataContext        = new AlarmClockRingViewModel(clockModel);
         _alarmClocksWindows.Add(view);
         view.Show();
     });
 }
예제 #7
0
 /// <summary>
 /// 删除闹钟
 /// </summary>
 public void DeleteData()
 {
     try
     {
         AlarmClockModel model = new AlarmClockModel();
         model.GuiD = GuiD;
         MainAlarmClockManager.Instance.AlarmClocks.RemoveAll((obj) => { return(obj.GuiD == model.GuiD); });
         DataManager.Instance.DeleteTables(model);
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
예제 #8
0
 /// <summary>
 /// 存储闹钟
 /// </summary>
 /// <param name="elememt"></param>
 private void SaveData(Grid elememt)
 {
     try
     {
         if (TitleContent.Equals("添加闹钟"))
         {
             AlarmClockModel model = new AlarmClockModel();
             GuiD               = Guid.NewGuid().ToString().Replace("-", "");
             model.GuiD         = GuiD;
             Hours              = _hours.Currentitem;
             Minutes            = _minutes.Currentitem;
             Format             = format.Currentitem;
             Time               = string.Format("{0:H:mm}", Convert.ToDateTime(Format + " " + Hours + ":" + Minutes));
             model.AlarmTime    = Time;
             model.AlarmDate    = Days == "永不" ? "" : Days;
             model.Label        = Label;
             model.IsRepetition = IsRepetition == "True" ? "1" : "0";
             model.IsOpen       = "1";
             model.Ring         = Ring;
             DataManager.Instance.InsertTables(model);
             MainAlarmClockManager.Instance.AlarmClocks.Add(model);
             BackToMainView("Cancel");
         }
         else if (TitleContent.Equals("编辑闹钟"))
         {
             int index = MainAlarmClockManager.Instance.AlarmClocks.IndexOf(MainAlarmClockManager.Instance.AlarmClocks.Where(temp => temp.GuiD == _lastAlarmClock.GuiD).First());
             Hours   = _hours.Currentitem;
             Minutes = _minutes.Currentitem;
             Format  = format.Currentitem;
             Time    = string.Format("{0:H:mm}", Convert.ToDateTime(Format + " " + Hours + ":" + Minutes));
             _lastAlarmClock.AlarmTime    = Time;
             _lastAlarmClock.AlarmDate    = Days == "永不" ? "" : Days;
             _lastAlarmClock.Label        = Label;
             _lastAlarmClock.IsOpen       = "1";
             _lastAlarmClock.IsRepetition = IsRepetition == "True" ? "1" : "0";
             _lastAlarmClock.Ring         = Ring;
             DataManager.Instance.UpdateTables(_lastAlarmClock);
             MainAlarmClockManager.Instance.AlarmClocks[index] = _lastAlarmClock;
             BackToMainView("Cancel");
         }
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
 private void FetchData()
 {
     try
     {
         AlarmClockModel model = new AlarmClockModel();
         DataTable       datas = DataManager.Instance.SelectTables(model);
         AlarmClocks.Clear();
         foreach (DataRow data in datas.Rows)
         {
             model.FetchData(data);
             AddToAlarmClocks(model);
         }
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
예제 #10
0
        private void lbList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lbList.SelectedIndex == -1)
            {
                return;
            }

            if (!string.IsNullOrEmpty(lbList.SelectedValue.ToString()))
            {
                AlarmClockModel ob = AlarmClockCore.GetBy(lbList.SelectedValue.ToString());
                if (ob != null)
                {
                    cbCity.SelectedItem = ob.CityName;
                    cbWeek.SelectedItem = ob.Week;
                    tpTime.DefaultValue = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + ob.Time);
                    tbRemark.Text       = ob.Remark;
                }
            }
        }
 /// <summary>
 /// 添加到闹钟集合
 /// </summary>
 /// <param name="model"></param>
 private void AddToAlarmClocks(AlarmClockModel model)
 {
     try
     {
         AlarmClockModel temp = new AlarmClockModel();
         temp.AlarmDate    = model.AlarmDate;
         temp.AlarmTime    = model.AlarmTime;
         temp.GuiD         = model.GuiD;
         temp.IsOpen       = model.IsOpen;
         temp.IsRepetition = model.IsRepetition;
         temp.Label        = model.Label;
         temp.Ring         = model.Ring;
         temp.RingPath     = model.RingPath;
         AlarmClocks.Add(temp);
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
예제 #12
0
 /// <summary>
 /// 编辑闹钟
 /// </summary>
 /// <param name="element"></param>
 private void MouseLeftButtonDownEdit(Grid element)
 {
     try
     {
         AlarmClockModel model = new AlarmClockModel();
         model.GuiD         = GuiD;
         model.AlarmTime    = Format + " " + AlarmTime;
         model.AlarmDate    = AlarmDate;
         model.Label        = Label;
         model.Ring         = Ring;
         model.RingPath     = RingPath;
         model.IsRepetition = IsRepetition;
         model.IsOpen       = IsOpen == "True" ? "1" : "0";
         EditAlarmClock(model);
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
 /// <summary>
 /// 时间匹配
 /// </summary>
 /// <param name="clockModel"></param>
 private void MatchTime(AlarmClockModel clockModel)
 {
     try
     {
         TimeSpan date = DateTime.Now - (Convert.ToDateTime(clockModel.AlarmTime));
         if (date.TotalSeconds <= 10 && date.TotalSeconds >= 0)
         {
             if (string.IsNullOrEmpty(clockModel.AlarmDate))
             {
                 clockModel.IsOpen = "0";
                 DataManager.Instance.UpdateTables(clockModel);
                 AlarmClocks.Where(temp => temp.GuiD == clockModel.GuiD).First().IsOpen = "0";
             }
             AlarmClockRing(clockModel);
         }
     }
     catch (Exception e)
     {
         LogWriter.Instance.Error(e);
     }
 }
예제 #14
0
 /// <summary>
 /// 是否开启闹钟
 /// </summary>
 /// <param name="element"></param>
 private void CheckedBox(ScrollViewer element)
 {
     Task.Factory.StartNew(() =>
     {
         AlarmClockModel model = new AlarmClockModel();
         model.GuiD            = GuiD;
         model.AlarmTime       = string.Format("{0:H:mm}", Convert.ToDateTime(Format + " " + AlarmTime));
         model.AlarmDate       = AlarmDate;
         model.Label           = Label;
         model.Ring            = Ring;
         model.RingPath        = RingPath;
         model.IsRepetition    = IsRepetition;
         model.IsOpen          = IsOpen == "True" ? "1" : "0";
         DataManager.Instance.UpdateTables(model);
         MainAlarmClockManager.Instance.AlarmClocks.Where((temp) => { return(temp.GuiD == model.GuiD); }).First().IsOpen = model.IsOpen;
     }).ContinueWith(result =>
     {
         if (result.IsFaulted)
         {
             LogWriter.Instance.Error(result.Exception);
         }
     });
 }
        /// <summary>
        /// 添加闹钟
        /// </summary>
        /// <param name="element"></param>
        /// <param name="model"></param>
        private void AddNewReminder(ListBox element, AlarmClockModel model)
        {
            try
            {
                ListBoxItem item = new ListBoxItem();
                //加载资源字典
                string             packUri = @"/LifeService;component/WindowDictionary.xaml";
                ResourceDictionary myResourceDictionary = Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary;
                item.SetValue(ListBoxItem.StyleProperty, myResourceDictionary["NoBackgroundListBoxItemStyle"]);

                AlarmClockView      clockView      = new AlarmClockView(element);
                AlarmClockViewModel clockViewModel = new AlarmClockViewModel();
                clockViewModel.DeleteFromListBox = DeleteFormListBox;
                clockViewModel.FetchData(model);
                clockView.DataContext = clockViewModel;
                item.Content          = clockView;
                ListBoxItems.Add(item);
            }
            catch (Exception e)
            {
                LogWriter.Instance.Error(e);
            }
        }