예제 #1
0
 private void buttonNew_Click(object sender, EventArgs e)
 {
     Session session = new Session();
     session.Start = DateTime.Now;
     session.Category = SessionCategory.New;
     using (EditSessionDialog dialog = new EditSessionDialog())
     {
         if (dialog.ShowDialog(this, session) == DialogResult.OK)
         {
             sessions.Add(session);
             RefreshListView();
             // Select the newly created item
             for (int i = 0; i < listView.Items.Count; i++)
             {
                 ListViewItem item = listView.Items[i];
                 if (object.ReferenceEquals(item.Tag, session))
                 {
                     item.Selected = true;
                     item.EnsureVisible();
                     break;
                 }
             }
             PendingChanges = true;
         }
     }
 }
예제 #2
0
        private void SetListViewItem(ListViewItem item, Session session)
        {
            item.SubItems.Clear();
            item.Text = Formatter.FormatDateTime(session.Start);
            item.SubItems.Add(Formatter.FormatDayOfWeek(session.Start));
            item.SubItems.Add(ValueOrEmpty(session.End));

            string durationString;
            if (session.End.HasValue)
            {
                var duration = session.End.Value - session.Start;
                durationString = Formatter.FormatHours(duration.TotalHours);
            }
            else
            {
                durationString = string.Empty;
            }
            item.SubItems.Add(durationString);

            item.SubItems.Add(session.Category.ToString());
            item.SubItems.Add(session.Text);
            item.Tag = session;

            if (session.IsWeekend)
            {
                MarkItemAsWeekend(item);
            }
            else if (session.IsOffHours)
            {
                MarkItemAsOffHours(item);
            }
        }
예제 #3
0
 public DialogResult ShowDialog(IWin32Window owner, Session session)
 {
     this.session = session;
     SessionToForm();
     return ShowDialog(owner);
 }