123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.IO;
- namespace DataGateWayProject
- {
- public partial class SettingForm : Form
- {
- public SettingForm()
- {
- InitializeComponent();
- }
- private void SettingFormSave_Click(object sender, EventArgs e)
- {
- Readini Ri = new Readini();
- SaveData();
- MessageBox.Show("저장되었습니다");
- }
- public void SaveData()
- {
- Readini Ri = new Readini();
- Ri.SetIniValue("USER", "UserIP", TbIP.Text);
- Ri.SetIniValue("USER", "UserPort", TbPort.Text);
- Ri.SetIniValue("USER", "UserDB", TbName.Text);
- Ri.SetIniValue("USER", "UserID", TbId.Text);
- Ri.SetIniValue("USER", "UserPW", TbPW.Text);
- Ri.SetIniValue("ICOS", "DGW_IP", DGW_IP.Text);
- Ri.SetIniValue("ICOS", "IP1", IP1.Text);
- Ri.SetIniValue("ICOS", "Port1", PORT1.Text);
- Ri.SetIniValue("ICOS", "Ip2", IP2.Text);
- Ri.SetIniValue("ICOS", "Port2", PORT2.Text);
- Ri.SetIniValue("HeatAndCool", "CoolDayFromgs", CoolDayFrom.Text);
- Ri.SetIniValue("HeatAndCool", "CoolDayTogs", CoolDayTo.Text);
- Ri.SetIniValue("HeatAndCool", "HeatDayFromgs", HeatDayFrom.Text);
- Ri.SetIniValue("HeatAndCool", "HeatDayTogs", HeatDayTo.Text);
- Ri.SetIniValue("PeakInfo", "SiteId", SiteId_txt.Text);
-
- //Ri.SetIniValue("ControlTable", "Table1", Control_Table1.Text);
- //Ri.SetIniValue("ControlTable", "Table2", Control_Table2.Text);
- }
- private void SettingForm_Load(object sender, EventArgs e)
- {
- Readini Ri = new Readini();
- Ri.ReadData();
- TbIP.Text = Ri.UserIP;
- TbPort.Text = Ri.UserPort;
- TbName.Text = Ri.UserDB;
- TbId.Text = Ri.UserID;
- TbPW.Text = Ri.UserPW;
- DGW_IP.Text = Ri.DGW_IP;
- IP1.Text = Ri.IP1;
- IP2.Text = Ri.Ip2;
- PORT1.Text = Ri.Port1;
- PORT2.Text = Ri.Port2;
- CoolDayFrom.Text = Ri.CoolDayFromgs;
- CoolDayTo.Text = Ri.CoolDayTogs;
- HeatDayFrom.Text = Ri.HeatDayFromgs;
- HeatDayTo.Text = Ri.HeatDayTogs;
- SiteId_txt.Text = Ri.SiteId;
- //Control_Table1.Text = Ri.Table1;
- //Control_Table2.Text = Ri.Table2;
- }
- private void SettingFormExit_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void Control_Table1_TextChanged(object sender, EventArgs e)
- {
- }
- }
- class Readini
- {
- //SettingForm SF = new SettingForm();
- public string UserIP { get; set; }
- public string UserPort { get; set; }
- public string UserDB { get; set; }
- public string UserID { get; set; }
- public string UserPW { get; set; }
- public string DGW_IP { get; set; }
- public string IP1 { get; set; }
- public string Port1 { get; set; }
- public string Ip2 { get; set; }
- public string Port2 { get; set; }
- //public string Table1 { get; set; }
- //public string Table2 { get; set; }
- public string MaxPeakValue { get; set; }
- public string MinPeakValue { get; set; }
- public string todayMaxPeakValue { get; set; }
- public string todayMinPeakValue { get; set; }
- public string SiteId { get; set; }
- public string CoolDayFromgs { get; set; }
- public string CoolDayTogs { get; set; }
- public string HeatDayFromgs { get; set; }
- public string HeatDayTogs { get; set; }
- public string TempPoint { get; set; }
- public string HumidityPoint { get; set; }
- private string filePath;
- [DllImport("kernel32.dll")]
- private static extern long WritePrivateProfileString(String section, String key, String val, String filePath);
- [DllImport("kernel32.dll")]
- private static extern int GetPrivateProfileString(String section, String key, String def, StringBuilder retVal, int size, String filePath);
- public string ReadIniFile(string section, string key, string path)
- {
- StringBuilder sb = new StringBuilder(255);
- GetPrivateProfileString(section, key, "", sb, sb.Capacity, path);
- return sb.ToString();
- }
- public void ReadData()
- {
- FileInfo exefileinfo = new FileInfo(Application.ExecutablePath);
- //string path = exefileinfo.Directory.FullName.ToString();
- string fileName = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "Login.ini");
- //string filePath = path + fileName;
- filePath = fileName;
- UserIP = ReadIniFile("USER", "UserIP", filePath);
- UserPort = ReadIniFile("USER", "UserPort", filePath);
- UserDB = ReadIniFile("USER", "UserDB", filePath);
- UserID = ReadIniFile("USER", "UserID", filePath);
- UserPW = ReadIniFile("USER", "UserPW", filePath);
- DGW_IP = ReadIniFile("ICOS", "DGW_IP", filePath);
- IP1 = ReadIniFile("ICOS", "IP1", filePath);
- Port1 = ReadIniFile("ICOS", "Port1", filePath);
- Ip2 = ReadIniFile("ICOS", "Ip2", filePath);
- Port2 = ReadIniFile("ICOS", "Port2", filePath);
- MaxPeakValue = ReadIniFile("PeakInfo", "MaxPeakValue", filePath);
- MinPeakValue = ReadIniFile("PeakInfo", "MinPeakValue", filePath);
- todayMaxPeakValue = ReadIniFile("PeakInfo", "todayMaxPeakValue", filePath);
- todayMinPeakValue = ReadIniFile("PeakInfo", "todayMinPeakValue", filePath);
- SiteId = ReadIniFile("PeakInfo", "SiteId", filePath);
- CoolDayFromgs = ReadIniFile("HeatAndCool", "CoolDayFromgs", filePath);
- CoolDayTogs = ReadIniFile("HeatAndCool", "CoolDayTogs", filePath);
- HeatDayFromgs = ReadIniFile("HeatAndCool", "HeatDayFromgs", filePath);
- HeatDayTogs = ReadIniFile("HeatAndCool", "HeatDayTogs", filePath);
-
- HumidityPoint = ReadIniFile("HumidityTempPoint", "HumidityPoint", filePath);
- TempPoint = ReadIniFile("HumidityTempPoint", "TempPoint", filePath);
- }
- public void SetIniValue(String Section, String Key, String Value)
- {
- FileInfo exefileinfo = new FileInfo(Application.ExecutablePath);
- //string path = exefileinfo.Directory.FullName.ToString();
- string fileName = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "Login.ini");
- //string filePath = path + fileName;
- string filePath = fileName;
- //SettingForm ini = new SettingForm(filePath);
- WritePrivateProfileString(Section, Key, Value, filePath);
- }
- }
- }
|