/// <summary>
        /// 获取图表列表
        /// </summary>
        /// <returns>成功返回图表列表,失败返回Null.</returns>
        public ReturnItem <List <RetHomeConfiguration> > GetChartList(HomeConfigurationModel parameter)
        {
            ReturnItem <List <RetHomeConfiguration> > r = new ReturnItem <List <RetHomeConfiguration> >();
            List <RetHomeConfiguration> listinfo        = new List <RetHomeConfiguration>();

            using (UserEntities user = new UserEntities())
            {
                try
                {
                    var deviceid      = Convert.ToInt32(parameter.DeviceID);
                    var dashboardtype = Convert.ToInt32(parameter.DashBoardType);
                    var getchartlist  = new List <U_HomeConfiguration>();
                    if (dashboardtype == 0)
                    {
                        var OrgID = Convert.ToInt32(parameter.OrgID);
                        getchartlist = user.U_HomeConfiguration.Where(s => s.DashBoardType == dashboardtype && s.OrgID == OrgID).ToList();
                    }
                    else if (dashboardtype == 1)
                    {
                        getchartlist = user.U_HomeConfiguration.Where(s => s.DeviceID == deviceid && s.DashBoardType == dashboardtype).ToList();
                    }
                    if (getchartlist.Count == 0 || getchartlist == null)
                    {
                        r.Data = null;
                        r.Code = -1;
                        r.Msg  = "未找到设备图表";
                        return(r);
                    }
                    if (getchartlist != null && getchartlist.Count != 0)
                    {
                        List <U_HomeConfiguration> list = getchartlist.ToList <U_HomeConfiguration>();
                        r.Count = getchartlist.Count();
                        r.Msg   = "设备信息获取成功";
                        r.Code  = 0;
                        foreach (var item in list)
                        {
                            var chartlistinfo = new RetHomeConfiguration();
                            chartlistinfo.ID            = item.ID;
                            chartlistinfo.DashBoardType = item.DashBoardType.ToString();
                            chartlistinfo.DeviceID      = item.DeviceID.ToString();
                            chartlistinfo.DeviceItemID  = item.DeviceItemID.ToString();
                            chartlistinfo.ChartName     = item.ChartName.ToString();
                            chartlistinfo.ChartType     = item.ChartType.ToString();
                            // ChartConfig赋值
                            chartlistinfo.ChartConfig = item.ChartConfig;
                            DashBoardChartConfigModel ChartConfig = new DashBoardChartConfigModel();
                            if (item.ChartConfig != "" && item.ChartConfig != null)
                            {
                                ChartConfig = JsonConvert.DeserializeObject <DashBoardChartConfigModel>(item.ChartConfig);
                            }
                            chartlistinfo.DatabaseType   = ChartConfig.DatabaseType;
                            chartlistinfo.DataType       = ChartConfig.DataType;
                            chartlistinfo.RecentInterval = ChartConfig.RecentInterval;
                            chartlistinfo.RecentUnit     = ChartConfig.RecentUnit;
                            if (ChartConfig.StartTime != "")
                            {
                                chartlistinfo.StartTime = Convert.ToDateTime(ChartConfig.StartTime);
                            }
                            if (ChartConfig.EndTime != "")
                            {
                                chartlistinfo.EndTime = Convert.ToDateTime(ChartConfig.EndTime);
                            }
                            chartlistinfo.StatisticalInterval = ChartConfig.StatisticalInterval;
                            chartlistinfo.IntervalUnit        = ChartConfig.IntervalUnit;
                            chartlistinfo.MinValue            = ChartConfig.MinValue;
                            chartlistinfo.MaxValue            = ChartConfig.MaxValue;
                            chartlistinfo.ValueType           = ChartConfig.ValueType;
                            chartlistinfo.TextColor           = ChartConfig.TextColor;
                            chartlistinfo.BackgroundColor     = ChartConfig.BackgroundColor;
                            chartlistinfo.HomeDeviceInfoList  = ChartConfig.HomeDeviceInfoList;
                            //首页
                            if (item.DashBoardType == 0)
                            {
                                List <BaseModel> Property = new List <BaseModel>();
                                if (ChartConfig.SelectionType == "1") //设备
                                {
                                    foreach (var info in ChartConfig.HomeDeviceInfoList)
                                    {
                                        BaseModel     model = new BaseModel();
                                        List <string> data  = new List <string>();
                                        data.Add("1");
                                        data.Add(info.DeviceID);
                                        data.Add(info.DeviceItemID);
                                        model.data = data;
                                        Property.Add(model);
                                    }
                                }
                                else if (ChartConfig.SelectionType == "2")//总览
                                {
                                    BaseModel     model = new BaseModel();
                                    List <string> data  = new List <string>();
                                    data.Add("2");
                                    data.Add(ChartConfig.ValueType);
                                    model.data = data;
                                    Property.Add(model);
                                }
                                else if (ChartConfig.SelectionType == "3")//表格
                                {
                                    BaseModel     model = new BaseModel();
                                    List <string> data  = new List <string>();
                                    data.Add("3");
                                    data.Add(ChartConfig.ValueType);
                                    model.data = data;
                                    Property.Add(model);
                                }
                                chartlistinfo.Property = Property;
                            }
                            //设备
                            else if (item.DashBoardType == 1)
                            {
                                List <DeviceBaseModel> DeviceItemList = new List <DeviceBaseModel>();
                                foreach (var info in ChartConfig.HomeDeviceInfoList)
                                {
                                    DeviceBaseModel model = new DeviceBaseModel();
                                    model.DeviceItemID = info.DeviceItemID;
                                    DeviceItemList.Add(model);
                                }
                                chartlistinfo.DeviceItemList = DeviceItemList;
                            }
                            // DashBoardData赋值
                            chartlistinfo.DashBoardData = item.DashBoardData;
                            RetDashBoardDataList DashBoardData = new RetDashBoardDataList();
                            if (item.DashBoardData != "" && item.DashBoardData != null)
                            {
                                DashBoardData = JsonConvert.DeserializeObject <RetDashBoardDataList>(item.DashBoardData);
                            }
                            chartlistinfo.DashBoardDataList = DashBoardData;
                            chartlistinfo.Remark            = item.Remark;
                            chartlistinfo.SortID            = item.SortID;
                            chartlistinfo.CreateTime        = item.CreateTime;
                            chartlistinfo.CreateUserID      = item.CreateUserID.ToString();
                            chartlistinfo.OrgID             = item.OrgID.ToString();
                            listinfo.Add(chartlistinfo);
                        }
                        r.Data = listinfo;
                    }
                }
                catch (Exception e)
                {
                    r.Msg = "内部错误请重试";
                    log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace);
                    r.Code = -1;
                }
            }

            return(r);
        }
        /// <summary>
        /// 利用ID获取图表列表
        /// </summary>
        public ReturnItem <RetHomeConfiguration> GetChart(HomeConfigurationModel parameter)
        {
            ReturnItem <RetHomeConfiguration> r = new ReturnItem <RetHomeConfiguration>();

            using (UserEntities user = new UserEntities())
            {
                try
                {
                    var getchart = user.U_HomeConfiguration.Where(s => s.ID == parameter.ID).FirstOrDefault();
                    if (getchart == null)
                    {
                        r.Data = null;
                        r.Code = -1;
                        r.Msg  = "未找到设备图表";
                        return(r);
                    }
                    if (getchart != null)
                    {
                        r.Msg  = "设备信息获取成功";
                        r.Code = 0;
                        r.Data = new RetHomeConfiguration()
                        {
                            ID            = getchart.ID,
                            DashBoardType = getchart.DashBoardType.ToString(),
                            DeviceID      = getchart.DeviceID.ToString(),
                            DeviceItemID  = getchart.DeviceItemID.ToString(),
                            ChartName     = getchart.ChartName.ToString(),
                            ChartType     = getchart.ChartType.ToString(),
                            ChartConfig   = getchart.ChartConfig,
                            DashBoardData = getchart.DashBoardData,
                            Remark        = getchart.Remark,
                            SortID        = getchart.SortID,
                            CreateTime    = getchart.CreateTime,
                            CreateUserID  = getchart.CreateUserID.ToString(),
                            OrgID         = getchart.OrgID.ToString()
                        };
                        // DashBoardData赋值
                        RetDashBoardDataList DashBoardData = new RetDashBoardDataList();
                        if (getchart.DashBoardData != "" && getchart.DashBoardData != null)
                        {
                            DashBoardData = JsonConvert.DeserializeObject <RetDashBoardDataList>(getchart.DashBoardData);
                        }
                        r.Data.DashBoardDataList = DashBoardData;
                        r.Data.XAxis             = DashBoardData.x.ToString();
                        r.Data.YAxis             = DashBoardData.y.ToString();
                        r.Data.Width             = DashBoardData.w.ToString();
                        r.Data.Height            = DashBoardData.h.ToString();
                        // ChartConfig赋值
                        DashBoardChartConfigModel ChartConfig = new DashBoardChartConfigModel();
                        if (getchart.ChartConfig != "" && getchart.ChartConfig != null)
                        {
                            ChartConfig = JsonConvert.DeserializeObject <DashBoardChartConfigModel>(getchart.ChartConfig);
                        }
                        r.Data.DatabaseType   = ChartConfig.DatabaseType;
                        r.Data.DataType       = ChartConfig.DataType;
                        r.Data.RecentInterval = ChartConfig.RecentInterval;
                        r.Data.RecentUnit     = ChartConfig.RecentUnit;
                        if (ChartConfig.StartTime != "")
                        {
                            r.Data.StartTime = Convert.ToDateTime(ChartConfig.StartTime);
                        }
                        if (ChartConfig.EndTime != "")
                        {
                            r.Data.EndTime = Convert.ToDateTime(ChartConfig.EndTime);
                        }
                        r.Data.StatisticalInterval = ChartConfig.StatisticalInterval;
                        r.Data.IntervalUnit        = ChartConfig.IntervalUnit;
                        r.Data.MinValue            = ChartConfig.MinValue;
                        r.Data.MaxValue            = ChartConfig.MaxValue;
                        r.Data.ValueType           = ChartConfig.ValueType;
                        r.Data.TextColor           = ChartConfig.TextColor;
                        r.Data.BackgroundColor     = ChartConfig.BackgroundColor;
                        r.Data.HomeDeviceInfoList  = ChartConfig.HomeDeviceInfoList;
                        //首页
                        if (getchart.DashBoardType == 0)
                        {
                            List <BaseModel> Property = new List <BaseModel>();
                            if (ChartConfig.SelectionType == "1") //设备
                            {
                                foreach (var info in ChartConfig.HomeDeviceInfoList)
                                {
                                    BaseModel     model = new BaseModel();
                                    List <string> data  = new List <string>();
                                    data.Add("1");
                                    data.Add(info.DeviceID);
                                    data.Add(info.DeviceItemID);
                                    model.data = data;
                                    Property.Add(model);
                                }
                            }
                            else if (ChartConfig.SelectionType == "2")//总览
                            {
                                BaseModel     model = new BaseModel();
                                List <string> data  = new List <string>();
                                data.Add("2");
                                data.Add(ChartConfig.ValueType);
                                model.data = data;
                                Property.Add(model);
                            }
                            else if (ChartConfig.SelectionType == "3")//表格
                            {
                                BaseModel     model = new BaseModel();
                                List <string> data  = new List <string>();
                                data.Add("3");
                                data.Add(ChartConfig.ValueType);
                                model.data = data;
                                Property.Add(model);
                            }
                            r.Data.Property = Property;
                        }
                        //设备
                        else if (getchart.DashBoardType == 1)
                        {
                            List <DeviceBaseModel> DeviceItemList = new List <DeviceBaseModel>();
                            foreach (var info in ChartConfig.HomeDeviceInfoList)
                            {
                                DeviceBaseModel model = new DeviceBaseModel();
                                model.DeviceItemID = info.DeviceItemID;
                                DeviceItemList.Add(model);
                            }
                            r.Data.DeviceItemList = DeviceItemList;
                        }
                    }
                }
                catch (Exception e)
                {
                    r.Msg = "内部错误请重试";
                    log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace);
                    r.Code = -1;
                }
            }

            return(r);
        }