基本信息
源码名称:统计棋类比赛个人积分
源码大小:1.68M
文件格式:.rar
开发语言:C#
更新时间:2015-11-25
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel;
using System.IO;
namespace Master
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
//string Path = "C:\\Documents and Settings\\Administrator\\桌面\\scores.xls";
if (label2.Text == "")
{
MessageBox.Show("请先选择目标文件!","提示");
return;
}
if (textBox1.Text == "")
{
MessageBox.Show("请导入成绩文件!", "提示");
return;
}
if (comboBox1.Text == "")
{
MessageBox.Show("请选择棋类!", "提示");
return;
}
string Path = label2.Text;
Excel.Application excel = new Excel.Application();
Excel.Workbook wb = null;
Excel.Worksheet ws = null;
excel.UserControl = true;
object Nothing = System.Reflection.Missing.Value;
wb=excel.Application.Workbooks.Open(Path, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
ws=(Excel.Worksheet)wb.Worksheets["Sheet1"];
int rowCount=ws.UsedRange.Rows.Count;
int colCount=ws.UsedRange.Columns.Count;
if(rowCount<=1)
{
MessageBox.Show("文件中没有队员姓名记录!", "提示");
return;
}
object ran = "F" rowCount.ToString();
Excel.Range rang1 = excel.get_Range("A2", ran);
rang1.NumberFormatLocal = "G/通用格式";
rang1.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; //左对齐
string ls_vic = string.Empty;
string ls_lose = string.Empty;
string ls_tie = string.Empty;
string vic_sum=string.Empty;
string lose_sum=string.Empty;
for (int i = 2; i <= rowCount; i )
{
Range curentCell = (Range)ws.Cells[i, 1];
string name = curentCell.Text.ToString().Trim(); //单元格文本
if (comboBox1.Text == "围棋")
{
string wins;
string lose;
string ls_sum = check(name, out wins,out lose);
if (ls_sum != "" && ls_sum != "0|0")
{
ls_vic = ls_sum.Substring(0, ls_sum.IndexOf("|"));
ls_lose = ls_sum.Substring(ls_sum.IndexOf("|") 1);
if (ls_vic != "0")
{
curentCell = (Range)ws.Cells[i, 2];
vic_sum = curentCell.Text.ToString();
if (vic_sum == "")
vic_sum = "0";
int li_v_sum = int.Parse(vic_sum) int.Parse(ls_vic);
ws.Cells[i, 2] = li_v_sum.ToString();
}
if (ls_lose != "0")
{
curentCell = (Range)ws.Cells[i, 3];
lose_sum = curentCell.Text.ToString();
if (lose_sum == "")
lose_sum = "0";
int li_v_lose = int.Parse(lose_sum) int.Parse(ls_lose);
ws.Cells[i, 3] = li_v_lose.ToString();
}
wins = wins.TrimStart();
lose = lose.TrimStart();
wins = wins.Replace(" ", "");
lose = lose.Replace(" ", "");
wins = wins.Replace(".", "");
lose = lose.Replace(".", "");
wins = wins.Replace(":", "");
lose = lose.Replace(":", "");
wins = wins.Replace("(", "");
lose = lose.Replace("(", "");
wins = wins.Replace("台", "");
lose = lose.Replace("台", "");
curentCell = (Range)ws.Cells[i, 5];
ws.Cells[i, 5] = curentCell.Text wins;
curentCell = (Range)ws.Cells[i, 6];
ws.Cells[i, 6] = curentCell.Text lose;
}
}
else //象棋
{
string ls_sum = check_xq(name);
if (ls_sum != "" && ls_sum != "0|0||0")
{
ls_vic = ls_sum.Substring(0, ls_sum.IndexOf("|"));
ls_tie = ls_sum.Substring(ls_sum.IndexOf("|") 1,ls_sum.IndexOf("||")-2);
ls_lose = ls_sum.Substring(ls_sum.IndexOf("||") 2);
if (ls_vic != "0")
{
curentCell = (Range)ws.Cells[i, 2];
vic_sum = curentCell.Text.ToString();
if (vic_sum == "")
vic_sum = "0";
int li_v_sum = int.Parse(vic_sum) int.Parse(ls_vic);
ws.Cells[i, 2] = li_v_sum.ToString();
}
if (ls_tie != "0")
{
curentCell = (Range)ws.Cells[i, 3];
vic_sum = curentCell.Text.ToString();
if (vic_sum == "")
vic_sum = "0";
int li_v_sum = int.Parse(vic_sum) int.Parse(ls_tie);
ws.Cells[i, 3] = li_v_sum.ToString();
}
if (ls_lose != "0")
{
curentCell = (Range)ws.Cells[i, 4];
vic_sum = curentCell.Text.ToString();
if (vic_sum == "")
vic_sum = "0";
int li_v_sum = int.Parse(vic_sum) int.Parse(ls_lose);
ws.Cells[i, 4] = li_v_sum.ToString();
}
}
}
}
//排序
rang1.Sort(
rang1.Columns[2, Nothing], Excel.XlSortOrder.xlDescending,
rang1.Columns[3, Nothing], Nothing, Excel.XlSortOrder.xlAscending,
Nothing, Excel.XlSortOrder.xlAscending,
Excel.XlYesNoGuess.xlNo, Nothing, Nothing,
Excel.XlSortOrientation.xlSortColumns,
Excel.XlSortMethod.xlPinYin,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal);
excel.Visible = true;
}
private string check(string name,out string Wins,out string Lose)
{
Wins = "";
Lose = "";
string ls_input=textBox1.Text;
if (ls_input == "")
return "";
//去掉空格
name = name.Replace(" ","");
ls_input = ls_input.Replace("(主)", "");
ls_input = ls_input.Replace("(主)", "");
ls_input = ls_input.Replace("(快)", "");
ls_input = ls_input.Replace("(快)", "");
ls_input = ls_input.Replace("初段", "");
ls_input = ls_input.Replace("一段", "");
ls_input = ls_input.Replace("二段", "");
ls_input = ls_input.Replace("三段", "");
ls_input = ls_input.Replace("四段", "");
ls_input = ls_input.Replace("五段", "");
ls_input = ls_input.Replace("六段", "");
ls_input = ls_input.Replace("七段", "");
ls_input = ls_input.Replace("八段", "");
ls_input = ls_input.Replace("九段", "");
ls_input = ls_input.Replace("1段", "");
ls_input = ls_input.Replace("2段", "");
ls_input = ls_input.Replace("3段", "");
ls_input = ls_input.Replace("4段", "");
ls_input = ls_input.Replace("5段", "");
ls_input = ls_input.Replace("6段", "");
ls_input = ls_input.Replace("7段", "");
ls_input = ls_input.Replace("8段", "");
ls_input = ls_input.Replace("2:0", "胜");
ls_input = ls_input.Replace("0:2", "负");
ls_input = ls_input.Replace("0", "");
ls_input = ls_input.Replace("1", "");
ls_input = ls_input.Replace("2", "");
ls_input = ls_input.Replace("3", "");
ls_input = ls_input.Replace("4", "");
ls_input = ls_input.Replace("5", "");
ls_input = ls_input.Replace("6", "");
ls_input = ls_input.Replace("7", "");
ls_input = ls_input.Replace("8", "");
ls_input = ls_input.Replace("9", "");
ls_input = ls_input.Replace("*", "");
ls_input = ls_input.Replace("(微博)", "");
ls_input = ls_input.Replace("(微博)", "");
ls_input = ls_input.Replace("[微博]", "");
ls_input = ls_input.Replace("\t", "");
ls_input = ls_input.Replace(" ", "");
int li_vic=0, li_lose=0;
string ls_name = name "胜";
int matchNumber = 0;
int currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
Wins = Wins ls_input.Substring(ls_input.IndexOf(ls_name) ls_name.Length, 3) ",";
}
li_vic = li_vic matchNumber;
ls_name ="负" name ;
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
Wins = Wins ls_input.Substring(ls_input.IndexOf(ls_name) -3, 3) ",";
}
li_vic = li_vic matchNumber;
ls_name = name "负";
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
Lose = Lose ls_input.Substring(ls_input.IndexOf(ls_name) ls_name.Length, 3) ",";
}
li_lose = li_lose matchNumber;
ls_name = "胜" name;
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
Lose = Lose ls_input.Substring(ls_input.IndexOf(ls_name) -3, 3) ",";
}
li_lose = li_lose matchNumber;
//胜负
string sf = li_vic.ToString() "|" li_lose.ToString();
return sf;
}
private string check_xq(string name)
{
string ls_input = textBox1.Text;
if (ls_input == "")
return "";
//去掉空格
name = name.Replace(" ", "");
ls_input = ls_input.Replace("\t", "");
ls_input = ls_input.Replace(":", "-");
ls_input = ls_input.Replace(":", "-");
ls_input = ls_input.Replace(" ", "");
int li_vic = 0;
int li_lose = 0;
int li_tie = 0;
string ls_name = name "1-";
int matchNumber = 0;
int currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
}
li_vic = li_vic matchNumber;
ls_name = "-1" name;
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
}
li_vic = li_vic matchNumber;
ls_name = name "0.5-";
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
}
li_tie = li_tie matchNumber;
ls_name = "-0.5" name;
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
}
li_tie = li_tie matchNumber;
ls_name = name "0-";
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
}
li_lose = li_lose matchNumber;
ls_name = "-0" name;
matchNumber = 0;
currentPos = 0;
while (ls_input.IndexOf(ls_name, currentPos) != -1)
{
currentPos = ls_input.IndexOf(ls_name, currentPos) 1;
matchNumber ;
}
li_lose = li_lose matchNumber;
//胜平负
string sf = li_vic.ToString() "|" li_tie.ToString() "||" li_lose.ToString();
return sf;
}
private void button1_Click(object sender, EventArgs e)
{
//FileDialog dlgOpenFile = new OpenFileDialog();
//dlgOpenFile.Filter = "word 文件|*.doc";
//if (dlgOpenFile.ShowDialog() == DialogResult.OK)
//{
// object filename = dlgOpenFile.FileName;
// object nothing = System.Reflection.Missing.Value;
// object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
// object originalFormat = Word.WdOriginalFormat.wdWordDocument;
// object routeDocument = true;
// try
// {
// //word导入
// Word._Application app = new Word.ApplicationClass();
// app.Visible = false;
// Word.Document doc = app.Documents.Add(ref filename, ref nothing, ref nothing, ref nothing);
// textBox1.Clear();
// textBox1.Text = doc.Content.Text;
// doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
// app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
// }
FileDialog dlgOpenFile = new OpenFileDialog();
dlgOpenFile.Filter = "文本文件|*.txt";
if (dlgOpenFile.ShowDialog() == DialogResult.OK)
{
string filename = dlgOpenFile.FileName;
try
{
StreamReader sr = new StreamReader(filename, Encoding.GetEncoding("GB2312"));
textBox1.Clear();
textBox1.Text =sr.ReadToEnd();
}
catch (IOException ex)
{
MessageBox.Show(ex.Message, "导入错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
string ls_help = string.Empty;
ls_help = "\r\n\r\n 欢迎使用胜负师软件!\r\n \r\n 该软件自动统计联赛中运动员个人成绩(胜平负场次),尤其适用于棋类等个人比赛项目。\r\n\r\n";
ls_help = " 创建一个Excel文件,该文件有六列(或七列),第一行为姓名,胜,平,负、队名、所胜、所\r\n \r\n负(围棋只有胜负)。从第二行开始,在姓名一列填上所有参加联赛的运动员的姓名备用。";
ls_help = "程序运行\r\n \r\n时最好关闭该文件,以免产生副本文件。\r\n\r\n";
ls_help = " 开始统计前,选择刚创建的Excel文件作为目标文件,用来存放统计结果。再把如下形式的成绩\r\n\r\n文件(文本文件)导入或直接粘贴到文本框,";
ls_help ="然后点统计按钮,稍后就会看到生成的Excel文件,已按\r\n\r\n胜场数排好序,保存即可。";
ls_help = "成绩文件的格式:\r\n\r\n";
ls_help = "围棋格式: \r\n\r\n";
ls_help = " 围甲第1轮赛果(队伍名后面括号内的数字为各队本轮积分)\r\n\r\n";
ls_help = " 贵州百灵(3) 3比1胜 重庆冷酸灵(0)\r\n\r\n";
ls_help = " 1 彭立峣 胜 谢赫\r\n\r\n";
ls_help = " 2 李喆 负 古力(主)\r\n\r\n";
ls_help = " 3 时越 胜 王檄(快)\r\n\r\n";
ls_help = " 4 朴文垚 胜 李轩豪\r\n\r\n";
ls_help = " 山东景芝酒业(2) 2比2主将胜 爱慕先生(1)\r\n\r\n";
ls_help = " 1 陶忻 胜 张强(快)\r\n\r\n";
ls_help = " 2 周睿羊 胜 范廷钰(主)\r\n\r\n";
ls_help = " 3 周鹤洋 负 毛睿龙\r\n\r\n";
ls_help = " 4 江维杰 负 童梦成\r\n\r\n";
ls_help = " ......\r\n\r\n";
ls_help = "国际象棋或中国象棋格式:\r\n\r\n";
ls_help = " 北京爱国者队 1.5-3.5 江苏蓝珀通信队\r\n\r\n";
ls_help = " 余泱漪 1-0 徐俊\r\n\r\n";
ls_help = " 李超 0-1 余瑞源\r\n\r\n";
ls_help = " 修德顺 0.5-0.5 韦奕\r\n\r\n";
ls_help = " 赵雪 0-1 沈阳\r\n\r\n";
ls_help = " 王珏 0-1 郭琦\r\n\r\n";
ls_help = " ......\r\n\r\n";
ls_help = "或 \r\n\r\n";
ls_help = " 北京爱国者队 1.5-3.5 江苏蓝珀通信队\r\n\r\n";
ls_help = " 余泱漪 1:0 徐俊\r\n\r\n";
ls_help = " 李超 0:1 余瑞源\r\n\r\n";
ls_help = " 修德顺 0.5:0.5 韦奕\r\n\r\n";
ls_help = " 赵雪 0:1 沈阳\r\n\r\n";
ls_help = " 王珏 0:1 郭琦\r\n\r\n";
ls_help = " ......\r\n\r\n";
ls_help = " 成绩可以每轮统计,自动累积;也可以把多轮次成绩文件一次性导入,一起统计。\r\n\r\n";
ls_help = " 需要注意的是成绩文件中的运动员姓名应和目标文件中的姓名完全一致,避免错白字。\r\n\r\n";
ls_help = " 点击帮助关闭该帮助文件。 \r\n\r\n";
ls_help = " 联系方式:dbtiger123@163.com 石家庄 李双虎 于2011年 5月 \r\n\r\n";
textBox1.Text = ls_help;
}
else
{
textBox1.Clear();
textBox1.Focus();
}
}
private void button4_Click(object sender, EventArgs e)
{
FileDialog dlgOpenFile = new OpenFileDialog();
dlgOpenFile.Filter = "Excle 文件|*.xls";
if (dlgOpenFile.ShowDialog() == DialogResult.OK)
{
string filename = dlgOpenFile.FileName.ToString();
label2.Text = filename;
}
else
label2.Text = "";
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Text = "围棋";
comboBox1.Enabled = false;
}
}
}