Ejemplo n.º 1
0
        private void fillChart()
        {
            DateTime currentDate           = DateTime.Now;
            int      TaskCountAll          = 0;
            int      TaskCountFinished     = 0;
            int      TaskCountIncomplete   = 0;
            int      notificationCount     = 0;
            int      newUsersCount         = 0;
            int      newCustomersCount     = 0;
            int      deletedCustomersCount = 0;
            int      newCommentCount       = 0;
            string   a = "";

            vwAllTasks.Clear();
            vwCompletedTasks.Clear();
            vwIncimpleteTasks.Clear();
            vwNewUsers.Clear();
            vwNewCustomers.Clear();
            vwDeletedCustomers.Clear();
            vwNewComment.Clear();
            //FILL Task aid statistics
            foreach (Models.Task t in db.Tasks.ToList())
            {
                if (t.CreationTime.Month == currentDate.Month && t.CreationTime.Year == currentDate.Year)
                {
                    TaskCountAll++;
                    //oAllTasks.Add(t);
                    vwTaskReport item = new vwTaskReport();
                    item.CustomerName = t.Customer.CustomerName;
                    item.UserName     = t.User.Username;
                    item.Description  = t.Description;
                    item.CreationTime = t.CreationTime.ToShortDateString();
                    item.DeadlineTime = t.DeadlineTime.ToShortDateString();
                    item.isFinished   = t.isFinised;
                    if (t.FinishTime != null)
                    {
                        item.FinishedTime = t.FinishTime.Value.ToShortDateString();
                    }
                    vwAllTasks.Add(item);
                }
                if (t.CreationTime.Month == currentDate.Month && t.CreationTime.Year == currentDate.Year && t.isFinised == true)
                {
                    TaskCountFinished++;
                    vwTaskReport item = new vwTaskReport();
                    item.CustomerName = t.Customer.CustomerName;
                    item.UserName     = t.User.Username;
                    item.Description  = t.Description;
                    item.CreationTime = t.CreationTime.ToShortDateString();
                    item.DeadlineTime = t.DeadlineTime.ToShortDateString();
                    item.isFinished   = t.isFinised;
                    if (t.FinishTime != null)
                    {
                        item.FinishedTime = t.FinishTime.Value.ToShortDateString();
                    }
                    vwCompletedTasks.Add(item);
                }

                if (t.CreationTime.Month == currentDate.Month && currentDate.Month == t.DeadlineTime.Month && currentDate.Day - t.DeadlineTime.Day > 0 && t.isFinised == false)
                {
                    TaskCountIncomplete++;
                    vwTaskReport item = new vwTaskReport();
                    item.CustomerName = t.Customer.CustomerName;
                    item.UserName     = t.User.Username;
                    item.Description  = t.Description;
                    item.CreationTime = t.CreationTime.ToShortDateString();
                    item.DeadlineTime = t.DeadlineTime.ToShortDateString();
                    item.isFinished   = t.isFinised;
                    if (t.FinishTime != null)
                    {
                        item.FinishedTime = t.FinishTime.Value.ToShortDateString();
                    }

                    vwIncimpleteTasks.Add(item);
                }
            }
            chrtAllTasks.Value            = TaskCountAll;
            lblCreatedTaskCount.Content   = TaskCountAll;
            chrtCompletedTasks.Value      = TaskCountFinished;
            lblCompletedTaskCount.Content = TaskCountFinished;
            chrtIncompleteTAskCount.Value = TaskCountIncomplete;
            lblDelayedTaskAll.Content     = TaskCountIncomplete;


            //Fill notifications Count

            foreach (Notification n in db.Notifications.ToList())
            {
                if (n.CreationDate.Year == currentDate.Year && n.CreationDate.Month == currentDate.Month)
                {
                    notificationCount++;
                }
            }
            chrtNotificationCount.Value     = notificationCount;
            lblNewNotificationCount.Content = notificationCount;


            //Fill New users count

            foreach (User u in db.Users.ToList())
            {
                if (u.CreationDate.Year == currentDate.Year && u.CreationDate.Month == currentDate.Month)
                {
                    newUsersCount++;
                    vwUsersReport item = new vwUsersReport();
                    item.CreatedBy    = u.CreatedBy;
                    item.FullName     = u.Name + " " + u.Surname;
                    item.Email        = u.Email;
                    item.RoleName     = u.Role.Name;
                    item.Username     = u.Username;
                    item.CreationDate = u.CreationDate.ToShortDateString();
                    vwNewUsers.Add(item);
                }
            }

            chrtNewUsersCount.Value = newUsersCount;
            lblNewUserCount.Content = newUsersCount;
            //Fill new customers count and deleted customers count
            foreach (Customer c in db.Customers.ToList())
            {
                if (c.CreationDate.Year == currentDate.Year && c.CreationDate.Month == currentDate.Month)
                {
                    newCustomersCount++;
                    vwNewCustomer item = new vwNewCustomer();
                    item.CreatedBy     = c.User.Username;
                    item.CustomerName  = c.CustomerName;
                    item.ContactPerson = c.ContactPerson;
                    item.Address       = c.Address;
                    item.OfficePhone   = c.OfficePhoneNumber;
                    item.Mobile        = c.MobilePhone;
                    item.Email         = c.Email;
                    item.CreationDate  = c.CreationDate.ToShortDateString();
                    vwNewCustomers.Add(item);
                }

                if (c.DeactivationDate != null && c.DeactivationDate.Value.Year == currentDate.Year && c.DeactivationDate.Value.Month == currentDate.Month && c.IsActive == false)
                {
                    deletedCustomersCount++;
                    vwNewCustomer item = new vwNewCustomer();
                    item.CreatedBy     = c.User.Username;
                    item.CustomerName  = c.CustomerName;
                    item.ContactPerson = c.ContactPerson;
                    item.Address       = c.Address;
                    item.OfficePhone   = c.OfficePhoneNumber;
                    item.Mobile        = c.MobilePhone;
                    item.Email         = c.Email;
                    item.CreationDate  = c.CreationDate.ToShortDateString();
                    vwDeletedCustomers.Add(item);
                }
            }
            chrtNewCustomersCount.Value     = newCustomersCount;
            lblNewCustomerCount.Content     = newCustomersCount;
            chrtDeletedCustomersCount.Value = deletedCustomersCount;
            lblDeletedCustomerCount.Content = deletedCustomersCount;

            //Fill Comment count

            foreach (Comment com in db.Comments.ToList())
            {
                if (com.CreationDate.Year == currentDate.Year && com.CreationDate.Month == currentDate.Month)
                {
                    newCommentCount++;
                    vwCommentReport item = new vwCommentReport();
                    item.CreatedBy    = com.User.Username;
                    item.CustomerName = com.Customer.CustomerName;
                    item.Text         = com.Text;
                    item.CreationDate = com.CreationDate.ToShortDateString();
                    vwNewComment.Add(item);
                }
            }
            chrtNewCommenetCount.Value = newCommentCount;
            lblNewCommentCount.Content = newCommentCount;

            using (TextWriter tw = new StreamWriter(path, true))
            {
                tw.WriteLine("{0} {1} Success:  User {2} with privelegies level : {3} generated monthly report for {4}, {5}", DateTime.Now.ToLongTimeString(),
                             DateTime.Now.ToShortDateString(), currentUser.Username, currentUser.Role.Name, DateTime.Now.ToString("MMMM"), DateTime.Now.Year);
            }
        }
Ejemplo n.º 2
0
        //Thismetod generates statistics for all user for date range
        private void FillCustomDate()
        {
            DateTime start = dtpStartTime.SelectedDate.Value;

            Xstart = dtpStartTime.SelectedDate.Value.ToShortDateString();
            DateTime finish = dtpFinishTime.SelectedDate.Value;

            Xend = dtpFinishTime.SelectedDate.Value.ToShortDateString();
            DateTime current               = DateTime.Now;
            int      TaskCountAll          = 0;
            int      TaskCountFinished     = 0;
            int      TaskCountIncomplete   = 0;
            int      notificationCount     = 0;
            int      newUsersCount         = 0;
            int      newCustomersCount     = 0;
            int      deletedCustomersCount = 0;
            int      newCommentCount       = 0;

            vwAllTasks.Clear();
            vwCompletedTasks.Clear();
            vwIncimpleteTasks.Clear();
            vwNewUsers.Clear();
            vwNewCustomers.Clear();
            vwDeletedCustomers.Clear();
            vwNewComment.Clear();
            #region Fill custom date Task
            foreach (Models.Task t in db.Tasks.ToList())
            {
                if (t.CreationTime.InRange(start, finish))
                {
                    TaskCountAll++;
                    vwTaskReport item = new vwTaskReport();
                    item.CustomerName = t.Customer.CustomerName;
                    item.UserName     = t.User.Username;
                    item.Description  = t.Description;
                    item.CreationTime = t.CreationTime.ToShortDateString();
                    item.DeadlineTime = t.DeadlineTime.ToShortDateString();
                    item.isFinished   = t.isFinised;
                    if (t.FinishTime != null)
                    {
                        item.FinishedTime = t.FinishTime.Value.ToShortDateString();
                    }
                    vwAllTasks.Add(item);
                }
                if (t.DeadlineTime.InRange(start, finish) && t.isFinised == true)
                {
                    TaskCountFinished++;
                    vwTaskReport item = new vwTaskReport();
                    item.CustomerName = t.Customer.CustomerName;
                    item.UserName     = t.User.Username;
                    item.Description  = t.Description;
                    item.CreationTime = t.CreationTime.ToShortDateString();
                    item.DeadlineTime = t.DeadlineTime.ToShortDateString();
                    item.isFinished   = t.isFinised;
                    if (t.FinishTime != null)
                    {
                        item.FinishedTime = t.FinishTime.Value.ToShortDateString();
                    }
                    vwCompletedTasks.Add(item);
                }

                if (t.CreationTime.InRange(start, finish) && finish > t.DeadlineTime && current > t.DeadlineTime && t.isFinised == false)
                {
                    TaskCountIncomplete++;
                    vwTaskReport item = new vwTaskReport();
                    item.CustomerName = t.Customer.CustomerName;
                    item.UserName     = t.User.Username;
                    item.Description  = t.Description;
                    item.CreationTime = t.CreationTime.ToShortDateString();
                    item.DeadlineTime = t.DeadlineTime.ToShortDateString();
                    item.isFinished   = t.isFinised;
                    if (t.FinishTime != null)
                    {
                        item.FinishedTime = t.FinishTime.Value.ToShortDateString();
                    }

                    vwIncimpleteTasks.Add(item);
                }
            }
            chrtAllTasks.Value            = TaskCountAll;
            lblCreatedTaskCount.Content   = TaskCountAll;
            chrtCompletedTasks.Value      = TaskCountFinished;
            lblCompletedTaskCount.Content = TaskCountFinished;
            chrtIncompleteTAskCount.Value = TaskCountIncomplete;
            lblDelayedTaskAll.Content     = TaskCountIncomplete;
            #endregion
            #region Fill custom date notification statistics
            foreach (Notification n in db.Notifications.ToList())
            {
                if (n.CreationDate.InRange(start, finish))
                {
                    notificationCount++;
                }
            }
            chrtNotificationCount.Value     = notificationCount;
            lblNewNotificationCount.Content = newCommentCount;
            #endregion
            #region Fill custom date user statistics
            foreach (User u in db.Users.ToList())
            {
                if (u.CreationDate.InRange(start, finish))
                {
                    newUsersCount++;
                    vwUsersReport item = new vwUsersReport();
                    item.CreatedBy    = u.CreatedBy;
                    item.FullName     = u.Name + " " + u.Surname;
                    item.Email        = u.Email;
                    item.RoleName     = u.Role.Name;
                    item.Username     = u.Username;
                    item.CreationDate = u.CreationDate.ToShortDateString();
                    vwNewUsers.Add(item);
                }
            }

            chrtNewUsersCount.Value = newUsersCount;
            lblNewUserCount.Content = newUsersCount;

            #endregion
            #region Fill custom date customer related statistics
            foreach (Customer c in db.Customers.ToList())
            {
                if (c.CreationDate.InRange(start, finish))
                {
                    newCustomersCount++;
                    vwNewCustomer item = new vwNewCustomer();
                    item.CreatedBy     = c.User.Username;
                    item.CustomerName  = c.CustomerName;
                    item.ContactPerson = c.ContactPerson;
                    item.Address       = c.Address;
                    item.OfficePhone   = c.OfficePhoneNumber;
                    item.Mobile        = c.MobilePhone;
                    item.Email         = c.Email;
                    item.CreationDate  = c.CreationDate.ToShortDateString();
                    vwNewCustomers.Add(item);
                }

                if (c.DeactivationDate != null && c.CreationDate.InRange(start, finish) && c.IsActive == false)
                {
                    deletedCustomersCount++;
                    vwNewCustomer item = new vwNewCustomer();
                    item.CreatedBy     = c.User.Username;
                    item.CustomerName  = c.CustomerName;
                    item.ContactPerson = c.ContactPerson;
                    item.Address       = c.Address;
                    item.OfficePhone   = c.OfficePhoneNumber;
                    item.Mobile        = c.MobilePhone;
                    item.Email         = c.Email;
                    item.CreationDate  = c.CreationDate.ToShortDateString();
                    vwDeletedCustomers.Add(item);
                }
            }
            chrtNewCustomersCount.Value     = newCustomersCount;
            lblNewCustomerCount.Content     = newCustomersCount;
            chrtDeletedCustomersCount.Value = deletedCustomersCount;
            lblDeletedCustomerCount.Content = deletedCustomersCount;
            #endregion
            #region Fill custom date comments statistics
            foreach (Comment com in db.Comments.ToList())
            {
                if (com.CreationDate.InRange(start, finish))
                {
                    newCommentCount++;
                    vwCommentReport item = new vwCommentReport();
                    item.CreatedBy    = com.User.Username;
                    item.CustomerName = com.Customer.CustomerName;
                    item.Text         = com.Text;
                    item.CreationDate = com.CreationDate.ToShortDateString();
                    vwNewComment.Add(item);
                }
            }
            chrtNewCommenetCount.Value = newCommentCount;
            lblNewCommentCount.Content = newCommentCount;
            #endregion
            using (TextWriter tw = new StreamWriter(path, true))
            {
                tw.WriteLine("{0} {1} Success:  User {2} with privelegies level : {3} generated report for period {4} -  {5}", DateTime.Now.ToLongTimeString(),
                             DateTime.Now.ToShortDateString(), currentUser.Username, currentUser.Role.Name, start.ToShortDateString(), finish.ToShortDateString());
            }
        }