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
    ''' 
    ''' ÆûÀ» Ç¥½ÃÇÕ´Ï´Ù.
    ''' 
    ''' 
    ''' 
    ''' 
    ''' 
    ''' 
    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
    ''' 
    ''' µ¿ÀÏÇÑ ÇÁ·Î¼¼½º°¡ Á¸ÀçÇÏ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
    ''' 
    ''' 
    ''' 
    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