XMLReader.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Xml;
  5. using System.Diagnostics;
  6. using System.Data;
  7. using System.IO;
  8. using System.Drawing;
  9. namespace FPER
  10. {
  11. public partial class XMLField
  12. {// xml 데이터 클래스
  13. public int FieldID = 0;
  14. public string ReceiverID = "";
  15. public string Name = "";
  16. public int Count_Dev = 0;
  17. public int Coutn_Link = 0;
  18. //public XMLDevice[] xDev
  19. public List<XMLDevice> LDevice = new List<XMLDevice>();
  20. public List<XMLButton> LButton = new List<XMLButton>();
  21. //public string imageBasePath = "";
  22. public string imagePath = "";
  23. public string imageFullPath
  24. {
  25. get
  26. {
  27. return imagePath;
  28. }
  29. }
  30. }
  31. public class XMLButton
  32. {// xml 버튼 데이터 클래스
  33. public string id = "";
  34. public int Xposition = 0;
  35. public int Yposition = 0;
  36. public int width = 0;
  37. public int height = 0;
  38. public string ImagePath = "";
  39. public Image image = null;
  40. public string name = "";
  41. public int jumpField = -1;
  42. }
  43. public partial class XMLDevice
  44. {
  45. public string devID = "";
  46. public int Xposition = 0;
  47. public int Yposition = 0;
  48. public string Image = "";
  49. public string DevIconID = "";
  50. public bool ISDBSetting = false;
  51. //public DataTable Dt;
  52. public string dev_type;
  53. public string dev_name;
  54. public int Receive_ID;
  55. public int Board_ID;
  56. public int Loop_No;
  57. public int Repeater_ID;
  58. public int Device_ID;
  59. public string Inout_Type;
  60. public int Device_Type;
  61. public string positioncode = "";
  62. public string position = "";
  63. public int status = -1;
  64. public string StatusStr
  65. {
  66. get
  67. {
  68. string str = "";
  69. switch (this.status)
  70. {
  71. case 0:
  72. if (this.Inout_Type == "I")
  73. {
  74. str += "감 지";
  75. }
  76. else
  77. {
  78. str += "출 력";
  79. }
  80. break;
  81. case 1:
  82. str += "정 상";
  83. break;
  84. //case 3:
  85. //break;
  86. default:
  87. str += "알수없음";
  88. break;
  89. }
  90. return str;
  91. }
  92. }
  93. public string Device_ViewID
  94. {// 회로 ID 표시 문자 리턴
  95. get
  96. {
  97. string ret = "";
  98. Receive_ID = int.Parse(devID.Substring(2, 2));
  99. Board_ID = int.Parse(devID.Substring(4, 2));
  100. Loop_No = int.Parse(devID.Substring(6, 1));
  101. Repeater_ID = int.Parse(devID.Substring(7, 3));
  102. Device_ID = int.Parse(devID.Substring(10, 1));
  103. ret = string.Format("{0}-{1:D2}-{2}-{3:D3}-{4}", Receive_ID, Board_ID, Loop_No, Repeater_ID, Device_ID);
  104. return ret;
  105. }
  106. }
  107. public string DevID
  108. {
  109. get
  110. {
  111. return devID;
  112. }
  113. set
  114. { //devID MI010100011 : M + I/O + 01 + 01 + 0 + 001 + 1
  115. devID = value;
  116. Receive_ID = int.Parse(devID.Substring(2, 2));
  117. Board_ID = int.Parse(devID.Substring(4, 2));
  118. Loop_No = int.Parse(devID.Substring(6, 1));
  119. Repeater_ID = int.Parse(devID.Substring(7, 3));
  120. Device_ID = int.Parse(devID.Substring(10, 1));
  121. Inout_Type = devID.Substring(1, 1);
  122. if (Inout_Type == "I")
  123. {
  124. Device_Type = 1;
  125. }
  126. else if (Inout_Type == "O")
  127. {
  128. Device_Type = 2;
  129. }
  130. }
  131. }
  132. }
  133. public partial class Dev_Type_Set
  134. {// 타입 데이터 set 클래스
  135. SortedList<string, Dev_Type> slDev_Type = new SortedList<string, Dev_Type>();
  136. List<Image> LTypeImage = new List<Image>();
  137. public string base_path = "";
  138. public string no_image = "";
  139. public string error_image = "";
  140. public void Add(string sID, Dev_Type sDT)
  141. {
  142. slDev_Type.Add(sID, sDT);
  143. Image devimg = Image.FromFile(Path.Combine(base_path, sDT.image));
  144. LTypeImage.Add(devimg);
  145. }
  146. public Image GetDevImage(string devtype)
  147. {
  148. int IndexKey = slDev_Type.IndexOfKey(devtype);
  149. return LTypeImage[IndexKey];
  150. }
  151. public string GetDevImagePath(string devtype)
  152. {// 회로 타입 이미지 경로 읽는 함수
  153. Dev_Type dt;
  154. string ret = "";
  155. if (slDev_Type.TryGetValue(devtype, out dt))
  156. {
  157. ret = Path.Combine(base_path, dt.image);
  158. }
  159. return ret;
  160. }
  161. }
  162. public partial class Dev_Type
  163. {// 회로 타입 데이터 클래스
  164. public string TypeID = "";
  165. public string image = "";
  166. public string name = "";
  167. }
  168. public partial class XMLReader
  169. {// xml 파일 파서 클래스
  170. DataTable dtDeviceDB;
  171. string XML_BasePath = "";
  172. string Field_BasePath = "";
  173. string Dev_BasePath = "";
  174. public void SetXML_BasePath(string XML_Path, DataTable dt)
  175. {
  176. this.XML_BasePath = Path.Combine(XML_Path, "mapview\\xml");
  177. this.Field_BasePath = Path.Combine(XML_Path, "mapview\\Field");
  178. this.Dev_BasePath = Path.Combine(XML_Path, "mapview\\Symbol");
  179. dtDeviceDB = dt;
  180. }
  181. public Dev_Type_Set GetXMLDevTypeData(string XML_name)
  182. {// xml 파일로 부터 회로 데이터 타입 읽는 함수
  183. Dev_Type_Set DataType_Set = null;
  184. try
  185. {
  186. XmlDocument xmlDoc = new XmlDocument();
  187. string stemp;
  188. stemp = Path.Combine(this.XML_BasePath, XML_name);
  189. xmlDoc.Load(stemp);
  190. XmlNodeList xmlNode_Field = xmlDoc.SelectNodes("/Dev_Setting/Device_Type");
  191. XmlElement XML_E = (XmlElement)xmlNode_Field[0];
  192. XmlNodeList xmlNode_Dev = xmlDoc.SelectNodes("/Dev_Setting/Device_Type/TYPE");
  193. //Debug.WriteLine(xmlNode_Dev.Count.ToString());
  194. int Count_TYPE = xmlNode_Dev.Count;
  195. DataType_Set = new Dev_Type_Set();
  196. DataType_Set.base_path = this.Dev_BasePath;
  197. DataType_Set.no_image = string.Format(XML_E.GetAttribute("NO_IMAGE"));
  198. DataType_Set.error_image = string.Format(XML_E.GetAttribute("ERROR_IMAGE"));
  199. for (int i = 0; i < Count_TYPE; i++)
  200. {
  201. //DataType_Set.dev_type[i] = new Dev_Type();
  202. Dev_Type dType = new Dev_Type();
  203. XmlElement XE = (XmlElement)xmlNode_Dev[i];
  204. dType.TypeID = XE.GetAttribute("ID");
  205. dType.image = XE.GetAttribute("IMAGE");
  206. dType.name = XE.GetAttribute("NAME");
  207. DataType_Set.Add(dType.TypeID, dType);
  208. }
  209. }
  210. catch (Exception ex)
  211. {
  212. Util.UErrorMessage(ex, 0, 0);
  213. }
  214. return DataType_Set;
  215. }
  216. //public string BasePath = "";
  217. public List<XMLField> GetXMLFieldData(string XML_name)
  218. {// xml 파일로 부터 현장도면 설정 읽는 함수
  219. //XMLField[] xField;
  220. List<XMLField> xField = new List<XMLField>();
  221. //Util.UDebugMessage(string.Format("+GetXMLFieldData "), 0, 0);
  222. string sTemp = "";
  223. try
  224. {
  225. //xField = new XMLField();
  226. XmlDocument xmlDoc = new XmlDocument();
  227. xmlDoc.Load(Path.Combine(this.XML_BasePath, XML_name));
  228. XmlNodeList XmlRoot = xmlDoc.SelectNodes("/FIELD_CONF");
  229. XmlNodeList xmlNode_Field = xmlDoc.SelectNodes("/FIELD_CONF/Field");
  230. for (int i = 0; i < xmlNode_Field.Count; i++)
  231. {
  232. XmlElement XML_E = (XmlElement)xmlNode_Field[i];
  233. XMLField field = new XMLField();
  234. field.FieldID = int.Parse(XML_E.GetAttribute("ID"));
  235. field.ReceiverID = XML_E.GetAttribute("Receiver_ID");
  236. field.Name = XML_E.GetAttribute("Name");
  237. field.imagePath = Path.Combine(Field_BasePath, XML_E.GetAttribute("IMAGE"));
  238. xField.Add(field);
  239. XmlNodeList xmlNode_Dev = xmlNode_Field[i].SelectNodes("Device");
  240. // 디바이스 필드를 읽는다.
  241. field.Count_Dev = xmlNode_Dev.Count;
  242. for (int j = 0; j < field.Count_Dev; j++)
  243. {
  244. XMLDevice device = new XMLDevice();
  245. XmlElement XE = (XmlElement)xmlNode_Dev[j];
  246. device.Xposition = int.Parse(XE.GetAttribute("Xposition"));
  247. device.Yposition = int.Parse(XE.GetAttribute("Yposition"));
  248. device.DevIconID = string.Format(XE.GetAttribute("DevIconID"));
  249. sTemp = XE.GetAttribute("ID");
  250. if (sTemp == "") // ID가 Null 인 경우..
  251. {
  252. device.DevID = "MI000000000"; // ID에 Null에 상당하는 데이터를 입력한다.
  253. device.ISDBSetting = false;
  254. device.dev_type = "";
  255. device.dev_name = "";
  256. device.positioncode = "";
  257. device.position = "";
  258. }
  259. else
  260. {
  261. device.DevID = XE.GetAttribute("ID");
  262. if (this.dtDeviceDB != null)
  263. {
  264. foreach (DataRow dr in this.dtDeviceDB.Rows)
  265. {
  266. if (dr["BOARD_ID"].ToString() == device.Board_ID.ToString() && dr["LOOP_NO"].ToString() == device.Loop_No.ToString()
  267. && dr["REPEATER_ID"].ToString() == device.Repeater_ID.ToString() && dr["DEVICE_ID"].ToString() == device.Device_ID.ToString()
  268. && dr["INOUT_TYPE"].ToString() == device.Inout_Type.ToString() && dr["COMM_ID"].ToString() == "1")
  269. {
  270. device.ISDBSetting = true;
  271. device.dev_type = dr["DEVICE_TYPE"].ToString();
  272. device.dev_name = dr["DEVICE_NAME"].ToString();
  273. device.positioncode = dr["POSITION_CODE"].ToString();
  274. device.position = dr["POSITION_NAME"].ToString();
  275. break;
  276. }
  277. }
  278. }
  279. }
  280. field.LDevice.Add(device);
  281. }
  282. // 버튼 설정을 읽어온다.
  283. XmlNodeList xmlNodeButton = xmlNode_Field[i].SelectNodes("Button");
  284. for (int j = 0; j < xmlNodeButton.Count; j++)
  285. {
  286. XMLButton button = new XMLButton();
  287. XmlElement XE = (XmlElement)xmlNodeButton[j];
  288. button.id = XE.GetAttribute("ID");
  289. button.Xposition = Convert.ToInt32(XE.GetAttribute("Xposition"));
  290. button.Yposition = Convert.ToInt32(XE.GetAttribute("Yposition"));
  291. button.ImagePath = Path.Combine(Field_BasePath, XE.GetAttribute("Image"));
  292. button.name = XE.GetAttribute("NAME");
  293. button.jumpField = Convert.ToInt32(XE.GetAttribute("JumpField"));
  294. button.width = Convert.ToInt32(XE.GetAttribute("Width"));
  295. button.height = Convert.ToInt32(XE.GetAttribute("Height"));
  296. field.LButton.Add(button);
  297. }
  298. }
  299. }
  300. //catch {
  301. // //Debug.WriteLine(ex);
  302. // //xField = null;
  303. //}
  304. catch (Exception ex)
  305. {
  306. Util.UErrorMessage(ex, 0, 0);
  307. }
  308. return xField;
  309. }
  310. }
  311. }