示例#1
0
        /// <summary>
        /// 获得FeildInformation(当前电流会从Ammeter表里)
        /// </summary>
        /// <param name="viewName"></param>
        /// <returns>键为表名,值为字段列表</returns>
        private IDictionary <string, List <FieldInformation> > GetFeildInformation(string organizationId, IList <string> variableNames, string myDataTableName, string tablePrefix = "Realtime")
        {
            Dictionary <string, List <FieldInformation> > fieldInformations = new Dictionary <string, List <FieldInformation> >();

            if (variableNames.Count < 0)
            {
                return(fieldInformations);
            }
            else
            {
                StringBuilder       queryString = new StringBuilder();
                List <SqlParameter> parameters  = new List <SqlParameter>();
                queryString.Append("select DatabaseName,TableName,FieldName,VariableName from MonitorContrast ");
                queryString.Append("where rtrim(TableName)=@TableName and OrganizationID=@organizationId and type=@type and Enabled=@enabled and (");
                parameters.Add(new SqlParameter("@TableName", myDataTableName));
                parameters.Add(new SqlParameter("@enabled", 1));
                parameters.Add(new SqlParameter("@organizationId", organizationId));
                parameters.Add(new SqlParameter("@type", _type));
                foreach (var item in variableNames)
                {
                    queryString.Append("VariableName=@" + item + " or ");
                    parameters.Add(new SqlParameter("@" + item, item));
                }
                queryString.Remove(queryString.Length - 4, 4).Append(")");
                DataTable table = _dataFactory.Query(queryString.ToString(), parameters.ToArray());
                foreach (DataRow row in table.Rows)
                {
                    FieldInformation fieldInfor = new FieldInformation();
                    string           key        = row["DatabaseName"].ToString().Trim() + ".dbo." + tablePrefix + "_" + row["TableName"].ToString().Trim();
                    fieldInfor.FeildName    = row["FieldName"].ToString().Trim();
                    fieldInfor.VariableName = row["VariableName"].ToString().Trim();
                    if (fieldInformations.Keys.Contains(key))
                    {
                        fieldInformations[key].Add(fieldInfor);
                    }
                    else
                    {
                        fieldInformations.Add(key, new List <FieldInformation>());
                        fieldInformations[key].Add(fieldInfor);
                    }
                }

                return(fieldInformations);
            }
        }
示例#2
0
        /// <summary>
        /// 获得FeildInformation
        /// </summary>
        /// <param name="viewName"></param>
        /// <returns>键为表名,值为字段列表</returns>
        private IDictionary <string, List <FieldInformation> > GetFeildInformation(string organizationId, IList <string> variableNames, string tablePrefix = "Realtime")
        {
            Dictionary <string, List <FieldInformation> > fieldInformations = new Dictionary <string, List <FieldInformation> >();

            if (variableNames.Count < 0)
            {
                return(fieldInformations);
            }
            //DCS的处理方法
            if ("DCS" == _type)
            {
                StringBuilder       queryString = new StringBuilder();
                List <SqlParameter> parameters  = new List <SqlParameter>();
                queryString.Append("select TagName,DCSName,DBName,TableName,FieldName from View_DCSContrast where ");
                //queryString.Append("where OrganizationID=@organizationId and type=@type and Enabled=@enabled and (");
                //parameters.Add(new SqlParameter("@enabled", 1));
                //parameters.Add(new SqlParameter("@organizationId", organizationId));
                //parameters.Add(new SqlParameter("@type", _type));
                foreach (var item in variableNames)
                {
                    queryString.Append("TagName=@" + item + " or ");
                    parameters.Add(new SqlParameter("@" + item, item));
                }
                queryString.Remove(queryString.Length - 4, 4);
                //DebugHelper.TestStart();
                DataTable table = _dataFactory.Query(queryString.ToString(), parameters.ToArray());
                //DebugHelper.TestStop("执行sql查询的时间(ms):");
                foreach (DataRow row in table.Rows)
                {
                    FieldInformation fieldInfor = new FieldInformation();
                    string           key        = row["DBName"].ToString().Trim() + ".dbo." + tablePrefix + "_" + row["TableName"].ToString().Trim();
                    fieldInfor.FeildName    = row["FieldName"].ToString().Trim();
                    fieldInfor.VariableName = row["DCSName"].ToString().Trim() + '_' + row["FieldName"].ToString().Trim();
                    if (fieldInformations.Keys.Contains(key))
                    {
                        fieldInformations[key].Add(fieldInfor);
                    }
                    else
                    {
                        fieldInformations.Add(key, new List <FieldInformation>());
                        fieldInformations[key].Add(fieldInfor);
                    }
                }
            }

            else if ("Environment" == _type)
            {
                StringBuilder       queryString = new StringBuilder();
                List <SqlParameter> parameters  = new List <SqlParameter>();
                queryString.Append("select TagName,DCSName,DBName,TableName,FieldName from View_DCSContrast where ");
                //queryString.Append("where OrganizationID=@organizationId and type=@type and Enabled=@enabled and (");
                //parameters.Add(new SqlParameter("@enabled", 1));
                //parameters.Add(new SqlParameter("@organizationId", organizationId));
                //parameters.Add(new SqlParameter("@type", _type));
                foreach (var item in variableNames)
                {
                    queryString.Append("TagName=@" + item + " or ");
                    parameters.Add(new SqlParameter("@" + item, item));
                }
                queryString.Remove(queryString.Length - 4, 4);
                //DebugHelper.TestStart();
                DataTable table = _dataFactory.Query(queryString.ToString(), parameters.ToArray());
                //DebugHelper.TestStop("执行sql查询的时间(ms):");
                foreach (DataRow row in table.Rows)
                {
                    FieldInformation fieldInfor = new FieldInformation();
                    string           key        = row["DBName"].ToString().Trim() + ".dbo." + tablePrefix + "_" + row["TableName"].ToString().Trim();
                    fieldInfor.FeildName    = row["FieldName"].ToString().Trim();
                    fieldInfor.VariableName = row["DCSName"].ToString().Trim() + '_' + row["FieldName"].ToString().Trim();
                    if (fieldInformations.Keys.Contains(key))
                    {
                        fieldInformations[key].Add(fieldInfor);
                    }
                    else
                    {
                        fieldInformations.Add(key, new List <FieldInformation>());
                        fieldInformations[key].Add(fieldInfor);
                    }
                }
            }
            else
            {
                StringBuilder       queryString = new StringBuilder();
                List <SqlParameter> parameters  = new List <SqlParameter>();
                queryString.Append("select DatabaseName,TableName,FieldName,VariableName from MonitorContrast ");
                queryString.Append("where OrganizationID=@organizationId and type=@type and Enabled=@enabled and (");
                parameters.Add(new SqlParameter("@enabled", 1));
                parameters.Add(new SqlParameter("@organizationId", organizationId));
                parameters.Add(new SqlParameter("@type", _type));
                foreach (var item in variableNames)
                {
                    queryString.Append("VariableName=@" + item + " or ");
                    parameters.Add(new SqlParameter("@" + item, item));
                }
                queryString.Remove(queryString.Length - 4, 4).Append(")");
                DataTable table = _dataFactory.Query(queryString.ToString(), parameters.ToArray());
                foreach (DataRow row in table.Rows)
                {
                    FieldInformation fieldInfor = new FieldInformation();
                    string           key        = row["DatabaseName"].ToString().Trim() + ".dbo." + tablePrefix + "_" + row["TableName"].ToString().Trim();
                    fieldInfor.FeildName    = row["FieldName"].ToString().Trim();
                    fieldInfor.VariableName = row["VariableName"].ToString().Trim();
                    if (fieldInformations.Keys.Contains(key))
                    {
                        fieldInformations[key].Add(fieldInfor);
                    }
                    else
                    {
                        fieldInformations.Add(key, new List <FieldInformation>());
                        fieldInformations[key].Add(fieldInfor);
                    }
                }
            }

            return(fieldInformations);
        }