Public Class Frm_1_Basic
    Dim DT지역중분류 As DataTable
    Dim init As Boolean = False

    Public Overrides Function AcceptChanged() As Boolean
        Me.bs.EndEdit()

        Dim drv As DataRowView = bs.Current
        If drv Is Nothing Then Return True

        If Me.cmbArea2.SelectedValue Is Nothing OrElse Me.cmbArea1.SelectedValue Is Nothing Then
            MsgBox("지역이 선택되지 않았습니다" + vbCrLf + "계산작업을 위해서는 지역이 선택되어야 합니다", MsgBoxStyle.Critical, "확인")
            drv("buildarea") = "0"
        Else
            drv("buildarea") = Me.cmbArea2.SelectedValue.ToString
        End If

         Me.bs.EndEdit()
        Return True
    End Function

    Private Sub MdiMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.bs.EndEdit()
        CEnergy.ARINCLASS.SaveLoad_FrmSetting(Me, Me.bs.Position, True)
    End Sub

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

    Private Sub MdiMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        init = False

        '//지역중분류값을 업데이트한다
        bsArea1.DataSource = DSET1
        bsArea1.DataMember = "weather_group"
        bsArea2.DataSource = DSET1
        bsArea2.DataMember = "weather_group"

        cmbArea1.DataSource = bsArea1
        cmbArea2.DataSource = bsArea2

        cmbArea1.DisplayMember = "name"
        cmbArea1.ValueMember = "code"
        bsArea1.Filter = "code like '%0000'"

        cmbArea2.DisplayMember = "name"
        cmbArea2.ValueMember = "code"
        bsArea2.Filter = "code ='test'"

        Me.bs.DataSource = DSET1.tbl_Desc
        If Me.bs.Count = 0 Then bs.AddNew()
        bs.EndEdit()

        Binding_Zone()
        init = True
        Try
            Me.bs.Position = CEnergy.ARINCLASS.Read_LastPos_Frm(Me)
        Catch ex As Exception
            Me.bs.MoveFirst()
        End Try

        지역코드설정()

        If Pub.Program = EProgram.친환경평가 Then
            Label10.Text = "면허번호"
            TextBox1.Enabled = True
            Label29.Enabled = True
        Else
            Label10.Text = "자격번호"
            TextBox1.Enabled = False
            Label29.Enabled = False
        End If

        Me.Show()
        Application.DoEvents()



    End Sub

    'Private Sub Frm_Intro_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    '    '//판넬1을 항상 중앙에 위치하도록
    '    If Not (Me.MdiParent Is Nothing) Then
    '        Me.Left = CInt((Me.MdiParent.ClientRectangle.Width - Me.Width) / 2)
    '        Me.Top = CInt((Me.MdiParent.ClientRectangle.Height - Me.Height) / 2)
    '    End If

    'End Sub

    'Private Sub Frm_1_Basic_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    '    '//판넬1을 항상 중앙에 위치하도록
    '    If Not (Me.MdiParent Is Nothing) Then
    '        Me.Left = CInt((Me.MdiParent.ClientRectangle.Width - Me.Width) / 2)
    '        Me.Top = CInt((Me.MdiParent.ClientRectangle.Height - Me.Height) / 2)
    '    End If

    'End Sub

    Private Sub Binding_Zone()
        'Dim bs_cmb_공조방식 As New BindingSource(DSET1, "tbl_weather")
        'Me.cmb_location.DataSource = bs_cmb_공조방식
        'cmb_location.DisplayMember = "건물위치"
        'cmb_location.ValueMember = "code"
        'Me.cmb_location.DataBindings.Add("selectedvalue", Me.bs, "buildarea")
        'AddHandler cmb_location.KeyDown, AddressOf Cmb_DeleteVal
    End Sub
    Private Sub Cmb_DeleteVal(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Delete Then
            CType(sender, ComboBox).SelectedValue = ""
        End If
    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
        Dim L As String = Me.cmbArea2.SelectedValue
        If MsgBox("공용코드값을 서버로부터 가져오시겠습니까?", MsgBoxStyle.Information Or MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then Read_CommonCode_OD()
        Me.cmbArea2.SelectedValue = L
        Me.bs.EndEdit()
    End Sub

    Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
        Dim L As String = Me.cmbArea2.SelectedValue
        If MsgBox("기상데이터값을 서버로부터 가져오시겠습니까?", MsgBoxStyle.Information Or MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then Read_WeatherData_OD()
        Me.cmbArea2.SelectedValue = L
        Me.bs.EndEdit()
    End Sub

    Dim 변경암함_세부지역 As Boolean = False

    Private Sub CmbArea1_SelectedIndexChanged_1(sender As System.Object, e As System.EventArgs) Handles cmbArea1.SelectedIndexChanged
        If init = False Then Return '//초기화전이면 수행안함
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return


        '//지역그룹선택을 바꾼다면 해당 지역에 맞도록 우측을 갱신해줘야한다
        If 변경암함_세부지역 Then Return '//순환참조방지
        If Me.cmbArea1.SelectedIndex < 0 OrElse cmbArea1.Text = "없음" OrElse cmbArea1.SelectedValue.ToString() = "00" Then
            Me.cmbArea2.SelectedIndex = -1
        Else
            Dim codeHeader As String = cmbArea1.SelectedValue.ToString().Substring(0, 2)
            bsArea2.Filter = String.Format("code like '{0}%' and code not like '%0000' and code like '%00'", codeHeader)
            If (cmbArea2.Items.Count > 0) Then
                cmbArea2.SelectedIndex = 0
            Else
                cmbArea2.SelectedIndex = -1
            End If

            If cmbArea1.SelectedIndex >= 0 Then
                drv("buildarea") = cmbArea1.SelectedValue.ToString()
                drv.EndEdit()
            End If

        End If
    End Sub

    Private Sub CmbArea2_SelectedIndexChanged_1(sender As System.Object, e As System.EventArgs) Handles cmbArea2.SelectedIndexChanged
        If init = False Then Return '//초기화전이면 수행안함
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return

        '//지역그룹선택을 바꾼다면 해당 지역에 맞도록 우측을 갱신해줘야한다
        If 변경암함_세부지역 Then Return '//순환참조방지
        If Me.cmbArea2.SelectedIndex < 0 OrElse cmbArea2.Text = "없음" OrElse cmbArea2.SelectedValue.ToString() = "00" Then
            'Me.cmbArea3.SelectedIndex = -1
        Else
            Dim codeHeader As String = cmbArea2.SelectedValue.ToString().Substring(0, 4)
            'bsArea3.Filter = String.Format("code like '{0}%' and code not like '%00'", codeHeader)
            'cmbArea3.SelectedIndex = -1

            If cmbArea2.SelectedIndex >= 0 Then
                drv("buildarea") = cmbArea2.SelectedValue.ToString()
                drv.EndEdit()
            End If

        End If
    End Sub


    Private Sub Bs_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs.CurrentChanged
        If init = False Then Return '//초기화전이면 수행안함

        Me.bs.EndEdit()
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return

        If drv("민간구분").ToString = "0" Then
            Me.RadioButton1.Checked = True
        Else
            Me.RadioButton2.Checked = True
        End If

        지역코드설정()
    End Sub

    Private Sub 지역코드설정()
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return

        '//지역코드에는 Weather_Group의 코드값이 들어있다.
        Dim 지역코드 As String = drv("buildarea").ToString
        If 지역코드 <> "" AndAlso 지역코드 <> "0" AndAlso 지역코드 <> "00" AndAlso 지역코드.Length = 6 Then

            변경암함_세부지역 = True

            '//Dep 1
            Dim codeHeader As String = 지역코드.Substring(0, 2)
            bsArea2.Filter = String.Format("code like '{0}%' and code not like '%0000' and code like '%00'", codeHeader)
            Me.cmbArea1.SelectedValue = codeHeader + "0000"   '//선택해줌   

            codeHeader = 지역코드.Substring(0, 4)
            'bsArea3.Filter = String.Format("code like '{0}%' and code not like '%00'", codeHeader)
            Me.cmbArea2.SelectedValue = codeHeader + "00"

            'Me.cmbArea3.SelectedValue = 지역코드

            '//찾은 중분류코드에맞는 중분류를 자동 선택해준다.
            변경암함_세부지역 = False
        Else
            bsArea1.Filter = "code like '%0000'"
            bsArea2.Filter = "code='test'"
            'bsArea3.Filter = "code='test'"
        End If
    End Sub

    Private Sub Bs_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bs.CurrentItemChanged
        Try
            Me.bs.EndEdit()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return
        If RadioButton1.Checked Then
            drv("민간구분") = "0"
        Else
            drv("민간구분") = "1"   '//공공
        End If
    End Sub

    Private Sub RibbonButton1_Click(sender As Object, e As EventArgs) Handles RibbonButton1.Click
        AcceptChanged()
    End Sub


End Class