Advertisement
Guest User

lv3

a guest
Mar 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace LV4_1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.        
  16.         //Kolekcija  (Queue - FIFO)  (Stack - LIFO)
  17.         Queue<Osoba> osobaCollection = new Queue<Osoba>();
  18.  
  19.         //Deklariramo listu
  20.         List<string> imeList = new List<string>();
  21.  
  22.         //Deklariramo niz
  23.         string[] imeArray = { "Maja", "Marko", "Ivan", "Iva", "Andrija" };
  24.  
  25.  
  26.  
  27.         public Form1()
  28.         {
  29.             InitializeComponent();
  30.         }
  31.  
  32.         private void btnPrint_Click(object sender, EventArgs e)
  33.         {
  34.  
  35.  
  36.             if (rbCollection.Checked)
  37.             {  
  38.                 richTextBox1.Clear();
  39.                 richTextBox1.Text = "Ime \t Prezime \t Godina rodjenja\n";
  40.                 foreach (Osoba os in osobaCollection)
  41.                 {
  42.                     richTextBox1.Text += String.Format("{0} \t {1} \t {2}\n", os.Ime, os.Prezime, os.GodinaRodjenja); ;
  43.                 }
  44.  
  45.                 richTextBox1.Text += "\n";
  46.                 richTextBox1.Text += "* Obrnuti redoslijed *\n";
  47.                 richTextBox1.Text += "**********************\n";
  48.  
  49.  
  50.                 foreach (Osoba os in osobaCollection.Reverse())
  51.                 {
  52.                     richTextBox1.Text += String.Format("{0} \t {1} \t {2}\n", os.Ime, os.Prezime, os.GodinaRodjenja); ;
  53.                 }
  54.  
  55.                 lblNoItems.Text = osobaCollection.Count.ToString();
  56.             }
  57.             else if (rbList.Checked)
  58.             {
  59.                 //Ispis
  60.                 richTextBox1.Clear();
  61.                 foreach (string ime in imeList)
  62.                 {
  63.                     richTextBox1.Text += ime + "\n";
  64.                 }
  65.  
  66.                 richTextBox1.Text += "\n";
  67.                 richTextBox1.Text += "* Sortirano *\n";
  68.                 richTextBox1.Text += "*************\n";
  69.  
  70.                 imeList.Sort();
  71.  
  72.                 foreach (string ime in imeList)
  73.                 {
  74.                     richTextBox1.Text += ime + "\n";
  75.                 }
  76.  
  77.                 lblNoItems.Text = imeList.Count.ToString();
  78.             }
  79.             else if (rbArray.Checked)
  80.             {
  81.                 //Ispis
  82.                 richTextBox1.Clear();
  83.                 for (int i = 0; i <= 4; i++)
  84.                 {
  85.                     richTextBox1.Text += imeArray[i] + "\n";
  86.                 }
  87.  
  88.                 richTextBox1.Text += "\n";
  89.                 richTextBox1.Text += "* Sortirano *\n";
  90.                 richTextBox1.Text += "*************\n";
  91.                 Array.Sort(imeArray);
  92.  
  93.                 foreach (string ime in imeArray)
  94.                 {
  95.                     richTextBox1.Text += ime + "\n";
  96.                 }
  97.  
  98.                 lblNoItems.Text = imeArray.Length.ToString();
  99.             }
  100.  
  101.  
  102.  
  103.            
  104.         }
  105.  
  106.         private void button1_Click(object sender, EventArgs e)
  107.         {
  108.             if (rbCollection.Checked)
  109.             {
  110.                 //Unos
  111.                 Osoba os = new Osoba(txtIme.Text, txtPrezime.Text, Convert.ToInt32(txtGodinaRodjenja.Text));
  112.                 osobaCollection.Enqueue(os);
  113.             }
  114.             else if (rbList.Checked)
  115.             {
  116.                 //Unos
  117.                 imeList.Add(txtIme.Text);
  118.             }
  119.         }
  120.  
  121.         private void btnOpen_Click(object sender, EventArgs e)
  122.         {
  123.             if (openFileDialog1.ShowDialog()==DialogResult.OK){
  124.                 this.Text=openFileDialog1.FileName;
  125.                 System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName);
  126.                 richTextBox2.Text=sr.ReadToEnd();
  127.                 sr.Close();
  128.             }
  129.         }
  130.  
  131.         private void btnFont_Click(object sender, EventArgs e)
  132.         {
  133.             if (fontDialog1.ShowDialog() == DialogResult.OK)
  134.             {
  135.                 richTextBox2.Font = fontDialog1.Font;
  136.             }
  137.         }
  138.  
  139.         private void btnColor_Click(object sender, EventArgs e)
  140.         {
  141.             if (colorDialog1.ShowDialog() == DialogResult.OK)
  142.             {
  143.                 richTextBox2.ForeColor = colorDialog1.Color;
  144.             }
  145.         }
  146.  
  147.         private void btnMultiply_Click(object sender, EventArgs e)
  148.         {
  149.             int a, b, rez;
  150.             try
  151.             {
  152.                 a = Convert.ToInt32(rbA.Text);
  153.                 b = Convert.ToInt32(rbB.Text);
  154.                 rez = a * b;
  155.                 rbResult.Text = rez.ToString();
  156.             }
  157.             catch(Exception)
  158.             {
  159.                 MessageBox.Show("Morate unijeti cijeli broj");
  160.                 //MessageBox.Show("Morate unijeti cijeli broj","Upozorenje", --> primjer za uredit taj messagebox
  161.             }
  162.            
  163.         }
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement