public RoleSexTotalInfo() { infos = new RoleSexStatisticInfo[Enum.GetValues(typeof(FS2RoleType)).Length]; for (int i = 0; i != Enum.GetValues(typeof(FS2RoleType)).Length; ++i) { infos[i] = new RoleSexStatisticInfo(); infos[i].roleType = (FS2RoleType)i; } }
bool CreateSearchRoleSexList(FS2RoleDataInfo[] infos) { RoleSexTotalInfo totalInfo = null; if (infos != null) { totalInfo = new RoleSexTotalInfo(); foreach (FS2RoleDataInfo info in infos) { totalInfo.infos[Convert.ToInt16(info.RoleType)].num[(int)info.RoleSex]++; } } if (totalInfo != null) { int totalMale = 0; int totalFemale = 0; int totalMaleJia = 0; int totalFemaleJia = 0; int totalMaleDao = 0; int totalFemaleDao = 0; int totalMaleYi = 0; int totalFemaleYi = 0; int rowNum = 0; foreach (RoleSexStatisticInfo info in totalInfo.infos) { ++rowNum; totalMale += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemale += info.num[Convert.ToInt16(FS2RoleSex.Female)]; TableRow row = new TableRow(); //三类职业行标头 TableCell headerCell = new TableCell(); headerCell.RowSpan = 3; switch (rowNum) { case 1: headerCell.Text = StringDef.Jiashi; row.Cells.Add(headerCell); break; case 4: headerCell.Text = StringDef.Daoshi; row.Cells.Add(headerCell); break; case 7: headerCell.Text = StringDef.Yiren; row.Cells.Add(headerCell); break; } TableCell cell1 = new TableCell(); string classDescription = string.Empty; switch (info.roleType) { case FS2RoleType.Jiashi: classDescription = StringDef.Jiashi + string.Format("[{0}]", StringDef.ProfessionalNotChoose); totalMaleJia += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleJia += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Xuanfeng: classDescription = StringDef.XuanFeng; totalMaleJia += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleJia += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Xingtian: classDescription = StringDef.XingTian; totalMaleJia += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleJia += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Daoshi: classDescription = StringDef.Daoshi + string.Format("[{0}]", StringDef.ProfessionalNotChoose); totalMaleDao += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleDao += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Zhenren: classDescription = StringDef.ZhenRen; totalMaleDao += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleDao += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Tianshi: classDescription = StringDef.TianShi; totalMaleDao += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleDao += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Yiren: classDescription = StringDef.Yiren + string.Format("[{0}]", StringDef.ProfessionalNotChoose); totalMaleYi += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleYi += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Shoushi: classDescription = StringDef.ShouShi; totalMaleYi += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleYi += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; case FS2RoleType.Yishi: classDescription = StringDef.YiShi; totalMaleYi += info.num[Convert.ToInt16(FS2RoleSex.Male)]; totalFemaleYi += info.num[Convert.ToInt16(FS2RoleSex.Female)]; break; } cell1.Text = classDescription; TableCell cell2 = new TableCell(); if (info.num[Convert.ToInt16(FS2RoleSex.Male)] != 0) { cell2.Text = string.Format("{0} ({1}%)", info.num[Convert.ToInt16(FS2RoleSex.Male)].ToString(), Decimal.Round((decimal)info.num[Convert.ToInt16(FS2RoleSex.Male)] / info.TotalNum * 100, 2).ToString()); } else { cell2.Text = "0"; } TableCell cell3 = new TableCell(); if (info.num[Convert.ToInt16(FS2RoleSex.Female)] != 0) { cell3.Text = string.Format("{0} ({1}%)", info.num[Convert.ToInt16(FS2RoleSex.Female)].ToString(), Decimal.Round((decimal)info.num[Convert.ToInt16(FS2RoleSex.Female)] / info.TotalNum * 100, 2).ToString()); } else { cell3.Text = "0"; } TableCell cell4 = new TableCell(); //cell4.Text = string.Format("{0} (100%)", info.TotalNum); row.Cells.Add(cell1); row.Cells.Add(cell2); row.Cells.Add(cell3); row.Cells.Add(cell4); TableCell tailCell = new TableCell(); tailCell.RowSpan = 3; switch (rowNum) { case 1: case 4: case 7: row.Cells.Add(tailCell); break; } TableSearchRoleSexStatistic.Rows.Add(row); } //九种职业统计 for (int totalInfoIndex = 0; totalInfoIndex != totalInfo.infos.Length; ++totalInfoIndex) { RoleSexStatisticInfo info = totalInfo.infos[totalInfoIndex] as RoleSexStatisticInfo; if (info != null) { switch (info.roleType) { case FS2RoleType.Jiashi: if ((totalMaleJia + totalFemaleJia) != 0) { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[4].Text = string.Format("{0} ({1}%)", info.TotalNum, Decimal.Round((decimal)info.TotalNum / (totalMaleJia + totalFemaleJia) * 100, 2).ToString()); } else { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[4].Text = "0"; } break; case FS2RoleType.Xuanfeng: case FS2RoleType.Xingtian: if ((totalMaleJia + totalFemaleJia) != 0) { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[3].Text = string.Format("{0} ({1}%)", info.TotalNum, Decimal.Round((decimal)info.TotalNum / (totalMaleJia + totalFemaleJia) * 100, 2).ToString()); } else { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[3].Text = "0"; } break; case FS2RoleType.Daoshi: if ((totalMaleDao + totalFemaleDao) != 0) { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[4].Text = string.Format("{0} ({1}%)", info.TotalNum, Decimal.Round((decimal)info.TotalNum / (totalMaleDao + totalFemaleDao) * 100, 2).ToString()); } else { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[4].Text = "0"; } break; case FS2RoleType.Zhenren: case FS2RoleType.Tianshi: if ((totalMaleDao + totalFemaleDao) != 0) { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[3].Text = string.Format("{0} ({1}%)", info.TotalNum, Decimal.Round((decimal)info.TotalNum / (totalMaleDao + totalFemaleDao) * 100, 2).ToString()); } else { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[3].Text = "0 (0%)"; } break; case FS2RoleType.Yiren: if ((totalMaleYi + totalFemaleYi) != 0) { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[4].Text = string.Format("{0} ({1}%)", info.TotalNum, Decimal.Round((decimal)info.TotalNum / (totalMaleYi + totalFemaleYi) * 100, 2).ToString()); } else { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[4].Text = "0 (0%)"; } break; case FS2RoleType.Shoushi: case FS2RoleType.Yishi: if ((totalMaleYi + totalFemaleYi) != 0) { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[3].Text = string.Format("{0} ({1}%)", info.TotalNum, Decimal.Round((decimal)info.TotalNum / (totalMaleYi + totalFemaleYi) * 100, 2).ToString()); } else { TableSearchRoleSexStatistic.Rows[totalInfoIndex + 1].Cells[3].Text = "0 (0%)"; } break; } } } //三类职业总统计 string typeStat = "{0}<br/>" + StringDef.Male + StringDef.Colon + "{1} {2}<br/>" + StringDef.Female + StringDef.Colon + "{3} {4}<br/>" + StringDef.Count + StringDef.Colon + " {5}"; TableSearchRoleSexStatistic.Rows[1].Cells[5].Text = string.Format(typeStat, StringDef.Jiashi, totalMaleJia, totalMaleJia + totalFemaleJia == 0 ? string.Empty : string.Format("({0}%)", Decimal.Round((decimal)totalMaleJia / (totalMaleJia + totalFemaleJia) * 100, 2)), totalFemaleJia, totalMaleJia + totalFemaleJia == 0 ? string.Empty : string.Format("({0}%)", Decimal.Round((decimal)totalFemaleJia / (totalMaleJia + totalFemaleJia) * 100, 2)), totalMaleJia + totalFemaleJia); TableSearchRoleSexStatistic.Rows[4].Cells[5].Text = string.Format(typeStat, StringDef.Daoshi, totalMaleDao, totalMaleDao + totalFemaleDao == 0 ? string.Empty : string.Format("({0}%)", Decimal.Round((decimal)totalMaleDao / (totalMaleDao + totalFemaleDao) * 100, 2)), totalFemaleDao, totalMaleDao + totalFemaleDao == 0 ? string.Empty : string.Format("({0}%)", Decimal.Round((decimal)totalFemaleDao / (totalMaleDao + totalFemaleDao) * 100, 2)), totalMaleDao + totalFemaleDao); TableSearchRoleSexStatistic.Rows[7].Cells[5].Text = string.Format(typeStat, StringDef.Yiren, totalMaleYi, totalMaleYi + totalFemaleYi == 0 ? string.Empty : string.Format("({0}%)", Decimal.Round((decimal)totalMaleYi / (totalMaleYi + totalFemaleYi) * 100, 2)), totalFemaleYi, totalMaleYi + totalFemaleYi == 0 ? string.Empty : string.Format("({0}%)", Decimal.Round((decimal)totalFemaleYi / (totalMaleYi + totalFemaleYi) * 100, 2)), totalMaleYi + totalFemaleYi); TableRow rowTotal = new TableRow(); rowTotal.Font.Bold = true; TableCell cell = new TableCell(); cell.ColumnSpan = 2; cell.Text = StringDef.Total; rowTotal.Cells.Add(cell); cell = new TableCell(); if (totalMale != 0) { cell.Text = string.Format("{0} ({1}%)", totalMale, Decimal.Round((decimal)totalMale / (totalMale + totalFemale) * 100, 2)); } else { cell.Text = "0"; } rowTotal.Cells.Add(cell); cell = new TableCell(); if (totalFemale != 0) { cell.Text = string.Format("{0} ({1}%)", totalFemale, Decimal.Round((decimal)totalFemale / (totalMale + totalFemale) * 100, 2)); } else { cell.Text = "0"; } rowTotal.Cells.Add(cell); cell = new TableCell(); cell.ColumnSpan = 2; if ((totalMale + totalFemale) != 0) { cell.Text = string.Format("{0} (100%)", totalMale + totalFemale); } else { cell.Text = "0"; } rowTotal.Cells.Add(cell); TableSearchRoleSexStatistic.Rows.Add(rowTotal); } return(true); }