Ejemplo n.º 1
0
        public MainWindow()
        {
            _currentMonthData = new MonthData();
            PreviousMonthData = new ObservableCollection<MonthData>();

            InitializeComponent();
        }
Ejemplo n.º 2
0
 private void ClearButton_Click(object sender, RoutedEventArgs e)
 {
     CurrentMonthData = new MonthData();
 }
Ejemplo n.º 3
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var goAhead = true;
            var oldData = PreviousMonthData.SingleOrDefault(x => x.CurrentMonth == CurrentMonthData.CurrentMonth && x.CurrentYear == CurrentMonthData.CurrentYear);
            if (oldData != null)
            {
                var result = MessageBox.Show("Do you want to overwrite the old data for this month?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                    PreviousMonthData.Remove(oldData);
                else
                    goAhead = false;
            }

            if (goAhead)
            {
                PreviousMonthData.Add(CurrentMonthData);

                Directory.CreateDirectory(SaveDir);
                using (var writer = new StreamWriter(Path.Combine(SaveDir, string.Format("file{0}-{1}", CurrentMonthData.CurrentYear, CurrentMonthData.CurrentMonth + 1))))
                {
                    writer.Write(CurrentMonthData.GetSaveString());
                }

                CurrentMonthData = new MonthData();
            }
        }
Ejemplo n.º 4
0
        public static MonthData Parse(System.IO.StreamReader stream)
        {
            var monthData = new MonthData();

            try
            {
                var line = stream.ReadLine();
                var sepIndex = line.IndexOf('-');
                var subLength2 = line.Length - sepIndex - 2;
                monthData.CurrentMonth = int.Parse(line.Substring(1, sepIndex - 1)) - 1;
                monthData.CurrentYear = int.Parse(line.Substring(sepIndex + 1, subLength2));
                line = stream.ReadLine();

                while (!stream.EndOfStream && !line.StartsWith("["))
                {
                    sepIndex = line.IndexOf(':');
                    subLength2 = line.Length - sepIndex - 1;
                    if (line.StartsWith("Rent"))
                        monthData.Rent = int.Parse(line.Substring(sepIndex + 1, subLength2));
                    else if (line.StartsWith("HGF"))
                        monthData.HGF = int.Parse(line.Substring(sepIndex + 1, subLength2));
                    else if (line.StartsWith("Insurance"))
                        monthData.Insurance = int.Parse(line.Substring(sepIndex + 1, subLength2));
                    else if (line.StartsWith("Broadband"))
                        monthData.Broadband = int.Parse(line.Substring(sepIndex + 1, subLength2));
                    else if (line.StartsWith("Electricity"))
                        monthData.Electricity = int.Parse(line.Substring(sepIndex + 1, subLength2));
                    line = stream.ReadLine();
                }

                var heading = line;
                line = stream.ReadLine();
                while (!stream.EndOfStream)
                {
                    if (line.StartsWith("[") && !stream.EndOfStream)
                    {
                        heading = line;
                        line = stream.ReadLine();
                    }

                    while (!line.StartsWith("[") && !stream.EndOfStream && line != "END")
                    {
                        switch (heading)
                        {
                            case "[HaraldReceipts]":
                                monthData.HaraldReceipts.Add(new Receipt(line));
                                break;
                            case "[HaraldDebts]":
                                monthData.HaraldDebts.Add(new DebtItem(line));
                                break;
                            case "[WellmanReceipts]":
                                monthData.WellmanReceipts.Add(new Receipt(line));
                                break;
                            case "[WellmanDebts]":
                                monthData.WellmanDebts.Add(new DebtItem(line));
                                break;
                        }

                        if (!stream.EndOfStream)
                            line = stream.ReadLine();
                    }
                }
            }
            catch
            {
                return null;
            }
            return monthData;
        }