Public Class Frm_Intro
    Public Overrides Function AcceptChanged() As Boolean

    End Function
    Public Overrides Function RejectChanged() As Boolean

    End Function
    Public Overrides Function HasChanged() As Boolean

    End Function
    Private Sub Save_SEtting()
        Myini.Write("user", "chkid", Me.chk_id.Checked)
        Myini.Write("user", "chkpass", Me.chk_pass.Checked)
        If Me.chk_id.Checked Then
            Myini.Write("user", "id", Me.tb_id.Text)
        Else
            Myini.Write("user", "id", "")
        End If
        If Me.chk_pass.Checked Then
            Myini.Write("user", "pass", Me.tb_pw.Text)
        Else
            Myini.Write("user", "pass", "")
        End If

    End Sub
    Private Sub Frm_Login_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.Escape
                Me.Close()
        End Select
    End Sub

    Private Sub Frm_Login_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'TODO: 이 코드는 데이터를 'DS.C2600' 테이블에 로드합니다. 필요한 경우 이 코드를 이동하거나 제거할 수 있습니다.
        ' Uselov = New Lov.ModLov(My.Settings.CS, "")

        Me.lbl_ip.Text = "현재  IP:" & Prj.CUrIP & "/MAC:" & Prj.CUrMac & " 컴퓨터에서 접속하였습니다."
        My.Application.DoEvents()
        '//지정된 정보를 가져옵니다.

        Try
            Me.chk_id.Checked = CBool(Myini.Read("user", "chkid", CStr(True)))
            Me.chk_pass.Checked = CBool(Myini.Read("user", "chkpass", CStr(True)))
        Catch ex As Exception
            Me.chk_id.Checked = False
            Me.chk_pass.Checked = False
        End Try

        If Me.chk_id.Checked Then Me.tb_id.Text = Myini.Read("user", "id", "")
        If Me.chk_pass.Checked Then Me.tb_pw.Text = Myini.Read("user", "pass", "")

    End Sub

    Private Function GetLevel(ByVal Dcode As String) As Short
        'im DR() As DataRow = Me.DS.tbl_user.Select("uid='" & Dcode & "'")
        'If DR Is Nothing Then Return 0 '//일반사원 반환
        'Try
        '    Return CShort(DR(0)("level"))
        'Catch ex As Exception
        '    Return 0
        'End Try
    End Function

    Private Sub tb_pw_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tb_pw.KeyDown
        If e.KeyCode = Keys.Enter Then
            '//지정된 id 와 비번으로 해당 계정이 존재하는지 확인한다.

            login()
        ElseIf e.KeyCode = Keys.Escape Then
            Me.DialogResult = Windows.Forms.DialogResult.Cancel
        End If
    End Sub

    Private Sub tb_id_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles tb_id.GotFocus, tb_pw.GotFocus
        CType(sender, TextBox).Focus()
        CType(sender, TextBox).SelectAll()
    End Sub

    Private Sub tB_id_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tb_id.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                Me.tb_pw.Focus()
            Case Keys.Escape
                Me.DialogResult = Windows.Forms.DialogResult.Cancel
        End Select
    End Sub
    Private Sub login()
        Work_msg("서버 응답을 기다리는중")
        Dim L As New ArinLogin.ArinLOgin
        Dim UseriNfo As ArinLogin.ArinLOgin.User_Info = L.Check_user("eco_user", Me.tb_id.Text, Me.tb_pw.Text)
        Work_msg("")

        Prj.Admin = False
        If UseriNfo.name = "" Then
            If Me.tb_id.Text = "guest" Then
                UseriNfo.authtype = "IP"

            Else
                MsgBox("존재하지 않는계정이거나 비밀번호오류입니다", MsgBoxStyle.Critical, "확인")
                Return
            End If

        End If
        Select Case UseriNfo.authtype
            Case "IP"
                If Me.tb_id.Text <> "guest" Then
                    If Prj.CUrIP.ToUpper <> UseriNfo.authip.ToUpper Then
                        MsgBox("로그인사용자와 현재컴퓨터의 IP가 일치하지않습니다", MsgBoxStyle.Critical, "확인")
                        Return
                    End If
                Else
                    Try
                        Dim userPass As String
                        Dim userMAC As String
                        Dim userIP As String
                        userMAC = Prj.CUrMac.GetHashCode
                        userIP = Prj.CUrIP.GetHashCode
                        userPass = userIP + userMAC
                        userPass = userPass.GetHashCode
                        If CLng(userPass) < 0 Then
                            userPass = (CLng(userPass) * -1).ToString
                        End If
                        If Me.tb_pw.Text <> userPass Then
                            MsgBox("존재하지 않는계정이거나 비밀번호오류입니다", MsgBoxStyle.Critical, "확인")
                            End
                        End If
                    Catch ex As Exception
                        MsgBox("존재하지 않는계정이거나 비밀번호오류입니다", MsgBoxStyle.Critical, "확인")
                        End
                    End Try
                End If
            Case "MAC"  '//MAC인증일경우 현재MAC과 비교한다.
                If Prj.CUrMac.ToUpper <> UseriNfo.authmac.ToUpper Then
                    MsgBox("로그인사용자와 현재컴퓨터의 MAC이 일치하지않습니다", MsgBoxStyle.Critical, "확인")
                    Return
                End If
            Case "BOTH", "BOTH1", "BOTH2" '// BOTH1, BOTH2 는 기존 일반사용자와 다른 권한 부여하기 위해 만듬. BOTH1은 가져오기 가능, BOTH2는 가져오기 + 프로파일 수정가능  2010.11.22 ---  BOTH0 은 일반유저로 설정
                If Prj.CUrIP.ToUpper <> UseriNfo.authip.ToUpper OrElse Prj.CUrMac.ToUpper <> UseriNfo.authmac.ToUpper Then
                    MsgBox("로그인사용자의 IP 또는 MAC이 일치하지 않습니다", MsgBoxStyle.Critical, "확인")
                    Return
                End If
            Case "ADMIN"
                Prj.Admin = True
            Case "BOTH0"

            Case Else
                Return

        End Select
        Prj.LoginTime = Format(Now, "yyyy-MM-dd HH:mi:ss")
        Prj.UserId = Me.tb_id.Text
        Prj.UserPass = Me.tb_pw.Text
        If Me.tb_id.Text = "guest" Then
            Prj.UserAuthType = "BOTH0"
        Else
            Prj.UserAuthType = UseriNfo.authtype
        End If

        Save_SEtting()

        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub
    'Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
    '    Dim LF As New Frm_user("")
    '    If LF.ShowDialog = Windows.Forms.DialogResult.OK Then
    '        Me.tB_id.Text = LF.UID
    '        Me.tb_pw.Text = ""
    '        Me.tb_pw.Focus()
    '    Else
    '        Me.tB_id.Text = ""
    '        Me.tb_pw.Text = ""
    '        Me.tB_id.Focus()
    '    End If
    'End Sub
    Private Sub Frm_Intro_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
        
    End Sub


    Private Sub lbl_ip_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
        Dim Str As New System.Text.StringBuilder
        Str.AppendLine("### 다음내용을 관리자에게  메일로 보내주세요 ###")
        Str.AppendLine("ip : " & Prj.CUrIP)
        Str.AppendLine("mac : " & Prj.CUrMac)
        'Str.AppendLine("lg : " & Prj.LGVersino)
        'Str.AppendLine("ui : " & Prj.UIVersion)
        My.Computer.FileSystem.WriteAllText("c:\address.txt", Str.ToString, False)
        Shell("notepad c:\address.txt", AppWinStyle.NormalFocus)
    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        login()
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        End
    End Sub

    Private Sub btn_end_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        End
    End Sub
End Class