Ejemplo n.º 1
0
        /// <summary>Towrzy okno programu i wczytuje plik profilu.</summary>
        /// <param name="file">Plik profilu.</param>
        /// <remarks>Wywolywany gdy uruchomieniu programu towarzyszy otwarcie pliku profilu.</remarks>
        public MainForm(string file)
        {
            InitializeComponent();

            this.portfel = new UserProfile();
            this.dateList = new List<Dates>();
            this.settings = new SettingsEntries();
            this.ProfileChanged += this.OnChange;
            this.ReadFile(file);
            this.RefreshListView();
            this.UpdateForm();
        }
Ejemplo n.º 2
0
        /// <summary>Zapisuje plik profilu.</summary>
        /// <param name="file">Ścieżka do zapisu.</param>
        private void SaveProfile(UserProfile profile, string file)
        {
            XmlTextWriter writer = new XmlTextWriter(file, Encoding.UTF8);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(UserProfile));

                writer.Formatting = Formatting.Indented;

                profile.categories.Remove("stałe");
                profile.categories.Remove("brak");

                serializer.Serialize(writer, profile);

                profile.categories.Insert(0, "stałe");
                profile.categories.Insert(0, "brak");

                this.ChangesSaved();
            }
            catch(Exception ex)
            {
                string text = "Zapis do pliku " + file + " nie powiódł się.";

            #if DEBUG
                text = ex.ToString();
            #endif

                MainForm.MessageBoxWrapper(text, MessageType.WOK);

                if(this.ProfileChanged != null)
                    this.ProfileChanged();
            }
            finally
            {
                writer.Close();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Zapisuje profil z wyborem ścieżki zapisu.
 /// </summary>
 private void SaveAs(UserProfile profile)
 {
     SaveFileDialog dialog = new SaveFileDialog();
     dialog.Filter = "Plik profilu (*.pr)|*.pr";
     dialog.ShowDialog(this);
     if(dialog.FileName != "")
     {
         this.SaveProfile(profile, dialog.FileName);
         profile.path = dialog.FileName;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Czyta profil z pliku XML.
        /// </summary>
        /// <param name="file">Plik profilu</param>
        /// <remarks>Nie obsługuje wyjątków.</remarks>
        private void ReadXmlFile(string file)
        {
            XmlTextReader reader = new XmlTextReader(file);

            this.Reset();

            XmlSerializer serializer = new XmlSerializer(typeof(UserProfile));

            this.portfel = serializer.Deserialize(reader) as UserProfile;

            this.portfel.path = file;

            this.portfel.categories.Sort();
            this.portfel.categories.Insert(0, "stałe");
            this.portfel.categories.Insert(0, "brak");

            this.settings.ReadSettings(this);

            this.EnableForm();
            this.UpdateForm();
            this.RefreshListView();
            this.ChangesSaved();

            this.Text = MainForm.caption + " - " + this.portfel.profile;

            foreach(Expense elem in this.portfel.hist)
                this.AddToDateList(elem.date);

            reader.Close();
        }
Ejemplo n.º 5
0
        /// <summary>Eksportuje gałąź do pliku</summary>
        /// <param name="start">Data początkowa</param>
        /// <param name="end">Data końcowa</param>
        private void ExportExpenses(DateTime start, DateTime end)
        {
            List<Expense> tmp = new List<Expense>();

            foreach(Expense e in this.portfel.hist)
            #warning tu jest dobrze porownania?
                if(e.date.CompareTo(start) > 0 && e.date.CompareTo(end) < 0)
                    tmp.Add(e);

            #warning dodac do Balance zeby sie kwoty zgadzaly
            foreach(Expense e in tmp)
                this.portfel.hist.Remove(e);

            UserProfile branch = new UserProfile();
            branch.categories = this.portfel.categories;
            branch.hist = tmp;
            branch.profile = this.portfel.profile;
            branch.path = null;

            this.SaveAs(branch);
            this.Save();
        }