Author Topic: The new ReportingD  (Read 2754 times)

abdala

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
The new ReportingD
« on: September 12, 2016, 07:44:43 AM »
Code: [Select]
Public Class ReportingD
    Inherits DataSubscriber2

    Private sw As System.IO.StreamWriter
    Private Sev As Boolean
    Private intCunt As Integer
    Private FullPaket As New List(Of String)
#Region "Properties"

    Private m_FileFolder As String = "C:"
    <BrowsableAttribute(True), EditorAttribute(GetType(FileFolderEditor), GetType(System.Drawing.Design.UITypeEditor))> _
    Public Property FileFolder As String
        Get
            Return m_FileFolder
        End Get
        Set(ByVal value As String)
            If value.Length > 0 Then
                '* Remove the last back slash if it is there
                If value.Substring(value.Length - 1, 1) = "\" Then value = value.Substring(0, value.Length - 1)
                m_FileFolder = value
            End If
        End Set
    End Property

    Private m_FileName As String = "PLCDataLog.log"
    Public Property FileName As String
        Get
            Return m_FileName
        End Get
        Set(ByVal value As String)
            If m_FileName <> value Then
                m_FileName = value
                If sw IsNot Nothing Then
                    sw.Dispose()
                    sw = New System.IO.StreamWriter(m_FileFolder & "\" & m_FileName, True)
                End If
            End If
        End Set
    End Property

    Public Enum TriggerType

        DataChange


    End Enum
    Private m_LogTriggerType As TriggerType
    Public Property LogTriggerType As TriggerType
        Get
            Return m_LogTriggerType
        End Get
        Set(ByVal value As TriggerType)
            m_LogTriggerType = value
        End Set
    End Property


    Private m_MaximumPoints As Integer
    Public Property MaximumPoints As Integer
        Get
            Return m_MaximumPoints
        End Get
        Set(ByVal value As Integer)
            m_MaximumPoints = value
        End Set
    End Property
#End Region

#Region "Constructor/Destructor"
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       
        MyBase.Dispose(disposing)
    End Sub
#End Region

#Region "Events"
    Private PointCount As Integer
    Protected Overrides Sub onDataChanged(ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        MyBase.OnDataChanged(e)
        If e.PlcAddress = "00001" Then
            Sev = CBool(e.Values(0))
           
        End If
 
        If m_LogTriggerType = TriggerType.DataChange Then
            If m_MaximumPoints = 0 OrElse PointCount < m_MaximumPoints And Sev = True Then
                StoreValue()
                PointCount += 1
            End If
        End If
    End Sub

   

   
    Public Sub insert_DateBase()
        Dim x As Integer

        Dim dt As DataTable = db.GetRecors("select * from BatchFinal")
        x = dt.Rows.Count + 1
        db.InsertBatchFinal(x, CStr(FullPaket(0).ToString), CDbl(FullPaket(1).ToString), CDbl(FullPaket(2).ToString), CDbl(FullPaket(3).ToString), CDbl(FullPaket(4).ToString), CDbl(FullPaket(5).ToString), CDbl(FullPaket(6).ToString), CDbl(FullPaket(7).ToString), CDbl(FullPaket(8).ToString), CStr(1), StringToWrite2)
    End Sub
    Dim StringToWrite2 As String
    Private Sub StoreValue()
        Try


            StringToWrite2 = Date.Now

            FullPaket.Clear()


            For Each item In PLCAddressValueItems
                If item.ScaleFactor = 1 Then

                    FullPaket.Add(item.LastValue)
                Else
                    Try

                    Catch ex As Exception

                    End Try
                End If
            Next

            If Sev = True Then
                intCunt = 1
                If intCunt = 1 Then
                    insert_DateBase()
                    FullPaket.Clear()
                End If
                Sev = False
                intCunt = 0
            Else
                Sev = False
                intCunt = 0
            End If


        Catch
        End Try
    End Sub
#End Region

Public Sub InsertBatchFinal(ByVal BatchID As Integer, ByVal BatchName As String, ByVal Tank1 As Double, ByVal Tank2 As Double, ByVal Tank3 As Double, ByVal Tank4 As Double, ByVal Tank5 As Double, ByVal Tank6 As Double, ByVal Tank7 As Double, ByVal Tank8 As Double, ByVal Works As String, ByVal Dates As String)
        Dim sqlstr As String = "INSERT INTO BatchFinal (BatchID, BatchName, Tank1, Tank2, Tank3, Tank4, Tank5, Tank6, Tank7, Tank8, [Work], [Date])VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)"
        Dim cmd As New OleDbCommand(sqlstr, conn)
        cmd.Parameters.AddWithValue("@BatchID", OleDbType.VarChar).Value = BatchID
        cmd.Parameters.AddWithValue("@BatchName", OleDbType.VarChar).Value = BatchName
        cmd.Parameters.AddWithValue("@Tank1", OleDbType.Double).Value = Tank1
        cmd.Parameters.AddWithValue("@Tank2", OleDbType.Double).Value = Tank2
        cmd.Parameters.AddWithValue("@Tank3", OleDbType.Double).Value = Tank3
        cmd.Parameters.AddWithValue("@Tank4", OleDbType.Double).Value = Tank4
        cmd.Parameters.AddWithValue("@Tank5", OleDbType.Double).Value = Tank5
        cmd.Parameters.AddWithValue("@Tank6", OleDbType.Double).Value = Tank6
        cmd.Parameters.AddWithValue("@Tank7", OleDbType.Double).Value = Tank7
        cmd.Parameters.AddWithValue("@Tank8", OleDbType.Double).Value = Tank8
        cmd.Parameters.AddWithValue("@[Work]", OleDbType.VarChar).Value = Works
        cmd.Parameters.AddWithValue("@[Date]", OleDbType.VarChar).Value = Dates

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
    End Sub

End Class



« Last Edit: September 12, 2016, 07:46:46 AM by abdala »