/// <summary> /// 读取地图中的配置 /// </summary> /// <param name="mapID">地图ID</param> /// <param name="path">配置文件路径</param> /// <param name="mapHeight">地图高度</param> /// <param name="MapWidth">地图宽度</param> /// <param name="readEquType">该设备类型是否进行读取</param> /// <returns>读取是否成功</returns> public bool Read(string mapID, string path, int mapHeight, int MapWidth, ReadEquType readEquType) { XmlDocument doc = new XmlDocument(); // 缓存设备 List <MyObject> equList = new List <MyObject>(); try { doc.Load(path); // 设备加载 List <Equ> equs = ds.ReadEqu(Convert.ToInt32(mapID)); List <yx> yxs = ds.GetYXs(); List <Yx_cfg> yxcfgs = ds.GetYXcfgs(); List <yk> yks = ds.GetYks(); List <Yk_cfg> ykcfgs = ds.GetYKcfgs(); List <yc> ycs = ds.GetYcs(); List <Yc_cfg> yccfgs = ds.GetYccfgs(); List <p_area_cfg> areas = ds.GetAllArea(); Log.WriteLog("start readxml:" + DateTime.Now.ToString("HH:mm:ss.fff")); List <Yx_cfg> yxcfgdb = new List <Yx_cfg>(); List <Yk_cfg> ykcfgdb = new List <Yk_cfg>(); //交大地图的宽度和高度 int width = Convert.ToInt32(doc.GetElementsByTagName("PicInfo")[0].Attributes["width"].InnerText); int hight = Convert.ToInt32(doc.GetElementsByTagName("PicInfo")[0].Attributes["hight"].InnerText); XmlNodeList xnl = doc.GetElementsByTagName("ob"); if (xnl != null) { //读取父设备信息 string tvFarther = ds.GetFartherID("TV"); string epFarther = ds.GetFartherID("EP"); string firFarther = ds.GetFartherID("F"); for (int i = 0; i < xnl.Count; i++) { MyObject m_object = null; //m_object = new MyObject(); string type = xnl[i].Attributes["Type"].Value; XmlNode ConXml = xnl[i].SelectSingleNode("ControlObject"); XmlNode drawob = xnl[i].SelectSingleNode("DrawOb"); XmlNode name = drawob.SelectSingleNode("ObjectName"); XmlNode xy = drawob.SelectSingleNode("EndPoint"); if (Convert.ToInt32(xy.Attributes["X"].Value) < 0) { continue; } if (Convert.ToInt32(xy.Attributes["Y"].Value) < 0) { continue; } switch (type) { case "12836": //情报板 #region 情报板 if (!readEquType.CMS) { continue; } m_object = new CMObject(); string strName = ConXml.Attributes["StrName"].Value; if (strName.IndexOf("1") > 0) //门架 { m_object.equtype = MyObject.ObjectType.CM; } //else //if (strName.IndexOf("2") > 0)//限速标志 //{ // m_object.equtype = "S"; //} else //F板 { m_object.equtype = MyObject.ObjectType.CF; } if (strName.IndexOf("r") > 0) { m_object.equ.DirectionID = 1; } if (strName.IndexOf("l") > 0) { m_object.equ.DirectionID = 2; } #region 情报板配置信息读取 XmlDocument xd = new XmlDocument(); var cmsNode = ConXml.SelectSingleNode("ExtAttribute"); if (cmsNode == null) { continue; } string cmsInfo = cmsNode.InnerText; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); xd.LoadXml(cmsInfo); ((CMSEqu)m_object).cms_pro.CMSWidth = Convert.ToInt32(xd.GetElementsByTagName("CMS")[0].Attributes["Width"].InnerText); ((CMSEqu)m_object).cms_pro.CMSHeight = Convert.ToInt32(xd.GetElementsByTagName("CMS")[0].Attributes["Height"].InnerText); ((CMSEqu)m_object).cms_pro.EquID = m_object.equ.EquID; ((CMSEqu)m_object).cms_pro.FontType = "楷体"; ((CMSEqu)m_object).cms_pro.FontColor = "黄"; ((CMSEqu)m_object).cms_pro.BackColor = "黑"; ((CMSEqu)m_object).cms_pro.FontSize = 24; ((CMSEqu)m_object).cms_pro.ContentType = 1; ((CMSEqu)m_object).cms_pro.CharBetween = 5; ((CMSEqu)m_object).cms_pro.OutType = 1; ((CMSEqu)m_object).cms_pro.OutSpeed = 20; ((CMSEqu)m_object).cms_pro.StayTime = 200; ((CMSEqu)m_object).cms_pro.BlankCount = 0; ((CMSEqu)m_object).cms_pro.MinFontSize = 16; ((CMSEqu)m_object).cms_pro.SupportPic = 1; ((CMSEqu)m_object).cms_pro.PicLocation = "CmsListBitmap1"; #endregion m_object.equ.TaskWV = 1; #endregion break; case "12839": //限速标志 m_object = new MyObject(); if (!readEquType.S) { continue; } m_object.equtype = MyObject.ObjectType.S; m_object.equ.TaskWV = 1; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); break; case "12838": //车检器 if (!readEquType.VC) { continue; } m_object = new MyObject(); m_object.equtype = MyObject.ObjectType.VC; m_object.equ.AlarmMethod = "NORMAL"; m_object.equ.TaskWV = 1; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); break; case "12862": //气象仪 if (!readEquType.VI) { continue; } m_object = new MyObject(); m_object.equtype = MyObject.ObjectType.VI; m_object.equ.AlarmMethod = "YW"; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.TaskWV = 1; break; case "12834": //广播 continue; case "12832": //紧急电话 if (!readEquType.EP) { continue; } m_object = new EPEqu(); m_object.equtype = MyObject.ObjectType.EP_T; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); AddEPConfig((EPEqu)m_object, ConXml); break; case "12833": //摄像机 if (!readEquType.TV) { continue; } m_object = new TVEqu(); switch (ConXml.Attributes["StrName"].Value) { case "lcctv1_mov.bmp": case "rcctv1_mov.bmp": m_object.equtype = MyObject.ObjectType.TV_CCTV_Gun; break; case "rcctv2_mov.bmp": case "lcctv2_mov.bmp": m_object.equtype = MyObject.ObjectType.TV_CCTV_E; break; default: m_object.equtype = MyObject.ObjectType.TV_CCTV_Ball; break; } m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); if (!ConXml.Attributes["Region"].Value.Equals("0")) { AddCCTVConfig((TVEqu)m_object, ConXml.Attributes["Region"].Value); } break; case "12835": //火灾 if (!readEquType.FIRE) { continue; } //m_object = new MyObject(); XmlNode addressxy = drawob.SelectSingleNode("EndPoint"); int x = Convert.ToInt32(addressxy.Attributes["X"].Value) * MapWidth / width; AddFireConfig(equList, ConXml, name.InnerText, x, ref firFarther, mapID); continue; #region plc case "12837": //车道指示器 if (!readEquType.P_TL) { continue; } m_object = new PLCEqu(); switch (ConXml.Attributes["StrName"].Value) { case "lindicator_mov.bmp": //左 case "uindicator_mov.bmp": m_object.equtype = MyObject.ObjectType.P_TL5_Left; break; case "rindicator_mov.bmp": //右 case "dindicator_mov.bmp": m_object.equtype = MyObject.ObjectType.P_TL5_Right; break; case "sindicator_mov.bmp": m_object.equtype = MyObject.ObjectType.P_TL2_Close; break; default: continue; } m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddConfig((PLCEqu)m_object, ConXml, yxcfgs, ykcfgs, equList, ref areas, mapID, yxcfgdb, ykcfgdb); break; case "12831": //交通灯 if (!readEquType.P_HL) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_HL2; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddConfig((PLCEqu)m_object, ConXml, yxcfgs, ykcfgs, equList, ref areas, mapID, yxcfgdb, ykcfgdb); break; case "12830": //照明 if (!readEquType.LIGHT) { continue; } m_object = new PLCEqu(); if (name.InnerText.IndexOf("应") > 0 || name.InnerText.IndexOf("引") > 0) //基本 { m_object.equtype = MyObject.ObjectType.P_LYJ; } else if (name.InnerText.IndexOf("JQ") > 0 || name.InnerText.IndexOf("加") > 0) //加强 { m_object.equtype = MyObject.ObjectType.P_LJQ; } else //基本 { m_object.equtype = MyObject.ObjectType.P_L; } m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddConfig((PLCEqu)m_object, ConXml, yxcfgs, ykcfgs, equList, ref areas, mapID, yxcfgdb, ykcfgdb); break; case "12829": //风机 if (!readEquType.P_JF) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_JF; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddConfig((PLCEqu)m_object, ConXml, yxcfgs, ykcfgs, equList, ref areas, mapID, yxcfgdb, ykcfgdb); break; case "12846": //GJ if (!readEquType.GJ) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_GJ; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddYCConfig(m_object as PLCEqu, ConXml, ycs, yccfgs, ref areas, equList, mapID); break; case "12843": //CO if (!readEquType.CO) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_CO; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddYCConfig(m_object as PLCEqu, ConXml, ycs, yccfgs, ref areas, equList, mapID); break; case "12844": //VI if (!readEquType.VI) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_VI; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddYCConfig(m_object as PLCEqu, ConXml, ycs, yccfgs, ref areas, equList, mapID); break; case "12848": //TW if (!readEquType.TW) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_TW; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddYCConfig(m_object as PLCEqu, ConXml, ycs, yccfgs, ref areas, equList, mapID); break; case "12842": //横通门 if (!readEquType.TD) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_TD; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddConfig((PLCEqu)m_object, ConXml, yxcfgs, ykcfgs, equList, ref areas, mapID, yxcfgdb, ykcfgdb); break; case "12845": //高位水池 if (!readEquType.LLID) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_LLDI; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddYCConfig(m_object as PLCEqu, ConXml, ycs, yccfgs, ref areas, equList, mapID); break; case "12855": //水泵 if (!readEquType.P_P) { continue; } m_object = new PLCEqu(); m_object.equtype = MyObject.ObjectType.P_P; m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddYCConfig(m_object as PLCEqu, ConXml, ycs, yccfgs, ref areas, equList, mapID); break; case "12840": //车行横通标志\转弯灯 if (!readEquType.P_TL2) { continue; } m_object = new PLCEqu(); switch (ConXml.Attributes["StrName"].Value) { case "uvehicleflag_mov.bmp": //向上 m_object.equtype = MyObject.ObjectType.P_TL2_UP; break; case "dvehicleflag_mov.bmp": //向下 m_object.equtype = MyObject.ObjectType.P_TL2_Down; break; default: continue; } m_object.equ.EquID = NameTool.CreateEquId(m_object.equtype); m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; AddConfig((PLCEqu)m_object, ConXml, yxcfgs, ykcfgs, equList, ref areas, mapID, yxcfgdb, ykcfgdb); break; #endregion default: continue; } m_object.equ.EquName = name.InnerText; m_object.equ.PileNo = ConXml.Attributes["Badge"].Value; m_object.equ.PointX = (Convert.ToInt32(xy.Attributes["X"].Value) * MapWidth / width).ToString(); m_object.equ.PointY = "-" + Convert.ToInt32(xy.Attributes["Y"].Value) * mapHeight / hight; m_object.equ.MapID = mapID; m_object.equ.plcStationAddress = ConXml.Attributes["Station"].Value; m_object.equ.AddressDiscribe = xnl[i].Attributes["ID"].Value; #region 子系统 if ("-1".Equals(ConXml.Attributes["Station"].Value) && m_object.equtype != MyObject.ObjectType.TV_CCTV_Gun) { if (m_object.equtype == MyObject.ObjectType.TV_CCTV_Gun || m_object.equtype == MyObject.ObjectType.TV_CCTV_E || m_object.equtype == MyObject.ObjectType.TV_CCTV_Ball || m_object.equtype == MyObject.ObjectType.EP_T) { } else { continue; } } if (m_object.equ.EquTypeID.StartsWith("TV_CCTV")) { if (tvFarther == null) { TVEqu tvInfo = new TVEqu(); tvInfo.equtype = MyObject.ObjectType.TV; tvInfo.equ.EquID = NameTool.CreateEquId(tvInfo.equtype); tvInfo.equ.EquName = "摄像机流媒体服务器"; tvInfo.equ.PointX = "0"; tvInfo.equ.PointY = "0"; tvInfo.equ.TaskWV = 1; tvInfo.equ.MapID = mapID; equList.Add(tvInfo); tvFarther = tvInfo.equ.EquID; } m_object.equ.FatherEquID = tvFarther; } if (m_object.equ.EquTypeID.StartsWith("EP_")) { if (epFarther == null) { EPEqu epInfo = new EPEqu(); epInfo.equtype = MyObject.ObjectType.EP; epInfo.equ.EquID = NameTool.CreateEquId(epInfo.equtype); epInfo.equ.EquName = "紧急电话主机"; epInfo.equ.PointX = "50"; epInfo.equ.PointY = "0"; epInfo.equ.TaskWV = 1; epInfo.equ.MapID = mapID; equList.Add(epInfo); epFarther = epInfo.equ.EquID; } m_object.equ.FatherEquID = epFarther; } if (m_object.equ.EquTypeID.StartsWith("F_")) { } #endregion equList.Add(m_object); } int InsertCount = 0; if (equList.Count > 0) { InsertCount = dbop.InsertEqu(equList); List <Tv_cctv_cfg> tvinfos = new List <Tv_cctv_cfg>(); List <f_c_cfg> fireinfos = new List <f_c_cfg>(); List <ep_c_cfg> epinfos = new List <ep_c_cfg>(); List <c_cfg> cms = new List <c_cfg>(); Log.WriteLog("yxcfgdb:" + DateTime.Now); if (yxcfgdb.Count > 0) { dbop.InsertYXConfig(yxcfgdb); } Log.WriteLog("ykcfgdb:" + DateTime.Now); if (ykcfgdb.Count > 0) { dbop.InsertYKConfig(ykcfgdb); } Log.WriteLog("子系统:" + DateTime.Now); for (int i = 0; i < equList.Count; i++) { if (equList[i] is FireEqu)//插入火灾配置信息 { fireinfos.Add((equList[i] as FireEqu).fire_pro); } else if (equList[i] is TVEqu)//插入摄像机配置信息 { if ((equList[i] as TVEqu).tv_pro.CCTVID != null) { tvinfos.Add((equList[i] as TVEqu).tv_pro); } } else if (equList[i] is EPEqu)//插入紧急电话配置 { epinfos.Add((equList[i] as EPEqu).ep_pro); } else if (equList[i] is CMSEqu)//插入plc配置信息 { cms.Add((equList[i] as CMSEqu).cms_pro); } } Log.WriteLog("火灾配置条数:" + dbop.InsertFire(fireinfos)); Log.WriteLog("摄像机配置条数:" + dbop.InsertCCTV(tvinfos)); Log.WriteLog("紧急电话配置条数:" + dbop.InsertEpList(epinfos)); Log.WriteLog("情报板配置条数:" + dbop.InsertC_cfgList(cms)); } //Log.WriteLog("InsertCount:" + InsertCount); } } catch (Exception e) { Log.WriteLog(e); return(false); } return(true); }