ÿþPublic Class ScheduleForm ' ************************************************************************************************************* Dim intColumn As Integer Dim intRow As Integer Dim MAXROWINDEX As Integer = 47 ' i.e. 48 rows 'Dim MAXCOLUMNINDEX As Integer = 12 ' i.e. 13 columns ' +*+*+* Dim MAXCOLUMNINDEX As Integer = 13 ' i.e. 14 columns ' +*+*+* Dim strDGVBoxText(MAXCOLUMNINDEX, MAXROWINDEX) As String Dim COLWIDTHROWHEADER As Integer = 120 Dim COLWIDTHREST As Integer = 20 Dim FONTSIZE As Integer = 8 Dim NO_FILE As Integer = 0 Dim FILE_ACTIVE As Integer = 1 Dim strRowTitle(MAXROWINDEX) As String Dim strPattern(MAXROWINDEX) As String Dim WANNENBAD As Integer = 1 Dim DUSCHBAD As Integer = 2 Dim WINDFANG As Integer = 3 Dim ESSDIELE As Integer = 4 Dim KUECHE As Integer = 5 Dim ELTERNSCHLAFZIMMER As Integer = 6 Dim WOHNZIMMERSO As Integer = 7 Dim WOHNZIMMERSW As Integer = 8 Dim ANGELIKA As Integer = 9 Dim REGINA As Integer = 10 Dim GALERIE As Integer = 11 Dim HOBBYRAUM As Integer = 12 Dim KELLERBAD As Integer = 13 Dim HEIZUNGSPUMPE As Integer = 14 Dim strFilePathNameOriginal As String Dim strValveSwitchTimeFilePathName As String Dim strValveSwitchTimeFolderName As String = "ValveSwitchTimes" 'Dim strTodaysValveSwitchTimeFileName As String = "NormalDay.txt" Dim strTodaysValveSwitchTimeFileName As String = "Default_Pattern.txt" Dim strDefaultValveSwitchTimeFilePathName As String = String.Empty Dim str_FunctionReply As String = String.Empty Dim i_Eye As Integer Dim i_Jay As Integer Dim i_AntiSlashPosi As Integer Dim strSwitchPattern As String = String.Empty ' ************************************************************************************************************* Public Sub New() Dim si_Eye As Single ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() 'Me.Text &= " Version 12507a" 'Me.Text &= " Version 12721b" ' General improvements 'Me.Text &= " Version 12830a" ' Added room status Oval Shape (OS_) 'Me.Text &= " Version 12901a" ' File Dialog for Fetch and Store File 'Me.Text &= " Version 12902a" ' Default is last file selected. 'Me.Text &= " Version 12903b" ' Changes necessary for TECS 'Me.Text &= " Version 12927a" ' Changes necessary for TECS 'Me.Text &= " Version 13118b" ' Heating Pump Action 'Me.Text &= " Version 13320a" ' strFilePathNameOriginal = "C:\MowastEngineering\TECS_Data" ' 20.03.2013 'Me.Text &= " Version 13322a" ' removing error when storing >Default_Pattern.txt< 'Me.Text &= " Version 13a08b" ' changing >Sub< to >Function< 'Me.Text &= " Version 14401a" ' Switch to Visual Studio Express 2013 Me.Text &= " Version 14429a" ' deleting all >My.Application.DoEvents()< ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. ' Row title are defined here For si_Eye = 0 To (MAXROWINDEX) Step 1 ' If (si_Eye Mod 2) = 0 Then strRowTitle(si_Eye) = (si_Eye / 2).ToString & ":00 - " & (si_Eye / 2).ToString & ":29 h" Else strRowTitle(si_Eye) = (CInt(si_Eye \ 2)).ToString & ":30 - " & (CInt(si_Eye \ 2)).ToString & ":59 h" End If Next si_Eye With Me.dgv_Display '.RowsDefaultCellStyle.BackColor = Color.Bisque .RowsDefaultCellStyle.BackColor = Color.Beige .AlternatingRowsDefaultCellStyle.BackColor = Color.Beige .RowHeadersVisible = True 'Header text for first column .RowHeadersWidth = COLWIDTHROWHEADER .TopLeftHeaderCell.Value = "Büchlweg 42" 'To hide the triangular arrow .RowHeadersDefaultCellStyle.Padding = New Padding(3) 'To hide the last row(Default newrow) .AllowUserToAddRows = False ' Allows Columns Header to be modified .EnableHeadersVisualStyles = False End With With Me.dgv_Display.ColumnHeadersDefaultCellStyle .Font = New Font(Me.dgv_Display.Font, FontStyle.Regular) .Font = New Font("Courier New", FONTSIZE) .Alignment = DataGridViewContentAlignment.MiddleCenter End With With Me.dgv_Display.DefaultCellStyle .BackColor = Color.Navy .ForeColor = Color.Black '.Font = New Font(Me.dgv_Display.Font, FontStyle.Regular) .Font = New Font(Me.dgv_Display.Font, FontStyle.Bold) .Font = New Font("Courier New", FONTSIZE) End With 'txt_Columns.Text = (MAXROWINDEX + 1).ToString OS_ElternSchlafzimmer lblA.Text = String.Empty 'txt_Folder.Text = strValveSwitchTimeFolderName txt_FileName.Text = strTodaysValveSwitchTimeFileName 'strFilePathNameOriginal = My.Computer.FileSystem.CurrentDirectory strFilePathNameOriginal = "C:\MowastEngineering\TECS_Data" ' 20.03.2013 My.Computer.FileSystem.CreateDirectory(strFilePathNameOriginal & "\" & strValveSwitchTimeFolderName) strValveSwitchTimeFilePathName = strFilePathNameOriginal & "\" & strValveSwitchTimeFolderName & "\" & txt_FileName.Text strDefaultValveSwitchTimeFilePathName = strFilePathNameOriginal & "\" & strValveSwitchTimeFolderName & "\" & strTodaysValveSwitchTimeFileName End Sub ' ************************************************************************************************************* Public Sub Versuch_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.BackColor = Color.AliceBlue 'Call Subroutine_CreateDGV() str_FunctionReply = strfctn_CreateScheduleDGV() 'Call Subroutine_FetchFileFill(NO_FILE) str_FunctionReply = strfctn_FetchFileFill(NO_FILE) dgv_Display.Visible = True ' My.Application.DoEvents() '14429 End Sub ' ************************************************************************************************************* ' ************************************************************************************************************* ' ########################################################### 'Public Sub Subroutine_CreateDGV() Public Function strfctn_CreateScheduleDGV() As String Dim str_ColHeader As String = "SpHeaderCol_" Dim iCounter As Integer dgv_Display.Rows.Clear() If dgv_Display.Columns.Count = 0 Then ' Spalten hinzufügen With dgv_Display .Columns.Add("SpHeaderCol_0", "01") .Columns.Add("SpHeaderCol_1", "02") .Columns.Add("SpHeaderCol_2", "03") .Columns.Add("SpHeaderCol_3", "04") .Columns.Add("SpHeaderCol_4", "05") .Columns.Add("SpHeaderCol_5", "06") .Columns.Add("SpHeaderCol_6", "07") .Columns.Add("SpHeaderCol_7", "08") .Columns.Add("SpHeaderCol_8", "09") .Columns.Add("SpHeaderCol_9", "10") .Columns.Add("SpHeaderCol_10", "11") .Columns.Add("SpHeaderCol_11", "12") ' +*+*+* .Columns.Add("SpHeaderCol_12", "13") ' +*+*+* .Columns.Add("SpHeaderCol_13", "14") ' +*+*+* '.Columns.Add("SpHeaderCol_14", "15") ' +*+*+* '.Columns.Add("SpHeaderCol_15", "16") ' +*+*+* End With 'For iCounter = 0 To (dgv_Display.Columns.Count - 1) ' str_ColHeader = "SpHeaderCol_" ' str_ColHeader &= iCounter.ToString ' dgv_Display.Columns.Add(str_ColHeader, (iCounter + 1).ToString) 'Next For iCounter = 0 To (dgv_Display.Columns.Count - 1) dgv_Display.Columns(iCounter).Width = COLWIDTHREST dgv_Display.Columns(iCounter).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter str_ColHeader = "SpHeaderCol_" str_ColHeader &= iCounter.ToString 'dgv_Display.Columns.Add(str_ColHeader, (iCounter + 1).ToString) dgv_Display.Columns(str_ColHeader).SortMode = DataGridViewColumnSortMode.NotSortable Next dgv_Display.Location = New Point(10, 20) ' (x , y) sets upper left corner of >dgv_Display< 'Call Subroutine_Setdgv_DisplaySize(COLWIDTHROWHEADER) str_FunctionReply = strfctn_SetScheduleDGV_DisplaySize(COLWIDTHROWHEADER) dgv_Display.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter End If ' end of >If dgv_Display.Columns.Count = 0 Then< strfctn_CreateScheduleDGV = "strfctn_CreateScheduleDGV is done" End Function ' ***************************************** ' ********************************************************* ' ########################################################### 'Public Sub Subroutine_Setdgv_DisplaySize(ByVal iRowHeaderWidth As Integer) Public Function strfctn_SetScheduleDGV_DisplaySize(ByVal iRowHeaderWidth As Integer) As String Dim iCounter As Integer = 0 Dim iTotalWidth As Integer = 0 Dim iTotalHeight As Integer = 0 Dim iYLocation As Integer 'Feld Breite einstellen iTotalWidth = 0 For iCounter = 0 To (dgv_Display.Columns.Count - 1) Step 1 iTotalWidth += dgv_Display.Columns(iCounter).Width Next iCounter 'Feld Höhe einstellen iTotalHeight = 0 For iCounter = 0 To (dgv_Display.Rows.Count - 1) Step 1 iTotalHeight += dgv_Display.Rows(iCounter).Height Next iCounter 'dgv_Display.Size = New Size((iTotalWidth + iRowHeaderWidth + 5), (iTotalHeight + 40)) dgv_Display.Size = New Size((iTotalWidth + iRowHeaderWidth + 20), 400) 'If ((iTotalHeight + 90) <= 250) Then ' Me.Height = 250 'Else ' Me.Height = iTotalHeight + 100 'End If Me.Height = 500 'If iTotalHeight < 600 Then ' iYLocation = 200 'Else ' iYLocation = 100 'End If iYLocation = 100 Dim NewYLocation As New System.Drawing.Point(iYLocation, Me.Location.Y) ' Starting at the upper left Me.Location = NewYLocation ' screen corner Dim NewXLocation As New System.Drawing.Point(100, Me.Location.X) ' Starting at the upper left Me.Location = NewXLocation ' screen corner strfctn_SetScheduleDGV_DisplaySize = "strfctn_SetScheduleDGV_DisplaySize is done" End Function ' ********************************************************* ' ########################################################### ' ###################################################################### ' ###################################################################### ' ########################################################### Private Sub btn_FetchFile_Click(sender As System.Object, e As System.EventArgs) Handles btn_FetchFile.Click Dim str_AktiveFileName As String Dim i_AsterixPosi As Integer strSwitchPattern = String.Empty 'Call Subroutine_FetchFileFill(FILE_ACTIVE) str_FunctionReply = strfctn_FetchFileFill(FILE_ACTIVE) Try ' clears default file ! My.Computer.FileSystem.WriteAllText(strDefaultValveSwitchTimeFilePathName, "", False) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try 'Call Subroutine_StoreInfo(strDefaultValveSwitchTimeFilePathName, strSwitchPattern) ' Default Backup str_FunctionReply = strfctn_StoreInfo(strDefaultValveSwitchTimeFilePathName, strSwitchPattern) ' Default Backup i_AsterixPosi = InStrRev(strSwitchPattern, "*") If i_AsterixPosi = 673 Then str_AktiveFileName = Mid(strSwitchPattern, (i_AsterixPosi + 1)) txt_FileName.Text = str_AktiveFileName Else MessageBox.Show("Error in SwitchPattern", "Warning") End If End Sub ' ********************************************************* ' ********************************************************* ' ########################################################### 'Public Sub Subroutine_FetchFileFill(ByVal i_FetchFlag) ' i_FetchFlag = 0 for Default Fetch Public Function strfctn_FetchFileFill(ByVal i_FetchFlag) As String ' i_FetchFlag = 0 for Default Fetch ' i_FetchFlag = 1 for Fetch File Dialoge Dim i_PatternLength As Integer Dim strEndString As String = String.Empty Dim i_Position As Integer Dim strFileName As String Select Case i_FetchFlag Case 0 strValveSwitchTimeFilePathName = strFilePathNameOriginal & "\" & strValveSwitchTimeFolderName & "\" & strTodaysValveSwitchTimeFileName Try strSwitchPattern = My.Computer.FileSystem.ReadAllText(strValveSwitchTimeFilePathName) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try i_Position = InStrRev(strSwitchPattern, "*") txt_FileName.Text = Mid(strSwitchPattern, (i_Position + 1)) Case 1 'Set the Open dialog properties With OFD_FetchSchedule .InitialDirectory = strFilePathNameOriginal & "\" & strValveSwitchTimeFolderName .Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*" .FilterIndex = 1 .Title = "Fetch Heating Schedule Data" End With 'Show the Open dialog and if the user clicks the Open button, 'load the file Select Case OFD_FetchSchedule.ShowDialog Case Windows.Forms.DialogResult.OK Try 'Save the file path and name strFileName = OFD_FetchSchedule.FileName i_Position = InStrRev(strFileName, "\") txt_FileName.Text = Mid(strFileName, (i_Position + 1)) strSwitchPattern = My.Computer.FileSystem.ReadAllText(strFileName) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try Case Windows.Forms.DialogResult.Cancel End Select End Select i_PatternLength = Len(strSwitchPattern) ' Testing pattern validity 'strEndString = Mid(strSwitchPattern, 625, 1) ' 13 * 48 + 1 = 625 strEndString = Mid(strSwitchPattern, 673, 1) ' 14 * 48 + 1 = 673 If strEndString = "*" Then txt_FileName.BackColor = Color.White 'Call Subroutine_Fill_Table(strSwitchPattern) str_FunctionReply = strfctn_Fill_Table(strSwitchPattern) Else 'txt_FileName.BackColor = Color.Red MessageBox.Show("in SwitchPatternFile", "Error") End If strfctn_FetchFileFill = "strfctn_FetchFileFill is done" End Function ' ###################################################################### ' ###################################################################### ' ########################################################### ' ########################################################### ' ########################################################### ' ########################################################### ' ########################################################### ' ########################################################### 'Private Sub Subroutine_Fill_Table(ByVal strIOPattern As String) Private Function strfctn_Fill_Table(ByVal strIOPattern As String) As String lblA.Text = String.Empty 'Call Subroutine_CreateDGV() str_FunctionReply = strfctn_CreateScheduleDGV() For Me.intRow = 0 To (MAXROWINDEX) Step 1 For Me.intColumn = 0 To (MAXCOLUMNINDEX) Step 1 Try 'strDGVBoxText(Me.intColumn, Me.intRow) = "O" strDGVBoxText(Me.intColumn, Me.intRow) = Mid(strIOPattern, Me.intRow * (MAXCOLUMNINDEX + 1) + Me.intColumn + 1, 1) Catch ex As System.Exception MessageBox.Show(ex.Message) End Try Next (Me.intColumn) With dgv_Display.Rows .Add(strDGVBoxText(0, intRow), _ strDGVBoxText(1, intRow), _ strDGVBoxText(2, intRow), _ strDGVBoxText(3, intRow), _ strDGVBoxText(4, intRow), _ strDGVBoxText(5, intRow), _ strDGVBoxText(6, intRow), _ strDGVBoxText(7, intRow), _ strDGVBoxText(8, intRow), _ strDGVBoxText(9, intRow), _ strDGVBoxText(10, intRow), _ strDGVBoxText(11, intRow), _ strDGVBoxText(12, intRow), _ strDGVBoxText(13, intRow)) ' +*+*+* End With 'strDGVBoxText(13, intRow), _ 'strDGVBoxText(14, intRow), _ With Me.dgv_Display.RowHeadersDefaultCellStyle '.Font = New Font(Me.dgv_Display.Font, FontStyle.Regular) .Font = New Font(Me.dgv_Display.Font, FontStyle.Underline) .Font = New Font("Courier New", FONTSIZE) .Alignment = DataGridViewContentAlignment.MiddleCenter End With Me.dgv_Display.Rows.Item(Me.intRow).HeaderCell.Value = strRowTitle(Me.intRow) Next (Me.intRow) 'Call Subroutine_Setdgv_DisplaySize(COLWIDTHROWHEADER) str_FunctionReply = strfctn_SetScheduleDGV_DisplaySize(COLWIDTHROWHEADER) For Me.intRow = 0 To (MAXROWINDEX) Step 1 For Me.intColumn = 0 To (MAXCOLUMNINDEX) Step 1 If Me.intColumn < (HEIZUNGSPUMPE - 1) Then If dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Value = "O" Then dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.BackColor = Color.LightBlue dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.ForeColor = Color.Black End If If dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Value = "I" Then dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.BackColor = Color.Tomato dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.ForeColor = Color.Yellow End If Else If dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Value = "O" Then dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.BackColor = Color.LightBlue dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.ForeColor = Color.Black End If If dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Value = "I" Then dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.BackColor = Color.Orange dgv_Display.Rows(Me.intRow).Cells(Me.intColumn).Style.ForeColor = Color.Black End If End If Next Me.intColumn Next Me.intRow strfctn_Fill_Table = "strfctn_Fill_Table is done" End Function ' ###################################################################### ' ###################################################################### ' ########################################################### Private Sub dgv_Display_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv_Display.CellClick Dim strBoxContent As String = String.Empty Dim intSelectedRow As Integer Dim intSelectedColumn As Integer Dim intIncrementedSelectedColumn As Integer ' My.Application.DoEvents() '14429 lblA.Text = "Spalte (Col): " & e.ColumnIndex & vbCrLf & "Zeile (Row): " & e.RowIndex & vbCrLf intSelectedRow = e.RowIndex intSelectedColumn = e.ColumnIndex ' My.Application.DoEvents() '14429 If ((intSelectedRow >= 0) And (intSelectedColumn >= 0)) Then If intSelectedColumn < (HEIZUNGSPUMPE - 1) Then If (dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.BackColor = Color.Tomato) Then dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Value = "O" dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.BackColor = Color.LightBlue dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.ForeColor = Color.Black Else dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Value = "I" dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.BackColor = Color.Tomato dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.ForeColor = Color.Yellow End If Else If (dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.BackColor = Color.Orange) Then dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Value = "O" dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.BackColor = Color.LightBlue dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.ForeColor = Color.Black Else dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Value = "I" dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.BackColor = Color.Orange dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Style.ForeColor = Color.Black End If End If ' My.Application.DoEvents() '14429 lblA.Text &= "Inhalt: >" & Convert.ToString(dgv_Display.Rows(intSelectedRow).Cells(intSelectedColumn).Value) & "<" & vbCrLf Else 'Call Beep() 'MessageBox.Show("You clicked to wrong area!", "Error") lblA.Text &= "Inhalt: Leer" & vbCrLf End If ' My.Application.DoEvents() '14429 If (intSelectedColumn >= 0) Then 'Call Subroutine_ClearAllAreas() str_FunctionReply = strfctn_ClearAllAreas() intIncrementedSelectedColumn = e.ColumnIndex + 1 'Call Subroutine_ColorDGVColumnHeader(intIncrementedSelectedColumn) str_FunctionReply = strfctn_ColorDGVColumnHeader(intIncrementedSelectedColumn) Select Case intIncrementedSelectedColumn Case WANNENBAD Area_Wannenbad.BackColor = Color.Red lbl_Zimmer.Text = "Wannenbad" ' My.Application.DoEvents() '14429 Case DUSCHBAD Area_Duschbad.BackColor = Color.Red lbl_Zimmer.Text = "Duschbad" ' My.Application.DoEvents() '14429 Case WINDFANG Area_Windfang.BackColor = Color.Red lbl_Zimmer.Text = "Windfang" ' My.Application.DoEvents() '14429 Case ESSDIELE Area_EssdieleA.BackColor = Color.Red Area_EssdieleB.BackColor = Color.Red Area_EssdieleC.BackColor = Color.Red lbl_Zimmer.Text = "Essdiele" ' My.Application.DoEvents() '14429 Case KUECHE Area_Kueche.BackColor = Color.Red lbl_Zimmer.Text = "Küche" ' My.Application.DoEvents() '14429 Case ELTERNSCHLAFZIMMER Area_ElternSchlafzimmer.BackColor = Color.Red lbl_Zimmer.Text = "ElternSchlafzimmmer" ' My.Application.DoEvents() '14429 Case WOHNZIMMERSO Area_WohnzimmerSO.BackColor = Color.Red lbl_Zimmer.Text = "WohnzimmerSO" ' My.Application.DoEvents() '14429 Case WOHNZIMMERSW Area_WohnzimmerSW.BackColor = Color.Red lbl_Zimmer.Text = "WohnzimmerSW" ' My.Application.DoEvents() '14429 Case ANGELIKA Area_Angelika.BackColor = Color.Red lbl_Zimmer.Text = "Angelika" ' My.Application.DoEvents() '14429 Case REGINA Area_Regina.BackColor = Color.Red lbl_Zimmer.Text = "Regina" ' My.Application.DoEvents() '14429 Case GALERIE Area_Galerie.BackColor = Color.Red lbl_Zimmer.Text = "Galerie" ' My.Application.DoEvents() '14429 Case HOBBYRAUM Area_HobbyRaum.BackColor = Color.Red lbl_Zimmer.Text = "HobbyRaum" ' My.Application.DoEvents() '14429 Case KELLERBAD Area_KellerBad.BackColor = Color.Red lbl_Zimmer.Text = "KellerBad" ' My.Application.DoEvents() '14429 Case HEIZUNGSPUMPE Area_Heizungspumpe.BackColor = Color.Orange lbl_Zimmer.Text = "Heizungspumpe" ' My.Application.DoEvents() '14429 'Case 15 ' MessageBox.Show("15", "Not used") ' My.Application.DoEvents() 'Case 16 ' MessageBox.Show("16", "Not used") ' My.Application.DoEvents() Case Else 'Call Subroutine_ClearAllAreas() str_FunctionReply = strfctn_ClearAllAreas() End Select End If ' end of >If (intSelectedRow < 0) Then< ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### 'Private Sub Subroutine_ClearAllAreas() Private Function strfctn_ClearAllAreas() As String Area_Wannenbad.BackColor = Color.LightGray Area_Duschbad.BackColor = Color.LightGray Area_Windfang.BackColor = Color.LightGray Area_EssdieleA.BackColor = Color.LightGray Area_EssdieleB.BackColor = Color.LightGray Area_EssdieleC.BackColor = Color.LightGray Area_Kueche.BackColor = Color.LightGray Area_ElternSchlafzimmer.BackColor = Color.LightGray Area_WohnzimmerSW.BackColor = Color.LightGray Area_WohnzimmerSO.BackColor = Color.LightGray Area_Angelika.BackColor = Color.LightGray Area_Regina.BackColor = Color.LightGray Area_Galerie.BackColor = Color.LightGray Area_HobbyRaum.BackColor = Color.LightGray Area_KellerBad.BackColor = Color.LightGray Area_Heizungspumpe.BackColor = Color.LightGray strfctn_ClearAllAreas = "strfctn_ClearAllAreas is done" End Function ' ##################################################################################### 'Private Sub Subroutine_ColorDGVColumnHeader(ByVal i_One As Integer) Private Function strfctn_ColorDGVColumnHeader(ByVal i_One As Integer) As String 'Call Subroutine_ClearColumnHeaderColor() str_FunctionReply = strfctn_ClearColumnHeaderColor() If i_One > 0 Then With Me.dgv_Display Dim bdStyle As New DataGridViewCellStyle bdStyle.BackColor = Color.Red .Columns(i_One - 1).HeaderCell.Style = bdStyle End With End If 'Call Subroutine_ClearAllAreas() str_FunctionReply = strfctn_ClearAllAreas() strfctn_ColorDGVColumnHeader = "strfctn_ColorDGVColumnHeader is done" End Function ' ##################################################################################### 'Private Sub Subroutine_ClearColumnHeaderColor() Private Function strfctn_ClearColumnHeaderColor() Dim i_Counter As Integer For i_Counter = 0 To MAXCOLUMNINDEX Step 1 With Me.dgv_Display Dim bdStyle As New DataGridViewCellStyle bdStyle.BackColor = Color.LightGray .Columns(i_Counter).HeaderCell.Style = bdStyle End With Next i_Counter strfctn_ClearColumnHeaderColor = "strfctn_ClearColumnHeaderColor is done" End Function ' ##################################################################################### Private Sub Area_Wannenbad_Click(sender As System.Object, e As System.EventArgs) Handles Area_Wannenbad.Click 'Call Subroutine_ColorDGVColumnHeader(WANNENBAD) str_FunctionReply = strfctn_ColorDGVColumnHeader(WANNENBAD) Area_Wannenbad.BackColor = Color.Red lbl_Zimmer.Text = "Wannenbad" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_Duschbad_Click(sender As System.Object, e As System.EventArgs) Handles Area_Duschbad.Click 'Call Subroutine_ColorDGVColumnHeader(DUSCHBAD) str_FunctionReply = strfctn_ColorDGVColumnHeader(DUSCHBAD) Area_Duschbad.BackColor = Color.Red lbl_Zimmer.Text = "Duschbad" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_Windfang_Click(sender As System.Object, e As System.EventArgs) Handles Area_Windfang.Click 'Call Subroutine_ColorDGVColumnHeader(WINDFANG) str_FunctionReply = strfctn_ColorDGVColumnHeader(WINDFANG) Area_Windfang.BackColor = Color.Red lbl_Zimmer.Text = "Windfang" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_EssdieleA_Click(sender As System.Object, e As System.EventArgs) Handles Area_EssdieleA.Click 'Call Subroutine_ColorDGVColumnHeader(ESSDIELE) str_FunctionReply = strfctn_ColorDGVColumnHeader(ESSDIELE) Area_EssdieleA.BackColor = Color.Red Area_EssdieleB.BackColor = Color.Red Area_EssdieleC.BackColor = Color.Red lbl_Zimmer.Text = "Essdiele" ' My.Application.DoEvents() '14429 End Sub Private Sub Area_EssdieleB_Click(sender As System.Object, e As System.EventArgs) Handles Area_EssdieleB.Click 'Call Subroutine_ColorDGVColumnHeader(ESSDIELE) str_FunctionReply = strfctn_ColorDGVColumnHeader(ESSDIELE) Area_EssdieleA.BackColor = Color.Red Area_EssdieleB.BackColor = Color.Red Area_EssdieleC.BackColor = Color.Red lbl_Zimmer.Text = "Essdiele" ' My.Application.DoEvents() '14429 End Sub Private Sub Area_EssdieleC_Click(sender As System.Object, e As System.EventArgs) Handles Area_EssdieleC.Click 'Call Subroutine_ColorDGVColumnHeader(ESSDIELE) str_FunctionReply = strfctn_ColorDGVColumnHeader(ESSDIELE) Area_EssdieleA.BackColor = Color.Red Area_EssdieleB.BackColor = Color.Red Area_EssdieleC.BackColor = Color.Red lbl_Zimmer.Text = "Essdiele" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_Kueche_Click(sender As System.Object, e As System.EventArgs) Handles Area_Kueche.Click 'Call Subroutine_ColorDGVColumnHeader(KUECHE) str_FunctionReply = strfctn_ColorDGVColumnHeader(KUECHE) Area_Kueche.BackColor = Color.Red lbl_Zimmer.Text = "Küche" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_ElternSchlafzimmmer_Click(sender As System.Object, e As System.EventArgs) Handles Area_ElternSchlafzimmer.Click 'Call Subroutine_ColorDGVColumnHeader(ELTERNSCHLAFZIMMER) str_FunctionReply = strfctn_ColorDGVColumnHeader(ELTERNSCHLAFZIMMER) Area_ElternSchlafzimmer.BackColor = Color.Red lbl_Zimmer.Text = "ElternSchlafzimmer" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_WohnzimmerSO_Click(sender As System.Object, e As System.EventArgs) Handles Area_WohnzimmerSO.Click 'Call Subroutine_ColorDGVColumnHeader(WOHNZIMMERSO) str_FunctionReply = strfctn_ColorDGVColumnHeader(WOHNZIMMERSO) Area_WohnzimmerSO.BackColor = Color.Red lbl_Zimmer.Text = "WohnzimmerSO" ' My.Application.DoEvents() '14429 End Sub Private Sub Area_WohnzimmerSW_Click(sender As System.Object, e As System.EventArgs) Handles Area_WohnzimmerSW.Click 'Call Subroutine_ColorDGVColumnHeader(WOHNZIMMERSW) str_FunctionReply = strfctn_ColorDGVColumnHeader(WOHNZIMMERSW) Area_WohnzimmerSW.BackColor = Color.Red lbl_Zimmer.Text = "WohnzimmerSW" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_Angelika_Click(sender As System.Object, e As System.EventArgs) Handles Area_Angelika.Click 'Call Subroutine_ColorDGVColumnHeader(ANGELIKA) str_FunctionReply = strfctn_ColorDGVColumnHeader(ANGELIKA) Area_Angelika.BackColor = Color.Red lbl_Zimmer.Text = "Angelika" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_Regina_Click(sender As System.Object, e As System.EventArgs) Handles Area_Regina.Click 'Call Subroutine_ColorDGVColumnHeader(REGINA) str_FunctionReply = strfctn_ColorDGVColumnHeader(REGINA) Area_Regina.BackColor = Color.Red lbl_Zimmer.Text = "Regina" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_Galerie_Click(sender As System.Object, e As System.EventArgs) Handles Area_Galerie.Click 'Call Subroutine_ColorDGVColumnHeader(GALERIE) str_FunctionReply = strfctn_ColorDGVColumnHeader(GALERIE) Area_Galerie.BackColor = Color.Red lbl_Zimmer.Text = "Galerie" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_HobbyRaum_Click(sender As System.Object, e As System.EventArgs) Handles Area_HobbyRaum.Click 'Call Subroutine_ColorDGVColumnHeader(HOBBYRAUM) str_FunctionReply = strfctn_ColorDGVColumnHeader(HOBBYRAUM) Area_HobbyRaum.BackColor = Color.Red lbl_Zimmer.Text = "HobbyRaum" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_KellerBad_Click(sender As System.Object, e As System.EventArgs) Handles Area_KellerBad.Click 'Call Subroutine_ColorDGVColumnHeader(KELLERBAD) str_FunctionReply = strfctn_ColorDGVColumnHeader(KELLERBAD) Area_KellerBad.BackColor = Color.Red lbl_Zimmer.Text = "KellerBad" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub Area_Heizungspumpe_Click(sender As System.Object, e As System.EventArgs) Handles Area_Heizungspumpe.Click 'Call Subroutine_ColorDGVColumnHeader(HEIZUNGSPUMPE) str_FunctionReply = strfctn_ColorDGVColumnHeader(HEIZUNGSPUMPE) Area_Heizungspumpe.BackColor = Color.Orange lbl_Zimmer.Text = "Heizungspumpe" ' My.Application.DoEvents() '14429 End Sub ' ##################################################################################### Private Sub btn_StorePattern_Click(sender As System.Object, e As System.EventArgs) Handles btn_StorePattern.Click Dim str_OriginalFileName As String ' Dim SFD_SaveSchedule As New SaveFileDialog() With SFD_SaveSchedule .InitialDirectory = strFilePathNameOriginal & "\" & strValveSwitchTimeFolderName .Filter = "Text File|*.txt" .Title = "Save Heating Schedule" End With Select Case SFD_SaveSchedule.ShowDialog() Case Windows.Forms.DialogResult.OK ' If the file name is not an empty string open it for saving. If SFD_SaveSchedule.FileName <> "" Then ' NOTE that the FilterIndex property is one-based. Select Case SFD_SaveSchedule.FilterIndex Case 1 Try ' clears file ! My.Computer.FileSystem.WriteAllText(SFD_SaveSchedule.FileName, "", False) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try Try ' clears default file ! My.Computer.FileSystem.WriteAllText(strDefaultValveSwitchTimeFilePathName, "", False) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try For Me.i_Eye = 0 To MAXROWINDEX Step 1 strPattern(i_Eye) = String.Empty For Me.i_Jay = 0 To MAXCOLUMNINDEX Step 1 strPattern(i_Eye) &= Convert.ToString(dgv_Display.Rows(i_Eye).Cells(i_Jay).Value) Next i_Jay If SFD_SaveSchedule.FileName <> strDefaultValveSwitchTimeFilePathName Then 'Call Subroutine_StoreInfo(SFD_SaveSchedule.FileName, strPattern(i_Eye)) str_FunctionReply = strfctn_StoreInfo(SFD_SaveSchedule.FileName, strPattern(i_Eye)) Else End If 'Call Subroutine_StoreInfo(strDefaultValveSwitchTimeFilePathName, strPattern(i_Eye)) ' Default Backup str_FunctionReply = strfctn_StoreInfo(strDefaultValveSwitchTimeFilePathName, strPattern(i_Eye)) ' Default Backup Next i_Eye If SFD_SaveSchedule.FileName <> strDefaultValveSwitchTimeFilePathName Then 'Call Subroutine_StoreInfo(SFD_SaveSchedule.FileName, "*") ' indicated end of schedule data str_FunctionReply = strfctn_StoreInfo(SFD_SaveSchedule.FileName, "*") ' indicated end of schedule data Else End If 'Call Subroutine_StoreInfo(strDefaultValveSwitchTimeFilePathName, "*") ' indicated end of schedule data and Default Backup str_FunctionReply = strfctn_StoreInfo(strDefaultValveSwitchTimeFilePathName, "*") ' indicated end of schedule data and Default Backup i_AntiSlashPosi = InStrRev(SFD_SaveSchedule.FileName, "\") str_OriginalFileName = Mid(SFD_SaveSchedule.FileName, (i_AntiSlashPosi + 1)) If SFD_SaveSchedule.FileName <> strDefaultValveSwitchTimeFilePathName Then 'Call Subroutine_StoreInfo(SFD_SaveSchedule.FileName, str_OriginalFileName) str_FunctionReply = strfctn_StoreInfo(SFD_SaveSchedule.FileName, str_OriginalFileName) Else End If 'Call Subroutine_StoreInfo(strDefaultValveSwitchTimeFilePathName, str_OriginalFileName) ' File Name of Original File str_FunctionReply = strfctn_StoreInfo(strDefaultValveSwitchTimeFilePathName, str_OriginalFileName) ' File Name of Original File txt_FileName.Text = str_OriginalFileName Case 2 Case 3 End Select Else End If Case Windows.Forms.DialogResult.Cancel MessageBox.Show("Bitte Datei wählen!", "Fehler") End Select End Sub ' ##################################################################################### ' **************************************************************************************** ' call: Subroutine_StoreInfo("Path and File", "second try") ' Path/Folder/File info to be stored ' **************************************************************************************** 'Private Sub Subroutine_StoreInfo(ByVal strFilePath As String, ByVal strInformation As String) Private Function strfctn_StoreInfo(ByVal strFilePath As String, ByVal strInformation As String) As String Dim strfileContents As String = String.Empty Try strfileContents = My.Computer.FileSystem.ReadAllText(strFilePath) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try strfileContents = strfileContents & strInformation Try My.Computer.FileSystem.WriteAllText(strFilePath, strfileContents, False) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try strfctn_StoreInfo = "strfctn_StoreInfo is done" End Function ' ########################################################### Private Sub btn_FetchPattern_Click(sender As System.Object, e As System.EventArgs) Handles btn_FetchPattern.Click 'Subroutine_FetchPattern(CInt(txt_MinuteIndex.Text)) str_FunctionReply = strfctn_FetchPattern(CInt(txt_MinuteIndex.Text)) End Sub ' ##################################################################################### 'Public Sub Subroutine_FetchPattern(ByVal i_MinuteIndex As Integer) Public Function strfctn_FetchPattern(ByVal i_MinuteIndex As Integer) As String Dim str_Pattern As String = String.Empty Dim str_Action As String = String.Empty Dim i_HalfHourIndex As Integer If i_MinuteIndex < 0 Or i_MinuteIndex > 1439 Then ' 24 hours x 60 = 1440 => 23 x 60 + 59 = 1439 txt_MinuteIndex.BackColor = Color.Red txt_MinuteIndex.ForeColor = Color.Yellow Else txt_MinuteIndex.BackColor = Color.White txt_MinuteIndex.ForeColor = Color.Black i_HalfHourIndex = i_MinuteIndex \ CInt(30) ' integer division 'Subroutine_ColorDGVRowHeader(i_HalfHourIndex + 1) str_FunctionReply = strfctn_ColorDGVRowHeader(i_HalfHourIndex + 1) str_Pattern = String.Empty For Me.i_Jay = 0 To MAXCOLUMNINDEX Step 1 Try str_Pattern &= Convert.ToString(dgv_Display.Rows(i_HalfHourIndex).Cells(i_Jay).Value) Catch ex As Exception End Try Next Me.i_Jay txt_Pattern.Text = str_Pattern End If For Me.i_Jay = 0 To MAXCOLUMNINDEX Step 1 str_Action = Mid(str_Pattern, (Me.i_Jay + 1), 1) If Me.i_Jay < MAXCOLUMNINDEX Then 'If str_Action = "O" Then Subroutine_SelectOvalShape((Me.i_Jay + 1), "40") ' Valves 'If str_Action = "I" Then Subroutine_SelectOvalShape((Me.i_Jay + 1), "570") If str_Action = "O" Then str_FunctionReply = strfctn_SelectOvalShape((Me.i_Jay + 1), "40") ' Valves If str_Action = "I" Then str_FunctionReply = strfctn_SelectOvalShape((Me.i_Jay + 1), "570") Else 'If str_Action = "O" Then Subroutine_SelectOvalShape((MAXCOLUMNINDEX + 1), "0") ' Pumps stop 'If str_Action = "I" Then Subroutine_SelectOvalShape((MAXCOLUMNINDEX + 1), "41") ' Pumps running If str_Action = "O" Then str_FunctionReply = strfctn_SelectOvalShape((MAXCOLUMNINDEX + 1), "0") ' Pumps stop If str_Action = "I" Then str_FunctionReply = strfctn_SelectOvalShape((MAXCOLUMNINDEX + 1), "41") ' Pumps running End If Next Me.i_Jay strfctn_FetchPattern = "strfctn_FetchPattern is done" End Function ' ##################################################################################### ' ##################################################################################### 'Private Sub Subroutine_ColorDGVRowHeader(ByVal i_One As Integer) Private Function strfctn_ColorDGVRowHeader(ByVal i_One As Integer) As String 'Call Subroutine_ClearRowHeaderColor() str_FunctionReply = strfctn_ClearRowHeaderColor() If i_One > 0 Then With Me.dgv_Display Dim bdStyle As New DataGridViewCellStyle bdStyle.BackColor = Color.Red Try .Rows(i_One - 1).HeaderCell.Style = bdStyle Catch ex As Exception End Try End With End If strfctn_ColorDGVRowHeader = "strfctn_ColorDGVRowHeader is done" End Function ' ##################################################################################### 'Private Sub Subroutine_ClearRowHeaderColor() Private Function strfctn_ClearRowHeaderColor() As String Dim i_Counter As Integer For i_Counter = 0 To MAXROWINDEX Step 1 With Me.dgv_Display Dim bdStyle As New DataGridViewCellStyle bdStyle.BackColor = Color.LightGray Try .Rows(i_Counter).HeaderCell.Style = bdStyle Catch ex As Exception End Try End With Next i_Counter strfctn_ClearRowHeaderColor = "strfctn_ClearRowHeaderColor is done" End Function ' ##################################################################################### Private Sub btn_ClearPattern_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClearPattern.Click 'Call Subroutine_DefinePattern("_Null_Pattern.txt") str_FunctionReply = strfctn_DefinePattern("_Null_Pattern.txt") End Sub ' **************************************************************************************** Private Sub btn_FillPattern_Click(sender As System.Object, e As System.EventArgs) Handles btn_FillPattern.Click 'Call Subroutine_DefinePattern("_Fill_Pattern.txt") str_FunctionReply = strfctn_DefinePattern("_Fill_Pattern.txt") End Sub ' **************************************************************************************** 'Private Sub Subroutine_DefinePattern(ByVal str_File_Name As String) Private Function strfctn_DefinePattern(ByVal str_File_Name As String) As String Dim str_SwitchPattern As String = String.Empty strValveSwitchTimeFilePathName = strFilePathNameOriginal & "\" & strValveSwitchTimeFolderName & "\" & str_File_Name Try str_SwitchPattern = My.Computer.FileSystem.ReadAllText(strValveSwitchTimeFilePathName) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try 'Call Subroutine_Fill_Table(str_SwitchPattern) str_FunctionReply = strfctn_Fill_Table(str_SwitchPattern) txt_FileName.Text = str_File_Name strfctn_DefinePattern = "strfctn_DefinePattern is done" End Function ' **************************************************************************************** 'Public Sub Subroutine_SelectOvalShape(ByVal i_WhichOne As Integer, ByVal str_Value As String) Public Function strfctn_SelectOvalShape(ByVal i_WhichOne As Integer, ByVal str_Value As String) As String Dim i_Setting As Integer Dim OS_Color As Color = Color.White Dim str_Test As String str_Test = "Yellow" i_Setting = CInt(str_Value) If i_WhichOne < HEIZUNGSPUMPE Then ' i.e. the other valves Try Select Case i_Setting Case Is > 600 OS_Color = Color.FromName("Gray") Case 550 To 600 ' including 600 'OS_Color = Color.FromName("Red") OS_Color = Color.Red 'FromName("Red") - these are equivalent Case 51 To 549 OS_Color = Color.FromName(str_Test) Case 0 To 50 OS_Color = Color.FromName("Blue") Case Else OS_Color = Color.FromName("Black") End Select Catch ex As Exception MessageBox.Show(ex.Message, "Fehlermeldung") End Try Else ' for the heating pump Try Select Case i_Setting Case Is > 44 OS_Color = Color.FromName("Gray") Case 6 To 44 ' including 44 OS_Color = Color.Orange 'FromName("Orange") - these are equivalent Case 1 To 5 OS_Color = Color.FromName(str_Test) Case 0 OS_Color = Color.FromName("Blue") Case Else OS_Color = Color.FromName("Black") End Select Catch ex As Exception MessageBox.Show(ex.Message, "Fehlermeldung") End Try End If Select Case i_WhichOne Case WANNENBAD OS_Wannenbad.FillColor = OS_Color Case DUSCHBAD OS_Duschbad.FillColor = OS_Color Case WINDFANG OS_Windfang.FillColor = OS_Color Case ESSDIELE OS_Essdiele.FillColor = OS_Color Case KUECHE OS_Kueche.FillColor = OS_Color Case ELTERNSCHLAFZIMMER OS_ElternSchlafzimmer.FillColor = OS_Color Case WOHNZIMMERSO OS_WohnzimmerSO.FillColor = OS_Color Case WOHNZIMMERSW OS_WohnzimmerSW.FillColor = OS_Color Case ANGELIKA OS_Angelika.FillColor = OS_Color Case REGINA OS_Regina.FillColor = OS_Color Case GALERIE OS_Galerie.FillColor = OS_Color Case HOBBYRAUM OS_HobbyRaum.FillColor = OS_Color Case KELLERBAD OS_KellerBad.FillColor = OS_Color Case HEIZUNGSPUMPE OS_Heizungspumpe.FillColor = OS_Color Case Else 'i_ClickCounter = 0 ' for testing only End Select strfctn_SelectOvalShape = "strfctn_SelectOvalShape is done" End Function ' **************************************************************************************** ' **************************************************************************************** End Class