コード例 #1
0
        /// <summary>
        /// Draw a pie chart depending on time worked and rested
        /// </summary>
        /// <param name="wd"></param>
        private void DrawChart(WorkingDay wd)
        {
            PieChart circle = new PieChart();

            // if not an empty entry
            if (wd != null)
            {
                var full_circle = 360;
                var total_time  = wd.BreakTime + wd.WorkTime; //  equals to 360

                if (total_time != 0)
                {
                    // work slice:
                    circle.work_start_angle = 360;
                    circle.work_end_angle   = wd.WorkTime * full_circle / total_time;

                    // break slice:
                    circle.break_start_angle = circle.work_end_angle;
                    circle.break_end_angle   = 0;

                    // labels:
                    UpdateTime(wd.WorkTime.ToString(), wd.BreakTime.ToString());
                }

                // update the data context: A BAD METHOD, CREATES LOTS OF OBJECTS, SHOULD IMPLEMENT A NOTIDFY PROPERTY CHANGED
                DataContext = circle;
            }
            else
            {
                circle.EmptyCircle();
                UpdateTime("No entry", "No entry");
                DataContext = circle;
            }
        }
コード例 #2
0
 /// <summary>
 /// Updates the text block where the comment is displayed
 /// </summary>
 private void UpdateComment(WorkingDay wd)
 {
     if (wd != null)
     {
         Comment.Text = wd.Comment;
     }
     else
     {
         Comment.Text = "Comment...";
     }
 }
コード例 #3
0
        /// <summary>
        /// Searches for working days in the given time period
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSearchButtonClicked(object sender, EventArgs e)
        {
            var    time       = "00:00:00";
            string start_date = null;
            string end_date   = null;

            if (multiple)
            {
                //  fill the search fields!:
                if (string.IsNullOrWhiteSpace(Start_Year.Text) || string.IsNullOrWhiteSpace(Start_Month.Text) || string.IsNullOrWhiteSpace(Start_Day.Text) ||
                    string.IsNullOrWhiteSpace(End_Year.Text) || string.IsNullOrWhiteSpace(End_Month.Text) || string.IsNullOrWhiteSpace(End_Day.Text))

                {
                    MessageBox.Show("One or more of the date fields are empty");
                }

                else
                {
                    start_date = Start_Year.Text + "-" + Start_Month.Text + "-" + Start_Day.Text + " " + time;
                    end_date   = End_Year.Text + "-" + End_Month.Text + "-" + End_Day.Text + " " + time;
                }

                // get the data between the given dates:
                try
                {
                    var Day_List = Data.GetTimePeriod(start_date, end_date);

                    if (Day_List.Count() > 0)
                    {
                        // show the total time and pie chart:
                        WorkingDay wd_period = new WorkingDay();

                        foreach (var day in Day_List)
                        {
                            wd_period.WorkTime  += day.WorkTime;
                            wd_period.BreakTime += day.BreakTime;
                        }

                        DrawChart(wd_period);
                    }
                    else
                    {
                        UpdateTime("No entries", "No entries"); DrawChart(null);
                    }
                }
                catch (SystemException ex) { /* empty list */ }
            }
            else
            {
                MessageBox.Show("'Single day' mode selected!");
            }
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: BenasKem/Csharp
        /// <summary>
        /// Default constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            TimerText.Text = "Welcome";



            // Initiate last time saved timers;
            if (Properties.Settings.Default.WorkTime != 0 && Properties.Settings.Default.BreakTime != 0)
            {
                _WorkingTime = Properties.Settings.Default.WorkTime;
                _BreakTime   = Properties.Settings.Default.BreakTime;
            }
            // case its the first time, load default times
            else
            {
                _WorkingTime = 25;
                _BreakTime   = 5;
            }
            // TODO :  refactor
            // load the database and see if a record of this day exists
            if (Data.DBLive())
            {
                // check if this days entry is all ready here:
                if (Data.GetDate(now.Date.ToString()) == "0")
                {   // create an entry if not:
                    WorkingDay wd = new WorkingDay()
                    {
                        WorkTime  = 0,
                        BreakTime = 0,
                        Date      = now.Date.ToString(),
                        Comment   = null
                    };
                    Data.InsertWorkingDay(wd);
                }
                // get the values from that existing day:
                else
                {
                    wd          = Data.GetWorkingDay(now.Date.ToString());
                    _TotalBreak = wd.BreakTime;
                    _TotalWork  = wd.WorkTime;
                }

                // we have an error:
            }
            else
            {
                MessageBox.Show("Could not connect to the database");
            }
        }
コード例 #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public StatisticsPage(WorkingDay wd)
        {
            InitializeComponent();

            // setup the working day object:
            _WD = new WorkingDay()
            {
                WorkTime  = wd.WorkTime,
                BreakTime = wd.BreakTime,
                Date      = wd.Date,
                Comment   = wd.Comment
            };

            DrawChart(_WD);
            UpdateComment(_WD);
        }
コード例 #6
0
        //TODO:
        // IF MINUTES > 60 CONVERT TO HOURS AND DISPLAY IT
        // ADD TEXT PROPERTY TO A WORKING DAY

        /// <summary>
        /// Handler for selecting a date from a calendar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Calendar_OnSelectedDatesChanged(object sender, EventArgs e)
        {
            if (single)
            {
                var getDate = Calendar.SelectedDate;

                dateWD = Data.GetWorkingDay(getDate.ToString());


                UpdateComment(dateWD);

                DrawChart(dateWD);
            }
            else
            {
                MessageBox.Show("'Multiple days' mode selected");
            }
        }
コード例 #7
0
ファイル: Data.cs プロジェクト: BenasKem/Csharp
        /// <summary>
        /// Updates the total working time
        /// </summary>
        /// <param name="day"></param>
        public static void UpdateWorkingTime(WorkingDay day)
        {
            using IDbConnection connection = new SQLiteConnection(LoadConnectionString());

            connection.Execute($"UPDATE WorkingDay SET WorkTime = @WorkTime WHERE Id = @Id", day);
        }
コード例 #8
0
ファイル: Data.cs プロジェクト: BenasKem/Csharp
        /// <summary>
        /// Method to put working times into the database
        /// </summary>
        /// <param name="day"></param>
        public static void InsertWorkingDay(WorkingDay day)
        {
            using IDbConnection connection = new SQLiteConnection(LoadConnectionString());

            connection.Execute("insert into WorkingDay (WorkTime, BreakTime, Date, Comment) values (@WorkTime, @BreakTime, @Date, @Comment)", day);
        }
コード例 #9
0
ファイル: Data.cs プロジェクト: BenasKem/Csharp
 /// <summary>
 /// Updates the comment of the working day
 /// </summary>
 /// <param name="day"></param>
 public static void UpdateComment(WorkingDay day)
 {
     using IDbConnection connection = new SQLiteConnection(LoadConnectionString());
     connection.Execute($"UPDATE WorkingDay SET Comment = @Comment WHERE Id = @Id", day);
 }