using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Drawing.Imaging; using System.Drawing; /// <summary> /// http://www.cnblogs.com/huangjianhuakarl/ /// </summary> public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } /// <summary> /// 在 GridView 控件中创建新行时发生,此事件通常用于在创建某个行时修改该行的布局或外观 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { //隐藏中奖号码所有列 if (e.Row.RowType == DataControlRowType.DataRow ||e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[2].Visible = false; e.Row.Cells[3].Visible = false; e.Row.Cells[4].Visible = false; e.Row.Cells[5].Visible = false; e.Row.Cells[6].Visible = false; e.Row.Cells[7].Visible = false; } switch (e.Row.RowType) { //判断是否表头 case DataControlRowType.Header: //第一行表头 TableCellCollection tcHeader = e.Row.Cells; tcHeader.Clear(); tcHeader.Add(new TableHeaderCell()); tcHeader[0].Attributes.Add("rowspan", "2"); tcHeader[0].Attributes.Add("bgcolor", "Azure"); tcHeader[0].Text = "序号"; tcHeader.Add(new TableHeaderCell()); tcHeader[1].Attributes.Add("rowspan", "2"); tcHeader[1].Attributes.Add("bgcolor", "Azure"); tcHeader[1].Text = "期数"; tcHeader.Add(new TableHeaderCell()); tcHeader[2].Attributes.Add("colspan", "34"); tcHeader[2].Attributes.Add("bgcolor", "Azure"); tcHeader[2].Text = "中 奖 号 码 分 布"; tcHeader.Add(new TableHeaderCell()); tcHeader[3].Attributes.Add("colspan", "5"); tcHeader[3].Attributes.Add("bgcolor", "Azure"); tcHeader[3].Text = "红 球 号 码 分 析</th></tr><tr>"; ////第二行表头 tcHeader.Add(new TableHeaderCell()); tcHeader[4].Attributes.Add("colspan", "11"); tcHeader[4].Attributes.Add("bgcolor", "AliceBlue"); tcHeader[4].Text = "红球一区"; tcHeader.Add(new TableHeaderCell()); tcHeader[5].Attributes.Add("colspan", "11"); tcHeader[5].Attributes.Add("bgcolor", "LavenderBlush"); tcHeader[5].Text = "红球二区"; tcHeader.Add(new TableHeaderCell()); tcHeader[6].Attributes.Add("colspan", "11"); tcHeader[6].Attributes.Add("bgcolor", "OldLace"); tcHeader[6].Text = "红球三区"; tcHeader.Add(new TableHeaderCell()); tcHeader[7].Attributes.Add("colspan", "1"); tcHeader[7].Attributes.Add("bgcolor", "Azure"); tcHeader[7].Text = "蓝球"; tcHeader.Add(new TableHeaderCell()); tcHeader[8].Attributes.Add("colspan", "1"); tcHeader[8].Attributes.Add("bgcolor", "Azure"); tcHeader[8].Text = "重号"; tcHeader.Add(new TableHeaderCell()); tcHeader[9].Attributes.Add("colspan", "1"); tcHeader[9].Attributes.Add("bgcolor", "Azure"); tcHeader[9].Text = "连号"; tcHeader.Add(new TableHeaderCell()); tcHeader[10].Attributes.Add("colspan", "1"); tcHeader[10].Attributes.Add("bgcolor", "Azure"); tcHeader[10].Text = "和值"; tcHeader.Add(new TableHeaderCell()); tcHeader[11].Attributes.Add("colspan", "1"); tcHeader[11].Attributes.Add("bgcolor", "Azure"); tcHeader[11].Text = "奇偶"; tcHeader.Add(new TableHeaderCell()); tcHeader[12].Attributes.Add("colspan", "1"); tcHeader[12].Attributes.Add("bgcolor", "Azure"); tcHeader[12].Text = "三区"; break; } } /// <summary> /// 在 GridView 控件中的某个行被绑定到一个数据记录时发生。此事件通常用于在某个行被绑定到数据时修改该行的内容。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { for (int i = 0; i < GridView1.Rows.Count-1; i++) { int repeat = 0; //重号的个数 for (int j = 2; j <= 7; j++) { for (int k = 2; k <= 7; k++) { string row1 = GridView1.Rows[I.Cells[j].Text; string row2 = GridView1.Rows[i+1].Cells[k].Text; repeat += (row1.Equals(row2)) ? 1 : 0; } } GridView1.Rows[I.Cells[42].Text = repeat.ToString();//重号列 GridView1.Rows[i + 1].Cells[42].Text = "0"; } if (e.Row.RowIndex != -1) { int id = GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString();//序号列 e.Row.Cells[41].BackColor = Color.Azure;//蓝球列 e.Row.Cells[41].Text= e.Row.Cells[41].Text.ToString().Length < 2 ? "0" + e.Row.Cells[41].Text.ToString() : e.Row.Cells[41].Text.ToString(); int next = 0; //连号的个数 int sum = 0; //所有红球和值 int flag = 0; //红球号码为偶数的个数 int area1 = 0; //红球一区的个数 int area2 = 0; //红球二区的个数 int area3 = 0; //红球三区的个数 for (int j = 2; j <= 7; j++)//循环中奖号码所有列 { //如果相邻列的差为1则为连号 if (j > 2) { next += ((Convert.ToInt32(e.Row.Cells[j].Text) - Convert.ToInt32(e.Row.Cells[j-1].Text))==1) ? 1 : 0; } int temp=Convert.ToInt32(e.Row.Cells[j].Text); sum += temp; flag += (temp) % 2 == 0 ? 1 : 0; //1-11为一区;12-22为二区;23-33为三区 if (temp <= 11) { area1 += 1; } else if (temp <= 22) { area2 += 1; } else { area3 += 1; } } e.Row.Cells[43].Text = next.ToString();//连号列 e.Row.Cells[44].Text = sum.ToString();//和值列 e.Row.Cells[45].Text = (6 - flag) + ":" + flag;//奇偶比例列 e.Row.Cells[46].Text = area1 + ":" + area2 + ":" + area3;//区间比例列 //红球一区 for (int i = 8; i <= 18; i++) { e.Row.Cells[I.BackColor = Color.AliceBlue; e.Row.Cells[I.Text = i <= 16 ? "0" + (i - 7).ToString() : (i - 7).ToString(); } //红球二区 for (int i = 19; i <= 29; i++) { e.Row.Cells[I.BackColor = Color.LavenderBlush; e.Row.Cells[I.Text = (i - 7).ToString(); } //红球三区 for (int i = 30; i <= 40; i++) { e.Row.Cells[I.BackColor = Color.OldLace; e.Row.Cells[I.Text = (i - 7).ToString(); } } //中奖红球号码高亮显示 foreach (TableCell tc in e.Row.Cells) { tc.Attributes["style"] = "border-color:Gray"; if (e.Row.RowIndex != -1) { for (int j = 2; j <= 7; j++) { for (int i = 8; i <= 40; i++) { string compStr = e.Row.Cells[j].Text.ToString().Length < 2 ? "0" + e.Row.Cells[j].Text.ToString() : e.Row.Cells[j].Text.ToString(); if (compStr == e.Row.Cells[I.Text.ToString()) { e.Row.Cells[I.BackColor = Color.Red; } } } } } } } |