You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

513 lines
18 KiB

Imports System.Data.SqlClient
Imports System.IO
Imports DataAccess
Imports Common
Public Class MainForm
Inherits System.Windows.Forms.Form
#Region " Vom Windows Form Designer generierter Code "
Public Sub New()
MyBase.New()
' Dieser Aufruf ist für den Windows Form-Designer erforderlich.
InitializeComponent()
' Initialisierungen nach dem Aufruf InitializeComponent() hinzufügen
End Sub
' Die Form überschreibt den Löschvorgang der Basisklasse, um Komponenten zu bereinigen.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' Für Windows Form-Designer erforderlich
Private components As System.ComponentModel.IContainer
'HINWEIS: Die folgende Prozedur ist für den Windows Form-Designer erforderlich
'Sie kann mit dem Windows Form-Designer modifiziert werden.
'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents lblEDKB02State As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents txtNextStartDate As System.Windows.Forms.TextBox
Friend WithEvents cmdSet As System.Windows.Forms.Button
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents lblReturnFile As System.Windows.Forms.Label
Friend WithEvents txtFileCount As System.Windows.Forms.TextBox
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents chkCleanReturn As System.Windows.Forms.CheckBox
Friend WithEvents chkCleanFileCount As System.Windows.Forms.CheckBox
Friend WithEvents chkNextStart As System.Windows.Forms.CheckBox
Friend WithEvents chkSetIsRunning As System.Windows.Forms.CheckBox
Friend WithEvents cmdRefresh As System.Windows.Forms.Button
Friend WithEvents lblProcessState As System.Windows.Forms.Label
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents chkKillWord As System.Windows.Forms.CheckBox
Friend WithEvents chkKillEDBK02 As System.Windows.Forms.CheckBox
Friend WithEvents Label6 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(MainForm))
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.lblEDKB02State = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.txtNextStartDate = New System.Windows.Forms.TextBox
Me.cmdSet = New System.Windows.Forms.Button
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.lblReturnFile = New System.Windows.Forms.Label
Me.txtFileCount = New System.Windows.Forms.TextBox
Me.chkCleanReturn = New System.Windows.Forms.CheckBox
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.chkCleanFileCount = New System.Windows.Forms.CheckBox
Me.chkNextStart = New System.Windows.Forms.CheckBox
Me.chkSetIsRunning = New System.Windows.Forms.CheckBox
Me.cmdRefresh = New System.Windows.Forms.Button
Me.lblProcessState = New System.Windows.Forms.Label
Me.Label9 = New System.Windows.Forms.Label
Me.chkKillWord = New System.Windows.Forms.CheckBox
Me.chkKillEDBK02 = New System.Windows.Forms.CheckBox
Me.Label6 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 0
Me.Label1.Text = "Allgemein"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(24, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(432, 40)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Mit Hilfe dieses Tools, können die Batch Parameter für den EDKB02 angepasst werde" & _
"n. Bitte beachten Sie, dass bei falscher Benutzung möglicherweise Mails an die S" & _
"ystemverantwortlichen ausgelöst werden."
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(8, 80)
Me.Label3.Name = "Label3"
Me.Label3.TabIndex = 2
Me.Label3.Text = "Status"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(24, 112)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(80, 16)
Me.Label4.TabIndex = 3
Me.Label4.Text = "Datenbank:"
'
'lblEDKB02State
'
Me.lblEDKB02State.Location = New System.Drawing.Point(120, 112)
Me.lblEDKB02State.Name = "lblEDKB02State"
Me.lblEDKB02State.Size = New System.Drawing.Size(376, 16)
Me.lblEDKB02State.TabIndex = 4
Me.lblEDKB02State.Text = "lblDBState"
'
'Label5
'
Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label5.Location = New System.Drawing.Point(8, 280)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(192, 23)
Me.Label5.TabIndex = 12
Me.Label5.Text = "Zurücksetzen"
'
'txtNextStartDate
'
Me.txtNextStartDate.Location = New System.Drawing.Point(192, 312)
Me.txtNextStartDate.Name = "txtNextStartDate"
Me.txtNextStartDate.Size = New System.Drawing.Size(136, 20)
Me.txtNextStartDate.TabIndex = 14
Me.txtNextStartDate.Text = ""
'
'cmdSet
'
Me.cmdSet.Location = New System.Drawing.Point(416, 496)
Me.cmdSet.Name = "cmdSet"
Me.cmdSet.Size = New System.Drawing.Size(80, 23)
Me.cmdSet.TabIndex = 21
Me.cmdSet.Text = "&Setzen"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(24, 184)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(80, 16)
Me.Label7.TabIndex = 9
Me.Label7.Text = "FileCount.txt:"
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(24, 168)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(80, 16)
Me.Label8.TabIndex = 7
Me.Label8.Text = "Return.txt:"
'
'lblReturnFile
'
Me.lblReturnFile.Location = New System.Drawing.Point(120, 168)
Me.lblReturnFile.Name = "lblReturnFile"
Me.lblReturnFile.Size = New System.Drawing.Size(376, 16)
Me.lblReturnFile.TabIndex = 8
Me.lblReturnFile.Text = "lblReturnFile"
'
'txtFileCount
'
Me.txtFileCount.BackColor = System.Drawing.SystemColors.Control
Me.txtFileCount.Location = New System.Drawing.Point(120, 184)
Me.txtFileCount.Multiline = True
Me.txtFileCount.Name = "txtFileCount"
Me.txtFileCount.ReadOnly = True
Me.txtFileCount.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtFileCount.Size = New System.Drawing.Size(288, 80)
Me.txtFileCount.TabIndex = 10
Me.txtFileCount.Text = ""
'
'chkCleanReturn
'
Me.chkCleanReturn.Checked = True
Me.chkCleanReturn.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkCleanReturn.Location = New System.Drawing.Point(24, 368)
Me.chkCleanReturn.Name = "chkCleanReturn"
Me.chkCleanReturn.Size = New System.Drawing.Size(384, 24)
Me.chkCleanReturn.TabIndex = 16
Me.chkCleanReturn.Text = "Return.txt auf ""0"" setzen"
'
'PictureBox1
'
Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
Me.PictureBox1.Location = New System.Drawing.Point(464, 8)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(32, 32)
Me.PictureBox1.TabIndex = 14
Me.PictureBox1.TabStop = False
'
'chkCleanFileCount
'
Me.chkCleanFileCount.Checked = True
Me.chkCleanFileCount.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkCleanFileCount.Location = New System.Drawing.Point(24, 392)
Me.chkCleanFileCount.Name = "chkCleanFileCount"
Me.chkCleanFileCount.Size = New System.Drawing.Size(384, 24)
Me.chkCleanFileCount.TabIndex = 17
Me.chkCleanFileCount.Text = "FileCount.txt leeren"
'
'chkNextStart
'
Me.chkNextStart.Checked = True
Me.chkNextStart.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkNextStart.Location = New System.Drawing.Point(24, 312)
Me.chkNextStart.Name = "chkNextStart"
Me.chkNextStart.Size = New System.Drawing.Size(168, 24)
Me.chkNextStart.TabIndex = 13
Me.chkNextStart.Text = "Nächster Start setzen auf:"
'
'chkSetIsRunning
'
Me.chkSetIsRunning.Checked = True
Me.chkSetIsRunning.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkSetIsRunning.Location = New System.Drawing.Point(24, 336)
Me.chkSetIsRunning.Name = "chkSetIsRunning"
Me.chkSetIsRunning.Size = New System.Drawing.Size(456, 24)
Me.chkSetIsRunning.TabIndex = 15
Me.chkSetIsRunning.Text = "IsRunning(läuft) auf 0 (bereit zum Starten) setzen"
'
'cmdRefresh
'
Me.cmdRefresh.Location = New System.Drawing.Point(416, 240)
Me.cmdRefresh.Name = "cmdRefresh"
Me.cmdRefresh.Size = New System.Drawing.Size(80, 23)
Me.cmdRefresh.TabIndex = 11
Me.cmdRefresh.Text = "&Aktualisieren"
'
'lblProcessState
'
Me.lblProcessState.Location = New System.Drawing.Point(120, 128)
Me.lblProcessState.Name = "lblProcessState"
Me.lblProcessState.Size = New System.Drawing.Size(376, 16)
Me.lblProcessState.TabIndex = 6
Me.lblProcessState.Text = "lblProcessState"
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(24, 128)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(80, 16)
Me.Label9.TabIndex = 5
Me.Label9.Text = "Prozess:"
'
'chkKillWord
'
Me.chkKillWord.Location = New System.Drawing.Point(24, 424)
Me.chkKillWord.Name = "chkKillWord"
Me.chkKillWord.Size = New System.Drawing.Size(384, 24)
Me.chkKillWord.TabIndex = 18
Me.chkKillWord.Text = "Alle Word Prozesse abrupt beenden (KILL)"
'
'chkKillEDBK02
'
Me.chkKillEDBK02.Location = New System.Drawing.Point(24, 496)
Me.chkKillEDBK02.Name = "chkKillEDBK02"
Me.chkKillEDBK02.Size = New System.Drawing.Size(384, 24)
Me.chkKillEDBK02.TabIndex = 20
Me.chkKillEDBK02.Text = "EDKB02 Prozess abrupt beenden (KILL)"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(64, 448)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(344, 40)
Me.Label6.TabIndex = 19
Me.Label6.Text = "Bitte beachten Sie, dass bei dieser Option ALLE Word Prozesse auf dieser Maschine" & _
" beendet werden. Dies kann möglicherweise zu Problemen führen."
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(506, 528)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.chkKillEDBK02)
Me.Controls.Add(Me.chkKillWord)
Me.Controls.Add(Me.lblProcessState)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.cmdRefresh)
Me.Controls.Add(Me.chkSetIsRunning)
Me.Controls.Add(Me.chkNextStart)
Me.Controls.Add(Me.chkCleanFileCount)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.chkCleanReturn)
Me.Controls.Add(Me.txtFileCount)
Me.Controls.Add(Me.lblReturnFile)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.cmdSet)
Me.Controls.Add(Me.txtNextStartDate)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.lblEDKB02State)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "MainForm"
Me.Text = "EDKB02 - Batch Status"
Me.ResumeLayout(False)
End Sub
#End Region
#Region "Members"
Dim _settings As New Common.Settings
#End Region
#Region "Private methods"
Private Sub LoadData()
Try
Dim isRunning As Boolean
Dim dsEDKB02 As New DataSet
Dim edkb02 As New Process
Dim sqlCom As New SqlCommand
Dim sqlConn As New SqlConnection(_settings.GetDecryptedDSN())
Dim da As New SqlDataAdapter
'get process informations
Dim edkb02s() As System.Diagnostics.Process = Process.GetProcessesByName(_settings.GetSettingValue("EDKB02ProcessName"))
If edkb02s.Length > 0 Then
edkb02 = edkb02s(0)
Else
edkb02 = Nothing
End If
'Get state for batch from db
sqlConn.Open()
sqlCom.CommandText = "SELECT * FROM Jobs WHERE JobId = " & _settings.GetSettingValue("JobId")
sqlCom.Connection = sqlConn
da.SelectCommand = sqlCom
da.Fill(dsEDKB02)
If dsEDKB02.Tables.Count > 0 Then
If dsEDKB02.Tables(0).Rows.Count > 0 Then
Dim row As DataRow = dsEDKB02.Tables(0).Rows(0)
'check is running for edkb02
isRunning = CBool(DataAccess.Job.CheckIsRunning(_settings.GetDecryptedDSN(), _settings.GetSettingValue("ProgramId")))
If (isRunning) Then
lblEDKB02State.Text = "Läuft zur Zeit (seit " & row("LastRunStart") & ")"
Else
lblEDKB02State.Text = "Bereit"
End If
'set next startdate
Dim oldDate As DateTime = CDate(row("NextStartDate"))
Dim nextStartDate As New DateTime(oldDate.Year, oldDate.Month, oldDate.Day, oldDate.Hour + 1, 0, 0)
txtNextStartDate.Text = nextStartDate
Else
MsgBox("Der Job EDKB02 konnte nicht geladen werden")
End If
Else
MsgBox("Der Job EDKB02 konnte nicht geladen werden")
End If
'get state for batch by process info
If Not edkb02 Is Nothing Then
If edkb02.Responding Then
lblProcessState.Text = "Läuft und antwortet"
Else
lblProcessState.Text = "Läuft, aber antwortet nicht"
End If
Else
lblProcessState.Text = "Läuft nicht"
End If
'read return.txt file
Dim returnFile As New StreamReader(CStr(_settings.GetSettingValue("ReturnFilePath")))
lblReturnFile.Text = returnFile.ReadLine()
returnFile.Close()
'read filecount.txt file
Dim fileCountFile As New StreamReader(CStr(_settings.GetSettingValue("FileCountPath")))
txtFileCount.Text = fileCountFile.ReadToEnd()
fileCountFile.Close()
Catch ex As Exception
'damn ><
Throw ex
End Try
End Sub
#End Region
#Region "Event handlers"
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
LoadData()
Catch ex As Exception
MsgBox("Beim Starten ist ein Fehler aufgetreten" & vbCrLf & vbCrLf & ex.Message & vbCrLf & ex.StackTrace, MsgBoxStyle.Critical, "Fehler beim Start")
Close()
End Try
End Sub
Private Sub cmdSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSet.Click
Try
cmdSet.Enabled = False
If chkNextStart.Checked Then
Dim nextStartDate As New DateTime
nextStartDate = CDate(txtNextStartDate.Text)
'set next execution time
Dim sqlCom As New SqlCommand
Dim sqlConn As New SqlConnection(_settings.GetDecryptedDSN())
sqlConn.Open()
sqlCom.CommandText = "UPDATE Jobs SET NextStartDate = CONVERT(DATETIME, '" & nextStartDate & "') WHERE JobId = " & _settings.GetSettingValue("JobId")
sqlCom.Connection = sqlConn
sqlCom.ExecuteNonQuery()
DataAccess.Job.SetNextStartDateCalculated(_settings.GetDecryptedDSN(), _settings.GetSettingValue("JobId"), True)
End If
If chkSetIsRunning.Checked Then
'reset is running
DataAccess.Job.SetIsRunning(_settings.GetDecryptedDSN(), _settings.GetSettingValue("ProgramId"), False)
End If
If chkCleanFileCount.Checked Then
'reset filecount.txt file
Dim fileCountFile As New StreamWriter(CStr(_settings.GetSettingValue("FileCountPath")))
fileCountFile.Write("")
fileCountFile.Close()
End If
If chkCleanReturn.Checked Then
'reset return.txt file
Dim returnFile As New StreamWriter(CStr(_settings.GetSettingValue("ReturnFilePath")))
returnFile.Write("0")
returnFile.Close()
End If
'kill word processes
If chkKillWord.Checked Then
Dim words() As System.Diagnostics.Process = Process.GetProcessesByName(_settings.GetSettingValue("WordProcessName"))
Dim word As Process
For Each word In words
word.Kill()
Next
End If
'kill edkb02 processes
If chkKillEDBK02.Checked Then
Dim edkb02s() As System.Diagnostics.Process = Process.GetProcessesByName(_settings.GetSettingValue("EDKB02ProcessName"))
Dim edkb02 As Process
For Each edkb02 In edkb02s
edkb02.Kill()
Next
End If
'refresh ui
LoadData()
Catch ex As Exception
MsgBox("Beim Speichern ist ein Fehler aufgetreten" & vbCrLf & vbCrLf & ex.Message & vbCrLf & ex.StackTrace, MsgBoxStyle.Critical, "Fehler beim Speichern")
Finally
cmdSet.Enabled = True
End Try
End Sub
Private Sub chkNextStart_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNextStart.CheckedChanged
If chkNextStart.Checked Then
txtNextStartDate.ReadOnly = False
Else
txtNextStartDate.ReadOnly = True
End If
End Sub
Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
Try
LoadData()
Catch ex As Exception
MsgBox("Beim Aktualisieren ist ein Fehler aufgetreten" & vbCrLf & vbCrLf & ex.Message & vbCrLf & ex.StackTrace, MsgBoxStyle.Critical, "Fehler beim Start")
End Try
End Sub
#End Region
End Class