コード例 #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);
        }
コード例 #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);
        }