Subversion Repositories DevTools

Rev

Rev 6643 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'|                                                   |
'|                                XML BOM Gen                                    |
'|                                                   |
'=====================================================
%>
<%
Option explicit
Response.Expires = 0    ' always load the page, dont store
%>
<!--#include file="common/globals.asp"-->
<!--#include file="common/config.asp"-->
<!--#include file="common/common_subs.asp"-->
<!--#include file="common/_popup_window_common.asp"-->

<%
'------------ VARIABLE DEFINITION -------------
Dim objWSH
Dim rsQry
Dim generated
'------------ CONSTANTS DECLARATION -----------
'------------ VARIABLE INIT -------------------
'------------ CONDITIONS ----------------------
'----------------------------------------------
%>
<%
Function DateReversed ( dDate )
        ' Ensures Reverse Date format YYYY-MM-DD
        If IsNull(dDate) Then Exit Function
        DateReversed = Year(dDate) &"-"&  Month(dDate) &"-"& Day(dDate)
End Function
'--------------------------------------------------------------------------------------------------------------------------

'--------------------------------------------------------------------------------------------------------------------------
%>
<%
'**************************** M  A  I  N ******************************

If Request("bom_id") <> "" Then
        
        OraDatabase.Parameters.Add "BOM_ID",    Request("bom_id"),      ORAPARM_INPUT, ORATYPE_NUMBER 
        Set rsQry = OraDatabase.DbCreateDynaset( GetQuery("NodesSpecFileNames.sql"), cint(0))
        OraDatabase.Parameters.Remove "BOM_ID"
        
        If rsQry.RecordCount <> 0 Then 
                
                generated = true
                
                Set objWSH = createWscriptShell()

                objWSH.Run   "cmd.exe /c cscript.exe //B //NoLogo "& APP_ROOT &"\jobs\NodesSpecRelease.wsf /bom_id:"& Request("bom_id") , 0, True 
                
            On Error Resume Next
                OraDatabase.Parameters.Add "BOM_ID",    Request("bom_id"),                      ORAPARM_INPUT, ORATYPE_NUMBER
                OraDatabase.Parameters.Add "USER_ID",   objAccessControl.UserId,        ORAPARM_INPUT, ORATYPE_NUMBER 
        
                objEH.TryORA ( OraSession )
        
                OraDatabase.ExecuteSQL _
                "BEGIN   pk_Bom.Log_Bom_Trail ( :BOM_ID, 'NODE SPECS FILE GENERATED', :USER_ID, NULL );   END;"
                objEH.CatchORA ( OraSession )
                
                OraDatabase.Parameters.Remove "BOM_ID"
                OraDatabase.Parameters.Remove "USER_ID" 
            On Error GoTo 0

        ' Create a sane path name for the output file
        ' Need to use the same rules as NodesSpecRelease.wsf to allow for BOM versions with a '/' in the name
        '
                Dim LocalPath, ZipFile, filesys, eMsg, zCount
        Set rsQry = OraDatabase.DbCreateDynaset( "SELECT bn.BOM_NAME, br.BRANCH_NAME, bn.BOM_NAME ||''|| b.BOM_VERSION ||'.'|| b.BOM_LIFECYCLE AS VERSION FROM BOMS B, BRANCHES BR, BOM_NAMES BN WHERE B.BOM_ID = "& Request("bom_id") &" AND B.BRANCH_ID = BR.BRANCH_ID AND B.BOM_NAME_ID = BN.BOM_NAME_ID", cint(0))
                LocalPath = Server.MapPath("nodespecfiles") & "\" &_
                    NicePath(rsQry("branch_name")) & "\" &_
                    NicePath(rsQry("version")) & "\"&_
                    DateReversed(Date)
        ZipFile = LocalPath &".zip"

            Set filesys = CreateObject("Scripting.FileSystemObject")
            If NOT filesys.FolderExists ( LocalPath ) Then
                    Response.write "<br>Internal Error: Folder Not Found"
                    Response.write "<br>LocalPath: "&LocalPath
                    Response.write "<br>Branch: "&rsQry("branch_name")
                    Response.write "<br>Version: "&rsQry("version")
                    Response.write "<br>"
                generated = false
        Else
                    Dim objZIPObject
                Set objZIPObject = Server.CreateObject("XStandard.Zip")

            If filesys.FileExists(ZipFile) Then
                    filesys.DeleteFile ZipFile, TRUE
            End If

            objZIPObject.Pack LocalPath &"\*.*", ZipFile
            eMsg = objZIPObject.ErrorDescription
            zCount = objZIPObject.Contents(ZipFile).Count
            'objZIPObject = Nothing
        
                Response.Write "Files Zipped=" & zCount 
            If eMsg <> "" Then
                    Response.Write " with Error="& eMsg
            End If
                        
                Response.write "<br>Node Spec Files Generated for: "&objAccessControl.UserEmail
            Response.Write "<br>"            
            If NOT filesys.FileExists ( ZipFile ) Then
                    Response.write "<br>Internal Error: File Not Found"
                    Response.write "<br>LocalPath: " & ZipFile & "<br>"
                generated = false
            Else
                Response.Write "<br>Emailing using: " & SMTP_HOST
                Dim myMail
                    Set myMail=Server.CreateObject("Persits.MailSender")
                        myMail.Host = SMTP_HOST
                        myMail.Subject="NODESPEC FILES Generated from Deployment Manager"
                        myMail.From="releasem@vixtechnology.com"
                        myMail.AddAddress objAccessControl.UserEmail
                        ' Attach the file
                        myMail.AddAttachment LocalPath &".zip"
                        myMail.Body = "Your requested node spec files .." 
                        myMail.Send
                    set myMail = nothing
            End If
        End If
                
                set objWSH = nothing
            Set filesys = nothing
                rsQry.Close
                Set rsQry = nothing
        Else    
        generated = false
                Response.write "<br>Node spec filenames not found in the BOM!!!"
                
        End If  
        
Else
        Response.write "Please specify bom_id. <br>Example:<br> "& SCRIPT_NAME &"?bom_id=1234"
End If

'**********************************************************************
If generated Then
%>
<script language="Javascript">
alert("You will be emailed shortly with the NodeSpec files generated. Click OK to Redirect to Previous Page...")
history.back()
</script>
<%Else%>
<script language="Javascript">
alert("Click OK to Redirect to Previous Page...")
history.back()
</script>
<%End If%>
<%Call Destroy_All_Objects%>