Advertisement
Guest User

binarka

a guest
Jan 28th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.13 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.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace Program_8_app
  13. {
  14.  
  15. public partial class Form1 : Form
  16. {
  17.  
  18. int a;
  19. int[] tab = new int[10];
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24. //public List<int> Inty = new List<int>();
  25. //public List<double> Double = new List<double>();
  26. //public List<string> Stringi = new List<string>();
  27.  
  28. private void szukaj_Click(object sender, EventArgs e)
  29. {
  30. FolderBrowserDialog fbd = new FolderBrowserDialog();
  31. if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  32. {
  33. sciezka.Text = fbd.SelectedPath + "/test.bin";
  34. }
  35. }
  36.  
  37.  
  38. private void zapis_int_Click(object sender, EventArgs e)
  39. {
  40. text.Clear();
  41. string ścieżka = sciezka.Text;
  42.  
  43. string s = pomoc.Text;
  44. String[] split;
  45. split = s.Split(' ');
  46. a = split.Length;
  47.  
  48. List<int> Inty = new List<int>();
  49. List<double> Double = new List<double>();
  50. List<string> Stringi = new List<string>();
  51.  
  52. if (int1.Checked)
  53. {
  54. spr.Text = "";
  55. FileStream fs = File.OpenWrite(ścieżka);
  56. BinaryWriter bw = new BinaryWriter(fs);
  57.  
  58. for (int i = 0; i < split.Length; i++)
  59. {
  60. int liczba = int.Parse(split[i]);
  61. Inty.Add(liczba);
  62. }
  63. bw.Write(Inty.Count);
  64. foreach (int liczba in Inty)
  65. {
  66. bw.Write(liczba);
  67. }
  68. bw.Close();
  69. fs.Close();
  70. }
  71. else if(double2.Checked)
  72. {
  73. spr.Text = "";
  74.  
  75. FileStream fs = File.OpenWrite(ścieżka);
  76. BinaryWriter bw = new BinaryWriter(fs);
  77.  
  78. for(int i = 0; i < split.Length; i++)
  79. {
  80. double liczba = double.Parse(split[i]);
  81. Double.Add(liczba);
  82. }
  83. bw.Write(Double.Count);
  84. foreach (double liczba in Double)
  85. {
  86. bw.Write(liczba);
  87. }
  88.  
  89. bw.Close();
  90. fs.Close();
  91. }
  92. else if (string3.Checked)
  93. {
  94. spr.Text = "";
  95. FileStream fs = File.OpenWrite(ścieżka);
  96. BinaryWriter bw = new BinaryWriter(fs);
  97. for (int i = 0; i < split.Length; i++)
  98. {
  99. Stringi.Add(split[i]);
  100. }
  101. bw.Write(Stringi.Count);
  102. foreach (string liczba in Stringi)
  103. {
  104. bw.Write(liczba);
  105. }
  106. bw.Close();
  107. fs.Close();
  108. }
  109. else if (osoby4.Checked)
  110. {
  111. try
  112. {
  113. error.Text = "";
  114. string sa = pomoc.Text; //1 , 3 , 5
  115. String[] split2 = sa.Split(' ');
  116. FileStream fs = File.OpenWrite(ścieżka);
  117. BinaryWriter bw = new BinaryWriter(fs);
  118.  
  119. bw.Write(split2[1]);
  120. bw.Write(split2[3]);
  121. bw.Write(int.Parse(split2[5]));
  122. bw.Close();
  123. fs.Close();
  124. }
  125. catch (FormatException)
  126. {
  127. error.Text = "error";
  128. }
  129.  
  130.  
  131.  
  132.  
  133. }
  134. else if(all5.Checked)
  135. {
  136. try
  137. {
  138.  
  139. spr.Text = "";
  140.  
  141. FileStream fs = File.OpenWrite(ścieżka);
  142. BinaryWriter bw = new BinaryWriter(fs);
  143.  
  144. string ścieżka2 = "I:/sharp/Hawryluk/Program 8 app/test2.bin";
  145. FileStream fs2 = File.OpenWrite(ścieżka2);
  146. BinaryWriter bw2 = new BinaryWriter(fs2);
  147. string sa = pomoc.Text;
  148.  
  149. for (int i = 0; i < split.Length; i++)
  150. {
  151. Stringi.Add(split[i]);
  152. }
  153. bw.Write(Stringi.Count);
  154.  
  155. for (int i = 0; i < split.Length; i++)
  156. {
  157. try
  158. {
  159. int Int = int.Parse(split[i]);
  160. bw.Write(Int);
  161. bw2.Write(1);
  162. }
  163. catch (FormatException)
  164. {
  165. try
  166. {
  167. double Doubla = double.Parse(split[i]);
  168. bw.Write(Doubla);
  169. bw2.Write(2);
  170. }
  171. catch (FormatException)
  172. {
  173. string String = split[i];
  174. bw.Write(String);
  175. bw2.Write(3);
  176. }
  177. }
  178. }
  179. bw2.Close();
  180. fs2.Close();
  181. bw.Close();
  182. fs.Close();
  183.  
  184. }
  185. catch (FormatException)
  186. {
  187. error.Text = "error";
  188. }
  189. }
  190. else
  191. {
  192. spr.Text = "wybierz rodzaj !";
  193. }
  194. }
  195.  
  196. private void koniec_Click(object sender, EventArgs e)
  197. {
  198. this.Close();
  199. }
  200.  
  201. private void czysc_Click(object sender, EventArgs e)
  202. {
  203. text.Clear();
  204. spr.Text = "";
  205. pomoc.Clear();
  206. }
  207.  
  208. private void odczyt_Click_1(object sender, EventArgs e)
  209. {
  210. text.Clear();
  211. string ścieżka = sciezka.Text;
  212.  
  213.  
  214. if (int1.Checked)
  215. {
  216.  
  217. spr.Text = "";
  218. FileStream fs2 = File.OpenRead(ścieżka);
  219. BinaryReader br = new BinaryReader(fs2);
  220.  
  221. a = br.ReadInt32();
  222. for (int i = 0; i < a; i++)
  223. {
  224. text.Text += br.ReadInt32().ToString() + " ";
  225. }
  226.  
  227. br.Close();
  228. fs2.Close();
  229. }
  230. else if (double2.Checked)
  231. {
  232. spr.Text = "";
  233. FileStream fs2 = File.OpenRead(ścieżka);
  234. BinaryReader br = new BinaryReader(fs2);
  235.  
  236. a = br.ReadInt32();
  237. for (int i = 0; i < a; i++)
  238. {
  239. text.Text += br.ReadDouble().ToString() + " ";
  240. }
  241. br.Close();
  242. fs2.Close();
  243. }
  244. else if (string3.Checked)
  245. {
  246. spr.Text = "";
  247. FileStream fs2 = File.OpenRead(ścieżka);
  248. BinaryReader br = new BinaryReader(fs2);
  249.  
  250. a = br.ReadInt32();
  251. for (int i = 0; i < a; i++)
  252. {
  253. text.Text += br.ReadString() + " ";
  254. }
  255. br.Close();
  256. fs2.Close();
  257. }
  258. else if (osoby4.Checked)
  259. {
  260. spr.Text = "";
  261. FileStream fs2 = File.OpenRead(ścieżka);
  262. BinaryReader br = new BinaryReader(fs2);
  263. for (int i = 0; i < 5; i++)
  264. {
  265. if (i == 2)
  266. {
  267. text.Text += ", "+br.ReadInt32().ToString() + " lat";
  268. }
  269. else
  270. {
  271. text.Text += br.ReadString() + " ";
  272. }
  273. }
  274. br.Close();
  275. fs2.Close();
  276.  
  277. }
  278. else if (all5.Checked)
  279. {
  280. spr.Text = "";
  281. FileStream fs = File.OpenRead(ścieżka);
  282. BinaryReader br = new BinaryReader(fs);
  283.  
  284. string ścieżka2 = "I:/sharp/Hawryluk/Program 8 app/test2.bin";
  285. FileStream fs2 = File.OpenRead(ścieżka2);
  286. BinaryReader br2 = new BinaryReader(fs2);
  287.  
  288. a = br.ReadInt32();
  289. for (int i = 0; i < a; i++)
  290. {
  291. int pomocznica = br2.ReadInt32();
  292. if (pomocznica==1) text.Text += br.ReadInt32().ToString() + "[i] ";
  293. else if (pomocznica==2) text.Text += br.ReadDouble().ToString() + "[d] ";
  294. else text.Text += br.ReadString() + "[s] ";
  295. }
  296. br2.Close();
  297. fs2.Close();
  298.  
  299. br.Close();
  300. fs.Close();
  301.  
  302.  
  303. }
  304. else
  305. {
  306. spr.Text = "wybierz rodzaj !";
  307. }
  308.  
  309.  
  310.  
  311. }
  312.  
  313. private void osoby4_CheckedChanged(object sender, EventArgs e)
  314. {
  315. if(osoby4.Checked)
  316. {
  317. pomoc.Text = "";
  318. pomoc.Text = "Imie: " + System.Environment.NewLine + "Nazwisko: " + System.Environment.NewLine + "Wiek: ";
  319. }
  320. }
  321.  
  322.  
  323. }
  324.  
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement