Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit a4da350d authored by Terry Burns's avatar Terry Burns Committed by Kostis ANAGNOSTOPOULOS
Browse files
parent 80e159af
No related branches found
No related tags found
No related merge requests found
......@@ -70,13 +70,13 @@ Public Class Alternator
Me.PulleyRatio = inputs.First().PulleyRatio
Dim values2k As Dictionary(Of single,single) = inputs.where( function(x) x.RPM=2000).Select( function(x) new KeyValuePair(of single,single)(x.Amps,x.Efficiency)).ToDictionary( Function(x) x.Key, Function(x) x.Value)
Dim values4k As Dictionary(Of single,single) = inputs.where( function(x) x.RPM=2000).Select( function(x) new KeyValuePair(of single,single)(x.Amps,x.Efficiency)).ToDictionary( Function(x) x.Key, Function(x) x.Value)
Dim values6k As Dictionary(Of single,single) = inputs.where( function(x) x.RPM=2000).Select( function(x) new KeyValuePair(of single,single)(x.Amps,x.Efficiency)).ToDictionary( Function(x) x.Key, Function(x) x.Value)
Dim values4k As Dictionary(Of single,single) = inputs.where( function(x) x.RPM=4000).Select( function(x) new KeyValuePair(of single,single)(x.Amps,x.Efficiency)).ToDictionary( Function(x) x.Key, Function(x) x.Value)
Dim values6k As Dictionary(Of single,single) = inputs.where( function(x) x.RPM=6000).Select( function(x) new KeyValuePair(of single,single)(x.Amps,x.Efficiency)).ToDictionary( Function(x) x.Key, Function(x) x.Value)
BuildInputTable( values2k, InputTable2000)
BuildInputTable( values4k, InputTable2000)
BuildInputTable( values6k, InputTable2000)
BuildInputTable( values4k, InputTable4000)
BuildInputTable( values6k, InputTable6000)
End Sub
......

Imports VectoAuxiliaries.Electrics
Imports System
Imports System.Collections.Generic
Imports System.Linq
......@@ -98,6 +98,7 @@ Public Class CombinedAlternator
End Sub
private Function Initialise() As Boolean
'From the map we construct this CombinedAlternator object and original CombinedAlternator Object
......@@ -105,10 +106,6 @@ Public Class CombinedAlternator
Alternators.Clear
OriginalAlternators.Clear
'Set Number of alternators in AltSignals.
altSignals.NumberOfAlternators= map.Count/9
For Each alt As IEnumerable(Of ICombinedAlternatorMapRow) In map.GroupBy( Function(g) g.AlternatorName)
......@@ -123,8 +120,32 @@ Public Class CombinedAlternator
Next
Return true
End Function
private Function AddNewAlternator( list As List(Of ICombinedAlternatorMapRow), ByRef feeback As string) As Boolean
Dim returnValue As Boolean = true
Dim altName As String = list.First().AlternatorName
Dim pulleyRatio As Single = list.First().PulleyRatio
'Check alt does not already exist in list
If Alternators.where( Function(w) w.AlternatorName=altName).Count>0 then
feeback="This alternator already exists in in the list, operation not completed."
Return False
End If
Dim alternator As IAlternator = New Alternator(altSignals, list.ToList())
Alternators.Add( alternator )
Return returnValue
End Function
Public Sub Clone( other As CombinedAlternator)
For Each Alternator As IAlternator In Alternators
......@@ -158,13 +179,21 @@ Public Class CombinedAlternator
End Function
Public Function AddAlternator( item As IAlternator, byref feedback as string) As Boolean
Public Function AddAlternator( rows As List( Of ICombinedAlternatorMapRow) , byref feedback as string) As Boolean
If Not AddNewAlternator( rows, feedback )
feedback=String.Format("Unable to add new alternator : {0}", feedback)
Return false
End If
Return true
End Function
Public Function UpdateAlternator( item As IAlternator , byref feedback as string ) As Boolean
Public Function UpdateAlternator( rows As List( Of ICombinedAlternatorMapRow) , byref feedback as string ) As Boolean
......
......@@ -2,6 +2,7 @@
Imports System.Windows.Forms
Imports VectoAuxiliaries.Electrics
Imports System.ComponentModel
Imports VectoAuxiliaries.Hvac
......@@ -12,9 +13,7 @@ Public Class frmCombinedAlternators
Private altSignals As ICombinedAlternatorSignals
Protected gbColor As System.Drawing.Color = Color.LightGreen
'Constructor
Public Sub New(aaltPath As String, altSignals As ICombinedAlternatorSignals)
' This call is required by the designer.
......@@ -30,17 +29,13 @@ Public Class frmCombinedAlternators
End Sub
Private Sub BindGrid()
' New BindingList(Of ITechListBenefitLine)(ssmTOOL.TechList.TechLines.OrderBy( Function(o) o.Category).ThenBy( Function(t) t.BenefitName).ToList())
'gvAlternators.DataSource = New BindingList(Of combinedAlternator)( combinedAlt.Alternators)
' gvAlternators.Refresh()
'General Helpders
Private Sub BindGrid()
gvAlternators.DataSource = New BindingList(Of IAlternator)( combinedAlt.Alternators )
End Sub
Private Sub SetupControls()
'gvAlternators
......@@ -149,6 +144,7 @@ End Function
Return True
End Function
Private Function IsNumberBetweenZeroandOne(test As String) As Boolean
'Is this numeric sanity check.
......@@ -160,6 +156,43 @@ End Function
If number < 0 OrElse number > 1 Then Return False
Return True
End Function
Private Function IsNumberBetweenOverZeroAndLessThan100(txtBox As TextBox ) As Boolean
'Is this numeric sanity check.
If Not IsNumeric(txtBox.Text) Then
ErrorProvider1.SetError(txtBox,"Please enter a number")
return false
else
End If
Return False
Dim number As Single = 0
If Not Double.TryParse(txtBox.Text, number) Then
ErrorProvider1.SetError(txtBox,"Please enter a number >0 and <100")
Return False
Else
ErrorProvider1.SetError(txtBox,String.Empty)
End If
If number <= 0 OrElse number >=100 Then
ErrorProvider1.SetError(txtBox,"Please enter a number >0 and <100")
Return False
Else
ErrorProvider1.SetError(txtBox,String.Empty)
Return true
End If
Return True
End Function
......@@ -188,9 +221,10 @@ End Function
End Function
'Form Events
'Form Non Button Events
Private Sub groupBoxUserInput_Paint(sender As Object, e As Windows.Forms.PaintEventArgs) Handles grpTable2000PRM.Paint, grpTable6000PRM.Paint, grpTable4000PRM.Paint
......@@ -228,7 +262,7 @@ End Function
'Grid Events
Private Sub gvAlternators_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles gvAlternators.CellClick
If e.ColumnIndex < 0 OrElse e.RowIndex < 0 Then Return
......@@ -270,6 +304,187 @@ End Sub
Private sub FillEditPanel( index as integer )
Dim alt As IAlternator
Dim alternatorName As String = gvAlternators.Rows(index).Cells("AlternatorName").Value
alt = combinedAlt.Alternators.First( Function(f) f.AlternatorName=alternatorName )
txtIndex.Text = index
txtAlternatorName.Text = alt.AlternatorName
txt2K10Efficiency.Text = alt.InputTable2000.First( Function(x) x.Amps=10).Eff
txt2K40Efficiency.Text = alt.InputTable2000.First( Function(x) x.Amps=40).Eff
txt2K60Efficiency.Text = alt.InputTable2000.First( Function(x) x.Amps=60).Eff
txt4K10Efficiency.Text = alt.InputTable4000.First( Function(x) x.Amps=10).Eff
txt4K40Efficiency.Text = alt.InputTable4000.First( Function(x) x.Amps=40).Eff
txt4K60Efficiency.Text = alt.InputTable4000.First( Function(x) x.Amps=60).Eff
txt6K10Efficiency.Text = alt.InputTable6000.First( Function(x) x.Amps=10).Eff
txt6K40Efficiency.Text = alt.InputTable6000.First( Function(x) x.Amps=40).Eff
txt6K60Efficiency.Text = alt.InputTable6000.First( Function(x) x.Amps=60).Eff
txtPulleyRatio .Text = alt.PulleyRatio
End Sub
public Sub UpdateButtonText()
If txtIndex.Text=String.Empty then
btnUpdate.Text = "Add"
Else
btnUpdate.Text = "Update"
End if
End sub
Private Sub gvAlternators_CellDoubleClick( sender As Object, e As DataGridViewCellEventArgs) Handles gvAlternators.CellDoubleClick
If gvAlternators.SelectedCells.Count<1 then Return
Dim row As Integer = gvAlternators.SelectedCells(0).OwningRow.Index
Dim alternatorName As String
alternatorName = gvAlternators.Rows(row).Cells("AlternatorName").Value
Dim alt as IAlternator = combinedAlt.Alternators.First( Function(w) w.AlternatorName= alternatorName)
FillEditPanel( row )
UpdateButtonText()
End Sub
'Button Events
Private Sub btnClearForm_Click( sender As Object, e As EventArgs) Handles btnClearForm.Click
ClearEditPanel()
UpdateButtonText()
End Sub
'List Management
Private Sub ClearEditPanel()
txtIndex.Text = String.Empty
txt2K10Efficiency.Text = string.Empty
txt2K40Efficiency.Text = string.Empty
txt2K60Efficiency.Text = string.Empty
txt4K10Efficiency.Text = string.Empty
txt4K40Efficiency.Text = string.Empty
txt4K60Efficiency.Text = string.Empty
txt6K10Efficiency.Text = string.Empty
txt6K40Efficiency.Text = string.Empty
txt6K60Efficiency.Text = string.Empty
txtPulleyRatio .Text = string.Empty
End Sub
public Function Validate_UpdatePanel() As Boolean
Dim returnResult As Boolean = True
IsEmptyString(txtAlternatorName.Text, txtAlternatorName,"Please enter a name for the alternator, names must be unique", returnResult)
If Not IsNumberBetweenOverZeroAndLessThan100(txt2K10Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt2K40Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt2K60Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt4K10Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt4K40Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt4K60Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt6K10Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt6K40Efficiency) then returnResult = False
If Not IsNumberBetweenOverZeroAndLessThan100(txt6K60Efficiency) then returnResult = False
If Not IsPostiveNumber(txtPulleyRatio.text) then
ErrorProvider1.SetError(txtPulleyRatio,"Please enter a sensible positive number")
returnResult=False
Else
ErrorProvider1.SetError(txtPulleyRatio,String.Empty)
End If
Return returnResult
End Function
public function GetAlternatorFromPanel() As List(Of ICombinedAlternatorMapRow )
Dim newAlt As New List(Of ICombinedAlternatorMapRow)
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 2000,10,txt2K10Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 2000,40,txt2K40Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 2000,60,txt2K60Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 4000,10,txt4K10Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 4000,40,txt4K40Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 4000,60,txt4K60Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 6000,10,txt6K10Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 6000,40,txt6K40Efficiency.Text,txtPulleyRatio.Text))
newAlt.Add( New CombinedAlternatorMapRow(txtAlternatorName.Text, 6000,60,txt6K60Efficiency.Text,txtPulleyRatio.Text))
Return newAlt
End Function
Private Sub btnUpdate_Click( sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim feedback As String = String.Empty
If NOT Validate_UpdatePanel() then Return
If txtIndex.Text.Trim.Length=0 then
'This is an Add
If Not combinedAlt.AddAlternator( GetAlternatorFromPanel(), feedback) then
MessageBox.Show( feedback )
Else
BindGrid()
UpdateButtonText()
End if
Else
'This is an update
If Not combinedAlt.UpdateAlternator( GetAlternatorFromPanel() , feedback) then
MessageBox.Show( feedback )
Else
BindGrid()
ClearEditPanel()
UpdateButtonText()
End If
End If
End Sub
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment