Esempio n. 1
0
        private void AddActivityToList(Structures.ActivityType activity)
        {
            var itmx = listView_activities.Items.Add(activity.Name, 0);

            itmx.SubItems.Add(activity.Description);
            itmx.SubItems.Add(activity.Billable.ToString());
            itmx.SubItems.Add(activity.HourlyRate.ToString(CultureInfo.InvariantCulture));
            itmx.SubItems.Add(activity.Currency);
            itmx.Tag = activity;
        }
Esempio n. 2
0
        private void toolStripButton_addActivity_Click(object sender, EventArgs e)
        {
            var activityType = new ActivityType {
                IsEdit = false
            };
            var activityNew = new Structures.ActivityType {
                Id = Guid.NewGuid().ToString()
            };

            activityType.Activity        = activityNew;
            activityType.DefaultCurrency = settings.DefaultCurrency;

            activityType.ShowDialog();

            if (activityType.Saved)
            {
                var foundName = (from ListViewItem itmx in listView_activities.Items
                                 select(Structures.ActivityType) itmx.Tag).Any(activity =>
                                                                               string.Compare(activity.Name, activityType.Activity.Name, StringComparison.OrdinalIgnoreCase) == 0);
                if (foundName)
                {
                    MessageBox.Show(this, @"Unable to save the Activity; name already exists!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    settings.ActivitiesTypes.Add(activityType.Activity);

                    AddActivityToList(activityType.Activity);



                    foreach (var profileInfo in settings.Clients)
                    {
                        var clientActivityType = new ClientActivityType
                        {
                            Id                   = Guid.NewGuid().ToString(),
                            IdActivity           = activityType.Activity.Id,
                            Activated            = activityType.checkBox_activateForAllClients.Checked,
                            HourlyRateClient     = activityType.Activity.HourlyRate,
                            HourlyRateAdjustment = 0
                        };



                        profileInfo.ClientActivities.Add(clientActivityType);
                    }

                    treeView_clients_AfterSelect(null, null);
                }
            }
            label_activities_count.Text = @"Activities: " + listView_activities.Items.Count;
        }
Esempio n. 3
0
        private void CheckAdjustment()
        {
            var comboboxItem = (ComboboxItem)comboBox_activity_type.SelectedItem;

            if (comboboxItem.Value != null)
            {
                var objs = (object[])comboboxItem.Value;

                Structures.ActivityType activityType = null;
                if (objs[0] != null)
                {
                    activityType = (Structures.ActivityType)objs[0];
                }
                ClientActivityType clientActivityType = null;
                if (objs[1] != null)
                {
                    clientActivityType = (ClientActivityType)objs[1];
                }


                Activity.HourlyRate = numericUpDown_hourly_rate_client.Value;

                if (activityType == null)
                {
                    return;
                }

                Activity.Currency = activityType.Currency;

                if (clientActivityType != null)
                {
                    Activity.HourlyRateAdjustment = Activity.HourlyRate - clientActivityType.HourlyRateClient;
                }
                else
                {
                    Activity.HourlyRateAdjustment = Activity.HourlyRate - activityType.HourlyRate;
                }

                if (Activity.HourlyRateAdjustment > 0)
                {
                    label_adjustment.Text      = "+" + Activity.HourlyRateAdjustment;
                    label_adjustment.ForeColor = Color.DarkBlue;
                }
                else if (Activity.HourlyRateAdjustment < 0)
                {
                    label_adjustment.Text      = Activity.HourlyRateAdjustment.ToString(CultureInfo.InvariantCulture);
                    label_adjustment.ForeColor = Color.DarkRed;
                }
                else
                {
                    label_adjustment.Text = string.Empty;
                }

                label_total.Text = Math.Round(numericUpDown_hourly_rate_client.Value * numericUpDown_quantity.Value, 2).ToString(CultureInfo.InvariantCulture);

                label_currency_hourly_rate.Text = activityType.Currency;
                label_currency_total.Text       = activityType.Currency;
            }
            else
            {
                label_total.Text                = @"0";
                label_adjustment.Text           = string.Empty;
                label_currency_hourly_rate.Text = string.Empty;
                label_currency_total.Text       = string.Empty;
            }
        }
Esempio n. 4
0
        private void TrackProjectActivity_Load(object sender, EventArgs e)
        {
            IsLoading = true;

            if (IsMerge)
            {
                Text += @" (Merge)";
            }
            else
            {
                Text += IsEdit ? " (Edit)" : " (New)";
            }

            #region  |  get company profile  |
            foreach (var clientProfileInfo in Tracked.Preferences.Clients)
            {
                if (clientProfileInfo.Id != Project.ClientId)
                {
                    continue;
                }

                Client = clientProfileInfo;
                break;
            }
            #endregion


            textBox_client.Text = Client != null ? Client.ClientName : "[no client]";


            initialize_projects_combobox();

            #region  |  set project  |


            var selectedProjectIndex = 0;
            for (var i = 0; i < comboBox_projects.Items.Count; i++)
            {
                var comboboxItem = (ComboboxItem)comboBox_projects.Items[i];

                if (comboboxItem.Value == null)
                {
                    continue;
                }

                var trackerProject = (TrackerProject)comboboxItem.Value;

                if (trackerProject.Id != Project.Id)
                {
                    continue;
                }

                selectedProjectIndex = i;
                break;
            }

            comboBox_projects.SelectedIndex = selectedProjectIndex;
            #endregion


            initialize_activity_types_combobox();

            #region  |  set activity type  |

            var selectedTypeIndex = 0;
            for (var i = 0; i < comboBox_activity_type.Items.Count; i++)
            {
                var comboboxItem = (ComboboxItem)comboBox_activity_type.Items[i];

                if (comboboxItem.Value == null)
                {
                    continue;
                }

                var objs = (object[])comboboxItem.Value;

                Structures.ActivityType activityType = null;
                if (objs[0] != null)
                {
                    activityType = (Structures.ActivityType)objs[0];
                }
                ClientActivityType clientActivityType = null;
                if (objs[1] != null)
                {
                    clientActivityType = (ClientActivityType)objs[1];
                }


                if (Client != null)
                {
                    if (clientActivityType == null)
                    {
                        continue;
                    }

                    if (clientActivityType.Id != Activity.ActivityTypeClientId)
                    {
                        continue;
                    }

                    selectedTypeIndex = i;
                    break;
                }
                if (activityType != null && activityType.Id != Activity.ActivityTypeId)
                {
                    continue;
                }

                selectedTypeIndex = i;
                break;
            }
            comboBox_activity_type.SelectedIndex = selectedTypeIndex;
            #endregion


            textBox_name.Text        = Activity.Name;
            textBox_description.Text = Activity.Description;


            #region  |  dates/times  |
            if (!IsEdit)
            {
                dateTimePicker_start_date.Value  = DateTime.Now;
                dateTimePicker_start_hours.Value = DateTime.Now;

                dateTimePicker_end_date.Value  = DateTime.Now;
                dateTimePicker_end_hours.Value = DateTime.Now;
            }
            else
            {
                dateTimePicker_start_date.Value  = Activity.DateStart;
                dateTimePicker_start_hours.Value = Activity.DateStart;

                dateTimePicker_end_date.Value  = Activity.DateEnd;
                dateTimePicker_end_hours.Value = Activity.DateEnd;
            }
            #endregion


            comboBox_status.SelectedItem = Activity.Status;

            checkBox_invoiced.Checked          = Activity.Invoiced;
            dateTimePicker_date_invoiced.Value = Activity.InvoicedDate != Common.DateNull ? Activity.InvoicedDate : DateTime.Now;

            checkBox_billable.Checked = Activity.Billable;

            numericUpDown_hourly_rate_client.Value = Activity.HourlyRate;
            numericUpDown_quantity.Value           = Activity.Quantity;

            label_total.Text = Math.Round(numericUpDown_quantity.Value * numericUpDown_hourly_rate_client.Value, 2).ToString(CultureInfo.InvariantCulture);


            textBox_name.Select();

            checkBox_invoiced_CheckedChanged(null, null);


            CheckActivatedControls();

            IsLoading = false;
            CheckAdjustment();
        }
Esempio n. 5
0
        private void CheckActivatedControls()
        {
            richTextBox_activity_type_note.Clear();


            var comboboxItem = (ComboboxItem)comboBox_projects.SelectedItem;

            if (comboboxItem.Value != null)
            {
                var trackerProject = (TrackerProject)comboboxItem.Value;

                Activity.TrackerProjectId     = trackerProject.Id;
                Activity.TrackerProjectName   = trackerProject.Name;
                Activity.TrackerProjectStatus = trackerProject.ProjectStatus;
            }

            var selectedItem = (ComboboxItem)comboBox_activity_type.SelectedItem;


            if (selectedItem.Value != null)
            {
                SaveButtonActive();

                var objs = (object[])selectedItem.Value;

                Structures.ActivityType activityType = null;
                if (objs[0] != null)
                {
                    activityType = (Structures.ActivityType)objs[0];
                }
                ClientActivityType clientActivityType = null;
                if (objs[1] != null)
                {
                    clientActivityType = (ClientActivityType)objs[1];
                }

                richTextBox_activity_type_note.SelectionFont = new Font(richTextBox_activity_type_note.Font.FontFamily.Name, richTextBox_activity_type_note.Font.Size, FontStyle.Bold);
                richTextBox_activity_type_note.ForeColor     = Color.DarkGray;
                richTextBox_activity_type_note.SelectedText += "Note: ";

                if (activityType != null)
                {
                    Activity.ActivityTypeId   = activityType.Id;
                    Activity.ActivityTypeName = activityType.Name;

                    Activity.Currency = activityType.Currency;

                    if (clientActivityType != null)
                    {
                        Activity.ActivityTypeClientId = clientActivityType.Id;

                        if (!IsLoading)
                        {
                            numericUpDown_hourly_rate_client.Value = clientActivityType.HourlyRateClient;
                        }

                        richTextBox_activity_type_note.SelectionFont = new Font(richTextBox_activity_type_note.Font.FontFamily.Name, richTextBox_activity_type_note.Font.Size, FontStyle.Regular);
                        richTextBox_activity_type_note.ForeColor     = Color.DarkGray;
                        richTextBox_activity_type_note.SelectedText += "default hourly rate (client): " + clientActivityType.HourlyRateClient + "; billable: " + activityType.Billable;
                    }
                    else
                    {
                        if (!IsLoading)
                        {
                            numericUpDown_hourly_rate_client.Value = activityType.HourlyRate;
                        }

                        richTextBox_activity_type_note.SelectionFont = new Font(richTextBox_activity_type_note.Font.FontFamily.Name, richTextBox_activity_type_note.Font.Size, FontStyle.Regular);
                        richTextBox_activity_type_note.ForeColor     = Color.DarkGray;
                        richTextBox_activity_type_note.SelectedText += "default hourly rate: " + activityType.HourlyRate + "; billable: " + activityType.Billable;
                    }
                    checkBox_billable.Checked = activityType.Billable;
                }


                checkBox_billable.Enabled = true;
                numericUpDown_hourly_rate_client.Enabled = true;
                numericUpDown_quantity.Enabled           = true;
            }
            else
            {
                SaveButtonActive();

                checkBox_billable.Checked = false;
                numericUpDown_hourly_rate_client.Value = 0;

                checkBox_billable.Enabled = false;
                numericUpDown_hourly_rate_client.Enabled = false;
                numericUpDown_quantity.Enabled           = false;
            }
        }