//基于C# winform
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Opacity += 0.01;
}
private void button1_Click(object sender, EventArgs e)
{
Button btn1 = (Button)sender;
MessageBox.Show("hello world");
}
//当窗体加载时,隐藏掉不必要的程序
private void Form1_Load(object sender, EventArgs e)
{
//功能
btnlrxx.Visible = false;
btnpwdf.Visible = false;
btnsjcx.Visible = false;
btnfscl.Visible = false;
btnzjsj.Visible = false;
ex.Visible = false;
//1
xs1.Visible = false;
bh1.Visible = false;
name1.Visible = false;
addbh1.Visible = false;
addname1.Visible = false;
bc1.Visible = false;
panel2.Visible = false;
//2
xs2.Visible = false;
panel1.Visible = false;
xs3.Visible = false;
bc2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
}
//判断登陆是否成功
private void btnLogin_Click(object sender, EventArgs e)
{
//获得用户输入的用户名和密码
string userName = txtName.Text;
string userPwd = txtPwd.Text;
if(userName == "yyq"&& userPwd =="yyq")
{
MessageBox.Show("登陆成功");
label1.Visible = false;
label2.Visible = false;
txtName.Visible = false;
txtPwd.Visible = false;
btnLogin.Visible = false;
btnRest.Visible = false;
btnlrxx.Visible = true;
btnpwdf.Visible = true;
btnsjcx.Visible = true;
btnfscl.Visible = true;
btnzjsj.Visible = true;
ex.Visible = true;
xs1.Visible = false;
bh1.Visible = false;
name1.Visible = false;
addbh1.Visible = false;
addname1.Visible = false;
bc1.Visible = false;
xs2.Visible = false;
panel1.Visible = false;
xs3.Visible = false;
bc2.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
}
else
{
MessageBox.Show("用户名不存在或密码错误");
txtName.Clear();
txtPwd.Clear();
txtName.Focus();
}
}
private void btnRest_Click(object sender, EventArgs e)
{
txtName.Clear();
txtPwd.Clear();
txtName.Focus();
}
//文件读取 文件录入
private void btnlrxx_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择要打开的文本";
//不设置多选
ofd.InitialDirectory = @"E:\";
// ofd.Filter = "文本文件丨*.txt丨所有文件丨*.*";
ofd.ShowDialog();
//获得选中文件路径
string path = ofd.FileName;
using (FileStream fsRead = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))
{
byte[] buffer = new byte[1024 * 1024 * 3];
int r = fsRead.Read(buffer, 0, buffer.Length);
xs1.Text = System.Text.Encoding.Default.GetString(buffer, 0, r);
}
xs1.Visible = true;
bh1.Visible = false;
name1.Visible = false;
addbh1.Visible = false;
addname1.Visible = false;
bc1.Visible = false;
xs2.Visible = false;
panel1.Visible = false;
xs3.Visible = false;
bc2.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
}
//退出系统
private void ex_Click(object sender, EventArgs e)
{
this.Close();
}
//评委打分 打开文件
private void btnpwdf_Click(object sender, EventArgs e)
{
OpenFileDialog offd = new OpenFileDialog();
offd.Title = "请选择要打开的文本";
//不设置多选
offd.InitialDirectory = @"E:\";
// ofd.Filter = "文本文件丨*.txt丨所有文件丨*.*";
offd.ShowDialog();
//获得选中文件路径
string path = offd.FileName;
using (FileStream fsRead = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))
{
byte[] buffer = new byte[1024 * 1024 * 3];
int r = fsRead.Read(buffer, 0, buffer.Length);
xs3.Text = System.Text.Encoding.Default.GetString(buffer, 0, r);
}
xs2.Visible = true;
panel1.Visible = true;
xs3.Visible = true;
bc2.Visible = true;
bh1.Visible = false;
name1.Visible = false;
addbh1.Visible = false;
addname1.Visible = false;
bc1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
}
//分数保存 保存2
private void bc2_Click(object sender, EventArgs e)
{
System.IO.FileInfo file = new System.IO.FileInfo(@"E:\234.txt");
if (file.Exists)//文件是否存在,存在则执行删除
file.Delete();
using (FileStream fsWrite = new FileStream(@"E:\234.txt", FileMode.Append, FileAccess.Write))
{
byte[] buffer1 = System.Text.Encoding.Default.GetBytes(xs2.Text.Trim() );
// System.T.Encoding.Default.GetBytes(xs2.Text.Trim());
fsWrite.Write(buffer1, 0, buffer1.Length);
}
MessageBox.Show("保存成功");
}
//追加数据
private void btnzjsj_Click(object sender, EventArgs e)
{
bh1.Visible = true;
name1.Visible = true;
addbh1.Visible = true;
addname1.Visible = true;
bc1.Visible = true;
panel2.Visible = false;
panel4.Visible = false;
}
private void bc1_Click(object sender, EventArgs e)
{
using (FileStream fsWrite = new FileStream(@"E:\1234.txt", FileMode.Append, FileAccess.Write))
{
byte[] buffer1 = System.Text.Encoding.Default.GetBytes(addbh1.Text + " ");
fsWrite.Write(buffer1, 0, buffer1.Length);
byte[] buffer2 = System.Text.Encoding.Default.GetBytes(addname1.Text + "\r\n");
fsWrite.Write(buffer2, 0, buffer2.Length);
}
MessageBox.Show("保存成功");
addbh1.Clear();
addname1.Clear();
addbh1.Focus();
}
double[,] num = new double[1000, 10];
double[] sum1 = new double[1000];
double[] ave1 = new double[1000];
//分数处理
private void btnfscl_Click(object sender, EventArgs e)
{
panel2.Visible = true;
panel3.Visible = true;
panel4.Visible = false;
}
//总分
private void sum_Click(object sender, EventArgs e)
{
xssum.Clear();
xsave.Clear();
List<string> listString = new List<string>();
FileStream aFile = new FileStream(@"E:\234.txt", FileMode.Open);
StreamReader sr = new StreamReader(aFile, Encoding.GetEncoding("gb2312"));
string strLine = sr.ReadLine();
while (strLine != null)
{
listString.Add(strLine);
strLine = sr.ReadLine();
}
sr.Close();
for (int h = 0; h < listString.Count; h++)
{
string[] stringOne = listString[h].Split(' ');//将一行数组解析到一个字符串数组中
double maxn, minx;
num[h, 0] = Convert.ToDouble(stringOne[0]);
maxn = num[h, 0];
minx = num[h, 0];
sum1[h] =num[h, 0];
for (int k = 1; k < stringOne.Length; k++)
{
num[h, k] = Convert.ToDouble (stringOne[k]);
sum1[h] += num[h, k];
if (num[h, k] > maxn)
maxn = num[h, k];
if (num[h, k] < minx)
minx = num[h, k];
}
sum1[h] = sum1[h] - maxn - minx;//总分
ave1[h] = sum1[h] / 8;//平均分
xssum.Text += sum1[h]+"\r\n";
xsave.Text += ave1[h] + "\r\n";
}
}
int zp;
string[] bh = new string[1000];
string[] name = new string[1000];
private void px_Click(object sender, EventArgs e)
{
xspx.Clear();
List<string> listString = new List<string>();
FileStream aFile = new FileStream(@"E:\1234.txt", FileMode.Open);
StreamReader sr = new StreamReader(aFile, Encoding.GetEncoding("gb2312"));
string strLine = sr.ReadLine();
while (strLine != null)
{
listString.Add(strLine);
strLine = sr.ReadLine();
}
sr.Close();
int i;
for ( i = 0; i < listString.Count; i++)
{
string[] stringOne = listString[i].Split(' ');//将一行数组解析到一个字符串数组中
bh[i] = stringOne[0];
name[i] = stringOne[1];
}
zp = i;
double temp;
double sum2;
string yyq=" ",yy=" ";
for (i = 0; i <zp-1 ; i++) //进行n-1趟
for (int j = 0; j < zp-1 ; j++)
if (ave1[j] < ave1[j + 1])
{
temp = ave1[j + 1];
yyq = bh[j + 1];
yy = name[j + 1];
sum2 = sum1[j + 1];
ave1[j + 1] = ave1[j];
bh[j + 1] = bh[j];
name[j + 1] = name[j];
sum1[j + 1] = sum1[j];
ave1[j] = temp;
bh[j] = yyq;
name[j] = yy;
sum1[j] = sum2;
}
for (i = 0; i < zp; i++) //遍历输出\
{
xspx.Text += bh[i] + " " + name[i] + " " + sum1[i] + " " + ave1[i] + "\r\n";
//x+= bh[i] + " " + name[i] + "\r\n";
}
}
private void btnsjcx_Click(object sender, EventArgs e)
{
xs1.Visible = false;
bh1.Visible = false;
name1.Visible = false;
addbh1.Visible = false;
addname1.Visible = false;
bc1.Visible = false;
xs2.Visible = false;
panel1.Visible = false;
xs3.Visible = false;
bc2.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = true;
}
private void bhcx_Click(object sender, EventArgs e)
{
string searchbh = srbh.Text;
bool b = true;
for (int i = 0; i < zp; i++)
{
if (bh[i] == searchbh)
{
b = false;
xsxx2.Clear();
xsxx2.Text += bh[i] + " " + name[i] + " " + sum1[i] + " " + ave1[i];//输出
}
}
if (b == true)
{
//没找到
MessageBox.Show("输入编号有误!!!!");
}
}
private void srbh_TextChanged(object sender, EventArgs e)
{
}
private void xsxx2_TextChanged(object sender, EventArgs e)
{
}
private void xmcx_Click(object sender, EventArgs e)
{
string searchname = srbh.Text;
bool b = true;
for (int i = 0; i < zp; i++)
{
if (name[i] == searchname)
{
b = false;
xsxx2.Clear();
xsxx2.Text += bh[i] + " " + name[i] + " " + sum1[i] + " " + ave1[i];//输出
}
}
if (b == true)
{
//没找到
MessageBox.Show("输入姓名有误!!!");
}
}
private void pw4_Click(object sender, EventArgs e)
{
}
}
}