"Original" One Time project plugin development

Source: Internet
Author: User

First, the development background

The recent project management with Microsoft Office Project 2010 saw a full line of scheduled tasks, one after another, and a sense of accomplishment. In fact, not only in the work can use project scheduling control, the same software can be used in daily life, such as to read a book line a plan, and the task Unit is the book directory, of course, the granularity can be customized, but also for fitness platoon a plan, go to the gym several times a week, Every time you do a number of actions, what type of action, can be scheduled ahead of schedule, each completed a task on the progress of the hard input 100%, that is how cool things ah.

However, through the use of a period of time, I found that I have a personalized needs, is the habit of the various state of the task with different background color, so that it is clear and intuitive to grasp the overall task of the completion of the situation, and is very not like the way project comes with the creation of tasks, Want to be able to create tasks in their own way, such as the resources of the task is usually my own name (in most cases), so I want to create a task, the default to bring out the resource name, and then I like to use Microsoft Jas as the default font, but each time is set up a single cell, and then brush with the format of the brush, Again such as the task status of the background color, but also a little bit of the brush with the format of the brush, if not commonly used this tool is OK, but always this inevitably makes people disgusted, so it produced this idea. The above is my own personalized needs, if there are other ideas, but also can expand their own, the lazy style to carry forward the end. In the garden also found some relevant information, but and my starting point are not very consistent, so nonsense not much to say, own hands, clothed.

Ii. Project Object Model

Before the plug-in development of word, the inside of the various components (range,paragraph,selection) are regular, most of the objects have their own collection, and the correlation between multiple objects is relatively close, but the model of project makes me very puzzled, For example, inside cell cell, there is no concept of the collection (see official Microsoft Document), which is more important model has the following: application, Task, cell, resource, of course, there are other more important models, but not very common, No instructions are made here.

Represents the active cell. (There is no collection for Cell objects.) The Cell object can be accessed only through the ActiveCell property of the the application object.

Represents a task. The Task object is a member of the Tasks collection.

Use Tasks(index), where index is the task index number or task name, to return a single Tas K object. The following example prints the name of every resource assigned to every task in the active project.

Iii. Creating a custom Task window

Let's take a look at the Custom Create Task window, which looks like this:

Because my personalization needs are not very complex, it simply creates a model that stores characters commonly used segments, mainly including the common properties of tasks such as task name, duration, start and end time, resource, and percent complete. Here is the code snippet for adding a new task:

1 Private voidCreate_click (Objectsender, EventArgs e)2 {3     if(string. IsNullOrEmpty (Taskname.text))return;4Project proj =Globals.ThisAddIn.Application.ActiveProject;5Taskmodel.taskmodel Taskmodel =NewTaskmodel.taskmodel6     {7TaskName =Taskname.text,8Taskduring =taskDuring.Value.ToString (),9ResourceNames =Taskresource.text,TenNotes =Tasknotes.text One     }; A  - Application_newproject (proj, Taskmodel); -}

Application_newproject accepts a current ActiveProject object and a Taskmodel object with the following code:

1 Private voidApplication_newproject (Microsoft.Office.Interop.MSProject.Project pj, Taskmodel.taskmodel Taskmodel)2 {3     ObjectMissing =Type.Missing;4Taskmodel.taskmodel TM =Taskmodel;5Microsoft.Office.Interop.MSProject.Task NewTask =PJ. Tasks.add (TM. TaskName, missing);6Newtask.start =DateTime.Now;7Newtask.duration =TM. taskduring;8Newtask.resourcenames =TM. Resourcenames.tostring ();9Newtask.notes =TM. Notes;Ten}

The new task is added through the Add method of the Tasks property of the Project object. There are many other properties of the task, which are not listed here.

Iv. to show the progress of the task more clearly

First look at the whole:

This is basically the case before using plug-in processing

After the use of plug-in processing is the case, pre-set a good background color, font, state and so on.

This one-button processing, looks much more comfortable, and the progress of the approximate level of completion has an intuitive grasp. The relative format brush is still very convenient.

Here's some code:

1 /// <summary>2 ///The core method of background padding based on task status3 /// </summary>4 Private voidCallselecttaskfield ()5 {6     foreach(Task taskinchGlobals.ThisAddIn.Application.ActiveProject.Tasks)7     {8Globals.ThisAddIn.Application.SelectTaskField (Task. Index,"name",false,6,0);9         if(Task. PercentComplete = =0)Ten         { One Callfont32ex (Commondata.mappingcolorstate (CommonData.TaskState.Ready)); A         } -         Else if(Task. PercentComplete = = -) -         { the Callfont32ex (Commondata.mappingcolorstate (CommonData.TaskState.Complete)); -         } -         Else -         { + Callfont32ex (Commondata.mappingcolorstate (CommonData.TaskState.Processing)); -         } +     } A}

The above code involves two core models, one is application, which is the entire application-level object, and many things are encapsulated inside, including ActiveCell, ActiveSelection, ActiveWindow and the ActiveProject in the above code, the specific members see here, and one is that the Task,task model corresponds to a task in project, and many of its members are dynamic types, the concrete model here, Members are here. The code obtains all the task collections from the currently active project and determines the PercentComplete (Percent complete) property of each task, setting each task background color based on the number of States that are not started, executed, and completed. At first, I thought that the task would have a background color background property, but not, but instead, by selecting a section of filed and then calling the Font32ex method for that segment filed set.

In this function point, or encountered a lot of trouble, go a lot of detours, such as the beginning of time, not using the Font32ex method to fill the task background color, but the use of the TextStyle method, the first parameter of this method is an enumeration, in the fill background color function point, Only the first enumeration takes effect (others have, but no attempt is made, the enumeration is more), and then it is resolved by recording the macro, the following is the macro code:

1 Sub Macro1 () 2 ' macro Macro1 3 ' XUHBD the macro that was recorded on December 12, 2016.  4     selectrow row:=05    outlineindent 6     Font32ex cellcolor:=622077End Sub

In this macro code, obviously see Font32ex this method, but looked at the official document, one of the parameters is CellColor, the object is PjColor enumeration, run to find the filled background color is black, regardless of the color chosen.

Later I put pjcolor directly with color to replace, incredibly successful.

The code is as follows:

1 /// <summary>2 ///call system methods to set the background color3 /// </summary>4 /// <param name= "BgColor" ></param>5 Private voidCallfont32ex (Color bgColor)6 {7     Objectmissing=Type.Missing;8 Globals.ThisAddIn.Application.Font32Ex (9         "Microsoft Ya-Black",9, missing, missing,Ten missing, missing, missing, One BgColor, missing, missing); A}

V. Conclusion

By completing this project plugin, I learned the project model, and made it easier for me to use project, to improve my motivation, and if new requirements could be expanded on that basis, this would create a virtuous circle. In this process, referring to a lot of Microsoft Official documents (and English, it seems very important to learn English), and finally, the code has been hosted on GitHub, the text stated if any problem, please leave a message, I will promptly correct.

Porject Addin Download

Melodious Shepherd's flute

Blog Address: http://www.cnblogs.com/xhb-bky-blog/p/6155809.html

Disclaimer: The original text of this blog only represents my work in a certain time to summarize the views or conclusions, and my unit does not have a direct interest in the relationship. Non-commercial, unauthorized posts please retain the status quo, reproduced must retain this paragraph of the statement, and in the article page obvious location to the original connection.

"Original" One Time project plugin development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.