コード例 #1
0
        private void AtualizarPlacas()
        {
            placas.Clear();
            foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
            {
                if ((ni.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 && ni.OperationalStatus != OperationalStatus.Up) ||
                    (ni.NetworkInterfaceType != NetworkInterfaceType.Ethernet && ni.OperationalStatus != OperationalStatus.Up))
                {
                    continue;
                }

                try
                {
                    var ipProperties = ni.GetIPProperties();
                    var placa        = new Placa();

                    if (!ipProperties.GetIPv4Properties().IsDhcpEnabled)
                    {
                        var ipInfo = ipProperties.UnicastAddresses.FirstOrDefault(ip => ip.Address.AddressFamily == AddressFamily.InterNetwork);

                        if (ipInfo == null)
                        {
                            continue;
                        }

                        var currentIPaddress  = ipInfo.Address.ToString();
                        var currentSubnetMask = ipInfo.IPv4Mask.ToString();

                        placa.SetIpAddr(currentIPaddress);
                        placa.SetSubNet(currentSubnetMask);
                    }

                    placa.Nome       = ni.Name;
                    placa.Descricao  = ni.Description;
                    placa.DhcpEnable = ipProperties.GetIPv4Properties().IsDhcpEnabled;

                    placas.Add(placa);
                }
                catch
                {
                }
            }
            //Carrega os dados
            CarregaComboBoxPlacas();
        }
コード例 #2
0
        private void dgvListaIps_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                var placa = placasSalvas[dgvListaIps.SelectedCells[0].RowIndex];

                //Verifica se a placa pode ser utilizada
                bool  encontrado      = false;
                Placa placaEncontrada = null;
                int   index           = 0;

                foreach (var p in placas)
                {
                    if (p.Descricao == placa.Descricao)
                    {
                        placaEncontrada = p;
                        encontrado      = true;
                    }

                    if (encontrado)
                    {
                        break;
                    }

                    index++;
                }

                if (!encontrado)
                {
                    MessageBox.Show("Esta placa nao esta disponivel agora. Verifique as sua conexao");
                    return;
                }

                placaEncontrada.SetIpAddr(placa.IP);
                placaEncontrada.SetSubNet(placa.Subnet);
                placaEncontrada.DhcpEnable = placa.DhcpEnable;

                CarregaComboBoxPlacas();
                cbPlacas.SelectedIndex = index;
            }catch
            {
            }
        }
コード例 #3
0
        private void btnSalvarConfiguracao_Click(object sender, EventArgs e)
        {
            string indicePk = iniFile.Read("INDICE_PK");
            int    iPk      = Convert.ToInt32(indicePk == "" ? "0" : indicePk);

            FormNomePlaca formNomePlaca = new FormNomePlaca();

            formNomePlaca.ShowDialog();

            Placa p = new Placa();

            p.Id         = iPk.ToString();
            p.Nome       = placas[cbPlacas.SelectedIndex].Nome;
            p.Descricao  = placas[cbPlacas.SelectedIndex].Descricao;
            p.DhcpEnable = cbDhcp.Checked;
            p.Apelido    = formNomePlaca.DialogResult == DialogResult.OK ? formNomePlaca.NomePlaca : "Sem nome";
            string ip     = "0.0.0.0";
            string subnet = "0.0.0.0";

            if (!p.DhcpEnable)
            {
                if (!ValidaIp(txtIP_1.Text, txtIP_2.Text, txtIP_3.Text, txtIP_4.Text, out ip))
                {
                    MessageBox.Show("A Faixa de IP esta incorreta!");
                    return;
                }

                if (!ValidaIp(txtSubNet_1.Text, txtSubNet_2.Text, txtSubNet_3.Text, txtSubNet_4.Text, out subnet))
                {
                    MessageBox.Show("A Faixa de IP da mascara esta incorreta!");
                    return;
                }
            }

            p.SetIpAddr(ip);
            p.SetSubNet(subnet);

            placasSalvas.Add(p);

            SalvarConfiguracao(p);
            AtualizarGridPlacasSalvas();
        }
コード例 #4
0
        private void SalvarConfiguracao(Placa placaConf)
        {
            string indicePk = iniFile.Read("INDICE_PK");
            int    iPk      = Convert.ToInt32(indicePk == "" ? "0" : indicePk);

            string identificador = iPk.ToString();
            string valor         =
                placaConf.Nome + ";" +
                placaConf.IP + ";" +
                placaConf.Subnet + ";" +
                (placaConf.DhcpEnable == true ? "TRUE" : "FALSE") + ";" +
                placaConf.Descricao + ";" +
                placaConf.Apelido;

            string valorGeral = iniFile.Read("PLACAS_SALVAS");

            iniFile.Write("PLACAS_SALVAS", valorGeral + identificador + ";");
            iniFile.Write(identificador, valor, "PLACAS");
            iniFile.Write("INDICE_PK", (iPk + 1).ToString());
        }