コード例 #1
0
    /// <summary>
    ///
    /// </summary>
    public void OpenDesignNotes()
    {
        try
        {
            IDXPProject Project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject();
            Dictionary <string, string> Params      = GetParams();
            IOptionsStorage             ProjOptions = Project.DM_OptionsStorage();
            if (Project == null)
            {
                MessageBox.Show("Project not found. Try again.");
                return;
            }

            string strProjPath = Util.ProjPath();

            if (strProjPath == "\\")
            {
                MessageBox.Show("Project not found. Try again.");
                return;
            }

            string DesignNotesPath = OneNotePath(strProjPath, "Open Notebook.onetoc2");
            string ProjAssy = "", ProjQual = "", PwbNum = "";


            for (int i = 0; i <= Project.DM_GetParameterCount() - 1; i++)
            {
                if (Project.DM_GetParameterName(i) == "SwRI_Pwb_Qual")
                {
                    ProjQual = Project.DM_GetParameterValue(i);
                }
                else if (Project.DM_GetParameterName(i) == "SwRI_Title_Assy")
                {
                    ProjAssy = Project.DM_GetParameterValue(i);
                }
                else if (Project.DM_GetParameterName(i) == "SwRI_Pwb_Number")
                {
                    PwbNum = Project.DM_GetParameterValue(i);
                }
            }

            if (ProjQual == null)
            {
                MessageBox.Show("SwRI_Pwb_Qual project parameter is blank. Please fill this parameter in and try again.");
                return;
            }
            if (ProjAssy == null)
            {
                MessageBox.Show("SwRI_Title_Assy project parameter is blank. Please fill this parameter in and try again.");
                return;
            }
            if (PwbNum == null)
            {
                MessageBox.Show("SwRI_Pwb_Number project parameter is blank. Please fill this parameter in and try again.");
                return;
            }
            if (PwbNum != "")
            {
                PwbNum = PwbNum.Substring(0, 5);
            }
            //SwRI_Pwb_Number
            System.IO.Directory.SetCurrentDirectory(Util.ProjPath());
            if (DesignNotesPath == "" && ProjQual != "" && ProjAssy != "")
            {
                CopyFile(Params["template"], ".\\" + PwbNum + "_" + ProjAssy + "_" + ProjQual + "_Notes");
                DesignNotesPath = Util.ProjPath() + PwbNum + "_" + ProjAssy + "_" + ProjQual + "_Notes\\Open Notebook.onetoc2";
            }
            //CopyFile(Params["template"], ".\\Design_Notes_" + ProjAssy + "_" + ProjQual);
            //DesignNotesPath = Util.ProjPath() + "Design_Notes_" + ProjAssy + "_" + ProjQual + "\\Open Notebook.onetoc2";

            else if (DesignNotesPath.Contains("Design_Notes\\Open Notebook.onetoc2"))
            {
                try
                {
                    Directory.Move(Path.GetDirectoryName(DesignNotesPath) + "\\", Util.ProjPath() + PwbNum + "_" + ProjAssy + "_" + ProjQual + "_Notes\\");
                    DesignNotesPath = Util.ProjPath() + PwbNum + "_" + ProjAssy + "_" + ProjQual + "_Notes\\Open Notebook.onetoc2";
                }
                catch //(IOException ex)
                {
                    //MessageBox.Show("")
                    //throw;
                }
            }
            else if (DesignNotesPath.Contains("Design_Notes_" + ProjAssy + "_" + ProjQual + "\\Open Notebook.onetoc2"))
            {
                try
                {
                    Directory.Move(Path.GetDirectoryName(DesignNotesPath) + "\\", Util.ProjPath() + PwbNum + "_" + ProjAssy + "_" + ProjQual + "_Notes\\");
                    DesignNotesPath = Util.ProjPath() + PwbNum + "_" + ProjAssy + "_" + ProjQual + "_Notes\\Open Notebook.onetoc2";
                }
                catch //(IOException ex)
                {
                    //MessageBox.Show("")
                    //throw;
                }
            }
            else if ((ProjQual == "" || ProjAssy == "") && DesignNotesPath == "")
            {
                CopyFile(Params["template"], ".\\" + Path.GetFileNameWithoutExtension(Project.DM_ProjectFileName()) + "_Notes");
                DesignNotesPath = Util.ProjPath() + Path.GetFileNameWithoutExtension(Project.DM_ProjectFileName()) + "_Notes" + "\\Open Notebook.onetoc2";
                //create folder using project name instead.
                //MessageBox.Show("Missing project Qual and Assembly parameters.");
                //return;
            }

            System.Diagnostics.Process proc = System.Diagnostics.Process.Start(DesignNotesPath);
            proc.Dispose();
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
        }
    }
コード例 #2
0
ファイル: PDF_Update.cs プロジェクト: RandyLyne/SwRI_Tools
    public void Update_PDF_Sch_Links()
    {
        DXP.Utils.StatusBarSetState(2, "Fixing PDFs");

        string ProjPath = Util.ProjPath();


        IDXPProject     Project     = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject();
        IOptionsStorage ProjOptions = Project.DM_OptionsStorage();

        if (Project == null)
        {
            MessageBox.Show("Project not found. Try again.");
            return;
        }

        if (ProjPath == "\\")
        {
            MessageBox.Show("Project not found. Try again.");
            return;
        }

        string SchRev = "";

        //SwRI_SCH_Rev

        for (int i = 0; i <= Project.DM_GetParameterCount() - 1; i++)
        {
            if (Project.DM_GetParameterName(i) == "SwRI_SCH_Rev")
            {
                SchRev = Project.DM_GetParameterValue(i);
            }
        }
        if (SchRev == "")
        {
            MessageBox.Show("Schematic rev not found.");
            return;
        }

        string SchFolder = ProjPath + "Project Outputs\\sch" + SchRev + "\\";

        if (!Directory.Exists(SchFolder))
        {
            MessageBox.Show("Schematic project output folder missing.");
            return;
        }
        bool errors = false;
        int  count  = 0;

        DXP.Utils.PercentInit("Fixing PDFs", Directory.GetFiles(SchFolder).Length);

        //string[] PDFs;
        //PDFs = Directory.GetFiles(PDFPath, "*.pdf");
        //DateTime LatestDT = new DateTime();
        //foreach (string item in PDFs)
        //{
        //    if (File.GetCreationTime(item).Date == DateTime.Today.Date)
        //        if (File.GetCreationTime(item) > LatestDT)
        //        {
        //            LatestDT = File.GetCreationTime(item);
        //            LatestPDF = item;
        //        }
        //}

        foreach (string path in Directory.GetFiles(SchFolder))
        {
            if (path.ToLower().EndsWith("pdf"))
            {
                if (UpdatePDF(path) == false)
                {
                    errors = true;
                }
                count++;
            }
            Utils.PercentUpdate();
        }

        DXP.Utils.PercentFinish();

        if (errors)
        {
            MessageBox.Show("Something went wrong. A PDF may have been open.\r\nPlease close the PDF and try again.");
        }
        MessageBox.Show("Process complete.\r\n" + count + " file(s) processed");
    }