Files
ECO2-OD/CEnergy/ArinClassV2/Common.vb
2018-12-09 20:18:51 +09:00

171 lines
7.1 KiB
VB.net

Imports Microsoft.Win32
Imports System.IO
Imports System.Net.NetworkInformation
Imports System.Net
Imports System.Net.Dns
Imports System.net.Mail
Imports System.Windows.Forms
Public Class ARINCLASS
Public Shared Sub SaveLoad_FrmSetting(ByVal Frm As Form, ByRef LastPos As Short, Optional ByVal Save As Boolean = False, Optional ByVal RestoreStatus As Boolean = False)
'//폼의 상태를 저장합니다.
'If Frm.FormBorderStyle <> FormBorderStyle.Sizable AndAlso Frm.FormBorderStyle <> FormBorderStyle.SizableToolWindow Then Return
Dim Width As Short
Dim Height As Short
Dim State As Short
Dim Left, Top As Short
If Save Then
Dim INI As New MyINI(My.Application.Info.DirectoryPath & "\Frm_Setting.ini")
INI.Write(Frm.Name, "state", Frm.WindowState)
INI.Write(Frm.Name, "width", Frm.Width)
INI.Write(Frm.Name, "height", Frm.Height)
INI.Write(Frm.Name, "left", Frm.Left)
INI.Write(Frm.Name, "top", Frm.Top)
INI.Write(Frm.Name, "LastPos", LastPos)
Else
Dim INI As New MyINI(My.Application.Info.DirectoryPath & "\Frm_Setting.ini")
If Frm.WindowState = FormWindowState.Normal Then
Width = INI.Read(Frm.Name, "width", 0)
Height = INI.Read(Frm.Name, "height", 0)
State = INI.Read(Frm.Name, "state", -1)
Left = INI.Read(Frm.Name, "left", 0)
Top = INI.Read(Frm.Name, "top", 0)
LastPos = INI.Read(Frm.Name, "LastPos", 0)
If Width <> 0 Then Frm.Width = Width
If Height <> 0 Then Frm.Height = Height
If RestoreStatus Then If State <> -1 Then Frm.WindowState = State
If Left <> 0 Then Frm.Left = Left
If Top <> 0 Then Frm.Top = Top
End If
End If
End Sub
Public Shared Function Read_LastPos_Frm(ByVal Frm As Form) As Short
'//폼의 상태를 저장합니다.
'If Frm.FormBorderStyle <> FormBorderStyle.Sizable AndAlso Frm.FormBorderStyle <> FormBorderStyle.SizableToolWindow Then Return
Dim INI As New MyINI(My.Application.Info.DirectoryPath & "\Frm_Setting.ini")
Return INI.Read(Frm.Name, "LastPos", 0)
End Function
Public Shared Function Read_LastPos_Frm(ByVal FrmName As String) As Short
'//폼의 상태를 저장합니다.
'If Frm.FormBorderStyle <> FormBorderStyle.Sizable AndAlso Frm.FormBorderStyle <> FormBorderStyle.SizableToolWindow Then Return
Dim INI As New MyINI(My.Application.Info.DirectoryPath & "\Frm_Setting.ini")
Return INI.Read(FrmName, "LastPos", 0)
End Function
Public Shared Sub Save_LastPos_Frm(ByVal FrmName As String, ByVal LastPos As Short)
'//폼의 상태를 저장합니다.
'If Frm.FormBorderStyle <> FormBorderStyle.Sizable AndAlso Frm.FormBorderStyle <> FormBorderStyle.SizableToolWindow Then Return
Dim INI As New MyINI(My.Application.Info.DirectoryPath & "\Frm_Setting.ini")
INI.Write(FrmName, "LastPos", LastPos)
End Sub
Public Shared Function Read_LastZone(ByVal FrmName As String) As String
'//폼의 상태를 저장합니다.
'If Frm.FormBorderStyle <> FormBorderStyle.Sizable AndAlso Frm.FormBorderStyle <> FormBorderStyle.SizableToolWindow Then Return
Dim INI As New MyINI(My.Application.Info.DirectoryPath & "\Frm_Setting.ini")
Return INI.Read(FrmName, "LastZone", "")
End Function
Public Shared Sub Save_LastZone(ByVal FrmName As String, ByVal LastPos As String)
'//폼의 상태를 저장합니다.
'If Frm.FormBorderStyle <> FormBorderStyle.Sizable AndAlso Frm.FormBorderStyle <> FormBorderStyle.SizableToolWindow Then Return
Dim INI As New MyINI(My.Application.Info.DirectoryPath & "\Frm_Setting.ini")
INI.Write(FrmName, "LastZone", LastPos)
End Sub
Public Shared Sub NOTICE(ByVal MSG As String, ByVal Src As Object)
On Error Resume Next
If Src.GetType.Name.ToUpper = "TOOLSTRIPSTATUSLABEL" Then
CType(Src, Windows.Forms.ToolStripStatusLabel).Text = "" & MSG & Space(1)
ElseIf Src.GetType.Name.ToUpper = "LABEL" Then
CType(Src, Windows.Forms.Label).Text = "" & MSG & Space(1)
End If
End Sub
Public Shared Sub NOTICE(ByVal MSG As String, ByVal FCOLOR As Drawing.Color, ByVal Src As Windows.Forms.ToolStripStatusLabel)
Src.Text = "" & MSG & Space(1)
Src.ForeColor = FCOLOR
End Sub
Public Shared Sub NOTICE(ByVal MSG As String, ByVal Src As Windows.Forms.ToolStripStatusLabel, ByVal FCOLOR As Drawing.Color)
Src.Text = "" & MSG & Space(1) & "[" & Format(Now, "HH시mm분ss초") & "]"
Src.ForeColor = FCOLOR
If FCOLOR = Drawing.Color.Red Then My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
End Sub
''' <summary>
''' 폼을 표시합니다.
''' </summary>
''' <param name="fForm"></param>
''' <param name="MdiMainForm"></param>
''' <param name="MODALFORM"></param>
''' <param name="Fstate"></param>
''' <remarks></remarks>
Public Shared Sub ShowForm(ByVal fForm As System.Windows.Forms.Form, ByVal MdiMainForm As System.Windows.Forms.Form, Optional ByVal MODALFORM As Boolean = False, Optional ByVal Fstate As System.Windows.Forms.FormWindowState = System.Windows.Forms.FormWindowState.Normal)
Dim objForms As System.Windows.Forms.Form
Dim ALREADY As Boolean = False
If MdiMainForm Is Nothing Then
If MODALFORM Then
fForm.ShowDialog()
Else
fForm.Show()
End If
fForm.Activate()
Return
End If
Try
For Each objForms In MdiMainForm.MdiChildren
If objForms.Name = fForm.Name Then
ALREADY = True
'fForm.Dispose()
'fForm = Nothing
objForms.Focus()
Return
End If
Next
Catch ex As Exception
End Try
If ALREADY = False Then
With fForm
If MdiMainForm Is Nothing Then
MsgBox("MDI 부모폼이 존재하지않습니다", MsgBoxStyle.Critical, "error")
Else
If Not MdiMainForm Is Nothing Then
.MdiParent = MdiMainForm
'.StartPosition = FormStartPosition.CenterParent
End If
.WindowState = Fstate
If MODALFORM Then
.ShowDialog()
Else
.Show()
End If
End If
End With
End If
End Sub
''' <summary>
''' 동일한 프로세스가 존재하는지 확인합니다.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function PrevInstance() As Boolean
If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function
End Class