Last active
October 5, 2016 18:31
-
-
Save dz0/140bac9f0d89c5a42f0b35f716331319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Windows; | |
| using System.Windows.Controls; | |
| using System.Windows.Data; | |
| using System.Windows.Documents; | |
| using System.Windows.Input; | |
| using System.Windows.Media; | |
| using System.Windows.Media.Imaging; | |
| using System.Windows.Navigation; | |
| using System.Windows.Shapes; | |
| namespace WpfApplication1 | |
| { | |
| public class Finansas | |
| { | |
| public int kiek; | |
| public string uz_ka; | |
| public Finansas(int kiek, string uz_ka) | |
| { | |
| this.kiek = kiek; // "this" reiskia dabartini objekta | |
| this.uz_ka = uz_ka; | |
| } | |
| public override string ToString() | |
| { | |
| return uz_ka + ": " + kiek; | |
| } | |
| } | |
| /// <summary> | |
| /// Interaction logic for MainWindow.xaml | |
| /// </summary> | |
| public partial class MainWindow : Window | |
| { | |
| public MainWindow() | |
| { | |
| InitializeComponent(); | |
| } | |
| // Prideti finansa (Create) | |
| private void button_Click(object sender, RoutedEventArgs e) | |
| { | |
| // paimam duomenis is laukeliu | |
| string uz_ka = tb_uz_ka.Text; | |
| int kiek = Convert.ToInt32(tb_kiek.Text); | |
| // sukuriam objekta | |
| Finansas fin = new Finansas(kiek, uz_ka); // Create | |
| // idedam i sarasa | |
| listBox.Items.Add( fin ); // bus Read | |
| skaiciuoti_balansa(); | |
| } | |
| void skaiciuoti_balansa() | |
| { | |
| // susumuojam balansa | |
| int suma = 0; | |
| foreach (Finansas f in listBox.Items) | |
| { | |
| suma += f.kiek; // reik, kad "kiek" butu "public" | |
| } | |
| label.Content = suma; | |
| } | |
| // pasirinkti is saraso (Read) | |
| private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) | |
| { | |
| // pradzioj patikrinam, jei nieko nepazymeta | |
| if (listBox.SelectedItem == null) return; // nieko nedarom | |
| Finansas fin = (Finansas) listBox.SelectedItem; | |
| tb_kiek.Text = fin.kiek.ToString(); // skaiciu paverciam tekstu | |
| tb_uz_ka.Text = fin.uz_ka; | |
| } | |
| // atnaujinti (Update) | |
| private void button1_Click(object sender, RoutedEventArgs e) | |
| { | |
| // paimam duomenis is laukeliu | |
| string uz_ka = tb_uz_ka.Text; | |
| int kiek = Convert.ToInt32(tb_kiek.Text); | |
| // paimam dabartini elementa, ir atnaujinam jam reiksmes | |
| Finansas fin = (Finansas)listBox.SelectedItem; | |
| fin.uz_ka = uz_ka; | |
| fin.kiek = kiek; | |
| listBox.Items.Refresh(); // atsviezinam vaizda | |
| skaiciuoti_balansa(); | |
| } | |
| // istrinti (Delete) | |
| private void button2_Click(object sender, RoutedEventArgs e) | |
| { | |
| listBox.Items.Remove(listBox.SelectedItem); // pasalinam pazymeta elementa | |
| // galima ir pagal numeri: listBox.Items.RemoveAt(listBox.SelectedIndex); | |
| listBox.Items.Refresh(); | |
| skaiciuoti_balansa(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment