public static void Run()
        {
            // ExStart:DefineWeekdayExceptions
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // Create a project instance
            Project prj = new Project();

            // Define Calendar
            Aspose.Tasks.Calendar cal = prj.Calendars.Add("Calendar1");

            // Define week days exception for a holiday
            CalendarException except = new CalendarException();

            except.EnteredByOccurrences = false;
            except.FromDate             = new DateTime(2009, 12, 24, 0, 0, 0);
            except.ToDate     = new DateTime(2009, 12, 31, 23, 59, 0);
            except.Type       = CalendarExceptionType.Daily;
            except.DayWorking = false;
            cal.Exceptions.Add(except);

            // Save the Project
            prj.Save(dataDir + "Project_DefineWeekDayException_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
            // ExEnd:DefineWeekdayExceptions
        }
Exemple #2
0
        public static void Run()
        {
            //ExStart:AddRemoveCalendarExceptions
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            using (FileStream fs = new FileStream(dataDir + "project_test.mpp", FileMode.Open))
            {
                // Create project instance
                Project prj = new Project(fs);

                // Remove an exception
                Aspose.Tasks.Calendar cal = prj.Calendars.ToList()[0];
                if (cal.Exceptions.Count > 1)
                {
                    CalendarException exc = cal.Exceptions.ToList()[0];
                    cal.Exceptions.Remove(exc);
                }

                // Add an exception
                CalendarException calExc = new CalendarException();
                calExc.FromDate = new System.DateTime(2009, 1, 1);
                calExc.ToDate   = new System.DateTime(2009, 1, 3);
                cal.Exceptions.Add(calExc);

                // Display exceptions
                foreach (CalendarException calExc1 in cal.Exceptions)
                {
                    Console.WriteLine("From" + calExc1.FromDate.ToShortDateString());
                    Console.WriteLine("To" + calExc1.ToDate.ToShortDateString());
                }
            }
            //ExEnd:AddRemoveCalendarExceptions
        }
        public static void Run()
        {
            // ExStart:WriteTaskCalendar
            // Create project instance
            Project project = new Project();

            // Add task
            Task tsk1 = project.RootTask.Children.Add("Task1");

            // Create calendar and assign to task
            Aspose.Tasks.Calendar cal = project.Calendars.Add("TaskCal1");
            tsk1.Set(Tsk.Calendar, cal);
            // ExEnd:WriteTaskCalendar
        }
Exemple #4
0
        public static void Run()
        {
            //ExStart:MakeAStandardCalendar
            // Create a project instance
            Project project = new Project();

            // Define Calendar and make it standard
            Aspose.Tasks.Calendar cal1 = project.Calendars.Add("My Cal");
            Aspose.Tasks.Calendar.MakeStandardCalendar(cal1);

            // Save the Project
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            project.Save(dataDir + "Project_MakeStandardCalendar_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
            //ExEnd:MakeAStandardCalendar
        }
Exemple #5
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            //ExStart:SetResourceCalendar
            // Create project instance and add resource
            Project  project = new Project();
            Resource res     = project.Resources.Add("Resource1");

            // Add standard calendar and assign to resource
            Aspose.Tasks.Calendar cal = project.Calendars.Add("Resource1");
            res.Set(Rsc.Calendar, cal);
            //ExEnd:SetResourceCalendar

            // Save project as XML
            project.Save(dataDir + "SetResourceCalendar_out.xml", SaveFileFormat.XML);
        }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // Create a project instance
            Project project1 = new Project();

            // Define Calendar
            Aspose.Tasks.Calendar cal = project1.Calendars.Add("Calendar1");

            // ExStart:HandleExceptionOccurences
            // Define exception and specify occurences
            CalendarException except = new CalendarException();

            except.EnteredByOccurrences = true;
            except.Occurrences          = 5;
            except.Type = CalendarExceptionType.YearlyByDay;
            // ExEnd:HandleExceptionOccurences

            // Add exception to calendar and save the Project
            cal.Exceptions.Add(except);
            project1.Save(dataDir + "Project_HandleExceptionOccurences_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
        }
        public static void Run()
        {
            // ExStart:CalculateWorkHours
            // Load an existing project
            string  dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            Project project = new Project(dataDir + "CalculateWorkHours.mpp");

            // Access Task By Id
            Task task = project.RootTask.Children.GetById(1);

            // Access Calendar and it's start and end dates
            Aspose.Tasks.Calendar taskCalendar = task.Get(Tsk.Calendar);
            DateTime startDate = task.Get(Tsk.Start);
            DateTime endDate   = task.Get(Tsk.Finish);
            DateTime tempDate  = startDate;

            // Access resource and their calendar
            Resource resource = project.Resources.GetByUid(1);

            Aspose.Tasks.Calendar resourceCalendar = resource.Get(Rsc.Calendar);

            TimeSpan timeSpan;

            // Get Duration in Minutes
            double durationInMins = 0;

            while (tempDate < endDate)
            {
                if (taskCalendar.IsDayWorking(tempDate) && resourceCalendar.IsDayWorking(tempDate))
                {
                    timeSpan       = taskCalendar.GetWorkingHours(tempDate);
                    durationInMins = durationInMins + timeSpan.TotalMinutes;
                }
                tempDate = tempDate.AddDays(1);
            }
            tempDate = startDate;

            // Get Duration in Hours
            double durationInHours = 0;

            while (tempDate < endDate)
            {
                if (taskCalendar.IsDayWorking(tempDate) && resourceCalendar.IsDayWorking(tempDate))
                {
                    timeSpan        = taskCalendar.GetWorkingHours(tempDate);
                    durationInHours = durationInHours + timeSpan.TotalHours;
                }
                tempDate = tempDate.AddDays(1);
            }
            tempDate = startDate;

            // Get Duration in Days
            double durationInDays = 0;

            while (tempDate < endDate)
            {
                if (taskCalendar.IsDayWorking(tempDate) && resourceCalendar.IsDayWorking(tempDate))
                {
                    timeSpan = taskCalendar.GetWorkingHours(tempDate);
                    if (timeSpan.TotalHours > 0)
                    {
                        durationInDays = durationInDays + timeSpan.TotalDays * (24 / (timeSpan.TotalHours));
                    }
                }
                tempDate = tempDate.AddDays(1);
            }

            Console.WriteLine("Duration in Minutes = " + durationInMins);
            Console.WriteLine("Duration in Hours = " + durationInHours);
            Console.WriteLine("Duration in Days = " + durationInDays);
            // ExEnd:CalculateWorkHours
        }