Advertisement
k_vychodilova

ucet c#

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