none
A local database file RRS feed

  • Question

  • Hi! 

    I am currently making a replica of a smple system for a bank. Ill add the code at the end. I want to somehow save the two libraries in a file that saves on the computer, and collects the information from that file again when starting up. i basically want my program to save the data in the libraries and collect the data when running the script again. the code:

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    
    namespace GOOD_bank_system
    {
        public class BankSystem
        {
           
    
            static void Main()
            {
    
    //variables
    
                 Dictionary<string, float> Saldo = new Dictionary<string, float>(); //This dictionary contains the string Bank Number and the float Saldo
                Dictionary<string, string> Name = new Dictionary<string, string>(); //This dictionary contains the string Bank Number and the string Name
    
    
    
            //WARNING
            //Right here i want the program to import the data form the file, and save it in the Dictionaries.
    
    
                string option;
                string option2;
    
                string name;
                float saldo;
                string bankNumber;
    
                string input;
                
            
            again:
    
    //startup
                Console.WriteLine("If you want to add, enter 1. If you want to view, enter 2. If you want to delete, enter 3. If you want to close the program, enter 4.");
                option = Console.ReadLine();
    
    //option 1
                if (option == "1")
                {
        //getting the credentials
                    Console.WriteLine("Enter Bank Number");
                    bankNumber = Console.ReadLine();
                    if (Name.ContainsKey(bankNumber) || Saldo.ContainsKey(bankNumber))
                    {
                        Console.WriteLine("This bankNumber is already in use!");
                        Console.WriteLine("If you want to change it, enter 1. if you want to stop, enter 2.");
                        option2 = Console.ReadLine();
        //option 1.1
                        if (option2 == "1")
                        {
                //getting the credentials
                            Console.WriteLine("Enter new name:");
                            name = Console.ReadLine();
                            Console.WriteLine("Enter new saldo:");
                            input = Console.ReadLine();
                            saldo = float.Parse(input);
    
                //adding the credentials
                            Console.WriteLine("Bank Number: " + bankNumber);
                            Console.WriteLine("Name: " + name);
                            Console.WriteLine("New Saldo: " + saldo);
                            Saldo.Remove(bankNumber);
                            Name.Remove(bankNumber);
                            Saldo.Add(bankNumber, saldo);
                            Name.Add(bankNumber, name);
    
                //clearing variables
                            option = "";
                            name = "";
                            saldo = 0;
                            bankNumber = "";
                            input = "";
    
                            System.Threading.Thread.Sleep(500);
    
                            goto again;
                        }
    
            //option 1.2
                        if (option2 == "2")
                        {
                //clearing variables
                            option = "";
                            name = "";
                            saldo = 0;
                            bankNumber = "";
                            input = "";
    
                            System.Threading.Thread.Sleep(500);
    
                            goto again;
                        }
                    }
                    Console.WriteLine("Enter Name");
                    name = Console.ReadLine();
                    Console.WriteLine("Enter New Saldo");
                    input = Console.ReadLine();
                    saldo = float.Parse(input);
    
    
        //adding the credentials
                    Console.WriteLine("Bank Number: " + bankNumber);
                    Console.WriteLine("Name: " + name);
                    Console.WriteLine("New Saldo: " + saldo);
                    Saldo.Add(bankNumber, saldo);
                    Name.Add(bankNumber, name);
    
        //clearing variables
                    option = "";
                    name = "";
                    saldo = 0;
                    bankNumber = "";
                    input = "";
                    System.Threading.Thread.Sleep(500);
                }
    
    //option 2
                if (option == "2")
                {
        //getting information
                    Console.WriteLine("Enter the Bank Number you want to view");
                    bankNumber = Console.ReadLine();
    
        //showing information
                    Console.WriteLine("this are the credentials:");
                    Console.WriteLine("Bank Number: " + bankNumber);
                    Console.WriteLine("Name: " + Name[bankNumber]);
                    Console.WriteLine("Saldo: " + Saldo[bankNumber]);
        //clearing variables
                    option = "";
                    bankNumber = "";
                    System.Threading.Thread.Sleep(500);
                }
    
    //option 3
                if (option == "3")
                {
                    Console.WriteLine("Enter the bank number you want to delete.");
                    bankNumber = Console.ReadLine();
                    Console.WriteLine("Removing...");
                    System.Threading.Thread.Sleep(500);
                    Saldo.Remove(bankNumber);
                    Name.Remove(bankNumber);
                    Console.WriteLine("Removed!");
                    System.Threading.Thread.Sleep(500);
                }
    
    //option 4
                if (option == "4")
                {
                    goto close;
                }
    
             //WARNING
             //Right here i want the program to save the credentials again, so if the program crashes the data isn't lost.
    
    
                goto again;
            close:
    
    //closing
    
             //WARNING!
             //Right here i want the program to make the final save and upload the libraries "Name" and "Saldo" to the new file.
    
    
                Console.Write("Closing Program");
                System.Threading.Thread.Sleep(500);
                Console.Write(".");
                System.Threading.Thread.Sleep(500);
                Console.Write(".");
                System.Threading.Thread.Sleep(500);
                Console.Write(".");
                System.Threading.Thread.Sleep(500);
    
    //end.
            }
        }
    }
    

    any other tips for the code are welcome

    thanks in advance!

    Murren from WebWing Productions

    Thursday, February 6, 2020 9:23 PM

Answers

All replies