-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf_avance.cs
286 lines (259 loc) · 9.74 KB
/
f_avance.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
using System;
using System.Data.OleDb;
using System.Globalization;
using System.Windows.Forms;
namespace Aiche_Bois
{
public partial class f_avance : Form
{
/// <summary>
/// this is a message custom box
/// </summary>
f_message message;
/// <summary>
/// c'est l'access a extereiur Client data base
/// </summary>
private readonly OleDbConnection connection = new OleDbConnection();
/// <summary>
/// perndre l'id de formulaire presedent;
/// </summary>
private long idClient;
/// <summary>
/// c'est le variable pour verifier le check box
/// </summary>
bool checkAvance;
/// <summary>
/// c'est formulaire de traitment
/// </summary>
/// <param name="idClient"></param>
public f_avance(String idClient)
{
/*
* get idClient from fomr client
*/
this.idClient = Convert.ToInt64(idClient);
/*
* set database connection
*/
connection.ConnectionString = Program.Path;
InitializeComponent();
}
/// <summary>
/// charger les donnees a partir de l'id prendre
/// </summary>
public void remplirData()
{
/**
* upload database id
*/
try
{
connection.Open();
var command = new OleDbCommand
{
Connection = connection,
CommandText = "SELECT * FROM query WHERE idClient = @idClient"
};
command.Parameters.AddWithValue("@idClient", idClient);
OleDbDataReader readerClient = command.ExecuteReader();
while (readerClient.Read())
{
l_id_client.Text = "N" + Convert.ToInt32(readerClient["idClient"]).ToString("D4");
l_nom_client.Text = readerClient["nomClient"].ToString();
l_date_client.Text = Convert.ToDateTime(readerClient["dateClient"]).ToString("d");
checkAvance = Convert.ToBoolean((readerClient["cavance"]).ToString());
l_price_avance_client.Text = Convert.ToDouble(readerClient["prixTotalAvance"]).ToString("F2");
l_price_rest_client.Text = Convert.ToDouble(readerClient["rest"]).ToString("F2");
l_price_total_client.Text = Convert.ToDouble(readerClient["total"]).ToString("F2");
}
readerClient = null;
command = null;
connection.Close();
}
catch (Exception ex)
{
connection.Close();
LogFile.Message(ex);
}
}
/// <summary>
/// on affiche la formulaire
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Avance_Load(object sender, EventArgs e)
{
/*
* upload data from data base
*/
remplirData();
b_save.Enabled = false;
}
/// <summary>
/// c'est button modifeir le prix avance est confirmer le triatmenet
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnConfirm_Click(object sender, EventArgs e)
{
/**
* updating database id
*/
try
{
connection.Open();
if (ckMines.Checked)
{
if (double.Parse(t_mines_price.Text) > double.Parse(l_price_avance_client.Text))
{
message = new f_message("le montant doit etre moins à montant payée", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_mines_price.Clear();
t_mines_price.Focus();
connection.Close();
return;
}
var command = new OleDbCommand
{
Connection = connection,
CommandText = "UPDATE client SET " +
"prixTotalAvance = prixTotalAvance - @prix where idClient = @idClient" + idClient
};
command.Parameters.AddWithValue("@prix", t_mines_price.Text);
command.Parameters.AddWithValue("@idClient", idClient);
command.ExecuteNonQuery();
command = null;
t_mines_price.Clear();
t_mines_price.Focus();
connection.Close();
}
else
{
if (double.Parse(t_price_add_cLient.Text) > double.Parse(l_price_rest_client.Text))
{
message = new f_message("le Prix à payer est plus grand a le reste", "Attention", true, FontAwesome.Sharp.IconChar.ExclamationTriangle);
message.ShowDialog();
t_price_add_cLient.Clear();
t_price_add_cLient.Focus();
connection.Close();
return;
}
var command = new OleDbCommand
{
Connection = connection,
CommandText = "UPDATE client SET " +
"prixTotalAvance = prixTotalAvance + @prix where idClient = @idClient" + idClient
};
command.Parameters.AddWithValue("@prix", t_price_add_cLient.Text);
command.Parameters.AddWithValue("@idClient", idClient);
command.ExecuteNonQuery();
command = null;
t_price_add_cLient.Clear();
t_price_add_cLient.Focus();
connection.Close();
}
// call function to full a fields
remplirData();
}
catch (Exception ex)
{
connection.Close();
LogFile.Message(ex);
}
}
/// <summary>
/// c'est evenet verifier le tye des donnees saisir
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPrix_KeyPress(object sender, KeyPressEventArgs e)
{
char comVer = Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
if (double.TryParse(Clipboard.GetText(), out double vlr) && e.KeyChar == 22)
{
e.Handled = true;
}
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != comVer)
{
e.Handled = true;
}
if (e.KeyChar == comVer && (((sender as TextBox).Text.IndexOf(comVer) > -1) || (sender as TextBox).TextLength == 0))
{
e.Handled = true;
}
}
/// <summary>
/// verifier c'est la champs n'est pas vide
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPrix_TextChanged(object sender, EventArgs e)
{
if (!ckMines.Checked)
{
if (t_price_add_cLient.TextLength > 0)
b_save.Enabled = true;
else
b_save.Enabled = false;
}
}
/// <summary>
/// verify field text if not empty
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtMines_TextChanged(object sender, EventArgs e)
{
if (ckMines.Checked)
{
if (t_mines_price.TextLength > 0)
b_save.Enabled = true;
else
b_save.Enabled = false;
}
}
/// <summary>
/// c'est le button pour annuler le traitement
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAnnuler_Click(object sender, EventArgs e)
{
Close();
}
/// <summary>
/// if button is checked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ckMines_CheckedChanged(object sender, EventArgs e)
{
t_mines_price.Enabled = ckMines.Checked;
t_price_add_cLient.Enabled = !ckMines.Checked;
if (ckMines.Checked)
t_mines_price.Focus();
else
t_price_add_cLient.Focus();
}
/// <summary>
/// textBox Style on Enter event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtMines_Enter(object sender, EventArgs e)
{
((TextBox)sender).BackColor = System.Drawing.Color.FromArgb(47, 47, 47);
((TextBox)sender).ForeColor = System.Drawing.Color.FromArgb(255, 170, 0);
}
/// <summary>
/// textBox Style on Leave event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtMines_Leave(object sender, EventArgs e)
{
((TextBox)sender).BackColor = System.Drawing.Color.FromArgb(255, 244, 228);
((TextBox)sender).ForeColor = System.Drawing.Color.FromArgb(47, 47, 47);
}
}
}