vs2013 +C#开发的演讲比赛简易打分系统, 可以实现录入选手名称 和评委分数,去掉最高分和最低分后求平均值 然后减去扣分,得到汇总分数.
下面附带"走马灯"字幕滚动和计时器功能.
功能很简单,附上源码,仅供参考,欢迎交流.
FORM1 控件截图
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//打分及排名
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
Dictionary<int, double> dic = new Dictionary<int, double>();
if (e.ColumnIndex > 0 && e.ColumnIndex < 12)
{
for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
{
if (i == 0)
{ }
else if (i == 12 || i == 11)
{
}
else
{
if (dataGridView1.Rows[e.RowIndex].Cells[i].Value != null)
{
string str = dataGridView1.Rows[e.RowIndex].Cells[i].Value.ToString();
double d;
if (double.TryParse(str, out d))
{
dic.Add(i, d);
}
else
{
dic.Add(i, 0);
}
}
else
{
dic.Add(i, 0);
}
}
}
double total = 0;
foreach (int key in dic.Keys)
{
total += dic[key];
}
if (this.dataGridView1.Rows[e.RowIndex].Cells[11].Value != null)
{
double d1;
if (double.TryParse(this.dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString(), out d1))
{
this.dataGridView1.Rows[e.RowIndex].Cells[12].Value = ((total - dic.Values.Max() - dic.Values.Min()) / 8) - d1;
}
else
{
this.dataGridView1.Rows[e.RowIndex].Cells[12].Value = ((total - dic.Values.Max() - dic.Values.Min()) / 8) - 0;
}
}
else
{
this.dataGridView1.Rows[e.RowIndex].Cells[12].Value = ((total - dic.Values.Max() - dic.Values.Min()) / 8) - 0;
}
}
}
//下面为计时加字幕滚动功能
private int t = 0;
public string GetAllTime(int time)
{
string mm, ss, fff;
int f = time % 60;//s
int s = time / 60;
int m = s / 60; //分
s = s % 60;//秒
if (f < 10)
{
fff = "0" + f.ToString();
}
else
{
fff = f.ToString();
}
//秒格式00
if (s < 10)
{
ss = "0" + s.ToString();
}
else
{
ss = s.ToString();
}
//分格式00
if (m < 10)
{
mm = "0" + m.ToString();
}
else
{
mm = m.ToString();
}
//返回 hh:mm:ss.ff
return mm + ":" + ss + ":" + fff;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void btnstar_Click(object sender, EventArgs e)
{
if (timer1.Enabled == false)
{
this.btnstar.Text = "暂停计时";
this.timer1.Enabled = true;
}
else {
this.btnstar.Text = "开始计时";
this.timer1.Enabled = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
t = t + 1;
this.textBox1.Text = GetAllTime(t);
}
private void btnclear_Click(object sender, EventArgs e)
{
t = 0;
//如果正在计时,则先停止再清零,否则直接清零
if (this.timer1.Enabled == true)
{
this.btnstar_Click(sender, e);
textBox1.Text = GetAllTime(t);
}
else
{
textBox1.Text = GetAllTime(t);
}
}
private void timer2_Tick(object sender, EventArgs e)
{
string tt = textBox2.Text;
string tt1 = tt.Substring(1);
string tt2 = tt1 + tt[0];
textBox2.Text = tt2;
//dataGridView1.CurrentCell.Value
}
private void button1_Click(object sender, EventArgs e)
{
if(timer2.Enabled==true)
{
button1.Text = "开始滚动字幕";
timer2.Enabled = false;
}
else
{
button1.Text = "暂停滚动字幕";
timer2.Enabled = true;
}
}
}
}
C#计时器和比赛简易打分winform