Ejemplo n.º 1
0
        private void RefreshGrid()
        {
            SU.SuspendUpdate.Suspend(this);             // Prevent form from repainting while we update the projects

            try
            {
                List <Project> projects = TimeKeeperData.GetActiveProjects();
                projects.Sort();

                foreach (Row row in this.rows)
                {
                    row.Refresh(projects);
                }

                // Check if there is only a single project entry, if so set it's time
                if (!this.rows.Any(r => r.TimeIsDirty) && this.rows.Count(r => r.ProjectBox.SelectedItem != null) == 1)
                {
                    this.rows.Single(r => r.ProjectBox.SelectedItem != null).SetTime(this.MinutesSinceLastSave, false);
                }

                this.RollupRows();
            }
            finally
            {
                SU.SuspendUpdate.Resume(this);                  // Ok...we can paint again
            }
        }
Ejemplo n.º 2
0
        private void LoadListBox(bool showInactive, long selectedProjectID = 0)
        {
            var projects = showInactive ? TimeKeeperData.GetAllProjects() : TimeKeeperData.GetActiveProjects();

            projects.Sort();

            var previousSelectedIndex = this.lvProjects.SelectedIndices.Count > 0 ? this.lvProjects.SelectedIndices[0] : 0;

            this.lvProjects.Items.Clear();

            this.lvProjects.Items.AddRange(projects.Select(a => new ListViewItem(new string[] { a.Name, a.Department, a.IsActive ? "X" : "" })
            {
                Tag = a
            }).ToArray());

            this.lvProjects.SelectedIndices.Clear();

            if (this.lvProjects.Items.Count > previousSelectedIndex)
            {
                this.lvProjects.Items[previousSelectedIndex].Selected = true;
            }
            else if (this.lvProjects.Items.Count > 0)
            {
                this.lvProjects.Items[0].Selected = true;
            }
        }
Ejemplo n.º 3
0
        public void SaveTime()
        {
            var errorMessages   = new List <string>();
            var hasEnteredTimes = false;
            var saveTime        = DateTime.Now;

            foreach (Row row in this.rows)
            {
                var project = row.ProjectBox.SelectedItem as Project;
                int minutes = row.GetTime();
                if (project != null && minutes > 0)
                {
                    try
                    {
                        TimeKeeperData.SaveLog(project.ProjectID, Settings.Default.userName, minutes, row.DescriptionBox.Text, saveTime);
                        row.SetTime(0, false);
                        hasEnteredTimes = true;
                    }
                    catch
                    {
                        errorMessages.Add(project + "\t" + minutes + "\t" + row.DescriptionBox.Text + "\tSystem Error");
                        continue;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(row.ProjectBox.Text) && row.ProjectBox.SelectedItem == null)
                    {
                        errorMessages.Add(row.ProjectBox.Text + "\t" + minutes.ToString() + "\t" + row.DescriptionBox.Text + "\tProject not found");
                    }
                    // TODO -- if a project is selected and there is no time then remove the row (based on the setting)
                    // TODO -- once implemented show the Settings Menu Item
                }
            }

            if (errorMessages.Count > 0)
            {
                MessageBox.Show("Your time was processed but some of your entries could not be save:\n\n" + string.Join("\n", errorMessages), "TimeKeeper - Error saving time", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (hasEnteredTimes)
            {
                this.timeSinceLastSave = saveTime;
            }
        }
Ejemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            long projectID = (this.Tag as Project)?.ProjectID ?? 0L;

            var projectName    = this.txtProjectName.Text.Trim();
            var departmentName = this.cmboDepartment.Text.Trim();
            var isActive       = this.cbIsActive.Checked;
            var dateCreated    = DateTime.Now;

            // Validate
            var errors = new List <string>();

            if (projectName.IsEmpty())
            {
                errors.Add("Project Name is required");
            }
            if (departmentName.IsEmpty())
            {
                errors.Add("Department is required");
            }
            if (projectID == 0 && !isActive)
            {
                errors.Add("New projects cannot be inactive");
            }


            if (errors.Count > 0)
            {
                MessageBox.Show("The project could not be saved due to the following issues:\n\n" + string.Join("\n", errors), "Missing Values");
                return;
            }

            try
            {
                TimeKeeperData.SaveProject(projectID, projectName, departmentName, dateCreated, isActive);
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an error saving the project. Report this please. Here are the details\n\n" + ex.ToDetailText(), "TimeKeeper - Save Project Error");
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Ejemplo n.º 5
0
        public DialogResult LoadAndShowDialog(IWin32Window owner, Project editProject = null)
        {
            // Get the department list and update the combo box
            List <string> departments = TimeKeeperData.GetAllProjects().Select(a => a.Department).Distinct().ToList();

            departments.Sort((a, b) => a.CompareTo(b));
            departments.Insert(0, "");

            this.cmboDepartment.DataSource = departments;

            if (editProject != null)
            {
                this.Text = "Edit Project";

                this.txtProjectName.Text = editProject.Name;
                this.cmboDepartment.Text = editProject.Department;
                this.cbIsActive.Checked  = editProject.IsActive;
                this.Tag = editProject;
            }
            else
            {
                this.Text = "Add Project";

                // Reset the form fields
                this.txtProjectName.Text = string.Empty;
                this.cmboDepartment.Text = string.Empty;

                this.cbIsActive.Checked = true;

                this.Tag = null;
            }

            this.txtProjectName.Focus();

            return(this.ShowDialog(owner));
        }
Ejemplo n.º 6
0
 public static List <Project> GetAllProjects()
 {
     return(TimeKeeperData.GetProjects(activeOnly: false));
 }
Ejemplo n.º 7
0
 public static List <Project> GetActiveProjects()
 {
     return(TimeKeeperData.GetProjects(activeOnly: true));
 }