Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ArrayDiRecord
- {
- public struct Alunno
- {
- public String cognome;
- public String nome;
- public String matricola;
- public double altezza;
- public double peso;
- }
- public partial class Form1 : Form
- {
- Alunno[] alunno;
- int n;
- public Form1()
- {
- InitializeComponent();
- }
- private void InitializeComponent()
- {
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
- this.label1 = new System.Windows.Forms.Label();
- this.bInserisci = new System.Windows.Forms.Button();
- this.bVisualizza = new System.Windows.Forms.Button();
- this.tNum = new System.Windows.Forms.TextBox();
- this.dgv = new System.Windows.Forms.DataGridView();
- this.bVisualizzaR = new System.Windows.Forms.Button();
- this.bCanc = new System.Windows.Forms.Button();
- this.bMediaAlt = new System.Windows.Forms.Button();
- this.bMinPeso = new System.Windows.Forms.Button();
- this.lAlt = new System.Windows.Forms.Label();
- this.lPes = new System.Windows.Forms.Label();
- this.bAdd = new System.Windows.Forms.Button();
- this.tPeso = new System.Windows.Forms.TextBox();
- this.tAltezza = new System.Windows.Forms.TextBox();
- this.tNome = new System.Windows.Forms.TextBox();
- this.tCognome = new System.Windows.Forms.TextBox();
- this.tMatricola = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.label6 = new System.Windows.Forms.Label();
- this.label7 = new System.Windows.Forms.Label();
- this.tCercaMatricola = new System.Windows.Forms.TextBox();
- this.tEditCognome = new System.Windows.Forms.TextBox();
- this.tEditNome = new System.Windows.Forms.TextBox();
- this.tEditAltezza = new System.Windows.Forms.TextBox();
- this.tEditPeso = new System.Windows.Forms.TextBox();
- this.bEdit = new System.Windows.Forms.Button();
- this.bRemove = new System.Windows.Forms.Button();
- this.label8 = new System.Windows.Forms.Label();
- this.label9 = new System.Windows.Forms.Label();
- this.label10 = new System.Windows.Forms.Label();
- this.label11 = new System.Windows.Forms.Label();
- ((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit();
- this.SuspendLayout();
- //
- // label1
- //
- resources.ApplyResources(this.label1, "label1");
- this.label1.ForeColor = System.Drawing.Color.Red;
- this.label1.Name = "label1";
- //
- // bInserisci
- //
- resources.ApplyResources(this.bInserisci, "bInserisci");
- this.bInserisci.Name = "bInserisci";
- this.bInserisci.UseVisualStyleBackColor = true;
- this.bInserisci.Click += new System.EventHandler(this.bInserisci_Click);
- //
- // bVisualizza
- //
- resources.ApplyResources(this.bVisualizza, "bVisualizza");
- this.bVisualizza.Name = "bVisualizza";
- this.bVisualizza.UseVisualStyleBackColor = true;
- this.bVisualizza.Click += new System.EventHandler(this.bVisualizza_Click);
- //
- // tNum
- //
- resources.ApplyResources(this.tNum, "tNum");
- this.tNum.Name = "tNum";
- //
- // dgv
- //
- this.dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- resources.ApplyResources(this.dgv, "dgv");
- this.dgv.Name = "dgv";
- //
- // bVisualizzaR
- //
- resources.ApplyResources(this.bVisualizzaR, "bVisualizzaR");
- this.bVisualizzaR.Name = "bVisualizzaR";
- this.bVisualizzaR.UseVisualStyleBackColor = true;
- this.bVisualizzaR.Click += new System.EventHandler(this.bVisualizzaR_Click);
- //
- // bCanc
- //
- resources.ApplyResources(this.bCanc, "bCanc");
- this.bCanc.Name = "bCanc";
- this.bCanc.UseVisualStyleBackColor = true;
- this.bCanc.Click += new System.EventHandler(this.bCanc_Click);
- //
- // bMediaAlt
- //
- resources.ApplyResources(this.bMediaAlt, "bMediaAlt");
- this.bMediaAlt.Name = "bMediaAlt";
- this.bMediaAlt.UseVisualStyleBackColor = true;
- this.bMediaAlt.Click += new System.EventHandler(this.bMediaAlt_Click);
- //
- // bMinPeso
- //
- resources.ApplyResources(this.bMinPeso, "bMinPeso");
- this.bMinPeso.Name = "bMinPeso";
- this.bMinPeso.UseVisualStyleBackColor = true;
- this.bMinPeso.Click += new System.EventHandler(this.bMinPeso_Click);
- //
- // lAlt
- //
- this.lAlt.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- resources.ApplyResources(this.lAlt, "lAlt");
- this.lAlt.Name = "lAlt";
- //
- // lPes
- //
- this.lPes.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- resources.ApplyResources(this.lPes, "lPes");
- this.lPes.Name = "lPes";
- //
- // bAdd
- //
- resources.ApplyResources(this.bAdd, "bAdd");
- this.bAdd.Name = "bAdd";
- this.bAdd.UseVisualStyleBackColor = true;
- this.bAdd.Click += new System.EventHandler(this.bAdd_Click);
- //
- // tPeso
- //
- resources.ApplyResources(this.tPeso, "tPeso");
- this.tPeso.Name = "tPeso";
- //
- // tAltezza
- //
- resources.ApplyResources(this.tAltezza, "tAltezza");
- this.tAltezza.Name = "tAltezza";
- //
- // tNome
- //
- resources.ApplyResources(this.tNome, "tNome");
- this.tNome.Name = "tNome";
- //
- // tCognome
- //
- resources.ApplyResources(this.tCognome, "tCognome");
- this.tCognome.Name = "tCognome";
- //
- // tMatricola
- //
- resources.ApplyResources(this.tMatricola, "tMatricola");
- this.tMatricola.Name = "tMatricola";
- //
- // label2
- //
- resources.ApplyResources(this.label2, "label2");
- this.label2.Name = "label2";
- //
- // label3
- //
- resources.ApplyResources(this.label3, "label3");
- this.label3.Name = "label3";
- //
- // label4
- //
- resources.ApplyResources(this.label4, "label4");
- this.label4.Name = "label4";
- //
- // label5
- //
- resources.ApplyResources(this.label5, "label5");
- this.label5.Name = "label5";
- //
- // label6
- //
- resources.ApplyResources(this.label6, "label6");
- this.label6.Name = "label6";
- //
- // label7
- //
- resources.ApplyResources(this.label7, "label7");
- this.label7.Name = "label7";
- //
- // tCercaMatricola
- //
- resources.ApplyResources(this.tCercaMatricola, "tCercaMatricola");
- this.tCercaMatricola.Name = "tCercaMatricola";
- this.tCercaMatricola.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cercaMatricola);
- //
- // tEditCognome
- //
- resources.ApplyResources(this.tEditCognome, "tEditCognome");
- this.tEditCognome.Name = "tEditCognome";
- //
- // tEditNome
- //
- resources.ApplyResources(this.tEditNome, "tEditNome");
- this.tEditNome.Name = "tEditNome";
- //
- // tEditAltezza
- //
- resources.ApplyResources(this.tEditAltezza, "tEditAltezza");
- this.tEditAltezza.Name = "tEditAltezza";
- //
- // tEditPeso
- //
- resources.ApplyResources(this.tEditPeso, "tEditPeso");
- this.tEditPeso.Name = "tEditPeso";
- //
- // bEdit
- //
- resources.ApplyResources(this.bEdit, "bEdit");
- this.bEdit.Name = "bEdit";
- this.bEdit.UseVisualStyleBackColor = true;
- this.bEdit.Click += new System.EventHandler(this.bEdit_Click);
- //
- // bRemove
- //
- resources.ApplyResources(this.bRemove, "bRemove");
- this.bRemove.Name = "bRemove";
- this.bRemove.UseVisualStyleBackColor = true;
- this.bRemove.Click += new System.EventHandler(this.bRemove_Click);
- //
- // label8
- //
- resources.ApplyResources(this.label8, "label8");
- this.label8.Name = "label8";
- //
- // label9
- //
- resources.ApplyResources(this.label9, "label9");
- this.label9.Name = "label9";
- //
- // label10
- //
- resources.ApplyResources(this.label10, "label10");
- this.label10.Name = "label10";
- //
- // label11
- //
- resources.ApplyResources(this.label11, "label11");
- this.label11.Name = "label11";
- //
- // Form1
- //
- resources.ApplyResources(this, "$this");
- this.Controls.Add(this.label11);
- this.Controls.Add(this.label10);
- this.Controls.Add(this.label9);
- this.Controls.Add(this.label8);
- this.Controls.Add(this.bRemove);
- this.Controls.Add(this.bEdit);
- this.Controls.Add(this.tEditPeso);
- this.Controls.Add(this.tEditAltezza);
- this.Controls.Add(this.tEditNome);
- this.Controls.Add(this.tEditCognome);
- this.Controls.Add(this.tCercaMatricola);
- this.Controls.Add(this.label7);
- this.Controls.Add(this.label6);
- this.Controls.Add(this.label5);
- this.Controls.Add(this.label4);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.tMatricola);
- this.Controls.Add(this.tCognome);
- this.Controls.Add(this.tNome);
- this.Controls.Add(this.tAltezza);
- this.Controls.Add(this.tPeso);
- this.Controls.Add(this.bAdd);
- this.Controls.Add(this.lPes);
- this.Controls.Add(this.lAlt);
- this.Controls.Add(this.bMinPeso);
- this.Controls.Add(this.bMediaAlt);
- this.Controls.Add(this.bCanc);
- this.Controls.Add(this.bVisualizzaR);
- this.Controls.Add(this.dgv);
- this.Controls.Add(this.tNum);
- this.Controls.Add(this.bVisualizza);
- this.Controls.Add(this.bInserisci);
- this.Controls.Add(this.label1);
- this.Name = "Form1";
- this.Load += new System.EventHandler(this.Form1_Load);
- ((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit();
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- bVisualizza.Enabled = false;
- bVisualizzaR.Enabled = false;
- dgv.ColumnCount = 5;
- dgv.RowCount = 1;
- dgv.Columns[0].HeaderText = "Matricola";
- dgv.Columns[1].HeaderText = "Cognome";
- dgv.Columns[2].HeaderText = "Nome";
- dgv.Columns[3].HeaderText = "Altezza";
- dgv.Columns[4].HeaderText = "Peso";
- }
- private void bInserisci_Click(object sender, EventArgs e)
- {
- n = Int16.Parse(tNum.Text);
- alunno = new Alunno[20];
- bVisualizza.Enabled = true;
- bVisualizzaR.Enabled = true;
- for (int i = 0; i < n; i++)
- {
- alunno[i].matricola = Interaction.InputBox("Dammi la matricola" + (i + 1));
- alunno[i].cognome = Interaction.InputBox("Dammi la cognome" + (i + 1));
- alunno[i].nome = Interaction.InputBox("Dammi la nome" + (i + 1));
- alunno[i].altezza = Convert.ToDouble(Interaction.InputBox("Dammi la altezza" + (i + 1)).Replace(".", ","));
- alunno[i].peso = Convert.ToDouble(Interaction.InputBox("Dammi la peso" + (i + 1)).Replace(".", ","));
- }
- }
- private void bVisualizza_Click(object sender, EventArgs e)
- {
- dgv.RowCount = n;
- for (int i = 0; i < n; i++)
- {
- dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
- dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
- dgv.Rows[i].Cells[2].Value = alunno[i].nome;
- dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
- dgv.Rows[i].Cells[4].Value = alunno[i].peso;
- }
- }
- private void bVisualizzaR_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < n; i++)
- {
- string[] riga = { alunno[i].matricola, alunno[i].cognome, alunno[i].nome, Convert.ToString(alunno[i].altezza), Convert.ToString(alunno[i].peso) };
- dgv.Rows.Add(riga);
- }
- }
- private void bCanc_Click(object sender, EventArgs e)
- {
- dgv.Rows.Clear();
- }
- private void bMediaAlt_Click(object sender, EventArgs e)
- {
- double num = 0;
- for (int i = 0; i < n; i++)
- num += alunno[i].altezza;
- num /= n;
- lAlt.Text = Convert.ToString(num);
- }
- private void bMinPeso_Click(object sender, EventArgs e)
- {
- double min = alunno[0].peso;
- for (int i = 0; i < n; i++)
- if (alunno[i].peso < min) min = alunno[i].peso;
- lPes.Text = Convert.ToString(min);
- }
- private void cercaMatricola(object sender, KeyEventArgs e)
- {
- for (int i = 0; i < n; i++)
- {
- if (tCercaMatricola.Text == alunno[i].matricola)
- {
- tEditCognome.Text = alunno[i].cognome;
- tEditNome.Text = alunno[i].nome;
- tEditAltezza.Text = Convert.ToString(alunno[i].altezza);
- tEditPeso.Text = Convert.ToString(alunno[i].peso);
- }
- }
- }
- private void bEdit_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < n; i++)
- {
- if (tCercaMatricola.Text == alunno[i].matricola)
- {
- alunno[i].cognome = tEditCognome.Text;
- alunno[i].nome = tEditNome.Text;
- alunno[i].altezza = Convert.ToDouble(tEditAltezza.Text);
- alunno[i].peso = Convert.ToDouble(tEditPeso.Text);
- }
- }
- dgv.RowCount = n;
- for (int i = 0; i < n; i++)
- {
- dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
- dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
- dgv.Rows[i].Cells[2].Value = alunno[i].nome;
- dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
- dgv.Rows[i].Cells[4].Value = alunno[i].peso;
- }
- }
- private void bRemove_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < n; i++)
- {
- if (tCercaMatricola.Text == alunno[i].matricola)
- {
- for (int j = i; j < n; j++)
- alunno[j] = alunno[(j + 1)];
- }
- }
- n -= 1;
- dgv.RowCount = n;
- for (int i = 0; i < n; i++)
- {
- dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
- dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
- dgv.Rows[i].Cells[2].Value = alunno[i].nome;
- dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
- dgv.Rows[i].Cells[4].Value = alunno[i].peso;
- }
- }
- private void bAdd_Click(object sender, EventArgs e)
- {
- alunno[n].matricola = tMatricola.Text;
- alunno[n].cognome = tCognome.Text;
- alunno[n].nome = tNome.Text;
- alunno[n].altezza = Convert.ToDouble(tAltezza.Text);
- alunno[n].peso = Convert.ToDouble(tPeso.Text);
- n++;
- dgv.RowCount = n;
- for (int i = 0; i < n; i++)
- {
- dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
- dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
- dgv.Rows[i].Cells[2].Value = alunno[i].nome;
- dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
- dgv.Rows[i].Cells[4].Value = alunno[i].peso;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement