Esempio n. 1
0
        /// <summary>
        /// 能耗集合
        /// </summary>
        /// <param name="model">查询的对象封装</param>
        /// <returns></returns>
        public static BaseResult GetBaseEneryDataList(BaseQueryModel model)
        {
            BaseResult Res = new BaseResult();
            Res.BaseLayerObjectResults = new Dictionary<string, BaseData>();
            //Res.DeviceResults = new Dictionary<Model.Device, BaseData>();
            bool IsDevice = model.IsDevice == 0 ? false : true;
            var datas = new DataTable();
            if (model != null && model.ObjectList.Count > 0)
            {
                foreach (var objects in model.ObjectList)
                {
                    decimal tempCount = 0;
                    BaseDataModel bmodel = new BaseDataModel();
                    bmodel.Starttime = model.Starttime;
                    if (model.Unit == ChartUnit.unit_hour)
                    {
                        bmodel.Endtime = (model.Starttime == model.Endtime)
                                             ? model.Starttime.AddDays(1).AddHours(-1)
                                             : model.Endtime;
                    }
                    else
                    {
                        bmodel.Endtime = model.Endtime;
                    }
                    bmodel.IsDevice = model.IsDevice;
                    bmodel.ItemCode = model.ItemCode;
                    bmodel.ObjectId = objects;
                    bmodel.Unit = model.Unit;
                    datas = GetBaseData(bmodel);
                    BaseData bsDatas = new BaseData();
                    bsDatas.itemCode = new Model.Itemcode();
                    var ItemCodeList = new DAL.Itemcode().GetItemcodeList(string.Format(" and ItemCodeNumber='{0}'", model.ItemCode), string.Format(" order by ItemcodeID"));
                    bsDatas.itemCode = ItemCodeList.Count > 0 ? ItemCodeList[0] : null;
                    Model.BaseLayerObject ObjectInfo = new Model.BaseLayerObject();

                    Model.Device DeviceObjectInfo = new Model.Device();
                    if (!IsDevice)
                    {
                        var infoList = new DAL.BaseLayerObject().GetBaseLayerObjectList(string.Format(" and LayerObjectID={0}", objects), string.Format(" order by LayerObjectID"));
                        ObjectInfo = infoList.Count > 0 ? infoList[0] : null;
                        bsDatas.Datas = new List<DataItems>();
                        foreach (DataRow item in datas.Rows)
                        {

                            tempCount += decimal.Parse(item["CountValue"].ToString());
                            bsDatas.Datas.Add(new DataItems()
                            {
                                DatePick = item["Starttime"].ToString(),
                                DataValue = decimal.Parse(item["CountValue"].ToString()),

                                CoalDataValue = decimal.Parse(item["CountValue"].ToString()) * (decimal)bsDatas.itemCode.ItemCoal,
                                Co2DataValue = decimal.Parse(item["CountValue"].ToString()) * (decimal)bsDatas.itemCode.ItemCO2,
                                MoneyDataValue = decimal.Parse(item["CountValue"].ToString()) * (decimal)bsDatas.itemCode.ItemMoney,
                                DataValueAndDept = item["CountValue"].ToString() + bsDatas.itemCode.Unit
                            });
                        }
                        bsDatas.baseLayerObject = ObjectInfo;
                    }
                    else
                    {
                        var infoList = new DAL.Device().GetDeviceList(string.Format(" and deviceid={0}", objects), string.Format(" order by DeviceID"));
                        DeviceObjectInfo = infoList.Count > 0 ? infoList[0] : null;
                        bsDatas.Datas = new List<DataItems>();
                        foreach (DataRow item in datas.Rows)
                        {
                            tempCount += decimal.Parse(item["CountValue"].ToString());
                            bsDatas.Datas.Add(new DataItems()
                            {
                                DatePick = item["Starttime"].ToString(),
                                DataValue = decimal.Parse(item["CountValue"].ToString()),
                                CoalDataValue = decimal.Parse(item["CountValue"].ToString()) *(decimal)bsDatas.itemCode.ItemCoal,
                                Co2DataValue = decimal.Parse(item["CountValue"].ToString()) * (decimal)bsDatas.itemCode.ItemCO2,
                                MoneyDataValue = decimal.Parse(item["CountValue"].ToString()) * (decimal)bsDatas.itemCode.ItemMoney,
                                DataValueAndDept = item["CountValue"].ToString() + bsDatas.itemCode.Unit
                            });
                        }
                        bsDatas.device = DeviceObjectInfo;
                    }
                    bsDatas.Total = tempCount;
                    bsDatas.ConvertDataValueList = new System.Collections.Hashtable();
                    bsDatas.ConvertDataValueList.Add("ITEMCOAL", decimal.Round(tempCount * (decimal)bsDatas.itemCode.ItemCoal, 4).ToString());
                    bsDatas.ConvertDataValueList.Add("ITEMCO2", decimal.Round(tempCount * (decimal)bsDatas.itemCode.ItemCO2, 4).ToString());
                    bsDatas.ConvertDataValueList.Add("ITEMMONEY", decimal.Round(tempCount * (decimal)bsDatas.itemCode.ItemMoney, 4).ToString());
                    Res.BaseLayerObjectResults.Add(
                        !IsDevice ? ObjectInfo.LayerObjectID.ToString() : DeviceObjectInfo.DeviceID.ToString(), bsDatas);
                }
                return Res;
            }
            return null;
        }
Esempio n. 2
0
        public QueryEneryTotal GetDeviceQueryEneryTotal(NTS.WEB.DataContact.BasicQuery query)
        {
            BaseResult baseResult = new BaseResult();
            baseResult.BaseLayerObjectResults = new Dictionary<string, BaseData>();
            var Object = new BLL.BaseLayerObject().GetDeviceObjectList(string.Format(" and deviceid={0}", query.ObjectNum), " order by deviceid")[0];
            baseResult.BaseLayerObjectResults = new Dictionary<string, BaseData>();
            baseResult.BaseLayerObjectResults.Add(Object.DeviceID.ToString(), new BaseData());
            baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList = new System.Collections.Hashtable();
            baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].Datas = new List<DataItems>();
            baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList.Add("ITEMCOAL", 0);
            baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList.Add("ITEMCO2", 0);

            if (query.ItemCode != "00000")
            {
                query.ItemCode = Object.ItemCodeID;
                var resList = GetQueryDeviceSingleItemCodeEneryTotal(query);
                return resList != null ? new QueryEneryTotal { TotalEnergy = resList.BaseLayerObjectResults[Object.DeviceID.ToString()].Total } : null;
            }
            else
            {
                query.ItemCode = Object.ItemCodeID;
                query.ItemCode = Object.ItemCodeID;
                var resList = GetQueryDeviceSingleItemCodeEneryTotal(query);
                return resList != null ? new QueryEneryTotal { TotalEnergy = decimal.Parse(resList.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList["ITEMCOAL"].ToString()) } : null;
                //var ItemList = new BLL.Itemcode().GetItemcodeList(" and ParentID=0", " order by ItemcodeID");
                //List<string> ItemCodeStr = (from item in ItemList select item.ItemCodeNumber).ToList<string>();

                //Dictionary<string, decimal> DataValue = new Dictionary<string, decimal>();
                //Dictionary<string, decimal> CoalDataValue = new Dictionary<string, decimal>();
                //Dictionary<string, decimal> Co2DataValue = new Dictionary<string, decimal>();
                //for (var item = 0; item < ItemCodeStr.Count; item++)
                //{

                //    query.ItemCode = ItemCodeStr[item];
                //    var ResList = GetQueryDeviceSingleItemCodeEneryTotal(query);
                //    if (ResList != null)
                //    {

                //        baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].Total += ResList.BaseLayerObjectResults[Object.DeviceID.ToString()].Total;
                //        baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList["ITEMCOAL"] = decimal.Parse(baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList["ITEMCOAL"].ToString()) + decimal.Parse(ResList.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList["ITEMCOAL"].ToString());
                //        baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList["ITEMCO2"] = decimal.Parse(baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList["ITEMCO2"].ToString()) + decimal.Parse(ResList.BaseLayerObjectResults[Object.DeviceID.ToString()].ConvertDataValueList["ITEMCO2"].ToString());
                //        foreach (var li in ResList.BaseLayerObjectResults[Object.DeviceID.ToString()].Datas)
                //        {
                //            #region 累加赋值
                //            if (DataValue.ContainsKey(li.DatePick))
                //            {
                //                DataValue[li.DatePick] += li.DataValue;
                //            }
                //            else
                //            {
                //                DataValue.Add(li.DatePick, li.DataValue);
                //            }
                //            if (CoalDataValue.ContainsKey(li.DatePick))
                //            {
                //                CoalDataValue[li.DatePick] += li.CoalDataValue;
                //            }
                //            else
                //            {
                //                CoalDataValue.Add(li.DatePick, li.CoalDataValue);
                //            }
                //            if (Co2DataValue.ContainsKey(li.DatePick))
                //            {
                //                Co2DataValue[li.DatePick] += li.Co2DataValue;
                //            }
                //            else
                //            {
                //                Co2DataValue.Add(li.DatePick, li.Co2DataValue);
                //            }
                //            #endregion

                //            if (item == ItemCodeStr.Count - 1)
                //            {
                //                li.DataValue = DataValue[li.DatePick];
                //                li.CoalDataValue = CoalDataValue[li.DatePick];
                //                li.Co2DataValue = Co2DataValue[li.DatePick];
                //                baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].Datas.Add(li);
                //            }
                //        }

                //    }
                //}
                // if (baseResult != null) { return new QueryEneryTotal { TotalEnergy = baseResult.BaseLayerObjectResults[Object.DeviceID.ToString()].Total }; }
                //return null;
            }
        }
