动态生成控件,达到顾虑动态绑不同类的报表

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CMB.MgmtCockpit.Portal.WCFService;
using CMB.MgmtCockpit.BusinessLogic;
using System.Web.Services;
using System.Web.Script.Serialization;
using CMB.MgmtCockpit.Common;

namespace CMB.MgmtCockpit.Portal._Layouts.MgmtCockpit.Portal.Report
{
    public partial class ReportingItemWithBI : PageBase
    {
        string HierarchyEName = "";

        public string SSISName
        {
            get { return ViewState["SSISName"] as string; }
            set { ViewState["SSISName"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            SSISName = "";
            if (this.Request.QueryString["Param"] != null)
            {
                HierarchyEName = this.Request.QueryString["Param"].ToString();
                SSISName = HierarchyEName;
            }
            if (!IsPostBack)
            {
                using (ITIL_DBEntities db = new ITIL_DBEntities())
                {
                    if (HierarchyEName != null || HierarchyEName != "")
                    {
                        BindReportData(HierarchyEName);
                    }
                    else
                    {
                        BindReportData("");
                    }
                }
            }
            if (HierarchyEName == "HRReport" || HierarchyEName == "TPReport")
            {
                BindReportData();
            } 

            CreateControl(HierarchyEName,"THolderTableZY","专用报表");//通用报表
            CreateControl(HierarchyEName, "HolderTable", "通用报表");//通用报表
            CreateControl(HierarchyEName, "TableZhuQi", "主题报表");//通用报表
            //CreateControl2();//专用报表
            //CreateControl5();//主题报表
        }


        private void BindReportData(string HierarchyEName = "")
        {
            if (HierarchyEName != "")
            {
                using (ITIL_DBEntities db = new ITIL_DBEntities())
                {
                    AspNetPager1.RecordCount = (from c in db.View_ReportingItemDetail
                                                where c.IndicatorTypeEName == HierarchyEName && c.ReportUrl != "" && c.ShowInList == 1
                                                orderby c.ReportCode
                                                select c).Count();
                    int pageIndex = AspNetPager1.CurrentPageIndex;
                    int pageSize = AspNetPager1.PageSize;
                    var ReportingItem = (from c in db.View_ReportingItemDetail
                                         where c.IndicatorTypeEName == HierarchyEName && c.ReportUrl != "" && c.ShowInList == 1 && c.ReportCode != ""
                                         orderby c.ReportCode
                                         select c).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

                    ListView_IndicatorMeaning.DataSource = ReportingItem;
                    ListView_IndicatorMeaning.DataBind();

                    var AnalysisItem = (from c in db.View_AnalysisOnLineItemDetail
                                        where c.IndicatorTypeEName == HierarchyEName && (c.PowerViewUrl != "" || c.ExcelServiceUrl != "")
                                        orderby c.ReportCode
                                        select c).ToList();


                    ListView1.DataSource = AnalysisItem;
                    ListView1.DataBind();
                }
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindReportData(SSISName);
        }

        protected void ImageButton_Collection_Click(object sender, EventArgs e)
        {
            string UserID = SharepointHelper.GetUserLoginName();
            if (UserID == null || UserID == "")
            {
                Response.Redirect("../../portal/login.aspx", true);
            }
            using (ITIL_DBEntities db = new ITIL_DBEntities())
            {
                Button ib = (Button)sender;
                int RSID = int.Parse(ib.CommandArgument);
                var ReportInfo = (from c in db.View_ReportingItemDetail
                                  where c.ReportingItemDetailID == RSID
                                  select c).FirstOrDefault();

                var CollectionInfo = (from c in db.View_IndicatorPersonalCollection
                                      where c.CreateEmp == UserID && c.State == "1" && c.URL == ReportInfo.ReportUrl
                                      select c).FirstOrDefault();
                if (CollectionInfo != null && CollectionInfo.URL.Length > 0)
                {
                    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "AddCollectione", "alert('报表已收藏,可在“我的关注”中查看。');", true);
                }
                else
                {
                    WCFService.IndicatorPersonalCollection newMeaning = new WCFService.IndicatorPersonalCollection();
                    newMeaning.CreateDate = DateTime.Now;
                    newMeaning.CollectionID = Guid.NewGuid().ToString();
                    newMeaning.CreateEmp = UserID;
                    newMeaning.Title = ReportInfo.ReportName;
                    newMeaning.CollectType = "报表浏览";
                    newMeaning.State = "1";
                    newMeaning.URL = ReportInfo.ReportUrl;
                    db.AddToIndicatorPersonalCollection(newMeaning);
                    db.SaveChanges();
                    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "AddCollection", "alert('收藏成功,可在“我的关注”中查看。');", true);
                }
            }
        }



        //ButZhuanYong_Click  /ButZhuQi_Click"ButTY_Click
        protected void But_Click(object sender, EventArgs e)
        {
            Button a = (Button)sender; 
            BindReportData3(HierarchyEName, a.CommandArgument.ToString()); 
        } 
       
        #region 通用报表

        public void CreateControl(string reportENama,string tbname,string typename)
        {

              //<asp:Button ID="Button4" OnClick="But_Click" CommandArgument="专用报表" runat="server" Text="all专用报表"  />
            int count = 1;
            Button btone = new Button();
            btone.Text ="ALL"+ typename;

            btone.CommandArgument = typename;
            btone.Click += But_Click;

            TableRow tr = new TableRow();
            TableCell cell1 = new TableCell();//格子

            cell1.Controls.Add(btone);

            using (ITIL_DBEntities db = new ITIL_DBEntities())
            {
                var mdxList = from c in db.View_ReportingType
                              where c.IndicatorTypeEName == reportENama && c.ReportType == typename
                              group c by new { xIndicatorTypeEName = c.IndicatorTypeEName, xReportType = c.ReportType, xReportSubType = c.ReportSubType } into g
                              select new { g.Key.xIndicatorTypeEName, g.Key.xReportType, g.Key.xReportSubType };


                //组合多个结果
                MDXParam mdp = new MDXParam();
                foreach (var oneItem in mdxList)
                {
                    TableCell cell = new TableCell();//格子
                    Button bt1 = new Button();
                    bt1.Text = string.Format("{0}", oneItem.xReportSubType.ToString());

                    bt1.CommandArgument = oneItem.xReportType.ToString();
                    bt1.Click += bt_Click;
                    if (count < 2)
                    {
                        tr.Cells.Add(cell1);
                    }
                    cell.Controls.Add(bt1);
                    tr.Cells.Add(cell);
                    count++;
                }
                //HolderTable
                Table a = (Table)this.form1.FindControl(tbname);
                a.Rows.Add(tr);
            }



            //------------------------------------------------------------------------------------------------------------------------------------
          
        }
        void bt_Click(object sender, EventArgs e)
        {
            SSISName = HierarchyEName;
            Button a = (Button)sender;
            BindReportData2(HierarchyEName, a.CommandArgument.ToString(), a.Text);
        }
        #endregion

        /// <summary>
        /// 通用报公共-----------------
        /// </summary>
        /// <param name="HierarchyEName"></param>
        private void BindReportData2(string HierarchyEName = "", string ReportType = "", string ReportSubType = "")//1
        {
            if (HierarchyEName != "")
            {
                using (ITIL_DBEntities db = new ITIL_DBEntities())
                {
                    AspNetPager1.RecordCount = (from c in db.View_ReportingItemDetail
                                                where c.IndicatorTypeEName == HierarchyEName && c.ReportUrl != "" && c.ShowInList == 1 && c.ReportType == ReportType && c.ReportSubType == ReportSubType
                                                orderby c.ReportCode
                                                orderby c.ReportCode
                                                select c).Count();
                    int pageIndex = AspNetPager1.CurrentPageIndex;
                    int pageSize = AspNetPager1.PageSize;
                    var ReportingItem = (from c in db.View_ReportingItemDetail
                                         where c.IndicatorTypeEName == HierarchyEName && c.ReportUrl != "" && c.ShowInList == 1 && c.ReportType == ReportType && c.ReportSubType == ReportSubType
                                         orderby c.ReportCode
                                         select c).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

                    ListView_IndicatorMeaning.DataSource = ReportingItem;
                    ListView_IndicatorMeaning.DataBind(); 
                }
            }
        }
        private void BindReportData3(string HierarchyEName = "", string ReportType = "")
        {
            if (HierarchyEName != "")
            {
                using (ITIL_DBEntities db = new ITIL_DBEntities())
                {
                    AspNetPager1.RecordCount = (from c in db.View_ReportingItemDetail
                                                where c.IndicatorTypeEName == HierarchyEName && c.ReportUrl != "" && c.ShowInList == 1 && c.ReportType == ReportType
                                                orderby c.ReportCode
                                                orderby c.ReportCode
                                                select c).Count();
                    int pageIndex = AspNetPager1.CurrentPageIndex;
                    int pageSize = AspNetPager1.PageSize;
                    var ReportingItem = (from c in db.View_ReportingItemDetail
                                         where c.IndicatorTypeEName == HierarchyEName && c.ReportUrl != "" && c.ShowInList == 1 && c.ReportType == ReportType
                                         orderby c.ReportCode
                                         select c).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

                    ListView_IndicatorMeaning.DataSource = ReportingItem;
                    ListView_IndicatorMeaning.DataBind(); 
                }
            }

        }

.aspx 前台

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportingItemWithBI.aspx.cs" Inherits="CMB.MgmtCockpit.Portal._Layouts.MgmtCockpit.Portal.Report.ReportingItemWithBI" %>

<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI.WebControls" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        #Layer1 {
            height: 160px;
            width: 450px;
            border: 5px solid #999;
            <%--display:none;--%>
            font-family: "微软雅黑", Verdana, sans-serif, "宋体";
            font-weight: bold;
            text-indent: 1em;
        }

