2008年6月27日 星期五

oracle command

ed # Edit
l # view Buffer
i # append

Unix Command

ls -lt ##list file according to time
ls -ltrs ##list file according to time (reverse order)

VBA--Excel Sheet

RunWksheet = Worksheets(Worksheet_Cnt).Name

Worksheets(RunWksheet).Activate 'Correct

Worksheets(Worksheet_Cnt).Activate 'Wrong

2008年6月2日 星期一

VBA---Main

Option Explicit
Public Function toStart(ByVal fileType As String) As String
Dim openFilesWorker As OpenAllFiles
Set openFilesWorker = New OpenAllFiles
Dim filesListSize As Long

Dim BrowseFolder As FileDialog
Set BrowseFolder = Application.FileDialog(msoFileDialogFolderPicker)
Dim folderPath


Dim toFormat

Dim saveFilesWorker As Save
Set saveFilesWorker = New Save

Dim toSaveAll As Boolean
Dim Prefix
Dim fileExtensionafterCon As String
Dim counter As Integer
Dim errSaveCounter As Integer
Dim succSaveCounter As Integer

Dim branches As Variant

Dim isCat

'initialization of the variables
counter = 0
errSaveCounter = 0
succSaveCounter = 0
fileExtensionafterCon = "doc"

isCat = MsgBox("Your files is catagorized?", vbYesNoCancel, "Check if files Prepared")

If (isCat = 6) Then
'folderPath = InputBox("Please enter of the file name", "File name of " & fileType, "", 100, 1)

With BrowseFolder
.Show
If BrowseFolder.SelectedItems.Count > 0 Then
folderPath = .SelectedItems(1)
End If
End With


'1. Open File'''''''''''''''''''''''''''''''
' Make sure strDirPath is a directory.
'Ignore errors to allow for error evaluation
If (folderPath <> "") And IsFileOrDirExists(folderPath) Then

filesListSize = openFilesWorker.GetAllFiles(folderPath)

On Error Resume Next

If fileType = "MIS" Then
Dim fileTypePrefix
fileTypePrefix = InputBox("Please enter the prefix of the file name. If you choose not to enter it , your document will be named with no prefix (e.g. _XXX.doc)", "Prefix of file request", "Mis")

Dim orientalworker As orientalChosenForm
Set orientalworker = New orientalChosenForm

Dim oriental As String
oriental = 1 ' default value is landscape


oriental = orientalworker.Ori

End If
For counter = 0 To filesListSize
'******************************************************************************************
'Operation after open the file and b4 saving***********************************************
'******************************************************************************************
'2. Format'''''''''''''''''''''''''''''''
If fileType = "MIS" And fileTypePrefix <> "" Then
branches = fileTypeChoice(fileType, fileTypePrefix, oriental)
Prefix = branches(0)

Else
branches = fileTypeChoice(fileType)
Prefix = branches(0)

End If

Prefix = "\" & Prefix & "_"
'******************************************************************************************
'3. Save and Close'''''''''''''''''''''''''''''''

toSaveAll = saveFilesWorker.toSave(Prefix, fileExtensionafterCon)

Select Case toSaveAll
Case Is = 1
succSaveCounter = succSaveCounter + 1
Case Else
errSaveCounter = errSaveCounter + 1
If Err.Number <> 0 Then
MsgBox Err.Number & Err.Description, vbMsgBoxHelpButton, "Error Encountered", Err.HelpFile
End If

End Select

Next counter
MsgBox "No. of files successfully Converted: " & succSaveCounter & vbCrLf & "No. of files fail Converted: " & errSaveCounter & vbCrLf, vbInformation, "Result"

Else
MsgBox "No files Converted!!!", vbInformation, "No files converted notice"
End If
ElseIf (isCat = 7) Then
On Error Resume Next
branches = fileTypeChoice(fileType)

Select Case Err.Number
Case Is = 0

Prefix = branches(0)
Prefix = "\" & Prefix & "_"
toSaveAll = saveFilesWorker.toSave(Prefix, fileExtensionafterCon)


Case Else
Select Case VBA.MsgBox("Do you want to open a single File?", vbOKCancel, "Active document exists checking")
Case VBA.vbOK
Dim BrowseFile As FileDialog
Set BrowseFile = Application.FileDialog(msoFileDialogFilePicker)
Dim choosenFileList As Variant

