예제 #1
0
        public object Get(string buildId, string svgId, string dataType)
        {
            SvgDataViewModel dataViewModel = new SvgDataViewModel();

            try
            {
                dataViewModel = service.GetSvgData(buildId, svgId);
            }
            catch (Exception e)
            {
                return(e.Message);
            }


            return(dataViewModel);
        }
예제 #2
0
파일: SvgDbContext.cs 프로젝트: Mx1014/EMS
        public SvgDataViewModel GetDataViewModel(string buildId, string svgId)
        {
            SvgBinding svgBinding = GetSvgBinding(svgId);

            if (svgBinding == null)
            {
                return(null);
            }

            string[] meterArray = svgBinding.Meters.Split('|');
            string[] paramArray = svgBinding.ParamStrings.Split('|');


            StringBuilder builder = new StringBuilder();

            builder.Append(@"SELECT F_MeterID MeterID
                             ,SUBSTRING(F_TagName,CHARINDEX('_',F_TagName)+1,LEN(F_TagName) -CHARINDEX('_',F_TagName)) ParamName
                             ,F_RecentData Value
                             FROM HistoryData
                             WHERE F_BuildID = @BuildId
                             AND F_MeterID in (");
            builder.Append("'" + string.Join("','", meterArray) + "')");
            builder.Append(" AND F_Year = YEAR(GETDATE())");
            if (paramArray.Length > 0)
            {
                builder.Append("AND (");
                for (int i = 0; i < paramArray.Length; i++)
                {
                    if (i == 0)
                    {
                        builder.Append("(F_TagName like ('%" + paramArray[i] + "'))");
                    }
                    else
                    {
                        builder.Append("or (F_TagName like ('%" + paramArray[i] + "'))");
                    }
                }
                builder.Append(")");
            }

            string sql = builder.ToString();

            List <SvgTempValue> tempValues = _hisdb.Database.SqlQuery <SvgTempValue>(sql, new SqlParameter("@BuildId", buildId)).ToList();

            SvgDataViewModel viewModel = new SvgDataViewModel();

            viewModel.MeterValueList = new List <SvgMeterParam>();

            if (tempValues.Count > 0)
            {
                foreach (string item in meterArray)
                {
                    List <SvgTempValue> tempParams = tempValues.FindAll(o => o.MeterId == item);

                    SvgMeterParam meterParam = new SvgMeterParam();
                    meterParam.MeterID   = item;
                    meterParam.ParamList = new List <SvgParamValue>();
                    if (tempParams.Count > 0)
                    {
                        foreach (var paramValue in tempParams)
                        {
                            meterParam.ParamList.Add(new SvgParamValue()
                            {
                                Code  = paramValue.ParamName,
                                Value = paramValue.Value
                            });
                        }
                    }

                    viewModel.MeterValueList.Add(meterParam);
                }
            }

            return(viewModel);
        }