Advertisement
StevanovicMilan

Vežba 09, Zadatak 1

Dec 1st, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.21 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.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace Vezba_09_2017
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void dodajToolStripMenuItem_Click(object sender, EventArgs e)
  22.         {
  23.             AddForm add = new AddForm();
  24.             if(add.ShowDialog() == DialogResult.OK)
  25.             {
  26.                 Predmet p = add.PodaciOPredmetu;
  27.                 listBox1.Items.Add(p);
  28.             }
  29.         }
  30.  
  31.         private void izmeniToolStripMenuItem_Click(object sender, EventArgs e)
  32.         {
  33.             if (listBox1.SelectedIndex < 0) return;
  34.  
  35.             Predmet p = (Predmet)listBox1.Items[listBox1.SelectedIndex];
  36.             AddForm add = new AddForm();
  37.             add.PodaciOPredmetu = p;
  38.             add.ShowDialog();
  39.             if (add.DialogResult == DialogResult.OK)
  40.             {
  41.                 listBox1.Items[listBox1.SelectedIndex] = add.PodaciOPredmetu;
  42.             }
  43.  
  44.         }
  45.        
  46.         private void obrišiToolStripMenuItem_Click(object sender, EventArgs e)
  47.         {
  48.             if (listBox1.SelectedIndex < 0) return;
  49.             listBox1.Items.RemoveAt(listBox1.SelectedIndex);
  50.         }
  51.  
  52.         private void obrišiSveToolStripMenuItem_Click(object sender, EventArgs e)
  53.         {
  54.             listBox1.Items.Clear();
  55.         }
  56.  
  57.         private void eksportujToolStripMenuItem_Click(object sender, EventArgs e)
  58.         {
  59.             SaveFileDialog saveDialog = new SaveFileDialog();
  60.             saveDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
  61.             if (saveDialog.ShowDialog() == DialogResult.OK)
  62.             {
  63.                 using (StreamWriter sw = new StreamWriter(saveDialog.FileName, false))
  64.                     foreach (Predmet predmet in listBox1.Items)
  65.                         sw.WriteLine(predmet.ToString());
  66.                 MessageBox.Show("Success");
  67.             }
  68.         }
  69.  
  70.         private void izlazToolStripMenuItem_Click(object sender, EventArgs e)
  71.         {
  72.             Close();
  73.         }
  74.  
  75.         private void oProgramuToolStripMenuItem_Click(object sender, EventArgs e)
  76.         {
  77.             MessageBox.Show("Editor predmeta.");
  78.         }
  79.     }
  80. }
  81.  
  82.  
  83.  
  84. using System;
  85. using System.Collections.Generic;
  86. using System.Linq;
  87. using System.Text;
  88. using System.Threading.Tasks;
  89.  
  90. namespace Vezba_09_2017
  91. {
  92.     public class Predmet
  93.     {
  94.         public string Naziv { get; set; }
  95.         public string Nastavnik { get; set; }
  96.         public string Udzbenik { get; set; }
  97.         public int Casovi { get; set; }
  98.  
  99.         public override string ToString()
  100.         {
  101.             return Naziv;
  102.         }
  103.     }
  104. }
  105.  
  106.  
  107.  
  108. using System;
  109. using System.Collections.Generic;
  110. using System.ComponentModel;
  111. using System.Data;
  112. using System.Drawing;
  113. using System.Linq;
  114. using System.Text;
  115. using System.Threading.Tasks;
  116. using System.Windows.Forms;
  117.  
  118. namespace Vezba_09_2017
  119. {
  120.     public partial class AddForm : Form
  121.     {
  122.         public Predmet PodaciOPredmetu { get; set; }
  123.         public AddForm()
  124.         {
  125.             InitializeComponent();
  126.         }
  127.  
  128.         private void button1_Click(object sender, EventArgs e)
  129.         {
  130.             PodaciOPredmetu = new Predmet();
  131.             PodaciOPredmetu.Naziv = textBox1.Text;
  132.             PodaciOPredmetu.Nastavnik = textBox2.Text;
  133.             PodaciOPredmetu.Udzbenik = textBox3.Text;
  134.             PodaciOPredmetu.Casovi = (int)numericUpDown1.Value;
  135.  
  136.             DialogResult = DialogResult.OK;
  137.             Close();
  138.         }
  139.  
  140.         private void button2_Click(object sender, EventArgs e)
  141.         {
  142.             DialogResult = DialogResult.Cancel;
  143.             Close();
  144.         }
  145.  
  146.         private void AddForm_Load(object sender, EventArgs e)
  147.         {
  148.             textBox1.Text = PodaciOPredmetu.Naziv;
  149.             textBox2.Text = PodaciOPredmetu.Nastavnik;
  150.             textBox3.Text = PodaciOPredmetu.Udzbenik;
  151.             numericUpDown1.Value = PodaciOPredmetu.Casovi;
  152.         }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement