教学点名神器随机点名器文档格式.docx
《教学点名神器随机点名器文档格式.docx》由会员分享,可在线阅读,更多相关《教学点名神器随机点名器文档格式.docx(28页珍藏版)》请在冰豆网上搜索。
若点击差评或缺勤,记录会自动加一,而且,一旦选择之后,该两个按钮即被隐藏,防止误操作。
当然你也可以不行,直接抽下一个人,但选择按钮照样被隐藏,同样该学生的点名信息也会被记录。
重复抽取后所有记录都会自动保存到该文件。
如果点击确定,或关闭程序再次打开程序选择该班级,同样执行上述步骤,则记录会在原来的基础上累加。
经过一系列操作后得到的记录表如下:
当然,如果你选择其他班级,照样会执行相应的操作。
现在,举个典型的例子,我在桌面上新建一个文本文件,内容如下:
选择该文件,执行同样的操作,立即生成“2班点名记录清单.txt”文件。
重复点名后,实时记录的点名内容:
C#部分源程序:
(本软件完全由个人编写,未经本人允许,请勿用于商业目的)usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows.Forms;
usingSystem.IO;
usingSystem.Drawing.Drawing2D;
namespace随机抽样
{
publicpartialclassForm1:
Form
{
staticintstep=0;
staticboolStartload=false;
staticstring[]pathstudent={System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"
//"
"
电科一班.txt"
};
staticstring[]name=getName();
staticint[]ppp=GetRandomArray(name.Length);
publicForm1()
InitializeComponent();
Timert=newTimer();
t.Interval=2000;
t.Tick+=newEventHandler(changeBackground);
t.Start();
Timert2=newTimer();
t2.Interval=100;
t2.Tick+=newEventHandler(changestudent);
t2.Start();
}
staticintiiii=0;
voidchangestudent(objectsender,EventArgse)
if(name==null)
return;
if(this.startrand.Text=="
停止抽取"
)
iiii++;
this.disinf.Text=name[ppp[(step+iiii)%name.Length]];
int[]q=GetRandomArray(3);
int[]colorval={0,100,newRandom().Next(100)};
this.disinf.ForeColor=Color.FromArgb(255,colorval[q[0]],colorval[q[1]],colorval[q[2]]);
voidchangeBackground(objectsender,EventArgse)
//inti=DateTime.Now.Second/15;
switch(GetRandomArray(18)[0])
case0:
BackgroundImage=imageList1.Images[0];
break;
case1:
BackgroundImage=imageList1.Images[1];
case2:
BackgroundImage=imageList1.Images[2];
case3:
BackgroundImage=imageList1.Images[3];
case4:
BackgroundImage=imageList1.Images[4];
case5:
BackgroundImage=imageList1.Images[5];
case6:
BackgroundImage=imageList1.Images[6];
case7:
BackgroundImage=imageList1.Images[7];
case8:
BackgroundImage=imageList1.Images[8];
case9:
BackgroundImage=imageList1.Images[9];
case10:
BackgroundImage=imageList1.Images[10];
case11:
BackgroundImage=imageList1.Images[11];
case12:
BackgroundImage=imageList1.Images[12];
case13:
BackgroundImage=imageList1.Images[13];
case14:
BackgroundImage=imageList1.Images[14];
case15:
BackgroundImage=imageList1.Images[15];
case16:
BackgroundImage=imageList1.Images[16];
case17:
BackgroundImage=imageList1.Images[17];
default:
privatevoidstartrand_Click(objectsender,EventArgse)//开始暂停按钮
this.button1.Visible=false;
this.button2.Visible=false;
//获取对比度大的随机深彩色
int[]colorval={170,255,newRandom().Next(80)+170};
startrand.FlatAppearance.MouseOverBackColor=Color.FromArgb(255,colorval[q[0]],colorval[q[1]],colorval[q[2]]);
//随机设置鼠标悬停在按钮上的颜色
startrand.FlatAppearance.MouseDownBackColor=Color.FromArgb(255,colorval[q[0]]-50,colorval[q[1]]-50,colorval[q[2]]-50);
//随机设置鼠标按下按钮后的颜色
try
开始抽取"
)//判断字符串检测鼠标是否按下
this.startrand.Text="
;
//如果按下,将字符串的颜色修改
else
String[]abcd={"
"
StreamWritersw;
step=step+1;
this.disinf.Text=name[ppp[step-1]];
if(Startload==true)
abcd=File.ReadAllLines(pathstudent[0]+pathstudent[1].Replace("
.txt"
"
点名记录清单.txt"
));
//编码格式
catch
sw=File.AppendText(pathstudent[0]+pathstudent[1].Replace("
sw.Write(pathstudent[1].Replace("
)+"
点名记录清单"
+"
创建日期:
+DateTime.Today.ToString("
yyyy"
年"
MM"
月"
dd"
日"
随机点名器原创者:
陈鹏"
\r\n"
);
sw.Write("
学生姓名(学号)"
.PadRight(30-8,'
'
被点次数"
.PadRight(20-4,'
缺勤次数"
老师不满意次数\r"
sw.Close();
abcd=Array.FindAll(abcd,line=>
!
string.IsNullOrEmpty(line));
//去除是null或是"
的string
stringn;
n=findn(abcd,this.disinf.Text);
if(n=="
1"
\n"
+this.disinf.Text.PadRight(30,'
)+n.PadRight(20,'
0"
.PadRight(20,'
.PadRight(5,'
\r"
//string1.PadLeft(100,"
"
)这句话的意思是如果string1的长度不够100位,则在前面加空格,知道补够100位。
)+n+"
//sw.Flush();
this.button1.Visible=true;
this.button2.Visible=true;
this.disinf.Text="
木有了咦(;
′⌒`)"
MessageBox.Show("
人已经抽完了,重新开始吧?
ppp=GetRandomArray(name.Length);
//重新排序
step=0;
iiii=0;
stringfindn(string[]f,stringw)
intn=1;
stringa;
for(inti=0;
i<
f.Length;
i++)//查找文件夹中是否存在该学生的信息
a=f[i].Substring(0,w.Length);
//从第m个位置,截取n个长度
if(a==w)//如果找到了学生的信息,刷新学生的得分
a=f[i].Substring(25,10).Replace("
n=Convert.ToInt32(a);
StreamWritersw=newStreamWriter(pathstudent[0]+pathstudent[1].Replace("
),false);
for(intj=0;
j<
j++)
if(i!
=j)
sw.WriteLine(f[j]);
//sw.Dispose();
return(n+1).ToString().PadRight(20,'
)+f[i].Substring(50,25);
continue;
returnn.ToString();
staticint[]GetRandomArray(intlength)//获取一个随机数组,元素长度为1~length,值包含1~length
double[]rnds=newdouble[length];
int[]num=newint[length];
int[]newNum=newint[num.Length];
length;
i++)
num[i]=i;
List<
int>
numCopy=newList<
();
foreach(intiinnum)
numCopy.Add(i);
Randomrandom=newRandom();
num.Length;
intselectedIndex=random.Next(num.Length-i);
newNum[i]=numCopy[selectedIndex];
numCopy.RemoveAt(selectedIndex);
returnnewNum;
staticstring[]getName()//程序打开后,获取姓名列表
//stringstr=System.Windows.Forms.Application.StartupPath;
String[]lines=File.ReadAllLines(pathstudent[0]+pathstudent[1],Encoding.Default);
//读取可执行文件路径下的txt文件
lines=Array.FindAll(lines,line=>
returnlines;
catch//如果路径文件搜索失败,则赋值如下语句。
string[]lines={"
貌似没找到你想要的文件哦!
2015年5月"
湖北工业大学"
随机点名器"
▽D=ρ"
▽×
D=0"
π=3.14159265358979323846264338328"
电气学院"
电科一班"
pathstudent=null;
privatevoiddisinf_TextChanged(objectsender,EventArgse)
privatevoidForm1_Load(objectsender,EventArgse)
privatevoidbtnchooseclass_Click(objectsender,EventArgse)//如果点击了选择班级按钮
OpenFileDialogdlg=newOpenFileDialog();
//就打开一个对话框,让你选择班级文件
if(dlg.ShowDialog()==System.Windows.Forms.DialogResult.OK)//如果选好了文件,并点击了确定按钮
if(File.ReadAllLines(@dlg.FileName,Encoding.Default).Length!
=0)//如果文件内容不为空
name=File.ReadAllLines(@dlg.FileName,Encoding.Default);
//逐行读入所有的内容,更新变量name;
name=Array.FindAll(name,line=>
//初始化点名次数
btnchooseclass.Visible=false;
//一般该按钮只会用一次,故使用后将其隐藏,避免占用空间。
pathstudent[1]=dlg.SafeFileName;
pathstudent[0]=dlg.FileName.Remove(dlg.FileName.Length-pathstudent[1].Length);
privatevoidbutton1_Click(objectsender,EventArgse)
String[]abcd={"
};
n=findqueqing(abcd,this.disinf.Text);
+n+"
stringfindqueqing(string[]f,stringw)
i