-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataContainer.cs
585 lines (507 loc) · 35.6 KB
/
DataContainer.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
namespace Tool
{
public class DataContainer
{
private static DataContainer instance = new DataContainer();
private List<Bestellposition> bestellungen;
private Dictionary<int, Teil> teile;
private Dictionary<int, Arbeitsplatz> arbeitsplatz;
private bool sonderproduktion = false;
private bool pufferChanged = false;
private int[] reihenfolge;
public double minLagerwertEnd = 0.0;
public double normalLagerwertEnd = 0.0;
public double maxLagerwertEnd = 0.0;
public double lagerwertStart = 0.0;
string openFile;
string saveFile;
string saveInputXML = "";
private bool ueberstundenErlaubt = true;
private Produktionsplanung prod;
private int periode = -1;
private bool xml = true;
public int AktuellePeriode
{
get { return periode; }
set { periode = value; }
}
public bool Xml
{
get { return xml; }
set { xml = value; }
}
private bool inet = false;
public bool Inet
{
get { return inet; }
set { inet = value; }
}
private DataContainer()
{
this.bestellungen = new List<Bestellposition>();
this.teile = new Dictionary<int, Teil>();
this.arbeitsplatz = new Dictionary<int, Arbeitsplatz>();
openFile = Application.StartupPath + "//output.jsp.xml";
saveFile = Application.StartupPath + "//input.xml";
}
#region Getter und Setter
/// <summary>
/// Gets the Data Cointainer instance.
/// </summary>
/// <value>The instance.</value>
public static DataContainer Instance
{
get
{
return instance;
}
}
public int[] Reihenfolge
{
get
{
return this.reihenfolge;
}
set
{
this.reihenfolge = value;
}
}
/// <summary>
///Liste aller kaufteil
/// </summary>
/// <value>The kaufteil list.</value>
public List<Kaufteil> KaufteilList
{
get
{
List<Kaufteil> res = new List<Kaufteil>();
foreach (KeyValuePair<int, Teil> kvp in this.teile)
{
if (kvp.Value is Kaufteil)
{
res.Add(kvp.Value as Kaufteil);
}
}
return res;
}
}
public List<Bestellposition> Bestellung
{
get
{
return this.bestellungen;
}
}
/// <summary>
/// Liste Aller Eteile
/// </summary>
/// <value>The E teil list.</value>
public List<ETeil> ETeilList
{
get
{
List<ETeil> res = new List<ETeil>();
foreach (KeyValuePair<int, Teil> kvp in this.teile)
{
if (kvp.Value is ETeil)
{
res.Add(kvp.Value as ETeil);
}
}
return res;
}
}
/// <summary>
/// Pfad zu der auszulesende Datei
/// </summary>
/// <value>pfad</value>
public string OpenFile
{
get { return this.openFile; }
set { this.openFile = value; }
}
/// <summary>
/// Pfad zum speichern
/// </summary>
/// <value>The save file.</value>
public string SaveFile
{
get { return this.saveFile; }
set {
this.saveFile = value;
this.saveFile += @"\\ScsimInput.xml";
}
}
public string SaveInputXML
{
get { return this.saveInputXML; }
set { this.saveInputXML = value; }
}
/// <summary>
/// WErt der angibt ob in dieser Periode die KDH teile hergestellt werden
/// </summary>
/// <value><c>true</c> if sonderproduktion; otherwise, <c>false</c>.</value>
public bool Sonderproduktion
{
get { return this.sonderproduktion; }
set { this.sonderproduktion = value; }
}
public bool UeberstundenErlaubt
{
get { return this.ueberstundenErlaubt; }
set { this.ueberstundenErlaubt = value; }
}
/// <summary>
/// Gets the teil.
/// </summary>
/// <param name="nr">Nummer des TEils.</param>
/// <returns></returns>
public Teil GetTeil(int nr)
{
if (this.teile.ContainsKey(nr))
{
return this.teile[nr];
}
else
{
throw new UnknownTeilException(nr);
}
}
/// <summary>
/// Setzt den Pufferwert für ein Teil
/// </summary>
/// <param name="nr">Teilnummer</param>
/// <param name="wert">zu setztender Wert</param>
public void SetPuffer(int nr, int wert)
{
if (!this.teile.ContainsKey(nr))
{
throw new UnknownTeilException(nr);
}
if (wert < 0)
{
throw new InputException(string.Format("Der Pufferwert für das Teil Nummer {0} darf nicht negativ sein", nr));
}
if (this.teile[nr].Pufferwert < 0)
{
this.teile[nr].Pufferwert = wert;
}
if (this.teile[nr].Pufferwert != wert)
{
this.teile[nr].Pufferwert = wert;
this.pufferChanged = true;
}
}
/// <summary>
/// Gets the data table kaufteil.
/// </summary>
/// <value>The data table kaufteil.</value>
public DataTable DataTableKaufteil
{
get
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Kaufteil"));
table.Columns.Add(new DataColumn("Anzahl"));
table.Columns.Add(new DataColumn("Typ"));
foreach (Bestellposition pos in this.bestellungen)
{
DataRow row = table.NewRow();
row["Kaufteil"] = pos.Kaufteil.Nummer;
row["Anzahl"] = pos.Menge;
if (pos.Eil)
{
row["Typ"] = "Eil";
}
else
{
row["Typ"] = "Normal";
}
table.Rows.Add(row);
}
return table;
}
}
/// <summary>
/// Reloads Bestellung
/// </summary>
/// <param name="table">The table.</param>
public void ReloadDataTableKaufteil(DataTable table)
{
this.bestellungen.Clear();
foreach (DataRow row in table.Rows)
{
Teil teil = this.teile[Convert.ToInt32(row["Kaufteil"])];
int menge = Convert.ToInt32(row["Anzahl"]);
if (row["Typ"].ToString().Equals("Eil"))
{
this.bestellungen.Add(new Bestellposition(teil as Kaufteil, menge, true));
}
else
{
this.bestellungen.Add(new Bestellposition(teil as Kaufteil, menge, false));
}
}
}
public DataTable DataTableProduktion
{
get
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Teil"));
table.Columns.Add(new DataColumn("Menge"));
foreach (int pos in this.reihenfolge)
{
DataRow row = table.NewRow();
row["Teil"] = pos;
row["Menge"] = (this.teile[pos] as ETeil).Produktionsmenge;
table.Rows.Add(row);
}
return table;
}
}
public void ReloadDataTableProduktion(DataTable table)
{
this.reihenfolge = new int[table.Rows.Count];
int count = 0;
foreach (DataRow row in table.Rows)
{
this.reihenfolge[count] = Convert.ToInt32(row[0]);
count++;
if ((this.teile[Convert.ToInt32(row[0])] as ETeil).Produktionsmenge < Convert.ToInt32(row[1]))
{
prod.Nachpruefen(this.teile[Convert.ToInt32(row[0])], Convert.ToInt32(row[1]));
}
else
{
(this.teile[Convert.ToInt32(row[0])] as ETeil).Produktionsmenge = Convert.ToInt32(row[1]);
}
}
}
public DataTable DataTableArbeitsPlatz
{
get
{
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Arbeitsplatz"));
table.Columns.Add(new DataColumn("Schichten"));
table.Columns.Add(new DataColumn("Minuten"));
foreach (KeyValuePair<int, Arbeitsplatz> platz in this.arbeitsplatz)
{
DataRow row = table.NewRow();
row["Arbeitsplatz"] = platz.Key;
row["Schichten"] = platz.Value.Schichten;
row["Minuten"] = platz.Value.UeberMin;
table.Rows.Add(row);
}
return table;
}
}
public void ReloadDataTableArbeitsPlatz(DataTable table)
{
foreach (DataRow row in table.Rows)
{
this.arbeitsplatz[Convert.ToInt32(row[0])].Schichten = Convert.ToInt32(row[1]);
this.arbeitsplatz[Convert.ToInt32(row[0])].UeberMin = Convert.ToInt32(row[2]);
}
}
/// <summary>
/// Einfügen einer neuen Bestellposition bestellposition.
/// </summary>
/// <param name="bpos">The bpos.</param>
public void AddBestellposition(Bestellposition bpos)
{
this.bestellungen.Add(bpos);
}
/// <summary>
/// Adds the bestellposition.
/// </summary>
/// <param name="kteilNr">The kteil nr.</param>
/// <param name="menge">The menge.</param>
/// <param name="eil">if set to <c>true</c> [eil].</param>
public void AddBestellposition(int kteilNr, int menge, bool eil)
{
if (!this.teile.ContainsKey(kteilNr))
{
throw new UnknownTeilException(kteilNr);
}
if (!(this.teile[kteilNr] is Kaufteil))
{
throw new InputException(string.Format("Teil mi der Nummer {0} ist kein Kaufteil!", kteilNr));
}
this.bestellungen.Add(new Bestellposition(this.teile[kteilNr] as Kaufteil, menge, eil));
}
/// <summary>
/// Sets the preis.
/// </summary>
/// <param name="kostenDict">The kosten dict.</param>
public void SetPreis(Dictionary<int, double> kostenDict)
{
foreach (KeyValuePair<int, double> kostKvp in kostenDict)
{
if (!this.teile.ContainsKey(kostKvp.Key))
{
throw new UnknownTeilException(kostKvp.Key);
}
if (!(this.teile[kostKvp.Key] is Kaufteil))
{
throw new InputException(string.Format("Teil mi der Nummer {0} ist kein Kaufteil!", kostKvp.Key));
}
(this.teile[kostKvp.Key] as Kaufteil).Preis = kostKvp.Value;
}
}
/// <summary>
/// Fügt ein neues K teil ein
/// </summary>
/// <param name="teil">Kaufteil Objekt</param>
public void AddKTeil(Kaufteil teil)
{
if (!this.teile.ContainsKey(teil.Nummer))
{
this.teile[teil.Nummer] = teil;
}
else
{
throw new InputException(string.Format("Die Teilnummer {0} wird doppelt verwendet", teil.Nummer));
}
}
/// <summary>
/// leigt ein neues Kteil an
/// </summary>
/// <param name="nr">Teil Nummer</param>
/// <param name="preis">Einkaufspreispreis</param>
/// <param name="bestellk">Bestellkosten</param>
/// <param name="ldauer">Liefer dauer</param>
/// <param name="abweichung">Abweichung.</param>
/// <param name="diskontmenge">Diskontmenge.</param>
/// <param name="bestand">Lagerbestand.</param>
/// <param name="verw">Verwendung{K,D,H,KDH}</param>
public void NewTeil(int nr, string bezeichnung, double preis, double bestellk, double ldauer, double abweichung, int diskontmenge, int bestand, string verw)
{
if (!this.teile.ContainsKey(nr))
{
Kaufteil kt = new Kaufteil(nr, bezeichnung);
kt.Preis = preis;
kt.Bestellkosten = bestellk;
kt.Lieferdauer = ldauer;
kt.Abweichung_lieferdauer = abweichung;
kt.Diskontmenge = diskontmenge;
kt.Lagerstand = bestand;
kt.Verwendung = verw;
this.teile[nr] = kt;
}
else
{
throw new InputException(string.Format("Es ist bereits ein Teil mit der nummer {0} vorhandet", nr));
}
}
/// <summary>
/// Fügt ein neues E teil hinzu
/// </summary>
/// <param name="teil">Objekt der KLasse E teil</param>
public void AddETeil(ETeil teil)
{
if (!this.teile.ContainsKey(teil.Nummer))
{
this.teile[teil.Nummer] = teil;
}
else
{
throw new InputException(string.Format("Die Teilnummer {0} wird doppelt verwendet", teil.Nummer));
}
}
/// <summary>
/// Legt ein neues E teil ein
/// </summary>
/// <param name="nr">Teilnummer</param>
/// <param name="bestand">Bestand</param>
/// <param name="verw">Verwendung{K,D,H,KDH}</param>
public void NewTeil(int nr, string bezeichnung, int bestand, string verw)
{
if (!this.teile.ContainsKey(nr))
{
ETeil et = new ETeil(nr, bezeichnung);
et.Lagerstand = bestand;
et.Verwendung = verw;
this.teile[nr] = et;
}
else
{
throw new InputException(string.Format("Es ist bereits ein Teil mit der nummer {0} vorhandet", nr));
}
}
/// <summary>
///Gibt das Arbeitsplatzobjekt mit der nummer nr
/// </summary>
/// <param name="nr">Arbeitsplatz nummer</param>
/// <returns></returns>
public Arbeitsplatz GetArbeitsplatz(int nr)
{
return this.arbeitsplatz[nr];
}
/// <summary>
/// Gets the arbeitsplatz list.
/// </summary>
/// <value>The arbeitsplatz list.</value>
public List<Arbeitsplatz> ArbeitsplatzList
{
get
{
List<Arbeitsplatz> res = new List<Arbeitsplatz>();
foreach (KeyValuePair<int, Arbeitsplatz> kvp in this.arbeitsplatz)
{
res.Add(kvp.Value);
}
return res;
}
}
public void NeuArbeitsplatz(Arbeitsplatz arb)
{
if (!this.arbeitsplatz.ContainsKey(arb.Nummer))
{
this.arbeitsplatz[arb.Nummer] = arb;
}
else
{
throw new Exception("Arbeitsplatz mit der Nummer " + arb.Nummer + " bereits vorhanden");
}
}
public void Optimieren()
{
prod = new Produktionsplanung();
Bestellverwaltung bv = new Bestellverwaltung();
//prod.Aufloesen();
prod.Planen();
bv.erzeugen_bestellungenlist();
}
public void ClearData()
{
prod = new Produktionsplanung();
prod.ClearData();
Bestellverwaltung bv = new Bestellverwaltung();
bv.ClearData();
}
public void Reset()
{
foreach (KeyValuePair<int, Arbeitsplatz> arbl in this.arbeitsplatz)
{
arbl.Value.UeberMin = 0;
arbl.Value.Schichten = 1;
}
foreach (ETeil teil in this.ETeilList)
{
teil.Produktionsmenge = 0;
teil.VerbrauchAktuell = 0;
teil.VerbrauchPrognose1 = 0;
teil.VerbrauchPrognose2 = 0;
}
}
#endregion
}
}