Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.80 KB | None | 0 0
  1. namespace ArrayDiRecord
  2. {
  3. public struct Alunno
  4. {
  5. public String cognome;
  6. public String nome;
  7. public String matricola;
  8. public double altezza;
  9. public double peso;
  10. }
  11.  
  12. public partial class Form1 : Form
  13. {
  14. Alunno[] alunno;
  15. int n;
  16.  
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void InitializeComponent()
  23. {
  24. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
  25. this.label1 = new System.Windows.Forms.Label();
  26. this.bInserisci = new System.Windows.Forms.Button();
  27. this.bVisualizza = new System.Windows.Forms.Button();
  28. this.tNum = new System.Windows.Forms.TextBox();
  29. this.dgv = new System.Windows.Forms.DataGridView();
  30. this.bVisualizzaR = new System.Windows.Forms.Button();
  31. this.bCanc = new System.Windows.Forms.Button();
  32. this.bMediaAlt = new System.Windows.Forms.Button();
  33. this.bMinPeso = new System.Windows.Forms.Button();
  34. this.lAlt = new System.Windows.Forms.Label();
  35. this.lPes = new System.Windows.Forms.Label();
  36. this.bAdd = new System.Windows.Forms.Button();
  37. this.tPeso = new System.Windows.Forms.TextBox();
  38. this.tAltezza = new System.Windows.Forms.TextBox();
  39. this.tNome = new System.Windows.Forms.TextBox();
  40. this.tCognome = new System.Windows.Forms.TextBox();
  41. this.tMatricola = new System.Windows.Forms.TextBox();
  42. this.label2 = new System.Windows.Forms.Label();
  43. this.label3 = new System.Windows.Forms.Label();
  44. this.label4 = new System.Windows.Forms.Label();
  45. this.label5 = new System.Windows.Forms.Label();
  46. this.label6 = new System.Windows.Forms.Label();
  47. this.label7 = new System.Windows.Forms.Label();
  48. this.tCercaMatricola = new System.Windows.Forms.TextBox();
  49. this.tEditCognome = new System.Windows.Forms.TextBox();
  50. this.tEditNome = new System.Windows.Forms.TextBox();
  51. this.tEditAltezza = new System.Windows.Forms.TextBox();
  52. this.tEditPeso = new System.Windows.Forms.TextBox();
  53. this.bEdit = new System.Windows.Forms.Button();
  54. this.bRemove = new System.Windows.Forms.Button();
  55. this.label8 = new System.Windows.Forms.Label();
  56. this.label9 = new System.Windows.Forms.Label();
  57. this.label10 = new System.Windows.Forms.Label();
  58. this.label11 = new System.Windows.Forms.Label();
  59. ((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit();
  60. this.SuspendLayout();
  61. //
  62. // label1
  63. //
  64. resources.ApplyResources(this.label1, "label1");
  65. this.label1.ForeColor = System.Drawing.Color.Red;
  66. this.label1.Name = "label1";
  67. //
  68. // bInserisci
  69. //
  70. resources.ApplyResources(this.bInserisci, "bInserisci");
  71. this.bInserisci.Name = "bInserisci";
  72. this.bInserisci.UseVisualStyleBackColor = true;
  73. this.bInserisci.Click += new System.EventHandler(this.bInserisci_Click);
  74. //
  75. // bVisualizza
  76. //
  77. resources.ApplyResources(this.bVisualizza, "bVisualizza");
  78. this.bVisualizza.Name = "bVisualizza";
  79. this.bVisualizza.UseVisualStyleBackColor = true;
  80. this.bVisualizza.Click += new System.EventHandler(this.bVisualizza_Click);
  81. //
  82. // tNum
  83. //
  84. resources.ApplyResources(this.tNum, "tNum");
  85. this.tNum.Name = "tNum";
  86. //
  87. // dgv
  88. //
  89. this.dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  90. resources.ApplyResources(this.dgv, "dgv");
  91. this.dgv.Name = "dgv";
  92. //
  93. // bVisualizzaR
  94. //
  95. resources.ApplyResources(this.bVisualizzaR, "bVisualizzaR");
  96. this.bVisualizzaR.Name = "bVisualizzaR";
  97. this.bVisualizzaR.UseVisualStyleBackColor = true;
  98. this.bVisualizzaR.Click += new System.EventHandler(this.bVisualizzaR_Click);
  99. //
  100. // bCanc
  101. //
  102. resources.ApplyResources(this.bCanc, "bCanc");
  103. this.bCanc.Name = "bCanc";
  104. this.bCanc.UseVisualStyleBackColor = true;
  105. this.bCanc.Click += new System.EventHandler(this.bCanc_Click);
  106. //
  107. // bMediaAlt
  108. //
  109. resources.ApplyResources(this.bMediaAlt, "bMediaAlt");
  110. this.bMediaAlt.Name = "bMediaAlt";
  111. this.bMediaAlt.UseVisualStyleBackColor = true;
  112. this.bMediaAlt.Click += new System.EventHandler(this.bMediaAlt_Click);
  113. //
  114. // bMinPeso
  115. //
  116. resources.ApplyResources(this.bMinPeso, "bMinPeso");
  117. this.bMinPeso.Name = "bMinPeso";
  118. this.bMinPeso.UseVisualStyleBackColor = true;
  119. this.bMinPeso.Click += new System.EventHandler(this.bMinPeso_Click);
  120. //
  121. // lAlt
  122. //
  123. this.lAlt.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  124. resources.ApplyResources(this.lAlt, "lAlt");
  125. this.lAlt.Name = "lAlt";
  126. //
  127. // lPes
  128. //
  129. this.lPes.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  130. resources.ApplyResources(this.lPes, "lPes");
  131. this.lPes.Name = "lPes";
  132. //
  133. // bAdd
  134. //
  135. resources.ApplyResources(this.bAdd, "bAdd");
  136. this.bAdd.Name = "bAdd";
  137. this.bAdd.UseVisualStyleBackColor = true;
  138. this.bAdd.Click += new System.EventHandler(this.bAdd_Click);
  139. //
  140. // tPeso
  141. //
  142. resources.ApplyResources(this.tPeso, "tPeso");
  143. this.tPeso.Name = "tPeso";
  144. //
  145. // tAltezza
  146. //
  147. resources.ApplyResources(this.tAltezza, "tAltezza");
  148. this.tAltezza.Name = "tAltezza";
  149. //
  150. // tNome
  151. //
  152. resources.ApplyResources(this.tNome, "tNome");
  153. this.tNome.Name = "tNome";
  154. //
  155. // tCognome
  156. //
  157. resources.ApplyResources(this.tCognome, "tCognome");
  158. this.tCognome.Name = "tCognome";
  159. //
  160. // tMatricola
  161. //
  162. resources.ApplyResources(this.tMatricola, "tMatricola");
  163. this.tMatricola.Name = "tMatricola";
  164. //
  165. // label2
  166. //
  167. resources.ApplyResources(this.label2, "label2");
  168. this.label2.Name = "label2";
  169. //
  170. // label3
  171. //
  172. resources.ApplyResources(this.label3, "label3");
  173. this.label3.Name = "label3";
  174. //
  175. // label4
  176. //
  177. resources.ApplyResources(this.label4, "label4");
  178. this.label4.Name = "label4";
  179. //
  180. // label5
  181. //
  182. resources.ApplyResources(this.label5, "label5");
  183. this.label5.Name = "label5";
  184. //
  185. // label6
  186. //
  187. resources.ApplyResources(this.label6, "label6");
  188. this.label6.Name = "label6";
  189. //
  190. // label7
  191. //
  192. resources.ApplyResources(this.label7, "label7");
  193. this.label7.Name = "label7";
  194. //
  195. // tCercaMatricola
  196. //
  197. resources.ApplyResources(this.tCercaMatricola, "tCercaMatricola");
  198. this.tCercaMatricola.Name = "tCercaMatricola";
  199. this.tCercaMatricola.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cercaMatricola);
  200. //
  201. // tEditCognome
  202. //
  203. resources.ApplyResources(this.tEditCognome, "tEditCognome");
  204. this.tEditCognome.Name = "tEditCognome";
  205. //
  206. // tEditNome
  207. //
  208. resources.ApplyResources(this.tEditNome, "tEditNome");
  209. this.tEditNome.Name = "tEditNome";
  210. //
  211. // tEditAltezza
  212. //
  213. resources.ApplyResources(this.tEditAltezza, "tEditAltezza");
  214. this.tEditAltezza.Name = "tEditAltezza";
  215. //
  216. // tEditPeso
  217. //
  218. resources.ApplyResources(this.tEditPeso, "tEditPeso");
  219. this.tEditPeso.Name = "tEditPeso";
  220. //
  221. // bEdit
  222. //
  223. resources.ApplyResources(this.bEdit, "bEdit");
  224. this.bEdit.Name = "bEdit";
  225. this.bEdit.UseVisualStyleBackColor = true;
  226. this.bEdit.Click += new System.EventHandler(this.bEdit_Click);
  227. //
  228. // bRemove
  229. //
  230. resources.ApplyResources(this.bRemove, "bRemove");
  231. this.bRemove.Name = "bRemove";
  232. this.bRemove.UseVisualStyleBackColor = true;
  233. this.bRemove.Click += new System.EventHandler(this.bRemove_Click);
  234. //
  235. // label8
  236. //
  237. resources.ApplyResources(this.label8, "label8");
  238. this.label8.Name = "label8";
  239. //
  240. // label9
  241. //
  242. resources.ApplyResources(this.label9, "label9");
  243. this.label9.Name = "label9";
  244. //
  245. // label10
  246. //
  247. resources.ApplyResources(this.label10, "label10");
  248. this.label10.Name = "label10";
  249. //
  250. // label11
  251. //
  252. resources.ApplyResources(this.label11, "label11");
  253. this.label11.Name = "label11";
  254. //
  255. // Form1
  256. //
  257. resources.ApplyResources(this, "$this");
  258. this.Controls.Add(this.label11);
  259. this.Controls.Add(this.label10);
  260. this.Controls.Add(this.label9);
  261. this.Controls.Add(this.label8);
  262. this.Controls.Add(this.bRemove);
  263. this.Controls.Add(this.bEdit);
  264. this.Controls.Add(this.tEditPeso);
  265. this.Controls.Add(this.tEditAltezza);
  266. this.Controls.Add(this.tEditNome);
  267. this.Controls.Add(this.tEditCognome);
  268. this.Controls.Add(this.tCercaMatricola);
  269. this.Controls.Add(this.label7);
  270. this.Controls.Add(this.label6);
  271. this.Controls.Add(this.label5);
  272. this.Controls.Add(this.label4);
  273. this.Controls.Add(this.label3);
  274. this.Controls.Add(this.label2);
  275. this.Controls.Add(this.tMatricola);
  276. this.Controls.Add(this.tCognome);
  277. this.Controls.Add(this.tNome);
  278. this.Controls.Add(this.tAltezza);
  279. this.Controls.Add(this.tPeso);
  280. this.Controls.Add(this.bAdd);
  281. this.Controls.Add(this.lPes);
  282. this.Controls.Add(this.lAlt);
  283. this.Controls.Add(this.bMinPeso);
  284. this.Controls.Add(this.bMediaAlt);
  285. this.Controls.Add(this.bCanc);
  286. this.Controls.Add(this.bVisualizzaR);
  287. this.Controls.Add(this.dgv);
  288. this.Controls.Add(this.tNum);
  289. this.Controls.Add(this.bVisualizza);
  290. this.Controls.Add(this.bInserisci);
  291. this.Controls.Add(this.label1);
  292. this.Name = "Form1";
  293. this.Load += new System.EventHandler(this.Form1_Load);
  294. ((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit();
  295. this.ResumeLayout(false);
  296. this.PerformLayout();
  297.  
  298. }
  299.  
  300. private void Form1_Load(object sender, EventArgs e)
  301. {
  302. bVisualizza.Enabled = false;
  303. bVisualizzaR.Enabled = false;
  304.  
  305. dgv.ColumnCount = 5;
  306. dgv.RowCount = 1;
  307. dgv.Columns[0].HeaderText = "Matricola";
  308. dgv.Columns[1].HeaderText = "Cognome";
  309. dgv.Columns[2].HeaderText = "Nome";
  310. dgv.Columns[3].HeaderText = "Altezza";
  311. dgv.Columns[4].HeaderText = "Peso";
  312. }
  313.  
  314. private void bInserisci_Click(object sender, EventArgs e)
  315. {
  316. n = Int16.Parse(tNum.Text);
  317. alunno = new Alunno[20];
  318.  
  319. bVisualizza.Enabled = true;
  320. bVisualizzaR.Enabled = true;
  321.  
  322. for (int i = 0; i < n; i++)
  323. {
  324. alunno[i].matricola = Interaction.InputBox("Dammi la matricola" + (i + 1));
  325. alunno[i].cognome = Interaction.InputBox("Dammi la cognome" + (i + 1));
  326. alunno[i].nome = Interaction.InputBox("Dammi la nome" + (i + 1));
  327. alunno[i].altezza = Convert.ToDouble(Interaction.InputBox("Dammi la altezza" + (i + 1)).Replace(".", ","));
  328. alunno[i].peso = Convert.ToDouble(Interaction.InputBox("Dammi la peso" + (i + 1)).Replace(".", ","));
  329. }
  330. }
  331.  
  332. private void bVisualizza_Click(object sender, EventArgs e)
  333. {
  334. dgv.RowCount = n;
  335.  
  336. for (int i = 0; i < n; i++)
  337. {
  338. dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
  339. dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
  340. dgv.Rows[i].Cells[2].Value = alunno[i].nome;
  341. dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
  342. dgv.Rows[i].Cells[4].Value = alunno[i].peso;
  343. }
  344. }
  345.  
  346. private void bVisualizzaR_Click(object sender, EventArgs e)
  347. {
  348. for (int i = 0; i < n; i++)
  349. {
  350. string[] riga = { alunno[i].matricola, alunno[i].cognome, alunno[i].nome, Convert.ToString(alunno[i].altezza), Convert.ToString(alunno[i].peso) };
  351. dgv.Rows.Add(riga);
  352. }
  353. }
  354.  
  355. private void bCanc_Click(object sender, EventArgs e)
  356. {
  357. dgv.Rows.Clear();
  358. }
  359.  
  360. private void bMediaAlt_Click(object sender, EventArgs e)
  361. {
  362. double num = 0;
  363. for (int i = 0; i < n; i++)
  364. num += alunno[i].altezza;
  365. num /= n;
  366.  
  367. lAlt.Text = Convert.ToString(num);
  368. }
  369.  
  370. private void bMinPeso_Click(object sender, EventArgs e)
  371. {
  372. double min = alunno[0].peso;
  373. for (int i = 0; i < n; i++)
  374. if (alunno[i].peso < min) min = alunno[i].peso;
  375.  
  376. lPes.Text = Convert.ToString(min);
  377. }
  378.  
  379. private void cercaMatricola(object sender, KeyEventArgs e)
  380. {
  381. for (int i = 0; i < n; i++)
  382. {
  383. if (tCercaMatricola.Text == alunno[i].matricola)
  384. {
  385. tEditCognome.Text = alunno[i].cognome;
  386. tEditNome.Text = alunno[i].nome;
  387. tEditAltezza.Text = Convert.ToString(alunno[i].altezza);
  388. tEditPeso.Text = Convert.ToString(alunno[i].peso);
  389. }
  390. }
  391. }
  392.  
  393. private void bEdit_Click(object sender, EventArgs e)
  394. {
  395. for (int i = 0; i < n; i++)
  396. {
  397. if (tCercaMatricola.Text == alunno[i].matricola)
  398. {
  399. alunno[i].cognome = tEditCognome.Text;
  400. alunno[i].nome = tEditNome.Text;
  401. alunno[i].altezza = Convert.ToDouble(tEditAltezza.Text);
  402. alunno[i].peso = Convert.ToDouble(tEditPeso.Text);
  403. }
  404. }
  405.  
  406. dgv.RowCount = n;
  407.  
  408. for (int i = 0; i < n; i++)
  409. {
  410. dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
  411. dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
  412. dgv.Rows[i].Cells[2].Value = alunno[i].nome;
  413. dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
  414. dgv.Rows[i].Cells[4].Value = alunno[i].peso;
  415. }
  416. }
  417.  
  418. private void bRemove_Click(object sender, EventArgs e)
  419. {
  420. for (int i = 0; i < n; i++)
  421. {
  422. if (tCercaMatricola.Text == alunno[i].matricola)
  423. {
  424. for (int j = i; j < n; j++)
  425. alunno[j] = alunno[(j + 1)];
  426. }
  427. }
  428.  
  429. n -= 1;
  430.  
  431. dgv.RowCount = n;
  432.  
  433. for (int i = 0; i < n; i++)
  434. {
  435. dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
  436. dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
  437. dgv.Rows[i].Cells[2].Value = alunno[i].nome;
  438. dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
  439. dgv.Rows[i].Cells[4].Value = alunno[i].peso;
  440. }
  441. }
  442.  
  443. private void bAdd_Click(object sender, EventArgs e)
  444. {
  445. alunno[n].matricola = tMatricola.Text;
  446. alunno[n].cognome = tCognome.Text;
  447. alunno[n].nome = tNome.Text;
  448. alunno[n].altezza = Convert.ToDouble(tAltezza.Text);
  449. alunno[n].peso = Convert.ToDouble(tPeso.Text);
  450.  
  451. n++;
  452.  
  453. dgv.RowCount = n;
  454.  
  455. for (int i = 0; i < n; i++)
  456. {
  457. dgv.Rows[i].Cells[0].Value = alunno[i].matricola;
  458. dgv.Rows[i].Cells[1].Value = alunno[i].cognome;
  459. dgv.Rows[i].Cells[2].Value = alunno[i].nome;
  460. dgv.Rows[i].Cells[3].Value = alunno[i].altezza;
  461. dgv.Rows[i].Cells[4].Value = alunno[i].peso;
  462. }
  463. }
  464. }
  465. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement