Esempio n. 1
0
        private void stopTrackingToolStripButton_Click(object sender, EventArgs e)
        {
            RefreshTimer.Stop();

            TimeTrackerData item = TrackingService.Stop();

            // fill in category
            if (categoryToolStripComboBox.Text.Length > 0)
            {
                item.Category = new TrackedDataCategory(categoryToolStripComboBox.Text.Trim(' '));
            }

            Data.Add(item);
            RefreshTrackingButtons();
            RefreshCategoryPicker();
        }
Esempio n. 2
0
        /// <summary>
        /// Opens an existing file with table data
        /// </summary>
        private void Open()
        {
            SaveIfNecessary();

            OpenFileDialog dialog = new OpenFileDialog
            {
                RestoreDirectory = true,
                DefaultExt       = FILE_EXT,
                FileName         = FILE_NAME,
                Filter           = String.Format("TimeTracker files (*.{0})|*.{0}|All files (*.*)|*.*", FILE_EXT),

                // use directory with "current" file if available
                InitialDirectory = file == null?Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) : file.DirectoryName
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                file = new FileInfo(dialog.FileName);
            }

            if (file != null)
            {
                if (!file.Exists)
                {
                    MessageBox.Show(this, Resources.Application_nonexistentFileMessageBox_Message,
                                    Resources.Application_nonexistentFileMessageBox_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                StreamReader fs = null;
                try
                {
                    Data.Clear();
                    fs = file.OpenText();

                    string line;
                    while ((line = fs.ReadLine()) != null)
                    {
                        TimeTrackerData value = DataSerializer.DeserializeValue(line, CATEGORY_MAXLENGTH);
                        Data.Add(value);
                    }
                }
                catch (DeserializationException)
                {
                    MessageBox.Show(this, Resources.Application_fileErrorMessageBox_Message,
                                    Resources.Application_fileErrorMessageBox_Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);

                    file = null;

                    return;
                }
                catch (Exception)
                {
                    MessageBox.Show(this, Resources.Application_fileErrorMessageBox_Message,
                                    Resources.Application_fileErrorMessageBox_Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                finally
                {
                    fs.Close();
                }
                isSaved = true;
            }

            RefreshFileButtons();
            RefreshTitle();
            RefreshCategoryPicker();
        }