k_vychodilova

Banka

Mar 20th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8.  
  9. namespace Ucet_Banka
  10. {
  11.     class Ucet {
  12.         public int Cislo { get; private set; }
  13.         public string Nazev { get; set; }
  14.         public decimal Zustatek { get; set; }
  15.  
  16.         public Ucet(int cislo, string nazev)
  17.         {
  18.             Cislo = cislo;
  19.             Nazev = nazev;
  20.             Zustatek = 10000;
  21.         }
  22.  
  23.         virtual public void Preved(decimal castka, int cisloUctu)
  24.         {
  25.             Zustatek -= castka;
  26.             // TODO: az budeme mit server, prevedeme na jiny ucet, zatim jen snizime zustatek
  27.         }
  28.  
  29.         public override string ToString()
  30.         {
  31.             return $"{Cislo} {Nazev}";
  32.         }
  33.     }
  34.  
  35.     class UcetPoplatky : Ucet
  36.     {
  37.         public decimal Poplatek { get; set; }
  38.         public UcetPoplatky(int cislo, string nazev) : base(cislo, nazev)
  39.         {
  40.             Poplatek = 10;
  41.         }
  42.  
  43.         public override void Preved(decimal castka, int cisloUctu)
  44.         {
  45.             Zustatek -= castka;
  46.             Zustatek -= Poplatek;
  47.         }
  48.     }
  49.         class Polozka
  50.     {   public DateTime Datum { get; set; }
  51.         public int Hodnota { get; set; }
  52.  
  53.         public Polozka(int hodnota)
  54.         {
  55.             Datum = DateTime.Now;
  56.             Hodnota = hodnota;
  57.         }
  58.         public override string ToString()
  59.         {
  60.             return $"{Datum:MM/dd/yyyy} {Hodnota:C}";
  61.         }
  62.     }
  63.     class StackForm : Form
  64.     {
  65.         private TableLayoutPanel panel = new TableLayoutPanel();
  66.         private ComboBox combo = null;
  67.         private BindingList<PolozkaVypisu> polozky = null;
  68.         // private BindingSource source = null;
  69.  
  70.         public StackForm()
  71.         {
  72.  
  73.  
  74.             panel.AutoSize = true;
  75.             panel.Dock = DockStyle.Fill;
  76.             panel.ColumnCount = 4;  //pocet sloupců
  77.             panel.RowCount = 8;   //pocet radku
  78.  
  79.             panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
  80.             panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
  81.             panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
  82.             panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));    //rozdeleni sloupcu,procentualni rozdeleni
  83.  
  84.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));          //rozdeleni radku
  85.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
  86.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
  87.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
  88.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
  89.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
  90.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
  91.             panel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
  92.  
  93.             panel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
  94.  
  95.             Label Vyberucet = new Label() { Text = "Vyber účet:" };
  96.             Label Nadpis = new Label() { Text = "Bankovní účet" };
  97.             Label Nadpis2 = new Label() { Text = "Výpis účtu" };
  98.  
  99.             combo = new ComboBox();
  100.             combo.Items.Add("Běžný účet");
  101.             combo.Items.Add("Účet s poplatky");
  102.             combo.Items.Add("Účet 3 převody zdarma");
  103.  
  104.  
  105.             Label jmeno_majitele = new Label() { Text = "Jmeno majitele" };
  106.  
  107.             ListBox listbox = new ListBox();
  108.             listbox.Dock = DockStyle.Fill;
  109.             listbox.DataSource = polozky;
  110.  
  111.             BindingSource bs = new BindingSource(polozky, null);
  112.  
  113.  
  114.             DataGridView grid = new DataGridView();
  115.             grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  116.             grid.Dock = DockStyle.Fill;
  117.             grid.DataSource = bs;
  118.             grid.AutoGenerateColumns = false;
  119.  
  120.            DataGridViewTextBoxColumn Datum_cas = new DataGridViewTextBoxColumn();
  121.             Datum_cas.HeaderText = "Datum a cas";
  122.             Datum_cas.DataPropertyName = nameof(Polozka.Datum);
  123.             Datum_cas.DefaultCellStyle.Format = "MM/dd/yyyy  HH:mm:ss.fff";
  124.            
  125.  
  126.             DataGridViewTextBoxColumn Typ_platby = new DataGridViewTextBoxColumn();
  127.             Datum_cas.HeaderText = "Typ platby";
  128.             //Datum_cas.DataPropertyName = nameof(Polozka.Hodnota);
  129.             // Datum_cas.DefaultCellStyle.Format = "MM/dd/yyyy  HH:mm:ss.fff";
  130.             grid.Columns.Add(Datum_cas);
  131.             grid.Columns.Add(Typ_platby);
  132.  
  133.  
  134.             TextBox Zadavani_jmena = new TextBox() { Text = "Nové jméno" };
  135.             Button ulozit_jmeno = new Button() { Text = "Uložit jmeno" };
  136.  
  137.  
  138.             Label zustatek = new Label() { Text = "Zustatek" };
  139.             TextBox Vypis_zustatku = new TextBox();
  140.  
  141.             Label PLatba_zuctu = new Label() { Text = "Platba z uctu: " };
  142.  
  143.             Label zadej_ucet = new Label() { Text = "Zadej ucet:" };
  144.             TextBox okno_zadejucet = new TextBox();
  145.             Button nahodne = new Button() { Text = "Nahodne" };
  146.             nahodne.Click += (sender, e) =>
  147.             {
  148.                 int nahoda;
  149.                 Random random = new Random();
  150.                 nahoda = random.Next(1, 4);
  151.                 if (nahoda == 1)
  152.                 {
  153.                     okno_zadejucet.Text = "Bezny ucet";
  154.                 }
  155.                 if (nahoda == 2)
  156.                 {
  157.                     okno_zadejucet.Text = "Účet s poplatky";
  158.                 }
  159.                 else
  160.                 {
  161.                     okno_zadejucet.Text = "Účet 3 převody zdarma";
  162.                 }
  163.  
  164.                
  165.             };
  166.  
  167.             Label zadej_castku = new Label() { Text = "Zadej castku:" };
  168.             TextBox okno_zadejcastku = new TextBox();
  169.             Button Odeslat = new Button() { Text = "Odeslat" };
  170.             Odeslat.Click += (sender, e) =>
  171.             {
  172.                 // int nove = (int)okno_zadejcastku.?????;
  173.                 //polozky.Add(new Polozka());
  174.            
  175.  
  176.             };
  177.  
  178.  
  179.             // Button potvrdit_vyber = new Button() { Text = "Potvrd vyber." };
  180.             //  potvrdit_vyber.AutoSize = true;
  181.             /* potvrdit_vyber.Click += (sender, e) =>
  182.              {
  183.                 //zobrazit zustatek
  184.  
  185.              };*/
  186.  
  187.             //  panel.Controls.Add(listbox, 3,2);
  188.             panel.Controls.Add(Zadavani_jmena, 2, 2);
  189.             panel.Controls.Add(ulozit_jmeno, 2, 3);
  190.             panel.Controls.Add(Nadpis,0,0);
  191.             panel.Controls.Add(Nadpis2, 3, 0);
  192.             panel.Controls.Add(Vyberucet, 0, 1);  //sloupec radek
  193.             panel.Controls.Add(combo,1 , 1);
  194.             panel.Controls.Add(grid, 3,1);
  195.             panel.SetRowSpan(grid, 4);
  196.             panel.SetRowSpan(listbox, 3);
  197.  
  198.             panel.Controls.Add(jmeno_majitele, 0, 2);
  199.             panel.Controls.Add(zustatek, 0, 4);
  200.             panel.Controls.Add(Vypis_zustatku, 1, 4);
  201.             panel.Controls.Add(PLatba_zuctu, 0, 5);
  202.             panel.Controls.Add(zadej_ucet, 0, 6);
  203.             panel.Controls.Add(okno_zadejucet, 1, 6);
  204.             panel.Controls.Add(nahodne, 2, 6);
  205.             panel.Controls.Add(zadej_castku, 0, 7);
  206.             panel.Controls.Add(okno_zadejcastku, 1, 7);
  207.             panel.Controls.Add(Odeslat, 2, 7);
  208.  
  209.            
  210.  
  211.  
  212.            
  213.  
  214.             //panel.Controls.Add(potvrdit_vyber, 2, 1);
  215.  
  216.  
  217.             this.Controls.Add(panel);
  218.  
  219.         }
  220.      
  221.  
  222.     }
  223.  
  224.     internal class PolozkaVypisu
  225.     {
  226.     }
  227.  
  228.     class Program
  229.     {
  230.         static void Main(string[] args)
  231.         {
  232.             StackForm form = new StackForm();
  233.  
  234.             Application.EnableVisualStyles();
  235.             Application.Run(form);
  236.  
  237.  
  238.  
  239.  
  240.         }
  241.     }
  242. }
Add Comment
Please, Sign In to add comment