public AlarmItem(ref AlarmUtil.ALARMINFO alarmInfo) { InitializeComponent(); ++_Counter; this.AlarmTitle = alarmInfo.AlarmName; this.AlarmRepeatInterval = alarmInfo.RepeatInterval; this.AlarmContents = alarmInfo.AlarmContents; this.AlarmSoundPath = alarmInfo.AlarmSound; this.BackColor = _DefaultBackgroundColor; this.AlarmID = alarmInfo.AlarmID; this.AlarmStatus = alarmInfo.AlarmStatus; this.CreateDate = DateTime.Now; this.AlarmDate = alarmInfo.AlarmDate; }
/// <summary> /// 创建闹钟对象,并添加到数据库 /// </summary> /// <param name="alarmInfo">一个存储闹钟信息的结构体变量</param> /// <param name="readFlag">该标志指示是读取(true)或创建(false)</param> private void CreateAlarmItem(AlarmUtil.ALARMINFO alarmInfo, bool readFlag) { if (!readFlag) //创建新的闹钟项目 { try { Pub.dbHelper.InsertData(Pub.dbHelper.MainTableName, AlarmUtil.GetStringArrayFromAlarmInfo(alarmInfo)); AlarmItem item = new AlarmItem(ref alarmInfo); LayoutPanel_AlarmItems.Controls.Add(item); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else //从数据库中读取,然后显示的项目 { AlarmItem item = new AlarmItem(ref alarmInfo); LayoutPanel_AlarmItems.Controls.Add(item); } }
/// <summary> /// 通过一个AlarmInfo来初始化窗口 /// </summary> /// <param name="alarmInfo"></param> public Wnd_AddAlarm(AlarmUtil.ALARMINFO alarmInfo) { InitializeComponent(); this.Combox_Hour.SelectedItem = alarmInfo.AlarmDate.Hour.ToString(); this.Combox_Minute.SelectedItem = alarmInfo.AlarmDate.Minute.ToString(); this.DateTimePicker_AlarmDate.Value = alarmInfo.AlarmDate; this.TextBox_AlarmContents.Text = alarmInfo.AlarmContents; this.TextBox_AlarmName.Text = alarmInfo.AlarmName; this.TextBox_AlarmSound.Text = alarmInfo.AlarmSound; if (alarmInfo.RepeatInterval.Once) { this.RadBtn_RepeatOnce.Checked = true; this.Panel_Weekday.Enabled = false; this.Panel_RepeatWeekday.Enabled = false; } if (alarmInfo.RepeatInterval.Daily) { this.ChkBox_Daily.Checked = true; RadBtn_Repeat.Checked = true; Combox_RepeatDayOfMonth.Enabled = false; } if (alarmInfo.RepeatInterval.Monthly) { this.RadBtn_Repeat.Checked = true; this.RadBtn_RepeatMonthly.Checked = true; this.Combox_RepeatDayOfMonth.SelectedItem = alarmInfo.RepeatInterval.DayOfMonth.ToString(); } if (alarmInfo.RepeatInterval.Weekly) { this.RadBtn_Repeat.Checked = true; this.ChkBox_Daily.Checked = false; if (alarmInfo.RepeatInterval.Monday) { this.ChkBox_Monday.Checked = true; } if (alarmInfo.RepeatInterval.Tuesday) { this.ChkBox_Tuesday.Checked = true; } if (alarmInfo.RepeatInterval.Wednesday) { this.ChkBox_Wednesday.Checked = true; } if (alarmInfo.RepeatInterval.Thursday) { this.ChkBox_Thursday.Checked = true; } if (alarmInfo.RepeatInterval.Friday) { this.ChkBox_Friday.Checked = true; } if (alarmInfo.RepeatInterval.Saturday) { this.ChkBox_Saturday.Checked = true; } if (alarmInfo.RepeatInterval.Sunday) { this.ChkBox_Sunday.Checked = true; } } }
/// <summary> /// 根据用户的选择,获取该闹钟的详细信息 /// </summary> /// <returns></returns> private AlarmUtil.ALARMINFO GetAlarmDetail() { AlarmUtil.ALARMINFO alarmInfo = new AlarmUtil.ALARMINFO(); AlarmUtil.REPEATINTERVAL repeatInterval = new AlarmUtil.REPEATINTERVAL(); alarmInfo.AlarmDate = new DateTime ( DateTimePicker_AlarmDate.Value.Year, DateTimePicker_AlarmDate.Value.Month, DateTimePicker_AlarmDate.Value.Day, int.Parse(Combox_Hour.SelectedItem.ToString()), int.Parse(Combox_Minute.SelectedItem.ToString()), 0 ); alarmInfo.CreateDate = DateTime.Now; alarmInfo.AlarmSound = TextBox_AlarmSound.Text; alarmInfo.AlarmName = TextBox_AlarmName.Text; alarmInfo.AlarmContents = TextBox_AlarmContents.Text; if (RadBtn_RepeatOnce.Checked) //一次性,不重复 { repeatInterval.Once = true; repeatInterval.Weekly = false; repeatInterval.Monthly = false; repeatInterval.Daily = false; } else if (ChkBox_Daily.Checked) //每日重复 { repeatInterval.Daily = true; repeatInterval.Once = false; repeatInterval.Monthly = false; repeatInterval.Weekly = false; } else if (RadBtn_RepeatMonthly.Checked) //按月重复 { repeatInterval.Monthly = true; repeatInterval.DayOfMonth = int.Parse(Combox_RepeatDayOfMonth.SelectedItem.ToString()); repeatInterval.Once = false; repeatInterval.Weekly = false; repeatInterval.Daily = false; } else if (!RadBtn_RepeatOnce.Checked && !ChkBox_Daily.Checked && !RadBtn_RepeatMonthly.Checked) //每周几重复 { repeatInterval.Weekly = true; repeatInterval.Monday = ChkBox_Monday.Checked; repeatInterval.Tuesday = ChkBox_Tuesday.Checked; repeatInterval.Wednesday = ChkBox_Wednesday.Checked; repeatInterval.Thursday = ChkBox_Thursday.Checked; repeatInterval.Friday = ChkBox_Friday.Checked; repeatInterval.Saturday = ChkBox_Saturday.Checked; repeatInterval.Sunday = ChkBox_Sunday.Checked; repeatInterval.Monthly = false; repeatInterval.Once = false; repeatInterval.Daily = false; } else { throw new Exception("Error Choice!"); } alarmInfo.RepeatInterval = repeatInterval; alarmInfo.AlarmStatus = true; return(alarmInfo); }