// ====================================================================
        // populate categories from a file
        // if filepath is not specified, read/save in AppData file
        // ====================================================================
        public void ReadFromFile(String filepath = null)
        {
            // ---------------------------------------------------------------
            // reading from file resets all the current categories,
            // ---------------------------------------------------------------
            _Cats.Clear();

            // ---------------------------------------------------------------
            // reset default dir/filename to null
            // ... filepath may not be valid,
            // ---------------------------------------------------------------
            _DirName  = null;
            _FileName = null;

            // ---------------------------------------------------------------
            // get filepath name (throws exception if it doesn't exist)
            // ---------------------------------------------------------------
            filepath = BudgetFiles.VerifyReadFromFileName(filepath, DefaultFileName);

            // ---------------------------------------------------------------
            // If file exists, read it
            // ---------------------------------------------------------------
            _ReadXMLFile(filepath);
            _DirName  = Path.GetDirectoryName(filepath);
            _FileName = Path.GetFileName(filepath);
        }
Exemple #2
0
        // ====================================================================
        // populate categories from a file
        // if filepath is not specified, read/save in AppData file
        // ====================================================================
        public void ReadFromFile(String filepath = null)
        {
            // ---------------------------------------------------------------
            // reading from file resets all the current expenses,
            // so clear out any old definitions
            // ---------------------------------------------------------------
            _Expenses.Clear();

            // ---------------------------------------------------------------
            // reset default dir/filename to null
            // ... filepath may not be valid,
            // ---------------------------------------------------------------
            _DirName  = null;
            _FileName = null;

            // ---------------------------------------------------------------
            // get filepath name (throws exception if it doesn't exist)
            // ---------------------------------------------------------------
            filepath = BudgetFiles.VerifyReadFromFileName(filepath, DefaultFileName);

            // ---------------------------------------------------------------
            // read the expenses from the xml file
            // ---------------------------------------------------------------
            _ReadXMLFile(filepath);

            // ----------------------------------------------------------------
            // save filename info for later use?
            // ----------------------------------------------------------------
            _DirName  = Path.GetDirectoryName(filepath);
            _FileName = Path.GetFileName(filepath);
        }
        // ---------------------------------------------------------------
        // Read
        // ---------------------------------------------------------------
        public void ReadFromFile(String budgetFileName)
        {
            // ---------------------------------------------------------------
            // read the budget file and process
            // ---------------------------------------------------------------
            try
            {
                // get filepath name (throws exception if it doesn't exist)
                budgetFileName = BudgetFiles.VerifyReadFromFileName(budgetFileName, "");

                // If file exists, read it
                string[] filenames = System.IO.File.ReadAllLines(budgetFileName);

                // ----------------------------------------------------------------
                // Save information about budget file
                // ----------------------------------------------------------------
                string folder = Path.GetDirectoryName(budgetFileName);
                _FileName = Path.GetFileName(budgetFileName);

                // read the expenses and categories from their respective files
                categories.ReadFromFile(folder + "\\" + filenames[0]);
                expenses.ReadFromFile(folder + "\\" + filenames[1]);

                // Save information about budget file
                _DirName  = Path.GetDirectoryName(budgetFileName);
                _FileName = Path.GetFileName(budgetFileName);
            }

            // ----------------------------------------------------------------
            // throw new exception if we cannot get the info that we need
            // ----------------------------------------------------------------
            catch (Exception e)
            {
                throw new Exception("Could not read budget info: \n" + e.Message);
            }
        }