2008年3月19日 星期三

11.從文件中以單一Key取得視界中所有的文件內容範例

若你想從這一份文件的的某一欄位當Key 而從視界中尋找與 該Key相關的文件,
可以從下面範例來修改,而從視界取得與該Key相關文件相關內容。
'-------------------------------------------------------------------------------
Sub Click(Source As Button)
'We are accessing a document in the same database the script lies.
'Therfore, get the session, the the current database.
Dim s As notessession
Set s=New notessession
Dim db As notesdatabase
Set db=s.currentdatabase

'get the front end document
Dim w As notesuiworkspace
Set w=New notesuiworkspace
Dim uidoc As notesuidocument
Set uidoc=w.currentdocument
'宣告ODBC connect
Dim conP As New ODBCConnection
Dim conC As New ODBCConnection
Dim qryP As New ODBCQuery
Dim qryC As New ODBCQuery
Dim resultP As New ODBCResultSet
Dim resultC As New ODBCResultSet
'
'Add code here
'
'get backend document of the current document
Dim doc As notesdocument
Set doc=uidoc.document
'將主文件資料存至Oracle
Set qryP.Connection = conP
Set qryC.Connection=conC
Set resultP.Query = qryP
Set resultC.Query=qryC
Call conP.ConnectTo("cerp","ymh","hedl26")
Call conC.ConnectTo("cerp","ymh","hedl26")
qryP.SQL = "SELECT * FROM scheduleoutline"
qryC.SQL="SELECT * FROM scheduleevent"
'----新增進度大綱資訊到Oracle scheduleoutlineTable-------------------------
resultP.Execute
resultP.addrow
Call resultP.setvalue("sitecode",Trim(uidoc.FieldGetText("sitecode")))
Call resultP.setvalue("sitelabel",Trim(uidoc.FieldGetText("sitelabel")))
Call resultP.setvalue("socode",Trim(uidoc.FieldGetText("socode")))
Call resultP.setvalue("rescode",Trim(uidoc.FieldGetText("rescode")))
Call resultP.setvalue("soname",Trim(uidoc.FieldGetText("soname")))
Call resultP.setvalue("soworkday",Trim(uidoc.FieldGetText("soworkday")))
Call resultP.setvalue("sostartdate",Trim(uidoc.FieldGetText("sostartdate")))
Call resultP.setvalue("sofinishdate",Trim(uidoc.FieldGetText("sofinishdate")))
Call resultP.setvalue("sorate",Trim(uidoc.FieldGetText("sorate")))
Call resultP.setvalue("somoney",Trim(uidoc.FieldGetText("somoney")))
Call resultP.setvalue("ndunid",Trim(uidoc.FieldGetText("unid")))
resultP.updaterow
'--------------------------------------------------------------------------
'---------取得進度項目資訊套表的進度項目文件轉入Oracle purchaseitem Table-------
Dim viewkey As String
Dim subnview As NotesView

Dim subndoc As NotesDocument

Set subnview=db.GetView("(ColScheduleoutlineR)")
Set subndoc=subnview.GetFirstDocument
viewkey=Trim(doc.socode(0)) 'Key請購單號

Do Until subndoc Is Nothing
If (subndoc.socode(0)=viewkey) Then
resultC.Execute
resultC.addrow
Call resultc.setvalue("sitecode",Trim(subndoc.sitecode(0)))
Call resultc.setvalue("socode",Trim(subndoc.socode(0)))
Call resultc.setvalue("rescode",Trim(subndoc.rescode(0)))
Call resultc.setvalue("resname",Trim(subndoc.resname(0)))
Call resultc.setvalue("seworkday",Trim(subndoc.seworkday(0)))
Call resultc.setvalue("sestartdate",Trim(subndoc.sestartdate(0)))
Call resultc.setvalue("sefinishdate",Trim(subndoc.sefinishdate(0)))
Call resultc.setvalue("serate",Trim(subndoc.serate(0)))
Call resultc.setvalue("semoney",Trim(subndoc.semoney(0)))
Call resultc.setvalue("ndpunid",Trim(subndoc.UnidParent(0)))
Call resultc.setvalue("ndcunid",Trim(subndoc.Unid(0)))
resultC.updaterow
End If
Set subndoc = subnview.GetNextDocument(subndoc)
Loop
'---------------------------------------------------------

