Exemple #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            Timer timer;

            switch (_editMode)
            {
            case EditMode.Undefined:
                break;

            case EditMode.Add:
                timer = new Timer()
                {
                    Name = this.txtName.Text, Description = this.txtDescription.Text
                };
                using (var objCtx = new TimersDBEntities()) {
                    objCtx.Timer.AddObject(timer);
                    objCtx.SaveChanges();
                }
                break;

            case EditMode.Edit:
                using (var objCtx = new TimersDBEntities()) {
                    timer             = objCtx.Timer.SingleOrDefault(x => x.Id == _id);
                    timer.Name        = this.txtName.Text;
                    timer.Description = this.txtDescription.Text;
                    objCtx.SaveChanges();
                }
                break;

            default:
                break;
            }
        }
Exemple #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (this.lvwTimers.SelectedItems.Count > 0)
            {
                var selectedLI = this.lvwTimers.SelectedItems[0];
                var timerName  = selectedLI.Text;
                using (var objCtx = new TimersDBEntities()) {
                    // GetTimer
                    var timer = (from t in objCtx.Timer
                                 where t.Name == timerName
                                 select t).FirstOrDefault();

                    var timerSession = new TimerSession();
                    timerSession.StartDate    = DateTime.Now;
                    timerSession.EndDate      = DateTime.Now;
                    timerSession.TotalSeconds = 0;
                    timerSession.IdTimer      = timer.Id;

                    objCtx.TimerSession.AddObject(timerSession);
                    objCtx.SaveChanges();

                    activeTimerSessionId = timerSession.Id;
                }

                setFormStatus(true, true);
                this.timerControl.Start();

                // Move progress bar
                setProgressBarPosition(selectedLI);

                this.progressBar.Visible = true;
            }
        }
Exemple #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            TimerSession timerSession;
            TimeSpan     sessionTime = this.dtpEndDate.Value.Subtract(this.dtpStartDate.Value);

            switch (_editMode)
            {
            case EditMode.Undefined:
                break;

            case EditMode.Add:
                using (var objCtx = new TimersDBEntities()) {
                    timerSession = new TimerSession()
                    {
                        StartDate = this.dtpStartDate.Value, EndDate = this.dtpEndDate.Value, TotalSeconds = Convert.ToInt64(sessionTime.TotalSeconds), IdTimer = _idTimer
                    };
                    objCtx.TimerSession.AddObject(timerSession);
                    objCtx.SaveChanges();
                }
                break;

            case EditMode.Edit:
                using (var objCtx = new TimersDBEntities()) {
                    timerSession              = objCtx.TimerSession.SingleOrDefault(x => x.Id == _idTimerSession);
                    timerSession.StartDate    = this.dtpStartDate.Value;
                    timerSession.EndDate      = this.dtpEndDate.Value;
                    timerSession.TotalSeconds = Convert.ToInt64(sessionTime.TotalSeconds);
                    objCtx.SaveChanges();
                }
                break;

            default:
                break;
            }
        }
Exemple #4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.lvwTimerSessions.SelectedItems.Count > 0)
            {
                if (MessageBox.Show("Confirm delete of timer session ?", "Timer Delete", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    long id = Convert.ToInt64(this.lvwTimerSessions.SelectedItems[0].Tag);
                    using (var objCtx = new TimersDBEntities()) {
                        // Get timer sessions
                        var timerSession = (from ts in objCtx.TimerSession
                                            where ts.Id == id
                                            select ts).FirstOrDefault();

                        // Delete timer session
                        objCtx.TimerSession.DeleteObject(timerSession);

                        // Commit changes
                        objCtx.SaveChanges();
                    }

                    refreshTimerSessions();
                    setFormStatus(false);
                }
            }
        }
Exemple #5
0
        private void timerControl_Tick(object sender, EventArgs e)
        {
            using (var objCtx = new TimersDBEntities()) {
                // Get timer session
                var timerSession = (from ts in objCtx.TimerSession
                                    where ts.Id == activeTimerSessionId
                                    select ts).FirstOrDefault();

                timerSession.EndDate      = DateTime.Now;
                timerSession.TotalSeconds = Convert.ToInt64(DateTime.Now.Subtract(timerSession.StartDate).TotalSeconds);

                objCtx.SaveChanges();
            }
        }
Exemple #6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.lvwTimers.SelectedItems.Count > 0)
            {
                ListViewItem lvi = this.lvwTimers.SelectedItems[0];
                if (MessageBox.Show("Confirm delete of timer '" + lvi.SubItems[0].Text + "' ?", "Timer Delete", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    long id = Convert.ToInt64(this.lvwTimers.SelectedItems[0].Tag);
                    using (var objCtx = new TimersDBEntities()) {
                        // GetTimer
                        var timer = (from t in objCtx.Timer
                                     where t.Id == id
                                     select t).FirstOrDefault();

                        // Get timer sessions list
                        var timersessions = (from ts in objCtx.TimerSession
                                             where ts.IdTimer == timer.Id
                                             select ts).ToList <TimerSession>();

                        // Delete timer sessions
                        foreach (var ts in timersessions)
                        {
                            objCtx.TimerSession.DeleteObject(ts);
                        }

                        // Delete timer
                        objCtx.Timer.DeleteObject(timer);

                        // Commit changes
                        objCtx.SaveChanges();
                    }

                    refreshTimers();
                    setFormStatus(false, false);
                }
            }
        }