List<LigneIp> l = new List<LigneIp>(); for (int i=0;i<=10;i++){ l.Add(new LigneIp(){ colonne1="Nombre " + i, colonne2=Math.Pow(2, Math.Ceiling(Math.Log10(i)/Math.Log10(2))) } ); } dataGridView1.DataSource = l;
public class LigneIp { public string colonne1 { get; set; } public double colonne2 { get; set; } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Alert (string Salrt, out int alrt) { alrt = Convert.ToInt32(Salrt); if (alrt < 0 && alrt > 255) { MessageBox.Show("Entrée une Valeur Comprise entre 0 et 255");} } private void radiomask_CheckedChanged_1(object sender, EventArgs e) { if (radiomask.Checked == true) { id.ReadOnly = true; m1.ReadOnly false; m2.ReadOnly false; m3.ReadOnly = false; m4.ReadOnly = false; id.Text = ""; } } private void radioid_CheckedChanged_1(object sender, EventArgs e) { if (radioid.Checked == true) { id.ReadOnly = false; m1.ReadOnly true; m2.ReadOnly true; m3.ReadOnly = true; m4.ReadOnly = true; m1.Text ""; m2.Text ""; m3.Text = ""; m4.Text = ""; } } public void Calculreseau (string ip_addr, byte m, out byte ip, out byte ar, out string maskpattern, out byte broad) { ip = Convert.ToByte(ip_addr); ar = (byte)(ip & m); maskpattern = Convert.ToString(m, 2); broad = (byte)(ip | ~m); } private int Count (string maskpattern, string pattern) { return Regex.Matches(maskpattern, pattern).Count; } private void button1_Click(object sender, EventArgs e) { byte ip; byte ar; byte broad; string maskpattern; int totalCount = 0; // Condition Masque ou ID + Calcul Address reseau if (radioid.Checked == true) { // transforme l'id et x serie de 1 ou x est la valeur de l'id et complemente a 0, et couper par 8 pour etre reconvertit en byte int masqueid = Convert.ToInt32(id.Text); string masqueid1 = "".PadLeft(masqueid, '1').PadRight(32, '0'); string maskidsub masqueid1.Substring(0, 8); byte maskid Convert.ToByte(Convert.ToInt32(maskidsub, 2)); string maskid2sub masqueid1.Substring(8, 8); byte maskid2 Convert.ToByte(Convert.ToInt32(maskid2sub, 2)); string maskid3sub masqueid1.Substring(16, 8); byte maskid3 Convert.ToByte(Convert.ToInt32(maskid3sub, 2)); string maskid4sub masqueid1.Substring(24, 8); byte maskid4 Convert.ToByte(Convert.ToInt32(maskid4sub, 2)); // Utilise la methode crée : Calculreseau(IP.Text, maskid, out ip, out ar, out maskpattern, out broad); adr.Text = Convert.ToString(ar); br.Text = broad.ToString(); totalCount += Count(maskidsub, "0"); Calculreseau(IP2.Text, maskid2, out ip, out ar, out maskpattern, out broad); adr2.Text = Convert.ToString(ar); br2.Text = broad.ToString(); totalCount += Count(maskid2sub, "0"); Calculreseau(IP3.Text, maskid3, out ip, out ar, out maskpattern, out broad); adr3.Text = Convert.ToString(ar); br3.Text = broad.ToString(); totalCount += Count(maskid3sub, "0"); Calculreseau(IP4.Text, maskid4, out ip, out ar, out maskpattern, out broad); adr4.Text = Convert.ToString(ar); br4.Text = broad.ToString(); totalCount += Count(maskid4sub, "0"); } else { byte maskid = Convert.ToByte(m1.Text); byte maskid2 = Convert.ToByte(m2.Text); byte maskid3 = Convert.ToByte(m3.Text); byte maskid4 = Convert.ToByte(m4.Text); // utilise la methode crée : Calculreseau(IP.Text, maskid, out ip, out ar, out maskpattern, out broad); adr.Text = Convert.ToString(ar); br.Text = broad.ToString(); totalCount += Count(maskpattern.PadLeft(8, '0'), "0"); Calculreseau(IP2.Text, maskid2, out ip, out ar, out maskpattern, out broad); adr2.Text = Convert.ToString(ar); br2.Text = broad.ToString(); totalCount += Count(maskpattern.PadLeft(8, '0'), "0"); Calculreseau(IP3.Text, maskid3, out ip, out ar, out maskpattern, out broad); adr3.Text = Convert.ToString(ar); br3.Text = broad.ToString(); totalCount += Count(maskpattern.PadLeft(8, '0'), "0"); Calculreseau(IP4.Text, maskid4, out ip, out ar, out maskpattern, out broad); adr4.Text = Convert.ToString(ar); br4.Text = broad.ToString(); totalCount += Count(maskpattern.PadLeft(8, '0'), "0"); } //Premiere address utilisable : padr.Text = adr.Text; padr2.Text = adr2.Text; padr3.Text = adr3.Text; padr4.Text = (Convert.ToInt32(adr4.Text) + 1).ToString(); //Derniere address utilisable : dadr.Text = br.Text; dadr2.Text = br2.Text; dadr3.Text = br3.Text; dadr4.Text = (Convert.ToInt32(br4.Text) - 1).ToString(); // Renvoi le Count de 0 dans le masque et le met en exposant a 2, pour determiner le nombre de reseau possible int nbReseau = (int)Math.Pow(2, totalCount); nbr.Text = nbReseau.ToString(); nbReseau -= 2; nbru.Text = nbReseau.ToString(); } private void button1_Click_1(object sender, EventArgs e) { // RAZ IP.Text ""; IP2.Text ""; IP3.Text = ""; IP4.Text = ""; m1.Text ""; m2.Text ""; m3.Text = ""; m4.Text = ""; adr.Text ""; adr2.Text ""; adr3.Text = ""; adr4.Text = ""; br.Text ""; br2.Text ""; br3.Text = ""; br4.Text = ""; dadr.Text ""; dadr2.Text ""; dadr3.Text = ""; dadr4.Text = ""; padr.Text ""; padr2.Text ""; padr3.Text = ""; padr4.Text = ""; nbr.Text ""; nbru.Text ""; id.Text = ""; } public string myValue() { // Méthode pour RicheTextBox de la Form2 return ("Adresse IP : " + IP.Text + "." + IP2.Text + "." + IP3.Text + "." + IP4.Text + Environment.NewLine + "Masque/ID : " + m1.Text + "." + m2.Text + "." + m3.Text + "." + m4.Text + " /" + id.Text + Environment.NewLine + Environment.NewLine + "Address du Réseau : " + adr.Text + "." + adr2.Text + "." + adr3.Text + "." + adr4.Text + Environment.NewLine + "Address Broadcast : " + br.Text + "." + br2.Text + "." + br3.Text + "." + br4.Text + Environment.NewLine + "Prm Address Dispo : " + padr.Text + "." + padr2.Text + "." + padr3.Text + "." + padr4.Text + Environment.NewLine + "Drn Address Dispo : " + dadr.Text + "." + dadr2.Text + "." + dadr3.Text + "." + dadr4.Text + Environment.NewLine + "Nbr Rsx Max/Usble : " + nbr.Text + "/" + nbru.Text); } private void enregistrezToolStripMenuItem_Click(object sender, EventArgs e) { // Ouvre une nouvelle instance d'objet de Type Windows.Form Form2 f = new Form2(); f.Owner = this; f.Show(); } private void convertisseurToolStripMenuItem_Click(object sender, EventArgs e) { // Ouvre une nouvelle instance d'objet de Type Windows.Form Form3 f3 = new Form3(); f3.Owner = this; f3.Show(); } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // Demande Confirmation pour fermer l'application DialogResult Demande = MessageBox.Show("Voulez-vous vraiment quitter l'application ","Fermeture", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if ( Demande == DialogResult.Yes) Application.Exit(); } } }
int nbsub = Convert.ToInt32(textBox1.Text); double coef = Math.Pow(2, Math.Ceiling(Math.Log10(nbsub)/Math.Log10(2))); textBox2.Text = coef.ToString();
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic class LigneIp { public string colonne1 { get; set; } public double colonne2 { get; set; } } private void button1_Click(object sender, EventArgs e) { int test = Convert.ToInt32(textBox1.Text); List<LigneIp> l = new List<LigneIp>(); for (int i = 0; i <= test; i++) { l.Add(new LigneIp() { colonne1 = "Nombre " + i, colonne2 = Math.Pow(2, (Math.Ceiling(Math.Log10(test) / Math.Log10(2))))*i } ); } dataGridView1.DataSource = l;