Exemple #1
0
        private void B_submit_Click(object sender, EventArgs e)
        {
            if (T_id.Text.Length != 0 && T_name.Text.Length != 0 && T_ip.Text.Length != 0)
            {
                String extension    = ".ini";
                String logextension = ".txt";
                String path         = T_id.Text + extension;
                String logpath      = T_id.Text + "_log" + logextension;
                String text;
                String text2 = T_id.Text + "로그파일입니다.\r\n";
                String resultStr;
                if (File.Exists(path) == false && File.Exists(logpath) == false)
                {
                    text = "id:" + T_id.Text + "\r\n"
                           + "name:" + T_name.Text + "\r\n"
                           + "ip:" + T_ip.Text + "\r\n"
                           + "screen:off/0\r\n"
                           + "monitoroff:off/0\r\n"
                           + "systemoff:off/0\r\n"
                           + "standby:off/0\r\n"
                           + "hibernate:off/0000/00/00/00:00:00\r\n"
                           + "systemoff:off/0000/00/00/00:00:00\r\n";
                    comm.SetURL("http://210.94.194.100:20151/registerUser.asp");
                    comm.SetMessage("id=" + T_id.Text);
                    comm.Request();
                    resultStr = comm.Response();
                    String[] error = resultStr.Split(':');//resultStr이 error라면 뒤에 메시지와 상관없이 Error만 남게 될것
                    if (resultStr.Equals("ERROR"))
                    {
                    }
                    else
                    {
                        comm.SetURL("http://210.94.194.100:20151/log.asp");
                        comm.SetMessage("id=" + T_id.Text + "&cmd=read");
                        comm.Request();
                        resultStr = comm.Response();
                        //BR로 스플릿하기위해
                        String[] cutbr = new String[] { "<BR>" };

                        String[] returnval = resultStr.Split(cutbr, StringSplitOptions.None);//<BR>로 스플릿
                        for (int i = 0; i < returnval.Length; i++)
                        {
                            text2 += returnval[i] + "\r\n";
                        }
                    }
                    File.WriteAllText(path, text);
                    File.WriteAllText(logpath, text2);
                    MessageBox.Show("회원가입되었습니다");
                    Close();
                }
                else
                {
                    MessageBox.Show("존재하는 아이디 입니다.");
                }
            }
            else
            {
                MessageBox.Show("모든 값을 입력해 주세요");
            }
        }
Exemple #2
0
        private void menu_monitoroff_Click(object sender, EventArgs e)//메뉴->monitor off
        {
            String resultStr;

            comm.SetURL("http://210.94.194.100:20151/log.asp");
            comm.SetMessage("id=" + id + "&cmd=write&action=sleep");
            comm.Request();
            resultStr = comm.Response();
            Process.Start("nircmd.exe", "monitor off"); //컴퓨터의 전원을 끈다
        }
Exemple #3
0
        private void RegisterButton_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("ID를 입력하세요!");
                return;
            }
            string data = textBox1.Text;

            try
            {
                HTTPWebComm comm = new HTTPWebComm();
                comm.SetURL("http://210.94.194.82:52131/registerUser.asp?id=" + data);
                comm.SetMessage("");
                comm.Request();
                comm.Response();
            }
            catch
            {
                MessageBox.Show("id등록에 실패했습니다.");
                return;
            }
            MessageBox.Show("id등록에 성공했습니다.");
            textBox1.Text = data;
        }
Exemple #4
0
        private void ChangeButton_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("ID를 입력하세요!");
                return;
            }
            string data = textBox1.Text;

            try
            {
                HTTPWebComm comm = new HTTPWebComm();
                comm.SetURL("http://210.94.194.82:52131/log.asp?id=" + data + "&cmd=read&action=wakeup");
                comm.SetMessage("");
                comm.Request();
                comm.Response();
            }
            catch
            {
                MessageBox.Show("존재하지 않는 id입니다.\r\nid등록에 실패했습니다.");
                return;
            }
            id = data;
            MessageBox.Show("id를 바꾸었습니다.");
            close = true;
            this.Close();
        }