resultP.close(DB_CLOSE)
conP.disconnect
resultC.close(DB_CLOSE)
conC.disconnect
End Sub
'-------------------------------------------------------------------------------

2008年3月18日 星期二

電腦突然無法進入windows下列檔案遺漏或損毀,無法啟動windows:c:\windows\system32\config\system

一、在正式解決問題前,希望你和我一起溫習一下在「修復主控台」裡會用到好久不見的「DOS」指令:
這些指令的用法都可以透過「 /?」的參數來獲得解答。
1、「cd /?」,按「Enter」鍵。
2、「dir /?」指令,按「Enter」鍵。
3、「attrib /?」指令,按「Enter」鍵。
4、「copy /?」,按「Enter」鍵。
5、「map /?」,按「Enter」鍵。
因為上面這些指令等一下都會用到,所以最少要弄懂「cd」和「copy」, 不然你可能沒有辦法將遺漏或損毀的檔案順利地拷貝回去正確的位置。

二、進入正題,因為你現在的硬碟已經沒有辦法順利進入 Windows XP或是 Windows 2000 了,我們打算進入「修復主控台」來解決。 所以,請先準備好可以光碟開機的 XP 光碟。

1、進入主機板的 BIOS 將光碟設為第一開機選項。
把光碟片放入光碟機裡存檔離開,
然後當我們看到「Press any key to boot from CD...」的提示時,
趕快隨便按任意鍵由光碟開機。
2、看到這個畫面按「R」進入「修復主控台」。
3、看到這個畫面按「1」按,「Enter」鍵。
4、如果你當年「Adinsitor」帳戶有設密碼請鍵入正確密碼,按「Enter」; 如果當年「Adinsitor」帳戶沒有設密碼請直接按「Enter」。
5、終於能進入「C:\WINNT」或「C:\WINDOWS」下了。
6、於「C:\WINNT>」下輸入「map」,然後按「Enter」。
請記下您含有 Windows xp 安裝光碟的光碟機代號,例如圖示裡光碟機代號是「E」和「F」。
備註:這個動作不是必要的,只是萬一將來有可能需要從光碟片拷貝某些檔案出來用。
7、於「C:\WINNT>」下輸入「cd system32」,然後按「Enter」,進入「C:\WINNT\SYSTEM32>」。
8、於「C:\WINNT\SYSTEM32>」下輸入「cd config」,然後按「Enter」,進入「C:\WINNT\SYSTEM32\CONFIG>」
9、於「C:\WINNT\SYSTEM32\CONFIG>」下輸入「attrib -s -r -a -h system」,然後按「Enter」,
這指令意思是:把這個資料夾的「system」檔解除「唯讀、保存、系統、隱藏,等屬性」,
主要目的是為了避免沒有辦法從其他地方拷貝「system」檔案到「C:\WINNT\SYSTEM32\CONFIG>」資料夾裡。
10、連續鍵入下列指令「cd ..」或是「cd /..」,直到回到根目錄「C:\>」。
11、於「C:\>」下鍵入「cd winnt」,按 Enter,到「C:\WINNT>」目錄。
12、於「C:\WINNT>」下鍵入「cd repair」,按 Enter,進入「C:\WINNT\REPAIR>」目錄。
13、於「C:\WINNT\REPAIR>」下鍵入「copy system C:\WINNT\system32\config\」,按 Enter。
14、如果系統提示您是否要覆蓋此檔案,輸入「Y」然後按「Enter」。
15、接著鍵入「EXIT」,按 Enter,重新啟動系統測試是否正常。
16、如果經過上述努力若還無法進入視窗,那就可能必須重灌了。

備註3:其實上述步驟有很多可以合併成一個步驟,慢慢來的原因是希望,我們能很清楚地知道,我們到底想做什麼?
例如7和8可以合併成於「C:\WINNT>」下輸入「cd "system32\config"」
備註4:萬一遇到檔案具備唯讀、隱藏等屬性,而又沒對該檔下「attrib -r -h」指令,可會沒有辦法覆蓋哦!
備註5:挑選正確版本的檔案來拷貝COPY也是很重要的,例如下圖發生的原因是:
她原本安裝時的光碟片是XP SP1,但經過多年使用早已更新到SP2,但偏偏用了SP1版本來覆蓋回去..... !剛剛的努力真是付諸流水啊!

