1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
[Serializable]
public class Tovar
{
public string tip;
public int stoim;
public int kolvo;
public static int erunda;
public Tovar(int kolvo,int stoim)
{
this.stoim = stoim;
this.kolvo = kolvo;
}
}
public ArrayList tovar = new ArrayList();
public bool flag;
public void zapf()
{
// Form2 f2 = new Form2();
// Создаем поток для сериализации:
FileStream StreamOut = new FileStream("tovar.dat",
FileMode.Create, FileAccess.Write);
// Используем двоичный формат:
BinaryFormatter fmt = new BinaryFormatter();
fmt.Serialize(StreamOut, tovar); // Сериализуем объекты
StreamOut.Close(); // Закрываем поток
}
public void vvod()
{
int i = 0;
// Создаем поток для десериализации:
FileStream StreamIn = new FileStream("tovar.dat",
FileMode.Open, FileAccess.Read);
// Используем двоичный формат:
BinaryFormatter fmt = new BinaryFormatter();
tovar = (ArrayList)fmt.Deserialize(StreamIn);//Десериализуем
Tovar.erunda = 0;
foreach (Tovar t in tovar)
{ Tovar.erunda++; i++; }
Tovar.erunda--;
StreamIn.Close();
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a, b;
if (radioButton1.Checked == true)
{
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
Tovar tv0 = new Tovar(a, b);
tv0.tip = "Канцелярский товар,";
tovar.Add(tv0);
richTextBox1.AppendText("ТИП:" + tv0.tip + " С Количеством:" + tv0.kolvo + ", Стоимостью:" + tv0.stoim + "\r\n");
}
if (radioButton2.Checked == true)
{
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
Tovar tv1 = new Tovar(a, b);
tv1.tip = "Хозяйственный товар,";
tovar.Add(tv1);
richTextBox1.AppendText("ТИП:" + tv1.tip + " С Количеством:" + tv1.kolvo + ", Стоимостью:" + tv1.stoim + "\r\n");
}
if (radioButton3.Checked == true)
{
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
Tovar tv2 = new Tovar(a, b);
tv2.tip = "Продукт,";
tovar.Add(tv2);
richTextBox1.AppendText("ТИП:" + tv2.tip + " С Количеством:" + tv2.kolvo + ", Стоимостью:" + tv2.stoim + "\r\n");
}
if (radioButton4.Checked == true)
{
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
Tovar tv3 = new Tovar(a, b);
tv3.tip = "Строительный товар,";
tovar.Add(tv3);
richTextBox1.AppendText("ТИП:" + tv3.tip + " С Количеством:" + tv3.kolvo + ", Стоимостью:" + tv3.stoim + "\r\n");
}
if (radioButton5.Checked == true)
{
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
Tovar tv4 = new Tovar(a, b);
tv4.tip = "Запчасти,";
tovar.Add(tv4);
richTextBox1.AppendText("ТИП:" + tv4.tip + " С Количеством:" + tv4.kolvo + ", Стоимостью:" + tv4.stoim + "\r\n");
}
if (radioButton6.Checked == true)
{
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
Tovar tv5 = new Tovar(a, b);
tv5.tip = "Промышленный товар,";
tovar.Add(tv5);
richTextBox1.AppendText("ТИП:" + tv5.tip + " С Количеством:" + tv5.kolvo + ", Стоимостью:" + tv5.stoim + "\r\n");
}
}
private void button2_Click(object sender, EventArgs e)
{
zapf();
MessageBox.Show("Запись произведена успешно =)");
}
private void button3_Click(object sender, EventArgs e)
{
vvod();
MessageBox.Show("Чтение прозведено успешно =)");
}
private void button4_Click(object sender, EventArgs e)
{
flag = true;
foreach (Tovar T1 in tovar)
{
richTextBox1.AppendText("ТИП:" + T1.tip + " С Количеством:" + T1.kolvo + ", Стоимостью:" + T1.stoim + "\r\n");
}
}
private void button5_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
}
}
} |