Beispiel #1
0
        protected void lbtnClearRecurrence_Click(object sender, EventArgs e)
        {
            txtRecurrenceEndDate.Text   = string.Empty;
            txtRecurrenceStartDate.Text = string.Empty;
            ddlRecurringRepeatFrequency.SelectedIndex = 0;

            if (ViewState["RecurringID"] != null)
            {
                RecurrenceManager.Delete(Convert.ToInt32(ViewState["RecurringID"]));
            }
        }
Beispiel #2
0
        protected void lbtnClearRecurrence_Click(object sender, EventArgs e)
        {
            txtRecurrenceEndDate.Text   = string.Empty;
            txtRecurrenceStartDate.Text = string.Empty;
            ddlRecurringRepeatFrequency.SelectedIndex = 0;

            if (ViewState["RecurringID"] != null)
            {
                RecurrenceManager.Delete(Convert.ToInt32(ViewState["RecurringID"]));

                // after recurrence is deleted, all tasks associated with recurrence are also deleted.
                // return to activities after deleting
                btnCancel_Click(sender, e);
            }
        }
Beispiel #3
0
        public void saveEvent()
        {
            Task       task       = null;
            Recurrence recurrence = null;
            Reminder   reminder   = null;
            string     success    = "Event saved successfully.";
            string     error      = "Event was not saved.";

            int taskID = Convert.ToInt32(hf_taskID.Value);

            int clientID = SessionHelper.getClientId();

            if (taskID > 0)
            {
                // edit
                task = TasksManager.Get(taskID);
            }
            else
            {
                // new
                task            = new Task();
                task.creator_id = clientID;
                task.TaskType   = 2;                    // save task as an event
                task.status_id  = 1;
            }

            if (task != null)
            {
                try {
                    task.text             = txtSubject.Text.Trim();
                    task.details          = txtDescription.Text.Trim();
                    task.start_date       = txtEventDateTimeStart.Date;
                    task.end_date         = txtEventDateTimeEnd.Date;
                    task.owner_id         = Convert.ToInt32(ddlOwner.SelectedValue);
                    task.ReminderInterval = Convert.ToInt32(ddlReminderWhen.SelectedValue);

                    using (TransactionScope scope = new TransactionScope()) {
                        taskID = TasksManager.Save(task);

                        hf_taskID.Value = taskID.ToString();

                        // reminder
                        if (ddlReminderWhen.SelectedIndex > 0 && task.Reminder != null && task.Reminder.Count == 0)
                        {
                            // new reminder
                            reminder        = new Reminder();
                            reminder.TaskID = taskID;

                            saveReminder(reminder);
                        }
                        else if (ddlReminderWhen.SelectedIndex > 0 && task.Reminder != null && task.Reminder.Count == 1)
                        {
                            // edit existing reminder
                            reminder = task.Reminder.FirstOrDefault();

                            saveReminder(reminder);
                        }
                        else if (ddlReminderWhen.SelectedIndex == 0 && task.Reminder != null && task.Reminder.Count == 1 && ViewState["ReminderID"] != null)
                        {
                            // delete reminder
                            ReminderManager.Delete(Convert.ToInt32(ViewState["ReminderID"]));
                        }

                        // recurring
                        if (!string.IsNullOrEmpty(txtRecurrenceStartDate.Text) && task.Recurrence == null)
                        {
                            // new recurrence
                            recurrence        = new Recurrence();
                            recurrence.TaskID = taskID;

                            saveRecurrence(recurrence);
                        }
                        else if (!string.IsNullOrEmpty(txtRecurrenceStartDate.Text) && task.Recurrence != null)
                        {
                            // edit recurrence
                            recurrence = (Recurrence)task.Recurrence;

                            saveRecurrence(recurrence);
                        }
                        else if (string.IsNullOrEmpty(txtRecurrenceStartDate.Text) && task.Recurrence != null && ViewState["RecurringID"] != null)
                        {
                            // delete recurrence
                            RecurrenceManager.Delete(Convert.ToInt32(ViewState["RecurringID"]));
                        }

                        // commit changes to DB
                        scope.Complete();
                    }

                    // allow user to add invitees
                    pnlInvitees.Visible = true;

                    if (this.Page is CRM.Web.Protected.EventEdit)
                    {
                        ((CRM.Web.Protected.EventEdit) this.Page).setErrorMessage(success, "ok");
                    }
                    else if (this.Page is CRM.Web.Protected.EventEditPopUp)
                    {
                        ((CRM.Web.Protected.EventEditPopUp) this.Page).setErrorMessage(success, "ok");
                    }

                    //lblMessage.Text = "Event saved successfully.";
                    //lblMessage.CssClass = "ok";
                }
                catch (Exception ex) {
                    Core.EmailHelper.emailError(ex);
                    if (this.Page is CRM.Web.Protected.EventEdit)
                    {
                        ((CRM.Web.Protected.EventEdit) this.Page).setErrorMessage(error, "error");
                    }
                    else if (this.Page is CRM.Web.Protected.EventEditPopUp)
                    {
                        ((CRM.Web.Protected.EventEditPopUp) this.Page).setErrorMessage(error, "error");
                    }

                    //lblMessage.Text = "Event was not saved.";
                    //lblMessage.CssClass = "error";
                }
            }
        }
