Insert into table without LOOP in VB.NET - vb.net

I have
For Each itemSN As SellingDetailSNCustomer In item.listSN
Dim newItem As New TR_Selling_Customer_Product_SN
newItem.FK_Selling_Detail_Customer_ID = oNew.PK_Selling_Customer_Detail_ID
newItem.SN = itemSN.SNProduct
newItem.CreatedDate = Now.ToString("yyyy-MM-dd")
newItem.CreatedBy = "system"
newItem.LastUpdateDate = Now.ToString("yyyy-MM-dd")
newItem.LastUpdateBy = "system"
newItem.Active = True
objdb.Entry(newItem).State = Entity.EntityState.Added
Dim obUpdateBookedSN As MS_Product_Serial_Number = (From x In objdb.Product_Serial_Number Where x.FK_Product_ID = item.FK_Product_ID And x.Serial_Number = itemSN.SNProduct Select x).FirstOrDefault
If obUpdateBookedSN IsNot Nothing Then
obUpdateBookedSN.Booked_Serial_Number = True
obUpdateBookedSN.LastUpdateDate = Now.ToString("yyyy-MM-dd")
obUpdateBookedSN.LastUpdateBy = "system"
objdb.Entry(obUpdateBookedSN).State = Entity.EntityState.Modified
End If
Next
objdb.SaveChanges()
When I have more than thousand serial number, this looping become very slow processing time.
I want to changes this code without looping.
How do I figure that out?

Related

TransformPDFFields option not working in CreateEnvelopeFromTemplatesAndForms using SOAP API

I am trying to create envelop using CreateEnvelopeFromTemplatesAndForms to make the pdf form fields editable. I am gettting unspecified_error. I have also tried removing the document from composite template and adding the document in the inline template envelop. In this case it creates and sends the envelop but does not make the fields editable. See my code below
'compositeTemplate
Dim envInfo As New EnvelopeInformation
With envInfo
.AccountId = c.AccountID
.Subject = subject
.EmailBlurb = emailBlurb
End With
Dim template As New CompositeTemplate
'recipients
Dim recipients As New List(Of Recipient)
For iRecip As Integer = 1 To packet.Recipients.Count
Dim recipient As New Recipient
Dim customfields As New List(Of String)
With packet.Recipients(iRecip - 1)
recipient.Email = .Email
recipient.SignerName = .Name
recipient.UserName = .Name
recipient.ID = .ID
recipient.RoutingOrder = .RoutingOrder
recipient.RoutingOrderSpecified = True
recipient.RequireIDLookup = .RequireIDLookup
recipient.RequireIDLookupSpecified = True
recipient.AccessCode = .AccessCode
recipient.AddAccessCodeToEmail = False
recipient.AddAccessCodeToEmailSpecified = True
recipient.DefaultRecipient = .DefaultRecipient
recipient.DefaultRecipientSpecified = .IsDefaultRecipientSpecified
If (Not String.IsNullOrEmpty(.CaptiveInfoClientUserId)) Then
recipient.CaptiveInfo = New RecipientCaptiveInfo()
recipient.CaptiveInfo.ClientUserId = .CaptiveInfoClientUserId
End If
customfields.Add(String.Format("SignerRole={0}", .Role))
End With
'add customfields list to recipient customfields
recipient.CustomFields = customfields.ToArray
recipients.Add(recipient)
Next
Dim inlineTemplate As New InlineTemplate
inlineTemplate.Sequence = 1
inlineTemplate.Envelope = New Envelope
inlineTemplate.Envelope.AccountId = c.AccountID
With inlineTemplate.Envelope
.Notification = New APIService.Notification
Dim exp As New APIService.Expirations
With exp
.ExpireEnabled = _envelopeExpirationEnabled
If _envelopeExpirationEnabled Then
.ExpireAfter = _envelopeExpirationDays
If _envelopeExpirationWarningEnabled Then
.ExpireWarn = _envelopeExpirationWarningDaysLeft
End If
End If
End With
.Notification.Expirations = exp
End With
Dim tabs As New List(Of Tab)
'add documents
Dim documents As New List(Of Document)
Dim matchBoxes As New List(Of MatchBox)
For iDoc As Integer = 1 To packet.Forms.Count
Dim theForm As Objects.Form = packet.Forms(iDoc - 1)
theForm.ID = iDoc
Dim document As New Document
document.Name = theForm.FilePath
document.PDFBytes = theForm.FileBytes
document.ID = theForm.ID
document.TransformPdfFields = True
'add tabs - this will be based on metadata defined in the database for the attached forms
For Each oTab As Objects.Tab In theForm.Tabs
Dim tab As New Tab
If Not String.IsNullOrEmpty(oTab.AnchorText) AndAlso oTab.TabType <> TabTypeCode.Custom Then
Dim aTab As New AnchorTab
aTab.AnchorTabString = oTab.AnchorText
tab.AnchorTabItem = aTab
ElseIf oTab.TabType = TabTypeCode.Custom Then
tab.TabLabel = oTab.AnchorText
End If
With tab
.DocumentID = document.ID
.RecipientID = oTab.Recipient.ID
.Type = oTab.TabType
.PageNumber = oTab.PageNumber
.XPosition = oTab.XPosition
.YPosition = oTab.YPosition
If .Type = TabTypeCode.InitialHere Then
.ScaleValueSpecified = True
.ScaleValue = 0.53
End If
End With
tabs.Add(tab)
Next
documents.Add(document)
Next
inlineTemplate.Envelope.Recipients = recipients.ToArray
inlineTemplate.Envelope.Tabs = tabs.ToArray
template.InlineTemplates = New InlineTemplate() {inlineTemplate}
template.Document = New Document
template.Document.ID = 1
template.Document.Name = "TemplateDoc"
template.Document.PDFBytes = documents(0).PDFBytes
template.Document.TransformPdfFields = True
template.Document.FileExtension = "pdf"
Dim _apiProxy As APIServiceSoap = CreateApiProxy(c)
Dim envStatus As EnvelopeStatus = _apiProxy.CreateEnvelopeFromTemplatesAndForms(envInfo, New CompositeTemplate() {template}, True)
Any assistance would be greatly appreciated.
Thanks,
Pulak
The best way to debug such issues (which are sometimes bugs on the DocuSign server side) is to inspect your raw (XML based) SOAP request that you are sending over the wire. If I were you I would include it here in your question as it's much easier to diagnose when we can see the request as opposed to the code that creates the request.
With that said, are setting the tab's Locked property to false so that it's editable? You'll also need to set CustomTabLockedSpecified property to true for this to take affect.
Basically, in your tab definition code try something like this:
With tab
.DocumentID = document.ID
.RecipientID = oTab.Recipient.ID
.Type = oTab.TabType
...
.CustomTabLockedSpecified = True
.CustomTabLocked = False

Datagridview doesnt show data in rows

I am currently working on project in which i have to display IP Configuration to user in VB.Net Application.
I am using DataGridView to display IP Config to user.
But problem is Datagridview doesnt display anything in its row at all.
Image for proof
Here is the code
Public Sub MT_Validate_Msg(ByRef lbData() As Byte)
Dim lsAddr(3) As String
Dim lsMAC(5) As String
Dim lstConfig As TCP_SER_Config
If lbData.Length >= 256 Then
'Check Header Footer and Response Size
If lbData(0) = Asc("$") And lbData(1) = Asc("#") _
And lbData(254) = Asc("<") And lbData(255) = Asc(">") _
And lbData(2) = UDP_RESPONSE_SIZE And lbData(3) = 0 Then
gnDevice_Search_Count += 1
'MsgBox("Response Received")
lsAddr(0) = lbData(7).ToString
lsAddr(1) = lbData(9).ToString
lsAddr(2) = lbData(11).ToString
lsAddr(3) = lbData(13).ToString
lstConfig.IP = String.Join(".", lsAddr)
lsAddr(0) = lbData(15).ToString
lsAddr(1) = lbData(17).ToString
lsAddr(2) = lbData(19).ToString
lsAddr(3) = lbData(21).ToString
lstConfig.Subnet = String.Join(".", lsAddr)
lsAddr(0) = lbData(23).ToString
lsAddr(1) = lbData(25).ToString
lsAddr(2) = lbData(27).ToString
lsAddr(3) = lbData(29).ToString
lstConfig.Gateway = String.Join(".", lsAddr)
lstConfig.Alive_Time = lbData(31)
lsMAC(0) = Hex(lbData(33)).ToString
lsMAC(1) = Hex(lbData(34)).ToString
lsMAC(2) = Hex(lbData(35)).ToString
lsMAC(3) = Hex(lbData(36)).ToString
lsMAC(4) = Hex(lbData(37)).ToString
lsMAC(5) = Hex(lbData(38)).ToString
lstConfig.MAC = String.Join("-", lsMAC)
MT_FillGrid(lstConfig)
End If
End If
End Sub
Public Sub MT_FillGrid(ByRef lstTCPConfig As TCP_SER_Config)
Dim row As String() = New String() {gnDevice_Search_Count.ToString, lstTCPConfig.IP, lstTCPConfig.Subnet, _
lstTCPConfig.Gateway, lstTCPConfig.Alive_Time.ToString, lstTCPConfig.MAC}
GridDev_List.Rows.Add(row)
row = New String() {"1", "192.168.0.100", "255.255.255.0", "255.255.255.255", "60", "22-0B-3C-2D-00-01"}
GridDev_List.Rows.Add(row)
End Sub
Expecting a result like this, Where i am going wrong in code ?

