| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Data;
 
- using System.Data.SqlClient;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Text;
 
- namespace DataGateWayProject
 
- {
 
-     class Creating_Setting_File
 
-     {
 
-         string Dir = "";
 
-         string _strFile = "\\SettingFile";
 
-         Form1 F1 = new Form1();
 
-         LogFileCreate LFC = new LogFileCreate();
 
-         public void Create_Setting_Point_File()
 
-         {
 
-             Dir = Environment.CurrentDirectory;
 
-             System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Dir);
 
-             System.IO.FileInfo fi = new System.IO.FileInfo(Dir + _strFile);
 
-             if (di.Exists)
 
-             {
 
-                 My_DB_DML MDD = new My_DB_DML();
 
-                 string ConnInfo = MDD.ConnDBInfo(); // DB접속정보를 담고 있음.
 
-                 DataSet ds = new DataSet();
 
-                 using (SqlConnection conn = new SqlConnection(ConnInfo))
 
-                 {
 
-                     string query = "SELECT * FROM BemsMonitoringPointConfig";
 
-                     SqlCommand cmd = new SqlCommand(query, conn);
 
-                     cmd.CommandType = CommandType.Text;
 
-                     cmd.CommandTimeout = 120;
 
-                     SqlDataAdapter da = new SqlDataAdapter(cmd);
 
-                     try
 
-                     {
 
-                         conn.Open();
 
-                         da.Fill(ds);
 
-                         conn.Close();
 
-                     }
 
-                     catch (Exception ex)
 
-                     {
 
-                         conn.Close();
 
-                     }
 
-                 }
 
-                 try
 
-                 {
 
-                     StreamWriter sw = new StreamWriter(new FileStream("SettingFile.csv", FileMode.Create), Encoding.UTF8);
 
-                     WriteToStream(sw, ds.Tables[0], false, false);
 
-                 }
 
-                 catch(Exception e)
 
-                 {
 
-                     LFC.Log("파일 생성 에러 = " + e);
 
-                 }
 
-                 //Console.ReadKey();
 
-                 //LFC.Log("셋팅 파일(SettingFile.csv)이 존재하지 않습니다. 파일을 자동생성합니다." + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
 
-             }
 
-             //else
 
-             //{
 
-             //    LFC.Log("관제점 셋팅 파일의 폴더가 존재하지 않습니다."+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
 
-             //}
 
-         }
 
-         public static void WriteToStream(TextWriter stream, DataTable table, bool header, bool quoteall)
 
-         {
 
-             int totalcount = table.Rows.Count;
 
-             int literal_count = 0;
 
-             int TagCount = 0;
 
-             //if (header) /
 
-             //{
 
-             //    for (int i = 0; i < table.Columns.Count; i++)
 
-             //    {
 
-             //        WriteItem(stream, table.Columns[i].Caption, quoteall, literal_count);
 
-             //        if (i >= 0 && i < 3)
 
-             //        {
 
-             //            stream.Write('.');
 
-             //        }
 
-             //        else if (i >= 3 && i < table.Columns.Count - 1)
 
-             //        {
 
-             //            stream.Write(',');
 
-             //        }
 
-             //        else
 
-             //        {
 
-             //            stream.Write("\r\n");
 
-             //        }
 
-             //    }
 
-             //}
 
-             foreach (DataRow row in table.Rows)
 
-             {
 
-                
 
-                 string[] Type_Store = new string[3];
 
-                 string tmpSaveMode_Store = "";
 
-                 literal_count = 0;
 
-                 
 
-                 for (int i = 0; i < table.Columns.Count; i++)
 
-                 {                   
 
-                     string s = row[i].ToString();
 
-                     s = s.Trim();
 
-                     literal_count++; // 글자수 카운트
 
-                     
 
-                     //WriteItem(stream, row[i], quoteall, literal_count);
 
-                     if (row[i] == null)
 
-                     {
 
-                         return;
 
-                     }
 
-                     if(literal_count == 7)
 
-                     {
 
-                         tmpSaveMode_Store = s;                      
 
-                         continue;                       
 
-                     }
 
-                     // ****************************값 Type만드는 부분
 
-                     if (literal_count == 5 || literal_count == 6 || literal_count == 9)
 
-                     {
 
-                         switch (literal_count)
 
-                         {
 
-                             case 5: Type_Store[0] = s; break;
 
-                             case 6: Type_Store[1] = s; break;
 
-                             case 9: Type_Store[2] = s; break;
 
-                         }
 
-                         if (!(literal_count == 9))
 
-                         {
 
-                             continue; // 다음으로...
 
-                         }
 
-                         else
 
-                         {
 
-                             if (Type_Store[0] == "False" || Type_Store[0] == "FAlSE" || Type_Store[0] == "0")
 
-                             {
 
-                                 if (Type_Store[1] == "False" || Type_Store[1] == "FAlSE" || Type_Store[1] == "0")
 
-                                 {
 
-                                     if (Type_Store[2] == "False" || Type_Store[2] == "FAlSE" || Type_Store[2] == "0")
 
-                                     {
 
-                                         s = "3";
 
-                                     }
 
-                                     else if (Type_Store[2] == "True")
 
-                                     {
 
-                                         s = "6";
 
-                                     }
 
-                                 }
 
-                                 else if (Type_Store[1] == "True")
 
-                                 {
 
-                                     s = "1";
 
-                                 }
 
-                             }
 
-                             else if (Type_Store[0] == "True")
 
-                             {
 
-                                 if (Type_Store[1] == "False" || Type_Store[1] == "FAlSE" || Type_Store[1] == "0")
 
-                                 {
 
-                                     if (Type_Store[2] == "False" || Type_Store[2] == "FAlSE" || Type_Store[2] == "0")
 
-                                     {
 
-                                         s = "2";
 
-                                     }
 
-                                     else if (Type_Store[2] == "True")
 
-                                     {
 
-                                         s = "5";
 
-                                     }
 
-                                 }
 
-                                 else if (Type_Store[1] == "True")
 
-                                 {
 
-                                     s = "4";
 
-                                 }
 
-                             }
 
-                         }
 
-                         TagCount++;
 
-                         stream.Write(s);   
 
-                         stream.Write(',');
 
-                         stream.Write("Tag" + TagCount);
 
-                         stream.Write(',');                        
 
-                         stream.Write(tmpSaveMode_Store);
 
-                         stream.Flush();
 
-                     }
 
-                     // ****************************값 Type만드는 부분
 
-                     else
 
-                     {                       
 
-                         stream.Write(s);
 
-                         stream.Flush();
 
-                     }                    
 
-                     if (i >= 0 && i < 3)
 
-                     {
 
-                         stream.Write('.');
 
-                     }
 
-                     else if (i >= 3 && i < table.Columns.Count - 1)
 
-                     {
 
-                         stream.Write(',');
 
-                     }
 
-                     else
 
-                     {
 
-                         if(!(totalcount== TagCount))stream.Write("\r\n");
 
-                     }
 
-                 }
 
-                 
 
-             }
 
-             stream.Flush();
 
-             stream.Close();
 
-         }
 
-         public void Create_Point_File()
 
-         {
 
-             Dir = Environment.CurrentDirectory;
 
-             System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Dir);
 
-             System.IO.FileInfo fi = new System.IO.FileInfo(Dir + _strFile);
 
-             if (di.Exists)
 
-             {
 
-                 My_DB_DML MDD = new My_DB_DML();
 
-                 string ConnInfo = MDD.ConnDBInfo(); // DB접속정보를 담고 있음.
 
-                 DataSet ds = new DataSet();
 
-                 using (SqlConnection conn = new SqlConnection(ConnInfo))
 
-                 {
 
-                     string query = "SELECT * FROM BemsMonitoringPointConfig";
 
-                     SqlCommand cmd = new SqlCommand(query, conn);
 
-                     cmd.CommandType = CommandType.Text;
 
-                     cmd.CommandTimeout = 120;
 
-                     SqlDataAdapter da = new SqlDataAdapter(cmd);
 
-                     try
 
-                     {
 
-                         conn.Open();
 
-                         da.Fill(ds);
 
-                         conn.Close();
 
-                     }
 
-                     catch (Exception ex)
 
-                     {
 
-                         conn.Close();
 
-                     }
 
-                 }
 
-                 try
 
-                 {
 
-                     StreamWriter sw = new StreamWriter(new FileStream("TagSetFile.csv", FileMode.Create), Encoding.UTF8);
 
-                     WriteToStream_TagSetFile(sw, ds.Tables[0], false, false);
 
-                 }
 
-                 catch(Exception e)
 
-                 {
 
-                     LFC.Log("파일생성 에러 = " + e);
 
-                 }
 
-                 //Console.ReadKey();
 
-                 //LFC.Log("셋팅 파일(SettingFile.csv)이 존재하지 않습니다. 파일을 자동생성합니다." + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
 
-             }
 
-             //else
 
-             //{
 
-             //    LFC.Log("관제점 셋팅 파일의 폴더가 존재하지 않습니다."+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
 
-             //}
 
-         }
 
-         public static void WriteToStream_TagSetFile(TextWriter stream, DataTable table, bool header, bool quoteall)
 
-         {
 
-             int totalcount = table.Rows.Count;
 
-             int literal_count = 0;
 
-             int TagCount = 0;
 
-        
 
-             foreach (DataRow row in table.Rows)
 
-             {
 
-                 TagCount++;
 
-                 literal_count = 0;
 
-                 for (int i = 0; i < table.Columns.Count; i++)
 
-                 {
 
-                     literal_count++;
 
-                     string s = row[i].ToString();
 
-                     s=s.Trim();
 
-                    
 
-                     if (row[i] == null)
 
-                     {
 
-                         return;
 
-                     }
 
-                     if (literal_count == 8)
 
-                     {
 
-                         stream.Write(TagCount-1);
 
-                         stream.Write(',');
 
-                         stream.Write(s);
 
-                         stream.Flush();
 
-                         continue;
 
-                     }
 
-                 }
 
-                 if (!(totalcount == TagCount))
 
-                     stream.Write("\r\n");                
 
-                 
 
-             }
 
-             stream.Flush();
 
-             stream.Close();
 
-         }        
 
-     }
 
- }
 
 
  |