Dim openSingleFile As Boolean
Dim openSingleFileWorker As OpenAllFiles



With BrowseFile
.Filters.Clear
.InitialFileName = "C:\Documents and Settings\hmdleung\Desktop\excel_rpt_trial"
.InitialView = msoFileDialogViewDetails
.Filters.Add "All out Files", "*.out"
.Filters.Add "All Files", "*.*"
.AllowMultiSelect = False
.Title = .SelectedItems(1)


If .Show Then
For Each choosenFileList In .SelectedItems
openSingleFile = openSingleFileWorker.openSingleFile(choosenFileList)

branches = fileTypeChoice(fileType)

Prefix = branches(0)
Prefix = "\" & Prefix & "_"
toSaveAll = saveFilesWorker.toSave(Prefix, fileExtensionafterCon)

Next
End If
End With
Case VBA.vbCancel
MsgBox "No files converted", vbCritical, "File not chosen"
End Select


End Select
Else
MsgBox "You have cancelled your action!", vbExclamation, "Cancel Action"
End If

End Function
Public Function IsFileOrDirExists(ByVal PathName As String) As Boolean
'Macro Purpose: Function returns TRUE if the specified file
' or folder exists, false if not.
'PathName : Supports Windows mapped drives or UNC
' : Supports Macintosh paths
'File usage : Provide full file path and extension
'Folder usage : Provide full folder path
' Accepts with/without trailing "\" (Windows)
' Accepts with/without trailing ":" (Macintosh)

Dim iTemp As Integer

'Ignore errors to allow for error evaluation
On Error Resume Next
iTemp = GetAttr(PathName)

'Check if error exists and set response appropriately
Select Case Err.Number
Case Is = 0
IsFileOrDirExists = True
Case Else
IsFileOrDirExists = False
End Select

'Resume error checking
On Error GoTo 0
End Function
Public Function fileTypeChoice(ByVal fileType As String, Optional ByVal fileNamePrefix As String, Optional ByVal orientation As Integer) As Variant

Dim formatFilesWorker As Format
Set formatFilesWorker = New Format

Dim tempArray(2) As Variant

Select Case fileType
Case "TB"
tempArray(0) = "Trial_Balance"
tempArray(1) = formatFilesWorker.PortraitFormat()
Case "GL"
tempArray(0) = "General_Ledger"
tempArray(1) = formatFilesWorker.LandscapeFormat()
Case "PL"
tempArray(0) = "P&L"
tempArray(1) = formatFilesWorker.LandscapeFormat()
Case "BS"
tempArray(0) = "BS"
tempArray(1) = formatFilesWorker.LandscapeFormat()
Case "UJ"
tempArray(0) = "Unposted Journals"
tempArray(1) = formatFilesWorker.LandscapeFormat()

Case Else
tempArray(0) = fileNamePrefix

If (orientation = 0) Then
tempArray(1) = formatFilesWorker.PortraitFormat()
Else
tempArray(1) = formatFilesWorker.LandscapeFormat()
End If

End Select

fileTypeChoice = tempArray

End Function

VBA Open and Save file in directory

OPEN


Option Explicit


Public Function GetAllFilesInDir(ByVal strDirPath As String) As Variant
' Loop through the directory specified in strDirPath and save each
' file name in an array, then return that array to the calling
' procedure.
' Return False if strDirPath is not a valid directory.


Dim strTempName As String
Dim varFiles() As Variant
Dim lngFileCount As Long

On Error GoTo GetAllFiles_Err

' Make sure that strDirPath ends with a "\" character.
If Right$(strDirPath, 1) <> "\" Then
strDirPath = strDirPath & "\"
End If

' Make sure strDirPath is a directory.
If GetAttr(strDirPath) = vbDirectory Then
strTempName = Dir(strDirPath, vbDirectory)
Do Until Len(strTempName) = 0
' Exclude ".", "..".
If (strTempName <> ".") And (strTempName <> "..") Then
' Make sure we do not have a sub-directory name.
If (GetAttr(strDirPath & strTempName) _
And vbDirectory) <> vbDirectory Then
' Increase the size of the array
' to accommodate the found filename
' and add the filename to the array.

