on 12-02-2011 12:51 PM
Hi,
I want to make an attachment function in an Matrix. But to link to my column with a capo in the database of the type "Connection" does not work. And if i do the same for one field it_EDIT out of the matrix, it works.
I want to make the function of the attachment (annex) pattern SAP in my Matrix.
Hi,
Please gothrough below code.
Case SAPbouiCOM.BoEventTypes.et_CLICK
Try
Select Case pVal.ItemUID
Case "b_browse"
If pVal.BeforeAction Then If frmProject.Items.Item(pVal.ItemUID).Enabled = False Then BubbleEvent = False
If pVal.ActionSuccess Then
If oMatrix2.RowCount <> 0 Then
If oMatrix2.Columns.Item("TrgtPath").Cells.Item(1).Specific.value.Equals("") Then
oMatrix2.Clear()
oDBDSDetail2.Clear()
End If
End If
If SetAttachMentFile(frmProject, oDBDSHeader, oMatrix2, oDBDSDetail2) = False Then
BubbleEvent = False
End If
End If
Case "b_display"
If pVal.BeforeAction Then If frmProject.Items.Item(pVal.ItemUID).Enabled = False Then BubbleEvent = False
If pVal.ActionSuccess Then
For i As Integer = 1 To oMatrix2.VisualRowCount
If oMatrix2.IsRowSelected(i) Then OpenAttachment(oMatrix2, oDBDSDetail2, i)
Exit For
Next
End If
Case "b_delete"
If pVal.BeforeAction Then If frmProject.Items.Item(pVal.ItemUID).Enabled = False Then BubbleEvent = False
If pVal.ActionSuccess Then
DeleteRowAttachment(frmProject, oMatrix2, oDBDSDetail2, oMatrix2.GetNextSelectedRow(0, SAPbouiCOM.BoOrderType.ot_RowOrder))
End If
Case "Attach"
If pVal.BeforeAction = False And pVal.Row > 0 Then
If oMatrix2.IsRowSelected(pVal.Row) Then
frmProject.Items.Item("b_display").Enabled = True
frmProject.Items.Item("b_delete").Enabled = True
End If
End If
End Select
Catch
End Try
'Fuctions
#Region " Attachment Option "
Sub AddAttachment(ByVal oMatAttach As SAPbouiCOM.Matrix, ByVal oDBDSAttch As SAPbouiCOM.DBDataSource, ByVal oDBDSHeader As SAPbouiCOM.DBDataSource)
Try
If oMatAttach.VisualRowCount > 0 Then
Dim rsetAttCount As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
Dim oAttachment As SAPbobsCOM.Attachments2 = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2)
Dim oAttchLines As SAPbobsCOM.Attachments2_Lines
oAttchLines = oAttachment.Lines
oMatAttach.FlushToDataSource()
rsetAttCount.DoQuery("Select Count(*) From ATC1 Where AbsEntry = '" & Trim(oDBDSHeader.GetValue("U_AtcEntry", 0)) & "'")
If Trim(rsetAttCount.Fields.Item(0).Value).Equals("0") Then
For i As Integer = 1 To oMatAttach.VisualRowCount
If i > 1 Then oAttchLines.Add()
oDBDSAttch.Offset = i - 1
oAttchLines.SourcePath = Trim(oDBDSAttch.GetValue("U_ScrPath", oDBDSAttch.Offset))
oAttchLines.FileName = Trim(oDBDSAttch.GetValue("U_FileName", oDBDSAttch.Offset))
oAttchLines.FileExtension = Trim(oDBDSAttch.GetValue("U_FileExt", oDBDSAttch.Offset))
oAttchLines.Override = SAPbobsCOM.BoYesNoEnum.tYES
Next
oAttachment.Add()
Dim rsetAttch As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
rsetAttch.DoQuery("Select Case When Count(*) > 0 Then Max(AbsEntry) Else 0 End AbsEntry From ATC1")
oDBDSHeader.SetValue("U_AtcEntry", 0, rsetAttch.Fields.Item(0).Value)
Else
oAttachment.GetByKey(Trim(oDBDSHeader.GetValue("U_AtcEntry", 0)))
For i As Integer = 1 To oMatAttach.VisualRowCount
If oAttchLines.Count < i Then oAttchLines.Add()
oDBDSAttch.Offset = i - 1
oAttchLines.SetCurrentLine(i - 1)
oAttchLines.SourcePath = Trim(oDBDSAttch.GetValue("U_ScrPath", oDBDSAttch.Offset))
oAttchLines.FileName = Trim(oDBDSAttch.GetValue("U_FileName", oDBDSAttch.Offset))
oAttchLines.FileExtension = Trim(oDBDSAttch.GetValue("U_FileExt", oDBDSAttch.Offset))
oAttchLines.Override = SAPbobsCOM.BoYesNoEnum.tYES
Next
oAttachment.Update()
End If
End If
'Delete the Attachment Rows...
Dim rsetDelete As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
rsetDelete.DoQuery("Delete From ATC1 Where AbsEntry = '" & Trim(oDBDSHeader.GetValue("U_AtcEntry", 0)) & "' And Line >'" & oMatAttach.VisualRowCount & "' ")
Catch ex As Exception
oApplication.StatusBar.SetText("AddAttachment Failed:" & ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
Finally
End Try
End Sub
Sub DeleteRowAttachment(ByVal oForm As SAPbouiCOM.Form, ByVal oMatrix As SAPbouiCOM.Matrix, ByVal oDBDSAttch As SAPbouiCOM.DBDataSource, ByVal SelectedRowID As Integer)
Try
oDBDSAttch.RemoveRecord(SelectedRowID - 1)
oMatrix.DeleteRow(SelectedRowID)
oMatrix.FlushToDataSource()
For i As Integer = 1 To oMatrix.VisualRowCount
oMatrix.GetLineData(i)
oDBDSAttch.Offset = i - 1
oDBDSAttch.SetValue("LineID", oDBDSAttch.Offset, i)
oDBDSAttch.SetValue("U_TrgtPath", oDBDSAttch.Offset, Trim(oMatrix.Columns.Item("trgtpath").Cells.Item(i).Specific.Value))
oDBDSAttch.SetValue("U_ScrPath", oDBDSAttch.Offset, Trim(oMatrix.Columns.Item("scrpath").Cells.Item(i).Specific.Value))
oDBDSAttch.SetValue("U_FileName", oDBDSAttch.Offset, Trim(oMatrix.Columns.Item("filename").Cells.Item(i).Specific.Value))
oDBDSAttch.SetValue("U_FileExt", oDBDSAttch.Offset, Trim(oMatrix.Columns.Item("fileext").Cells.Item(i).Specific.Value))
oDBDSAttch.SetValue("U_Date", oDBDSAttch.Offset, Trim(oMatrix.Columns.Item("date").Cells.Item(i).Specific.Value))
oMatrix.SetLineData(i)
oMatrix.FlushToDataSource()
Next
'oDBDSAttch.RemoveRecord(oDBDSAttch.Size - 1)
oMatrix.LoadFromDataSource()
oForm.Items.Item("b_display").Enabled = False
oForm.Items.Item("b_delete").Enabled = False
If oForm.Mode <> SAPbouiCOM.BoFormMode.fm_ADD_MODE Then oForm.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE
Catch ex As Exception
oApplication.StatusBar.SetText("DeleteRowAttachment Method Failed:" & ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
Finally
End Try
End Sub
Function SetAttachMentFile(ByVal oForm As SAPbouiCOM.Form, ByVal oDBDSHeader As SAPbouiCOM.DBDataSource, ByVal oMatrix As SAPbouiCOM.Matrix, ByVal oDBDSAttch As SAPbouiCOM.DBDataSource) As Boolean
Try
If oCompany.AttachMentPath.Length <= 0 Then
StatusBarErrorMsg("Attchment folder not defined, or Attchment folder has been changed or removed. [Message 131-102]")
Return False
End If
Dim strFileName As String = FindFile()
If strFileName.Equals("") = False Then
Dim FileExist() As String = strFileName.Split("\")
Dim FileDestPath As String = oCompany.AttachMentPath & FileExist(FileExist.Length - 1)
If File.Exists(FileDestPath) Then
Dim LngRetVal As Long = oApplication.MessageBox("A file with this name already exists,would you like to replace this? " & FileDestPath & " will be replaced.", 1, "Yes", "No")
If LngRetVal <> 1 Then Return False
End If
Dim fileNameExt() As String = FileExist(FileExist.Length - 1).Split(".")
Dim ScrPath As String = oCompany.AttachMentPath
ScrPath = ScrPath.Substring(0, ScrPath.Length - 1)
Dim TrgtPath As String = strFileName.Substring(0, strFileName.LastIndexOf("\"))
oMatrix.AddRow()
oMatrix.FlushToDataSource()
oDBDSAttch.Offset = oDBDSAttch.Size - 1
oDBDSAttch.SetValue("LineID", oDBDSAttch.Offset, oMatrix.VisualRowCount)
oDBDSAttch.SetValue("U_TrgtPath", oDBDSAttch.Offset, ScrPath)
oDBDSAttch.SetValue("U_ScrPath", oDBDSAttch.Offset, TrgtPath)
oDBDSAttch.SetValue("U_FileName", oDBDSAttch.Offset, fileNameExt(0))
oDBDSAttch.SetValue("U_FileExt", oDBDSAttch.Offset, fileNameExt(1))
oDBDSAttch.SetValue("U_Date", oDBDSAttch.Offset, GetServerDate())
oMatrix.SetLineData(oDBDSAttch.Size)
oMatrix.FlushToDataSource()
If oForm.Mode <> SAPbouiCOM.BoFormMode.fm_ADD_MODE Then oForm.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE
End If
Return True
Catch ex As Exception
oApplication.StatusBar.SetText("Set AttachMent File Failed:" & ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
Return False
Finally
End Try
End Function
Sub OpenAttachment(ByVal oMatrix As SAPbouiCOM.Matrix, ByVal oDBDSAttch As SAPbouiCOM.DBDataSource, ByVal PvalRow As Integer)
Try
If PvalRow <= oMatrix.VisualRowCount And PvalRow <> 0 Then
Dim RowIndex As Integer = oMatrix.GetNextSelectedRow(0, SAPbouiCOM.BoOrderType.ot_RowOrder) - 1
Dim strServerPath, strClientPath As String
strServerPath = Trim(oDBDSAttch.GetValue("U_TrgtPath", RowIndex)) + "\" + Trim(oDBDSAttch.GetValue("U_FileName", RowIndex)) + "." + Trim(oDBDSAttch.GetValue("U_FileExt", RowIndex))
strClientPath = Trim(oDBDSAttch.GetValue("U_ScrPath", RowIndex)) + "\" + Trim(oDBDSAttch.GetValue("U_FileName", RowIndex)) + "." + Trim(oDBDSAttch.GetValue("U_FileExt", RowIndex))
'Open Attachment File
OpenFile(strServerPath, strClientPath)
End If
Catch ex As Exception
oApplication.StatusBar.SetText("OpenAttachment Method Failed:" & ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
Finally
End Try
End Sub
Sub AttchButtonEnable(ByVal oForm As SAPbouiCOM.Form, ByVal Matrix As SAPbouiCOM.Matrix, ByVal PvalRow As Integer)
Try
If PvalRow <= Matrix.VisualRowCount And PvalRow <> 0 Then
Matrix.SelectRow(PvalRow, True, False)
If Matrix.IsRowSelected(PvalRow) = True Then
oForm.Items.Item("b_display").Enabled = True
oForm.Items.Item("b_delete").Enabled = True
Else
oForm.Items.Item("b_display").Enabled = False
oForm.Items.Item("b_delete").Enabled = False
End If
End If
Catch ex As Exception
StatusBarErrorMsg("Attach Button Enble Function...")
End Try
End Sub
#End Region
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.