Exemplo n.º 1
0
        public static UserEffort MaxAllocationValidation(string userName, DateTime startDate, DateTime endDate, int inputEffort, int projectResourceId)
        {
            double TotalEffort = 0;
            double Duration = 0;
            double TotalCurrentEffort = 0;
            double UserEffort = 0;
            double UserMaxEffort = 0;
            double RemEffort = 0;
            double UserRequestdEffort = 0;
            string SelStartDate = null;
            string SelEndDate = null;

            Hashtable HTResource = new Hashtable();

            /*------------------Calculate Period------------------------*/

            TimeSpan tsDuration = endDate.Subtract(startDate);
            Duration = tsDuration.TotalDays;

            /*-----------------Calculate MaximumUserEffort for Given User-----------*/

            List<PM_MaxUserEfforts> ListUserEfforts = null;
            PM_ProjectResources projectRes = null;
            MembershipUser edituser = null;
            if (projectResourceId == 0)
            {
                 edituser = Membership.GetUser(userName);

                IQueryable<PM_MaxUserEfforts> maxUserEffortQuery = from m in GetSynegyRMSInstance().PM_MaxUserEfforts
                                                                   where m.aspnet_Users.UserName == edituser.UserName
                                                                   select m;

                ListUserEfforts = maxUserEffortQuery.ToList();
                UserMaxEffort = Convert.ToDouble(ListUserEfforts[0].MaxEffort);
                UserEffort = UserMaxEffort;

            }
            else
            {

                projectRes = SynergyService.GetResouceById(projectResourceId);

                edituser = Membership.GetUser(projectRes.aspnet_Users.UserName);

                IQueryable<PM_MaxUserEfforts> maxUserEffortQuery = from m in GetSynegyRMSInstance().PM_MaxUserEfforts
                                                                   where m.aspnet_Users.UserName == edituser.UserName
                                                                   select m;

                ListUserEfforts = maxUserEffortQuery.ToList();
                UserMaxEffort = Convert.ToDouble(ListUserEfforts[0].MaxEffort);
                UserEffort = UserMaxEffort;

            }

            /*----------------------Calculate Current Allocation-------------------------*/

            List<PM_ProjectResources> ResList = new List<PM_ProjectResources>();
            List<PM_ProjectResources> ResourceList = null;
            List<PM_ProjectResources> ResourceList2 = null;

            if (projectResourceId == 0)
            {

                /*------------- Addded New Project Resource---------------------------*/

                IQueryable<PM_ProjectResources> projectQuery = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                               where ((p.aspnet_Users.UserName == edituser.UserName) && ((p.AllocatedStartDate >= startDate && p.AllocatedStartDate <= endDate) || (p.AllocatedEndDate >= startDate && p.AllocatedEndDate <= endDate)))
                                                               select p;

                IQueryable<PM_ProjectResources> projectQuery2 = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                                where ((p.aspnet_Users.UserName == edituser.UserName) && ((p.AllocatedStartDate <= startDate && p.AllocatedEndDate >= startDate) || (p.AllocatedStartDate <= endDate && p.AllocatedEndDate >= endDate)))
                                                                select p;

                ResourceList = projectQuery.ToList();

                ResourceList2 = projectQuery2.ToList();

                foreach (PM_ProjectResources resorcesObj in ResourceList)
                {

                    ResList.Add(resorcesObj);
                    HTResource.Add(resorcesObj.ProjectResorcesId, 0);
                }

                foreach (PM_ProjectResources resorcesObj in ResourceList2)
                {

                    if (!HTResource.Contains(resorcesObj.ProjectResorcesId))
                    {
                        ResList.Add(resorcesObj);
                    }
                }
            }
            else
            {

                /*------------- Updated New Project Resource---------------------------*/

                SelStartDate = startDate.ToString().Substring(0,8);
                SelEndDate = endDate.ToString().Substring(0,8);
                if (SelStartDate == "1/1/0001" || SelEndDate == "1/1/0001")
                {
                    IQueryable<PM_ProjectResources> projectQuery = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                                   where ((p.aspnet_Users.UserName == edituser.UserName) && (p.ProjectResorcesId != projectResourceId) && ((p.AllocatedStartDate >= projectRes.AllocatedStartDate && p.AllocatedStartDate <= projectRes.AllocatedEndDate) || (p.AllocatedEndDate >= projectRes.AllocatedStartDate && p.AllocatedEndDate <= projectRes.AllocatedEndDate)))
                                                                   select p;

                    IQueryable<PM_ProjectResources> projectQuery2 = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                                    where ((p.aspnet_Users.UserName == edituser.UserName) && (p.ProjectResorcesId != projectResourceId) && ((p.AllocatedStartDate <= projectRes.AllocatedStartDate && p.AllocatedEndDate >= projectRes.AllocatedStartDate) || (p.AllocatedStartDate <= projectRes.AllocatedEndDate && p.AllocatedEndDate >= projectRes.AllocatedEndDate)))
                                                                    select p;

                    ResourceList = projectQuery.ToList();

                    ResourceList2 = projectQuery2.ToList();

                    foreach (PM_ProjectResources resorcesObj in ResourceList)
                    {
                        ResList.Add(resorcesObj);
                        HTResource.Add(resorcesObj.ProjectResorcesId, 0);
                    }

                    foreach (PM_ProjectResources resorcesObj in ResourceList2)
                    {
                        if (!HTResource.Contains(resorcesObj.ProjectResorcesId))
                        {
                            ResList.Add(resorcesObj);
                        }
                    }

                }
                else
                {

                    IQueryable<PM_ProjectResources> projectQuery = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                                   where ((p.aspnet_Users.UserName == edituser.UserName) && (p.ProjectResorcesId != projectResourceId) && ((p.AllocatedStartDate >= startDate && p.AllocatedStartDate <= endDate) || (p.AllocatedEndDate >= startDate && p.AllocatedEndDate <= endDate)))
                                                                   select p;

                    IQueryable<PM_ProjectResources> projectQuery2 = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                                    where ((p.aspnet_Users.UserName == edituser.UserName) && (p.ProjectResorcesId != projectResourceId) && ((p.AllocatedStartDate <= startDate && p.AllocatedEndDate >= startDate) || (p.AllocatedStartDate <= endDate && p.AllocatedEndDate >= endDate)))
                                                                    select p;

                    ResourceList = projectQuery.ToList();

                    ResourceList2 = projectQuery2.ToList();

                    foreach (PM_ProjectResources resorcesObj in ResourceList)
                    {
                        ResList.Add(resorcesObj);
                        HTResource.Add(resorcesObj.ProjectResorcesId, 0);
                    }

                    foreach (PM_ProjectResources resorcesObj in ResourceList2)
                    {
                        if (!HTResource.Contains(resorcesObj.ProjectResorcesId))
                        {
                            ResList.Add(resorcesObj);
                        }
                    }

                }

            }

            if (ResList != null)
            {
                if (ResList.Count > 0)
                {

                    foreach (PM_ProjectResources objResources in ResList)
                    {
                        double projectEffort = Convert.ToDouble(objResources.Effort);
                        TotalCurrentEffort = TotalCurrentEffort + projectEffort;

                        //objResources.UM_UsersReference.Load();
                        //int aa = single1.T_User.UserId;
                    }
                }
                else
                {
                    /*-----Current Allocation is 0 for the Given period--------*/
                    TotalCurrentEffort = 0;
                }
            }

            else
            {
                /*-----Current Allocation is 0 for the Given period--------*/
                TotalCurrentEffort = 0;
            }

            /*--------------------Total  Effort For the given period ---------------*/

            TotalEffort = UserMaxEffort;

            /*-----------------------Check Allocation----------------------------- */

            RemEffort = TotalEffort - TotalCurrentEffort;

            /*----------------------Calculate requested Effort------------------------*/

            UserRequestdEffort = inputEffort;

            /*--------------calculate Remaining Effort----------------*/

            UserEffort effortObj = new UserEffort();

            if (RemEffort >= UserRequestdEffort)
            {

                /*-----------------Fill Information -------------------*/

                effortObj.RemEffort = RemEffort;
                effortObj.IsCanAllocated = true;
                effortObj.CustomeMessge = "Allocation Is Done";

            }
            else
            {
                effortObj.RemEffort = RemEffort;
                effortObj.IsCanAllocated = false;
                effortObj.CustomeMessge = "Maximum Allocation Excedded";
            }

            return effortObj;
        }
