70825b624a9704990a20400a8c3ca6c9fe38e887.svn-base 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using System.IO;
  11. namespace BEMSDataGateway
  12. {
  13. public partial class SettingForm : Form
  14. {
  15. public SettingForm()
  16. {
  17. InitializeComponent();
  18. }
  19. private void SettingFormSave_Click(object sender, EventArgs e)
  20. {
  21. Readini Ri = new Readini();
  22. SaveData();
  23. MessageBox.Show("저장되었습니다");
  24. }
  25. public void SaveData()
  26. {
  27. Readini Ri = new Readini();
  28. Ri.SetIniValue("USER", "UserIP", TbIP.Text);
  29. Ri.SetIniValue("USER", "UserPort", TbPort.Text);
  30. Ri.SetIniValue("USER", "UserDB", TbName.Text);
  31. Ri.SetIniValue("USER", "UserID", TbId.Text);
  32. Ri.SetIniValue("USER", "UserPW", TbPW.Text);
  33. Ri.SetIniValue("ICOS", "DGW_IP", DGW_IP.Text);
  34. Ri.SetIniValue("ICOS", "IP1", IP1.Text);
  35. Ri.SetIniValue("ICOS", "Port1", PORT1.Text);
  36. Ri.SetIniValue("ICOS", "Ip2", IP2.Text);
  37. Ri.SetIniValue("ICOS", "Port2", PORT2.Text);
  38. Ri.SetIniValue("HeatAndCool", "CoolDayFromgs", CoolDayFrom.Text);
  39. Ri.SetIniValue("HeatAndCool", "CoolDayTogs", CoolDayTo.Text);
  40. Ri.SetIniValue("HeatAndCool", "HeatDayFromgs", HeatDayFrom.Text);
  41. Ri.SetIniValue("HeatAndCool", "HeatDayTogs", HeatDayTo.Text);
  42. Ri.SetIniValue("PeakInfo", "SiteId", SiteId_txt.Text);
  43. //Ri.SetIniValue("ControlTable", "Table1", Control_Table1.Text);
  44. //Ri.SetIniValue("ControlTable", "Table2", Control_Table2.Text);
  45. }
  46. private void SettingForm_Load(object sender, EventArgs e)
  47. {
  48. Readini Ri = new Readini();
  49. Ri.ReadData();
  50. TbIP.Text = Ri.UserIP;
  51. TbPort.Text = Ri.UserPort;
  52. TbName.Text = Ri.UserDB;
  53. TbId.Text = Ri.UserID;
  54. TbPW.Text = Ri.UserPW;
  55. DGW_IP.Text = Ri.DGW_IP;
  56. IP1.Text = Ri.IP1;
  57. IP2.Text = Ri.Ip2;
  58. PORT1.Text = Ri.Port1;
  59. PORT2.Text = Ri.Port2;
  60. CoolDayFrom.Text = Ri.CoolDayFromgs;
  61. CoolDayTo.Text = Ri.CoolDayTogs;
  62. HeatDayFrom.Text = Ri.HeatDayFromgs;
  63. HeatDayTo.Text = Ri.HeatDayTogs;
  64. SiteId_txt.Text = Ri.SiteId;
  65. //Control_Table1.Text = Ri.Table1;
  66. //Control_Table2.Text = Ri.Table2;
  67. }
  68. private void SettingFormExit_Click(object sender, EventArgs e)
  69. {
  70. Close();
  71. }
  72. }
  73. class Readini
  74. {
  75. //SettingForm SF = new SettingForm();
  76. public string UserIP { get; set; }
  77. public string UserPort { get; set; }
  78. public string UserDB { get; set; }
  79. public string UserID { get; set; }
  80. public string UserPW { get; set; }
  81. public string DGW_IP { get; set; }
  82. public string IP1 { get; set; }
  83. public string Port1 { get; set; }
  84. public string Ip2 { get; set; }
  85. public string Port2 { get; set; }
  86. //public string Table1 { get; set; }
  87. //public string Table2 { get; set; }
  88. public string MaxPeakValue { get; set; }
  89. public string MinPeakValue { get; set; }
  90. public string todayMaxPeakValue { get; set; }
  91. public string todayMinPeakValue { get; set; }
  92. public string SiteId { get; set; }
  93. public string CoolDayFromgs { get; set; }
  94. public string CoolDayTogs { get; set; }
  95. public string HeatDayFromgs { get; set; }
  96. public string HeatDayTogs { get; set; }
  97. private string filePath;
  98. [DllImport("kernel32.dll")]
  99. private static extern long WritePrivateProfileString(String section, String key, String val, String filePath);
  100. [DllImport("kernel32.dll")]
  101. private static extern int GetPrivateProfileString(String section, String key, String def, StringBuilder retVal, int size, String filePath);
  102. public string ReadIniFile(string section, string key, string path)
  103. {
  104. StringBuilder sb = new StringBuilder(255);
  105. GetPrivateProfileString(section, key, "", sb, sb.Capacity, path);
  106. return sb.ToString();
  107. }
  108. public void ReadData()
  109. {
  110. FileInfo exefileinfo = new FileInfo(Application.ExecutablePath);
  111. //string path = exefileinfo.Directory.FullName.ToString();
  112. string fileName = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "Login.ini");
  113. //string filePath = path + fileName;
  114. filePath = fileName;
  115. UserIP = ReadIniFile("USER", "UserIP", filePath);
  116. UserPort = ReadIniFile("USER", "UserPort", filePath);
  117. UserDB = ReadIniFile("USER", "UserDB", filePath);
  118. UserID = ReadIniFile("USER", "UserID", filePath);
  119. UserPW = ReadIniFile("USER", "UserPW", filePath);
  120. DGW_IP = ReadIniFile("ICOS", "DGW_IP", filePath);
  121. IP1 = ReadIniFile("ICOS", "IP1", filePath);
  122. Port1 = ReadIniFile("ICOS", "Port1", filePath);
  123. Ip2 = ReadIniFile("ICOS", "Ip2", filePath);
  124. Port2 = ReadIniFile("ICOS", "Port2", filePath);
  125. MaxPeakValue = ReadIniFile("PeakInfo", "MaxPeakValue", filePath);
  126. MinPeakValue = ReadIniFile("PeakInfo", "MinPeakValue", filePath);
  127. todayMaxPeakValue = ReadIniFile("PeakInfo", "todayMaxPeakValue", filePath);
  128. todayMinPeakValue = ReadIniFile("PeakInfo", "todayMinPeakValue", filePath);
  129. SiteId = ReadIniFile("PeakInfo", "SiteId", filePath);
  130. CoolDayFromgs = ReadIniFile("HeatAndCool", "CoolDayFromgs", filePath);
  131. CoolDayTogs = ReadIniFile("HeatAndCool", "CoolDayTogs", filePath);
  132. HeatDayFromgs = ReadIniFile("HeatAndCool", "HeatDayFromgs", filePath);
  133. HeatDayTogs = ReadIniFile("HeatAndCool", "HeatDayTogs", filePath);
  134. //Table1 = ReadIniFile("ControlTable", "Table1", filePath);
  135. //Table2 = ReadIniFile("ControlTable", "Table2", filePath);
  136. }
  137. public void SetIniValue(String Section, String Key, String Value)
  138. {
  139. FileInfo exefileinfo = new FileInfo(Application.ExecutablePath);
  140. //string path = exefileinfo.Directory.FullName.ToString();
  141. string fileName = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "Login.ini");
  142. //string filePath = path + fileName;
  143. string filePath = fileName;
  144. //SettingForm ini = new SettingForm(filePath);
  145. WritePrivateProfileString(Section, Key, Value, filePath);
  146. }
  147. }
  148. }