示例#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;
            }
        }
示例#2
0
文件: Main.cs 项目: tmldsousa/PWM
        private void refreshTimers()
        {
            this.lvwTimers.Items.Clear();

            using (var objCtx = new TimersDBEntities()) {
                foreach (Timer timer in objCtx.Timer)
                {
                    ListViewItem lvi = new ListViewItem(timer.Name);

                    lvi.Tag = timer.Id;

                    string startDate    = "";
                    string endDate      = "";
                    double totalSeconds = 0;

                    if (timer.TimerSession.Count > 0)
                    {
                        startDate    = (from ts in objCtx.TimerSession select ts.StartDate).Min().ToString();
                        endDate      = (from ts in objCtx.TimerSession select ts.EndDate).Max().ToString();
                        totalSeconds = (from ts in objCtx.TimerSession select ts.TotalSeconds).Sum();
                    }

                    TimeSpan sessionsSpan = TimeSpan.FromSeconds(totalSeconds);

                    lvi.SubItems.Add(startDate);
                    lvi.SubItems.Add(endDate);
                    lvi.SubItems.Add(sessionsSpan.ToString());
                    this.lvwTimers.Items.Add(lvi);
                }
            }
        }
示例#3
0
文件: Main.cs 项目: tmldsousa/PWM
        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;
            }
        }
示例#4
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;
            }
        }
示例#5
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);
                }
            }
        }
示例#6
0
        public DialogResult ShowEdit(Form Owner, long IdTimer)
        {
            _editMode = EditMode.Edit;
            _id       = IdTimer;

            TimersDBEntities db = new TimersDBEntities();
            var timer           = db.Timer.SingleOrDefault(x => x.Id == _id);

            this.txtName.Text        = timer.Name;
            this.txtDescription.Text = timer.Description;
            return(this.ShowDialog(Owner));
        }
示例#7
0
文件: Main.cs 项目: tmldsousa/PWM
        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();
            }
        }
示例#8
0
        public DialogResult ShowEdit(Form Owner, long IdTimer, long IdTimerSession)
        {
            _editMode       = EditMode.Edit;
            _idTimer        = IdTimer;
            _idTimerSession = IdTimerSession;

            using (var objCtx = new TimersDBEntities()) {
                var timerSession = objCtx.TimerSession.SingleOrDefault(x => x.Id == _idTimerSession);
                this.dtpStartDate.Value = timerSession.StartDate;
                this.dtpEndDate.Value   = timerSession.EndDate;
                TimeSpan sessionTime = TimeSpan.FromSeconds(timerSession.TotalSeconds);
                this.dtpSessionTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, sessionTime.Hours, sessionTime.Minutes, sessionTime.Seconds);
            }

            return(this.ShowDialog(Owner));
        }
示例#9
0
文件: Main.cs 项目: tmldsousa/PWM
 private void lvwTimers_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.lvwTimers.SelectedItems.Count > 0)
     {
         using (var objCtx = new TimersDBEntities()) {
             var timerName = this.lvwTimers.SelectedItems[0].Text;
             //var timer = objCtx.Timer.SingleOrDefault(x => x.Name == this.lvwTimers.SelectedItems[0].Text); --> Dá erro. Alterar 'this.lvwTimers.SelectedItems[0].Text' por 'TimerName'.
             var timer = (from t in objCtx.Timer
                          where t.Name == timerName
                          select t).FirstOrDefault <Timer>();
             this.lblDescription.Text = timer.Description;
         }
         setFormStatus(false, true);
     }
     else
     {
         setFormStatus(false, false);
     }
 }
示例#10
0
        private void refreshTimerSessions()
        {
            this.lvwTimerSessions.Items.Clear();

            using (var objCtx = new TimersDBEntities()) {
                // Get Timer
                var timer = (from t in objCtx.Timer
                             where t.Id == _idTimer
                             select t).FirstOrDefault();

                foreach (TimerSession timersession in timer.TimerSession)
                {
                    ListViewItem lvi = new ListViewItem(timersession.StartDate.ToString());
                    lvi.Tag = timersession.Id;
                    lvi.SubItems.Add(timersession.EndDate.ToString());
                    TimeSpan sessionsSpan = TimeSpan.FromSeconds(timersession.TotalSeconds);
                    lvi.SubItems.Add(sessionsSpan.ToString());
                    this.lvwTimerSessions.Items.Add(lvi);
                }
            }
        }
示例#11
0
文件: Main.cs 项目: tmldsousa/PWM
        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);
                }
            }
        }