排球教练助手:
计划:估计这个任务需要多长时间:9天。
生成设计文档:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//测试代码:
test mgr = new test();
mgr.WriteListToTextFile(mgr.GetUserNames(), @"c: est.txt"); //测试生成新的Txt文件
List<string> list = mgr.ReadTextFileToList(@"C: est.txt");//记取字符串
foreach (string s in list) Console.WriteLine(s); //显示出来′
Console.ReadKey(); //按′任一键关闭Console
/*
* 结果:
* JUQIASPNET
JUQIcapable
JUQIGuest
JUQIitd0300166
JUQIIUSR_PLSH166
JUQIIWAM_PLSH166
JUQISUPPORT_388945a0
*
* */
}
}
public class test
{
public List<String> GetUserNames()
{
ManagementClass mcs = new ManagementClass("Win32_UserAccount");
ManagementObjectCollection moc = mcs.GetInstances();
List<String> lstNames = new List<string>();
foreach (ManagementObject mo in moc)
{
lstNames.Add(Environment.UserDomainName + "\" + mo.GetPropertyValue("Name").ToString());
//domainName = mo.GetPropertyValue("Domain").ToString();
}
return lstNames;
}
//将List转换为TXT文件
public void WriteListToTextFile(List<string> list, string txtFile)
{
//创建一个文件流,用以写入或者创建一个StreamWriter
FileStream fs = new FileStream(txtFile, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
// 使用StreamWriter来往文件中写入内容
sw.BaseStream.Seek(0, SeekOrigin.Begin);
for (int i = 0; i < list.Count; i++) sw.WriteLine(list[i]);
//关闭此文件t
sw.Flush();
sw.Close();
fs.Close();
}
//读取文本文件转换为List
public List<string> ReadTextFileToList(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
List<string> list = new List<string>();
StreamReader sr = new StreamReader(fs);
//使用StreamReader类来读取文件
sr.BaseStream.Seek(0, SeekOrigin.Begin);
// 从数据流中读取每一行,直到文件的最后一行
string tmp = sr.ReadLine();
while (tmp != null)
{
list.Add(tmp);
tmp = sr.ReadLine();
}
//关闭此StreamReader对象
sr.Close();
fs.Close();
return list;
}
}
}
设计复审:和同学讨论。
具体设计:
具体编码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.IO;
namespace 排球
{
public partial class ZhuShou : Form
{
public ZhuShou()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
string ZhuGong111 = txtZhuGong1.Text;
string ZhuGong222 = txtZhuGong2.Text;
string FuGong111 = txtFuGong1.Text;
string FuGong222 = txtFuGong2.Text;
string JieYing111 = txtJieYing.Text;
string ErChuan111 = txtErChuan.Text;
string ZiYouRen111 = txtZiYouRen.Text;
if (string.IsNullOrEmpty(ZhuGong111)) { MessageBox.Show("请输入本场比赛的主攻手一"); }
else if (string.IsNullOrEmpty(FuGong111)) { MessageBox.Show("请输入本场比赛的副攻手一"); }
else if (string.IsNullOrEmpty(ZhuGong222)) { MessageBox.Show("请输入本场比赛的主攻手二"); }
else if (string.IsNullOrEmpty(FuGong222)) { MessageBox.Show("请输入本场比赛的副攻手二"); }
else if (string.IsNullOrEmpty(JieYing111)) { MessageBox.Show("请输入本场比赛的接应"); }
else if (string.IsNullOrEmpty(ErChuan111)) { MessageBox.Show("请输入本场比赛的二传"); }
else if (string.IsNullOrEmpty(ZiYouRen111)) { MessageBox.Show("请输入本场比赛的自由人"); }
else
{
groupBox1.Visible = false;
groupBox2.Visible = true;
linkZhuGong1.Text = ZhuGong1.Text + txtZhuGong1.Text;
linkFuGong1.Text=FuGong1.Text+txtFuGong1.Text;
linkZhuGong2.Text = ZhuGong2.Text + txtZhuGong2.Text;
linkFuGong2.Text = FuGong2.Text + txtFuGong2.Text;
linkJieYing.Text = JieYing.Text + txtJieYing.Text;
linkErChuan.Text = ErChuan.Text + txtErChuan.Text;
linkZiYouRen.Text = ZiYouRen.Text + txtZiYouRen.Text;
}
}
private void ZhouShou_Load(object sender, EventArgs e)
{
groupBox1.Visible = true;
groupBox2.Visible = false;
}
int i = 0;
private void button1_Click(object sender, EventArgs e)
{
i++;
txtFen.Text = lblName.Text + button1.Text + " " + i;
}
int FQ = 0;
private void btnFaQiu_Click(object sender, EventArgs e)
{
FQ++;
txtFen.AppendText(lblName.Text+btnFaQiu.Text+" "+FQ);
}
int KQ=0;
private void btnKouQiu_Click(object sender, EventArgs e)
{
KQ++;
txtFen.AppendText(lblName.Text + btnKouQiu.Text + " " + KQ);
}
int CW=0;
private void btnChouWang_Click(object sender, EventArgs e)
{
CW++;
txtFen.AppendText(lblName.Text + btnChouWang.Text + " " + CW);
}
int DQ = 0;
private void btnDiaoQiu_Click(object sender, EventArgs e)
{
DQ++;
txtFen.AppendText(lblName.Text + btnDiaoQiu.Text + " " + DQ);
}
int LWCJ = 0;
private void btnLWChuJie_Click(object sender, EventArgs e)
{
LWCJ++;
txtFen.AppendText(lblName.Text + btnLWChuJie.Text + " " + LWCJ);
}
int FQSW = 0;
private void btnFaQiuShiWu_Click(object sender, EventArgs e)
{
FQSW++;
txtFen.AppendText(lblName.Text + btnFaQiuShiWu.Text + " " + FQSW);
}
int KQCJ = 0;
private void btnKouQiuChuJie_Click(object sender, EventArgs e)
{
KQCJ++;
txtFen.AppendText(lblName.Text + btnKouQiuChuJie.Text + " " + KQCJ);
}
private void lastOK_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("C:\file.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.Flush();
m_streamWriter.BaseStream.Seek(0, SeekOrigin.Begin);
m_streamWriter.Write(txtFen.Text);
m_streamWriter.Close();
MessageBox.Show("保存成功!");
groupBox2.Visible = false;
groupBox1.Visible = true;
}
private void linkZhuGong1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
{
lblName.Text = linkZhuGong1.Text;
}
private void linkFuGong1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
lblName.Text = linkFuGong1.Text;
}
private void linkZhuGong2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
lblName.Text = linkZhuGong2.Text;
}
private void linkFuGong2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
lblName.Text = linkFuGong2.Text;
}
private void linkJieYing_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
lblName.Text = linkJieYing.Text;
}
private void linkErChuan_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
lblName.Text = linkErChuan.Text;
}
private void linkZiYouRen_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
lblName.Text = linkZiYouRen.Text;
}
代码复审:无。
总结:排球教练助手思路有些不正确,代码还有待完善,没有使用三成架构,数据库没有连接。