投递文章投递文章 投稿指南投稿指南 RSS订阅RSS订阅

sqlserver2005的KPI展示控件开发详解

来源:cnBLOGs 发布时间:2008-04-19 收藏 投稿 字体:【

以下为代码的内容:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace KPIDisplayer
{
    internal class DataGridViewTrendColumn : DataGridViewImageColumn
    {
        public DataGridViewTrendColumn()
        {
            CellTemplate = new DataGridViewTrendCell();
        }
    }
}

step3.取得analysis services 中的定义的KPI的信息和KPI的值。

以下为代码的内容:

/// <summary>
        /// 展示结果
        /// </summary>
        public void Display()
        {

            AdomdConnection myKPIConnection = new AdomdConnection(_connectString);

            _kpiDataSet = new KPIDataSet();

            KPIDataSet.KPIModelRow kpiRow;

            try
            {
                myKPIConnection.Open();
                CubeDef myCubeDef = myKPIConnection.Cubes[this._cubeName];
                AdomdCommand myKPICommand;

                foreach (Kpi k in myCubeDef.Kpis)
                {

                    myKPICommand = new AdomdCommand();

                    myKPICommand.Connection = myKPIConnection;
                  
                    StringBuilder sb = new StringBuilder();
                    sb.Append("SELECT { ");
                    sb.Append("KPIValue(\"" + k.Name + "\"), ");
                    sb.Append("KPIGoal(\"" + k.Name + "\"), ");
                    sb.Append("KPIStatus(\"" + k.Name + "\"), ");
                    sb.Append("KPITrend(\"" + k.Name + "\")");
                    sb.Append("} ON COLUMNS FROM ["+this._cubeName+"]");

                    myKPICommand.CommandText = sb.ToString();

                    CellSet cellset = myKPICommand.ExecuteCellSet();

                    string kpiName = k.Name;
                    string kpiValue = cellset.Cells[0].FormattedValue;
                    string kpiGoal = cellset.Cells[1].FormattedValue;
                    string kpiStatus = cellset.Cells[2].FormattedValue;
                    string kpiTrend = cellset.Cells[3].FormattedValue;
                    string kpiStatusGraph = k.StatusGraphic;
                    string kpiTrendGraph = k.TrendGraphic;

                    kpiRow = this._kpiDataSet.KPIModel.NewKPIModelRow();

                    kpiRow.Name = kpiName;
                    kpiRow.Value = Convert.ToDecimal(kpiValue);
                    kpiRow.Goal = Convert.ToDecimal(kpiGoal);
                    kpiRow.Status = kpiStatusGraph + "," + kpiStatus;
                    kpiRow.Trend = kpiTrendGraph + "," + kpiTrend;

                    this._kpiDataSet.KPIModel.AddKPIModelRow(kpiRow);
                }
            }
            catch (AdomdErrorResponseException myException)
            {
                MessageBox.Show(this, "连接Analysis Service服务器出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "未知错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
            finally
            {
                myKPIConnection.Close();
            }

step4.绑定到DataGridView。
 this.kpiDataGridView1.DataSource = this._kpiDataSet.KPIModel;

step5.搞定,运行。



完整代码下载地址:
KPIDisplayer.rar

最新5条评论 查看所有评论
评论内容:请自觉遵守互联网相关政策法规。
用户名: 密码: 匿名 注册
热门文章
随机推荐
About iTtang - 联系方法  - 专题列表 - 友情链接  -  高级搜索   -  帮助中心  -