Beispiel #1
0
        private void WriteINI()
        {
            //Server 1
            _servername = txtServerName1.Text;
            _username   = txtUserName1.Text;
            _password   = txtPassword1.Text;
            _database   = cbxDatabaseName1.SelectedItem.ToString();
            bool Wserver   = IniFileHelper.WriteValue(Database1, ServerName1, new Encoding().Encrypt(_servername), Path.GetFullPath(fileconfig));
            bool Wusername = IniFileHelper.WriteValue(Database1, UserName1, new Encoding().Encrypt(_username), Path.GetFullPath(fileconfig));
            bool Wpass     = IniFileHelper.WriteValue(Database1, Password1, new Encoding().Encrypt(_password), Path.GetFullPath(fileconfig));
            bool Wdatabase = IniFileHelper.WriteValue(Database1, DatabaseName1, new Encoding().Encrypt(_database), Path.GetFullPath(fileconfig));

            //Server FTP
            _serverFTP = txtServerFTP.Text;
            _userFTP   = txtUserFTP.Text;
            _passFTP   = txtPassFTP.Text;
            _pathFTP   = txtPathFTP.Text;
            bool WserverFTP = IniFileHelper.WriteValue(FTP, ServerFTP, new Encoding().Encrypt(_serverFTP), Path.GetFullPath(fileconfig));
            bool WuserFTP   = IniFileHelper.WriteValue(FTP, UserFTP, new Encoding().Encrypt(_userFTP), Path.GetFullPath(fileconfig));
            bool WpassFTP   = IniFileHelper.WriteValue(FTP, PassFTP, new Encoding().Encrypt(_passFTP), Path.GetFullPath(fileconfig));
            bool WpathFTP   = IniFileHelper.WriteValue(FTP, PathFTP, new Encoding().Encrypt(_pathFTP), Path.GetFullPath(fileconfig));

            MessageBox.Show("บันทึกสำเร็จ");
            this.Close();
        }
Beispiel #2
0
        private void DefaultSettings()
        {
            string filePath = Environment.CurrentDirectory + @"\set.dat";

            if (!File.Exists(filePath))
            {
                File.Create(filePath);
            }

            IniFileHelper.WriteValue("Timer", "Enable", "false", filePath);
            IniFileHelper.WriteValue("Timer", "Format", "seconds", filePath);
            IniFileHelper.WriteValue("Timer", "Value", "3600", filePath);

            IniFileHelper.WriteValue("Main", "ErrorCount", "10", filePath);
            IniFileHelper.WriteValue("Main", "Regex", @"fa\S+|suc\S+|\<\S+.+\>|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\'.+'", filePath);
            IniFileHelper.WriteValue("Main", "Success", "succeeded", filePath);
            IniFileHelper.WriteValue("Main", "Failed", "Failed", filePath);
            IniFileHelper.WriteValue("Main", "EventLogs", "Application", filePath);
            IniFileHelper.WriteValue("Main", "EventSource", "MSSQLSERVER", filePath);
            IniFileHelper.WriteValue("Main", "EventCategory", "Logon", filePath);


            IniFileHelper.WriteValue("Firewall", "Name", "Block", filePath);
            IniFileHelper.WriteValue("Firewall", "Protocol", "tcp", filePath);
            IniFileHelper.WriteValue("Firewall", "Profile", "private", filePath);
            IniFileHelper.WriteValue("Firewall", "LocalPort", "1433", filePath);
            IniFileHelper.WriteValue("Firewall", "RemotePort", "any", filePath);
            IniFileHelper.WriteValue("Firewall", "Action", "block", filePath);
            IniFileHelper.WriteValue("Firewall", "Dir", "in", filePath);
        }
Beispiel #3
0
        private void bSaveConfig_Click(object sender, EventArgs e)
        {
            string filePath = Environment.CurrentDirectory + @"\set.dat";

            if (!File.Exists(filePath))
            {
                File.Create(filePath);
            }

            IniFileHelper.WriteValue("Timer", "Enable", checkBox1.Checked.ToString(), filePath);
            IniFileHelper.WriteValue("Timer", "Format", (string)comboBox1.SelectedItem, filePath);
            IniFileHelper.WriteValue("Timer", "Value", textBox7.Text, filePath);

            IniFileHelper.WriteValue("Main", "ErrorCount", numericUpDown1.Value.ToString(), filePath);
            IniFileHelper.WriteValue("Main", "Regex", textBox1.Text, filePath);
            IniFileHelper.WriteValue("Main", "Success", textBox5.Text, filePath);
            IniFileHelper.WriteValue("Main", "Failed", textBox6.Text, filePath);
            IniFileHelper.WriteValue("Main", "EventLogs", (string)cbCollectEventLogs.SelectedItem, filePath);
            IniFileHelper.WriteValue("Main", "EventSource", (string)cbCollectEventSource.SelectedItem, filePath);
            IniFileHelper.WriteValue("Main", "EventCategory", (string)cbCollectEventCategory.SelectedItem, filePath);

            IniFileHelper.WriteValue("Firewall", "Name", textBox2.Text, filePath);
            IniFileHelper.WriteValue("Firewall", "Protocol", comboBox2.Text, filePath);
            IniFileHelper.WriteValue("Firewall", "Profile", (string)comboBox3.SelectedItem, filePath);
            IniFileHelper.WriteValue("Firewall", "LocalPort", textBox3.Text, filePath);
            IniFileHelper.WriteValue("Firewall", "RemotePort", textBox4.Text, filePath);
            IniFileHelper.WriteValue("Firewall", "Action", (string)comboBox4.SelectedItem, filePath);
            IniFileHelper.WriteValue("Firewall", "Dir", (string)comboBox5.SelectedItem, filePath);
        }