三、馬後砲!
我個人的實務經驗是,很多人習慣把東西丟到桌面上,
「桌 面」「Desktop」的東西其實就是「C:\Documents and Settings\UserNames\Desktop」, 日積月累的結果把「C」塞爆了,例如下圖用 DOS 版的 GHOST來檢查,「C」快滿了,所以檔案在沒中毒的狀況下會莫名奇妙消失。
參考資料 http://www.horngjyi.com.tw/sphpblog/index.php?entry=entry070620-022750

2008年3月13日 星期四

10.利用LS複製MsExcel工作表的方法。

請使用以下範例或是語法:
這範例是用在有一個固定表格時,將此表格當為範本,
然後使用 這各複製的方法來建立 格式 並將資料填入格式中。
'--------------------------------------

xlapp.Application.Worksheets(1).Cells.Copy
xlapp.Application.Worksheets.Add
xlapp.Range("A1").Select
xlapp.ActiveSheet.Paste
'-----------------------------------------------------------

09.利用LS取得Excel目前正在使用中的工作表。

在LS取得目前Excel的工作或是將資料Focus到某個工作表,
可以使用以下方式設定。
'-------------------------------------------------------


Set XlSheet = XlWbk.Worksheets(2) '設定工作表
Call XlSheet.Activate '設定為目前正在使用的工作表

'-------------------------------------------------------

08.透過LS增加Excel的工作表範例語法。

可以使用以下範例語法:
'------------------------------------------------------


Set xlApp = CreateObject("Excel.Application")
' expression.Add(Before, After, Count, Type)
' "Before" is null 增加在目前工作表前面的參數
' "After" is the last sheet that currently exists
' "Count" is null 增加在目前工作表後面的參數
' "Type" is xlWorksheet which the Excel Object Browser shows is -4167
xlApp.Worksheets.Add ,xlApp.Worksheets(xlApp.Worksheets.Count), , -4167
'------------------------------------------------------

07.我要將Excel資料匯入Notes中,但只更新Notes中已存在文件的部份欄位資料,要如何修改程式碼

這各範例我還沒有測試過,不過我找到了有這方式可以是..提供給大家測試。
'-------------------------------------------------------------------------

Sub Click(Source As Button)
Dim s As notessession
Dim ws As notesuiworkspace
Dim db As notesdatabase
Dim doc As notesdocument
Dim xl As Variant
Dim xlwbk As Variant
Dim xlsht As Variant
Dim selected As Variant
Dim filename As String
Dim row As Integer
Set ws = New notesuiworkspace
selected = ws.openfiledialog(False,"請選擇你要匯入的人員 / 評量表對照檔", "Microsoft Excel|*.xls", "")
If Isempty(selected) Then
Messagebox "您沒有選擇要匯入的檔案", 16, "訊息"
Exit Sub
End If
filename = selected(0)
Set xl = createobject("Excel.Application")
xl.visible = False
xl.workbooks.open filename
Set xlwbk = xl.activeworkbook
Set xlsht = xlwbk.activesheet
row = 2
Set s = New notessession
Set db = s.currentdatabase
Set view = db.getview("(allpeoplebyempno)")
Do Until Cstr(Trim(xlsht.cells(row, 1).value)) = ""
keystr = Ucase(Cstr(Trim(xlsht.cells(row, 1).value)))
Set doc = view.getdocumentbykey(Ucase(Cstr(Trim(xlsht.cells(row, 1).value))), False)
If Not(doc Is Nothing) Then
idnostr = doc.idno(0)
doc.category = Ucase(Cstr(Trim(xlsht.cells(row, 6).value)))
doc.execute = "Yes"
Call doc.save(False, False)
End If
row = row + 1
Loop
Call ws.viewrefresh
Messagebox "評量表對應檔匯入完成", 64, "訊息"
End Sub

'-------------------------------------------------------------------------

06.請問要如何將資料庫的所有視界問題

將資料庫的所有視界的名稱收集放進套表的對話清單的欄位中。
'-------------------------------------------------------------------------------------
Make a new view named "Views", with no selection formula. Make the first column title "Title" and the formula $TITLE.

Somewhere in the database make a temporary button containing the following code. Press the button just once. After that, you can discard the button.