            #Layer1 #win_top {
                height: 30px;
                width: 450px;
                border-bottom-width: 1px;
                border-bottom-style: solid;
                border-bottom-color: #999;
                line-height: 30px;
                color: #666;
                font-family: "微软雅黑", Verdana, sans-serif, "宋体";
                font-weight: bold;
                text-indent: 1em;
            }
    </style>
    

    <link rel="stylesheet" type="text/css" href="/_Layouts/Information/css/layout.css" />
    <link rel="stylesheet" type="text/css" href="/_Layouts/Information/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/_Layouts/Information/css/easyui.css" />
    <%--<script type="text/javascript" src="_Layouts/MgmtCockpit/js/json2.js"></script>--%>

    <script type="text/javascript" src="/_Layouts/Information/js/jquery-1.8.3.min.js"></script>
    <script src="/_Layouts/Information/js/Common.js"></script>
    <script src="/_Layouts/Information/js/LoadSilverLight.js"></script>
    <script type="text/javascript" src="/_Layouts/Information/js/jquery.easyui.min.js"></script>
    <script language="javascript">
        function openDialogWin(RSID) {
            window.showModalDialog("SelectCollectionItemType.aspx?RSID=" + RSID, window, 'center=yes;help=no;status=no;dialogheight:150px;dialogwidth:350px;scroll:no')
        }
        function selectTag(showContent, selfObj) {
            // 操作标签
            var tag = document.getElementById("tags").getElementsByTagName("li");
            var taglength = tag.length;
            for (i = 0; i < taglength; i++) {
                tag[i].className = "";
            }
            selfObj.parentNode.className = "selectTag";
            // 操作内容
            for (i = 0; j = document.getElementById("tagContent" + i) ; i++) {
                j.style.display = "none";
            }
            document.getElementById(showContent).style.display = "block";
        }
        $(document).ready(function () {
            document.getElementById("tagContent0").style.display = "block";
        });
    </script>




</head>
<body class="bgcolor_fff">

    <form id="form1" runat="server" class="form-height">
        <!--tab开始-->
        <div class="Kon_statement_wrap">
            <div id="con" class="Kon_min_h1">
                <div class="Kon_tab_wrap">
                    <ul id="tags">
                        <li class="selectTag selectTag_two"><a onclick="selectTag('tagContent0',this)" href="javascript:void(0)">数据报表</a> </li>
                        <li><a onclick="selectTag('tagContent1',this)" href="javascript:void(0)">自助报表</a> </li>
                    </ul>
                    
                    <div class="cl_both">


                    </div>
                </div>


            </div>
          

            <%-- //1--%>
            <div id="tagContent" class="Kon_statement">
                 
             
            <div class="tagContent selectTag" id="tagContent0" style="background: none; border:0px solid #808080">
                       <div id="Layer1" style="border:none">
                 
                   <div style="border:0px solid #ffffff; width:80px;height:120px;float:left; width:1000px;" >

                                       <div style="border:1px solid #808080;width:500px;height:20px;" ><h3>专用报表</h3>  
                                             <asp:Table ID="THolderTableZY" runat="server"></asp:Table>
                                       </div>
                                     <div style="border:1px solid #808080;width:500px;height:20px;"><h3>通用报表</h3> 
                                          <asp:Table ID="HolderTable" runat="server"></asp:Table>
                                     </div> 
                                    <div style="border:1px solid #808080;width:500px;height:20px;"><h3>主题报表</h3>  
                                        <asp:Table ID="TableZhuQi" runat="server"></asp:Table>
                                     </div>                    
                              </div>
                       </div>
                    <div class="KonS_tab_box">
                        <div class="" id="tab_box1">
                            <asp:ListView ID="ListView_IndicatorMeaning" runat="server">
                                <LayoutTemplate>
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="Kontab_list datatable">
                                        <tr>
                                            <th width="10%">报表类型
                                            </th>
                                            <th width="12%">报表编码
                                            </th>
                                            <th width="30%">报表名称
                                            </th>
                                            <th width="22%">报表说明
                                            </th>
                                            <th width="16%">创建日期
                                            </th>
                                            <th width="10%">操作
                                            </th>
                                        </tr>
                                        <tr runat="server" id="itemPlaceholder" />
                                    </table>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td class="Kon_td_bt" width="10%">
                                            <asp:Label ID="Label_ReportType" runat="server" Text='<%# Eval("ReportType") %>'></asp:Label>
                                        </td>
                                        <td class="Kon_td_bt" width="12%">
                                            <asp:Label ID="Label_ReportCode" runat="server" Text='<%# Eval("ReportCode") %>'></asp:Label>
                                        </td>
                                        <td class="Kon_td_bt" width="30%">
                                            <asp:Label ID="Label_ReportName" runat="server" Text='<%# Eval("ReportName") %>'></asp:Label>
                                        </td>
                                        <td class="Kon_td_bt" width="22%">
                                            <asp:Label ID="Label_Remark" runat="server" Text='<%# Eval("ReportRemark") %>'></asp:Label>
                                        </td>
                                        <td width="16%">
                                            <asp:Label ID="Label_DraftDate" runat="server" Text='<%# Eval("CreateDate") %>'></asp:Label></td>
                                        <td width="10%" align="center">
                                            <a href='<%# Eval("ReportUrl") %>' target="_blank" class="Kon_button_tiqu" title="提取报表"></a>

