public static void LoadData(string filename)
{
if (data.Load(filename))
{
Console.WriteLine("Loading Data Worked!");
}
}
public bool LoadClient(string name)
{
try
{
client = new ClientManagement(data.FindClient(name).GetName(), data.FindClient(name).GetPhone(), data.FindClient(name).GetAddress(), data.FindClient(name).GetProductNumber(), data.FindClient(name).GetGuid());
Console.Clear();
Console.WriteLine("Running from LoadClient:\nName:\t" + client.GetName() + "\nPhone:\t" + client.GetPhone() + "\nAddress:" +client.GetAddress()+"\nGUID:\t" + client.GetGuid());
}
catch
{
Console.WriteLine("Client not found.\n\n");
return false;
}
return true;
}
public void EditClient()
{
ConsoleKeyInfo readKey;
bool edit = true;
try
{
while (edit)
{
Console.Clear();
Console.WriteLine("Current Information:\nName:\t" + client.GetName() + "\nPhone:\t" + client.GetPhone() + "\nAddress:" + client.GetAddress() + "\n" + "GUID:\t:" + client.GetGuid() + "\n\n");
Console.WriteLine("Select What you would like to edit:\t(Press <E> to exit)\n<N>ame\t<P>hone\t<A>ddress\n\n");
readKey = Console.ReadKey();
switch (readKey.Key)
{
case ConsoleKey.N:
Console.Write("ame\nCurrent Name: " + client.GetName() + "\n");
Console.Write("Enter the new name: ");
client.SetName(Console.ReadLine());
break;
case ConsoleKey.P:
Console.Write("one\nCurrent phone number: " + client.GetPhone() + "\n");
Console.Write("Enter the new phone number: ");
client.SetPhone(Console.ReadLine());
break;
case ConsoleKey.A:
Console.Write("ddress\nCurrent address: " + client.GetAddress() + "\n");
Console.Write("Enter the new address: ");
client.SetAddress(Console.ReadLine());
break;
case ConsoleKey.E:
Console.Clear();
edit = false;
break;
/* default:
Console.WriteLine("\nInvalid Command");
break;*/
}
}
Console.WriteLine("Edited Information:\nName:\t" + client.GetName() + "\nPhone:\t" + client.GetPhone() + "\nAddress:" + client.GetAddress() + "\nGUID:\t" + client.GetGuid());
/*Console.ReadLine();
data.StoreClient(client);
Console.ReadLine();*/
}
catch
{
Console.Clear();
Console.WriteLine("No Client Loaded.\n");
}
finally
{
data.StoreClient(client); /*this is the part that seems to give me the problem it runs fine without this, however, It doesn't save any data*/
}
}
class DataBank : IClientData
{
Hashtable clientHashtable = new Hashtable();
Hashtable productHashtable = new Hashtable();
public ClientManagement FindClient(string name)
{
return clientHashtable[name] as ClientManagement;
}
public void StoreClient(ClientManagement client)
{
foreach (ClientManagement cl in clientHashtable.Values)/*the "in" in this line is where it gives me the Exception unhandled error*/
{
if (cl.GetGuid() == client.GetGuid() || (clientHashtable[client.GetName()] != null))
{
RemoveClient(cl.GetName());
}
}
clientHashtable.Add(client.GetName(), client);
}
ASKER
C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).
TRUSTED BY
ASKER
Thanks again
Open in new window