Exemple #5
0
        public log()
        {
            InitializeComponent();
            DateTime wakeUp    = new DateTime();
            DateTime shutDown  = new DateTime();
            DateTime hibernate = new DateTime();

            string[] delim = { "<BR>", "\r\n" };
            String   resultStr;

            comm.SetURL("http://210.94.194.100:20151/log.asp");
            comm.SetMessage("id=" + id + "&cmd=read");
            comm.Request();
            resultStr = comm.Response();
            string[] s = resultStr.Split(new char[] { '|', '<', '>' });
            for (int i = 0; i < s.Length - 1; i++)
            {
                if (s[i] == "BR") // log에 BR이 나올 경우 줄바꿈
                {
                    textBox1.Text += "\n";
                }
                else // 로그 분리를 하면서 분리되어 없어진 '|'를 다시 삽입
                {
                    textBox1.Text += s[i] + "|";
                }
                if (s[i] == "WAKEUP") // 명령어가 WAKEUP일경우
                {
                    DateTime.TryParse(s[i + 1], out wakeUp);
                }
                if (s[i] == "SHUTDOWN")                        // 명령어가 SHUTDOWN일경우
                {
                    DateTime.TryParse(s[i + 1], out shutDown); // 그 다음 배열의 내용을 DateTime으로 변환
                }
                if (s[i] == "HIBERNATE")
                {
                    DateTime.TryParse(s[i + 1], out hibernate);
                }
            }
            DateTime startSuspend;
            DateTime endSuspend = DateTime.Now;

            DateTimeConverter dtc = new DateTimeConverter();

            startSuspend   = (DateTime)dtc.ConvertFromString(shutDown.ToString("HH:mm:ss"));
            endSuspend     = (DateTime)dtc.ConvertFromString(endSuspend.ToString("HH:mm:ss"));
            TotalTimeSpan += endSuspend.Subtract(startSuspend);

            double saveelec = (TotalTimeSpan.TotalSeconds * 0.056 / 1000) * 0.424;

            textBox1.Text = "절감 전기량 : ";
            textBox1.AppendText((TotalTimeSpan.TotalSeconds * 0.056 / 1000).ToString() + "KWh\n");
            textBox1.AppendText("절약 배출 CO2량 : ");
            textBox1.AppendText(((int)(saveelec)).ToString() + "KG\n");
            saveelec = saveelec / 2.77;
            textBox1.AppendText("절약 나무 수 : ");
            textBox1.AppendText(((int)(saveelec)).ToString() + "그루\n");
        }
Exemple #6
0
 private void OnPowerModeChange(object sender, PowerModeChangedEventArgs e)
 {
     if (e.Mode == PowerModes.Suspend)
     {
         HTTPWebComm comm = new HTTPWebComm();
         string      url  = "http://210.94.194.82:52131/log.asp?id=2014112089&cmd=write&action=wakeup";
         comm.SetURL(url);
         comm.setMessage("");
         comm.Reqeust();
         comm.Response();
     }
 }
Exemple #7
0
 //thread
 private void serverThread(string message)
 {
     try
     {
         HTTPWebComm comm = new HTTPWebComm();
         comm.SetURL("http://210.94.194.82:52131/log.asp?id=" + id + "&cmd=write&action=" + message);
         comm.SetMessage("");
         comm.Request();
     }
     catch
     {
         frm2.setLogTextbox("서버 전송 오류(" + message + ")\r\n");
     }
 }
Exemple #8
0
        /* 서버로부터 각 Action에 대한 Log를 읽어오는 메소드로, 해당 Action 및 UnixTime을
         * 읽어오게 되므로, 받아온 값을 Parsing 하여 UnixTime만 분리하여 DateTime으로 변환하여
         * Return 하게 된다. */

        private DateTime ReadActionLog(string action)
        {
            string url = "http://210.94.194.82:52131/log.asp?id=2014112089&cmd=read&action=";

            url += action;
            char   split = ':';
            double time;

            comm.SetURL(url);
            comm.setMessage("");
            comm.Reqeust();
            string result = comm.Response();

            time = double.Parse(result.Substring(result.IndexOf(split) + 1, 10));
            return(UnixTimeToDateTime(time));
        }
        private void register_id_Click(object sender, EventArgs e)
        {
            new_login.email = input_email.Text;
            new_login.name  = input_name.Text;
            new_login.id    = input_id.Text;

            if (new_login.email != null && new_login.name != null && new_login.id != null)
            {
                System.IO.File.WriteAllText(filePath, null);
                new_login.loginstate = true;
                stream_write         = new StreamWriter(filePath);
                stream_write.Write(new_login.email + "+" + new_login.id + "+" + new_login.name);
                stream_write.Close();
                comm.SetURL("http://210.94.181.168/member_join2.php");
                comm.SetMessage("id=" + input_id.Text + "&name=" + input_name.Text + "&email=" + input_email.Text);
                comm.Request();
                this.Close();
            }
            else
            {
                MessageBox.Show("등록양식이 완성되지 않았습니다!");
            }
        }