'Control the file type(optional) for entering the array
If Right(strTempName, 4) = ".out" Then
ReDim Preserve varFiles(lngFileCount)
varFiles(lngFileCount) = strTempName
lngFileCount = lngFileCount + 1
End If
End If
End If
' Use the Dir function to find the next filename.
strTempName = Dir()
Loop
' Return the array of found files.
GetAllFilesInDir = varFiles
End If
GetAllFiles_End:
Exit Function
GetAllFiles_Err:
GetAllFilesInDir = False
Resume GetAllFiles_End
End Function

Public Function GetAllFiles(ByVal folderPath As String) As Long

Dim varFileArray As Variant
Dim lngI As Long
Dim strDirName As String


Const NO_FILES_IN_DIR As Long = 9
Const INVALID_DIR As Long = 13

' On Error GoTo Test_Err

strDirName = folderPath
varFileArray = GetAllFilesInDir(strDirName)

GetAllFiles = UBound(varFileArray)
For lngI = 0 To UBound(varFileArray)
Debug.Print "Inside the Array: " & varFileArray(lngI)

Documents.Open strDirName & "\" & varFileArray(lngI)
'ActiveDocument.Close , varFileArray(lngI)

Next lngI


End Function

Public Function openSingleFile(ByVal fn As String) As Boolean

Workbooks.OpenText Filename:= _
fn, Origin:= _
950, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(12, 1), Array(94, 1), Array(122, 1), Array(150, 1)), TrailingMinusNumbers:= _
True
Cells.Select
Selection.Columns.AutoFit



openSingleFile_End:
Exit Function
openSingleFile_Err:
openSingleFile = False
Resume openSingleFile_End
End Function





Save
Option Explicit


Public Function toSave(ByVal fileNamePrefix As String, ByVal filesExtensionAfterCon As String) As Boolean


Dim Filename
Dim callSaveVar As Boolean


'Avoid if the user new a document (i.e. Document1 )
If (InStr(ActiveDocument.Name, ".") <> 0) Then
Filename = ActiveDocument.path & fileNamePrefix & Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1)
callSaveVar = checkIfDocExistNDetermineIfSave(Filename, filesExtensionAfterCon)

'To save the document b4 quit
ActiveDocument.Close savechanges:=True

toSave = callSaveVar

Else
Filename = ActiveDocument.path & fileNamePrefix & ActiveDocument.Name
Select Case VBA.MsgBox("Do you want to save the file as " & Filename, vbYesNo, "Confirm to save the file")
Case VBA.vbYes
callSaveVar = checkIfDocExistNDetermineIfSave(Filename, filesExtensionAfterCon)

'To save the document b4 quit
ActiveDocument.Close savechanges:=True

toSave = callSaveVar
Case VBA.vbNo
MsgBox "No file reformatted", vbInformation, "Action aborted"
toSave = False
End Select
End If





End Function
Public Function checkIfDocExistNDetermineIfSave(ByVal strPath As String, ByVal filesExtensionAfterCon As String) As Boolean
Dim checkFileExistsWorker As StartReformat
Set checkFileExistsWorker = New StartReformat

Dim isFileExists As Boolean
Dim isSaveOK As Boolean

isFileExists = checkFileExistsWorker.IsFileOrDirExists(strPath & "." & filesExtensionAfterCon)

Dim isSaveAnyway As Boolean

If (isFileExists) Then
'isSaveAnyway = MsgBox("The file " & strPath & ".doc is existed already, do you still want to save??", vbYesNoCancel, "Files Exists")

Select Case VBA.MsgBox("The file " & strPath & "." & filesExtensionAfterCon & " is existed already, do you still want to save??", vbYesNoCancel, "Files Exists")
Case VBA.vbYes
isSaveOK = Save(strPath, filesExtensionAfterCon)
checkIfDocExistNDetermineIfSave = isSaveOK
Case VBA.vbNo
MsgBox "File not saved due to duplication", vbExclamation, "Duplicated File not been sasved"
checkIfDocExistNDetermineIfSave = False
Case VBA.vbCancel
MsgBox "File not saved as you stop the process", vbExclamation, "File abort by user"
checkIfDocExistNDetermineIfSave = False
End Select

Else
isSaveOK = Save(strPath, filesExtensionAfterCon)
checkIfDocExistNDetermineIfSave = isSaveOK
End If
End Function

