Advertisement
Guest User

Untitled

a guest
May 5th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 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.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace testApp
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public List<int> A = new List<int>();
  17. public List<int> B = new List<int>();
  18. public List<int> C = new List<int>();
  19.  
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24.  
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27. try
  28. {
  29. int x1 = Convert.ToInt32(textBox1.Text);
  30. int x2 = Convert.ToInt32(textBox2.Text);
  31.  
  32. if (radioButton1.Checked)
  33. {
  34. for (int i = x1; i <= x2; i++)
  35. {
  36. A.Add(i);
  37. }
  38. }
  39. else if (radioButton2.Checked)
  40. {
  41. for (int i = x1; i <= x2; i++)
  42. {
  43. B.Add(i);
  44. }
  45. }
  46. else if (radioButton3.Checked)
  47. {
  48. for (int i = x1; i <= x2; i++)
  49. {
  50. C.Add(i);
  51. }
  52. }
  53. else
  54. {
  55. MessageBox.Show("Bez pośpiechu, " +
  56. "musisz wybrać do której grupy chcesz dodać liczby :)");
  57. }
  58.  
  59. }
  60. catch (Exception ex)
  61. {
  62. MessageBox.Show("Ups wystąpił jakiś błąd: " + ex.ToString());
  63. //throw;
  64. }
  65. }
  66.  
  67. private void otwórzToolStripMenuItem_Click(object sender, EventArgs e)
  68. {
  69. string[] lines = { };
  70. try
  71. {
  72. lines = System.IO.File.ReadAllLines("dokumentTekstowy.txt");
  73. }
  74. catch (Exception ex)
  75. {
  76. MessageBox.Show(ex.ToString());
  77. //throw;
  78. }
  79.  
  80. int space = 0;
  81.  
  82. foreach (string line in lines)
  83. {
  84.  
  85. if (space == 0)
  86. {
  87. if (line != "") A.Add(Convert.ToInt32(line));
  88. else space++;
  89. }
  90. else if (space == 1)
  91. {
  92. if (line != "") B.Add(Convert.ToInt32(line));
  93. else space++;
  94. }
  95. else if (space == 2)
  96. {
  97. if (line != "") C.Add(Convert.ToInt32(line));
  98. else space++;
  99. }
  100. }
  101. }
  102.  
  103. private void button2_Click(object sender, EventArgs e)
  104.  
  105. {
  106. try
  107. {
  108. int x = Convert.ToInt32(textBox3.Text);
  109. foreach (int Item in A)
  110. {
  111. if (Item == x)
  112. {
  113. listView1.Items.Add(Item.ToString() + "Br1");
  114.  
  115. }
  116. }
  117. foreach (int Item in B)
  118. {
  119. if (Item == x)
  120. {
  121. listView1.Items.Add(Item.ToString() + "Br2");
  122. }
  123. }
  124. foreach (int Item in C)
  125. {
  126. if (Item == x)
  127. {
  128. listView1.Items.Add(Item.ToString() + "Br3");
  129. }
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. MessageBox.Show(ex.ToString());
  135. //throw
  136. }
  137.  
  138. }
  139.  
  140. private void zapiszToolStripMenuItem_Click_1(object sender, EventArgs e)
  141. {
  142. TextWriter tw = new StreamWriter("myFile.txt");
  143. foreach (int item in A)
  144. {
  145. tw.WriteLine(item.ToString());
  146. }
  147. tw.Close();
  148. }
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement