1、Github项目地址:https://github.com/saodan/PairProgramming
2、结对伙伴博客:https://www.cnblogs.com/saodan
3、结对PSP表格
PSP | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 10min | 15min |
· Estimate | · 估计这个任务需要多少时间 | 5h | 5h+ |
Development | 开发 | 4h | 3h |
· Analysis | · 需求分析 (包括学习新技术) | 1h | 1h |
· Design Spec | · 生成设计文档 | 10min | 10min |
· Design Review | · 设计复审 (和同事审核设计文档) | 8min | 10min |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 30min | 25min |
· Design | · 具体设计 | 45min | 45min |
· Coding | · 具体编码 | 4h | 5h+ |
· Code Review | · 代码复审 | 40min | 35min |
· Test | · 测试(自我测试,修改代码,提交修改) | 1h | 1h30min |
Reporting | 报告 | 8min | 10min |
· Test Report | · 测试报告 | 5min | 5min |
· Size Measurement | · 计算工作量 | 15min | 15min |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 20min | 20min |
合计 | 1091min | 1120min+ |
设计结构图:
和伙伴一起讨论:
4、具体设计
(1)导入学生名单
code
OpenFileDialog op = new OpenFileDialog();
op.Filter = "Excel(97-2003)文件|*.xls|所有文件|*.*";
op.Title = "打开文件夹";
string path = null;
op.InitialDirectory = "d:\\";//最初从D盘开始查找文件,测试文件放置于本文件夹。
op.FilterIndex = 1;
if (op.ShowDialog() == DialogResult.OK)//判断路径是否正确
{
path = op.FileName;
}
string name = GetExcelFile.GetFile(path);//获取Excel文件。
string Tsql = "SELECT * FROM [" + name + "]";
DataTable table = ExcelToDataTable.Redatatable(path, Tsql).Tables[0];//将Excel转换为dataset类型并赋值于table
/*获取文件名*/
public static class GetExcelFile
{
public static string GetFile(string path)
{
string name = null;
if (File.Exists(path))
{
using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Ace.OleDb.12.0;Persist Security Info=False;" + "data source=" + path + ";Extended Properties='Excel 12.0; HDR=yes; IMEX=2'"))
{
conn.Open();
name = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0][2].ToString().Trim();
}
}
return name;
}
}
/*将Excel类型转换成datatable*/
public static DataSet Redatatable(string path,string Tsql)
{
DataSet ds;
string strcon = "Provider=Microsoft.Ace.OleDb.12.0;Persist Security Info=False;" + "data source=" + path + ";Extended Properties='Excel 12.0; HDR=yes; IMEX=2'";
OleDbConnection mycon = new OleDbConnection(strcon);
mycon.Open();
OleDbDataAdapter myconn = new OleDbDataAdapter(Tsql, strcon);
ds = new DataSet();
myconn.Fill(ds);
mycon.Close();
return ds;
}
说明:
运用OpenFileDialog控件打开文件
运用OLedb连接Excel,并将Excel表中的信息填充到datatable表中
(2)建立学生信息的数据字典
code
stuList = studentList.StudentList(table);//将学生信息存储到字典中
public static class studentList
{
public static Dictionary StudentList(DataTable data)
{
Dictionary stuList = new Dictionary();
for (int i = 1; i < data.Rows.Count; i++)
{
stuList.Add(i, data.Rows[i][1].ToString());
}
return stuList;
}
}
(3)随机点名并记录缺课名单
code
string path1 = @"E:/";
filepath = path1 + System.DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString().Replace(":", "-") + "缺课名单" + ".xls";//缺课学生文件命名
private void timerCallname_(object sender, EventArgs e)
{
Random random = new Random();
int t = random.Next(1, stuList.Count + 1);
label1.Text = stuList[t];
}
private void label1_Click(object sender, EventArgs e)
{
DialogResult re = MessageBox.Show(string.Format("{0}是否缺席。", label1.Text),"提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (re == DialogResult.Yes)
{
WriteOutStu.Class1.Write(filepath, label1.Text.ToString());//将缺课学生导出为Excel文件
}
}
public static void Write(string Path,string str)
{
FileStream datafile = new FileStream(Path, FileMode.Append, FileAccess.Write);
string data = string.Format("{0}\t缺席\n",str);
StreamWriter writer = new StreamWriter(datafile, Encoding.GetEncoding("gb2312"));
writer.Write(data);
writer.Flush();
writer.Close();
}
6、总结
伙伴在算法设计方便帮了我不少,在测试阶段代码规范上出了不少错误,然后重新审核编写,也花了不少时间,也为今后的学习,代码算法设计积累了不少经验。结对编程也是两人之间的协作,间接的为团队合作打了基础