Exemplo n.º 2
0
        public static UserEffort ValidateMaxAllocation(string userkey, DateTime startDate, DateTime endDate, int inputEffort, int projectResourceId)
        {
            double TotalEffort = 0;
            double Duration = 0;
            double TotalCurrentEffort = 0;
            double UserEffort = 0;
            double UserMaxEffort = 0;
            double RemEffort = 0;
            double UserRequestdEffort = 0;
            double NoOfRemainingDays = 0;
            Hashtable HTResource = new Hashtable();

            /*------------------Calculate Period------------------------*/

            TimeSpan tsDuration = endDate.Subtract(startDate);
            Duration = tsDuration.TotalDays;

            /*-----------------Calculate MaximumUserEffort for Given User-----------*/

            List<PM_MaxUserEfforts> ListUserEfforts = null;

            MembershipUser edituser = Membership.GetUser(new Guid(userkey));

            IQueryable<PM_MaxUserEfforts> maxUserEffortQuery = from m in GetSynegyRMSInstance().PM_MaxUserEfforts
                                                               where m.aspnet_Users.UserName == edituser.UserName
                                                               select m;

            ListUserEfforts = maxUserEffortQuery.ToList();
            UserMaxEffort = Convert.ToDouble(ListUserEfforts[0].MaxEffort);
            UserEffort = UserMaxEffort * Duration;

            /*----------------------Calculate Current Allocation-------------------------*/

            List<PM_ProjectResources> ResList = new List<PM_ProjectResources>();
            List<PM_ProjectResources> ResourceList = null;
            List<PM_ProjectResources> ResourceList2 = null;

            if (projectResourceId == 0)
            {

                /*------------- Addded New Project Resource---------------------------*/

                IQueryable<PM_ProjectResources> projectQuery = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                               where  ((p.aspnet_Users.UserName == edituser.UserName) && ((p.AllocatedStartDate >= startDate && p.AllocatedStartDate <= endDate) || (p.AllocatedEndDate >= startDate && p.AllocatedEndDate <= endDate)))
                                                               select p;

                IQueryable<PM_ProjectResources> projectQuery2 = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                                where ((p.aspnet_Users.UserName == edituser.UserName) && ((p.AllocatedStartDate <= startDate && p.AllocatedEndDate >= startDate) || (p.AllocatedStartDate <= endDate && p.AllocatedEndDate >= endDate)))
                                                               select p;

                //IQueryable<PM_ProjectResources> projectQuery = from p in GetSynegyRMSInstance().PM_ProjectResources
                //                                               where ((p.aspnet_Users.UserName == edituser.UserName) && ((p.AllocatedStartDate <= startDate && p.AllocatedEndDate >= startDate) || (p.AllocatedStartDate <= endDate && p.AllocatedEndDate <= endDate)))
                //                                               select p;

                ResourceList = projectQuery.ToList();

                ResourceList2 = projectQuery2.ToList();

                foreach (PM_ProjectResources resorcesObj in ResourceList)
                {

                    ResList.Add(resorcesObj);
                    HTResource.Add(resorcesObj.ProjectResorcesId, 0);
                }

                foreach (PM_ProjectResources resorcesObj in ResourceList2)
                {

                    if (!HTResource.Contains(resorcesObj.ProjectResorcesId))
                    {
                        ResList.Add(resorcesObj);
                    }
                }

            }
            else
            {

                /*------------- Updated New Project Resource---------------------------*/

                //IQueryable<PM_ProjectResources> projectQuery = from p in GetSynegyRMSInstance().PM_ProjectResources
                //                                               where ((p.aspnet_Users.UserName == edituser.UserName) && (p.ProjectResorcesId !=projectResourceId) &&  ((p.AllocatedStartDate >= startDate || p.AllocatedStartDate <= endDate) || (p.AllocatedEndDate >= startDate || p.AllocatedEndDate <= endDate)))
                //                                               select p;

                IQueryable<PM_ProjectResources> projectQuery = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                               where ((p.aspnet_Users.UserName == edituser.UserName) && (p.ProjectResorcesId != projectResourceId) && ((p.AllocatedStartDate >= startDate && p.AllocatedStartDate <= endDate) || (p.AllocatedEndDate >= startDate && p.AllocatedEndDate <= endDate)))
                                                               select p;

                IQueryable<PM_ProjectResources> projectQuery2 = from p in GetSynegyRMSInstance().PM_ProjectResources
                                                                where ((p.aspnet_Users.UserName == edituser.UserName) && (p.ProjectResorcesId != projectResourceId) && ((p.AllocatedStartDate <= startDate && p.AllocatedEndDate >= startDate) || (p.AllocatedStartDate <= endDate && p.AllocatedEndDate >= endDate)))
                                                                select p;

                ResourceList = projectQuery.ToList();

                ResourceList2 = projectQuery2.ToList();

                foreach (PM_ProjectResources resorcesObj in ResourceList)
                {

                    ResList.Add(resorcesObj);
                    HTResource.Add(resorcesObj.ProjectResorcesId, 0);
                }

            }

            if (ResList != null)
            {
                if (ResList.Count > 0)
                {

                    foreach (PM_ProjectResources objResources in ResList)
                    {
                        DateTime startPeriod;
                        DateTime endPeriod;
                        double numOfDays = 0;

                        if (objResources.AllocatedStartDate < startDate)
                        {
                            startPeriod = startDate;
                        }
                        else
                        {
                            startPeriod = objResources.AllocatedStartDate;
                        }

                        if (objResources.AllocatedEndDate > endDate)
                        {
                            endPeriod = endDate;
                        }
                        else
                        {
                            endPeriod = objResources.AllocatedEndDate;
                        }

                        TimeSpan tsPeriod = endPeriod.Subtract(startPeriod);
                        numOfDays = tsPeriod.TotalDays;

                        double projectEffort = Convert.ToDouble(objResources.Effort);
                        TotalCurrentEffort = TotalCurrentEffort + projectEffort * numOfDays;

                        //objResources.UM_UsersReference.Load();
                        //int aa = single1.T_User.UserId;
                    }
                }
                else
                {
                    /*-----Current Allocation is 0 for the Given period--------*/
                    TotalCurrentEffort = 0;
                }
            }

            else
            {
                /*-----Current Allocation is 0 for the Given period--------*/
                TotalCurrentEffort = 0;
            }

            /*--------------------Total  Effort For the given period ---------------*/

            TotalEffort = UserMaxEffort * Duration;

            /*-----------------------Check Allocation----------------------------- */

            RemEffort = TotalEffort - TotalCurrentEffort;

            /*----------------------Calculate requested Effort------------------------*/

            UserRequestdEffort = inputEffort * Duration;

            /*--------------calculate Remaining Effort----------------*/

            UserEffort effortObj = new UserEffort();

            if (RemEffort > UserRequestdEffort)
            {
                NoOfRemainingDays = RemEffort / UserMaxEffort;

                /*-----------------Fill Information -------------------*/

                effortObj.RemEffort = NoOfRemainingDays;
                effortObj.IsCanAllocated = true;
                effortObj.CustomeMessge = "Allocation Is Done";

            }
            else
            {
                effortObj.RemEffort = 0;
                effortObj.IsCanAllocated = false;
                effortObj.CustomeMessge = "Maximum Allocation Excedded";
            }

            return effortObj;
        }