Esempio n. 3
0
        public MainInfo GetIndexCompareEneryNew(DateTime startTime, DateTime endTime)
        {
            MainInfo mainInfo = new MainInfo();
            mainInfo.IsOnlyElec = false;
            mainInfo.ItemValues = new List<EneryStatistic>();
            mainInfo.PeriodValues = new List<EnerySum>();
            var ObjectList = new BLL.BaseLayerObject().GetBaseFuncLayerObjectList(string.Format(" and LayerObjectParentID={0}", 0), " order by LayerObjectID");
            var ItemList = new BLL.Itemcode().GetItemcodeList(" and ParentID=0", " order by ItemcodeID");
            //var ItemList = new BLL.Itemcode().GetItemcodeList("", " order by ItemcodeID");

            EneryStatistic eneryStatistic4Elec = new EneryStatistic();
            if (ItemList.Count == 1)
            {//只有电
                mainInfo.IsOnlyElec = true;//只有电
                eneryStatistic4Elec.CName = ItemList[0].ItemCodeName;
                eneryStatistic4Elec.ItemCode = ItemList[0].ItemCodeNumber;
                eneryStatistic4Elec.Unit = ItemList[0].Unit;
                ItemList = new BLL.Itemcode().GetItemcodeList(string.Format(" and ParentID={0}", ItemList[0].ItemcodeID), " order by ItemcodeID");
            }
            BaseQueryModel model = new BaseQueryModel();
            model.IsDevice = 0;
            model.ObjectList = (from p in ObjectList select p.LayerObjectID).ToList<int>();

            foreach (var item in ItemList)
            {
                EneryStatistic eneryStatistic = new EneryStatistic();
                eneryStatistic.CName = item.ItemCodeName;
                eneryStatistic.ItemCode = item.ItemCodeNumber;
                eneryStatistic.Unit = item.Unit;

                model.ItemCode = item.ItemCodeNumber;
                decimal tempItemCoalEneryValue = 0;
                decimal tempLastMonthItemCoalEneryValue = 0;
                BaseResult ResList = new BaseResult();
                if ((endTime - startTime).Days > 0)
                {
                    model.Unit = ChartUnit.unit_day;
                    model.Starttime = startTime;
                    model.Endtime = DateTime.Parse(endTime.AddDays(-1).ToString("yyyy-MM-dd 00:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EneryValue += r.Value.Total;
                        eneryStatistic.EnergyValue2Coal += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                        tempItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }
                if (endTime.Hour > 0)
                {
                    model.Unit = ChartUnit.unit_hour;
                    model.Starttime = DateTime.Parse(endTime.ToString("yyyy-MM-dd 00:00:00"));
                    model.Endtime = DateTime.Parse(endTime.ToString("yyyy-MM-dd HH:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EneryValue += r.Value.Total;
                        eneryStatistic.EnergyValue2Coal += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                        tempItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }

                eneryStatistic.EneryValue = decimal.Round(eneryStatistic.EneryValue, 2);
                eneryStatistic.EnergyValue2Coal = decimal.Round(eneryStatistic.EnergyValue2Coal, 2);
                tempItemCoalEneryValue = decimal.Round(tempItemCoalEneryValue, 2);

                model.Starttime = startTime.AddMonths(-1);
                model.Endtime = endTime.AddMonths(-1);

                if ((endTime - startTime).Days > 0)
                {
                    model.Unit = ChartUnit.unit_day;
                    model.Endtime = DateTime.Parse(model.Endtime.AddDays(-1).ToString("yyyy-MM-dd 00:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EnergyLastMonth += decimal.Round(r.Value.Total, 2);
                        tempLastMonthItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }
                if (endTime.Hour > 0)
                {
                    model.Unit = ChartUnit.unit_hour;
                    model.Starttime = DateTime.Parse(endTime.AddMonths(-1).ToString("yyyy-MM-dd 00:00:00"));
                    model.Endtime = DateTime.Parse(endTime.AddMonths(-1).ToString("yyyy-MM-dd HH:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EnergyLastMonth += decimal.Round(r.Value.Total, 2);
                        tempLastMonthItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }

                eneryStatistic.EnergyLastMonth = decimal.Round(eneryStatistic.EnergyLastMonth, 2);
                tempLastMonthItemCoalEneryValue = decimal.Round(tempLastMonthItemCoalEneryValue, 2);
                if (eneryStatistic.EnergyLastMonth > 0)
                {
                    eneryStatistic.MonthCompare = decimal.Round(100 * (eneryStatistic.EneryValue - eneryStatistic.EnergyLastMonth) / eneryStatistic.EnergyLastMonth, 2)
                                 .ToString(CultureInfo.InvariantCulture) + "%";
                }

                mainInfo.Total += Math.Round(tempItemCoalEneryValue, 2);
                mainInfo.TotalLastMon += Math.Round(tempLastMonthItemCoalEneryValue, 2);

                if (mainInfo.IsOnlyElec)
                {
                    eneryStatistic4Elec.EneryValue += eneryStatistic.EneryValue;
                    eneryStatistic4Elec.EnergyValue2Coal += eneryStatistic.EneryValue;
                    eneryStatistic4Elec.EnergyLastMonth += eneryStatistic.EnergyLastMonth;
                }
                mainInfo.ItemValues.Add(eneryStatistic);

                if (item.ItemCodeNumber == "01000")
                {

                    GeneratePeriodValues(model, mainInfo);
                }

            }

            if (mainInfo.TotalLastMon > 0)
            {
                mainInfo.TotalCompare = decimal.Round(100 * (mainInfo.Total - mainInfo.TotalLastMon) / mainInfo.TotalLastMon, 2)
                             .ToString(CultureInfo.InvariantCulture) + "%";
            }
            if (mainInfo.IsOnlyElec)
            {
                eneryStatistic4Elec.MonthCompare = mainInfo.TotalCompare;
                mainInfo.ItemValues.Insert(0, eneryStatistic4Elec);
                model.ItemCode = "01000";
                GeneratePeriodValues(model, mainInfo);
            }
            return mainInfo;
        }
Esempio n. 4
0
        public QueryEneryTotal GetQueryEneryTotal(NTS.WEB.DataContact.BasicQuery query)
        {
            BaseResult baseResult = new BaseResult();
            baseResult.BaseLayerObjectResults = new Dictionary<string, BaseData>();
            var Object = new BLL.BaseLayerObject().GetBaseLayerObjectList(string.Format(" and LayerObjectID={0}", query.ObjectNum), " order by LayerObjectID")[0];
            baseResult.BaseLayerObjectResults = new Dictionary<string, BaseData>();
            baseResult.BaseLayerObjectResults.Add(Object.LayerObjectID.ToString(), new BaseData());
            baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList = new System.Collections.Hashtable();
            baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].Datas = new List<DataItems>();
            baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList.Add("ITEMCOAL", 0);
            baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList.Add("ITEMCO2", 0);
            if (query.ItemCode != "00000")
            {
                var ResList = GetQuerySingleItemCodeEneryTotal(query);
                if (ResList != null) { return new QueryEneryTotal { TotalEnergy = decimal.Parse(ResList.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCOAL"].ToString()) }; }//TotalEnergy = ResList.BaseLayerObjectResults[Object.LayerObjectID.ToString()].Total
                return null;
            }
            else
            {
                var ItemList = new BLL.Itemcode().GetItemcodeList(" and ParentID=0", " order by ItemcodeID");
                List<string> ItemCodeStr = (from item in ItemList select item.ItemCodeNumber).ToList<string>();

                Dictionary<string, decimal> DataValue = new Dictionary<string, decimal>();
                Dictionary<string, decimal> CoalDataValue = new Dictionary<string, decimal>();
                Dictionary<string, decimal> Co2DataValue = new Dictionary<string, decimal>();
                for (var item = 0; item < ItemCodeStr.Count; item++)
                {

                    query.ItemCode = ItemCodeStr[item];
                    var ResList = GetQuerySingleItemCodeEneryTotal(query);
                    if (ResList != null)
                    {

                        baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].Total += ResList.BaseLayerObjectResults[Object.LayerObjectID.ToString()].Total;
                        baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCOAL"] = decimal.Parse(baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCOAL"].ToString()) + decimal.Parse(ResList.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCOAL"].ToString());
                        baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCO2"] = decimal.Parse(baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCO2"].ToString()) + decimal.Parse(ResList.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCO2"].ToString());
                        foreach (var li in ResList.BaseLayerObjectResults[Object.LayerObjectID.ToString()].Datas)
                        {
                            #region 累加赋值
                            if (DataValue.ContainsKey(li.DatePick))
                            {
                                DataValue[li.DatePick] += li.DataValue;
                            }
                            else
                            {
                                DataValue.Add(li.DatePick, li.DataValue);
                            }
                            if (CoalDataValue.ContainsKey(li.DatePick))
                            {
                                CoalDataValue[li.DatePick] += li.CoalDataValue;
                            }
                            else
                            {
                                CoalDataValue.Add(li.DatePick, li.CoalDataValue);
                            }
                            if (Co2DataValue.ContainsKey(li.DatePick))
                            {
                                Co2DataValue[li.DatePick] += li.Co2DataValue;
                            }
                            else
                            {
                                Co2DataValue.Add(li.DatePick, li.Co2DataValue);
                            }
                            #endregion

                            if (item == ItemCodeStr.Count - 1)
                            {
                                li.DataValue = DataValue[li.DatePick];
                                li.CoalDataValue = CoalDataValue[li.DatePick];
                                li.Co2DataValue = Co2DataValue[li.DatePick];
                                baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].Datas.Add(li);
                            }
                        }

                    }
                }
                if (baseResult != null) { return new QueryEneryTotal { TotalEnergy = decimal.Parse(baseResult.BaseLayerObjectResults[Object.LayerObjectID.ToString()].ConvertDataValueList["ITEMCOAL"].ToString()) }; }
                return null;
            }
        }