aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UsualSaleTotal.aspx.cs" Inherits="CEO_UsualSaleTotal" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>无标题页</title> <mce:script type="text/javascript" src="../js/popcalendar.js" mce_src="js/popcalendar.js"></mce:script> <mce:script type="text/javascript" src="../js/popcalendar2.js" mce_src="js/popcalendar2.js"></mce:script> <mce:style type="text/css"><!-- body{font-size:12px;background:url(../images/sale_bg.jpg) no-repeat center;} div#GridView{} div#search1{width:900px;height:100%;margin-bottom:5px;} .mylink{text-decoration:none;color:infotext;font-weight:bold;} --></mce:style><style type="text/css" mce_bogus="1"> body{font-size:12px;background:url(../images/sale_bg.jpg) no-repeat center;} div#GridView{} div#search1{width:900px;height:100%;margin-bottom:5px;} .mylink{text-decoration:none;color:infotext;font-weight:bold;} </style> </head> <body> <form id="form1" runat="server"> <div> <div id="search1"> 起始时间:<asp:textbox id="txt_StartCPXG_DATE" runat="server" Width="80px" CssClass="edLine" Height="20px"></asp:textbox> <img alt="" id="Image_blqx1" style="CURSOR: hand" mce_style="CURSOR: hand" onclick="popUpCalendar(this,document.forms[0].txt_StartCPXG_DATE,'yyyy-mm-dd')" src="../images/calendar.gif" mce_src="images/calendar.gif" /> 截止时间:<asp:textbox id="txt_StartCPXG_DATE2" runat="server" Width="80px" CssClass="edLine" Height="20px"></asp:textbox> <img alt="" id="Image_blqx12" style="CURSOR: hand" mce_style="CURSOR: hand" onclick="popUpCalendar(this,document.forms[0].txt_StartCPXG_DATE2,'yyyy-mm-dd')" src="../images/calendar.gif" mce_src="images/calendar.gif" /> <asp:Button ID="search" runat="server" Font-Size="10pt" Text="搜 索" Height="23px" Width="111px" OnClick="search_Click"/> <br /><br /> </div> <div id="GridView"> <asp:GridView ID="GridView1" runat="server" Font-Size="12px" AutoGenerateColumns="False" CellPadding="3" ForeColor="#333333" AllowSorting="true" PageSize="20" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" Height="344px" Width="1060px" BorderColor="gray"> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <Columns> <asp:BoundField DataField="id" HeaderText="序号" ReadOnly="True" /> <asp:BoundField DataField="SALES_PERSON_ID" HeaderText="姓名" /> <asp:BoundField DataField="APPLY_NUM" HeaderText="截至昨日本月签单数" /> <asp:BoundField DataField="D_PLAN" HeaderText="本月目标" /> <asp:TemplateField HeaderText="截至昨日目标完成率"> <ItemTemplate> <asp:Label ID="lblDfisishPercent" runat="server"></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="E_PLAN" HeaderText="跟单客户总数" /> <asp:BoundField DataField="VISIT_TIMES" HeaderText="客户拜访数" /> <asp:BoundField DataField="B_PLAN" HeaderText="本月目标" /> <asp:BoundField DataField="B_FINISH" HeaderText="截至昨日完成" /> <asp:TemplateField HeaderText="完成率"> <ItemTemplate> <asp:Label ID="lblBfisishPercent" runat="server"></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="C_PLAN" HeaderText="本月目标" /> <asp:BoundField DataField="C_FINISH" HeaderText="截至昨日完成" /> <asp:TemplateField HeaderText="完成率"> <ItemTemplate> <asp:Label ID="lblCfisishPercent" runat="server"></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle ForeColor="#000066" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" /> <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource> </div> </div> </form> </body> </html> cs文件 using System; using System.Data; using System.Configuration; using System.Collections; 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 i_salesDAL; using i_salesModels; using i_salesBLL; using MySql.Data.MySqlClient; public partial class CEO_UsualSaleTotal : System.Web.UI.Page { string strCon = "server=localhost;user id=root;password=root;database=google;CharSet=gb2312;"; MySqlConnection mysqlcon; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } //绑定GridView1 public void bind() { string sqlstr = "select * from sales_plan group by SALES_PERSON_ID"; //防止程序池溢出 using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "sales_plan"); GridView1.DataSource = myds; GridView1.DataKeyNames = new string[] { "id" };//主键 GridView1.DataBind(); } } //行事件,鼠标移到GridView某一行时改变该行的背景色方法 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { //如果是绑定数据行 if (e.Row.RowType == DataControlRowType.DataRow) { //鼠标经过时,行背景色变 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ff99ff'"); //鼠标移出时,行背景色变 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='Transparent'"); //绑定完成率 Label lblBfisishPercent = e.Row.Cells[9].FindControl("lblBfisishPercent") as Label; if (lblBfisishPercent != null) { int a = int.Parse(e.Row.Cells[8].Text); int b = int.Parse(e.Row.Cells[7].Text); double c = Convert.ToDouble(a) / b; lblBfisishPercent.Text = c.ToString("0.##%"); } Label lblCfisishPercent = e.Row.Cells[12].FindControl("lblCfisishPercent") as Label; if (lblCfisishPercent != null) { int a = int.Parse(e.Row.Cells[11].Text); int b = int.Parse(e.Row.Cells[10].Text); double c = Convert.ToDouble(a) / b; lblCfisishPercent.Text = c.ToString("0.##%"); //attention!!!! //lblDfisishPercent.Text = c.ToString("0.##%"); } } //把前台的第一列的表头该为“序号”,因为以前的第一列被“遮盖”了。GridView实现自动编号 if (e.Row.RowIndex != -1) { int id = e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); e.Row.Cells[1].Text = Ss_usersManager.GetNameById(int.Parse(e.Row.Cells[1].Text)); } } //手动写分页时必须添加的事件 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { string sqlstr = "select * from sales_plan group by SALES_PERSON_ID"; //防止程序池溢出 using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "sales_plan"); GridView1.PageIndex = e.NewPageIndex; GridView1.DataSource = myds; GridView1.DataBind(); } } //表头合并等 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) { case DataControlRowType.Header: //第一行表头 TableCellCollection tcHeader = e.Row.Cells; tcHeader.Clear(); tcHeader.Add(new TableHeaderCell()); tcHeader[0].Attributes.Add("rowspan", "4"); //跨Row tcHeader[0].Attributes.Add("bgcolor", "white"); tcHeader[0].Text = ""; tcHeader.Add(new TableHeaderCell()); //tcHeader[1].Attributes.Add("bgcolor", "Red"); tcHeader[1].Attributes.Add("colspan", "12"); //跨Column tcHeader[1].Text = "常规销售个人统计全部信息</th></tr><tr>"; //第二行表头 tcHeader.Add(new TableHeaderCell()); tcHeader[2].Attributes.Add("bgcolor", "DarkSeaGreen"); tcHeader[2].Attributes.Add("rowspan", "3"); tcHeader[2].Text = "姓名"; tcHeader.Add(new TableHeaderCell()); tcHeader[3].Attributes.Add("bgcolor", "LightSteelBlue"); tcHeader[3].Attributes.Add("colspan", "3"); tcHeader[3].Text = "签单"; tcHeader.Add(new TableHeaderCell()); tcHeader[4].Attributes.Add("bgcolor", "DarkSeaGreen"); tcHeader[4].Attributes.Add("colspan", "8"); tcHeader[4].Text = "截至昨日</th></tr><tr>"; //第三行表头 tcHeader.Add(new TableHeaderCell()); tcHeader[5].Attributes.Add("bgcolor", "LightSteelBlue"); tcHeader[5].Attributes.Add("rowspan", "2"); tcHeader[5].Text = "截至昨日本月签单数"; tcHeader.Add(new TableHeaderCell()); tcHeader[6].Attributes.Add("bgcolor", "DarkSeaGreen"); tcHeader[6].Attributes.Add("rowspan", "2"); tcHeader[6].Text = "本月目标"; tcHeader.Add(new TableHeaderCell()); tcHeader[7].Attributes.Add("bgcolor", "Khaki"); tcHeader[7].Attributes.Add("rowspan", "2"); tcHeader[7].Text = "截至昨日目标完成率"; tcHeader.Add(new TableHeaderCell()); tcHeader[8].Attributes.Add("bgcolor", "DarkSeaGreen"); tcHeader[8].Attributes.Add("rowspan", "2"); tcHeader[8].Text = "跟单客户总数"; tcHeader.Add(new TableHeaderCell()); tcHeader[9].Attributes.Add("bgcolor", "Khaki"); tcHeader[9].Attributes.Add("rowspan", "2"); tcHeader[9].Text = "客户拜访数"; tcHeader.Add(new TableHeaderCell()); tcHeader[10].Attributes.Add("bgcolor", "LightSteelBlue"); tcHeader[10].Attributes.Add("colspan", "3"); tcHeader[10].Text = "B"; tcHeader.Add(new TableHeaderCell()); tcHeader[11].Attributes.Add("bgcolor", "LightSteelBlue"); tcHeader[11].Attributes.Add("colspan", "3"); tcHeader[11].Text = "C</th></tr><tr>"; //第四行表头 tcHeader.Add(new TableHeaderCell()); tcHeader[12].Attributes.Add("bgcolor", "DarkSeaGreen"); tcHeader[12].Text = "本月目标"; tcHeader.Add(new TableHeaderCell()); tcHeader[13].Attributes.Add("bgcolor", "Khaki"); tcHeader[13].Text = "截至昨日完成"; tcHeader.Add(new TableHeaderCell()); tcHeader[14].Attributes.Add("bgcolor", "DarkSeaGreen"); tcHeader[14].Text = "完成率"; tcHeader.Add(new TableHeaderCell()); tcHeader[15].Attributes.Add("bgcolor", "Khaki"); tcHeader[15].Text = "本月目标"; tcHeader.Add(new TableHeaderCell()); tcHeader[16].Attributes.Add("bgcolor", "LightSteelBlue"); tcHeader[16].Text = "截至昨日完成"; tcHeader.Add(new TableHeaderCell()); tcHeader[17].Attributes.Add("bgcolor", "LightSteelBlue"); tcHeader[17].Text = "完成率"; break; } } //搜索 protected void search_Click(object sender, EventArgs e) { string time1 = this.txt_StartCPXG_DATE.Text.Trim(); string time2 = this.txt_StartCPXG_DATE2.Text.Trim(); string sqlstr = "select * from sales_plan where STARTDATE like '" + time1 + "' or ENDDATE like '" + time2 + "' group by SALES_PERSON_ID";// and (TIME between '%" + time1 + "%' and '%" + time2 + "%') //防止程序池溢出 using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "sales_plan"); GridView1.DataSource = myds; GridView1.DataKeyNames = new string[] { "id" };//主键 GridView1.DataBind(); } } }