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; }
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(); }
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(); } }
//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"); } }
/* 설정 버튼과 이미지를 제외한 나머지 버튼에 대한 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); }
//재시작 시간 체크 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 + "시간 만입니다."); }