Ejemplo n.º 1
0
 /// <summary>
 /// 根据子网地址和掩码地址初始化子网类
 /// </summary>
 /// <param name="_ip">子网地址</param>
 /// <param name="_mask">掩码地址</param>
 public Subnet(IpAddress _ip, IpAddress _mask)
 {
     if (!_mask.IsValidMask())
     {
         throw new SubnetErrorException("不是正确的掩码格式");
     }
     if (_ip.GetSubnetAddress(_mask).CompareTo(_ip) != 0)
     {
         throw new SubnetErrorException("子网地址和掩码不搭配");
     }
     ip          = _ip;
     mask        = _mask;
     maskBitsNum = _mask.GetMaskBits();
 }
Ejemplo n.º 2
0
        private void btnAddSubnet_Click(object sender, RoutedEventArgs e)
        {
            if (tbIP.IP == null && tbMask.IP == null)
            {
                MessageBox.Show("子网地址或掩码不是正确的IP格式");
                return;
            }
            IpAddress ip   = new IpAddress(tbIP.IP);
            IpAddress mask = new IpAddress(tbMask.IP);

            if (!mask.IsValidMask())
            {
                MessageBox.Show("掩码的格式不正确");
                return;
            }
            IpAddress subnet = ip.GetSubnetAddress(mask);

            subnetList.Add(new Subnet(subnet, mask));
            tbIP.Clear();
            tbMask.Clear();
        }
Ejemplo n.º 3
0
        private void btnAddIP_Click(object sender, RoutedEventArgs e)
        {
            string    strIpAddr = tbAddIP.Text.Trim();
            IpAddress ipAddr, ipMask, ipGateWay;
            string    strIpMask    = tbAddMask.Text.Trim();
            string    strIpGateWay = tbAddGateway.Text.Trim();
            string    ipName       = tbAddIPName.Text.Trim();
            string    ipEquipName  = cbbAddIPEquipName.Text;

            if (ipEquipName.Equals("选择设备"))
            {
                MessageBox.Show("请选择一个设备");
                return;
            }
            if (!IpAddress.IsIP(strIpAddr))
            {
                MessageBox.Show("地址格式不正确");
                return;
            }
            ipAddr = new IpAddress(strIpAddr);
            if (string.IsNullOrEmpty(strIpMask))
            {
                ipMask = null;
            }
            else
            {
                if (!IpAddress.IsIP(strIpMask))
                {
                    MessageBox.Show("掩码应是一个IP地址格式");
                    return;
                }
                ipMask = new IpAddress(strIpMask);
                if (!ipMask.IsValidMask())
                {
                    MessageBox.Show("掩码格式不正确");
                    return;
                }
            }
            if (string.IsNullOrEmpty(strIpGateWay))
            {
                ipGateWay = null;
            }
            else
            {
                if (!IpAddress.IsIP(strIpGateWay))
                {
                    MessageBox.Show("网关格式错误");
                    return;
                }
                ipGateWay = new IpAddress(strIpGateWay);
            }
            string getIDSql = "SELECT Equip_Index FROM Equipments WHERE Equip_Name = '" + ipEquipName + "'";
            int    equipID  = Convert.ToInt32(App.DBHelper.returnScalar(getIDSql));

            if (equipID <= 0)
            {
                MessageBox.Show("数据库中未找到相应的设备号");
                return;
            }
            string insertSql = string.Format("INSERT INTO IPAddress(IP_Address, IP_EquipID, IP_Mask, IP_GateWay, IP_Name) VALUES('{0}',{1},'{2}','{3}','{4}')", strIpAddr, equipID, strIpMask, strIpGateWay, ipName);

            if (!App.DBHelper.ExecuteReturnBool(insertSql))
            {
                MessageBox.Show("插入IP失败");
                return;
            }
            IPInfor4DB ipInfo     = new IPInfor4DB(ipAddr, equipID, ipEquipName, ipMask, ipGateWay, ipName, false);
            string     getipIDSql = string.Format("SELECT IP_Index FROM IPAddress WHERE  IP_EquipID = {0} AND IP_Address = '{1}'", equipID, strIpAddr);

            ipInfo.IpIndex = Convert.ToInt32(App.DBHelper.returnScalar(getipIDSql));
            ipInformationList.Add(ipInfo);
            tbAddIP.Text      = "";
            tbAddIPName.Text  = "";
            tbAddMask.Text    = "";
            tbAddGateway.Text = "";
        }