Пример #1
0
        /// <summary>
        /// Reads items from <see cref="ProjectTimeDataPath"/> and initializes the <see cref="Items"/> collection and its <see cref="CollectionView"/>
        /// </summary>
        private void InitializeProjectTimeDataItems()
        {
            // Initialize items
            Items = new ObservableCollection <ProjectTimeDataViewModel>(ProjectTimeDataCollection.GetProjectTimeData(ProjectTimeDataPath).Select(item => new ProjectTimeDataViewModel(item)));

            // Initialize collection view
            CollectionView = CollectionViewSource.GetDefaultView(Items);
            CollectionView.SortDescriptions.Add(new SortDescription("ChargeNumber", ListSortDirection.Ascending));
            //CollectionView.Filter = Filter;
        }
Пример #2
0
        /// <summary>
        /// Attempts to read program data from <see cref="ProgramDataPath"/> and sets file paths to base directory if the path specified is invalid
        /// </summary>
        private void InitializeProgramData()
        {
            // Create the file if it doesn't exist
            if (!File.Exists(ProgramDataPath))
            {
                ProjectTimeDataCollection.SaveProgramData(ProgramDataPath, new ProgramData());
            }

            ProgramData programData = ProjectTimeDataCollection.GetProgramData(ProgramDataPath);

            // Verify the read-in file's directory exists and that the file is an xml file, otherwise set path to default
            try
            {
                ProjectTimeDataPath = programData.ProjectTimeDataPath;
                FileInfo f = new FileInfo(ProjectTimeDataPath);
                if (!Directory.Exists(f.Directory.FullName))
                {
                    throw new Exception();
                }
                if (string.Compare(f.Extension, ".xml", true) != 0)
                {
                    throw new Exception();
                }
            }
            // Exception caught means read-in file's directory does not exist or that the file is not an xml file, so set to default
            catch (Exception ex)
            {
                ProjectTimeDataPath = DefaultProjectTimeDataPath;
            }

            // Verify the read-in directory exists, otherwise set path to default
            try
            {
                TimesheetsDir = programData.TimesheetsDir;
                if (!Directory.Exists(TimesheetsDir))
                {
                    throw new Exception();
                }
            }
            // Exception caught means read-in directory does not exist, so set to default
            catch (Exception ex)
            {
                TimesheetsDir = DefaultTimesheetsDir;
            }

            Name = programData.Name;
            ID   = programData.ID;
        }
Пример #3
0
 private void SaveProgramData()
 {
     ProjectTimeDataCollection.SaveProgramData(ProgramDataPath, new ProgramData(ProjectTimeDataPath, TimesheetsDir, Name, ID));
 }
Пример #4
0
        /// <summary>
        /// Saves account data as sorted by <see cref="CollectionView"/>
        /// </summary>
        private void SaveProjectTimeData()
        {
            List <ProjectTimeData> sortedProjectTimeData = new List <ProjectTimeData>(Items.Select(i => new ProjectTimeData(i)));

            sortedProjectTimeData.Sort();

            ProjectTimeDataCollection.SaveProjectTimeData(ProjectTimeDataPath, sortedProjectTimeData);

            List <string> lines = new List <string>();

            foreach (ProjectTimeData data in sortedProjectTimeData)
            {
                lines.Add("--" + data.DisplayName + "--");
                lines.Add("M: " + data.MondayTime + " - " + data.MondayNotes);
                lines.Add("T: " + data.TuesdayTime + " - " + data.TuesdayNotes);
                lines.Add("W: " + data.WednesdayTime + " - " + data.WednesdayNotes);
                lines.Add("R: " + data.ThursdayTime + " - " + data.ThursdayNotes);
                lines.Add("F: " + data.FridayTime + " - " + data.FridayNotes);
                lines.Add("Total logged time: " + data.TotalLoggedTime);
                lines.Add("");
            }

            lines = new List <string>();

            lines.Add("==Monday==");
            foreach (ProjectTimeDataViewModel item in Items)
            {
                if (item.MondayTime > 0)
                {
                    lines.Add(item.MondayTime + " - " + item.DisplayName + " - " + item.MondayNotes);
                }
            }
            lines.Add("");
            lines.Add("==Tuesday==");
            foreach (ProjectTimeDataViewModel item in Items)
            {
                if (item.TuesdayTime > 0)
                {
                    lines.Add(item.TuesdayTime + " - " + item.DisplayName + " - " + item.TuesdayNotes);
                }
            }
            lines.Add("");
            lines.Add("==Wednesday==");
            foreach (ProjectTimeDataViewModel item in Items)
            {
                if (item.WednesdayTime > 0)
                {
                    lines.Add(item.WednesdayTime + " - " + item.DisplayName + " - " + item.WednesdayNotes);
                }
            }
            lines.Add("");
            lines.Add("==Thursday==");
            foreach (ProjectTimeDataViewModel item in Items)
            {
                if (item.ThursdayTime > 0)
                {
                    lines.Add(item.ThursdayTime + " - " + item.DisplayName + " - " + item.ThursdayNotes);
                }
            }
            lines.Add("");
            lines.Add("==Friday==");
            foreach (ProjectTimeDataViewModel item in Items)
            {
                if (item.FridayTime > 0)
                {
                    lines.Add(item.FridayTime + " - " + item.DisplayName + " - " + item.FridayNotes);
                }
            }

            File.WriteAllLines(mTxtProjectTimeDataDailyReportFilePath, lines);

            /*
             * for(int i = 0; i < lines.Count; i++)
             * {
             *  lines[i] = "<p>" + lines[i] + "</p>";
             * }
             *
             * File.WriteAllText(mHtmlAccountDataFilePath, "<html><body>");
             * File.AppendAllLines(mHtmlAccountDataFilePath, lines);
             * File.AppendAllText(mHtmlAccountDataFilePath, "</body></html>");
             */
        }