Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsFormsApplication4
- {
- public partial class Form1 : Form
- {
- public enum pc_type { table, mono, nettop, gaming };
- public struct PC
- {
- public string firm;
- public pc_type state;
- public int ram, hdd_capacity;
- public bool tv;
- public PC(string FIRM, pc_type t, int RAM, int HDD, bool TV)
- {
- firm = FIRM;
- state = t;
- ram = RAM;
- hdd_capacity = HDD;
- tv = TV;
- }
- }
- public pc_type radio_state()
- {
- if (radioButton1.Checked) { return pc_type.table; }
- else if (radioButton2.Checked) { return pc_type.mono; }
- else if (radioButton3.Checked) { return pc_type.nettop; }
- else { return pc_type.gaming; }
- }
- public void radio_off()
- {
- radioButton1.Checked = false;
- radioButton2.Checked = false;
- radioButton3.Checked = false;
- radioButton4.Checked = false;
- }
- public Form1()
- {
- InitializeComponent();
- radioButton1.Checked = true;
- string path = Environment.CurrentDirectory + "\\pc.dat";
- BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate));
- writer.Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string path = Environment.CurrentDirectory + "\\pc.dat";
- PC input = new PC(textBox1.Text, radio_state(), Convert.ToInt32(textBox2.Text),
- Convert.ToInt32(textBox3.Text), checkBox1.Checked);
- BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Append));
- writer.Write(input.firm);
- writer.Write(Convert.ToInt32(input.state));
- writer.Write(input.ram);
- writer.Write(input.hdd_capacity);
- writer.Write(input.tv);
- writer.Close();
- }
- private void radioButton1_Click(object sender, EventArgs e)
- {
- radio_off();
- radioButton1.Checked = true;
- }
- private void radioButton2_Click(object sender, EventArgs e)
- {
- radio_off();
- radioButton2.Checked = true;
- }
- private void radioButton3_Click(object sender, EventArgs e)
- {
- radio_off();
- radioButton3.Checked = true;
- }
- private void radioButton4_Click(object sender, EventArgs e)
- {
- radio_off();
- radioButton4.Checked = true;
- }
- private void button3_Click(object sender, EventArgs e)
- {
- richTextBox1.Clear();
- string path = Environment.CurrentDirectory + "\\pc.dat";
- BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open));
- if(reader.PeekChar() == - 1)
- {
- reader.Close();
- richTextBox1.Text += "File is empty. \n";
- return;
- }
- while(reader.PeekChar() > -1 )
- {
- richTextBox1.Text += "////////\n";
- richTextBox1.Text += reader.ReadString() + '\n';
- string type = "pc type: ";
- switch(reader.ReadInt32())
- {
- case 1: { type += "table"; break; }
- case 2: { type += "mono"; break; }
- case 3: { type += "nettop"; break; }
- case 4: { type += "gaming"; break; }
- }
- richTextBox1.Text += type + '\n';
- richTextBox1.Text += "ram: " + reader.ReadInt32() + '\n';
- richTextBox1.Text += "hdd capacity: " + reader.ReadInt32() + '\n';
- if(reader.ReadBoolean())
- {
- richTextBox1.Text += "have tv \n";
- }
- else
- {
- richTextBox1.Text += "dont have tv \n";
- }
- }
- reader.Close();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- string path = Environment.CurrentDirectory + "\\pc.dat";
- BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create));
- writer.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment