Пример #1
0
        private void setReminder(int masterStatusID)
        {
            int lastStatusID = 0;
            double duration = 0;
            LeadTask task = null;
            DateTime reminderDate = DateTime.MaxValue;
            string sdate = null;

            // return if no change in status
            int.TryParse(ViewState["LastStatusID"].ToString(), out lastStatusID);

            if (lastStatusID == masterStatusID)
                return;

            // get status with reminder duration
            StatusMaster statusMaster = StatusManager.GetStatusId(masterStatusID);

            // return if master status not loaded properly
            if (statusMaster == null)
                return;

            // get task associated with policy
            task = TasksManager.GetPolicyReminderTask(leadID, policyID);

            // master status has no reminder
            if (statusMaster.ReminderMaster == null) {
                // delete existing reminder
                if (task != null)
                    TasksManager.Delete(task.id);
            }
            else {
                if (task == null) {
                    // create new reminder as task
                    task = new LeadTask();
                    task.lead_id = leadID;
                    task.lead_policy_id = policyID;
                    //task.policy_type = policy.PolicyType;
                }

                if (SessionHelper.getClientId() > 0)
                    task.creator_id = SessionHelper.getClientId();

                // update existing reminder
                task.master_status_id = masterStatusID;

                sdate = DateTime.Now.ToShortDateString() + " 5:00:00 AM";

                DateTime.TryParse(sdate, out reminderDate);

                // get duration from status reminder
                if (statusMaster.ReminderMaster != null)
                    duration = (double)(statusMaster.ReminderMaster.Duration ?? 0);

                if ((int)statusMaster.ReminderMaster.DurationType == 1)
                    task.start_date = reminderDate.AddHours(duration);
                else
                    task.start_date = reminderDate.AddDays(duration);

                task.end_date = task.start_date;
                task.status_id = 1;
                task.text = "Alert";
                task.isAllDay = true;
                task.details = statusMaster.StatusName;// +"<div>Ins. Co: " + policy.InsuranceCompanyName + "</div><div>Pol: " + policy.PolicyNumber + "</div>";
                task.owner_id = SessionHelper.getUserId();

                TasksManager.Save(task);
            }
        }
Пример #2
0
        private void bindTasks(DateTime fromDate, DateTime toDate)
        {
            List<LeadTask> tasks = null;

            Expression<Func<CRM.Data.Entities.Task, bool>> predicate = PredicateBuilder.True<CRM.Data.Entities.Task>();

            if (roleID == (int)UserRole.Administrator) {
            }
            else if ((roleID == (int)UserRole.Client || roleID == (int)UserRole.SiteAdministrator) && clientID > 0) {
                // load all tasks for client (sort of admin)

                predicate = predicate.And(LeadTask => LeadTask.creator_id == clientID);

                predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate);

                // get overdue task for client
                predicate = predicate.Or(LeadTask => LeadTask.status_id == 1 && LeadTask.end_date <= toDate && LeadTask.creator_id == clientID);
            }
            else {
                // regular users

                predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate);

                predicate = predicate.And(LeadTask => LeadTask.owner_id == userID);
            }

            tasks = TasksManager.GetLeadTask(predicate, fromDate, toDate);

            if (rbOn.Checked)
            {
                userID = SessionHelper.getUserId();

                CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID);
                string emailaddress = secUser.Email;
                string password = SecurityManager.Decrypt(secUser.emailPassword);
                string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx";

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new WebCredentials(emailaddress, password);
                service.Url = new Uri(url);

                try
                {
                    TasksFolder tasksfolder = TasksFolder.Bind(service, WellKnownFolderName.Tasks);

                    ItemView view = new ItemView(int.MaxValue);
                    FindItemsResults<Item> OutlookTasks = tasksfolder.FindItems(view);

                    CalendarView calView = new CalendarView(fromDate, toDate);

                    FindItemsResults<Item> instanceResults = service.FindItems(WellKnownFolderName.Calendar, calView);

                    foreach (var item in instanceResults)
                    {
                        LeadTask newTask = new LeadTask();
                        Microsoft.Exchange.WebServices.Data.Appointment appointment = item as Microsoft.Exchange.WebServices.Data.Appointment;

                        newTask.creator_id = userID;
                        newTask.details = appointment.Subject;
                        newTask.end_date = appointment.End;
                        newTask.isAllDay = appointment.IsRecurring;
                        newTask.text = appointment.Subject;

                        newTask.priorityName = appointment.Importance.ToString();
                        newTask.owner_name = appointment.Organizer.Name;
                        newTask.start_date = appointment.Start;

                        tasks.Add(newTask);
                    }

                    foreach (var task in OutlookTasks)
                    {
                        task.Load();
                        Microsoft.Exchange.WebServices.Data.Task myTask = task as Microsoft.Exchange.WebServices.Data.Task;

                        LeadTask newTask = new LeadTask();
                        newTask.creator_id = userID;
                        newTask.details = ExtractHtmlInnerText(myTask.Body.Text);
                        newTask.end_date = myTask.DueDate;
                        newTask.isAllDay = myTask.IsRecurring;
                        newTask.text = myTask.Subject;
                        newTask.statusName = myTask.Status.ToString();
                        newTask.priorityName = myTask.Importance.ToString();
                        newTask.owner_name = myTask.Owner;
                        if (myTask.StartDate == null)
                            newTask.start_date = myTask.DueDate;
                        else
                            newTask.start_date = myTask.StartDate;

                        tasks.Add(newTask);
                    }

                }
                catch (Exception ex)
                {

                }
            }
            // show tasks
            gvTasks.DataSource = tasks;
            gvTasks.DataBind();
        }
Пример #3
0
        private List<LeadTask> getSelectedTasks()
        {
            List<LeadTask> tasks = new List<LeadTask>();
            LeadTask task = null;
            DateTime date = DateTime.MinValue;

            foreach (GridViewRow row in gvTasks.Rows) {
                if (row.RowType == DataControlRowType.DataRow) {
                    CheckBox cbxExport = row.FindControl("cbxExport") as CheckBox;

                    if (cbxExport != null && cbxExport.Checked) {
                        task = new LeadTask();
                        Label start_date = row.FindControl("start_date") as Label;

                        DateTime.TryParse(start_date.Text, out date);
                        task.start_date = date;

                        Label end_date = row.FindControl("end_date") as Label;

                        DateTime.TryParse(end_date.Text, out date);
                        task.end_date = date;

                        Label title = row.FindControl("event") as Label;
                        task.text = title.Text;

                        Label details = row.FindControl("details") as Label;
                        task.details = details.Text;

                        tasks.Add(task);
                    }
                }
            }
            return tasks;
        }
Пример #4
0
        public static int Save(LeadTask leadTask)
        {
            Task task = null;

            if (leadTask.id == 0) {
                task = new Task();

                DbContextHelper.DbContext.Add(task);
            }
            else {
                task = DbContextHelper.DbContext.Task.Where(x => x.id == leadTask.id).FirstOrDefault();
            }

            task.creator_id = leadTask.creator_id;
            task.details = leadTask.details;
            task.end_date = leadTask.end_date;
            task.lead_id = leadTask.lead_id;
            task.owner_id = leadTask.owner_id;
            task.start_date = leadTask.start_date;
            task.status_id = leadTask.status_id;
            task.text = leadTask.text;

            task.lead_policy_id = leadTask.lead_policy_id;
            task.master_status_id = leadTask.master_status_id;

            task.policy_type = leadTask.policy_type;

            DbContextHelper.DbContext.SaveChanges();

            return task.id;
        }