Beispiel #1
0
        public static Account pull(string id)
        {
            Account account = null;

            try
            {
                if (!File.Exists(FILENAME))
                {
                    throw new FileNotFoundException();
                }
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(FILENAME);

                XmlNode res = xmlDocument.SelectSingleNode($"//*[@id='{id}']");
                if (res == null)
                {
                    return(account);
                }
                Currency currency;
                double   Balance;

                NodeData nd = parseDefaultAccount(res);

//                if (!Enum.TryParse<Currency>(res["currency"].InnerText, out currency))
//                {
//                    throw new Exception("Invalid currency");
//                }
//                if (!double.TryParse(res["Balance"].InnerText, out Balance))
//                {
//                    throw new Exception("Invalid balance type");
//                }
//
                switch (res.Name)
                {
                case "DefaultAccount": {
                    account = new DefaultAccount(nd);
                } break;

                case "OverdraftAccount":
                {
                    OverDraftData extra = parseOverdraftData(res);
                    account = new OverdraftAccount(nd, extra);
                }
                break;

                default: throw new Exception("Invalid account");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            return(account);
        }
Beispiel #2
0
        public static List <Account> pullAll()
        {
            List <Account> res = new List <Account>();

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(FILENAME);
                foreach (XmlNode xmlNode in xmlDocument.DocumentElement.ChildNodes)
                {
                    Account account;

                    NodeData nd = parseDefaultAccount(xmlNode);

                    switch (xmlNode.Name)
                    {
                    case "DefaultAccount": account = new DefaultAccount(nd);
                        break;

                    case "OverdraftAccount":
                        OverDraftData extra = parseOverdraftData(xmlNode);
                        account = new OverdraftAccount(nd, extra);
                        break;

                    default: account = new DefaultAccount(nd);
                        break;
                    }
                    res.Add(account);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }

            return(res);
        }
Beispiel #3
0
 public OverdraftAccount(NodeData nd, OverDraftData xd) : base(nd)
 {
     this.journal = new List <Transaction>();
     Limit        = xd.limit;
     Percents     = xd.percents;
 }