在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 统计棋类比赛个人积分

统计棋类比赛个人积分

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:1.68M
  • 下载次数:12
  • 浏览次数:223
  • 发布时间:2015-11-25
  • 实例类别:C#语言基础
  • 发 布 人:李双虎
  • 文件格式:.rar
  • 所需积分: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;
        }
    }
}

标签: 胜负师

实例下载地址

统计棋类比赛个人积分

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警