Beispiel #4
0
        private void saveTask()
        {
            int?       contactID  = 0;
            Task       task       = null;
            Recurrence recurrence = null;
            int        taskID     = 0;

            clientID = SessionHelper.getClientId();

            if (this.TaskID > 0)
            {
                // edit
                task = TasksManager.Get(this.TaskID);
            }
            else
            {
                // new
                task            = new Task();
                task.creator_id = this.clientID;
                task.TaskType   = (int)Globals.TaskType.Task;
            }

            if (task != null)
            {
                try
                {
                    contactID = Convert.ToInt32(hf_contactID.Value);

                    task.text       = txtSubject.Text.Trim();
                    task.details    = txtDescription.Text.Trim();
                    task.start_date = txtDateDue.Date;
                    task.status_id  = Convert.ToInt32(ddlTaskStatus.SelectedValue);
                    task.owner_id   = Convert.ToInt32(ddlOwner.SelectedValue);
                    task.PriorityID = Convert.ToInt32(ddlPriority.SelectedValue);

                    // contact information
                    task.ContactID = contactID > 0 ? contactID : null;

                    using (TransactionScope scope = new TransactionScope())
                    {
                        // recurring
                        if (!string.IsNullOrEmpty(txtRecurrenceStartDate.Text) && task.Recurrence.Count <= 0)
                        {
                            // new recurrence
                            recurrence        = new Recurrence();
                            recurrence.TaskID = task.id;
                            saveRecurrence(recurrence);

                            generateRecurrenceSequence(task, recurrence);
                        }
                        else if (!string.IsNullOrEmpty(txtRecurrenceStartDate.Text) && task.Recurrence.Count > 0)
                        {
                            // edit recurrence
                            //recurrence = (Recurrence)task.Recurrence;
                            foreach (Recurrence recu in task.Recurrence)
                            {
                                editRecurrence(recu);


                                RecurrenceManager.DeleteTasks(Convert.ToInt32(ViewState["RecurringID"]));

                                generateRecurrenceSequence(task, recu);
                            }
                        }
                        else if (string.IsNullOrEmpty(txtRecurrenceStartDate.Text) && string.IsNullOrEmpty(txtRecurrenceEndDate.Text) &&
                                 task.Recurrence != null && ViewState["RecurringID"] != null)
                        {
                            // delete recurrence along with tasks
                            RecurrenceManager.Delete(Convert.ToInt32(ViewState["RecurringID"]));
                        }
                        else
                        {
                            // save task with no recurrence
                            taskID = TasksManager.Save(task);
                        }

                        // commit changes to DB
                        scope.Complete();
                    }

                    lblMessage.Text     = "Task saved successfully.";
                    lblMessage.CssClass = "ok";
                }
                catch (Exception ex)
                {
                    Core.EmailHelper.emailError(ex);

                    lblMessage.Text     = "Task was not saved.";
                    lblMessage.CssClass = "error";
                }
            }
        }