File: RouteCutForm.cs

package info (click to toggle)
quickroute-gps 2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,576 kB
  • sloc: cs: 74,488; makefile: 72; sh: 43
file content (101 lines) | stat: -rw-r--r-- 2,645 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuickRoute.BusinessEntities;
using QuickRoute.BusinessEntities.Numeric;

namespace QuickRoute.Controls.Forms
{
  public partial class RouteCutForm : Form
  {
    private DateTime initialTime;

    public RouteCutForm()
    {
      InitializeComponent();
    }

    public DateTime InitialTime
    {
      get { return initialTime; }
      set 
      {
        initialTime = value;
        timeTextbox.Text = FormatTime(initialTime.ToLocalTime(), false);
      }
    }

    public DateTime Time
    {
      get
      {
        string timeString = timeTextbox.Text;
        string timeSeparator = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.TimeSeparator;
        timeString = timeString.Replace(".", timeSeparator);
        timeString = timeString.Replace(",", timeSeparator);
        timeString = timeString.Replace(":", timeSeparator);

        TimeSpan ts;
        if (TimeSpan.TryParse(timeString, out ts))
        {
          DateTime dt = initialTime.Date.AddSeconds(ts.TotalSeconds);
          dt = new DateTime(dt.Ticks, DateTimeKind.Local).ToUniversalTime();
          return dt;
        }

        DateTime t;
        if (DateTime.TryParse(timeString, out t))
        {
          return t.ToUniversalTime();
        }
        return initialTime.ToUniversalTime();
      }
    }

    public CutType CutType
    {
      get
      {
        return (cutBefore.Checked ? CutType.Before : CutType.After); 
      }
      set
      {
        cutBefore.Checked = (value == CutType.Before);
        cutAfter.Checked = (value == CutType.After);
      }
    }

    private static string FormatTime(DateTime time, bool includeDate)
    {
      var firstPart = includeDate ? time.ToString("G") : time.ToLongTimeString();
      return firstPart + time.ToString(".fffffff").TrimEnd("0".ToCharArray()).TrimEnd(".".ToCharArray());
    }

    private void OK_Click(object sender, EventArgs e)
    {
      DialogResult = DialogResult.OK;
      Close();
    }

    private void Cancel_Click(object sender, EventArgs e)
    {
      DialogResult = DialogResult.Cancel;
      Close();
    }

    private void TimeTextbox_Leave(object sender, EventArgs e)
    {
      timeTextbox.Text = FormatTime(Time.ToLocalTime(), Time.Date != initialTime.Date);
    }

    private void TimeTextbox_Enter(object sender, EventArgs e)
    {
      timeTextbox.SelectAll();
    }
  
  }
}