📄 form1.cs
字号:
{
mAllInfors.Add(newInfor);
}
else
{
fAllInfors.Add(newInfor);
}
}
}
private void SortByGroup()//按组别分类
{
for (int i = 0; i < mAllInfors.Count; i++)
{
switch (((Infor)mAllInfors[i]).Group)
{
case "甲":
Infors[0].Add(mAllInfors[i]);
FillLevels(((Infor)mAllInfors[i]).Level,ref Levels[0]);
break;
case "乙":
Infors[1].Add(mAllInfors[i]);
FillLevels(((Infor)mAllInfors[i]).Level, ref Levels[1]);
break;
case "丙":
Infors[2].Add(mAllInfors[i]);
FillLevels(((Infor)mAllInfors[i]).Level,ref Levels[2]);
break;
case "丁":
Infors[3].Add(mAllInfors[i]);
FillLevels(((Infor)mAllInfors[i]).Level, ref Levels[3]);
break;
}
}
for (int i = 0; i < fAllInfors.Count; i++)
{
switch (((Infor)fAllInfors[i]).Group)
{
case "甲":
Infors[4].Add(fAllInfors[i]);
FillLevels(((Infor)fAllInfors[i]).Level,ref Levels[4]);
break;
case "乙":
Infors[5].Add(fAllInfors[i]);
FillLevels(((Infor)fAllInfors[i]).Level, ref Levels[5]);
break;
case "丙":
Infors[6].Add(fAllInfors[i]);
FillLevels(((Infor)fAllInfors[i]).Level,ref Levels[6]);
break;
case "丁":
Infors[7].Add(fAllInfors[i]);
FillLevels(((Infor)fAllInfors[i]).Level,ref Levels[7]);
break;
}
}
}
private void FillLevels(string level,ref ArrayList Level)//设置各组级别
{
for (int i = 0; i < Level.Count; i++)
{
if ((string)Level[i] == level)
{
return;
}
}
Level.Add(level);
}
private void SortByLevel(ref ArrayList GroupInfors, int[,] Group,int groupIndex)//按级别调整好次序,输出
{
if (GroupInfors.Count == 0) return;
int CurrentIndex = 0;
int LevelIndex = 0;//级别索引
Infor Temp = new Infor();
int GroupIndex = 0;//作为Group数组的下标
Group[0, GroupIndex++] = 0;
int i = 0;
while (LevelIndex < Levels[groupIndex].Count)
{//按级别调整GroupInfors中的运动员信息
string compareLevel=Levels[groupIndex][LevelIndex].ToString();
while (CurrentIndex<GroupInfors.Count&&((Infor)GroupInfors[CurrentIndex]).Level == compareLevel)
{
CurrentIndex++;
}
for (i = CurrentIndex+1; i < GroupInfors.Count; i++)
{
if (((Infor)GroupInfors[i]).Level == compareLevel)
{
Temp = (Infor)GroupInfors[i];
GroupInfors[i] = GroupInfors[CurrentIndex];
GroupInfors[CurrentIndex] = Temp;
CurrentIndex++;
}
}
LevelIndex++;
if (GroupIndex < Levels[groupIndex].Count)
{
Group[0, GroupIndex++] = CurrentIndex;
}
}
for (i = 0; i < GroupIndex - 1; i++)
{//统计各个级别人数
Group[1, i] = Group[0, i + 1] - Group[0, i];
}
Group[1, i] = GroupInfors.Count - Group[0, i];
bool Flag = true;//级别合并
while (Flag)
{
Flag = false;
for (i = 1; i < Levels[groupIndex].Count; i++)
{
if (Group[1, i] < 3 && Group[1, i] != 0)
{
Group[1, i - 1] = Group[1, i - 1] + Group[1, i];
Group[1, i] = 0;
Group[0, i] = Group[0, i - 1] + Group[1, i - 1];
Flag = true;
}
}
}
}
private int GetSequence(int i,int halfnumPlayer)//选手随机号 这个模板的人数的一半
{
switch(halfnumPlayer){
case 2:
return 5 - i;
case 4:
switch (i)
{
case 8:
return 1;
case 5:
return 2;
case 6:
return 3;
case 7:
return 4;
}
break;
case 8:
switch (i)
{
case 9:
return 2;
case 10:
return 7 ;
case 11:
return 6;
case 12:
return 3;
case 13:
return 4;
case 14:
return 5;
case 15:
return 8;
case 16:
return 1;
}
break;
case 16:
switch (i)
{
case 17:
return 2;
case 18:
return 15;
case 19:
return 10;
case 20:
return 7;
case 21:
return 6;
case 22:
return 11;
case 23:
return 14;
case 24:
return 3;
case 25:
return 4;
case 26:
return 13;
case 27:
return 12;
case 28:
return 5;
case 29:
return 8;
case 30:
return 9;
case 31:
return 16;
case 32:
return 1;
}
break;
}
return 0;
}
private void SortSequence(int[] LSequ,ArrayList ToExcel)//从小到大排序
{
for (int i = 0; i < LSequ.Length; i++)
{
for (int j = i + 1; j < LSequ.Length; j++)
{
if (LSequ[j] < LSequ[i])
{
int temp = LSequ[j];
LSequ[j] = LSequ[i];
LSequ[i] = temp;
ToExcelInfor TEMP = new ToExcelInfor();
TEMP = (ToExcelInfor)ToExcel[j];
ToExcel[j] = (ToExcelInfor)ToExcel[i];
ToExcel[i] = TEMP;
}
}
}
}
private void OutPutToWord(ref ArrayList GroupInfors, int[,] Group,int fieldIndex,string FolderPath)
{
if (GroupInfors.Count == 0) return;
bool Flag = true;
string findText ;
bool matchCase = false;
object MatchCase = matchCase;
object FindText;
object Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
object ReplaceWith ;
string FieldName = Convert.ToChar(fieldIndex + 65).ToString();
int FileIndex = 1;//文件名索引,从人多文件到人少文件
int preDual=0;//已经在前面排过的场次
int NumLevel = ((int[,])GroupMerge[fieldIndex]).Length / 2;
bool [] SortedLevel=new bool [NumLevel];//已经排过的级别
for (int i = 0; i < NumLevel; i++)
{
SortedLevel[i] = false;
}
while (Flag)//先排级别内人多场次 一次循环输出一个级别
{
Flag = false;
int max = 0;
int maxIndex = 0;
for (int i = 0; i < NumLevel; i++)//找出人最多的那个级别
{
if (Group[1, i] != 0 && max < Group[1, i] && !SortedLevel[i])
{
max = Group[1, i];
maxIndex = i;
Flag = true;
}
}
if (Flag)
{
int HalfNumPlayer;
PlayerIndex = 0;
if (Group[1, maxIndex] <= 4)
{
sWordTemFileName = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "4.doc";
HalfNumPlayer = 2;
}
else
{
if (Group[1, maxIndex] <= 8)
{
sWordTemFileName = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "8.doc";
HalfNumPlayer = 4;
}
else
{
if (Group[1, maxIndex] <= 16)
{
sWordTemFileName = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "16.doc";
HalfNumPlayer = 8;
}
else
{
sWordTemFileName = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "17-32.doc";
HalfNumPlayer = 16;
}
}
}
if (!System.IO.File.Exists((string)sWordTemFileName)) {
MessageBox.Show("word模板文件\"" + sWordTemFileName + "\"不存在!");
this.Close();
return;
}
Word.Document doc = TheWordApp.Documents.Open(ref sWordTemFileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
int i = Group[0, maxIndex];
int iTop = i + Group[1, maxIndex];
int nDual = Group[1, maxIndex] - HalfNumPlayer;//在这个级别中有几对选手
string ToExcelLevel = LevelsMerge[fieldIndex][maxIndex].ToString();
string ToExcelGroup = ((Infor)GroupInfors[i]).Sex + ((Infor)GroupInfors[i]).Group;
ArrayList CurrentLevelInfors = new ArrayList();////存储当前场地,组别,级别中的所有选手,包括没有对手的
ArrayList ToExcelInfor = new ArrayList();//存储当前场地,组别,级别中的每对参赛选手,长度 为nDual
ToExcelInfor myToExcelInfor;
int[] LSequ = new int[nDual];
int lsIndex = 0;//LSequ的索引
for (; i < iTop; i++)//对某一个级别
{
PlayerIndex++;
findText = "@" + PlayerIndex.ToString() + "@";
FindText = findText;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -