Ioc-StructureMap

1. Global.asax

  protected void Application_Start()
        {
            BootStrapper.ConfigureStructureMap(); 
        }


2.BootStrapper

    public class BootStrapper
    {
        public static void ConfigureStructureMap()
        {
            // Initialize the registry
            ObjectFactory.Initialize(x =>
            {
                x.AddRegistry<ModelRegistry>();

            });
        }

        public class ModelRegistry : Registry
        {
            public ModelRegistry()
            {
                ForRequestedType<IGetTotalElectricGrid>().TheDefault.Is.OfConcreteType<GetTotalElectricGridDPI>();
                ForRequestedType<IGetAirSystemElectric>().TheDefault.Is.OfConcreteType<GetAirSystemElectricDPI>();
                ForRequestedType<IGetItemsElectric>().TheDefault.Is.OfConcreteType<GetItemsElectricDPI>();
                ForRequestedType<IGetDataByDay>().TheDefault.Is.OfConcreteType<GetDataByDayDIP>();
                ForRequestedType<IGetDataByWeek>().TheDefault.Is.OfConcreteType<GetDataByWeekDPI>();
                ForRequestedType<IGetDataByMonth>().TheDefault.Is.OfConcreteType<GetDataByMonthDPI>();
                ForRequestedType<IGetDataByYear>().TheDefault.Is.OfConcreteType<GetDataByYearDPI>();
            }
        }
    }


3.HomeController

 [HttpPost]
        public string GetChartIt(FormCollection fc)
        {
            HomePageClientControl homePageClientControl = ObjectFactory.GetInstance<HomePageClientControl>();
            return homePageClientControl.GetData(fc["data"].ToString());
            //return HomePageClientControl.Instance().GetData(fc["data"].ToString());
        }


4.IGetDataByDay

   public interface IGetDataByDay
    {
        StringBuilder GetDataByDay(string data);
    }


5.GetItemsElectricDPI

    public class GetItemsElectricDPI : IGetItemsElectric
    {
        public StringBuilder GetItemsElectric(string time)
        {
            string[] str = ClientControl.GetChartDataType.GetTimeByType.GetTimeByTypeTime(time);
            DataTable dt = null;
            if (time == "日")
            {
                dt = HomePageDataControl.Instance().GetTypeElectric(str[0], str[1]);
            }
            else//周,月,年
            {
                dt = HomePageDataControl.Instance().GetTypeElectricByDay(str[0], str[1]);
            }
            StringBuilder json = new StringBuilder();
            json.Append("{ 'chart': { 'caption': '分项用电比例', 'numberSuffix': '(kwh)', 'baseFont':'微软雅黑','baseFontSize':'12'}, 'data': [ " +
                        "{ 'label': '照明插座', 'value': '" + dt.Rows[0][0].ToString() + "' }, " +
                        "{ 'label': '空调', 'value': '" + dt.Rows[1][0].ToString() + "' }, " +
                        "{ 'label': '动力', 'value': '" + dt.Rows[2][0].ToString() + "' }, " +
                        "{ 'label': '特殊', 'value': '" + dt.Rows[3][0].ToString() + "' }]}");
            json = json.Replace("'", "\"");
            return json;
        }
    }


6. HomePageClientControl

 

     private readonly IGetTotalElectricGrid _getTotalElectricGrid;
        private readonly IGetAirSystemElectric _getAirSystemElectric;
        private readonly IGetItemsElectric _getItemsElectric;
        private readonly IGetDataByDay _getDataByDay;
        private readonly IGetDataByWeek _getDataByWeek;
        private readonly IGetDataByMonth _getDataByMonth;
        private readonly IGetDataByYear _getDataByYear;

        public HomePageClientControl(IGetTotalElectricGrid getTotalElectricGrid, 
                                     IGetAirSystemElectric getAirSystemElectric,
                                     IGetItemsElectric getItemsElectric,
                                     IGetDataByDay getDataByDay,
                                     IGetDataByWeek getDataByWeek,
                                     IGetDataByMonth getDataByMonth,
                                     IGetDataByYear getDataByYear)
        {
            this._getTotalElectricGrid = getTotalElectricGrid;
            this._getAirSystemElectric = getAirSystemElectric;
            this._getItemsElectric = getItemsElectric;
            this._getDataByDay = getDataByDay;
            this._getDataByWeek = getDataByWeek;
            this._getDataByMonth = getDataByMonth;
            this._getDataByYear = getDataByYear;
        }

        public string GetData(string data)
        {
            StringBuilder json = new StringBuilder();
            //json.Append(GetChartData.GetTotalElectricGrid(data));

            json.Append(this._getTotalElectricGrid.GetTotalElectricGrid(data));json.Append("&&");

            //json.Append(GetChartData.GetAirSystemElectric(data));

            json.Append(this._getAirSystemElectric.GetAirSystemElectric(data));json.Append("&&");

            //json.Append(GetChartData.GetItemsElectric(data));

            json.Append(this._getItemsElectric.GetItemsElectric(data));json.Append("&&");

            //json.Append(GetChartData.GetUnitAreaElectric(data));
            //json.Append("&&");
            //json.Append(GetChartData.GetPerAverage(data));
            //json.Append("&&");
            //json.Append(GetChartData.GetTotalEnergy(data));
            //json.Append("&&");
            //json.Append(GetChartData.GetTotalElectric(data, ""));
            //json.Append("&&");
            //json.Append(GetChartData.GetTotalWater(data, ""));
            //json.Append("&&");
            //json.Append(GetChartData.GetTotalGas(data));
            if (data.Equals("日")) { json.Append(this._getDataByDay.GetDataByDay(data)); }
            if (data.Equals("周")) { json.Append(this._getDataByWeek.GetDataByWeek(data)); }
            if (data.Equals("月")) { json.Append(this._getDataByMonth.GetDataByMonth(data)); }
            if (data.Equals("年")) { json.Append(this._getDataByYear.GetDataByYear(data)); }

            return json.ToString();
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值