完成第五步:实现分页及选择框取UID

本文介绍了一个指标配置页面的设计与实现,通过该页面可以从PBC库中获取并展示特定指标的数据,支持用户选择和导出。代码示例展示了如何使用C#处理数据并将其转换为XML文件。

PBCAnalyzer:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DataAccess.PO;

namespace BusinessFacade
ExpandedBlockStart.gifContractedBlock.gif
{
    
public class PBCAnalyzer
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
public static DataTable GetIndicatorMonthBase(List<Import_MonthBase> monthbaseList,List<Indicator> indicatorList)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (monthbaseList == nullreturn null;

            DataTable dt 
= new DataTable();
            dt.Columns.Add(
new DataColumn("UID"));
            dt.Columns.Add(
new DataColumn("指标ID"));
            dt.Columns.Add(
new DataColumn("指标名称"));
            dt.Columns.Add(
new DataColumn("年份"));
            dt.Columns.Add(
new DataColumn("月份"));
            dt.Columns.Add(
new DataColumn("指标值"));

            
//2,赋值
            DataRow dr;
            
foreach (Import_MonthBase monthbase in monthbaseList)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                dr 
= dt.NewRow();
                dr[
"UID"= monthbase.UID;
                dr[
"指标ID"= monthbase.IndicatorID;
                dr[
"指标名称"= GetIndiCnNameByID(monthbase.IndicatorID, indicatorList);
                dr[
"年份"= monthbase.YearNo;
                dr[
"月份"= monthbase.MonthNo;
                dr[
"指标值"= monthbase.IndicatorValue;

                dt.Rows.Add(dr);
            }


            
//3,添加到表
            return dt;
        }


        
private static string GetIndiCnNameByID(string indiID, List<Indicator> indicatorList)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
foreach (Indicator indi in indicatorList)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
if (indi.IndicatorCode.Equals(indiID, StringComparison.OrdinalIgnoreCase))
                    
return indi.DisplayName;
            }

            
return string.Empty;

        }


        
public static DataTable GetCnnameList(List<PBCIndicatorCode> cnnameList)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
if (cnnameList == nullreturn null;

            DataTable dt 
= new DataTable();
            dt.Columns.Add(
new DataColumn("PBC库指标ID"));
            dt.Columns.Add(
new DataColumn("PBC库指标名称"));
           

            
//2,赋值
            DataRow dr;
            
foreach (PBCIndicatorCode cnname in cnnameList)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                dr 
= dt.NewRow();
                dr[
"PBC库指标ID"= cnname.IndicatorID;
                dr[
"PBC库指标名称"= cnname.IndicatorName;
              
                dt.Rows.Add(dr);
            }


            
//3,添加到表
            return dt;
        }

    }

}

 DataManagement_IndicatorConfiguration.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 System.Collections.Generic;
using System.ComponentModel;
using System.Xml;
using System.Data.SqlClient;
using System.IO;
using System.Xml.Serialization;
using System.Diagnostics;
using System.Text;
using DataAccess.PO;
using BusinessFacade;

public partial class DataManagement_IndicatorConfiguration : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
{

    
private void Bind(int pageIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        StringBuilder indiCodes 
= new StringBuilder();
        
if (IndicatorMultiSelectControl1.SelectedIndicatorList != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            
foreach (Indicator indi in IndicatorMultiSelectControl1.SelectedIndicatorList)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                indiCodes.Append(
"'" + indi.IndicatorCode + "',");//加逗号是因为参数里有逗号分隔符
            }

        }


        
if (indiCodes == null || indiCodes.Length == 0)
            
return;
        indiCodes.Remove(indiCodes.Length 
- 11);//去掉加上的逗号
        string filter = "IndicatorID  in ( " + indiCodes.ToString() + " )";


ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////从PBC库中取出数据  
        PBCIntegrationManager manager = new PBCIntegrationManager();
        List
<Import_MonthBase> monthbase = new List<Import_MonthBase>();
        monthbase 
= manager.GetEntityList(filter);
        Session[
"PBCmonthbase"= monthbase;

        DataTable dt 
= PBCAnalyzer.GetIndicatorMonthBase(monthbase, IndicatorMultiSelectControl1.SelectedIndicatorList);

        ImportGridView.DataSource 
= dt;
        ImportGridView.PageIndex 
= pageIndex;
        ImportGridView.DataBind();
    }

    
protected void ShowButton_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
          
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////从EWS库取指标
        Bind(0);

    }


    
protected void ImportGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        Bind(e.NewPageIndex);
    }


    
protected void SelectBoxCheckedChanged(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        CheckBox box 
= (CheckBox)sender;
        
int rowIndex = ((GridViewRow)box.NamingContainer).RowIndex;
        
string key = ImportGridView.DataKeys[rowIndex].Value.ToString();
        Response.Write(
"<script>alert('"+key+"')</script>");
    }

        
    
protected void Import_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////从EWS库取指标
        List<Import_MonthBase> mbs = Session["PBCmonthbase"as List<Import_MonthBase>;
        
string file = "D:\\PBCmonth.xml";
        TextWriter writer 
= new StreamWriter(file);
        XmlSerializer sr 
= new XmlSerializer(typeof(List<Import_MonthBase>));
        sr.Serialize(writer, mbs);
        writer.Close();


    }

    
protected void ImportGridView_SelectedIndexChanged(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{

    }

    
protected void PBCButton_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//文本框 关键字匹配
        string keyWord = KeyWordTextBox.Text;


    }

}


 DataManagement_IndicatorConfiguration.aspx

 

<%@ Page Language="C#" MasterPageFile="~/Common/MainFramePage.master" AutoEventWireup="true" CodeFile="IndicatorConfiguration.aspx.cs" Inherits="DataManagement_IndicatorConfiguration" Title="Untitled Page" %>

<%@ Register Src="../Common/UserControl/IndicatorMultiSelectControl.ascx" TagName="IndicatorMultiSelectControl"
    TagPrefix
="uc1" %>
    
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderMainFramePage" Runat="Server">
    
<asp:Label ID="LbTitle" runat="server" Text="IndicatorConfiguration" Height="16px" Width="117px"></asp:Label>&nbsp;<br />
    
&nbsp; &nbsp;<table frame="void"  border="0" cellpadding="5" cellspacing="0" width ="100%" align="center"  id="TABLE2">
        
<tr>
            
<td style="width: 116px; height: 124px;" valign="top">
                
<asp:Label ID="ImportLabel" runat="server" Text="请选择EWS库指标:" Width="122px" Height="108px"></asp:Label></td> 
            
<td>
                
<uc1:IndicatorMultiSelectControl ID="IndicatorMultiSelectControl1" runat="server" />
            
</td>
        
</tr>
    
</table>
    
<table style="width: 547px">
        
<tr>
            
<td>
    
<asp:Button ID="ShowButton" runat="server" Height="32px" Text="显示数据" Width="156px" OnClick="ShowButton_Click" /></td>
            
<td style="width: 297px">
    
<asp:Label ID="nodataLabel" runat="server" Text=" " Width="186px" Height="31px"></asp:Label></td>
        
</tr>
    
</table>
    
<asp:GridView ID="ImportGridView" runat="server" Height="186px" Width="635px" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" OnPageIndexChanging="ImportGridView_PageIndexChanging" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="UID"  >
        
<FooterStyle BackColor="Tan" />
        
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
        
<HeaderStyle BackColor="Tan" Font-Bold="True" />
        
<AlternatingRowStyle BackColor="PaleGoldenrod" />
              
<Columns>
                  
<asp:TemplateField>
                        
<ItemTemplate>
                            
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true"  OnCheckedChanged="SelectBoxCheckedChanged" />
                        
</ItemTemplate>
                  
</asp:TemplateField>
                  
<asp:BoundField DataField="指标ID" HeaderText="指标ID" />
                  
<asp:BoundField DataField="指标名称" HeaderText="指标名称" />
                  
<asp:BoundField DataField="年份" HeaderText="年份" />
                  
<asp:BoundField DataField="月份" HeaderText="月份" />
                  
<asp:BoundField DataField="指标值" HeaderText="指标值" />
                  
            
</Columns>
    
</asp:GridView>
    
<br />
    
<table style="width: 635px">
        
<tr>
            
<td style="width: 154px; height: 36px">
    
<asp:Label ID="KeyWordLabel" runat="server" Height="32px" Text="请输入PBC库指标关键字:" Width="154px"></asp:Label></td>
            
<td style="width: 253px; height: 36px">
    
<asp:TextBox ID="KeyWordTextBox" runat="server" Height="26px" Width="243px"></asp:TextBox></td>
            
<td style="width: 217px; height: 36px">
    
<asp:Button ID="PBCButton" runat="server" Height="29px" Text="显示PBC库指标" Width="106px" OnClick="PBCButton_Click" /></td>
        
</tr>
    
</table>
    
<asp:GridView ID="PBCGridView" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
        BorderWidth
="1px" CellPadding="2" ForeColor="Black" GridLines="None" Height="153px"
        Width
="639px">
        
<FooterStyle BackColor="Tan" />
        
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
        
<HeaderStyle BackColor="Tan" Font-Bold="True" />
        
<AlternatingRowStyle BackColor="PaleGoldenrod" />
              
<Columns>
                
<asp:TemplateField HeaderText="全选">
                    
<HeaderTemplate>
                        
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" type="checkbox" />全选
                    
</HeaderTemplate>
                     
<ItemTemplate>
                        
<asp:CheckBox ID="CheckBox1" runat="server" />
                    
</ItemTemplate>
                    
<FooterTemplate>
                        
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" type="checkbox" />全选
                    
</FooterTemplate>
                
</asp:TemplateField>
            
</Columns>
    
</asp:GridView>
    
&nbsp;<br />
    
&nbsp;<br />
    
<asp:Button ID="Import" runat="server" Height="32px" Text="导出数据" Width="156px" OnClick="Import_Click" /><br />
    
<br />
    
<hr style="width: 658px; height: 1px" />
    
<asp:Button ID="Export" runat="server" Height="32px" Text="导入数据" Width="156px" />
</asp:Content>

转载于:https://www.cnblogs.com/xubensave/archive/2008/09/27/2430439.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值