DevExpress.XtraGrid.StyleFormatCondition using vb.net

How can i format some cell value into something else using DevExpress.XtraGrid.StyleFormatCondition . For example I need to bold some value in one or more cell with same value and how to change only one column not entire row
Here it is my example:
For i As Integer = 0 To GridView1.DataRowCount
Dim a As String = (GridView1.Columns(0)).ToString
If a = "Vrsta računa" Then 'THE NAME OF COLUMN
Dim b = GridView1.GetRowCellValue(i, "accountsType") ' THE NAME OF CELL
If b = "KLASA" Then
Dim condition1 As StyleFormatCondition = New DevExpress.XtraGrid.StyleFormatCondition()
condition1.Appearance.BorderColor = Color.Blue
condition1.Appearance.BackColor = Color.Red
condition1.Appearance.Options.UseBackColor = True
condition1.Appearance.Options.UseBorderColor = True
'***** HOW TO BOLD CELL VALUE *******
condition1.Condition = FormatConditionEnum.Expression
condition1.ApplyToRow = False
condition1.Expression = "[accountsType] = 'KLASA'"
GridView1.FormatConditions.Add(condition1)
ElseIf b = "SINTETIKA" Then
Dim condition1 As StyleFormatCondition = New DevExpress.XtraGrid.StyleFormatCondition()
condition1.Appearance.BorderColor = Color.Blue
condition1.Appearance.BackColor = Color.HotPink
condition1.Appearance.Options.UseBackColor = True
condition1.Appearance.Options.UseBorderColor = True
condition1.Condition = FormatConditionEnum.Expression
condition1.ApplyToRow = False
condition1.Expression = "[accountsType] = 'SINTETIKA'"
' I WANT TO Have an effect on a cell , AND not on entire row
GridView1.FormatConditions.Add(condition1)
ElseIf b = "ANALITIKA" Then
Dim condition1 As StyleFormatCondition = New DevExpress.XtraGrid.StyleFormatCondition()
condition1.Appearance.BorderColor = Color.Blue
condition1.Appearance.BackColor = Color.Green
condition1.Appearance.Options.UseBackColor = True
condition1.Appearance.Options.UseBorderColor = True
condition1.Condition = FormatConditionEnum.Expression
condition1.ApplyToRow = False
condition1.Expression = "[accountsType] = 'ANALITIKA'"
GridView1.FormatConditions.Add(condition1)
End If
End If
Next
It looks like you are using Format Conditions not in a correct way.
There is no need to traverse through all rows and columns manually. Before painting each row, GridView automatically checks if it meets any condition in its FormatConditions collection. If so, GridView applies a corresponding style.
Please refer to the following help topic to learn how to use Format Conditions correctly:
https://documentation.devexpress.com/#WindowsForms/CustomDocument759

Calling ABAP function module from Excel VBA Macro