Public Function Save(ByVal strPath As String, ByVal filesExtensionAfterCon As String) As Boolean
ActiveDocument.SaveAs Filename:=strPath & "." & filesExtensionAfterCon, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

Select Case Err.Number
Case Is = 0
Save = True
Case Else
Save = False
MsgBox Err.Number & " " & Err.Description, vbMsgBoxHelpButton


End Select


End Function


2008年6月1日 星期日

Create view


Create or replace view

(PLAN_PERIOD_TYPE, PERIOD_PROFILE_ID, GL_PERIOD_TYPE, NUMBER_OF_PERIODS,
PERIOD_SET_NAME)

AS
(SELECT pppp.PLAN_PERIOD_TYPE, pppp.PERIOD_PROFILE_ID, pppp.GL_PERIOD_TYPE, pppp.NUMBER_OF_PERIODS, pppp.PERIOD_SET_NAME from pa_proj_period_profiles pppp, pa_budget_versions pbv WHERE pbv.budget_version_id = pa_fin_plan_view_global.Get_Version_ID() and pppp.PERIOD_PROFILE_ID = pbv.PERIOD_PROFILE_ID)

PL/SQL

 
PACKAGE ABM_APP AUTHID CURRENT_USER AS
/* $Header: ABMAPPS.pls 115.4 2002/11/04 19:56:45 nmartine ship $ */

/**
* Write the AbmApplet HTML to the web server HTTP stream.
*/
PROCEDURE LAUNCH;
PROCEDURE LAUNCHCOREABMDOCUMENTS;
PROCEDURE LAUNCHABMANALYZERDOCUMENTS;
PROCEDURE LAUNCHSEMEXCHANGEDOCUMENTS;

END ABM_APP;

===========================================================





Package Body ABM_APP as
-- $Header: ABMAPPB.pls 115.28.11571.7 2004/04/01 17:16:06 rdharams ship $

/**
* Write the AbmApplet HTML to the web server HTTP stream.
*/
PROCEDURE launch
IS

dbcFilePath VARCHAR2(128) := FEM_GLOBAL.getDbcFilePath();
sessionCookieValue VARCHAR2(128) := ICX_CALL.ENCRYPT3(ICX_SEC.getSessionCookie());
remoteHost VARCHAR2(128) := FND_PROFILE.VALUE('ABM_REMOTE_HOST');
remotePort VARCHAR2(128) := FND_PROFILE.VALUE('ABM_REMOTE_PORT');
serverHost VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_HOST');
serverPort VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_PORT');
ORBGatekeeperIOR VARCHAR2(256) := FND_PROFILE.VALUE('ABM_ORB_GATEKEEPER_IOR');
-- RD 04/01/2004 No longer passing resp id due to security reasons. This was not needed
-- and redundant to begin with. It was only used in the non-enterprise mode of the app.
-- This mode of ABM was never releeased and has been de-supported.
-- abmResponsibilityid FND_USER.USER_NAME%TYPE := 'APPS';
abmResponsibilityid FND_USER.USER_NAME%TYPE := '';

-- RD 04/01/2004 A simple error message is defined below for users trying to call procedures below
-- from unauthorised functions in the system. Please note that this error msg is not NLS enabled
-- because it will rarely get called. And since ABM is in maintenance mode, we want to avoid
-- generating the seed ldts, etc.
error VARCHAR2(250) := 'You do not have the required security privileges to launch Activity Based Management. Please contact your System Administrator';

BEGIN
-- RD 04/01/2004 Additional function security check added below for 11.5.10
IF NOT(fnd_function.test('ABM_APP')) THEN
htp.p(error);
ELSIF (icx_sec.validateSession ) THEN