Beispiel #4
0
 public void cbxPrinter_DropDownClosed(ComboBox cbx)
 {
     try
     {
         bool result = IniFileHelper.WriteValue("Printer", "Printer", cbx.SelectedItem.ToString(), Path.GetFullPath(pathIni));
     }
     catch
     {
     }
 }
Beispiel #5
0
        private void writeToINI()
        {
            if (!File.Exists(iniFilePath))
            {
                bool DateTimeMode = IniFileHelper.WriteValue(iniSettingsSection, iniSetKey, iniSetValue, System.IO.Path.GetFullPath(iniFilePath));
            }

            bool lastfile   = IniFileHelper.WriteValue(iniMainSection, iniKey, iniValue, System.IO.Path.GetFullPath(iniFilePath));
            bool lastfolder = IniFileHelper.WriteValue(iniMainSection, iniOpenFileKey, iniOpenFileValue, System.IO.Path.GetFullPath(iniFilePath));

            if (iniReadSetvalue == "manual")
            {
                bool ManualDate = IniFileHelper.WriteValue(iniManualSection, iniManualDateKey, textBox2.Text, System.IO.Path.GetFullPath(iniFilePath));
                bool ManualTime = IniFileHelper.WriteValue(iniManualSection, iniManualTimeKey, textBox3.Text, System.IO.Path.GetFullPath(iniFilePath));
            }

            if (iniReadSetvalue == "auto")
            {
                bool ManualDate = IniFileHelper.DeleteSection(iniManualSection, System.IO.Path.GetFullPath(iniFilePath));
            }
        }
        private void DefaultSettings()
        {
            string filePath = Environment.CurrentDirectory + @"\set.dat";

            if (!File.Exists(filePath))
            {
                File.Create(filePath);
            }

            IniFileHelper.WriteValue("Timer", "Enable", "false", filePath);
            IniFileHelper.WriteValue("Timer", "Timer", "", filePath);

            IniFileHelper.WriteValue("Main", "ErrorCount", "10", filePath);
            IniFileHelper.WriteValue("Main", "Regex", @"fa\S+|suc\S+|\<\S+.+\>|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\'.+'", filePath);

            IniFileHelper.WriteValue("Firewall", "Name", "Block", filePath);
            IniFileHelper.WriteValue("Firewall", "Protocol", "tcp", filePath);
            IniFileHelper.WriteValue("Firewall", "Profile", "private", filePath);
            IniFileHelper.WriteValue("Firewall", "LocalPort", "1433", filePath);
            IniFileHelper.WriteValue("Firewall", "RemotePort", "any", filePath);
            IniFileHelper.WriteValue("Firewall", "Action", "block", filePath);
            IniFileHelper.WriteValue("Firewall", "Dir", "in", filePath);
        }
Beispiel #7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //var ServerName1 = new Encoding().Encrypt(txtServerName1.Text);
            //var ServerName1 = new Encoding().Encrypt(txtServerName1.Text);
            //var ServerName1 = new Encoding().Encrypt(txtServerName1.Text);
            //var ServerName1 = new Encoding().Encrypt(txtServerName1.Text);

            var fileconfig = "config.ini";

            var Database1     = "Database";
            var ServerName1   = "ServerName";
            var UserName1     = "UserName";
            var Password1     = "Password";
            var DatabaseName1 = "DatabaseName";
            var test          = Path.GetFullPath(fileconfig);

            _ServerName1   = IniFileHelper.ReadValue(Database1, ServerName1, test);
            _UserName1     = IniFileHelper.ReadValue(Database1, UserName1, Path.GetFullPath(fileconfig));
            _Password1     = IniFileHelper.ReadValue(Database1, Password1, Path.GetFullPath(fileconfig));
            _DatabaseName1 = IniFileHelper.ReadValue(Database1, DatabaseName1, Path.GetFullPath(fileconfig));

            bool result = IniFileHelper.WriteValue(Database1, ServerName1, new Encoding().Encrypt(txtServerName1.Text), Path.GetFullPath(fileconfig));
        }
