You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
7.3 KiB
241 lines
7.3 KiB
4 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.IO;
|
||
|
using System.Runtime.Serialization;
|
||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||
|
|
||
|
namespace Globale_Variablen.Global
|
||
|
{
|
||
|
public sealed class ReadWrite
|
||
|
{
|
||
|
public static int DatenEintragLesen(Hashtable HT, object Key, ref object P)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (HT == null)
|
||
|
{
|
||
|
HT = new Hashtable();
|
||
|
return -1;
|
||
|
}
|
||
|
if (HT.Contains(Key))
|
||
|
{
|
||
|
P = HT[Key];
|
||
|
return HT.Count;
|
||
|
}
|
||
|
return -2;
|
||
|
}
|
||
|
catch (Exception exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed reading! " + exception.Message + " [PE 3208]");
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static int DatenEintragLesen(Hashtable HT, ref object[] Keys, ref object[] Values)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (HT == null)
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
Values = new object[HT.Count];
|
||
|
Keys = new object[HT.Count];
|
||
|
int index = 0;
|
||
|
foreach (object obj2 in HT.Keys)
|
||
|
{
|
||
|
Keys[index] = obj2;
|
||
|
Values[index] = HT[obj2];
|
||
|
index++;
|
||
|
}
|
||
|
return HT.Count;
|
||
|
}
|
||
|
catch (Exception exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed reading! " + exception.Message + " [PE 3207]");
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static int DatenLesen(string filename, ref object obj)
|
||
|
{
|
||
|
FileStream stream;
|
||
|
int num;
|
||
|
try
|
||
|
{
|
||
|
stream = new FileStream(filename, FileMode.Open);
|
||
|
}
|
||
|
catch (Exception exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed reading. Reason: " + exception.Message + " [PE 3205]");
|
||
|
return -1;
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
obj = new BinaryFormatter().Deserialize(stream);
|
||
|
num = 0;
|
||
|
}
|
||
|
catch (SerializationException exception2)
|
||
|
{
|
||
|
//MessageBox.Show("Failed to deserialize. Reason: " + exception2.Message + " [PE 3204]");
|
||
|
num = -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
stream.Close();
|
||
|
}
|
||
|
return num;
|
||
|
}
|
||
|
|
||
|
public static int DatenSaetzeLesen(ref Hashtable HashT, string FileName)
|
||
|
{
|
||
|
FileStream stream;
|
||
|
int count;
|
||
|
HashT = null;
|
||
|
try
|
||
|
{
|
||
|
if (!File.Exists(FileName))
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
stream = new FileStream(FileName, FileMode.Open);
|
||
|
}
|
||
|
catch (Exception exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed reading. Reason: " + exception.Message + " [PE 3210]");
|
||
|
return -1;
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
BinaryFormatter formatter = new BinaryFormatter();
|
||
|
HashT = (Hashtable) formatter.Deserialize(stream);
|
||
|
count = HashT.Count;
|
||
|
}
|
||
|
catch (SerializationException exception2)
|
||
|
{
|
||
|
//MessageBox.Show("Failed to deserialize. Reason: " + exception2.Message + " [PE 3209]");
|
||
|
count = -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
stream.Close();
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
public static int DatenSaetzeSpeichern(Hashtable HashT, string FileName)
|
||
|
{
|
||
|
int num;
|
||
|
FileStream serializationStream = new FileStream(FileName, FileMode.Create);
|
||
|
BinaryFormatter formatter = new BinaryFormatter();
|
||
|
try
|
||
|
{
|
||
|
formatter.Serialize(serializationStream, HashT);
|
||
|
num = 0;
|
||
|
}
|
||
|
catch (SerializationException exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed to serialize. Reason: " + exception.Message + " [PE 3211]");
|
||
|
num = -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
serializationStream.Close();
|
||
|
}
|
||
|
return num;
|
||
|
}
|
||
|
|
||
|
public static int DatenSatzEintragen(Hashtable HT, object Key, object P)
|
||
|
{
|
||
|
if (HT == null)
|
||
|
{
|
||
|
HT = new Hashtable();
|
||
|
return -1;
|
||
|
}
|
||
|
if (HT.Contains(Key))
|
||
|
{
|
||
|
HT.Remove(Key);
|
||
|
}
|
||
|
HT.Add(Key, P);
|
||
|
return HT.Count;
|
||
|
}
|
||
|
|
||
|
public static int DatenSatzLesen(ref Globale_Variablen.AnzeigeDaten.tDatenAnzeige Var)
|
||
|
{
|
||
|
FileStream stream;
|
||
|
int num;
|
||
|
string path = Environment.CurrentDirectory + @"\DatenAnzeige.bin";
|
||
|
try
|
||
|
{
|
||
|
stream = new FileStream(path, FileMode.Open);
|
||
|
}
|
||
|
catch (Exception exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed reading. Reason: " + exception.Message + " [PE 3213]");
|
||
|
return -1;
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
BinaryFormatter formatter = new BinaryFormatter();
|
||
|
Var = (Globale_Variablen.AnzeigeDaten.tDatenAnzeige)formatter.Deserialize(stream);
|
||
|
num = 0;
|
||
|
}
|
||
|
catch (SerializationException exception2)
|
||
|
{
|
||
|
//MessageBox.Show("Failed to deserialize. Reason: " + exception2.Message + " [PE 3212]");
|
||
|
num = -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
stream.Close();
|
||
|
}
|
||
|
return num;
|
||
|
}
|
||
|
|
||
|
public static int DatenSatzSpeichern(Globale_Variablen.AnzeigeDaten.tDatenAnzeige Var)
|
||
|
{
|
||
|
int num;
|
||
|
FileStream serializationStream = new FileStream(Environment.CurrentDirectory + @"\DatenAnzeige.bin", FileMode.Create);
|
||
|
BinaryFormatter formatter = new BinaryFormatter();
|
||
|
try
|
||
|
{
|
||
|
formatter.Serialize(serializationStream, Var);
|
||
|
num = 0;
|
||
|
}
|
||
|
catch (SerializationException exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed to serialize. Reason: " + exception.Message + " [PE 3214]");
|
||
|
num = -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
serializationStream.Close();
|
||
|
}
|
||
|
return num;
|
||
|
}
|
||
|
|
||
|
public static int DatenSpeichern(string filename, object obj)
|
||
|
{
|
||
|
int num;
|
||
|
FileStream serializationStream = new FileStream(filename, FileMode.Create);
|
||
|
BinaryFormatter formatter = new BinaryFormatter();
|
||
|
try
|
||
|
{
|
||
|
formatter.Serialize(serializationStream, obj);
|
||
|
num = 0;
|
||
|
}
|
||
|
catch (SerializationException exception)
|
||
|
{
|
||
|
//MessageBox.Show("Failed to serialize. Reason: " + exception.Message + " [PE 3206]");
|
||
|
num = -1;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
serializationStream.Close();
|
||
|
}
|
||
|
return num;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|