fnd_applet_launcher.launch(
applet_class => 'oracle.apps.abm.javaui.AbmApplet',
archive_list => 'oracle/apps/abm/jar/abmclient.jar' ||
',oracle/apps/abm/jar/femserver.jar' ||
',oracle/apps/abm/jar/jbodomorcl.jar' ||
',oracle/apps/abm/jar/fwk_client.jar' ||
',oracle/apps/abm/jar/fndswingall.jar' ||
',oracle/apps/abm/jar/jdev-rt.jar' ||
',oracle/apps/abm/jar/fnddacf.jar' ||
',oracle/apps/abm/jar/fndinfobus.jar' ||
',oracle/apps/abm/jar/jbodatum111.jar' ||
',oracle/apps/abm/jar/jboremote.jar' ||
',oracle/apps/abm/jar/fndjndi.jar' ||
',oracle/apps/abm/jar/fndjewtall.jar' ||
',oracle/apps/abm/jar/jbovbclient.jar' ||
',oracle/apps/abm/jar/fndvbj.jar' ||
',oracle/apps/abm/jar/fndaolj.jar' ||
',oracle/apps/abm/jar/fndf1j.jar' ||
',oracle/apps/abm/jar/fndconnectionmanager.jar' ||
'',
user_args => '&gp1=ServerName&gv1=' ||
serverHost ||
'&gp2=ServerPort&gv2=' ||
serverPort ||
'&gp3=DeployPlatform&gv3=' ||
'VB' ||
'&gp4=DBC_FILE_NAME&gv4=' ||
dbcFilePath ||
'&gp5=HostName&gv5=' ||
remoteHost ||
'&gp6=ConnectionPort&gv6=' ||
remotePort ||
'&gp7=ORBgatekeeperIOR&gv7=' ||
ORBGatekeeperIOR ||
'&gp8=ORBalwaysProxy&gv8='||
'false' ||
'&gp9=ORBbackCompat&gv9=' ||
'true' ||
'&gp10=USE_ORB_LOCATOR&gv10=' ||
'true' ||
'&gp11=ABM_RESPONSIBILITY_ID&gv11=' ||
abmResponsibilityId ||
'&gp12=COOKIE_ID&gv12=' ||
sessionCookieValue ||
'',
title_app => 'ABM',
title_msg => 'ABM_PAGE_TITLE',
cache => 'off'
);

END IF;

END LAUNCH;



/**
* Write the Pdf Docs HTML to the web server HTTP stream.
*/
PROCEDURE LAUNCHCOREABMDOCUMENTS IS

serverHost VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_HOST');
serverPort VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_PORT');
helpPath VARCHAR2(128) := FND_PROFILE.VALUE('ABM_HELP_CORE_ABM');
coreAbmHelpUrl VARCHAR2(256) := 'http://' || serverHost || ':' || serverPort || helpPath;

BEGIN

IF (icx_sec.validateSession ) THEN
owa_util.redirect_url(coreAbmHelpUrl);
END IF;

END LAUNCHCOREABMDOCUMENTS;



PROCEDURE LAUNCHABMANALYZERDOCUMENTS IS

serverHost VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_HOST');
serverPort VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_PORT');
helpPath VARCHAR2(128) := FND_PROFILE.VALUE('ABM_HELP_ABMA');
abmAnalyzerHelpUrl VARCHAR2(256) := 'http://' || serverHost || ':' || serverPort || helpPath;

BEGIN

IF (icx_sec.validateSession ) THEN
owa_util.redirect_url(abmAnalyzerHelpUrl);
END IF;
END LAUNCHABMANALYZERDOCUMENTS;



PROCEDURE LAUNCHSEMEXCHANGEDOCUMENTS
IS

serverHost VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_HOST');
serverPort VARCHAR2(128) := FND_PROFILE.VALUE('ABM_SERVER_PORT');
helpPath VARCHAR2(128) := FND_PROFILE.VALUE('ABM_HELP_SEMX');
semExchangeHelpUrl VARCHAR2(256) := 'http://' || serverHost || ':' || serverPort || helpPath;

BEGIN

IF (icx_sec.validateSession ) THEN
owa_util.redirect_url(semExchangeHelpUrl);
END IF;
END LAUNCHSEMEXCHANGEDOCUMENTS;

END ABM_APP;

2008年5月23日 星期五

struts2 + hibernate + ms access ><

VBA---radio btn

Form --radio btn
========================
Option Explicit

Public Property Get Ori() As Integer
Select Case True
Case Me.rbLandscape.Value
Ori = 1
Case Me.rbPortrait.Value
Ori = 0
End Select
End Property

Public Property Let Ori(ByVal sNewValue As Integer)
If UCase$(sNewValue) = 1 Then
Me.rbLandscape = True
Else
Me.rbPortrait = True
End If
End Property


Private Sub btnOrientationConfirm_Click()
Me.Hide
End Sub