几天前,老师问我
“如果给你一本C#的书去自学,你能做出一个作品吗”
于是这个小工具就诞生啦~
工具介绍

使用方法
分组列表
  增加 按钮:增加一个分组,组别信息包括组名、人数。
  重设 按钮:清除分组列表与结果列表。
  删除 按钮:删除DataGridView中当前选定的组。
组员列表
  SelectFileLog:显示为当前选定的文本文件名。
  重载 按钮:当未选定文本文件时按下按钮将载入根目录中的“group.txt”,当指定txt文本后,在编辑txt文本文件后,按下此按钮会重新载入选定的txt文本。
  编辑 按钮:当已选定txt文本后,按下此按钮将打开txt文本文件,并进行组员编辑。
  浏览 按钮:按下此按钮后,用户可自行选择一个写有组员列表的txt文件,格式为每行一个姓名。
开始
  按下此按钮后,程序会将组员列表中的组员随机分配至用户设定的分组列表中,并显示于“结果”栏内。
      注:当需分组人数小于组员数时,余出的组员将被忽略。
技术简述
部分源代码
random| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 
 | iDicPar = new Dictionary<int, string>();Random rand = new Random();
 
 for (int i = 0; i < textcount; i++){
 iDicPar.Add(i, textBox3.Lines[i]);
 }
 
 for (int i = 0; i < dgvGroup.Rows.Count; i++){
 int groupqual = int.Parse(dgvGroup.Rows[i].Cells[1].Value.ToString());
 for (int j = 0; j < groupqual; j++){
 int randnum = rand.Next(0, textcount);
 bool done = false;
 while (!done){
 if (iDicPar.ContainsKey(randnum)){
 this.dgvResult.Rows.Add(1);
 this.dgvResult.Rows[this.dgvResult.Rows.Count - 1].Cells[0].Value = this.dgvGroup.Rows[i].Cells[0].Value;
 this.dgvResult.Rows[this.dgvResult.Rows.Count - 1].Cells[1].Value = iDicPar[randnum];
 iDicPar.Remove(randnum);
 done = true;
 }else{
 randnum = rand.Next(0, textcount);
 }
 }
 }
 }
 
 | 
 
encode| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 
 | 
 
 namespace FileEncoding{
 
 
 
 public class EncodingType{
 
 
 
 
 
 public static System.Text.Encoding GetType(string FILE_NAME){
 FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);
 Encoding r = GetType(fs);
 fs.Close();
 return r;
 }
 
 
 
 
 
 
 public static System.Text.Encoding GetType(FileStream fs){
 byte[] Unicode = new byte[] { 0xFF, 0xFE, 0x41 };
 byte[] UnicodeBIG = new byte[] { 0xFE, 0xFF, 0x00 };
 byte[] UTF8 = new byte[] { 0xEF, 0xBB, 0xBF };
 Encoding reVal = Encoding.Default;
 
 BinaryReader r = new BinaryReader(fs, System.Text.Encoding.Default);
 int i;
 int.TryParse(fs.Length.ToString(), out i);
 byte[] ss = r.ReadBytes(i);
 if (IsUTF8Bytes(ss) || (ss[0] == 0xEF && ss[1] == 0xBB && ss[2] == 0xBF)){
 reVal = Encoding.UTF8;
 }else if (ss[0] == 0xFE && ss[1] == 0xFF && ss[2] == 0x00){
 reVal = Encoding.BigEndianUnicode;
 }else if (ss[0] == 0xFF && ss[1] == 0xFE && ss[2] == 0x41){
 reVal = Encoding.Unicode;
 }
 r.Close();
 return reVal;
 }
 
 
 
 
 
 
 private static bool IsUTF8Bytes(byte[] data){
 int charByteCounter = 1;
 byte curByte;
 for (int i = 0; i < data.Length; i++){
 curByte = data[i];
 if (charByteCounter == 1){
 if (curByte >= 0x80){
 
 while (((curByte <<= 1) & 0x80) != 0){
 charByteCounter++;
 }
 
 if (charByteCounter == 1 || charByteCounter > 6){
 return false;
 }
 }
 }else{
 
 if ((curByte & 0xC0) != 0x80){
 return false;
 }
 charByteCounter--;
 }
 }
 if (charByteCounter > 1){
 throw new Exception("非预期的byte格式");
 }
 return true;
 }
 }
 }
 
 | 
 
笔记
- [ Dictionary<int, string> iDicPar; ] 为一个HashMap类型,泛型 <int, string> 中,int为不可重复的key,string为可重复的value。
下载地址
打包:https://share.weiyun.com/5UFmCwF
绿色:https://share.weiyun.com/5HTEfBo
制作时间
2019-3-29 — 2019-3-30
开发环境
VS2017
软件使用素材
图标:野田工房P
资料查阅
CSDN、博客园