คำสั่งที่อยู่ในปุ่ม add new item เพื่อใช้ในการเพิ่มรายการสินค้าใหม่หรือแก้ไขรายการสินค้าเดิมค่ะ
call SOEditItem(1)
Sub SOEditItem(NewItem As Integer)
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim uidoc As notesuidocument
Dim item As NotesItem
Dim RItem As NotesItem
Dim Itemdoc As NotesDocument
Dim Itemdata As NotesDocument
Dim ItemList List As String
Dim key As String
Dim dc As NotesDocumentCollection
Set db = session.CurrentDatabase
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
If NewItem =0 Then
If doc.docfullno(0) = "" Then
key = doc.mydocid(0)
Else
key = doc.docfullno(0)
End If
Set dc = ws.PickListCollection(PICKLIST_CUSTOM, False,db.Server, db.FilePath,"(LookupItemBySO)", "สินค้า", "เลือกสินค้า",key)
If dc.Count = 0 Then Exit Sub
End If
Call uidoc.Save
ItemList("MatDesc") = "MatDesc_SO"
ItemList("MatCode") = "MatCode_SO"
ItemList("Quantity") = "Quantity"
ItemList("Units") = "Units_SO"
Set Itemdata = New NotesDocument( db )
Set Itemdoc = Nothing
If NewItem = 0 Then
itemdata.UpdateField = "1"
Set Itemdoc = dc.GetFirstDocument
Call GetItemDetail(ItemList,Itemdata,Itemdoc)
End If
Edititem:
Dim v As Variant
v = ws.DialogBox _
( "ItemStock", True,1000 , False, False, _
False, False ,"รายละเอียดสินค้า",Itemdata,True)
If v = True Then
'Check Require Field
Dim ChckRequire As String
ChckRequire = ""
If Cstr(Itemdata.MatCode(0)) = "" Then
ChckRequire = "กรุณาระบุรายการสินค้า"
Elseif Not Isnumeric(Itemdata.Quantity(0)) Then
ChckRequire = "กรุณาระบุจำนวนสินค้าให้เป็นตัวเลข"
Elseif Itemdata.Quantity(0) <= 0 Then
ChckRequire = "กรุณาระบุจำนวนสินค้า"
End If
If ChckRequire <> "" Then
Msgbox ChckRequire,0+16,"แก้ไขข้อมูล"
Goto Edititem
End If
'New ITem
If Itemdoc Is Nothing Then
Set Itemdoc = New NotesDocument( db )
Set item = New NotesItem(Itemdoc, "FixReaders", "*", READERS)
Set item = New NotesItem(Itemdoc, "CreatedBy", doc.CreatedBy(0), AUTHORS)
Set item = New NotesItem(Itemdoc, "Editors", "", AUTHORS)
itemdoc.Form = "ItemDetail"
itemdoc.Mydocid = itemdoc.UniversalID
itemdoc.Parentdocid = doc.UniversalID
Itemdoc.CreatedBy = doc.CreatedBy
Itemdoc.History = "- "+session.CommonUserName+" สร้างรายการสินค้า ณ วันที่ " + Itemdoc.Created
If doc.docfullno(0) <> "" Then
itemdoc.SOFullno = doc.docfullno
itemdoc.SODateNo = doc.DocNoDate
End If
End If
Call SetItemDetail(ItemList,Itemdata,Itemdoc)
Call ws.ViewRefresh
Call uidoc.Reload
Call uidoc.Refresh
End If
End Sub |