/// <summary> /// Edit a Task object showing a specific section. /// </summary> /// <param name="task">Task to edit</param> /// <param name="start_tab">The forst section to show</param> public TaskForm(Languages.Language language, Utils.AppSettings settings, Task task, StartingTab start_tab) { // Windows Forms designer support. InitializeComponent(); // Setup task this.task = task; // Form icon System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TaskForm)); Icon = (task.Id == 0) ? ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))) : ((System.Drawing.Icon)(resources.GetObject("$this.Icon2"))); // Language Lang = language; Text = Lang.Get((task.Id == 0) ? "task_add" : "task_edit"); btnOk.Text = " " + Lang.Get((task.Id == 0) ? "add" : "edit"); btnCancel.Text = Lang.Get("cancel"); ApplyLanguage(); // Settings Settings = settings; lblCurrency.Text = Settings.Get("currency").ToString(); // Starting tab switch (start_tab) { case StartingTab.DatesTime: tabs.SelectedTab = tabDatesTime; break; case StartingTab.Payment: tabs.SelectedTab = tabPayment; break; case StartingTab.Notes: tabs.SelectedTab = tabNotes; break; } // Populate combos PopulateColourCombo(); PopulatePriorityCombo(); PopulatePaymentCombo(); if (task.IsRoot()) { PopulateCategoryCombo(task.CategoryId); // Category combo also for root tasks } // Fill in GUI fields (general) txtName.Text = task.Name; try { txtDescription.Text = task.Description; } catch { txtDescription.Text = ""; } foreach (ImageComboItem item in cmbColour.Items) { if (item.Text == Lang.Get("colour_as") + " " + task.Name) { cmbColour.SelectedItem = item; } } cmbPriority.SelectedIndex = task.Priority % 3; // Fill in GUI fields (dates and time) dtCreationDate.Value = task.CreationDate; try { dtDueDate.Value = task.DueDate; chkDueDateNot.Checked = false; } catch { chkDueDateNot.Checked = true; } try { dtCompleted.Value = task.Completed; chkCompletedNot.Checked = false; } catch { chkCompletedNot.Checked = true; } try { int t = task.Timer; chkUseTimer.Checked = true; } catch { chkUseTimer.Checked = false; } try { numTimerS.Value = task.Timer % 60; numTimerM.Value = ((task.Timer - numTimerS.Value) / 60) % 60; numTimerH.Value = (task.Timer - numTimerS.Value - numTimerM.Value * 60) / (60 * 60); } catch { } // If the timer is running, disable timer fields. if (task.IsTimerRunning()) { chkUseTimer.Enabled = false; lblTimer.Visible = btnTimerReset.Visible = btnSumTimers.Visible = false; numTimerS.Visible = numTimerM.Visible = numTimerH.Visible = false; lblTimerS.Visible = lblTimerM.Visible = lblTimerH.Visible = false; panCannotEditTimer.Visible = true; lblCannotEditTimer.Text = Lang.Get("task_timer_is_running"); } // Fill in GUI fields (payment) try { chkPerHour.Checked = task.PricingByHour; if (task.PricingByHour) { numPrice.Value = (Decimal)task.PriceByHour; } else { numPrice.Value = (Decimal)task.Price; } chkPriceNot.Checked = false; } catch { chkPriceNot.Checked = true; } try { dtPaid.Value = task.Paid; chkPaidNot.Checked = false; } catch { chkPaidNot.Checked = true; } try { cmbPaymentType.Text = task.Payment; } catch { } try { txtPaymentNote.Text = task.PaymentNote; } catch { txtPaymentNote.Text = ""; } chkPerHour.Enabled = !chkPriceNot.Checked; // Show/hide task parent if (task.ParentId != 0) { cmbCategory.Hide(); } lblCategory.Visible = btnAddCategory.Visible = (task.ParentId == 0); btnAddCategory.Enabled = (task.ParentId == 0); lblSubTaskOf.Visible = panParent.Visible = (task.ParentId != 0); // Setup task parent if (!task.IsRoot()) { try { Task parent = new Task(task.ParentId); lblParentName.Text = parent.Name; boxParentIcon.Image = IconColoured.GetSquared(parent.Colour); task.CategoryId = parent.CategoryId; // Same category of the parent! if (task.Id == 0) { foreach (ImageComboItem item in cmbColour.Items) { if (item.Text == Lang.Get("colour_as") + " " + parent.Name) { cmbColour.SelectedItem = item; } } } } catch { lblParentName.Text = Lang.Get("task_loading_error"); boxParentIcon.Image = IconColoured.GetSquared(Color.Gray); } } // Notes settings (this is not so good, calling MainForm in this way...) try { notes_monospace_font = new FontFamily("Consolas"); } catch { } chkMonospace.Checked = (Todomoo.mainForm.Settings.Get("note_monospace").ToString() == "1"); chkWordWrap.Checked = (Todomoo.mainForm.Settings.Get("note_word_wrap").ToString() == "1"); // Draw note accordion DrawNotesAccordion(); // Form size and "sizeability" TabsSelectedIndexChanged(); TaskFormResize(); }
/// <summary> /// Update properties of the Task object. /// </summary> public bool Save() { // Check compulsory fields if (txtName.Text == "") { Utils.MsgDialog.Warning(Lang.Get("invalid_entry"), Lang.Get("warning")); tabs.SelectedTab = tabGeneral; txtName.Focus(); return(false); } // Check if there is no category if (cmbCategory.Enabled == false) { Utils.MsgDialog.Warning(Lang.Get("category_must_create"), Lang.Get("warning")); tabs.SelectedTab = tabGeneral; if (btnAddCategory.Visible && btnAddCategory.Enabled) { btnAddCategory.Focus(); } return(false); } // Update fields from the GUI (General) task.Name = txtName.Text; if (txtDescription.Text != "") { task.Description = txtDescription.Text; } else { task.RemoveDescription(); } task.Colour = (Color)(((ImageComboItem)cmbColour.SelectedItem).Tag); task.Priority = cmbPriority.SelectedIndex; // Category switch if (task.IsRoot()) { int newCategory = (int)(((ImageComboItem)cmbCategory.SelectedItem).Tag); if (newCategory != task.CategoryId) { Todomoo.ChangeCategoryToHierarchy(task, newCategory); } } // Update fields from the GUI (Dates and time) task.CreationDate = dtCreationDate.Value; if (!chkDueDateNot.Checked) { task.DueDate = dtDueDate.Value; } else { task.RemoveDueDate(); } if (!chkCompletedNot.Checked) { task.Completed = dtCompleted.Value; } else { task.RemoveCompleted(); } if (!task.IsTimerRunning()) { if (chkUseTimer.Checked) { task.Timer = (int)numTimerS.Value + (int)numTimerM.Value * 60 + (int)numTimerH.Value * 60 * 60; } else { task.RemoveTimer(); } } // Update fields from the GUI (Payment) if (!chkPriceNot.Checked) { task.PricingByHour = chkPerHour.Checked; if (task.PricingByHour) { task.PriceByHour = (float)numPrice.Value; } else { task.Price = (float)numPrice.Value; } } else { task.RemovePrice(); } if ((!chkPaidNot.Checked) && (!chkPriceNot.Checked)) { task.Paid = dtPaid.Value; } else { task.RemovePaid(); } if ((!chkPaidNot.Checked) && (!chkPriceNot.Checked)) { task.Payment = cmbPaymentType.Text; } else { task.RemovePayment(); } if (txtPaymentNote.Text != "") { task.PaymentNote = txtPaymentNote.Text; } else { task.RemovePaymentNote(); } // Say to the task object the notes to update ArrayList pending_notes = new ArrayList(); foreach (Control item in accordion.Controls) { if (item is AccordionItem) { try { pending_notes.Add((Note)item.Tag); } catch { } } } task.SetUnsavedNotes(pending_notes); return(true); }