📄 main.cs
字号:
this.label7.Size = new System.Drawing.Size(40, 16);
this.label7.TabIndex = 23;
this.label7.Text = "提示选项 ";
//
// label6
//
this.label6.Location = new System.Drawing.Point(8, 53);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(40, 16);
this.label6.TabIndex = 22;
this.label6.Text = "时间";
//
// label5
//
this.label5.Location = new System.Drawing.Point(328, 20);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 16);
this.label5.TabIndex = 21;
this.label5.Text = "优先度";
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 20);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(40, 16);
this.label4.TabIndex = 20;
this.label4.Text = "类型";
//
// scheduleGroup
//
this.scheduleGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label2,
this.label1,
this.taskTitleBox,
this.taskDetailBox});
this.scheduleGroup.Location = new System.Drawing.Point(24, 8);
this.scheduleGroup.Name = "scheduleGroup";
this.scheduleGroup.Size = new System.Drawing.Size(744, 232);
this.scheduleGroup.TabIndex = 9;
this.scheduleGroup.TabStop = false;
this.scheduleGroup.Text = "新日程属性";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 67);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 16);
this.label2.TabIndex = 3;
this.label2.Text = "内容";
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(8, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 16);
this.label1.TabIndex = 2;
this.label1.Text = "标题";
//
// taskTitleBox
//
this.taskTitleBox.BackColor = System.Drawing.SystemColors.Info;
this.taskTitleBox.Location = new System.Drawing.Point(56, 32);
this.taskTitleBox.MaxLength = 256;
this.taskTitleBox.Name = "taskTitleBox";
this.taskTitleBox.Size = new System.Drawing.Size(624, 21);
this.taskTitleBox.TabIndex = 1;
this.taskTitleBox.Text = "";
//
// taskDetailBox
//
this.taskDetailBox.BackColor = System.Drawing.SystemColors.Info;
this.taskDetailBox.Location = new System.Drawing.Point(56, 72);
this.taskDetailBox.MaxLength = 8000;
this.taskDetailBox.Multiline = true;
this.taskDetailBox.Name = "taskDetailBox";
this.taskDetailBox.Size = new System.Drawing.Size(624, 136);
this.taskDetailBox.TabIndex = 2;
this.taskDetailBox.Text = "";
//
// OK
//
this.OK.Location = new System.Drawing.Point(680, 384);
this.OK.Name = "OK";
this.OK.TabIndex = 0;
this.OK.Text = "确定";
this.OK.Click += new System.EventHandler(this.OK_Click);
//
// tp_notdoneview
//
this.tp_notdoneview.Name = "tp_notdoneview";
this.tp_notdoneview.TabIndex = 0;
//
// MainForm
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(792, 566);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1});
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "SmartSchedule";
this.Load += new System.EventHandler(this.MainForm_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage_scheduleshow.ResumeLayout(false);
this.tabControl2.ResumeLayout(false);
this.tp_dayview.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dg_dayview)).EndInit();
this.tp_thingsleft.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dg_Remain)).EndInit();
this.tp_addSchedule.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.scheduleGroup.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void MainForm_Load(object sender, System.EventArgs e)
{
///设置控件属性
///
taskDateTimeSetupBox.CustomFormat = "hh:mm:ss yyyy年MM月dd日,dddd";
///填充日视图
///
myConn = new SqlConnection(ConnString);
try
{
myConn.Open();
}
catch(Exception ee)
{
MessageBox.Show (ee.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
Application.Exit();
}
Init_AddSchedulePage();
if ( Fill_dayview(DateTime.Now) == -1 || Fill_RemainView() == -1)
Application.Exit();
}
//////////////////////////////////////////////////////////////////////////
///<summary>
///用于生成日视图
///</summary>
///<param name="GivenDay"></param>
private int Fill_dayview(DateTime GivenDay)
{
DataSet DS_DayView = new DataSet();
MySchedule DaySchedule = new MySchedule();
if(!DaySchedule.GetScheduleByGivenDay(ref myConn, ref DS_DayView, ref GivenDay))
return -1;
int nScheduleCount = DS_DayView.Tables["ScheduleList"].Rows.Count;
// if( nScheduleCount > 0)
dg_dayview.DataSource = DS_DayView.Tables["ScheduleList"].DefaultView;
return 0;
}
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// 初始化“添加日程”属性页
/// </summary>
private bool Init_AddSchedulePage()
{
if(!Init_TaskTypeBox() || !Init_TaskPriorityBox())
return false;
taskTitleBox.Text = "";
taskDetailBox.Text = "";
taskDateTimeSetupBox.Value = DateTime.Now;
notifyCheckBox.Checked = true;
notifyTimeSetupBox.Enabled = true;
notifyTimeSetupBox.SelectedIndex = 0;
periodSetupListBox.SelectedIndex = 0;
return true;
}
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// 初始化任务类型列表
/// </summary>
private bool Init_TaskTypeBox()
{
SqlDataAdapter da_tasktype = new SqlDataAdapter("FillTaskTypeBox",myConn);
da_tasktype.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds_TaskType = new DataSet();
try
{
da_tasktype.Fill(ds_TaskType, "TaskType");
taskTypeListbox.DataSource = ds_TaskType.Tables["TaskType"];
taskTypeListbox.DisplayMember = "TypeTitle";
taskTypeListbox.ValueMember = "TASKTYPE_ID";
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// 初始化任务优先度列表
/// </summary>
private bool Init_TaskPriorityBox()
{
SqlDataAdapter da_TaskPriority = new SqlDataAdapter("FillTaskPriorityBox",myConn);
da_TaskPriority.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds_TaskPriority = new DataSet();
try
{
da_TaskPriority.Fill(ds_TaskPriority, "TaskPriority");
taskPriorityListbox.DataSource = ds_TaskPriority.Tables["TaskPriority"];
taskPriorityListbox.DisplayMember = "PriorityTitle";
taskPriorityListbox.ValueMember = "PRIORITY_ID";
taskPriorityListbox.SelectedIndex = 1;
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// 计算提醒时间
/// </summary>
/// <param name="BeginTime"></param>
private DateTime notifyTimeCalc(ref DateTime BeginTime)
{
DateTime notifyTime = BeginTime;
string forwardTime = notifyTimeSetupBox.SelectedText.Trim();
if(notifyCheckBox.Checked)
{
switch(forwardTime)
{
case "准时提醒":
break;
case "提前15分钟":
notifyTime.AddMinutes(-15);
break;
case "提前30分钟":
notifyTime.AddMinutes(-30);
break;
case "提前45分钟":
notifyTime.AddMinutes(-45);
break;
case "提前1小时":
notifyTime.AddHours(-1);
break;
case "提前2小时":
notifyTime.AddHours(-2);
break;
case "提前6小时":
notifyTime.AddHours(-6);
break;
case "提前12小时":
notifyTime.AddHours(-12);
break;
case "提前1天":
notifyTime.AddDays(-1);
break;
case "提前1周":
notifyTime.AddDays(-7);
break;
case "提前1月":
notifyTime.AddMonths(-1);
break;
default:
break;
}
}
return notifyTime;
}
private void notifyCheckBox_Click(object sender, System.EventArgs e)
{
notifyTimeSetupBox.Enabled = notifyCheckBox.Checked;
}
private void OK_Click(object sender, System.EventArgs e)
{
if(taskTitleBox.Text == "" )
{
MessageBox.Show("日程标题不能为空!","Error");
return;
}
if(taskTypeListbox.SelectedIndex == -1)
{
MessageBox.Show("请指定日程类型!","Error");
return;
}
if(taskPriorityListbox.SelectedIndex == -1)
{
MessageBox.Show("请指定优先度!","Error");
return;
}
string Title = taskTitleBox.Text.Trim(); //标题
string Detail = taskDetailBox.Text.Trim(); //内容
if(Detail == "") Detail = "无详细信息";
DateTime BeginTime = DateTime.Parse(taskDateTimeSetupBox.Text.Trim()); //开始时间
if(BeginTime < DateTime.Now)
{
MessageBox.Show("日程开始时间已过!","Error");
return;
}
int Type = Int32.Parse(taskTypeListbox.SelectedValue.ToString()); //类型
int Priority = Int32.Parse(taskPriorityListbox.SelectedValue.ToString()); //优先级
int NeedNotify = 0;
if(notifyCheckBox.Checked) //是否需要提醒
NeedNotify = 1;
DateTime NotifyTime = BeginTime;
if(NeedNotify == 1)
notifyTimeCalc(ref BeginTime);
MySchedule NewSchedule = new MySchedule();
NewSchedule.SetSchedule(0, Title, Detail, BeginTime, NotifyTime, NeedNotify, Type, Priority);
if(!NewSchedule.InsertSchedule(ref myConn))
MessageBox.Show("添加新日程失败!","Error");
MessageBox.Show("添加新日程成功!","OK");
return;
}
private void Cancel_Click(object sender, System.EventArgs e)
{
Init_AddSchedulePage();
}
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if ( Fill_dayview(DateTime.Now) == -1 || Fill_RemainView() == -1)
Application.Exit();
}
//////////////////////////////////////////////////////////////////////////
///<summary>
///用于生成未完成事件视图
///</summary>
private int Fill_RemainView()
{
DataSet DS_Unfinished = new DataSet();
MySchedule UnfinishedSchedule = new MySchedule();
if(!UnfinishedSchedule.GetUnfinishedSchedule(ref myConn, ref DS_Unfinished))
return -1;
if(DS_Unfinished.Tables["ScheduleList"].Rows.Count > 0)
{
dg_Remain.DataSource = DS_Unfinished.Tables["ScheduleList"].DefaultView;
}
return 0;
}
private void ViewScheduleButton_Click(object sender, System.EventArgs e)
{
DateTime GivenDay = DateTime.Parse(SelectDay.Text.Trim());
Fill_dayview(GivenDay);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -