Lambda VB.Net Max

 

‘Lambda

Dim dList As IList(Of Decision) = CType(DecisionBindingSource.DataSource, IList(Of Decision))
dNew.ID = dList.Max(
Function(d) d.ID) + 1

Talking about How to: Bind Windows Forms Controls to DBNull Database Values

How to: Bind Objects to Windows Forms DataGridView Controls

 

Taken from MSDN Link Here but adjusted to make abstract

Private Sub SetupDGVComboBoxToEnum()
SetupDGVComboBoxColumnToEnumType(GetType(Decision.StatusIDEnum))
DGVColumnStatusID.DataPropertyName = "StatusID"
DGVColumnStatusID.Name = "Status"
End Sub

Private Sub SetupDGVComboBoxColumnToEnumType(ByVal enumType As Type)
DGVColumnStatusID.DataSource = [Enum].GetValues(enumType)
End Sub

Most Recently Used for objects on a form

 
Probably other ways of doing this. However this is my quickly devised method. Using a MRUToolStripDropDownButton.
Need to call MRUAdd after loading an object


Private mruList As IList(Of T)

Private Sub MRUAdd()
If mruList.Contains(Me.cPadMain) Then
mruList.Remove(Me.cPadMain)
End If

'Lambda
If mruList.Where(Function(m) m.ID = cPadMain.ID).Count = 0 Then
mruList.Insert(0, Me.cPadMain)
End If
MRUDisplay()

End Sub


Private Sub MRUDisplay()
MRUToolStripDropDownButton.DropDownItems.Clear()

'LINQ
Dim MRU As IEnumerable(Of PadMain) = From pm In mruList Order By pm.PadMaterial Descending
For Each pm As PadMain In MRU
Dim tsi As New ToolStripMenuItem
tsi.Tag = pm.ID
tsi.Text = pm.Pad + " in " + pm.Material.Material + " " + pm.ID.ToString
MRUToolStripDropDownButton.DropDownItems.Insert(0, tsi)
If MRUToolStripDropDownButton.DropDownItems.Count > 10 Then
Exit For
End If
Next

End Sub

LINQ samples

To use LINQ need

Imports System.Linq
May need reference to System.Core and System.Data
‘LINQ
Dim MRU As IEnumerable(Of PadMain) = From pm In mruList OrderBy pm.PadMaterial

LINQ to Entity Framework

Private
context As BC.SWT.EntityModel.SOPEntities

Dim EntityConnectionString = Configuration.ConfigurationManager.ConnectionStrings(“SOPEntities”).ConnectionString
context = New BC.SWT.EntityModel.SOPEntities(EntityConnectionString)

Dim
CustomerQuery AsObjectQuery(OfCustomer) = context.Customers
Dim results = From a In CustomerQuery Select a.CustomerID, a.Customer1 OrderBy Customer1

Lambda

Lamda Where


If cPadMain.PadHistoryList.Where(Function(h) h.IsNew = True).Count <> 0 Then
Dim cPadHistoryData As New PadHistoryData(Me.ConnectionStringSettings)
For Each ph As PadHistory In cPadMain.PadHistoryList.Where(Function(h) h.IsNew = True)
cPadHistoryData.Insert(ph)
Next
End If

Lamda Max

Dim dList As IList(Of Decision) = CType(DecisionBindingSource.DataSource, IList(Of Decision))
dNew.ID = dList.Max(Function(d) d.ID) + 1

Lamda check for repeats

Public Function IsSupplierPriorityOK() As Boolean
 
    'Lambda Check for repeats
    For Each cs1 As Costing.ComponentSupplier In Me.ComponentSupplierList.OrderBy(Function(h) h.Priority)
        Dim p1 As Integer = cs1.Priority
        If Me.ComponentSupplierList.Where(Function(h) h.Priority = p1).Count <> 1 Then
            Return False
        End If
    Next
    Return True
 
End Function

Q&A BWT

 
Help system ?
UML or other design documentation
SQL manipulate from where ? SSMS or VS
Certification – Too difficult – too much detail on individual subjects. MCTS 70-433 SQL Server Development
BIDS – SSRS – SSIS – SSAS
Any experience of T4 v CodeDom
Grog Talk interactive idea – How Visual Studio could be better
Naming Conventions
Data access technologies – Datasets – Directly coded – LINQ to SQL – Entity Framework ?
LINQ – Lambda

HTML Links

00/01/1900 in MS Excel

 
00/01/1900 is zero i.e. 0 formatted as a date ‘dd/mm/yyyy’
 
Custom Formats in MS Excel accept multiple arguments, so if you want a 0 but formatted as a blank then use a custom format
 
dd/mm/yyyy;;
 
that’s 2 x ;; on the end, indicating put nothing if you get a zero

SSRS Configuration

 
> Internet > Tools > Options > Security > Local Intranet > Sites > Advanced. Add address of local server.
 
For me only – see files in vs\projects\ssrs\configuration