构建统计图标 - StatisticItemContainer

2017-02-24 09:20:46  访问(1462) 赞(0) 踩(0)

  • using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace SlowX.Statistic.Classes
    {
        /// <summary>
        /// 统计项
        /// </summary>
        [Serializable]
        public class StatisticItemContainer
        {
            /// <summary>
            /// X轴字段
            /// </summary>
            public const string x_Id = "{x-Id}";
    
            /// <summary>
            /// 
            /// </summary>
            public const string y_Id = "{y-Id}";
    
            /// <summary>
            /// 
            /// </summary>
            public const string x_TheName = "{x-TheName}";
    
            /// <summary>
            /// 
            /// </summary>
            public const string y_TheName = "{y-TheName}";
    
            /// <summary>
            /// 
            /// </summary>
            public const string v_TheNumber = "{TheNumber}";
    
            /// <summary>
            /// 默认参数
            /// </summary>
            public readonly static string[] defaultItemClickScriptParams 
                = 
                GetDefaultItemClickScriptParams();
    
            /// <summary>
            /// 默认参数
            /// </summary>
            /// <returns></returns>
            public static string[] GetDefaultItemClickScriptParams()
            {
                string[] theResult
                    = 
                    new string[3];
    
                theResult[0] = x_Id;
                theResult[1] = y_Id;
                theResult[2] = v_TheNumber;
    
                return theResult;
            }
    
            /// <summary>
            /// 默认参数
            /// </summary>
            public readonly static string[] defaultOneItemClickScriptParams 
                = 
                GetDefaultOneItemClickScriptParams();
    
            /// <summary>
            /// 默认参数
            /// </summary>
            /// <returns></returns>
            public static string[] GetDefaultOneItemClickScriptParams()
            {
                string[] theResult = new string[2];
    
                theResult[0] = x_Id;
                theResult[1] = v_TheNumber;
    
                return theResult;
            }
    
    
            /// <summary>
            /// 统计项
            /// </summary>
            public StatisticItemContainer()
            {
    
            }
    
            /// <summary>
            /// X轴的列表
            /// </summary>
            protected Dictionary<string, string> m_dictionaryX = null;
    
            /// <summary>
            /// Y轴的列表
            /// </summary>
            protected Dictionary<string, string> m_dictionaryY = null;
    
            /// <summary>
            /// 数值
            /// </summary>
            protected List<StatisticItemTwo> m_TheNumber = null;
    
            /// <summary>
            /// 打印NumberShow
            /// </summary>
            protected bool m_printNumberShow = false;
    
            /// <summary>
            /// 脚本语句
            /// </summary>
            protected string m_itemClickScript = "";
    
            /// <summary>
            /// 脚本参数
            /// </summary>
            protected string[] m_itemClickScriptParams = null;
    
            /// <summary>
            /// X轴
            /// </summary>
            public Dictionary<string, string> dictionaryX
            {
                get
                {
                    return m_dictionaryX;
                }
                set
                {
                    m_dictionaryX = value;
                }
            }
    
            /// <summary>
            /// Y轴
            /// </summary>
            public Dictionary<string, string> dictionaryY
            {
                get
                {
                    return m_dictionaryY;
                }
                set
                {
                    m_dictionaryY = value;
                }
            }
    
            /// <summary>
            /// 数值
            /// </summary>
            public List<StatisticItemTwo> TheNumber
            {
                get
                {
                    return m_TheNumber;
                }
                set
                {
                    m_TheNumber = value;
                }
            }
    
            /// <summary>
            /// 打印NumberShow
            /// </summary>
            public bool  printNumberShow
            {
                get
                {
                    return m_printNumberShow;
                }
                set
                {
                    m_printNumberShow = value;
                }
            }
    
            /// <summary>
            /// 单元格点击事件
            /// </summary>
            public string itemClickScript
            {
                get
                {
                    return m_itemClickScript;
                }
                set
                {
                    m_itemClickScript = value;
                }
            }
    
    
            /// <summary>
            /// 单元格点击事件
            /// </summary>
            public string[] itemClickScriptParams
            {
                get
                {
                    return m_itemClickScriptParams;
                }
                set
                {
                    m_itemClickScriptParams = value;
                }
            }
        }
    }
    
    

  • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="WebForms_AdmFineUI_Szdf_ZK_Zyjcd_Stats_Jcnr_List" ValidateRequest="false" %>


    <!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>

    <link href="~/css/font14.css" rel="stylesheet" type="text/css" />
    </head>
    <body style="margin: 0px;">
    <script src="<%=WebCommonData.phyPath %>/JavaScripts/ChartsInit.js" type="text/javascript"></script>
    <form id="form1" runat="server">
    <x:PageManager ID="PageManager1" AutoSizePanelID="main_TabStrip" runat="server" />
    <x:TabStrip ID="main_TabStrip" runat="server" ShowBorder="false"
    EnableAjaxLoading="true" AutoPostBack="true" OnTabIndexChanged="main_TabStrip_TabIndexChanged">
    <Toolbars>
    <x:Toolbar ID="Toolbar1" runat="server" Hidden="true">
    <Items>
    <x:ToolbarText ID="lbl_Title" runat="server" Text="检查内容统计"></x:ToolbarText>
    <x:Button ID="btn_RefreshPage" EnablePostBack="false" Icon="PageRefresh" runat="server" Text=""
    ToolTip="刷新">
    </x:Button>
    </Items>
    </x:Toolbar>
    </Toolbars>
    <Tabs>
    <x:Tab ID="tab_Table" runat="server" Title="统计表">
    <Items>
    <x:Label ID="lbl_Result" EncodeText="false" runat="server"></x:Label>
    </Items>
    </x:Tab>
    <x:Tab ID="tab_Chart" runat="server" Title="统计图">
    <Items>
    <x:ContentPanel ShowHeader="false" ShowBorder="false" runat="server" ID="df">
    <div id="container" style="width: 100%; height: 500px;"></div>
    </x:ContentPanel>
    </Items>
    </x:Tab>
    <x:Tab ID="tab1" runat="server" Title="搜索条件">
    <Items>
    <x:Form runat="server" ID="form_AdvSearch" LabelWidth="100px" EnableBackgroundColor="true" Height="220px" AutoHeight="true" ShowBorder="false" ShowHeader="false" BodyPadding="10px">
    <Rows>
    <x:FormRow ID="FormRow5" runat="server">
    <Items>
    <x:DatePicker ID="dpsFrom_CheckDate" runat="server" Label="检查日期"></x:DatePicker>
    <x:DatePicker ID="dpsTo_CheckDate" runat="server" LabelSeparator="" Label="至"></x:DatePicker>
    </Items>
    </x:FormRow>
    <x:FormRow ID="FormRow1" runat="server">
    <Items>
    <x:DropDownList ID="ddl_HighchartType" AutoPostBack="true" OnSelectedIndexChanged="ddl_HighchartType_SelectedIndexChanged" runat="server" Label="统计图"></x:DropDownList>
    <x:Button ID="btn_Query" runat="server" Text="查询统计" Icon="SystemSearch" OnClick="btn_Query_Click"></x:Button>
    </Items>
    </x:FormRow>
    </Rows>
    </x:Form>
    </Items>
    </x:Tab>
    </Tabs>
    </x:TabStrip>

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

  • using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using SlowX.Common;
    using SlowX.Core.Functions;
    using SlowX.Core.Model;
    using SlowX.DAL.Helpers;
    using SlowX.FineUIUtils.Functions;
    using SlowX.UserLib.Common;
    using SlowX.Exceptions;
    using System.Reflection;
    using SlowX.Class.Classess;
    using SlowX.Core.Classes;
    using SlowX.Functions.Functions;

    using SlowX.WebSite.Common;
    using SlowX.Functions.DrawTableClasses;

    using SlowX.Statistic.Classes;
    using SlowX.Statistic.Functions;
    using SlowX.WebSite.IBLL;
    using SlowX.Highcharts.Functions;
    using SlowX.Highcharts.Classes;
    using SlowX.Core.ICoreClasses;
    using SlowX.WebSite.Pages;


    public partial class WebForms_AdmFineUI_Szdf_ZK_Zyjcd_Stats_Jcnr_List
    :
    PageBase
    {
    /// <summary>
    /// Charts.Init 的 JavaScript
    /// </summary>
    protected string chartsInitJavaScript
    {
    get
    {
    return StringSlowXFunctions.NullToEmpty(ViewState["chartsInitJavaScript"]);
    }
    set
    {
    ViewState["chartsInitJavaScript"] = value;
    }
    }

    /// <summary>
    /// 执行查询统计
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Query_Click(object sender, EventArgs e)
    {
    try
    {
    DataBindStatControls(null);
    }
    catch (Exception err)
    {
    PageBaseExceptionDO(err);
    }
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddl_HighchartType_SelectedIndexChanged(object sender, EventArgs e)
    {
    try
    {
    DataBindStatControls(null);
    }
    catch (Exception err)
    {
    PageBaseExceptionDO(err);
    }
    }

    #region 加载事件

    /// <summary>
    /// 绑定控件
    /// </summary>
    /// <param name="dbHelper"></param>
    protected void DataBindTheControls(DBHelper dbHelper)
    {
    bool bIsCreate = true;

    if (dbHelper == null)
    {
    dbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
    }
    else
    {
    // 没有打开链接 //
    bIsCreate = dbHelper.IsNotOpen();
    }

    try
    {
    if (bIsCreate)
    dbHelper.OpenDBHelper();

    // 初始化控件 //
    InitTheControls(dbHelper);

    // 绑定列表 //
    DataBindStatControls(dbHelper);

    if (bIsCreate)
    dbHelper.EndDBHelper();

    }
    catch (Exception err)
    {
    if (bIsCreate)
    dbHelper.TranDBHelper();

    throw err;
    }
    finally
    {
    if (bIsCreate)
    dbHelper.FinallyDBHelper();
    }
    }

    #region 初始化控件

    /// <summary>
    /// 初始化控件
    /// </summary>
    /// <param name="dbHelper"></param>
    protected void InitTheControls(DBHelper dbHelper)
    {
    bool bIsCreate = true;

    if (dbHelper == null)
    {
    dbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
    }
    else
    {
    // 没有打开链接 //
    bIsCreate = dbHelper.IsNotOpen();
    }

    try
    {
    if (bIsCreate)
    dbHelper.OpenDBHelper();

    IFineUIUtil iFineUI = WebSiteBLL.instance;

    //iFineUI.InitFineUIDropDownListByDataTable
    // (
    // ddl_HighchartType,
    // SlowX.Highcharts.Enums.HighchartType.GetDataTable(),
    // SlowX.FineUIUtils.Enums.ListControlAddItem.EmListControlAddItem.自定义
    // );

    ddl_HighchartType.Items.Add
    (
    new FineUI.ListItem
    (
    SlowX.Highcharts.Enums.HighchartType.EmHighchartType.柱状图.ToString(),
    ((int)SlowX.Highcharts.Enums.HighchartType.EmHighchartType.柱状图).ToString()
    )
    );

    ddl_HighchartType.Items.Add
    (
    new FineUI.ListItem
    (
    SlowX.Highcharts.Enums.HighchartType.EmHighchartType.线状图.ToString(),
    ((int)SlowX.Highcharts.Enums.HighchartType.EmHighchartType.线状图).ToString()
    )
    );

    if (ddl_HighchartType.Items.Count > 0)
    ddl_HighchartType.SelectedIndex = 0;



    if (bIsCreate)
    dbHelper.EndDBHelper();

    }
    catch (Exception err)
    {
    if (bIsCreate)
    dbHelper.TranDBHelper();

    throw err;
    }
    finally
    {
    if (bIsCreate)
    dbHelper.FinallyDBHelper();
    }
    }

    #endregion 初始化控件

    #region 绑定列表控件

    /// <summary>
    /// 绑定列表控件
    /// </summary>
    /// <param name="iPageIndex"></param>
    /// <param name="iRowCount"></param>
    /// <param name="dbHelper"></param>
    protected void DataBindStatControls
    (
    DBHelper dbHelper
    )
    {
    bool bIsCreate = true;

    bool isDetail = false;

    if (dbHelper == null)
    {
    dbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
    }
    else
    {
    // 没有打开链接 //
    bIsCreate = dbHelper.IsNotOpen();
    }

    try
    {
    if (bIsCreate)
    dbHelper.OpenDBHelper();

    SlowX.Highcharts.Enums.HighchartType.EmHighchartType
    em
    =
    SlowX.Highcharts.Enums.HighchartType.GetEmByString(this.ddl_HighchartType.SelectedValue);

    // isDetail = (ddls_YwyId.SelectedValue == "");

    // 合并 //
    // 饼图效果 //
    isDetail = true;


    List<StatisticItemOne> theList = null;

    // 容器 //
    StatisticItemContainer statisticItemContainerValue = null;

    if (isDetail)
    {
    statisticItemContainerValue = new StatisticItemContainer();
    statisticItemContainerValue.dictionaryX
    =
    DataSetSlowXFunctions.DataTableToDictionary
    (
    eKing.SzdfLib.Business.ZKB.UTB_SZDF_ZKB_JCNR.instance.GetCacheBasicDataTable
    (
    SlowX.Core.Enums.CacheModel.EmCacheModel.字典数据, dbHelper
    )
    );

    statisticItemContainerValue.dictionaryY
    =
    DataSetSlowXFunctions.DataTableToDictionary
    (
    eKing.SzdfLib.Enums.ZkCheck.ReturnDataTable()
    );
    }
    else
    {
    // theList = iHelper.CreateListStatisticItemOne(dtFrom, dtTo);
    }


    eKing.SzdfLib.Business.ZK.UTB_SZDF_ZK_ZYJCD bll = eKing.SzdfLib.Business.ZK.UTB_SZDF_ZK_ZYJCD.instance;
    eKing.SzdfLib.Entity.ZK.UTB_SZDF_ZK_ZYJCD entity = new eKing.SzdfLib.Entity.ZK.UTB_SZDF_ZK_ZYJCD();

    IQueryDriver iq = entity;
    ISelectDriver iselect = entity;

    iq.InitIQueryItem(SlowX.Core.Enums.WhereModel.EmWhereModel.显示);



    iq.AddIQueryItemSearchFromToStringDateTimeValue
    (
    entity._CheckDate,
    dpsFrom_CheckDate.Text,
    dpsTo_CheckDate.Text
    );





    iselect.AddISelectItemWithEntityFieldInfo(entity._ID);
    iselect.AddISelectItemWithEntityFieldInfo(entity._EmZkCheck_V);
    iselect.AddISelectItemWithEntityFieldInfo(entity._ZKB_JCNR_Ids);

    // entity.i_iselectDriver.AddISelectItemWithEntityFieldInfo(entity._OperatorId);

    DataSet ds = bll.List(entity, dbHelper);
    string strResult = "";
    string js = "";

    if (isDetail)
    {
    // 做二维 //
    string xId = "";
    string yId = "";
    string xDataColumnName = entity._ZKB_JCNR_Ids._Name;
    string yDataColumnName = entity._EmZkCheck_V._Name;

    bool isFindItem = false;
    List<StatisticItemTwo> theTwoList = new List<StatisticItemTwo>();
    StatisticItemTwo two = null;

    string[] sA = null;

    foreach (DataRow dr in ds.Tables[0].Rows)
    {
    xId = dr[xDataColumnName].ToString();

    if (xId.Length == 0)
    continue;

    yId = dr[yDataColumnName].ToString();

    if (yId.Length == 0)
    continue;

    sA = xId.Split(',');

    foreach (string s in sA)
    {
    isFindItem = false;

    foreach (StatisticItemTwo item in theTwoList)
    {
    if (item.yID == yId)
    {
    if (s == item.xID )
    {
    isFindItem = true;
    item.TheNumber += 1;
    break;
    }
    }
    }

    if (!isFindItem)
    {
    two = new StatisticItemTwo(s, yId, 1);
    theTwoList.Add(two);
    }

    }
    }

    statisticItemContainerValue.TheNumber = theTwoList;

    switch (em)
    {
    case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.饼图:
    strResult = WebSiteBLL.instance.CommonDrawStatTwoTable("合计", "<b>合计</b>", "类型/状态", statisticItemContainerValue);
    break;
    case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.线状图:
    case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.柱状图:
    strResult = WebSiteBLL.instance.CommonDrawStatTwoTable("合计", "<b>合计</b>", "类型/状态", statisticItemContainerValue);
    break;
    default:
    throw ThrowSlowXExceptions.NewSlowXExceptionUnkownEnumMessage(MethodBase.GetCurrentMethod(), em);
    }

    lbl_Result.Text = strResult;



    switch (em)
    {
    case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.柱状图:
    js = ColumnSlowXHighchartsFunctions.ToColumnBasicByDictionary
    (
    ColumnSlowXHighchartsFunctions.container,
    "类型",
    "",
    CommonSlowXStatisticFunctions.ToListTitleByDictionary(statisticItemContainerValue.dictionaryX),
    "个数",
    CommonSlowXStatisticFunctions.ToDictionaryListData(true, statisticItemContainerValue)
    );
    break;
    case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.线状图:
    js = LineSlowXHighchartsFunctions.ToLineLabelsByDictionary
    (
    ColumnSlowXHighchartsFunctions.container,
    "类型",
    "",
    CommonSlowXStatisticFunctions.ToListTitleByDictionary(statisticItemContainerValue.dictionaryX),
    "个数",
    CommonSlowXStatisticFunctions.ToDictionaryListData(true, statisticItemContainerValue)
    );
    break;
    case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.饼图:

    //List<PieBasicData> listPieBasicData = PieSlowXHighchartsFunctions.ToListPieBasicData
    // (
    // CommonSlowXStatisticFunctions.ToListTitle(theList),
    // CommonSlowXStatisticFunctions.ToListData(theList),
    // "{0} ({1})"
    // );

    //js = PieSlowXHighchartsFunctions.ToPieBasic
    //(
    // ColumnSlowXHighchartsFunctions.container,
    // "类型",
    // "个数",
    // listPieBasicData
    //);
    break;
    default:
    throw ThrowSlowXExceptions.NewSlowXExceptionUnkownEnumMessage(MethodBase.GetCurrentMethod(), em);
    }

    chartsInitJavaScript = js;

    }
    else
    {


    //string theID = "";
    //string dataColumnName = entity._StartUseDate._Name;


    //foreach (DataRow dr in ds.Tables[0].Rows)
    //{
    // theID = dr[dataColumnName].ToString();

    // if (theID.Length == 0)
    // continue;

    // theID = DateTime.Parse(theID).ToString("yyyyMM");

    // foreach (StatisticItemOne item in theList)
    // {
    // if (item.ID == theID)
    // {
    // item.TheNumber += 1;
    // break;
    // }
    // }
    //}

    //switch (em)
    //{
    // case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.饼图:
    // strResult = WebSiteBLL.instance.CommonDrawStatHorizontalTable(true, "合计", "类型", theList);
    // break;
    // case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.线状图:
    // case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.柱状图:
    // strResult = WebSiteBLL.instance.CommonDrawStatHorizontalTable(true, "合计", "类型", theList);
    // break;
    // default:
    // throw ThrowSlowXExceptions.NewSlowXExceptionUnkownEnumMessage(MethodBase.GetCurrentMethod(), em);
    //}

    //lbl_Result.Text = strResult;



    //switch (em)
    //{
    // case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.柱状图:
    // js = ColumnSlowXHighchartsFunctions.ToColumnBasic
    // (
    // ColumnSlowXHighchartsFunctions.container,
    // "类型",
    // "",
    // CommonSlowXStatisticFunctions.ToListTitle(theList),
    // "个数",
    // ColumnSlowXHighchartsFunctions.GetListBasicCommonData("个数", CommonSlowXStatisticFunctions.ToListData(theList))
    // );
    // break;
    // case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.线状图:
    // js = LineSlowXHighchartsFunctions.ToLineLabels
    // (
    // ColumnSlowXHighchartsFunctions.container,
    // "类型",
    // "",
    // CommonSlowXStatisticFunctions.ToListTitle(theList),
    // "个数",
    // ColumnSlowXHighchartsFunctions.GetListBasicCommonData("个数", CommonSlowXStatisticFunctions.ToListData(theList))
    // );
    // break;
    // case SlowX.Highcharts.Enums.HighchartType.EmHighchartType.饼图:

    // List<PieBasicData> listPieBasicData = PieSlowXHighchartsFunctions.ToListPieBasicData
    // (
    // CommonSlowXStatisticFunctions.ToListTitle(theList),
    // CommonSlowXStatisticFunctions.ToListData(theList),
    // "{0} ({1})"
    // );

    // js = PieSlowXHighchartsFunctions.ToPieBasic
    // (
    // ColumnSlowXHighchartsFunctions.container,
    // "类型",
    // "个数",
    // listPieBasicData
    // );
    // break;
    // default:
    // throw ThrowSlowXExceptions.NewSlowXExceptionUnkownEnumMessage(MethodBase.GetCurrentMethod(), em);
    //}

    //chartsInitJavaScript = js;

    }

    mainTabStripTabIndexChanged();

    if (bIsCreate)
    dbHelper.EndDBHelper();

    }
    catch (Exception err)
    {
    if (bIsCreate)
    dbHelper.TranDBHelper();

    throw err;
    }
    finally
    {
    if (bIsCreate)
    dbHelper.FinallyDBHelper();
    }

    }

    #endregion 绑定列表控件


    /// <summary>
    /// 切换统计图
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void main_TabStrip_TabIndexChanged(object sender, EventArgs e)
    {
    try
    {
    mainTabStripTabIndexChanged();
    }
    catch (Exception err)
    {
    PageBaseExceptionDO(err);
    }
    }

    /// <summary>
    /// 切换统计图
    /// </summary>
    protected void mainTabStripTabIndexChanged()
    {
    if (tab_Chart == main_TabStrip.ActiveTab)
    {
    FineUI.PageContext.RegisterStartupScript(chartsInitJavaScript);
    }
    }

    #endregion 加载事件


    /// <summary>
    /// 页面加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!WebSiteBLL.instance.i_IWebAppCheckPowerBLL.CheckPower())
    return;

    if (!this.IsPostBack)
    {
    DataBindTheControls(null);

    ButtonSlowXFineUIUtilsFunctions.WindowLocation(btn_RefreshPage, strCurUrl);

    }

    Header.Title = WebSiteBLL.instance.i_IWebAppCommonBLL.GetPageAdminTitle("检查内容统计");

    WebSiteBLL.instance.i_IWebAppCommonBLL.SetPageCss(Header, WebCommonData.AdminThemes + "/css/viewitem.css");

    }

    }

  • 
            /// <summary>
            /// 创建时间段 
            /// </summary>
            /// <param name="dtFrom"></param>
            /// <param name="dtTo"></param>
            /// <returns></returns>
            public Dictionary<string, string> CreateDictionaryDateTime
                (
                    DateTime dtFrom,
                    DateTime dtTo
                )
            {
                Dictionary<string, string> theResult = new Dictionary<string, string>();
    
                DateTime dtFromMonth = DateTime.Parse(dtFrom.ToString("yyyy-MM") + "-01");
                DateTime dtToMonth = DateTime.Parse(dtTo.ToString("yyyy-MM") + "-01");
    
    
                int idx = 0;
                DateTime dt = DateTime.Now;
    
                while (true)
                {
                    if (idx == 0)
                        dt = dtFromMonth;
                    else
                        dt = dtFromMonth.AddMonths(idx);
    
    
                    if (dt > dtToMonth)
                        break;
    
                    theResult.Add(dt.ToString("yyyyMM"), dt.ToString("yyyy年MM月"));
    
                    ++idx;
                }
    
                return theResult;
            }
    
    
            /// <summary>
            /// 创建时间段 
            /// </summary>
            /// <param name="dtFrom"></param>
            /// <param name="dtTo"></param>
            /// <returns></returns>
            public List<StatisticItemOne> CreateListStatisticItemOne
                (
                    DateTime dtFrom,
                    DateTime dtTo
                )
            {
                List<StatisticItemOne> theResult = new List<StatisticItemOne>();
    
                DateTime dtFromMonth = DateTime.Parse(dtFrom.ToString("yyyy-MM") + "-01");
                DateTime dtToMonth = DateTime.Parse(dtTo.ToString("yyyy-MM") + "-01");
    
                StatisticItemOne itemOne = null;
                int idx = 0;
                DateTime dt = DateTime.Now;
    
                while (true)
                {
                    if (idx == 0)
                        dt = dtFromMonth;
                    else
                        dt = dtFromMonth.AddMonths(idx);
    
    
                    if (dt > dtToMonth)
                        break;
    
                    itemOne = new StatisticItemOne();
                    itemOne.TheName = dt.ToString("yyyy年MM月");
                    itemOne.TheNumber = 0;
                    itemOne.ID = dt.ToString("yyyyMM");
    
                    theResult.Add(itemOne);
    
                    ++idx;
                }
    
                return theResult;
            }
    
    
            /// <summary>
            /// 填充DIV
            /// </summary>
            /// <param name="divHeight"></param>
            /// <param name="htmlValue"></param>
            /// <returns></returns>
            public string CommonFillDivOverflowAuto(int divHeight, string htmlValue)
            {
                if (htmlValue == null)
                    htmlValue = "";
    
                return "<div id=\"div_View\" style=\" padding-top:5px; text-align:center; width:100%;height:" + divHeight.ToString() + "px; overflow:auto;\">" + htmlValue + "</div>";
            }
    
            /// <summary>
            /// 绘制统计图表
            /// </summary>
            /// <param name="totalTitle"></param>
            /// <param name="title"></param>
            /// <param name="theList"></param>
            /// <returns></returns>
            public string CommonDrawStatTable
                (
                    string totalTitle,
                    string title,
                    List<StatisticItemOne> theList
                )
            {
    
                if (theList == null)
                    return "";
    
                int iCount = theList.Count;
    
                if (iCount <= 7)
                    return CommonDrawStatHorizontalTable(totalTitle, title, theList);
                else
                    return CommonDrawStatVerticalTable(totalTitle, title, theList);
            }
    
    
            /// <summary>
            /// 绘制统计图表
            /// </summary>
            /// <param name="showPercentage"></param>
            /// <param name="totalTitle"></param>
            /// <param name="title"></param>
            /// <param name="theList"></param>
            /// <returns></returns>
            public string CommonDrawStatTable
                (
                    bool showPercentage,
                    string totalTitle,
                    string title,
                    List<StatisticItemOne> theList
                )
            {
                if (theList == null)
                    return "";
    
                int iCount = theList.Count;
    
                if (iCount <= 7)
                    return CommonDrawStatHorizontalTable(showPercentage, totalTitle, title, theList);
                else
                    return CommonDrawStatVerticalTable(showPercentage, totalTitle, title, theList);
            }
    
            /// <summary>
            /// 绘制统计图表
            /// </summary>
            /// <param name="theList"></param>
            /// <returns></returns>
            public string CommonDrawStatVerticalTable
                (
                    string totalTitle,
                    string title,
                    List<StatisticItemOne> theList
                )
            {
                if (theList == null)
                    return "";
    
                StringBuilder theResult = new StringBuilder();
    
                theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + title + "</td>");
                theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">统计数</td>");
                theResult.Append("</tr>");
    
                foreach (StatisticItemOne item in theList)
                {
                    theResult.Append("<tr class=\"trItem\">");
                    theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + item.TheName + "</td>");
                    theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + item.TheNumber.ToString() + "</td>");
                    theResult.Append("</tr>");
                }
    
                if (totalTitle != null)
                {
                    decimal totalValue = 0;
    
                    foreach (StatisticItemOne item in theList)
                    {
                        totalValue += item.TheNumber;
                    }
    
                    theResult.Append("<tr class=\"trItem\">");
                    theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + totalTitle + "</td>");
                    theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + totalValue.ToString() + "</td>");
                    theResult.Append("</tr>");
                }
    
                theResult.Append("</table>");
    
                return CommonFillDivOverflowAuto(500, theResult.ToString());
            }
    
    
            /// <summary>
            /// 绘制统计图表
            /// </summary>
            /// <param name="theList"></param>
            /// <returns></returns>
            public string CommonDrawStatHorizontalTable
                (
                    string totalTitle,
                    string title,
                    List<StatisticItemOne> theList
                )
            {
    
                if (theList == null)
                    return "";
    
                int iCount = theList.Count + 1;
    
                if (totalTitle != null)
                    iCount = iCount + 1;
    
                int rate = 100 / iCount;
    
                StringBuilder theResult = new StringBuilder();
    
                theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + title + "</td>");
    
                foreach (StatisticItemOne item in theList)
                {
                    theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + item.TheName + "</td>");
                }
    
                if (totalTitle != null)
                    theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + totalTitle + "</td>");
    
    
                theResult.Append("</tr>");
    
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">统计数</td>");
    
                foreach (StatisticItemOne item in theList)
                {
                    theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + item.TheNumber.ToString() + "</td>");
                }
    
                if (totalTitle != null)
                {
    
                    decimal totalValue = 0;
    
                    foreach (StatisticItemOne item in theList)
                    {
                        totalValue += item.TheNumber;
                    }
    
                    theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\"  >" + totalValue.ToString() + "</td>");
    
                }
    
                theResult.Append("</tr>");
    
                theResult.Append("</table>");
    
                return CommonFillDivOverflowAuto(500, theResult.ToString());
            }
    
    
            /// <summary>
            /// 绘制统计图表
            /// </summary>
            /// <param name="theList"></param>
            /// <returns></returns>
            public string CommonDrawStatVerticalTable
                (
                    bool showPercentage,
                    string totalTitle,
                    string title,
                    List<StatisticItemOne> theList
                )
            {
                if (theList == null)
                    return "";
    
                StringBuilder theResult = new StringBuilder();
    
                theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + title + "</td>");
                theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">统计数</td>");
                theResult.Append("</tr>");
    
                decimal totalValue = 0;
    
                if (showPercentage || totalTitle != null)
                {
                    foreach (StatisticItemOne item in theList)
                    {
                        totalValue += item.TheNumber;
                    }
                }
    
                if (showPercentage && totalValue != 0)
                {
                    string strPercentage = "";
                    decimal percentageValue = 0;
    
                    foreach (StatisticItemOne item in theList)
                    {
                        percentageValue = (item.TheNumber * 100) / totalValue;
    
                        strPercentage = MathSlowXFunctions.GetMathRoundShowString(percentageValue, 2);
    
                        theResult.Append("<tr class=\"trItem\">");
                        theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + item.TheName + "</td>");
                        theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">"
                            + item.TheNumber.ToString() + "&nbsp;(" + strPercentage + "%)"
                            + "</td>");
                        theResult.Append("</tr>");
                    }
                }
                else
                {
                    foreach (StatisticItemOne item in theList)
                    {
                        theResult.Append("<tr class=\"trItem\">");
                        theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + item.TheName + "</td>");
                        theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + item.TheNumber.ToString() + "</td>");
                        theResult.Append("</tr>");
                    }
                }
    
                if (totalTitle != null)
                {
                    theResult.Append("<tr class=\"trItem\">");
                    theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + totalTitle + "</td>");
                    theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + totalValue.ToString() + "</td>");
                    theResult.Append("</tr>");
                }
    
                theResult.Append("</table>");
    
                return CommonFillDivOverflowAuto(500, theResult.ToString());
            }
    
            /// <summary>
            /// 绘制二维统计图表
            /// </summary>
            /// <param name="xTotalTitle"></param>
            /// <param name="yTotalTitle"></param>
            /// <param name="title"></param>
            /// <param name="statisticItemContainerValue"></param>
            /// <returns></returns>
            public string CommonDrawStatTwoTable
                (
                    string xTotalTitle,
                    string yTotalTitle,
                    string title,
                    StatisticItemContainer statisticItemContainerValue
                )
            {
                if (statisticItemContainerValue == null)
                    return "";
    
                bool isFind = false;
                bool xFillTotal = (xTotalTitle != null);
                bool yFillTotal = (yTotalTitle != null);
    
                StringBuilder theResult = new StringBuilder();
    
    
    
                theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
    
                // 绘制title //
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\">" + title + "</td>");
    
    
                Dictionary<string, string> dictionaryX = statisticItemContainerValue.dictionaryX;
                Dictionary<string, string> dictionaryY = statisticItemContainerValue.dictionaryY;
                List<StatisticItemTwo> theNumber = statisticItemContainerValue.TheNumber;
    
                foreach (string xValue in dictionaryX.Values)
                {
                    theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" >" + xValue + "</td>");
                }
    
                if (xFillTotal)
                {
                    theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" >" + xTotalTitle + "</td>");
                }
    
                theResult.Append("</tr>");
    
                decimal totalValue = 0;
    
                foreach (string yKey in dictionaryY.Keys)
                {
                    totalValue = 0;
    
                    theResult.Append("<tr class=\"trItem\">");
                    theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">" + dictionaryY[yKey] + "</td>");
    
                    foreach (string xKey in dictionaryX.Keys)
                    {
                        isFind = false;
    
                        foreach (StatisticItemTwo item in theNumber)
                        {
                            if (item.xID == xKey && item.yID == yKey)
                            {
                                if (xFillTotal)
                                    totalValue += item.TheNumber;
    
                                theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + item.TheNumber.ToString() + "</td>");
                                isFind = true;
                                break;
                            }
                        }
    
                        if (!isFind)
                        {
                            theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >0</td>");
                        }
    
                    }
    
                    if (xFillTotal)
                        theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + totalValue.ToString() + "</td>");
    
                    theResult.Append("</tr>");
                }
    
                if (yFillTotal)
                {
                    decimal allValue = 0;
    
                    theResult.Append("<tr class=\"trItem\">");
                    theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">" + yTotalTitle + "</td>");
    
                    foreach (string xKey in dictionaryX.Keys)
                    {
                        totalValue = 0;
    
                        foreach (StatisticItemTwo item in theNumber)
                        {
                            if (item.xID == xKey)
                            {
    
                                totalValue += item.TheNumber;
    
                            }
                        }
    
                        theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + totalValue.ToString() + "</td>");
    
                        allValue += totalValue;
                    }
    
                    if (xFillTotal)
                        theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + allValue.ToString() + "</td>");
    
                    theResult.Append("</tr>");
                }
    
                theResult.Append("</table>");
    
                return CommonFillDivOverflowAuto(500, theResult.ToString());
            }
    
            /// <summary>
            /// 绘制统计图表
            /// </summary>
            /// <param name="theList"></param>
            /// <returns></returns>
            public string CommonDrawStatHorizontalTable
                (
                    bool showPercentage,
                    string totalTitle,
                    string title,
                    List<StatisticItemOne> theList
                )
            {
    
                if (theList == null)
                    return "";
    
                int iCount = theList.Count + 1;
    
                if (totalTitle != null)
                    iCount = iCount + 1;
    
                int rate = 100 / iCount;
    
                StringBuilder theResult = new StringBuilder();
    
                theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + title + "</td>");
    
                decimal totalValue = 0;
    
                if (showPercentage || totalTitle != null)
                {
                    foreach (StatisticItemOne item in theList)
                    {
                        totalValue += item.TheNumber;
                    }
                }
    
                foreach (StatisticItemOne item in theList)
                {
                    theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + item.TheName + "</td>");
                }
    
                if (totalTitle != null)
                    theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + totalTitle + "</td>");
    
    
                theResult.Append("</tr>");
    
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">统计数</td>");
    
                if (showPercentage && totalValue != 0)
                {
                    string strPercentage = "";
                    decimal percentageValue = 0;
    
                    foreach (StatisticItemOne item in theList)
                    {
                        percentageValue = (item.TheNumber * 100) / totalValue;
    
                        strPercentage = MathSlowXFunctions.GetMathRoundShowString(percentageValue, 2);
    
                        theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >"
                            + item.TheNumber.ToString() + "&nbsp;(" + strPercentage + "%)"
                            + "</td>");
                    }
                }
                else
                {
                    foreach (StatisticItemOne item in theList)
                    {
                        theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + item.TheNumber.ToString() + "</td>");
                    }
                }
    
                if (totalTitle != null)
                {
                    theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\"  >" + totalValue.ToString() + "</td>");
    
                }
    
                theResult.Append("</tr>");
    
                theResult.Append("</table>");
    
                return CommonFillDivOverflowAuto(500, theResult.ToString());
            }
    
            /// <summary>
            /// 获得DIV的HTML
            /// </summary>
            /// <returns></returns>
            public string CommonGetDefaultChartDiv()
            {
                return "<div id=\"container\" style=\"width: 100%; height: 500px;\"></div>";
            }
    
    
            /// <summary>
            /// 绘制统计图表
            /// </summary>
            /// <param name="theList"></param>
            /// <returns></returns>
            public string CommonDrawStatChartTable
                (
                    string totalTitle,
                    string title,
                    int titleWidth,
                    int numberWidth,
                    int chartDivWidth,
                    string chartDiv,
                    List<StatisticItemOne> theList
                )
            {
                StringBuilder theResult = new StringBuilder();
    
                string titleWidthValue = "";
                string numberWidthValue = "";
                string chartDivWidthValue = "";
    
                if (titleWidth > 0)
                    titleWidthValue = " width=\"" + titleWidth.ToString() + "px\"";
                else if (titleWidth < 0)
                    titleWidthValue = " width=\"" + (-titleWidth).ToString() + "%\"";
    
                if (numberWidth > 0)
                    numberWidthValue = " width=\"" + numberWidth.ToString() + "px\"";
                else if (numberWidth < 0)
                    numberWidthValue = " width=\"" + (-numberWidth).ToString() + "%\"";
    
    
                if (chartDivWidth > 0)
                    chartDivWidthValue = " width=\"" + chartDivWidth.ToString() + "px\"";
                else if (chartDivWidth < 0)
                    chartDivWidthValue = " width=\"" + (-chartDivWidth).ToString() + "%\"";
    
                int rowspan = theList.Count + 1;
    
                if (totalTitle != null)
                {
                    rowspan += 1;
                }
    
    
                theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
                theResult.Append("<tr class=\"trItem\">");
                theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\"" + titleWidthValue + ">" + title + "</td>");
                theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\"" + numberWidthValue + ">统计数</td>");
                theResult.Append("<td class=\"tdRightItem\" align=\"center\" rowspan=\"" + rowspan.ToString() + "\"" + chartDivWidthValue + ">" + chartDiv + "</td>");
                theResult.Append("</tr>");
    
                foreach (StatisticItemOne item in theList)
                {
                    theResult.Append("<tr class=\"trItem\">");
                    theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\">" + item.TheName + "</td>");
                    theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\">" + item.TheNumber.ToString() + "</td>");
                    theResult.Append("</tr>");
                }
    
                if (totalTitle != null)
                {
                    decimal totalValue = 0;
    
                    foreach (StatisticItemOne item in theList)
                    {
                        totalValue += item.TheNumber;
                    }
    
                    theResult.Append("<tr class=\"trItem\">");
                    theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\"" + titleWidthValue + ">" + totalTitle + "</td>");
                    theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\"" + numberWidthValue + ">" + totalValue.ToString() + "</td>");
                    theResult.Append("</tr>");
                }
    
                theResult.Append("</table>");
    
                return CommonFillDivOverflowAuto(500, theResult.ToString());
            }
    

标签:构建统计图标 - StatisticItemContainer 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)