| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 | using System;using System.Collections.Generic;using System.Text;using System.Xml;using System.Diagnostics;using System.Data;using System.IO;using System.Drawing;namespace FPER{    public partial class XMLField    {// xml 데이터 클래스         public int FieldID = 0;        public string ReceiverID = "";        public string Name = "";        public int Count_Dev = 0;        public int Coutn_Link = 0;        //public XMLDevice[] xDev        public List<XMLDevice> LDevice = new List<XMLDevice>();        public List<XMLButton> LButton = new List<XMLButton>();        //public string imageBasePath = "";        public string imagePath = "";        public string imageFullPath        {            get            {                return imagePath;            }        }    }    public class XMLButton    {// xml 버튼 데이터 클래스        public string id = "";        public int Xposition = 0;        public int Yposition = 0;        public int width = 0;        public int height = 0;        public string ImagePath = "";        public Image image = null;        public string name = "";        public int jumpField = -1;    }    public partial class XMLDevice    {        public string devID = "";        public int Xposition = 0;        public int Yposition = 0;        public string Image = "";        public string DevIconID = "";        public bool ISDBSetting = false;        //public DataTable Dt;        public string dev_type;        public string dev_name;        public int Receive_ID;        public int Board_ID;        public int Loop_No;        public int Repeater_ID;        public int Device_ID;        public string Inout_Type;        public int Device_Type;        public string positioncode = "";        public string position = "";        public int status = -1;        public string StatusStr        {            get            {                string str = "";                switch (this.status)                {                    case 0:                        if (this.Inout_Type == "I")                        {                            str += "감 지";                        }                        else                        {                            str += "출 력";                        }                        break;                    case 1:                        str += "정 상";                        break;                    //case 3:                    //break;                    default:                        str += "알수없음";                        break;                }                return str;            }        }        public string Device_ViewID        {// 회로 ID 표시 문자 리턴            get            {                string ret = "";                Receive_ID = int.Parse(devID.Substring(2, 2));                Board_ID = int.Parse(devID.Substring(4, 2));                Loop_No = int.Parse(devID.Substring(6, 1));                Repeater_ID = int.Parse(devID.Substring(7, 3));                Device_ID = int.Parse(devID.Substring(10, 1));                ret = string.Format("{0}-{1:D2}-{2}-{3:D3}-{4}", Receive_ID, Board_ID, Loop_No, Repeater_ID, Device_ID);                return ret;            }        }        public string DevID        {            get            {                return devID;            }            set            { //devID MI010100011 : M + I/O + 01 + 01 + 0 + 001 + 1                devID = value;                Receive_ID = int.Parse(devID.Substring(2, 2));                Board_ID = int.Parse(devID.Substring(4, 2));                Loop_No = int.Parse(devID.Substring(6, 1));                Repeater_ID = int.Parse(devID.Substring(7, 3));                Device_ID = int.Parse(devID.Substring(10, 1));                Inout_Type = devID.Substring(1, 1);                if (Inout_Type == "I")                {                    Device_Type = 1;                }                else if (Inout_Type == "O")                {                    Device_Type = 2;                }            }        }    }    public partial class Dev_Type_Set    {// 타입 데이터 set 클래스         SortedList<string, Dev_Type> slDev_Type = new SortedList<string, Dev_Type>();        List<Image> LTypeImage = new List<Image>();        public string base_path = "";        public string no_image = "";        public string error_image = "";        public void Add(string sID, Dev_Type sDT)        {            slDev_Type.Add(sID, sDT);            Image devimg = Image.FromFile(Path.Combine(base_path, sDT.image));            LTypeImage.Add(devimg);        }        public Image GetDevImage(string devtype)        {            int IndexKey = slDev_Type.IndexOfKey(devtype);            return LTypeImage[IndexKey];        }        public string GetDevImagePath(string devtype)        {// 회로 타입 이미지 경로 읽는 함수             Dev_Type dt;            string ret = "";            if (slDev_Type.TryGetValue(devtype, out dt))            {                ret = Path.Combine(base_path, dt.image);            }            return ret;        }    }    public partial class Dev_Type    {// 회로 타입 데이터 클래스         public string TypeID = "";        public string image = "";        public string name = "";    }    public partial class XMLReader    {// xml 파일 파서 클래스         DataTable dtDeviceDB;        string XML_BasePath = "";        string Field_BasePath = "";        string Dev_BasePath = "";        public void SetXML_BasePath(string XML_Path, DataTable dt)        {            this.XML_BasePath = Path.Combine(XML_Path, "mapview\\xml");            this.Field_BasePath = Path.Combine(XML_Path, "mapview\\Field");            this.Dev_BasePath = Path.Combine(XML_Path, "mapview\\Symbol");            dtDeviceDB = dt;        }        public Dev_Type_Set GetXMLDevTypeData(string XML_name)        {// xml 파일로 부터 회로 데이터 타입 읽는 함수             Dev_Type_Set DataType_Set = null;            try            {                XmlDocument xmlDoc = new XmlDocument();                string stemp;                stemp = Path.Combine(this.XML_BasePath, XML_name);                xmlDoc.Load(stemp);                XmlNodeList xmlNode_Field = xmlDoc.SelectNodes("/Dev_Setting/Device_Type");                XmlElement XML_E = (XmlElement)xmlNode_Field[0];                XmlNodeList xmlNode_Dev = xmlDoc.SelectNodes("/Dev_Setting/Device_Type/TYPE");                //Debug.WriteLine(xmlNode_Dev.Count.ToString());                int Count_TYPE = xmlNode_Dev.Count;                DataType_Set = new Dev_Type_Set();                DataType_Set.base_path = this.Dev_BasePath;                DataType_Set.no_image = string.Format(XML_E.GetAttribute("NO_IMAGE"));                DataType_Set.error_image = string.Format(XML_E.GetAttribute("ERROR_IMAGE"));                for (int i = 0; i < Count_TYPE; i++)                {                    //DataType_Set.dev_type[i] = new Dev_Type();                    Dev_Type dType = new Dev_Type();                    XmlElement XE = (XmlElement)xmlNode_Dev[i];                    dType.TypeID = XE.GetAttribute("ID");                    dType.image = XE.GetAttribute("IMAGE");                    dType.name = XE.GetAttribute("NAME");                    DataType_Set.Add(dType.TypeID, dType);                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            return DataType_Set;        }        //public string BasePath = "";        public List<XMLField> GetXMLFieldData(string XML_name)        {// xml 파일로 부터 현장도면 설정 읽는 함수             //XMLField[] xField;            List<XMLField> xField = new List<XMLField>();            //Util.UDebugMessage(string.Format("+GetXMLFieldData "), 0, 0);             string sTemp = "";            try            {                //xField = new XMLField();                XmlDocument xmlDoc = new XmlDocument();                xmlDoc.Load(Path.Combine(this.XML_BasePath, XML_name));                XmlNodeList XmlRoot = xmlDoc.SelectNodes("/FIELD_CONF");                XmlNodeList xmlNode_Field = xmlDoc.SelectNodes("/FIELD_CONF/Field");                for (int i = 0; i < xmlNode_Field.Count; i++)                {                    XmlElement XML_E = (XmlElement)xmlNode_Field[i];                    XMLField field = new XMLField();                    field.FieldID = int.Parse(XML_E.GetAttribute("ID"));                    field.ReceiverID = XML_E.GetAttribute("Receiver_ID");                    field.Name = XML_E.GetAttribute("Name");                    field.imagePath = Path.Combine(Field_BasePath, XML_E.GetAttribute("IMAGE"));                    xField.Add(field);                    XmlNodeList xmlNode_Dev = xmlNode_Field[i].SelectNodes("Device");                    // 디바이스 필드를 읽는다.                    field.Count_Dev = xmlNode_Dev.Count;                    for (int j = 0; j < field.Count_Dev; j++)                    {                        XMLDevice device = new XMLDevice();                        XmlElement XE = (XmlElement)xmlNode_Dev[j];                        device.Xposition = int.Parse(XE.GetAttribute("Xposition"));                        device.Yposition = int.Parse(XE.GetAttribute("Yposition"));                        device.DevIconID = string.Format(XE.GetAttribute("DevIconID"));                        sTemp = XE.GetAttribute("ID");                        if (sTemp == "")  // ID가 Null 인 경우..                        {                            device.DevID = "MI000000000";   // ID에 Null에 상당하는 데이터를 입력한다.                            device.ISDBSetting = false;                            device.dev_type = "";                            device.dev_name = "";                            device.positioncode = "";                            device.position = "";                        }                        else                        {                            device.DevID = XE.GetAttribute("ID");                            if (this.dtDeviceDB != null)                            {                                foreach (DataRow dr in this.dtDeviceDB.Rows)                                {                                    if (dr["BOARD_ID"].ToString() == device.Board_ID.ToString() && dr["LOOP_NO"].ToString() == device.Loop_No.ToString()                                        && dr["REPEATER_ID"].ToString() == device.Repeater_ID.ToString() && dr["DEVICE_ID"].ToString() == device.Device_ID.ToString()                                        && dr["INOUT_TYPE"].ToString() == device.Inout_Type.ToString() && dr["COMM_ID"].ToString() == "1")                                    {                                        device.ISDBSetting = true;                                        device.dev_type = dr["DEVICE_TYPE"].ToString();                                        device.dev_name = dr["DEVICE_NAME"].ToString();                                        device.positioncode = dr["POSITION_CODE"].ToString();                                        device.position = dr["POSITION_NAME"].ToString();                                        break;                                    }                                }                            }                        }                        field.LDevice.Add(device);                    }                    // 버튼 설정을 읽어온다.                    XmlNodeList xmlNodeButton = xmlNode_Field[i].SelectNodes("Button");                    for (int j = 0; j < xmlNodeButton.Count; j++)                    {                        XMLButton button = new XMLButton();                        XmlElement XE = (XmlElement)xmlNodeButton[j];                        button.id = XE.GetAttribute("ID");                        button.Xposition = Convert.ToInt32(XE.GetAttribute("Xposition"));                        button.Yposition = Convert.ToInt32(XE.GetAttribute("Yposition"));                        button.ImagePath = Path.Combine(Field_BasePath, XE.GetAttribute("Image"));                        button.name = XE.GetAttribute("NAME");                        button.jumpField = Convert.ToInt32(XE.GetAttribute("JumpField"));                        button.width = Convert.ToInt32(XE.GetAttribute("Width"));                        button.height = Convert.ToInt32(XE.GetAttribute("Height"));                        field.LButton.Add(button);                    }                }            }            //catch {            //  //Debug.WriteLine(ex);            //  //xField = null;            //}            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            return xField;        }    }}
 |