I want to call an ABAP function from an Excel VBA Macro.
Is there any method I can follow to achieve this.
Please help me regarding this.
Dim sapConn As Object 'Declare connection object
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
sapConn.Connection.user = "user" 'Specify user
sapConn.Connection.Password = "" 'Then password
sapConn.Connection.client = "001" 'Client
sapConn.Connection.ApplicationServer = "server" 'Target server address
sapConn.Connection.Language = "PT" 'Language code
'Finally, try to logon to the specified system and check if the connection established
If sapConn.Connection.Logon(0, True) <> True Then
MsgBox "Cannot Log on to SAP" 'Issue message if cannot logon
Else
MsgBox "Logged on to SAP!"
End If
Dim rfcAcctDocCheck As Object
Dim oAcctHeader As Object
Dim otAcctAR, otAcctGL, otAcctAP, otAcctAMT, otReturn As Object
Set rfcAcctDocCheck = sapConn.Add("BAPI_ACC_DOCUMENT_CHECK")
Set oAcctHeader = rfcAcctDocCheck.Exports("DOCUMENTHEADER")
Set otAcctGL = rfcAcctDocCheck.Tables("ACCOUNTGL")
Set otAcctAR = rfcAcctDocCheck.Tables("ACCOUNTRECEIVABLE")
Set otAcctAP = rfcAcctDocCheck.Tables("ACCOUNTPAYABLE")
Set otAcctAMT = rfcAcctDocCheck.Tables("CURRENCYAMOUNT")
Set otReturn = rfcAcctDocCheck.Tables("RETURN")
Dim qtLegs As Integer
Dim dt, comp, tpDoc, docRef, tpAcct, acct, customer, vendor, _
curr, val, spLedger, ccenter, order As String
Dim curLine As Integer
For lin = 1 To UBound(reg)
id = Format(tbPost.Cells(reg(lin).lin_ini, K_COL_ID), "0000000000")
dt = getDate(tbPost.Cells(reg(lin).lin_ini, K_COL_DT))
comp = getCompanyCode(tbPost.Cells(reg(lin).lin_ini, K_COL_EMPR))
tpDoc = getDocumentType(tbPost.Cells(reg(lin).lin_ini, K_COL_TP_DOC))
docRef = tbPost.Cells(reg(lin).lin_ini, K_COL_DOC_REF)
otAcctGL.freeTable
otAcctAR.freeTable
otAcctAP.freeTable
otAcctAMT.freeTable
oAcctHeader("USERNAME") = sapConn.Connection.user
oAcctHeader("HEADER_TXT") = "Lancado via Excel"
oAcctHeader("COMP_CODE") = comp
oAcctHeader("DOC_DATE") = dt
oAcctHeader("PSTNG_DATE") = dt
oAcctHeader("DOC_TYPE") = tpDoc
oAcctHeader("REF_DOC_NO") = docRef
otAcctAMT.Rows.Add
otAcctAMT(otAcctAMT.Rows.Count, "ITEMNO_ACC") = Format(leg, "0000000000")
otAcctAMT(otAcctAMT.Rows.Count, "CURRENCY") = curr
otAcctAMT(otAcctAMT.Rows.Count, "AMT_BASE") = val
Next
If rfcAcctDocCheck.Call = False Then
MsgBox rfcAcctDocCheck.Exception
End If

Datagrid on VB.net auto complete the other column?

I have a datagrid and I have imported it to my project under vb.net language, and the database is MS access...
any way in this datagrid one table call
"Employees"
ID - Name - Nationality - Job title
and what I want is when I write the ID number of the Employee, all the other details automatically comes upon to his ID number.
I found near answer I made it by my self ...
But it shown the result in combobox not text box :'(
Dim dgvc1 As New DataGridViewComboBoxColumn()
Dim index1 As Integer = DataGridView1.Columns.IndexOf(DataGridView1.Columns("code"))
Dim index11 As Integer = DataGridView1.Columns.IndexOf(DataGridView1.Columns("nu"))
Dim index111 As Integer = DataGridView1.Columns.IndexOf(DataGridView1.Columns("aaa"))
Dim dgvc11 As New DataGridViewComboBoxColumn()
dgvc1.Name = "Code Meaning"
dgvc1.DataPropertyName = "nu"
dgvc1.ValueMember = "nu"
dgvc1.DisplayMember = "code"
dgvc1.DataSource = CodesTableAdapter.GetData()
dgvc1.SortMode = DataGridViewColumnSortMode.Automatic
If DataGridView1.Columns.Contains(dgvc1) = False Then
DataGridView1.Columns.Insert(index1, dgvc1)
Else
End If
dgvc1.ReadOnly = True
dgvc1.Width = 250
dgvc11.Name = "meaning total"
dgvc11.DataPropertyName = "nu"
dgvc11.ValueMember = "nu"
dgvc11.DisplayMember = "aaa"
dgvc11.DataSource = CodesTableAdapter.GetData()
dgvc11.SortMode = DataGridViewColumnSortMode.Automatic
If DataGridView1.Columns.Contains(dgvc11) = False Then
DataGridView1.Columns.Insert(index111, dgvc11)
Else
End If
dgvc11.ReadOnly = True
dgvc11.Width = 250
dgvc11.DefaultCellStyle.BackColor = Color.White
dgvc11.DefaultCellStyle.ForeColor = Color.Black