123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.IO;
- using System.Data;
- using System.Collections;
- namespace IControls_FireManager
- {
- // 파일입출력 관련 함수는 여기 클래스에서 전담한다
- public static class _File
- {
- // 프로그램 경로 (경로추가시 여기에 추가요망)
- public static string ProgramPath = Environment.CurrentDirectory + "\\";
- // 프로그램 환경설정 파일명 (설정파일이 여러개라면 여기에 추가요망)
- public static string ProgramFileName_Config = "Program_Configuration.xml";
- public static string ProgramFileName_DevType= "DevType.xml";
- public static string ProgramFileName_FieldSetting = "FieldSetting.xml";
- // _Receiver.xml 제거 : cyim 2012.8.29 -> 복구 2013.5.27
- public static string ProgramFileName_Receiver = "Receiver.xml";
- // 프로그램 에러로그 파일명
- public static string ProgramFileName_Log_Error = "Log_Error.txt";
-
- ///
- /// Program_Configuration.xml
- ///
- // 프로그램 환경설정 파일 읽기
- public static bool Read_ProgramConfiguration()
- {
- try
- {
- // XML 파일 경로 찾기
- string FilePath = ProgramPath + ProgramFileName_Config;
-
- ///
- /// 프로그램
- ///
-
- _Data.Program_Version = _Xml.Get_Value(new XmlTextReader(FilePath), "Program", "Version");
- //_Data.Program_Version = System.Windows.Forms.Application.ProductVersion;
- ///
- /// 프로젝트
- ///
- _Data.Project_Path = _Xml.Get_Value(new XmlTextReader(FilePath), "Project", "Path");
- _Data.Project_ExcelOpenCheck = _Xml.Get_Value(new XmlTextReader(FilePath), "Project", "ExcelOpenCheck");
- _Data.Project_MapGroupIDTypeNumber = _Xml.Get_Value(new XmlTextReader(FilePath), "Project", "MapGroupIDTypeNumber"); // cyim 2016.04.01 : 6자리 혹은 4자리로 맵아이디와 그룹아이디 지정할수 있도록함
- ///
- /// 데이타베이스 환경 설정
- ///
- // 데이터베이스 아이피
- _Data.DB_IP = _Xml.Get_Value(new XmlTextReader(FilePath), "Database", "IP");
- // 데이터베이스 접근 아이디
- _Data.DB_ID = _Xml.Get_Value(new XmlTextReader(FilePath), "Database", "ID");
- // 데이타베이스 접근 패스워드
- _Data.DB_PassWord = _Xml.Get_Value(new XmlTextReader(FilePath), "Database", "PassWord");
-
-
- ///
- /// Janus
- ///
-
- _Data.Style_PanelVisualStyle = _Style.Get_PanelVisualStyle(_Xml.Get_Value(new XmlTextReader(FilePath), "Janus", "PanelVisualStyle"));
- _Data.Style_VisualStyle = _Style.Get_VisualStyle(_Xml.Get_Value(new XmlTextReader(FilePath), "Janus", "VisualStyle"));
- _Data.Style_Office2007ColorScheme = _Style.Get_Office2007ColorScheme(_Xml.Get_Value(new XmlTextReader(FilePath), "Janus", "Office2007ColorScheme"));
-
-
- return true;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return false;
- }
- }
-
- // 프로그램 환경설정 파일 쓰기
- public static void Write_ProgramConfiguration()
- {
- // XML 파일 경로 찾기
- string FilePath = ProgramPath + ProgramFileName_Config;
- // 시스템 기본값이 저장될 파일 지정
- TextWriter streamWriter = new StreamWriter(FilePath);
- // 스트림 생성
- XmlTextWriter writer = new XmlTextWriter(streamWriter);
- try
- {
- StringBuilder strPacket = new StringBuilder();
-
- // 헤더
- strPacket.Append(_Xml.Set_XMLHeader());
- strPacket.Append(_Xml.Set_XMLComment(_Text.XML_Comment_1th));
-
- // 바디 시작
- strPacket.Append(_Xml.Set_BodyHeader(Xml_Body_Type.Program_Configuration, true));
- // 태그 : Program
- strPacket.Append(_Xml.Set_XMLComment(_Text.XML_Comment_2th));
- strPacket.Append(_Xml.Set_Body("Program", null,
- "Version=" + _Data.Program_Version, true));
- // 태그 : Project
- strPacket.Append(_Xml.Set_XMLComment(_Text.XML_Comment_3th));
- strPacket.Append(_Xml.Set_Body("Project", null,
- "Path=" + _Data.Project_Path +
- ";ExcelOpenCheck=" + _Data.Project_ExcelOpenCheck +
- ";MapGroupIDTypeNumber=" + _Data.Project_MapGroupIDTypeNumber, true)); // cyim 2016.04.01 : 6자리 혹은 4자리로 맵아이디와 그룹아이디 지정할수 있도록함
- // 태그 : Database
- strPacket.Append(_Xml.Set_XMLComment(_Text.XML_Comment_4th));
- strPacket.Append(_Xml.Set_Body("Database", null,
- "IP=" + _Data.DB_IP +
- ";ID=" + _Data.DB_ID +
- ";PassWord=" + _Data.DB_PassWord, true));
-
- // 태그 : Janus
- strPacket.Append(_Xml.Set_XMLComment(_Text.XML_Comment_5th));
- strPacket.Append(_Xml.Set_Body("Janus", null,
- "PanelVisualStyle=" + _Data.Style_PanelVisualStyle.ToString() +
- ";VisualStyle=" + _Data.Style_VisualStyle.ToString() +
- ";Office2007ColorScheme=" + _Data.Style_Office2007ColorScheme.ToString(), true));
-
- // 바디 종료
- strPacket.Append(_Xml.Set_BodyHeader(Xml_Body_Type.Program_Configuration, false));
-
- // 쓰기
- writer.WriteRaw(strPacket.ToString());
- writer.Close();
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- if (writer != null)
- writer.Close();
- }
- }
- // _Receiver.xml 제거 : cyim 2012.8.29 -> 복구 2013.5.27
- ///
- /// Receiver.xml
- ///
- // 파일 쓰기
- public static void Write_Receiver_XML(string ProjectPath)
- {
- // XML 파일 경로 찾기 (주의할점 : ProgramPath 가 아니므로 반드시 \\ 추가)
- string FilePath = ProjectPath + "\\" + _Text.DEFALUT_FOLDER_TEMP + "\\" + ProgramFileName_Receiver;
- // 시스템 기본값이 저장될 파일 지정
- TextWriter streamWriter = new StreamWriter(FilePath);
- // 스트림 생성
- XmlTextWriter writer = new XmlTextWriter(streamWriter);
- try
- {
- StringBuilder strPacket = new StringBuilder();
- // 헤더
- strPacket.Append(_Xml.Set_XMLHeader());
- strPacket.Append(_Xml.Set_XMLComment(_Text.XML_Comment_6th));
- // 바디 시작
- strPacket.Append(_Xml.Set_BodyHeader(Xml_Body_Type.FIRE_Receiver, true));
- // 태그 : Receiver
- strPacket.Append(_Xml.Set_XMLComment(_Text.XML_Comment_7th));
- // 내용
- string TempId = null;
- foreach (string RECEIVER_ID in _Data.LIST_XMLRECEIVER_ID)
- TempId = TempId + RECEIVER_ID + _Text.Blank; // 공백으로 아이디 구분
- if(TempId != null)
- TempId = TempId.TrimEnd();
- strPacket.Append(_Xml.Set_Body("Receiver", null,
- "ID=" + TempId, true));
-
- // 바디 종료
- strPacket.Append(_Xml.Set_BodyHeader(Xml_Body_Type.FIRE_Receiver, false));
- // 쓰기
- writer.WriteRaw(strPacket.ToString());
- writer.Close();
- // LOG
- _Event.DebugView_SendMessage_Write(_Text.FieldSetting_Xml_Save);
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
- // 파일 읽기
- public static bool Read_Receiver_XML(string ProjectPath)
- {
- try
- {
- // XML 파일 경로 찾기
- string FilePath = ProjectPath + "\\" + _Text.DEFALUT_FOLDER_TEMP + "\\" + ProgramFileName_Receiver;
- ///
- /// ID
- ///
- string Temp_ID = _Xml.Get_Value(new XmlTextReader(FilePath), "Receiver", "ID");
- // 파일이 없다!
- if (Temp_ID == null) return false;
-
- string[] Temp_ID_Array = _Convert.String_to_ArrayString(_Text.BlankChar, Temp_ID);
- foreach(string ID in Temp_ID_Array)
- {
- if (_Data.LIST_XMLRECEIVER_ID.Contains(ID) == false && ID.Trim().Length != 0)
- _Data.LIST_XMLRECEIVER_ID.Add(ID);
- }
-
- return true;
- }
- catch
- {
- return false;
- }
- }
- ///
- /// FieldSetting.xml
- ///
- // 저장된 페이지 해쉬 테이블과 리스트를 이용해서 페이지의 순번을 지정하기
- private static void Create_Page_ID_Order(string RECEIVER_ID)
- {
- int PAGE_ID_Order = 0; // 페이지 아이디
-
- // 메인은 무조건 0 이다.
- foreach (string PAGE_ID in ((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).LIST_PAGE_ID)
- {
- if (PAGE_ID == _Data.CREATE_PAGE_ID(RECEIVER_ID,_Text.Main))
- {
- ((_Page)((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).HASH_PAGE[PAGE_ID]).ID = PAGE_ID_Order++.ToString();
- break;
- }
- }
-
- // 메인이 아닌것
- foreach (string PAGE_ID in ((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).LIST_PAGE_ID)
- {
- if (PAGE_ID != _Data.CREATE_PAGE_ID(RECEIVER_ID, _Text.Main))
- {
- ((_Page)((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).HASH_PAGE[PAGE_ID]).ID = PAGE_ID_Order++.ToString();
- }
- }
- }
- // 점프 페이지 이름 -> 아이디
- public static string Create_Page_ID_Order(string RECEIVER_ID, string JumpPageName)
- {
- foreach (string PAGE_ID in ((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).LIST_PAGE_ID)
- {
- if (((_Page)((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).HASH_PAGE[PAGE_ID]).NodeText == JumpPageName)
- return ((_Page)((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).HASH_PAGE[PAGE_ID]).ID;
- }
- return null;
- }
- // 점프 페이지 이름 <- 아이디
- public static string Read_Page_ID_Order(ArrayList Result, string JumpPageID)
- {
- foreach (_FieldSetting FieldSetting in Result)
- {
- if (FieldSetting.ID == JumpPageID)
- return FieldSetting.Name;
- }
- return null;
- }
- // 회로번호 생성
- // MO-01-0-001-1 -> MO010100011 즉 수신기 아이디를 2자리로 변환하여 넣기
- public static string Create_Device_Oper_ID(string PictureBox_Device_Oper_ID, string Receiver_ID)
- {
- if (PictureBox_Device_Oper_ID == null || PictureBox_Device_Oper_ID.Length == 0)
- return null;
- string[] Datas = PictureBox_Device_Oper_ID.Split('-');
- return Datas[0] + _Convert.String_to_Int_TwoType(Receiver_ID) + Datas[1] + Datas[2] + Datas[3] + Datas[4];
- }
- // 회로번호 읽기
- // MO-01-0-001-1 <- MO010100011
- public static string Read_Device_Oper_ID(string XML_Device_Oper_ID)
- {
- if (XML_Device_Oper_ID == null || XML_Device_Oper_ID.Length == 0 || XML_Device_Oper_ID == _Text.Blank)
- return null;
- // 스트링 문자열을 배열로 변환한다 , 단 수신기 아이디는 제외한다
- string result = null;
- result = result + XML_Device_Oper_ID[0].ToString();
- result = result + XML_Device_Oper_ID[1].ToString();
- result = result + "-";
- result = result + XML_Device_Oper_ID[4].ToString();
- result = result + XML_Device_Oper_ID[5].ToString();
- result = result + "-";
- result = result + XML_Device_Oper_ID[6].ToString();
- result = result + "-";
- result = result + XML_Device_Oper_ID[7].ToString();
- result = result + XML_Device_Oper_ID[8].ToString();
- result = result + XML_Device_Oper_ID[9].ToString();
- result = result + "-";
- result = result + XML_Device_Oper_ID[10].ToString();
- return result;
- }
- // 맵디자이너의 내용을 토대로 저장한다
- public static void Write_FieldSetting_XML(string RECEIVER_ID, string ProjectPath)
- {
- // XML 파일 경로 찾기 (주의할점 : ProgramPath 가 아니므로 반드시 \\ 추가)
- string FilePath = ProjectPath + "\\" + ProgramFileName_FieldSetting;
- // 시스템 기본값이 저장될 파일 지정
- TextWriter streamWriter = new StreamWriter(FilePath);
- // 스트림 생성
- XmlTextWriter writer = new XmlTextWriter(streamWriter);
- try
- {
- StringBuilder strPacket = new StringBuilder();
- // 헤더
- strPacket.Append(_Xml.Set_XMLHeader());
-
- // 바디 시작
- strPacket.Append(_Xml.Set_BodyHeader(Xml_Body_Type.FIRE_FieldSetting, true));
- ///
- /// 메인부터 저장
- ///
- // 페이지의 아이디를 지정한다
- Create_Page_ID_Order(RECEIVER_ID);
-
- // 순번에 맞게
- for (int i = 0; i < ((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).LIST_PAGE_ID.Count; i++)
- {
- foreach (string PAGE_ID in ((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).LIST_PAGE_ID)
- {
- if (((_Page)((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).HASH_PAGE[PAGE_ID]).ID == i.ToString())
- {
- _Page Page = ((_Page)((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).HASH_PAGE[PAGE_ID]);
- // 페이지 시작 태그
- strPacket.Append(_Xml.Set_Body_NotEnd("Field", null,
- "Receiver_ID=" + Page.Receiver_ID +
- ";ID=" + Page.ID +
- ";Name=" + Page.NodeText +
- ";IMAGE=" + Page.PictureBoxItem_BackGround.FileName, true));
- // 디바이스 아이콘
- foreach (string ICON_ID in Page.LIST_ICON_ID)
- {
- if (((_PictureBoxItem)Page.HASH_ICON[ICON_ID]).ItemType == Item_Type.Device)
- {
- _PictureBoxItem PictureBoxItem = ((_PictureBoxItem)Page.HASH_ICON[ICON_ID]);
- // 특별히 디바이스 아이콘의 경우 회로번호는 전부 - 를 제거한다. 또한 회로번호의 경우 앞부분에 수신기 아이디를 포함한다(두자리)
- string temp_Device_ID = Create_Device_Oper_ID(PictureBoxItem.Device_Oper_ID, Page.Receiver_ID);
- strPacket.Append(_Xml.Set_Body("Device", null,
- "ID=" + temp_Device_ID +
- ";Xposition=" + PictureBoxItem.Location.X +
- ";Yposition=" + PictureBoxItem.Location.Y +
- ";DevIconID=" + PictureBoxItem.Device_Icon_ID, true));
- }
- }
- // 버튼 아이콘
- foreach (string ICON_ID in Page.LIST_ICON_ID)
- {
- if (((_PictureBoxItem)Page.HASH_ICON[ICON_ID]).ItemType == Item_Type.Button)
- {
- _PictureBoxItem PictureBoxItem = ((_PictureBoxItem)Page.HASH_ICON[ICON_ID]);
- // 버튼 아이콘의 점프 페이지는 이름이 아닌 아이디로 대체한다 (HASH_PAGE 접근시 키는 수신기ID-페이지명)
- string temp_JumpField_ID =null;
- if (PictureBoxItem.Button_JumpPageName != null
- && PictureBoxItem.Button_JumpPageName.Length != 0
- && PictureBoxItem.Button_JumpPageName != _Text.None) // None 은 결국 null 로 대체된다
- {
- // 점프페이지 이름을 토대로 페이지 아이디를 추출해야한다
- temp_JumpField_ID = Create_Page_ID_Order(RECEIVER_ID,PictureBoxItem.Button_JumpPageName);
-
- //temp_JumpField_ID = ((_Page)((_RECEIVER)_Data.HASH_RECEIVER[RECEIVER_ID]).HASH_PAGE[_Data.CREATE_PAGE_ID(RECEIVER_ID, PictureBoxItem.Button_JumpPageName)]).ID;
- }
- // 점프필드에는 널값이 들어가면 수신기UI 가 에러처리됨 - 2013.6.18
- temp_JumpField_ID = _Data.Get_Verify_ID(temp_JumpField_ID);
- strPacket.Append(_Xml.Set_Body("Button", null,
- "ID=" + "B" + PictureBoxItem.Name + // 특별히 버튼 아이콘의 경우 "B" 를 추가한다
- ";Xposition=" + PictureBoxItem.Location.X +
- ";Yposition=" + PictureBoxItem.Location.Y +
- ";Image=" + PictureBoxItem.FileName +
- ";NAME=" + _Text.Null +
- ";JumpField=" + temp_JumpField_ID +
- ";Width=" + PictureBoxItem.Image.Size.Width +
- ";Height=" + PictureBoxItem.Image.Size.Height, true));
- }
- }
- // 페이지 종료 태그
- strPacket.Append("</Field>\r\n");
- break;
- }
- }
- }
-
- // 바디 종료
- strPacket.Append(_Xml.Set_BodyHeader(Xml_Body_Type.FIRE_FieldSetting, false));
- // 쓰기
- writer.WriteRaw(strPacket.ToString());
- writer.Close();
- // LOG
- _Event.DebugView_SendMessage_Write(_Text.FieldSetting_Xml_Save);
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
- // 파일 읽기
- public static ArrayList Read_FieldSetting_XML(string ProjectPath)
- {
- try
- {
- // XML 파일 경로 찾기
- string FilePath = ProjectPath + "\\" + ProgramFileName_FieldSetting;
- // 결과 리스트
- ArrayList Result = new ArrayList();
- // XML 파일 읽기
- XmlDocument xmldoc = new XmlDocument();
-
- xmldoc.Load(FilePath);
- XmlElement Page = xmldoc.DocumentElement;
- XmlNodeList Fields = Page.ChildNodes;
- foreach (XmlNode Field in Fields)
- {
- _FieldSetting FieldSetting = new _FieldSetting();
- FieldSetting.Receiver_ID = Field.Attributes["Receiver_ID"].Value.ToString();
- FieldSetting.ID = Field.Attributes["ID"].Value.ToString();
- FieldSetting.Name = Field.Attributes["Name"].Value.ToString();
- FieldSetting.IMAGE = Field.Attributes["IMAGE"].Value.ToString();
- XmlNodeList nodes = Field.ChildNodes;
- foreach (XmlNode node in nodes)
- {
- if (node.Name == "Device")
- {
- _FieldSetting_Device FieldSetting_Device = new _FieldSetting_Device();
- FieldSetting_Device.ID = node.Attributes["ID"].Value.ToString();
- FieldSetting_Device.Xposition = node.Attributes["Xposition"].Value.ToString();
- FieldSetting_Device.Yposition = node.Attributes["Yposition"].Value.ToString();
- FieldSetting_Device.DevIconID = node.Attributes["DevIconID"].Value.ToString();
- FieldSetting.Device.Add(FieldSetting_Device);
- }
- else if (node.Name == "Button")
- {
- _FieldSetting_Button FieldSetting_Button = new _FieldSetting_Button();
- FieldSetting_Button.ID = node.Attributes["ID"].Value.ToString();
- FieldSetting_Button.Xposition = node.Attributes["Xposition"].Value.ToString();
- FieldSetting_Button.Yposition = node.Attributes["Yposition"].Value.ToString();
- FieldSetting_Button.Image = node.Attributes["Image"].Value.ToString();
- FieldSetting_Button.NAME = node.Attributes["NAME"].Value.ToString();
- FieldSetting_Button.JumpField = node.Attributes["JumpField"].Value.ToString();
- FieldSetting_Button.Width = node.Attributes["Width"].Value.ToString();
- FieldSetting_Button.Height = node.Attributes["Height"].Value.ToString();
- FieldSetting.Button.Add(FieldSetting_Button);
- }
- }
- Result.Add(FieldSetting);
- }
- return Result;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return null;
- }
- }
- ///
- /// DevType.XML
- ///
- // 아이콘 파일명을 통해서 조회하기
- public static _DevTypeXML Read_DevType_By_FileName(string filename)
- {
- foreach (string DevTypeID in _Data.LIST_XMLDEVTYPE_ID)
- {
- if (((_DevTypeXML)_Data.HASH_XMLDEVTYPE[DevTypeID]).FILENAME == filename)
- return ((_DevTypeXML)_Data.HASH_XMLDEVTYPE[DevTypeID]);
- }
- return null;
- }
- // 아이콘 아이디를 통해서 조회하기
- public static _DevTypeXML Read_DevType_FileName_by_IconID(string IconID)
- {
- foreach (string XMLDEVTYPE_ID in _Data.LIST_XMLDEVTYPE_ID)
- {
- if (((_DevTypeXML)_Data.HASH_XMLDEVTYPE[XMLDEVTYPE_ID]).ID == IconID)
- return ((_DevTypeXML)_Data.HASH_XMLDEVTYPE[XMLDEVTYPE_ID]);
- }
- return null;
- }
- // 파일 읽기
- public static bool Read_DevType_XML(string ProjectPath)
- {
- try
- {
- // XML 파일 경로 찾기
- string FilePath = ProjectPath + "\\" + ProgramFileName_DevType;
- // 일반 텍스트로 읽고
- string xml = File.ReadAllText(FilePath);
- System.IO.StringReader reader = new StringReader(xml);
- // 데이타셋
- DataSet ds = new DataSet();
- // XML 파일을 인코딩
- ds.ReadXml(reader, XmlReadMode.Auto);
- // 데이타셋의 테이블 두번째 바디부터 행별로 가져온다
- DataRowCollection rows = ds.Tables[1].Rows;
- // 클래스를 각각 해쉬에 추가
- foreach (DataRow row in rows)
- {
- _DevTypeXML DevType = new _DevTypeXML();
- DevType.ID = row["ID"].ToString();
- DevType.FILENAME = row["IMAGE"].ToString();
- DevType.NAME = row["NAME"].ToString();
-
- // 해쉬 추가
- if (_Hash.Add(_Data.HASH_XMLDEVTYPE, DevType.ID, DevType) == true)
- {
- _Data.LIST_XMLDEVTYPE_ID.Add(DevType.ID);
- }
- }
- return true;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return false;
- }
- }
- ///
- /// 프로젝트 폴더 생성
- ///
- public static void Create_ProjectFolder(string ProjectPath, string ProjectName)
- {
- // 현재 프로젝트 폴더를 생성한다
- // 예시)
- // 용인성복
- // - Temp
- // 타겟 경로
- string TargetPath_Project = ProjectPath + "\\" + ProjectName;
- string TargetPath_Temp = ProjectPath + "\\" + ProjectName + "\\" + _Text.DEFALUT_FOLDER_TEMP;
- // 폴더 생성
- Create_Folder(ProjectPath, ProjectName);
- Create_Folder(TargetPath_Project, _Text.DEFALUT_FOLDER_TEMP);
- // 원본 경로
- string SourcePath_Temp = ProgramPath + "\\" + _Text.DEFAULT_PROJECT_NAME + "\\" + _Text.DEFALUT_FOLDER_TEMP;
-
- // 폴더 복사
- Copy_Folder(SourcePath_Temp, TargetPath_Temp);
- }
- ///
- /// 수신기 폴더 생성
- ///
- public static void Create_ReceiverFolder(string ProjectPath, string ProjectName, string RECEIVER_ID)
- {
- try
- {
- // 현재 수신기 아이디를 토대로 폴더를 생성한다
- // 예시)
- // 용인성복
- // - Temp
- // - Receiver1
- // - DB
- // - mapview
- // - field
- // - symbol
- // - xml
- // 수신기 폴더명
- string ReiceiverFolderName = _Text.DEFAULT_FOLDER_RECEIVER_PREFIX + RECEIVER_ID;
- // 타겟 경로
- string TargetPath_Project = ProjectPath + "\\" + ProjectName;
- string TargetPath_Receiver = ProjectPath + "\\" + ProjectName + "\\" + ReiceiverFolderName;
- string TargetPath_DB = ProjectPath + "\\" + ProjectName + "\\" + ReiceiverFolderName + "\\" + _Text.DEFAULT_FOLDER_DB;
- string TargetPath_Mapview = ProjectPath + "\\" + ProjectName + "\\" + ReiceiverFolderName + "\\" + _Text.DEFAULT_FOLDER_MAPVIEW;
- // 폴더 생성
- Create_Folder(TargetPath_Project, ReiceiverFolderName);
- Create_Folder(TargetPath_Receiver, _Text.DEFAULT_FOLDER_DB);
- Create_Folder(TargetPath_Receiver, _Text.DEFAULT_FOLDER_MAPVIEW);
- Create_Folder(TargetPath_Mapview, _Text.DEFAULT_FOLDER_FIELD);
- Create_Folder(TargetPath_Mapview, _Text.DEFAULT_FOLDER_SYMBOL);
- Create_Folder(TargetPath_Mapview, _Text.DEFAULT_FOLDER_XML);
- // 원본 경로
- string SourcePath_Receiver = ProgramPath + "\\" + _Text.DEFAULT_PROJECT_NAME + "\\" + _Text.DEFAULT_FOLDER_RECEIVER_1;
- string SourcePath_DB = ProgramPath + "\\" + _Text.DEFAULT_PROJECT_NAME + "\\" + _Text.DEFAULT_FOLDER_RECEIVER_1 + "\\" + _Text.DEFAULT_FOLDER_DB;
- string SourcePath_Mapview = ProgramPath + "\\" + _Text.DEFAULT_PROJECT_NAME + "\\" + _Text.DEFAULT_FOLDER_RECEIVER_1 + "\\" + _Text.DEFAULT_FOLDER_MAPVIEW;
- // 폴더 복사
- Copy_Folder(SourcePath_Receiver, TargetPath_Receiver);
- Copy_Folder(SourcePath_DB, TargetPath_DB);
- Copy_Folder(SourcePath_Mapview, TargetPath_Mapview);
- Copy_Folder(SourcePath_Mapview + "\\" + _Text.DEFAULT_FOLDER_FIELD, TargetPath_Mapview + "\\" + _Text.DEFAULT_FOLDER_FIELD);
- Copy_Folder(SourcePath_Mapview + "\\" + _Text.DEFAULT_FOLDER_SYMBOL, TargetPath_Mapview + "\\" + _Text.DEFAULT_FOLDER_SYMBOL);
- Copy_Folder(SourcePath_Mapview + "\\" + _Text.DEFAULT_FOLDER_XML, TargetPath_Mapview + "\\" + _Text.DEFAULT_FOLDER_XML);
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
- ///
- /// 폴더
- ///
- // 폴더 생성
- public static bool Create_Folder(string path, string foldername)
- {
- try
- {
- // 폴더 만들기
- if (!System.IO.Directory.Exists(path + "\\" + foldername))
- {
- System.IO.Directory.CreateDirectory(path + "\\" + foldername);
- }
- return true;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return false;
- }
- }
- // 폴더 삭제
- public static bool Delete_Folder(string path, string foldername)
- {
- try
- {
- System.IO.Directory.Delete(path + "\\" + foldername, true);
-
- return true;
- }
- catch //(Exception e)
- {
- // LOG
- //_Event.DebugView_SendMessage_Write(e.ToString());
- return false;
- }
- }
- // 폴더명 가져오기
- public static string Get_Folder(string path)
- {
- try
- {
- string result = null;
- string [] Directories = null;
- Directories = System.IO.Directory.GetDirectories(path);
- foreach(string Directorie in Directories)
- {
- result = result + Directorie.Replace(path,_Text.Null) + _Text.SemiColon;
- }
- if(result!=null)
- result = result.TrimEnd(_Convert.Split_Key);
- return result;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return null;
- }
- }
- // 폴더명으로 부터 폴더 리스트 가져오기
- public static string Get_FolderNameList(string path)
- {
- try
- {
- string result = null;
- string[] Files = null;
- Files = System.IO.Directory.GetDirectories(path);
- foreach (string File in Files)
- {
- result = result + File.Replace(path + "\\", _Text.Null) + _Text.SemiColon;
- }
- if (result != null)
- result = result.TrimEnd(_Convert.Split_Key);
- return result;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return null;
- }
- }
- // 폴더명으로 부터 파일 이름 리스트 가져오기
- public static string Get_FileNameList(string path)
- {
- try
- {
- string result = null;
- string[] Files = null;
- Files = System.IO.Directory.GetFiles(path);
- foreach (string File in Files)
- {
- result = result + File.Replace(path + "\\", _Text.Null) + _Text.SemiColon;
- }
- if (result != null)
- result = result.TrimEnd(_Convert.Split_Key);
- return result;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return null;
- }
- }
- // 폴더 복사
- public static void Copy_Folder(string sourcePath, string targetPath)
- {
- // 소스 폴더 -> DB폴더의 파일을 모두 가져옴
- string[] files = System.IO.Directory.GetFiles(sourcePath);
- // 타겟 폴더 -> DB폴더로 파일을 하나씩 복사
- foreach (string file in files)
- {
- string fileName = System.IO.Path.GetFileName(file);
- string destfile = System.IO.Path.Combine(targetPath, fileName);
- // 단 기존의 파일이 없다면 복사한다
- if (!File.Exists(destfile))
- System.IO.File.Copy(file, destfile, true);
- }
- }
- ///
- /// 파일 정보
- ///
-
- public static FileInfo Read_FileInfo(string path)
- {
- try
- {
- FileInfo Info = new FileInfo(path);
- return Info;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return null;
- }
- }
- ///
- /// 에러로그
- ///
- // 프로그램 에러로그 파일 쓰기
- public static void Write_Log(string txt)
- {
- try
- {
- string path = ProgramPath + ProgramFileName_Log_Error;
- if (!File.Exists(path))
- {
- // Create a file to write to.
- string createText = txt + "\r\n";// Environment.NewLine;
- File.WriteAllText(path, createText);
- }
- else
- {
- // This text is always added, making the file longer over time
- // if it is not deleted.
- string appendText = txt + "\r\n";
- File.AppendAllText(path, appendText);
- }
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
- // 프로그램 에러로그 파일 삭제
- public static void Delete_Log()
- {
- try
- {
- string path = ProgramPath + ProgramFileName_Log_Error;
- if (File.Exists(path))
- {
- File.Delete(path);
- }
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
- }
- }
|