-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edit.cs
177 lines (158 loc) · 6.84 KB
/
Edit.cs
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace course_job
{
public partial class Edit : Form
{
public static bool returnAccesPassword = false;
public int index1;
List<Clients> clients = new List<Clients>();
public static string pathclientDB = @"C:\coursejobDB\clients";
public Edit(int index)
{
index1 = index;
InitializeComponent();
using (BinaryReader reader = new BinaryReader(File.Open(pathclientDB, FileMode.Open)))
{
// index = 0;
while (reader.PeekChar() > -1)
{
Clients clients1 = new Clients();
clients1.FIO1 = reader.ReadString();
clients1.CardNumber = reader.ReadDouble();
clients1.Job = reader.ReadString();
clients1.Cost = reader.ReadDouble();
clients1.CheckPayment = reader.ReadBoolean();
clients1.Dolg = reader.ReadDouble();
clients.Add(clients1);
}
}
FIOField.Text = clients[index].FIO1;
NOCField.Text = clients[index].CardNumber.ToString();
comboBox1.Text = clients[index].Job;
CostField.Text = clients[index].Cost.ToString();
if (clients[index].CheckPayment == true)
checkBox1.Checked = true;
else
checkBox2.Checked = true;
Debt.Text = clients[index].Dolg.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
returnAccesPassword = false;
PasswordCheck check = new PasswordCheck();
check.ShowDialog();
if (returnAccesPassword == true)
{
button1.Enabled = true;
FIOField.Enabled = true;
NOCField.Enabled = true;
comboBox1.Enabled = true;
CostField.Enabled = true;
checkBox1.Enabled = true;
checkBox2.Enabled = true;
Debt.Enabled = true;
button2.Enabled = false;
button3.Enabled = true;
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
checkBox2.Checked = false;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Clients temp = new Clients();
if (checkBox1.Checked == true || checkBox2.Checked == true)
{
if (Double.TryParse(NOCField.Text, out temp.cardNumber) &&
Double.TryParse(CostField.Text, out temp.cost) &&
Double.TryParse(Debt.Text, out temp.dolg) &&
FIOField.Text.Length > 0 && comboBox1.Text.Length > 0)
if (temp.Cost > 0)
if (checkBox2.Checked == true && temp.Dolg != temp.Cost)
MessageBox.Show("Что-то не так с задолженностью, отметкой об оплате или долгом");
else
using (BinaryWriter bf = new BinaryWriter(File.Open(pathclientDB, FileMode.Open)))
{
if (temp.Dolg <= temp.Cost && temp.Dolg > -1)
{
temp.FIO1 = FIOField.Text;
temp.Job = comboBox1.Text;
if (checkBox1.Checked == true)
temp.CheckPayment = true;
if (checkBox2.Checked == true)
temp.CheckPayment = false;
clients[index1] = temp;
for (int i = 0; i < clients.Count; i++)
{
bf.Write(clients[i].FIO1);
bf.Write(clients[i].CardNumber);
bf.Write(clients[i].Job);
bf.Write(clients[i].Cost);
bf.Write(clients[i].CheckPayment);
bf.Write(clients[i].Dolg);
}
MessageBox.Show("Данные отредактированы");
}
else
{
MessageBox.Show("Проверьте на корректность поля с задолженностью и долгом");
}
}
else
{
MessageBox.Show("Стоимость услуг должна быть больше 0");
}
else
{
MessageBox.Show("Неправильный ввод в поля с численным вводом");
}
}
else
{
MessageBox.Show("Выберите отметку об оплате");
}
}
catch (Exception)
{
MessageBox.Show("ошибка сохранения обьекта в файл");
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true)
checkBox1.Checked = false;
}
private void button3_Click(object sender, EventArgs e)
{
clients.RemoveAt(index1);
File.Delete(pathclientDB);
using (BinaryWriter bf = new BinaryWriter(File.Open(pathclientDB, FileMode.Create)))
{
for (int i = 0; i < clients.Count; i++)
{
bf.Write(clients[i].FIO1);
bf.Write(clients[i].CardNumber);
bf.Write(clients[i].Job);
bf.Write(clients[i].Cost);
bf.Write(clients[i].CheckPayment);
bf.Write(clients[i].Dolg);
}
}
MessageBox.Show("Клиент удален");
this.Hide();
}
}
}