Beispiel #8
0
        private void cbxPrinter_DropDownClosed(object sender, EventArgs e)
        {
            bool result = IniFileHelper.WriteValue("Printer", "Printer", cbxPrinter.SelectedItem.ToString(), Path.GetFullPath(dc.pathIni));

            ReadIniFile();
        }
Beispiel #9
0
 private void comboBox1_DropDownClosed(object sender, System.EventArgs e)
 {
     var  cbx    = comboBox1;
     bool result = IniFileHelper.WriteValue("Printer", "Printer", cbx.SelectedItem.ToString(), Path.GetFullPath(dc.pathIni));
 }
    public static void ReadCallback(IAsyncResult ar)
    {
        String content = String.Empty;

        //IniFileHelper
        IniFileHelper iniFile = new IniFileHelper();

        // Retrieve the state object and the handler socket
        // from the asynchronous state object.
        StateObject state   = (StateObject)ar.AsyncState;
        Socket      handler = state.workSocket;

        // Read data from the client socket.
        int bytesRead = handler.EndReceive(ar);

        if (bytesRead > 0)
        {
            // There  might be more data, so store the data received so far.
            state.sb.Append(Encoding.ASCII.GetString(
                                state.buffer, 0, bytesRead));

            // Check for end-of-file tag. If it is not there, read
            // more data.
            content = state.sb.ToString();
            if (content.IndexOf("\r") > -1)
            {
                string ReceivedOutput = null;

                switch (content.Substring(0, 3))
                {
                case "611":
                    string device1Result = iniFile.ReadValue("Device1", "status", System.IO.Path.GetFullPath("IniFile.ini"));
                    string device2Result = iniFile.ReadValue("Device2", "status", System.IO.Path.GetFullPath("IniFile.ini"));
                    string resultOutput  = null;
                    if (device1Result == "-1" && device2Result == "-1")
                    {
                        resultOutput = "0";
                    }
                    else
                    {
                        resultOutput = "1";
                    }

                    ReceivedOutput = "621" + DateTime.Now.ToString("HHmmss") + "015" + "|" + content.Substring(13, 6) + "|" + resultOutput + "|01|02|";

                    if (device1Result != "-1")
                    {
                        bool result = IniFileHelper.WriteValue("Device1", "status", " 1", System.IO.Path.GetFullPath("IniFile.ini"));
                    }
                    if (device2Result != "-1")
                    {
                        bool results = IniFileHelper.WriteValue("Device2", "status", " 1", System.IO.Path.GetFullPath("IniFile.ini"));
                    }
                    break;

                case "612":
                    string device1Reset = iniFile.ReadValue("Device1", "status", System.IO.Path.GetFullPath("IniFile.ini"));
                    string device2Reset = iniFile.ReadValue("Device2", "status", System.IO.Path.GetFullPath("IniFile.ini"));
                    string resetOutput1 = null;
                    string resetOutput2 = null;
                    if (device1Reset == "-1")
                    {
                        resetOutput1 = "1";
                    }
                    else
                    {
                        resetOutput1 = "0";
                    }

                    if (device2Reset == "-1")
                    {
                        resetOutput2 = "1";
                    }
                    else
                    {
                        resetOutput2 = "0";
                    }
                    ReceivedOutput = "622" + DateTime.Now.ToString("HHmmss") + "010" + "|" + content.Substring(13, 6) + "|" + resetOutput1 + "|" + resetOutput2 + "|";

                    if (device1Reset != "-1")
                    {
                        bool result = IniFileHelper.WriteValue("Device1", "status", "0", System.IO.Path.GetFullPath("IniFile.ini"));
                    }
                    if (device2Reset != "-1")
                    {
                        bool results = IniFileHelper.WriteValue("Device2", "status", "0", System.IO.Path.GetFullPath("IniFile.ini"));
                    }
                    //modbusClient.Connect();
                    //modbusClient.WriteSingleCoil(0001, false);
                    //modbusClient.Disconnect();
                    break;

                case "619":
                    string device1Status = iniFile.ReadValue("Device1", "status", System.IO.Path.GetFullPath("IniFile.ini"));
                    string device2Status = iniFile.ReadValue("Device2", "status", System.IO.Path.GetFullPath("IniFile.ini"));

                    ReceivedOutput = "629" + DateTime.Now.ToString("HHmmss") + "011" + "|" + content.Substring(13, 6) + "|" + device1Status + "|" + device2Status + "|";
                    break;

                default:
                    ReceivedOutput = "invalid command code";
                    break;
                }

                // All the data has been read from the
                // client. Display it on the console.
                Console.WriteLine("Read {0} bytes from socket.\nData : {1}",
                                  content.Length, content);

                // Echo the data back to the client.
                Send(handler, ReceivedOutput + "\r");
            }
            else
            {
                // Not all data received. Get more.
                handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                     new AsyncCallback(ReadCallback), state);
            }
        }
    }