Exemple #1
0
        ///<summary>获取属性值</summary>
        string getPropertyValue(object obj, PropertyDesc pd)
        {
            //反射设置属性值
            PropertyInfo pi    = obj.GetType().GetProperty(pd.propertyname);
            object       value = pi.GetValue(obj, null);

            if (value == null)
            {
                return("");
            }
            else if (value is Boolean)
            {
                return((Boolean)value ? "1" : "0");
            }
            else if (value is Enum)  //枚举类型
            {
                return(Convert.ToInt32(value).ToString());
            }
            return(value.ToString());
        }
Exemple #2
0
        ///<summary>设置属性值</summary>
        void setPropertyValue(object obj, DataRow dr, PropertyDesc pd, DataLayer.EReadMode readmode)
        {
            //反射设置属性值
            PropertyInfo pi            = obj.GetType().GetProperty(pd.propertyname);
            string       fieldtypename = readmode == DataLayer.EReadMode.模拟 ? pd.simtypename : pd.fieldtypename;
            string       fieldname     = readmode == DataLayer.EReadMode.模拟 ? pd.simFieldName : pd.fieldname;

            switch (pd.propertyTypeName)
            {
            case "Float":
                pi.SetValue(obj, getValueFromDB <float>(dr, fieldtypename, fieldname), null);
                break;

            case "Double":
                pi.SetValue(obj, getValueFromDB <double>(dr, fieldtypename, fieldname), null);
                break;

            case "Int32":
                pi.SetValue(obj, getValueFromDB <int>(dr, fieldtypename, fieldname), null);
                break;

            case "String":
                pi.SetValue(obj, getValueFromDB <string>(dr, fieldtypename, fieldname), null);
                break;

            case "Boolean":
                pi.SetValue(obj, getValueFromDB <bool>(dr, fieldtypename, fieldname), null);
                break;

            case "DateTime":
                pi.SetValue(obj, getValueFromDB <DateTime>(dr, fieldtypename, fieldname), null);
                break;

            default:      //zh注:枚举的处理,还要检查
                pi.SetValue(obj, getValueFromDB <int>(dr, fieldtypename, fieldname), null);
                break;
            }
        }
Exemple #3
0
        ///<summary>
        ///从数据库载入关键属性、台账数据和基础拓扑,依据dr提供的数据载入。
        ///适用在初始批量创建对象:
        ///1. 以acntSelectAll语句获取的DataTable
        ///2. 以DataTable中的DataRow(dr)创建对象(obj),并填入基本信息id, dbopkey
        ///3. 调用本方法填充关键属性、台账和基础拓扑
        ///</summary>
        public void loadKeyAcnt(DataRow dr, PowerBasicObject obj)
        {
            //=====处理关键属性
            //obj.id = dr.getString(this.acntTableRelation.mainTable.keyFieldName);
            obj.id = dr.getString(this.keypdesces.FirstOrDefault(p => p.propertyname == "ID").fieldname);
            if (this.keypdesces.FirstOrDefault(p => p.propertyname == "ID2") != null)
            {
                obj.id2 = dr.getString(this.keypdesces.FirstOrDefault(p => p.propertyname == "ID2").fieldname);
            }

            double x, y; x = y = 0;
            string ps = "";

            foreach (PropertyDesc item in keypdesces)
            {
                if (item.propertyname == "name")
                {
                    obj.name = dr.getString(item.fieldname);
                }
                else if (item.propertyname == "X")
                {
                    x  = dr.getDouble(item.fieldname);
                    ps = (new System.Windows.Point(x, y)).ToString();
                }
                else if (item.propertyname == "Y")
                {
                    y  = dr.getDouble(item.fieldname);
                    ps = (new System.Windows.Point(x, y)).ToString();
                }
                else if (item.propertyname == "points")
                {
                    ps = dr.getString(item.fieldname);
                    if (ps.IndexOf(" ") < ps.IndexOf(",")) //转换为标准格式
                    {
                        ps = ps.Replace(',', '_');
                        ps = ps.Replace(' ', ',');
                        ps = ps.Replace('_', ' ');
                        ps = ps.Replace(";", "");
                    }
                    else if (!ps.Contains(','))
                    {
                        ps = ps.Replace(' ', ',');
                    }
                }
                else if (item.propertyname == "shape")
                {
                    ps = analShape(dr.getString(item.fieldname));
                }
            }

            if (obj is pDotObject)
            {
                (obj as pDotObject).location = ps;
            }
            else if (obj is pPowerLine)
            {
                (obj as pPowerLine).strPoints = ps;
            }
            else if (obj is pArea)
            {
                (obj as pPowerLine).strPoints = ps;
            }
            //=====处理台账
            if (obj.busiAccount == null)
            {
                obj.busiAccount = createAcnt();
            }
            else
            if (obj.busiAccount.GetType().FullName != acntTypeFullName)
            {
                System.Windows.MessageBox.Show("已有台账类型与描述不一致, 强制使用描述类型。" + key);
                obj.busiAccount = createAcnt();
            }

            foreach (DataColumn item in dr.Table.Columns)
            {
                PropertyDesc pd = anctdesces.FirstOrDefault(p => p.fieldname != null && p.fieldname.ToLower() == item.ColumnName.ToLower());
                if (pd != null)
                {
                    setPropertyValue(obj.busiAccount, dr, pd, DataLayer.EReadMode.数据库读取);
                }
                //补充信息
                pd = acntfreedesces.FirstOrDefault(p => p.fieldname != null && p.fieldname.ToLower() == item.ColumnName.ToLower());
                if (pd != null)
                {
                    (obj.busiAccount as AcntDataBase).additionInfoes.Add(new AdditionInfo()
                    {
                        name = pd.propertycname, value = dr[pd.fieldname].ToString()
                    });
                }
            }

            //拓扑相关
            if (toporelationdesces.Count > 0 || toposubordinatedesces.Count > 0 || topoBelontToFacility != null || topoBelongToEquipment != null)
            {
                if (obj.busiTopo == null)
                {
                    obj.busiTopo = new TopoData(obj);
                }
                foreach (DataColumn item in dr.Table.Columns)
                {
                    PropertyDesc pd = toporelationdesces.FirstOrDefault(p => p.fieldname != null && p.fieldname.ToLower() == item.ColumnName.ToLower());
                    if (pd != null) //添加基础关联
                    {
                        if (dbdesc.parseTopoMode == EParseTopoMode.北京经研院格式)
                        {
                            List <string> ss = parseTopoByBJJYY(dr[item].ToString());
                            foreach (string sid in ss)
                            {
                                (obj.busiTopo as TopoData).relationObjs.Add(new TopoObjDesc()
                                {
                                    id = sid, table = pd.tablename, field = pd.fieldname
                                });
                            }
                        }
                        else  //直接字段值为关联对象ID
                        {
                            (obj.busiTopo as TopoData).relationObjs.Add(new TopoObjDesc()
                            {
                                id = dr[item].ToString(), table = pd.tablename, field = pd.fieldname
                            });
                        }
                    }
                    pd = toposubordinatedesces.FirstOrDefault(p => p.fieldname != null && p.fieldname.ToLower() == item.ColumnName.ToLower());
                    if (pd != null) //添加基础从属
                    {
                        (obj.busiTopo as TopoData).subordinateObjs.Add(new TopoObjDesc()
                        {
                            id = dr[item].ToString(), table = pd.tablename, field = pd.fieldname
                        });
                    }
                    if (topoBelontToFacility != null && topoBelontToFacility.fieldname.ToLower() == item.ColumnName.ToLower())  //填写直接所属设施
                    {
                        (obj.busiTopo as TopoData).belontToFacilityID = new TopoObjDesc()
                        {
                            id = dr[item].ToString(), table = topoBelontToFacility.tablename, field = topoBelontToFacility.fieldname
                        }
                    }
                    ;
                    if (topoBelongToEquipment != null && topoBelongToEquipment.fieldname.ToLower() == item.ColumnName.ToLower())  //填写直接所属设备(等效设备)
                    {
                        (obj.busiTopo as TopoData).belongToEquipmentID = new TopoObjDesc()
                        {
                            id = dr[item].ToString(), table = topoBelongToEquipment.tablename, field = topoBelongToEquipment.fieldname
                        }
                    }
                    ;
                }
            }
        }

        ///<summary>解析北京经研院的CONNECTION关联拓扑字段</summary>
        List <string> parseTopoByBJJYY(string s)
        {
            //2;23580694:<1397383_36000000:36000000:(513626.330492,287090.556251019):-1>;23454695:<1397367_36000000:36000000:(513625.610492,287090.556250981):-1>
            List <string> list = new List <string>();

            Regex           rgx     = new Regex(";(\\w*|\\d*|-):<.[^<>]*>", RegexOptions.IgnoreCase);
            MatchCollection matches = rgx.Matches(s);

            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    list.Add(match.Groups[1].Value);
                }
            }
            return(list);
        }

        ///<summary>解析shape形式的坐标描述串</summary>
        string analShape(string shape)
        {
            //例2:2:0(539411.543202,287283.9925172764);(539411.543202,287283.99251);(539411.543202,287283.99250272365)
            //表示:
            //以":"分隔,  第一位2表示类型, 1-点设备, 2-线设备, 3-多边形设备
            //第二位2表示维度, 2 - 两维, 3-三维
            //第三位 表示SRID,
            //第四位,表示坐标点, 以括号表示一个点的坐标,上面的结构表示三个点的坐标
            string s = shape.Substring(shape.IndexOf('('));

            s = s.Replace("(", "").Replace(")", "").Replace(";", " ");
            return(s);
        }