Files
WOL-Manager/WoL-Manager v0.1/NewHostWindow.cs
T
2017-10-26 20:11:00 +02:00

70 lines
1.8 KiB
C#
Executable File

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WoL_Manager
{
public partial class NewHostWindow : Form
{
public NewHostWindow()
{
InitializeComponent();
}
protected virtual void NewHostWindow_Load(object sender, EventArgs e)
{
OkButton1.Click += new System.EventHandler(this.buttonEventHandler);
CancelButton1.Click += new System.EventHandler(this.buttonEventHandler);
}
protected virtual void buttonEventHandler(object sender, EventArgs e)
{
if (sender == OkButton1)
{
string name = InputName.Text.Trim();
if (name.Length < 1)
{
MessageBox.Show("There is no name given!", "ERROR", MessageBoxButtons.OK);
return;
}
string mac = InputMAC.Text.Trim().ToUpper();
if (!MainWindow.checkMAC(mac))
{
MessageBox.Show("Wasn't able to parse MAC-Address!\nShould be like this: 00AF2C4323D3",
"ERROR", MessageBoxButtons.OK);
return;
}
string description = InputDescription.Text;
System.Net.IPAddress ip_addr;
System.Net.IPAddress bc_addr;
try
{
ip_addr = System.Net.IPAddress.Parse(InputIP.Text);
}
catch (Exception)
{
MessageBox.Show("Wasn't able to parse IP-Address!\nShould be like this: 192.168.0.1",
"ERROR", MessageBoxButtons.OK);
return;
}
try
{
bc_addr = System.Net.IPAddress.Parse(InputBroadcast.Text);
}
catch (Exception)
{
MessageBox.Show("Wasn't able to parse Broadcast-Address!\nShould be like this: 192.168.0.255",
"ERROR", MessageBoxButtons.OK);
return;
}
Host.createHost(name, ip_addr, mac, bc_addr, description);
}
this.Close();
}
}
}