Guest User

Untitled

a guest
Jan 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 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 WindowsFormsApplication4
  13. {
  14.  
  15.  
  16.  
  17. public partial class Form1 : Form
  18. {
  19. public enum pc_type { table, mono, nettop, gaming };
  20. public struct PC
  21. {
  22. public string firm;
  23. public pc_type state;
  24. public int ram, hdd_capacity;
  25. public bool tv;
  26. public PC(string FIRM, pc_type t, int RAM, int HDD, bool TV)
  27. {
  28. firm = FIRM;
  29. state = t;
  30. ram = RAM;
  31. hdd_capacity = HDD;
  32. tv = TV;
  33. }
  34. }
  35. public pc_type radio_state()
  36. {
  37. if (radioButton1.Checked) { return pc_type.table; }
  38. else if (radioButton2.Checked) { return pc_type.mono; }
  39. else if (radioButton3.Checked) { return pc_type.nettop; }
  40. else { return pc_type.gaming; }
  41. }
  42. public void radio_off()
  43. {
  44. radioButton1.Checked = false;
  45. radioButton2.Checked = false;
  46. radioButton3.Checked = false;
  47. radioButton4.Checked = false;
  48. }
  49. public Form1()
  50. {
  51. InitializeComponent();
  52. radioButton1.Checked = true;
  53. string path = Environment.CurrentDirectory + "\\pc.dat";
  54. BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate));
  55. writer.Close();
  56. }
  57.  
  58. private void button1_Click(object sender, EventArgs e)
  59. {
  60. string path = Environment.CurrentDirectory + "\\pc.dat";
  61. PC input = new PC(textBox1.Text, radio_state(), Convert.ToInt32(textBox2.Text),
  62. Convert.ToInt32(textBox3.Text), checkBox1.Checked);
  63. BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Append));
  64. writer.Write(input.firm);
  65. writer.Write(Convert.ToInt32(input.state));
  66. writer.Write(input.ram);
  67. writer.Write(input.hdd_capacity);
  68. writer.Write(input.tv);
  69. writer.Close();
  70.  
  71. }
  72.  
  73. private void radioButton1_Click(object sender, EventArgs e)
  74. {
  75. radio_off();
  76. radioButton1.Checked = true;
  77. }
  78.  
  79. private void radioButton2_Click(object sender, EventArgs e)
  80. {
  81. radio_off();
  82. radioButton2.Checked = true;
  83. }
  84.  
  85. private void radioButton3_Click(object sender, EventArgs e)
  86. {
  87. radio_off();
  88. radioButton3.Checked = true;
  89. }
  90.  
  91. private void radioButton4_Click(object sender, EventArgs e)
  92. {
  93. radio_off();
  94. radioButton4.Checked = true;
  95. }
  96.  
  97. private void button3_Click(object sender, EventArgs e)
  98. {
  99. richTextBox1.Clear();
  100. string path = Environment.CurrentDirectory + "\\pc.dat";
  101. BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open));
  102. if(reader.PeekChar() == - 1)
  103. {
  104. reader.Close();
  105. richTextBox1.Text += "File is empty. \n";
  106. return;
  107. }
  108. while(reader.PeekChar() > -1 )
  109. {
  110. richTextBox1.Text += "////////\n";
  111. richTextBox1.Text += reader.ReadString() + '\n';
  112. string type = "pc type: ";
  113. switch(reader.ReadInt32())
  114. {
  115. case 1: { type += "table"; break; }
  116. case 2: { type += "mono"; break; }
  117. case 3: { type += "nettop"; break; }
  118. case 4: { type += "gaming"; break; }
  119. }
  120. richTextBox1.Text += type + '\n';
  121. richTextBox1.Text += "ram: " + reader.ReadInt32() + '\n';
  122. richTextBox1.Text += "hdd capacity: " + reader.ReadInt32() + '\n';
  123. if(reader.ReadBoolean())
  124. {
  125. richTextBox1.Text += "have tv \n";
  126. }
  127. else
  128. {
  129. richTextBox1.Text += "dont have tv \n";
  130. }
  131.  
  132. }
  133. reader.Close();
  134.  
  135. }
  136.  
  137. private void button2_Click(object sender, EventArgs e)
  138. {
  139. string path = Environment.CurrentDirectory + "\\pc.dat";
  140. BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create));
  141. writer.Close();
  142. }
  143. }
  144. }
Add Comment
Please, Sign In to add comment