-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaboratorio.cs
316 lines (287 loc) · 10.6 KB
/
Laboratorio.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
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 WindowsFormsApplication3
{
public partial class Laboratorio : Form
{
const string archivoDrogas = "../../Archivos/droga.txt";
const string archivoRemedios = "../../Archivos/remedio.txt";
const string archivoVentas = "../../Archivos/venta.txt";
public static List<Droga> lstDrogas = new List<Droga>();
public static List<Remedio> lstRemedio = new List<Remedio>();
public static List<Remedio> lstRemedioByPrice = new List<Remedio>();
public static List<Remedio> lstRemedioByRecaudacion = new List<Remedio>();
public static List<Venta> lstVentas = new List<Venta>();
public static List<Usuario> lstUsuarios = new List<Usuario>();
public int recaudacionTotal;
public double precioPromedio;
public int masDrogaOcho;
int drogaMenosUsada;
int drogaMasCara;
int remedioMasBarato;
public Laboratorio(List<Usuario> _lstUsuarios)
{
lstUsuarios = _lstUsuarios;
populateDrogas(archivoDrogas);
populateRemedios(archivoRemedios);
populateVentas(archivoVentas);
InitializeComponent();
refreshAll();
txtBoxRecaudacion.ReadOnly = true;
txtBoxPromedio.ReadOnly = true;
txtBoxDroga8.ReadOnly = true;
txtBoxCheapest.ReadOnly = true;
txtBoxExpensive.ReadOnly = true;
txtBoxLessUsed.ReadOnly = true;
}
public void refreshAll()
{
getRecaudacionRemedio();
recaudacionTotal = getRecaudacionTotal();
txtBoxRecaudacion.Text = recaudacionTotal.ToString();
Console.WriteLine("Recaudacion Total: " + recaudacionTotal);
porcentajeRemedio(recaudacionTotal);
precioPromedio = lstRemedio.Average(value => value.valor);
Console.WriteLine("Precio Promedio: " + precioPromedio);
txtBoxPromedio.Text = precioPromedio.ToString();
masDrogaOcho = getDrogaOcho();
Console.WriteLine("remedioMasDroga8: " + masDrogaOcho);
txtBoxDroga8.Text = masDrogaOcho.ToString();
drogaMenosUsada = getMenosUsada();
Console.WriteLine("drogaMenosUsada: " + drogaMenosUsada);
txtBoxLessUsed.Text = drogaMenosUsada.ToString();
drogaMasCara = getDrogaMasCara();
Console.WriteLine("drogaMasCara: " + drogaMasCara);
txtBoxExpensive.Text = drogaMasCara.ToString();
remedioMasBarato = getRemedioMasBarato();
Console.WriteLine("remedioMasbarato: " + remedioMasBarato);
txtBoxCheapest.Text = remedioMasBarato.ToString();
}
static void populateDrogas(string archivo)
{
lstDrogas.Clear();
FileStream file = new FileStream(archivo, FileMode.Open);
StreamReader archivoReader = new StreamReader(file);
string [] temparr = { } ;
while (!(archivoReader.Peek() == -1))
{
Droga tempObj = new Droga();
temparr = archivoReader.ReadLine().Split(';');
tempObj.codigo = Int32.Parse(temparr[0]);
tempObj.valor = Int32.Parse(temparr[1]);
lstDrogas.Add(tempObj);
}
file.Close();
}
static void populateRemedios(string archivo)
{
lstRemedio.Clear();
FileStream file = new FileStream(archivo, FileMode.Open);
StreamReader archivoReader = new StreamReader(file);
string[] tempvar;
while (!(archivoReader.Peek() == -1))
{
Remedio tempObj = new Remedio();
tempvar = archivoReader.ReadLine().Split(';');
tempObj.codigo = Int32.Parse(tempvar[0]);
tempObj.droga = Int32.Parse(tempvar[1]);
tempObj.cantidad = Int32.Parse(tempvar[2]);
tempObj.valor = tempObj.cantidad * lstDrogas.Find(e=> tempObj.droga == e.codigo).valor;
lstRemedio.Add(tempObj);
}
file.Close();
}
static void populateVentas(string archivo)
{
lstVentas.Clear();
FileStream file = new FileStream(archivo, FileMode.Open);
StreamReader archivoReader = new StreamReader(file);
string[] tempvar;
while (!(archivoReader.Peek() == -1))
{
Venta tempObj = new Venta();
tempvar = archivoReader.ReadLine().Split(';');
tempObj.factura = Int32.Parse(tempvar[0]);
tempObj.remedio = Int32.Parse(tempvar[1]);
tempObj.cantidad = Int32.Parse(tempvar[2]);
lstVentas.Add(tempObj);
}
file.Close();
}
static int getRecaudacionTotal()
{
var total = 0;
foreach (Remedio remedio in lstRemedio)
{
total += remedio.recaudacion;
}
return total;
}
static void getRecaudacionRemedio()
{
foreach (Remedio remedio in lstRemedio)
{
remedio.recaudacion = 0;
foreach (Venta venta in lstVentas)
{
if (venta.remedio == remedio.codigo)
{
remedio.recaudacion += venta.cantidad * remedio.valor;
}
}
Console.WriteLine("Se recaudo:" + remedio.recaudacion + " remedio: " + remedio.codigo);
}
}
static void porcentajeRemedio(int total)
{
foreach (Remedio remedio in lstRemedio)
{
remedio.porcentaje = (remedio.recaudacion * 1000) / total;
remedio.porcentaje /= 1000;
Console.WriteLine("Porcentaje: " + remedio.porcentaje + " Remedio: " + remedio.codigo);
}
}
static int getDrogaOcho()
{
int codMayor = 0;
int cantMayor = 0;
foreach(Remedio remedio in lstRemedio)
{
if (remedio.droga == 8)
{
if (remedio.cantidad > cantMayor)
{
codMayor = remedio.codigo;
cantMayor = remedio.cantidad;
}
}
}
return codMayor;
}
static int getMenosUsada()
{
int lessUsed = 0;
int quantityLessUsed = 0;
foreach(Droga droga in lstDrogas)
{
int quantity = 0;
foreach(Remedio remedio in lstRemedio)
{
if (remedio.droga == droga.codigo)
{
quantity += remedio.cantidad;
}
}
if (quantityLessUsed == 0)
{
lessUsed = droga.codigo;
quantityLessUsed = quantity;
}
if (quantity < quantityLessUsed)
{
lessUsed = droga.codigo;
quantityLessUsed = quantity;
}
}
return lessUsed;
}
static int getDrogaMasCara()
{
int codMasCara = 0;
int precMasCara = 0;
foreach (Droga droga in lstDrogas)
{
if (droga.valor > precMasCara)
{
codMasCara = droga.codigo;
precMasCara = droga.valor;
}
}
return codMasCara;
}
static int getRemedioMasBarato()
{
int codCheapest = 0;
int precCheapest = 0;
foreach (Remedio remedio in lstRemedio)
{
if (precCheapest == 0)
{
precCheapest = remedio.valor;
codCheapest = remedio.codigo;
}
if (remedio.valor < precCheapest)
{
codCheapest = remedio.codigo;
precCheapest = remedio.valor;
}
}
return codCheapest;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void altaBajaYModiicacionToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void btnAbmUser_Click(object sender, EventArgs e)
{
frmUsuario frmusuario = new frmUsuario(lstUsuarios);
frmusuario.Show();
}
private void btnAbmRemedio_Click(object sender, EventArgs e)
{
frmRemedio frmremedio = new frmRemedio(lstRemedio,lstDrogas);
frmremedio.Show();
}
private void btnAbmVenta_Click(object sender, EventArgs e)
{
frmVenta frmventa = new frmVenta(lstVentas,lstRemedio);
frmventa.Show();
}
private void btnAbmDroga_Click(object sender, EventArgs e)
{
frmDroga frmdroga = new frmDroga(lstDrogas);
frmdroga.Show();
}
private void btnShowValores_Click(object sender, EventArgs e)
{
lstBoxInfo.Items.Clear();
foreach (Remedio remedio in lstRemedio)
{
string tempString = "Remedio: " + remedio.codigo + "\trecaudacion: $" + remedio.recaudacion;
lstBoxInfo.Items.Add(tempString);
}
}
private void btnPromedio_Click(object sender, EventArgs e)
{
lstBoxInfo.Items.Clear();
foreach (Remedio remedio in lstRemedio)
{
string tempString = "Remedio: " + remedio.codigo + "\tvalor: $" + remedio.valor;
lstBoxInfo.Items.Add(tempString);
}
}
private void btnPorcentaje_Click(object sender, EventArgs e)
{
lstBoxInfo.Items.Clear();
foreach (Remedio remedio in lstRemedio)
{
string tempString = "Remedio: " + remedio.codigo + "\tporcentaje: " + remedio.porcentaje;
lstBoxInfo.Items.Add(tempString);
}
}
private void btnRefresh_Click(object sender, EventArgs e)
{
refreshAll();
}
}
}