public Boolean OpenMSPProject(String sProjectID) { // Open an MS Project .mpp file for merging with SAP Data, // If the file open fails then SAP data is loaded signifying // a new project. // TestDir stores the merger working .mpp file String sTemp = Properties.Settings.Default.TestDir + sProjectID; try { //Load the existing .mpp file rApplication.FileOpen(sTemp, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.MSProject.PjPoolOpen.pjDoNotOpenPool, Missing.Value, Missing.Value, Missing.Value, Missing.Value); //Assign reference from opened MSProject to our own rProject = rApplication.ActiveProject; rTasks = rProject.Tasks; } catch (COMException ex) { //FileOpen failed return(false); } return(true); }
private void Application_NewProject(Microsoft.Office.Interop.MSProject.Project pj, TaskModel.TaskModel taskModel) { object missing = Type.Missing; TaskModel.TaskModel tm = taskModel; Microsoft.Office.Interop.MSProject.Task newTask = pj.Tasks.Add(tm.TaskName, missing); newTask.Start = DateTime.Now; newTask.Duration = tm.TaskDuring; newTask.ResourceNames = tm.ResourceNames.ToString(); newTask.Notes = tm.Notes; }
private void CcmRibbon_Load(object sender, RibbonUIEventArgs e) { application = CmmAddIn.thisApp; CmmAddIn.OnProjectLoaded += (project) => { this.project = project; // Update ribbon display var isBuffersHidden = CcmData.GetIsBuffersHidden(); HideUnhideBuffers(isBuffersHidden); }; }
/// <summary> /// Assigns all the properties based upon the data in the /// Microsoft Project task. /// </summary> /// <param name="o">The task to get the values from.</param> public void SetProperties(MSProject.Project o) { Wbs = o.WBS.ToString(); Name = o.Name.ToString(); StartDate = (System.DateTime)o.Start; FinishDate = (System.DateTime)o.Finish; PercentComplete = (System.Int16)o.PercentComplete; savedVersion = "1"; fileName = o.Name; titleName = o.Title.ToString(); createdDate = (System.DateTime)o.CreationDate; lastSaved = (System.DateTime)o.LastSaveDate; }
private void bnOk_Click(object sender, System.EventArgs e) { // user hit okay. ProjectListItem selectedProject = (ProjectListItem)cbSelectProject.SelectedItem; MSProject.Project current = projectApp.ActiveProject; if (current != null) { try { ToDo[] todos = psc.getTodoManager().getAllToDosForProject(selectedProject.Project.id); DateTime startTime = todos[0].dueDate; for (int i = 0; i < todos.Length; i++) { try { if (todos[i].dueDate < startTime) { startTime = todos[i].dueDate; } MSProject.Task newTask = current.Tasks.Add(todos[i].name, i + 1); newTask.Notes = todos[i].description; newTask.Finish = todos[i].dueDate; //MessageBox.Show(todos[i].dueDate.GetType().Name); //MessageBox.Show(newTask.Finish.ToString() + " :: " + newTask.Finish.GetType().Name); } catch {} } //current.ProjectStart = startTime; // temporary! } catch (Exception ex) { } Close(); Dispose(); } else { MessageBox.Show("ERROR: Unable to find an Active Project!"); } }
// Constructor public CProject(ref MSProject.Application Application) { // sGlobalTemplate is our global MS Project objects string sGlobalTemplate = Properties.Settings.Default.TestDir + "SAPProject.mpt"; rApplication = Application; try { //Load our GlobalTemplate //rApplication.FileNew(false, @sGlobalTemplate, false, false); rApplication.FileNew(false, @sGlobalTemplate, false, false); } catch (IOException e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } //Assign reference from standard MSProject to our own rProject = rApplication.ActiveProject; rTasks = rProject.Tasks; }
public CcmData() { application = CmmAddIn.thisApp; project = CmmAddIn.thisApp.ActiveProject; }
public ProjectContent(MSProject.Project o) { SetProperties(o); }
public static new int Convert(String inputFile, String outputFile, Hashtable options) { Boolean running = (Boolean)options["noquit"]; MSProject.Application app = null; object missing = System.Reflection.Missing.Value; try { try { app = (MSProject.Application)Marshal.GetActiveObject("MSProject.Application"); } catch (System.Exception) { app = new MSProject.Application(); running = false; } System.Type type = app.GetType(); if (type.GetMethod("DocumentExport") == null || System.Convert.ToDouble(app.Version.ToString()) < 14) { Console.WriteLine("Not implemented with Office version {0}", app.Version); return((int)ExitCode.UnsupportedFileFormat); } app.ShowWelcome = false; app.DisplayAlerts = false; app.DisplayPlanningWizard = false; app.DisplayWizardErrors = false; Boolean includeProps = !(Boolean)options["excludeprops"]; Boolean markup = (Boolean)options["markup"]; FileInfo fi = new FileInfo(inputFile); switch (fi.Extension) { case ".mpp": MSProject.Project project = null; if (app.FileOpenEx(inputFile, false, MSProject.PjMergeType.pjDoNotMerge, missing, missing, missing, missing, missing, missing, missing, missing, MSProject.PjPoolOpen.pjDoNotOpenPool, missing, missing, false, missing)) { project = app.ActiveProject; } if (project == null) { return((int)ExitCode.UnknownError); } app.DocumentExport(outputFile, MSProject.PjDocExportType.pjPDF, includeProps, markup, false, missing, missing); app.FileCloseEx(MSProject.PjSaveType.pjDoNotSave, missing, missing); break; } return(File.Exists(outputFile) ? (int)ExitCode.Success : (int)ExitCode.UnknownError); } catch (System.Exception e) { Console.WriteLine(e.Message); return((int)ExitCode.UnknownError); } finally { if (app != null && !running) { ((MSProject.Application)app).Quit(); } Converter.ReleaseCOMObject(app); } }
public void CalculateLineOfBalance() { MSProject.Project project = ThisAddIn.Application.ActiveProject; }
void Application_NewProject(MSProject.Project pj) { _project = pj; //ConnectToJiraServer(); }
private void LaunchMSProject() { try { this.application = new MSProject.Application(); application.Visible = true; System.Threading.Thread.Sleep(5000); application.Projects.Add(System.Type.Missing, System.Type.Missing, System.Type.Missing); this.project = this.application.ActiveProject; this.SetCalendarNoHolidays(); this.launched = true; #region Example code from http://social.technet.microsoft.com/Forums/ru-RU/project2010custprog/thread/0d4b2b34-3051-4b27-bb51-e3cae64ac9f9 //bool launched = false; //for (int timerSec = 0; timerSec < 20 && !launched; timerSec++) //{ // try // { // this.application.WorkOffline(false); // launched = true; // break; // } // catch // { // } //} //if (!launched) //{ // application.DocClose(); // System.Threading.Thread.Sleep(1500); // application.Quit(MSProject.PjSaveType.pjDoNotSave); // throw new ApplicationException("Unable to start an instance of MS Project"); //} #endregion } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void button1_Click(object sender, RibbonControlEventArgs e) { DateTime currentdate = System.DateTime.Now; #region get path and project info //get active project and path MSPROJECT.Project project1 = Globals.ThisAddIn.Application.ActiveProject; string projectpath = project1.Path.ToString(); projectname = project1.Name.ToString(); string datadir = projectpath; bool baseline_ = false; //project1.SaveAs(datadir + "\\" + "temp.mpp"); DialogResult result = MessageBox.Show("All Projects Will Be Saved and Closed. Proceed?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); try { if (result == DialogResult.Yes) { Globals.ThisAddIn.Application.FileCloseAllEx(MSPROJECT.PjSaveType.pjSave); Aspose.Tasks.Project prj = new Aspose.Tasks.Project(datadir + "\\" + projectname); // Declare ChildTasksCollector class object ChildTasksCollector collector = new ChildTasksCollector(); // Use TaskUtils to get all children tasks in RootTask TaskUtils.Apply(prj.RootTask, collector, 0); //create entity SchedulingEntities db = new SchedulingEntities(); Schedule_Actual actual = new Schedule_Actual(); Schedule_Baseline baseline = new Schedule_Baseline(); #region view all tasks DialogResult baselineresult = MessageBox.Show("Create/Update Baseline?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (baselineresult == DialogResult.Yes) { baseline_ = true; } else { } foreach (Task tsk2 in collector.Tasks) { Calendar tskCal = tsk2.Get(Tsk.Calendar); string taskinfo = tsk2.ToString(); int id1 = tsk2.Get(Tsk.Id); if (id1 == 0) { string jobnumber = tsk2.Get(Tsk.Name); actual.job = jobnumber; actual.createdate = currentdate; if (baseline_ == true) { baseline.job = jobnumber; baseline.createdate = currentdate; } } if (tsk2.Get(Tsk.Name) == "Design") { DateTime designStart = tsk2.Get(Tsk.Start); DateTime designEnd = tsk2.Get(Tsk.Finish); actual.designend = designEnd; actual.designstart = designStart; if (baseline_ == true) { baseline.designstart = designStart; baseline.designend = designEnd; } } if (tsk2.Get(Tsk.Name) == "Processing") { DateTime processingStart = tsk2.Get(Tsk.Start); DateTime processingEnd = tsk2.Get(Tsk.Finish); actual.processingend = processingEnd; actual.processingstart = processingStart; if (baseline_ == true) { baseline.processingend = processingEnd; baseline.processingstart = processingStart; } } if (tsk2.Get(Tsk.Name) == "Weld Fab") { DateTime weldStart = tsk2.Get(Tsk.Start); DateTime weldEnd = tsk2.Get(Tsk.Finish); actual.weldstart = weldStart; actual.weldend = weldEnd; if (baseline_ == true) { baseline.weldstart = weldStart; baseline.weldend = weldEnd; } } if (tsk2.Get(Tsk.Name) == "Machine") { DateTime machineStart = tsk2.Get(Tsk.Start); DateTime machineEnd = tsk2.Get(Tsk.Finish); actual.machineend = machineEnd; actual.machinestart = machineStart; if (baseline_ == true) { baseline.machineend = machineEnd; baseline.machinestart = machineStart; } } if (tsk2.Get(Tsk.Name) == "Assembly") { DateTime assemblyStart = tsk2.Get(Tsk.Start); DateTime assemblyEnd = tsk2.Get(Tsk.Finish); actual.assemblystart = assemblyStart; actual.assemblyend = assemblyEnd; if (baseline_ == true) { baseline.assemblyend = assemblyEnd; baseline.assemblystart = assemblyStart; } } if (tsk2.Get(Tsk.Name) == "QA BUY OFF") { DateTime qaStart = tsk2.Get(Tsk.Start); DateTime qaEnd = tsk2.Get(Tsk.Finish); actual.qastart = qaStart; actual.qaend = qaEnd; if (baseline_ == true) { baseline.qaend = qaEnd; baseline.qastart = qaStart; } } if (tsk2.Get(Tsk.Name) == "Material") { DateTime matStart = tsk2.Get(Tsk.Start); DateTime matEnd = tsk2.Get(Tsk.Finish); actual.materialstart = matStart; actual.materialend = matEnd; if (baseline_ == true) { baseline.materialstart = matStart; baseline.materialend = matEnd; } } } db.Schedule_Actual.Add(actual); if (baseline_ == true) { db.Schedule_Baseline.Add(baseline); } db.SaveChanges(); SaveOptions saveOptions = new PdfSaveOptions(); saveOptions.PageSize = PageSize.Ledger; saveOptions.SaveFormat.Equals(SaveFileFormat.PDF); saveOptions.FitContent = true; saveOptions.Timescale = Timescale.ThirdsOfMonths; saveOptions.PresentationFormat = PresentationFormat.GanttChart; saveOptions.LegendOnEachPage = false; projectname = projectname.Replace("-", "_"); string filename = "R:\\wipviewer2017\\prjfiles\\" + projectname + ".pdf"; prj.Save(filename, saveOptions); email_team(filename); PdfPageEditor pEdit = new PdfPageEditor(); } #endregion else if (result == DialogResult.No) { // DO NOTHING } } catch (Exception ee) { MessageBox.Show(ee.ToString()); } #endregion }