Exemple #10
0
        /* 설정 버튼과 이미지를 제외한 나머지 버튼에 대한 Event Handler로,
        * nircmd를 이용하여 클릭된 버튼에 따라 해당 기능을 수행하도록 하였다.*/

        private void Button_Handler(object sender, EventArgs e)
        {
            string operation = "";
            string url       = "http://210.94.194.82:52131/log.asp?id=2014112089&cmd=write&action=";
            Button button    = sender as Button;

            switch (button.Name)
            {
            case "shutdownButton":
                url      += "shutdown";
                operation = "exitwin poweroff";
                break;

            case "sleepButton":
                url      += "sleep";
                operation = "monitor off";
                break;

            case "suspendButton":
                url      += "suspend";
                operation = "standby force";
                break;

            case "hibernateButton":
                url      += "hibernate";
                operation = "hibernate force";
                break;
            }
            HTTPWebComm comm = new HTTPWebComm();

            comm.SetURL(url);
            comm.setMessage("");
            comm.Reqeust();
            comm.Response();
            Process.Start(path, operation);
        }
Exemple #11
0
        //재시작 시간 체크
        private void TimeCheck(object sender, EventArgs e)
        {
            int result = 0;

            try
            {
                HTTPWebComm comm = new HTTPWebComm();
                comm.SetURL("http://210.94.194.82:52131/log.asp?id=" + id + "&cmd=read&action=shutdown");
                comm.SetMessage("");
                comm.Request();

                result = int.Parse(Regex.Replace(comm.Response(), @"\D", ""));

                frm2.setLogTextbox("시작\r\n");

                comm.SetURL("http://210.94.194.82:52131/log.asp?id=" + id + "&cmd=write&action=wakeup");
                comm.Request();

                comm.SetURL("http://210.94.194.82:52131/log.asp?id=" + id + "&cmd=read&action=wakeup");
                comm.Request();

                result -= int.Parse(Regex.Replace(comm.Response(), @"\D", ""));
                result  = -result;
            }
            catch (System.Net.WebException)
            {
                frm2.setLogTextbox("서버에 접속하지 못하였습니다.\r\n");
                MessageBox.Show("서버에 접속하지 못하였습니다.");
                return;
            }
            catch (Exception err)
            {
                frm2.setLogTextbox("알수없는 에려\r\n" + err.ToString() + "\r\n");
                MessageBox.Show("알수없는 에려\r\n" + err.ToString());
                return;
            }
            finally
            {
                if (timeData != null)
                {
                    Array.Resize(ref timeData, timeData.Length + 1);
                }
                else
                {
                    timeData = new string[1];
                }
                timeData[timeData.Length - 1] = DateTime.Now.ToString("yyyy MM dd HH mm ss") + " w";
            }

            frm2.setLogTextbox("환영합니다 " + id + "님\r\n");
            if (result < 300)
            {
                frm2.setLogTextbox("다시 시작한지 " + result + "초 만입니다.\r\n");
                MessageBox.Show("환영합니다.\r\n다시 시작한지 " + result + "초 만입니다.");
                return;
            }
            else if (result / 60 < 60)
            {
                frm2.setLogTextbox("다시 시작한지 " + result / 60 + "분 " + result % 60 + "초 만입니다.\r\n");
                MessageBox.Show("환영합니다.\r\n다시 시작한지 " + result / 60 + "분 만입니다.");
                return;
            }
            else if (result > 259200)//1달이상
            {
                frm2.setLogTextbox("다시 시작한지 1달 이상이거나 처음 시작합니다.\r\n");
                MessageBox.Show("환영합니다.");
                return;
            }
            frm2.setLogTextbox("다시 시작한지 " + result / 3600 + "시간 " + result % 3600 / 60 + "분 " + result % 360 % 60 + "초 만입니다.\r\n");
            MessageBox.Show("환영합니다.\r\n다시 시작한지 " + result / 3600 + "시간 만입니다.");
        }