                                            <%--<a href="../../AdminPortal/AdminIndex.aspx?url=IndicatorInfo/Collection.aspx?RSID=<%# Eval("ReportingItemDetailID") %>|RS=<%# Eval("ReportUrl") %>" target="_blank" class="Kon_button_shoucang" title="收藏关注"></a>--%>
                                            <%--<asp:ImageButton id="ImageButton_Collection1" OnClick="ImageButton_Collection_Click" CommandArgument='<%# Eval("ReportingItemDetailID") %>' runat="server" class="Kon_button_shoucang"  title="点击添加收藏"></asp:ImageButton>--%>
                                            <asp:Button ID="ImageButton_Collection" runat="server" OnClick="ImageButton_Collection_Click" Text="" CommandArgument='<%# Eval("ReportingItemDetailID") %>' runat="server" class="Kon_button_shoucang" title="点击添加收藏"></asp:Button>
                                        </td>

                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>

                            <table cellpadding="0" cellspacing="0" align="center" width="99%" class="border">
                                <tr>
                                    <td align="left" colspan="2">
                                        <webdiyer:AspNetPager ID="AspNetPager1" CssClass="paginator" CurrentPageButtonClass="cpb" runat="server" AlwaysShow="True"
                                            FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PageSize="15" PrevPageText="上一页" ShowCustomInfoSection="Never"
                                            ShowInputBox="Never" OnPageChanged="AspNetPager1_PageChanged" CustomInfoTextAlign="Left" LayoutType="Table">
                                        </webdiyer:AspNetPager>
                                    </td>
                                </tr>
                            </table>
                        </div>

                    </div>
                                  
              </div>
       </div>




                </div>
                <div class="tagContent" id="tagContent1">
                    <div class="KonS_tab_box">
                        <div class="" id="tab_box2">
                            <asp:ListView ID="ListView1" runat="server">
                                <LayoutTemplate>
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="Kontab_list datatable">
                                        <tr>
                                            <th width="10%">报表编码
                                            </th>
                                            <th width="35%">报表名称
                                            </th>
                                            <th width="33%">报表说明
                                            </th>
                                            <th width="12%">创建日期
                                            </th>
                                            <th width="10%">操作
                                            </th>
                                        </tr>
                                        <tr runat="server" id="itemPlaceholder" />
                                    </table>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td class="Kon_td_bt" width="10%">
                                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("ReportCode") %>'></asp:Label>
                                        </td>
                                        <td class="Kon_td_bt" width="35%">
                                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("ReportName") %>'></asp:Label>
                                        </td>
                                        <td class="Kon_td_bt" width="33%">
                                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("ReportRemark") %>'></asp:Label>
                                        </td>
                                        <td width="12%">
                                            <asp:Label ID="Label4" runat="server" Text='<%# Eval("CreateDate") %>'></asp:Label></td>
                                        <td width="10%" align="center">
                                            <a href='<%# Eval("PowerViewUrl") %>' target="_blank" class="Kon_button_BI" title="提取自助BI报表"></a>&nbsp;
                                                            <a href='<%# Eval("ExcelServiceUrl") %>' target="_blank" class="Kon_button_EX" title="提取ExcelService报表"></a>&nbsp;
                                                            <a onclick="openDialogWin('<%# Eval("ReportingItemDetailID") %>');" class="Kon_button_shoucang" title="点击添加收藏"></a>

                                        </td>

                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>
                        </div>

                    </div>
                </div>
         
        <!--tab结束-->

    </form>
</body>
</html>

       
    }
}

posted @ 2016-12-07 11:20  狼牙者.net  阅读(207)  评论(0)    收藏  举报