Advertisement
k_vychodilova

zasobnik

Mar 20th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using System.ComponentModel;
  8.  
  9. namespace Cviko7._2 {
  10.  
  11.     class StackForm : Form
  12.     {
  13.         private TableLayoutPanel panel = new TableLayoutPanel();  //nebo null
  14.  
  15.         public StackForm()
  16.         {
  17.             panel.AutoSize = true;
  18.             panel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  19.             panel.Dock = DockStyle.Fill;
  20.  
  21.             panel.ColumnCount = 3;   //pocet sloupců
  22.             panel.RowCount = 3;   //pocet radku
  23.  
  24.             panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
  25.             panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
  26.             panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));    //rozdeleni sloupcu,procentualni rozdeleni
  27.  
  28.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));          //rozdelei radku
  29.             panel.RowStyles.Add(new RowStyle(SizeType.AutoSize));          //rozdelei radku
  30.             panel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
  31.  
  32.  
  33.             panel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
  34.  
  35.             BindingList<Polozka> Cisla = new BindingList<Polozka>()
  36.             {
  37.               new Polozka(5), new Polozka(6),new Polozka(7)
  38.  
  39.             };
  40.  
  41.             NumericUpDown numericUpDown = new NumericUpDown() { DecimalPlaces = 0 };
  42.             Button buttonpsh = new Button() { Text = "Push" };
  43.             buttonpsh.Click += (sender, e) =>
  44.             {
  45.                 int nove = (int)numericUpDown.Value;
  46.                 Cisla.Add(new Polozka(nove));
  47.  
  48.             };
  49.  
  50.             ListBox list_box_buffer = new ListBox();
  51.  
  52.             list_box_buffer.Dock = DockStyle.Fill;
  53.             list_box_buffer.DataSource = Cisla;
  54.  
  55.             BindingSource bs = new BindingSource(Cisla, null);
  56.  
  57.  
  58.             DataGridView grid = new DataGridView();
  59.             grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  60.             grid.Dock = DockStyle.Fill;
  61.             grid.DataSource = bs;
  62.             grid.AutoGenerateColumns = false;
  63.  
  64.             DataGridViewTextBoxColumn dtDatum = new DataGridViewTextBoxColumn();
  65.             dtDatum.HeaderText = "Dátum a čas";
  66.             dtDatum.DataPropertyName = nameof(Polozka.Datum);
  67.             dtDatum.DefaultCellStyle.Format = "MM/dd/yyyy  HH:mm:ss.fff";
  68.  
  69.             //hodnota
  70.             DataGridViewTextBoxColumn dtHodnota = new DataGridViewTextBoxColumn();
  71.             dtHodnota.HeaderText = "Hodnota";
  72.             dtHodnota.DataPropertyName = nameof(Polozka.Hodnota);
  73.             dtHodnota.DefaultCellStyle.Format = "C";
  74.  
  75.             grid.Columns.Add(dtDatum);
  76.             grid.Columns.Add(dtHodnota);
  77.  
  78.  
  79.  
  80.             TextBox textBox = new TextBox() { ReadOnly = true };
  81.             Button buttonPop = new Button() { Text = "Pop" };
  82.             buttonPop.Click += (sender, e) =>
  83.             {
  84.                 if (Cisla.Count > 0)
  85.                 {
  86.                     int lastIndex = Cisla.Count - 1;
  87.                     Polozka posledni = Cisla[lastIndex];
  88.                     Cisla.RemoveAt(lastIndex);
  89.  
  90.                     textBox.Text = posledni.ToString();
  91.                 }
  92.  
  93.             };
  94.  
  95.             Label radek_navic = new Label() { Text = "Zatim nic" };
  96.             radek_navic.Dock = DockStyle.Fill;
  97.             radek_navic.AutoSize = true;
  98.  
  99.  
  100.             bs.Position = 0;
  101.             bs.CurrentItemChanged += (sender, e) =>       //umoznuje zobrazit v lablu na co jsme klikli
  102.             {
  103.                 Polozka aktualni = bs.Current as Polozka;
  104.                 if (aktualni != null)
  105.                 {
  106.                     radek_navic.Text = aktualni.ToString();
  107.                 }
  108.  
  109.  
  110.             };
  111.  
  112.             panel.Controls.Add(numericUpDown, 0, 0);   //cisla oznacuji sloupec radek
  113.             panel.Controls.Add(buttonpsh, 1, 0);
  114.             panel.Controls.Add(grid, 2, 0);
  115.             panel.SetRowSpan(grid, 3);
  116.             panel.SetRowSpan(list_box_buffer, 2);
  117.             panel.Controls.Add(textBox, 0, 1);
  118.             panel.Controls.Add(buttonPop, 1, 1);
  119.             panel.Controls.Add(radek_navic, 0, 2);
  120.             panel.SetColumnSpan(radek_navic, 2);
  121.             Controls.Add(panel);
  122.  
  123.  
  124.         }
  125.  
  126.        
  127.     }
  128.     class Polozka{
  129.     public DateTime Datum { get; set; }
  130.     public int Hodnota { get; set; }
  131.  
  132.     public Polozka(int hodnota)
  133.     {
  134.         Datum = DateTime.Now;
  135.         Hodnota = hodnota;
  136.     }
  137.         public override string ToString()
  138.         {
  139.             return $"{Datum:MM/dd/yyyy} {Hodnota:C}";
  140.         }
  141.     }
  142.  
  143.     class Program
  144.     {
  145.         [STAThread]
  146.         static void Main(string[] args)
  147.         {
  148.         //pokud chceme velmi rychle pridavat na konec a odebirat od konce pouzijeme tridu stack
  149.         //Stack<int> zasobnik = new Stack<int>;
  150.        
  151.             //fronta odebira a uklada na zacatek  Queue
  152.            
  153.             StackForm form = new StackForm();
  154.  
  155.             Application.EnableVisualStyles();
  156.             Application.Run(form);
  157.  
  158.  
  159.  
  160.         }
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement