コード例 #1
0
ファイル: DataBase.cs プロジェクト: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        virtual public AttributePropertyInfoPairCollection GetDeviceDataItemAttributes()
        {
            AttributePropertyInfoPairCollection result = new AttributePropertyInfoPairCollection();

            PropertyInfo[] propertyInfos = this.GetType().GetProperties();
            foreach (PropertyInfo pi in propertyInfos)
            {
                object[] atts = pi.GetCustomAttributes(typeof(DataItemAttribute), false);
                if (atts.Length > 0)
                {
                    DataItemAttribute att = (DataItemAttribute)atts[0];

                    AttributePropertyInfoPair pair = new AttributePropertyInfoPair(
                        att, pi);

                    result.Add(pair);
                }
            }

            // sort
            //
            result.Sort();

            return(result);
        }
コード例 #2
0
ファイル: DataBase.cs プロジェクト: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        virtual public ReportItemCollection GetReportItems()
        {
            ReportItemCollection reportItems = new ReportItemCollection();

            AttributePropertyInfoPairCollection attPropertyInfos = this.GetDeviceDataItemAttributes();

            foreach (AttributePropertyInfoPair item in attPropertyInfos)
            {
                DataItemAttribute att   = item.Attribute;
                PropertyInfo      pi    = item.PropertyInfo;
                object            value = pi.GetValue(this, null);

                //if (!this.HideDataAttributeNames.Contains(att.Name))
                if (!HideDataAttributeNameManager.Default.Contains(this.GetType().Name, att.Name))
                {
                    ReportItem reportItem = new ReportItem(att.Name, value, att.Unit, att.Format);
                    reportItems.Add(reportItem);
                }
            }

            return(reportItems);
        }
コード例 #3
0
ファイル: DataBase.cs プロジェクト: hkiaipc/C3
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public virtual AttributePropertyInfoPairCollection GetDeviceDataItemAttributes()
        {
            AttributePropertyInfoPairCollection result = new AttributePropertyInfoPairCollection();
            PropertyInfo[] propertyInfos = this.GetType().GetProperties();
            foreach (PropertyInfo pi in propertyInfos)
            {
                object[] atts = pi.GetCustomAttributes(typeof(DataItemAttribute), false);
                if (atts.Length > 0)
                {
                    DataItemAttribute att = (DataItemAttribute)atts[0];

                    AttributePropertyInfoPair pair = new AttributePropertyInfoPair(
                        att, pi);

                    result.Add(pair);
                }
            }

            // sort
            //
            result.Sort();

            return result;
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        private DataTable ConvertToDataTable(DataCollection datas)
        {
            DataTable tbl = new DataTable();

            if (datas.Count > 0)
            {
                IData last     = datas[datas.Count - 1];
                Type  lastType = last.GetType();
                //ReportItemCollection reportItems = last.GetReportItems();

                //foreach (ReportItem ri in reportItems)
                //{
                //    Type valueType = ri.Value.GetType();
                //    DataColumn column = new DataColumn(ri.Name, valueType);
                //    tbl.Columns.Add(column);
                //}

                //foreach (IData data in datas)
                //{
                //    if (data.GetType() != lastType)
                //    {
                //        continue;
                //    }
                //    object[] values = GetReportItemCollectionValues(data.GetReportItems());
                //    tbl.Rows.Add(values);
                //}



                AttributePropertyInfoPairCollection ss = last.GetDeviceDataItemAttributes();
                foreach (AttributePropertyInfoPair s in ss)
                {
                    Type valueType = s.PropertyInfo.PropertyType;
                    DataItemAttribute diAttribute = s.Attribute;
                    string            columnName  = diAttribute.Name;

                    DataColumn column = new DataColumn(columnName, valueType);
                    column.ExtendedProperties["unit"]   = diAttribute.Unit.Text;
                    column.ExtendedProperties["format"] = diAttribute.Format;
                    column.ExtendedProperties["name"]   = diAttribute.Name;
                    tbl.Columns.Add(column);
                }


                foreach (IData data in datas)
                {
                    if (data.GetType() != lastType)
                    {
                        continue;
                    }
                    object[] values = new object[ss.Count];
                    int      idx    = 0;
                    foreach (AttributePropertyInfoPair s in ss)
                    {
                        object v = s.PropertyInfo.GetValue(data, null);
                        values[idx++] = v;
                    }
                    tbl.Rows.Add(values);
                }
            }
            return(tbl);
        }