Sub Click(Source As Button)
Dim session As New NotesSession
With session.CurrentDatabase
With .GetDocumentByUNID(.GetView("Views").UniversalID)
.~$FormulaClass = "8"
.Save True, False
End With
End With
End Sub

'-------------------------------------------------------------------------------------

05.請問如何更新前景文件欄位值(背景的欄位值較新)

這個範例是寫在代理程式上面去執行:
'-----------------------------------------------------------------------
Declarations
Dim nuiw As notesuiworkspace
Dim nuidb As notesuidatabase
Dim ndb As notesdatabase
Dim ndoccol As notesdocumentcollection
Dim ndoc As notesdocument
Dim nuidoc As notesuidocument

Initialize
Sub Initialize
Set nuiw = New notesuiworkspace
Set nuidb = nuiw.currentdatabase
Set ndb = nuidb.database
Set ndoccol = ndb.unprocesseddocuments 'this collects the flagged documents

For j = 1 To ndoccol.count
Set ndoc = ndoccol.getnthdocument(j)
Set nuidoc = nuiw.editdocument(True,ndoc)

Call nuidoc.refresh
Call nuidoc.save
Call nuidoc.close
Next

End Sub
'----------------------------------------------------------------------------------------------------

2008年3月11日 星期二

04.延續[03]文章在DialogBox中取值的技巧。

向在03例子中指示將「值」取出,我測試過程中若要在對取出的「值」加以邊化修飾,
必須注意使用以下的技巧:
'----------------------------------------------------------------------------------
docvalue = dialogDoc.GetItemValue("ListResName")(0) '取得User所選擇的"值"
'----------------------------------------------------------------------------------

2008年3月10日 星期一

03.當在DialogBox中,如果還想要開啟一個對話框,並且傳回相關值時,使用這個例子。

這個範例是當你已經開啟(設計)對話框DialogBox後,又想在開啟(設計)一個Dialogbox傳回值時
可以使用這個範例。
'-------------------------
Sub Click(Source As Button)
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim thisDb As NotesDatabase
Dim uidoc As NotesUIDocument
Dim thisDoc As NotesDocument
Dim dialogDoc As NotesDocument
Dim continue As Variant

Set uidoc = ws.CurrentDocument
Set thisDb = s.CurrentDatabase
Set thisDoc = uidoc.Document
Set dialogDoc = thisDb.CreateDocument
dialogDoc.InstructionText = "Put your user instructions here"
dialogDoc.UserInput = thisDoc.FieldA

continue = ws.Dialogbox("DialogForm",True,True,False,False,False,False,"Title For Dialog Box",dialogDoc,True,False,True)
If continue Then
thisDoc.FieldA = dialogDoc.UserInput

If uidoc.EditMode = False Then
Call thisDoc.Save(True,False)
End If
End If
End Sub
'--------------------------------------

2008年3月6日 星期四

02.在Lotus視界中的文件若要在Diablog中顯示可用以下範例。

在視界(View)中的Sub Queryopendocument(Source As Notesuiview, Continue As Variant)中使用。
'-------------------------------------------
Dim ws As New NotesUIWorkspace
Dim sess As New NotesSession
Dim db As NotesDatabase '目前資料庫
Dim doc As NotesDocument '選取文件
Dim fdb As NotesDatabase '要開啟視界的資料庫
Dim fview As NotesView '要開啟的視界
Set db = ws.CurrentDatabase.Database
Set doc = db.GetDocumentByID(Source.CaretNoteID)
Set fview=db.GetView("scheduleevent")

Call ws.DialogBox _
( "scheduleevent", True, True, True, True, _
False, False, "scheduleevent")
Continue = False
'------------------------------------
當『視界』是以『嵌入視界』的型態,那麼就要使用以下語法範例才可以將文件開啟在DialogBox中
'------------------------------------------------------------


Call ws.dialogbox("TheForm", True, True, False, True, False, False, "TheTitle", source.documents.getfirstdocument)


若要儲存開啟中的文件可以使用『button』公式如下:

@Command([FileSave])

P.S.: When calling the dialogbox using

Call ws.dialogbox("TheForm", True, True, True, True, False, False, "TheTitle", source.documents.getfirstdocument, False, True)

it displays no "OK" or "Cancel" button.
Then you can make your button to execute

@Command([FileSave]);
@Command([FileCloseWindow])

to save and close the dialogbox.