Example #1
0
        private void setDateRange(WeekData week)
        {
            string dateRangeFormat     = "MMM dd";  // EXPORT TO PARAMS
            string dateRangeTextFamily = "Bold";    // EXPORT TO PARAMS
            float  dateRangeTextSize   = 14;        // EXPORT TO PARAMS

            dateRange.Font = new System.Drawing.Font(dateRangeTextFamily, dateRangeTextSize);
            dateRange.Text = week.startDate.ToString(dateRangeFormat) + " - " + week.endDate.ToString(dateRangeFormat);
        }
Example #2
0
        private void FillTables(WeekData week)
        {
            dataGridPsaView.Rows.Clear();
            int row = 0;

            foreach (string project in week.tasksDict.Keys)
            {
                string[] cells = new string[8];


                foreach (DayOfWeek day in week.Days.Keys)
                {
                    int d = (day != 0) ? (int)day - 1 : 6;
                    cells[d] = (week.Days[day].ContainsKey(project)) ? week.Days[day][project].ToString("0.##") : "";
                }

                // Week total for project
                cells[7] = (week.tasksDict.ContainsKey(project)) ? week.tasksDict[project].ToString("0.##") : "";
                dataGridPsaView.Rows.Add(cells);

                dataGridPsaView.Rows[row].HeaderCell.Value = project;
                row++;
            }

            // Add row of totals per day
            double[] tots = new double[8];
            for (int i = 0; i < 8; i++)
            {
                foreach (DataGridViewRow r in dataGridPsaView.Rows)
                {
                    double cell;
                    if (double.TryParse((string)r.Cells[i].Value, out cell))
                    {
                        tots[i] += cell;
                    }
                }
            }
            string[] totstr = Array.ConvertAll <double, string>(tots, Convert.ToString);
            dataGridPsaView.Rows.Add(totstr);
            dataGridPsaView.Rows[row].HeaderCell.Value = "Total";
            dataGridPsaView.Rows[row].DefaultCellStyle = new System.Windows.Forms.DataGridViewCellStyle()
            {
                // TODO: change color of cells
                BackColor = System.Drawing.Color.Gray
            };

            currentWeekStart = week.startDate;
            setDateRange(week);
        }
Example #3
0
        public bool computeData(DateTime date)
        {
            Debug.WriteLineIf(date.CompareTo(DateTime.Today) > 0, "Trying to compute data for the future.");

            bool success = false;

            week = new WeekData(date);

            try
            {
                using (StreamReader reader = new StreamReader(timerFile))
                {
                    string   line, taskName;
                    TimeSpan duration;
                    while (!reader.EndOfStream)
                    {
                        line = reader.ReadLine();
                        string[] columns = line.Split('\t');

                        DateTime d = DateTime.Parse(columns[0]);
                        if (d.CompareTo(week.startDate) >= 0 && d.CompareTo(week.endDate) <= 0)
                        {
                            if (columns[1].Contains("START"))
                            {
                                // Start calculating this task occurence
                                taskName = columns[2];
                                string start    = columns[0];
                                string end      = "";
                                bool   foundEnd = false;
                                do
                                {
                                    try
                                    {
                                        line = reader.ReadLine();
                                        if (line.Split('\t')[1].Contains("END"))
                                        {
                                            foundEnd = true;
                                            end      = line.Split('\t')[0];
                                        }
                                    }
                                    catch (NullReferenceException)
                                    {
                                        foundEnd = true;
                                        end      = DateTime.Now.ToString();
                                    }
                                }while (!foundEnd);
                                DateTime startD = DateTime.Parse(start);
                                DateTime endD   = DateTime.Parse(end);

                                // Check if start and end times are reasonable.
                                checkDayDiff(startD, endD, taskName);

                                duration = endD.Subtract(startD);
                                addDurationToDay(taskName, duration, startD.DayOfWeek);
                            } // Task occurence duration added
                        }     // Line parsed
                    }         // File streamed
                }
                success = true;
            }
            catch (Exception)
            {
                return(false);
            }

            return(success);
        }