个人日程表
首先解决与SQL Server的连接问题:
主要有2点:
1.在SQL配置那里,启动TCP/IP(默认的是disable,要改为enable)
2. 在surface area configuration ,给TCP添加端口(默认没有端口,可以加端口1433)
(详细解决办法见:http://www.cnblogs.com/lin614/archive/2008/06/02/1211985.html)
form1.cs
1
using System;2
using System.Collections.Generic;3
using System.ComponentModel;4
using System.Data;5
using System.Drawing;6
using System.Linq;7
using System.Text;8
using System.Windows.Forms;9
using System.Data.SqlClient;10

11
namespace 个人日程表12


{13
public partial class Form1 : Form14

{15
private SqlConnection myConn;16
static string ConnString = "data source = (local);user id = sa;password = 71690202;database=SmartSchedule;";17

18
public Form1()19

{20
InitializeComponent();21
}22

23
private void button1_Click(object sender, EventArgs e)24

{25
DateTime GivenDay = DateTime.Parse(SelectDay.Text.Trim());26
//添加Fill_dayview27
Fill_dayview(GivenDay);28
}29

30

/**////<summary>31
///用于生成日视图32
///</summary>33
///<param name="GivenDay"></param>34
private int Fill_dayview(DateTime GivenDay)35

{36
DataSet DS_DayView = new DataSet();37
MySchedule DaySchedule = new MySchedule();38
if (!DaySchedule.GetScheduleByGivenDay(ref myConn, ref DS_DayView, ref GivenDay))39
return -1;40
int nScheduleCount = DS_DayView.Tables["ScheduleList"].Rows.Count;41
dg_dayview.DataSource = DS_DayView.Tables["ScheduleList"].DefaultView;42
return 0;43
}44

45
private void Form1_Load(object sender, EventArgs e)46

{47

/**////设置控件属性48
taskDateTimeSetupBox.CustomFormat = "hh:mm:ss yyyy年MM月dd日,dddd";49

50
myConn = new SqlConnection(ConnString);51
try52

{53
myConn.Open();54
}55
catch (System.Exception ee)56

{57
MessageBox.Show(ee.Message,"错误!");58
Application.Exit();59
}60

61
// Init_AddSchedulePage();62

63
if (Fill_dayview(DateTime.Now) == -1 || Fill_RemainView() == -1)64
Application.Exit();65
}66

67

/**///////////////////////////////////////////////////////////////////////////68
///<summary>69
///用于生成未完成事件视图70
///</summary>71
private int Fill_RemainView()72

{73
DataSet DS_Unfinished = new DataSet();74

75
MySchedule UnfinishedSchedule = new MySchedule();76

77
if (!UnfinishedSchedule.GetUnfinishedSchedule(ref myConn, ref DS_Unfinished))78
return -1;79

80
if (DS_Unfinished.Tables["ScheduleList"].Rows.Count > 0)81

{82
dataGridView1.DataSource = DS_Unfinished.Tables["ScheduleList"].DefaultView;83
}84

85
return 0;86
}87

88

89
}90
}
MySchedule.cs
1
using System;2
using System.Collections.Generic;3
using System.Linq;4
using System.Text;5
using System.Data;6
using System.Data.SqlClient;7

8
namespace 个人日程表9


{10
public class MySchedule11

{12
//无参构造函数,调用初始化方法13
public MySchedule()14

{15
//InitSchedule();16
}17

18
public MySchedule(ref MySchedule srcSchedule)19

{20
// InitSchedule();21
// TaskId = srcSchedule.GetTaskId();22
}23

24
//获取指定日期的日程25
public bool GetScheduleByGivenDay(ref SqlConnection myConn,ref DataSet ds,ref DateTime GivenDay)26

{27
SqlDataAdapter da = new SqlDataAdapter("GetScheduleByGivenDay", myConn);28
da.SelectCommand.CommandType = CommandType.StoredProcedure;29
da.SelectCommand.Parameters.Add("@GivenDay", GivenDay);30
try31

{32
da.Fill(ds, "ScheduleList");33
}34
catch35

{36
return false;37
}38
return true;39
}40

41
//获取未完成日程列表42
public bool GetUnfinishedSchedule(ref SqlConnection myConn, ref DataSet ds)43

{44
SqlDataAdapter da = new SqlDataAdapter("getUnfinishedSchedule", myConn);45
da.SelectCommand.CommandType = CommandType.StoredProcedure;46
try47

{48
da.Fill(ds, "ScheduleList");49
}50
catch51

{52
return false;53
}54
return true;55
}56
}57
}
简单界面
浙公网安备 33010602011771号