Imports System.Windows.Forms

Public Class Frm_NaengBang

    Dim Init As Boolean = False
    Dim SrcDrv As DataRowView



    Public Sub New(_opentime)

        ' 이 호출은 디자이너에 필요합니다.
        InitializeComponent()
        OpenTime = _opentime

        ' InitializeComponent() 호출 뒤에 초기화 코드를 추가하십시오.


    End Sub
#Region "data Base 변경여부및 적용방법"

    '''변경된내용을적용한다.
    Public Overrides Function AcceptChanged() As Boolean
        bs.EndEdit()
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Dim BaseDT As DataTable = BaseDS.Tables(bs.DataMember)
        BaseDT.AcceptChanges()
        Return True
    End Function

    '''변경된내용이있다면 취소한다.
    Public Overrides Function RejectChanged() As Boolean
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Dim BaseDT As DataTable = BaseDS.Tables(bs.DataMember)
        BaseDT.RejectChanges()
        Return True
    End Function

    '''데이터에변형이있었는가?
    Public Overrides Function HasChanged() As Boolean
        bs.EndEdit()
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Dim BaseDT As DataTable = BaseDS.Tables(bs.DataMember)
        Dim ChangeDT As DataTable = BaseDT.GetChanges
        If Not ChangeDT Is Nothing Then Return True
        Return False
    End Function

    '''기본데이터테이블을 반환합니다.
    Public Function DT() As DataTable
        Dim BaseDS As DataSet = CType(bs.DataSource, DataSet)
        Return BaseDS.Tables(bs.DataMember)
    End Function


#End Region

    Private Sub ShowHistory()
        Dim drv As DataRowView = Me.bs.Current
        Dim f As New Frm_History("tbl_nangbangkiki", drv("code").ToString)
        If f.ShowDialog = DialogResult.OK Then
            drv(f.colname) = f.val
            Me.Validate()
            Me.bs.EndEdit()
            My.Application.DoEvents()
            MsgBox("값이 변경되었습니다", MsgBoxStyle.Information, "확인")
        End If
    End Sub
    Private Sub AddNewDataRow_Zone_Changed2(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs)
        Dim oval As String = e.Row(e.Column.ColumnName).ToString
        Dim nval As String = e.ProposedValue.ToString
        If oval <> nval Then
            Dim newdr As DS2.historyRow = DSHistory.history.NewhistoryRow
            newdr.time = Now.ToString("yyyy-MM-dd HH:mm:ss")
            newdr.tablename = "tbl_nangbangkiki"
            newdr.ovalue = oval
            newdr.nvalue = nval
            newdr.column = e.Column.ColumnName
            newdr.code = e.Row("code").ToString
            DSHistory.history.AddhistoryRow(newdr)
            DSHistory.history.AcceptChanges()
        End If
    End Sub
    Private Sub MdiMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Show()
        My.Application.DoEvents()
        'Work_msg_timer("잠시만 기다려주세요")

        '//프로필 관련

        '//공유데이터셋에 연결한다.
        Me.bs.DataSource = DSET1

        '//냉방기기
        AddHandler DSET1.tbl_nangbangkiki.TableNewRow, AddressOf AddNewDataRow_nangbangkiki
        AddHandler DSET1.tbl_nangbangkiki.ColumnChanging, AddressOf AddNewDataRow_Zone_Changed2

        '//콤보컨트롤 바인딩
        Binding_Zone()

        '//모든컨트롤의 cTrl_enter 를 추가합니다
        BindProperty(CType(Me.SplitContainer1.Panel2.Controls, Control.ControlCollection))




        Me.bs.Filter = "code <> '0'"
        If Me.Parameter <> "" Then Me.bs.Filter &= " and 냉동기방식 ='" + Me.Parameter + "'"
        'Me.lb_grpname.Text = Me.Parameter


        Me.Init = True

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

        bs_CurrentChanged(sender, e)
        Validate_Control()
        AddDebug("▲ Form Load")
    End Sub
#Region "Control_Enter"
    Private Sub BindProperty(ByVal Ctl As Control.ControlCollection)
        For Each C As Control In Ctl
            If C.Controls.Count > 1 Then
                BindProperty(C.Controls)
            Else
                If C.GetType.ToString.ToUpper.IndexOf("MYTB") <> -1 Then
                    AddHandler CType(C, MyTb).KeyDown, AddressOf TextBOx_KeyDown
                ElseIf C.GetType.ToString.ToUpper.IndexOf("MYCMB") <> -1 Then
                    AddHandler CType(C, MyCmb).KeyDown, AddressOf Cmd_KeyDown
                End If
            End If
        Next
    End Sub


    Private Sub TextBOx_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter AndAlso e.Control Then
            Try
                Dim Field As String = (CType(sender, MyTb).DataBindings.Item("text").BindingMemberInfo.BindingField)
                For Each Dr As DataRow In DT.Select(Me.bs.Filter, "")
                    Dr(Field) = CType(sender, MyTb).Text
                Next
                Work_msg_timer("모든값이 변경되었습니다", 25)
            Catch ex As Exception

            End Try

        End If
    End Sub
    Private Sub Cmd_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter AndAlso e.Control Then
            Try
                Dim Field As String = (CType(sender, MyCmb).DataBindings.Item("selectedvalue").BindingMemberInfo.BindingField)
                For Each Dr As DataRow In DT.Select(Me.bs.Filter, "")
                    Dr(Field) = CType(sender, MyCmb).SelectedValue
                Next
                Work_msg_timer("모든값이 변경되었습니다", 25)
            Catch ex As Exception

            End Try
        End If
    End Sub
#End Region
#Region "냉방기기"
    Private Sub MdiMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        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
                ShowHistory()
        End Select
    End Sub
    Private Function GetMaxCode(ByVal dt As DataTable) As String
        Try
            Dim Dr As DataRow = dt.Select("", "code desc")(0)
            Return Format(CInt(Dr("code")) + 1, "0000")
        Catch ex As Exception
            Return "0001"
        End Try
    End Function

#Region "제어버튼"
    Private Sub ToolStripButton48_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_add.Click
        If Not EndEdit(Me.bs) Then Return
        Me.bs.AddNew()
        INitRow(Me.Controls)
        MdiMain.RefreshMenuList(TreeTag)
    End Sub

    Private Sub ToolStripButton49_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Del.Click
        Dbbase.DelCrow(Me.bs, True)
        MdiMain.RefreshMenuList(TreeTag)
    End Sub

    Private Sub ToolStripButton51_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_cancel.Click
        If Not EndEdit(Me.bs) Then Return
        Data_Cancel(DSET1.tbl_profile, Nothing)
        MdiMain.RefreshMenuList(TreeTag)
    End Sub
#End Region

    Private Sub Binding_Zone()
        '//냉동기기
        Dim bs_냉동기방식ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_냉동기방식ComboBox.Filter = "gubun='1046'"
        bs_냉동기방식ComboBox.Sort = "code"
        Me.냉동기방식ComboBox.DataSource = bs_냉동기방식ComboBox
        냉동기방식ComboBox.DisplayMember = "name"
        냉동기방식ComboBox.ValueMember = "name"
        Me.냉동기방식ComboBox.DataBindings.Add("selectedvalue", Me.bs, "냉동기방식")
        'AddHandler 냉동기방식ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_냉동기종류ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_냉동기종류ComboBox.Filter = "gubun='1047'"
        bs_냉동기종류ComboBox.Sort = "code"
        Me.냉동기종류ComboBox.DataSource = bs_냉동기종류ComboBox
        냉동기종류ComboBox.DisplayMember = "name"
        냉동기종류ComboBox.ValueMember = "name"
        Me.냉동기종류ComboBox.DataBindings.Add("selectedvalue", Me.bs, "냉동기종류")
        'AddHandler 냉동기종류ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_냉동기압축방식ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_냉동기압축방식ComboBox.Filter = "gubun='1048'"
        bs_냉동기압축방식ComboBox.Sort = "code"
        Me.냉동기압축방식ComboBox.DataSource = bs_냉동기압축방식ComboBox
        냉동기압축방식ComboBox.DisplayMember = "name"
        냉동기압축방식ComboBox.ValueMember = "name"
        Me.냉동기압축방식ComboBox.DataBindings.Add("selectedvalue", Me.bs, "냉동기압축방식")
        ' AddHandler 냉동기압축방식ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_압축기제어방식ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_압축기제어방식ComboBox.Filter = "gubun='1049'"
        bs_압축기제어방식ComboBox.Sort = "code"
        Me.압축기제어방식ComboBox.DataSource = bs_압축기제어방식ComboBox
        압축기제어방식ComboBox.DisplayMember = "name"
        압축기제어방식ComboBox.ValueMember = "name"
        Me.압축기제어방식ComboBox.DataBindings.Add("selectedvalue", Me.bs, "압축기제어방식")
        'AddHandler 압축기제어방식ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_냉동기설비시스템ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_냉동기설비시스템ComboBox.Filter = "gubun='1050'"
        bs_냉동기설비시스템ComboBox.Sort = "code"
        Me.냉동기설비시스템ComboBox.DataSource = bs_냉동기설비시스템ComboBox
        냉동기설비시스템ComboBox.DisplayMember = "name"
        냉동기설비시스템ComboBox.ValueMember = "name"
        Me.냉동기설비시스템ComboBox.DataBindings.Add("selectedvalue", Me.bs, "냉동기설비시스템")
        'AddHandler 냉동기설비시스템ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_제어방식ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_제어방식ComboBox.Filter = "gubun='1051'"
        bs_제어방식ComboBox.Sort = "code"
        Me.제어방식ComboBox.DataSource = bs_제어방식ComboBox
        제어방식ComboBox.DisplayMember = "name"
        제어방식ComboBox.ValueMember = "name"
        Me.제어방식ComboBox.DataBindings.Add("selectedvalue", Me.bs, "제어방식")
        'AddHandler 제어방식ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_열생산연결방식 As New BindingSource(DSET1, "tbl_common")
        bs_열생산연결방식.Filter = "gubun='1085'"
        bs_열생산연결방식.Sort = "code"
        Me.cmb_열생산연결방식.DataSource = bs_열생산연결방식
        cmb_열생산연결방식.DisplayMember = "name"
        cmb_열생산연결방식.ValueMember = "name"
        Me.cmb_열생산연결방식.DataBindings.Add("selectedvalue", Me.bs, "열생산연결방식")

        Dim bs_사용연료 As New BindingSource(DSET1, "tbl_common")
        bs_사용연료.Filter = "gubun='1086'"
        bs_사용연료.Sort = "code"
        Me.cmb_사용연료.DataSource = bs_사용연료
        cmb_사용연료.DisplayMember = "name"
        cmb_사용연료.ValueMember = "name"
        Me.cmb_사용연료.DataBindings.Add("selectedvalue", Me.bs, "사용연료")
        'AddHandler 온수열생산기기ComboBox.KeyDown, AddressOf Cmb_DeleteVal


        Dim bs_온수열생산기기ComboBox As New BindingSource(DSET1, "tbl_nanbangkiki")
        bs_온수열생산기기ComboBox.Sort = "code"
        Me.온수열생산기기ComboBox.DataSource = bs_온수열생산기기ComboBox
        온수열생산기기ComboBox.DisplayMember = "설명"
        온수열생산기기ComboBox.ValueMember = "code"
        Me.온수열생산기기ComboBox.DataBindings.Add("selectedvalue", Me.bs, "온수열생산기기")
        'AddHandler 온수열생산기기ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_증발식건식냉각기ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_증발식건식냉각기ComboBox.Filter = "gubun='1052'"
        bs_증발식건식냉각기ComboBox.Sort = "code"
        Me.증발식건식냉각기ComboBox.DataSource = bs_증발식건식냉각기ComboBox
        증발식건식냉각기ComboBox.DisplayMember = "name"
        증발식건식냉각기ComboBox.ValueMember = "name"
        Me.증발식건식냉각기ComboBox.DataBindings.Add("selectedvalue", Me.bs, "증발식건식냉각기")
        'AddHandler 증발식건식냉각기ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_증발식냉각기ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_증발식냉각기ComboBox.Filter = "gubun='1053'"
        bs_증발식냉각기ComboBox.Sort = "code"
        Me.증발식냉각기ComboBox.DataSource = bs_증발식냉각기ComboBox
        증발식냉각기ComboBox.DisplayMember = "name"
        증발식냉각기ComboBox.ValueMember = "name"
        Me.증발식냉각기ComboBox.DataBindings.Add("selectedvalue", Me.bs, "증발식냉각기")
        'AddHandler 증발식냉각기ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_보조방음기유무ComboBox As New BindingSource(DSET1, "tbl_common")
        bs_보조방음기유무ComboBox.Filter = "gubun='1054'" '//예 아니오 아직 결정안됨
        bs_보조방음기유무ComboBox.Sort = "code"
        Me.보조방음기유무ComboBox.DataSource = bs_보조방음기유무ComboBox
        보조방음기유무ComboBox.DisplayMember = "name"
        보조방음기유무ComboBox.ValueMember = "name"
        Me.보조방음기유무ComboBox.DataBindings.Add("selectedvalue", Me.bs, "보조방음기유무")
        'AddHandler 보조방음기유무ComboBox.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_신재생연결여부ComboBox1 As New BindingSource(DSET1, "tbl_common")
        bs_신재생연결여부ComboBox1.Filter = "gubun='1044'"
        bs_신재생연결여부ComboBox1.Sort = "code"
        Me.신재생연결여부ComboBox1.DataSource = bs_신재생연결여부ComboBox1
        신재생연결여부ComboBox1.DisplayMember = "name"
        신재생연결여부ComboBox1.ValueMember = "name"
        Me.신재생연결여부ComboBox1.DataBindings.Add("selectedvalue", Me.bs, "신재생연결여부")
        'AddHandler 신재생연결여부ComboBox1.KeyDown, AddressOf Cmb_DeleteVal

        Dim bs_연결된시스템ComboBox1 As New BindingSource(DSET1, "tbl_new")
        bs_연결된시스템ComboBox1.Sort = "code"
        Me.cmb_신재생.DataSource = bs_연결된시스템ComboBox1
        cmb_신재생.DisplayMember = "설명"
        cmb_신재생.ValueMember = "code"
        Me.cmb_신재생.DataBindings.Add("selectedvalue", Me.bs, "연결된시스템")
        'AddHandler cmb_신재생.KeyDown, AddressOf Cmb_DeleteVal
    End Sub

    Private Sub AddNewDataRow_nangbangkiki(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_nangbangkiki)
        e.Row.Item("설명") = "신규데이터"
        e.Row.Item("sortkey") = GetNewSortKey()
    End Sub

    Private Function GetNewSortKey() As String
        AddDebug("GetNewSortKey")

        Dim drows() As DS.tbl_nangbangkikiRow = DSET1.tbl_nangbangkiki.Select("code <> '0'", "sortkey desc")
        If drows.Length < 1 Then Return 1
        Dim Dr As DS.tbl_nangbangkikiRow = drows(0)
        Dim maxsortkey As Integer = Dr.sortkey
        Return maxsortkey + 1

    End Function

    Private Sub Frm_V20091231_Zone_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
        If e.Delta < 0 Then
            If Me.bs.Position < Me.bs.Count Then Me.bs.Position += 1
        Else
            If Me.bs.Position > 0 Then Me.bs.Position -= 1
        End If
        Me.Validate()
        My.Application.DoEvents()
    End Sub
#End Region

    Private Sub 신재생연결여부ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 신재생연결여부ComboBox1.SelectedIndexChanged
        Try
            If Me.신재생연결여부ComboBox1.SelectedIndex = 0 Then '//신재생연결없음
                cmb_신재생.Enabled = False
            Else
                cmb_신재생.Enabled = True
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub 냉동기방식ComboBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles 냉동기방식ComboBox.KeyDown
        If e.KeyCode = Keys.V And e.Control Then
            e.Handled = True
            e.SuppressKeyPress = False
            '//클립보드붙여넣기
            Dim CB() As String = My.Computer.Clipboard.GetText.Split(CChar(vbCrLf))
            If CB.GetUpperBound(0) <> 32 Then
                MsgBox("붙여넣기가 호환되는 데이터가 아닙니다.", MsgBoxStyle.Information, "확인")
                Return
            End If

            For ii As Integer = 0 To CType(CB(0).Split(CChar(vbTab)), String()).GetUpperBound(0)
                If Me.bs.Count = 0 OrElse ii > 0 Then Me.bt_add.PerformClick() '//한줄추가

                Dim Cnt As Short = 0
                For i As Integer = 0 To CB.GetUpperBound(0)
                    Select Case i
                        Case 0
                            CType(bs.Current, DataRowView)("설명") = CB(i).Split(CChar(vbTab))(ii).Trim
                        Case 0 + 5 '//사용프로필 앞에 두개를 숫자4자로변환
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.냉동기방식ComboBox.SelectedIndex = 0
                            Else
                                Me.냉동기방식ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If

                            'Me.냉동기방식ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 1 + 5
                            Me.냉동기용량NTb.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                        Case 2 + 5
                            Me.열성능비NTb.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                        Case 5 + 5
                            '  Me.TabControl13.SelectedIndex = 1
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.냉동기종류ComboBox.SelectedIndex = 0
                            Else
                                Me.냉동기종류ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If

                            'Me.냉동기종류ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 7 + 5
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.냉동기압축방식ComboBox.SelectedIndex = 0
                            Else
                                Me.냉동기압축방식ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If


                            'Me.냉동기압축방식ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 13
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.압축기제어방식ComboBox.SelectedIndex = 0
                            Else
                                Me.압축기제어방식ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If


                            'Me.압축기제어방식ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 10 + 5
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.냉동기설비시스템ComboBox.SelectedIndex = 0
                            Else
                                Me.냉동기설비시스템ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If


                            'Me.냉동기설비시스템ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 11 + 5
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.제어방식ComboBox.SelectedIndex = 0
                            Else
                                Me.제어방식ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If

                            'Me.제어방식ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 14 + 5  '//열생산연결방식
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.cmb_열생산연결방식.SelectedIndex = 0
                            Else
                                Me.cmb_열생산연결방식.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If
                        Case 14 + 5 + 1   '//사용연로
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.cmb_사용연료.SelectedIndex = 0
                            Else
                                Me.cmb_사용연료.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If
                        Case 14 + 5 + 2
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.온수열생산기기ComboBox.SelectedIndex = 0
                            Else
                                Me.온수열생산기기ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If

                            ' Me.온수열생산기기ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 24
                            ' Me.TabControl13.SelectedIndex = 2
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.증발식건식냉각기ComboBox.SelectedIndex = 0
                            Else
                                Me.증발식건식냉각기ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If


                            ' Me.증발식건식냉각기ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 25
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.증발식냉각기ComboBox.SelectedIndex = 0
                            Else
                                Me.증발식냉각기ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If

                            'Me.증발식냉각기ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 26
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.보조방음기유무ComboBox.SelectedIndex = 0
                            Else
                                Me.보조방음기유무ComboBox.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If

                            'Me.보조방음기유무ComboBox.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 27
                            Me.냉각수토출온도NTb.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                        Case 30
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.신재생연결여부ComboBox1.SelectedIndex = 0
                            Else
                                Me.신재생연결여부ComboBox1.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If
                            'Me.신재생연결여부ComboBox1.Text = CStr(IIf( CB(i).Split(CChar(vbTab))(ii).Trim = "", "0",  CB(i).Split(CChar(vbTab))(ii).Trim))
                        Case 31
                            If CB(i).Split(CChar(vbTab))(ii).Trim = "" Then
                                Me.cmb_신재생.SelectedIndex = 0
                            Else
                                Me.cmb_신재생.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            End If

                            'Me.연결된시스템ComboBox1.Text = CStr(IIf(CB(i).Trim = "", "0", CB(i).Trim))
                    End Select
                Next
            Next

            Me.bs.EndEdit()
        End If
    End Sub

    Private Sub Validate_Control()
        If Not Init Then Return
        '//오류 냉동기방식 오류
        Try
            Dim V As String = CStr(CType(Me.bs.Current, DataRowView)("설명"))
            Select Case Me.냉동기방식ComboBox.SelectedValue.ToString.Trim
                Case "압축식", "압축식(LNG)"  '//압축식
                    'Select Case V
                    '    Case "냉동기A", "냉동기B"
                    '        냉동기종류ComboBox.Enabled = True
                    '        냉동기압축방식ComboBox.Enabled = True

                    '        압축기제어방식ComboBox.Enabled = False
                    '        냉동기설비시스템ComboBox.Enabled = False
                    '        제어방식ComboBox.Enabled = False
                    '        온수열생산기기ComboBox.Enabled = False
                    '        증발식건식냉각기ComboBox.Enabled = False
                    '        증발식냉각기ComboBox.Enabled = False
                    '        보조방음기유무ComboBox.Enabled = False
                    '        냉각수토출온도NTb.Enabled = False
                    '    Case "냉동기C"
                    '        냉동기종류ComboBox.Enabled = True
                    '        냉동기압축방식ComboBox.Enabled = True

                    '        압축기제어방식ComboBox.Enabled = False
                    '        냉동기설비시스템ComboBox.Enabled = False
                    '        제어방식ComboBox.Enabled = False
                    '        온수열생산기기ComboBox.Enabled = False
                    '        증발식건식냉각기ComboBox.Enabled = True
                    '        증발식냉각기ComboBox.Enabled = True
                    '        보조방음기유무ComboBox.Enabled = True
                    '        냉각수토출온도NTb.Enabled = True
                    'End Select

                    '//건기연 수정 2010.04.07
                    냉동기종류ComboBox.Enabled = True
                    냉동기압축방식ComboBox.Enabled = True

                Case "흡수식"  '//흡수식
                    'Select Case V
                    '    Case "냉동기A", "냉동기C"
                    '        냉동기종류ComboBox.Enabled = False
                    '        '냉동기종류Label.Enabled = False
                    '        냉동기압축방식ComboBox.Enabled = False
                    '        압축기제어방식ComboBox.Enabled = False
                    '        냉동기설비시스템ComboBox.Enabled = False
                    '        제어방식ComboBox.Enabled = False

                    '        온수열생산기기ComboBox.Enabled = True
                    '        증발식건식냉각기ComboBox.Enabled = True
                    '        증발식냉각기ComboBox.Enabled = True
                    '        보조방음기유무ComboBox.Enabled = True
                    '        냉각수토출온도NTb.Enabled = True
                    '    Case "냉동기B"
                    '        냉동기종류ComboBox.Enabled = False
                    '        냉동기압축방식ComboBox.Enabled = False
                    '        압축기제어방식ComboBox.Enabled = False
                    '        냉동기설비시스템ComboBox.Enabled = False
                    '        제어방식ComboBox.Enabled = False

                    '        온수열생산기기ComboBox.Enabled = True
                    '        증발식건식냉각기ComboBox.Enabled = True
                    '        증발식냉각기ComboBox.Enabled = False
                    '        보조방음기유무ComboBox.Enabled = False
                    '        냉각수토출온도NTb.Enabled = True
                    'End Select

                    냉동기종류ComboBox.Enabled = False
                    냉동기압축방식ComboBox.Enabled = False

                Case "지역냉방"  '//지역냉방
                    'Select Case V
                    '    Case "냉동기A", "냉동기B", "냉동기C"
                    '        냉동기종류ComboBox.Enabled = False
                    '        냉동기압축방식ComboBox.Enabled = False
                    '        압축기제어방식ComboBox.Enabled = False
                    '        냉동기설비시스템ComboBox.Enabled = False
                    '        제어방식ComboBox.Enabled = False
                    '        온수열생산기기ComboBox.Enabled = False
                    '        증발식건식냉각기ComboBox.Enabled = False
                    '        증발식냉각기ComboBox.Enabled = False
                    '        보조방음기유무ComboBox.Enabled = False
                    '        냉각수토출온도NTb.Enabled = False
                    'End Select


                    냉동기종류ComboBox.Enabled = False
                    냉동기압축방식ComboBox.Enabled = False
            End Select
        Catch ex As Exception

        End Try
        Try
            If Me.냉동기압축방식ComboBox.Text = "왕복동/스크롤 압축기" Then
                Me.압축기제어방식ComboBox.Enabled = True
            Else
                Me.압축기제어방식ComboBox.SelectedIndex = 0 '//없음으로 설정하고
                Me.압축기제어방식ComboBox.Enabled = False
            End If
        Catch ex As Exception

        End Try

        Try
            If Me.냉동기방식ComboBox.Text = "흡수식" Then
                Me.cmb_열생산연결방식.Enabled = True
                Me.압축기제어방식ComboBox.Enabled = False
                Me.냉동기설비시스템ComboBox.Enabled = False
                Me.제어방식ComboBox.Enabled = False
                Try
                    If Me.cmb_열생산연결방식.Text = "직화식" Then
                        Me.cmb_사용연료.Enabled = True
                        Me.온수열생산기기ComboBox.Enabled = False
                    Else
                        If Me.cmb_열생산연결방식.Text = "외부연결" Then
                            Me.cmb_사용연료.Enabled = False
                            Me.온수열생산기기ComboBox.Enabled = True
                        Else
                            Me.cmb_사용연료.Enabled = False
                            Me.온수열생산기기ComboBox.Enabled = False
                        End If
                    End If
                Catch ex As Exception
                End Try
                Me.재냉각기GroupBox.Enabled = True
            Else
                Me.cmb_열생산연결방식.Enabled = False
                Me.cmb_사용연료.Enabled = False
                Me.온수열생산기기ComboBox.Enabled = False

                If Me.냉동기방식ComboBox.Text = "압축식" Or Me.냉동기방식ComboBox.Text = "압축식(LNG)" Then
                    Select Case Me.냉동기종류ComboBox.Text
                        Case "수냉식"
                            Me.재냉각기GroupBox.Enabled = True
                            Me.냉동기압축방식ComboBox.Enabled = True
                            Me.냉동기설비시스템ComboBox.Enabled = False
                            Me.제어방식ComboBox.Enabled = False
                        Case "공냉식"
                            Me.재냉각기GroupBox.Enabled = False
                            Me.냉동기압축방식ComboBox.Enabled = True
                            Me.냉동기설비시스템ComboBox.Enabled = False
                            Me.제어방식ComboBox.Enabled = False
                        Case "실내공조시스템"
                            Me.냉동기압축방식ComboBox.Enabled = False
                            Me.냉동기설비시스템ComboBox.Enabled = True
                            Me.제어방식ComboBox.Enabled = True
                            Me.압축기제어방식ComboBox.Enabled = False
                            Me.재냉각기GroupBox.Enabled = False
                        Case Else

                    End Select
                Else
                    Me.냉동기압축방식ComboBox.Enabled = False
                    Me.냉동기설비시스템ComboBox.Enabled = False
                    Me.제어방식ComboBox.Enabled = False
                    Me.압축기제어방식ComboBox.Enabled = False
                    Me.재냉각기GroupBox.Enabled = False
                End If
            End If
        Catch ex As Exception

        End Try
        Me.bs.EndEdit()
    End Sub

    Private Sub bs_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs.CurrentChanged
        If Not Init Then Return

        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return
        Me.lb_code.Text = "[" + drv("code").ToString + "]"

        If drv Is Nothing Then Return
        Dim DR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("열생산냉방생산기기='" & drv("code").ToString & "' or 공조냉방생산기기='" & drv("code").ToString & "'") '//2010.12.02 수정
        Dim cnt As Integer = 0
        For Each drow As DS.tbl_zoneRow In DR
            Dim 입력존수문자 As Integer = drow.입력존의수
            If IsNumeric(입력존수문자) = False Then 입력존수문자 = "1"
            cnt += CInt(입력존수문자)
        Next
        Me.tb_zone_cnt.Text = cnt.ToString()
        Me.bs.EndEdit()
    End Sub

    Private Sub 냉동기방식ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 냉동기방식ComboBox.SelectedIndexChanged
        Validate_Control()
    End Sub

    Private Sub 냉동기압축방식ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 냉동기압축방식ComboBox.SelectedIndexChanged
        Validate_Control()
    End Sub


    Private Sub bt_Del_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles bt_Del.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Right Then
            If MsgBox("전체삭제를 하시겠습니까?", MsgBoxStyle.Information Or MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then
                Dim dR() As DataRow = DSET1.tbl_nangbangkiki.Select(Me.bs.Filter, "")
                For i As Integer = dR.GetUpperBound(0) To 0 Step -1
                    dR(i).Delete()
                Next
                DSET1.tbl_nangbangkiki.AcceptChanges()
            End If
        End If
    End Sub

    Private Sub SplitContainer1_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer1.Panel2.Paint

    End Sub

    Private Sub 냉동기종류ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 냉동기종류ComboBox.SelectedIndexChanged
        Validate_Control()
    End Sub

    Private Sub cmb_열생산연결방식_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmb_열생산연결방식.SelectedIndexChanged
        Validate_Control()
    End Sub

    Private Sub dv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dv.MouseUp
        If Prj.UserAuthType = "ADMIN" OrElse Prj.UserAuthType = "BOTH" OrElse Prj.UserAuthType = "BOTH2" OrElse Prj.UserAuthType = "BOTH1" Then  '//2011.03.08 추가
            If e.Button = Windows.Forms.MouseButtons.Right Then
                Dim Frm_FilterA As New Frm_Filter
                Frm_FilterA.ColumTitle = getColCaption(Me.DT)
                Frm_FilterA.ColumList = getColName(Me.DT)
                Frm_FilterA.Colorlist = "온수열생산기기,연결된시스템"
                Frm_FilterA.Numfield = ""    '//20100618  Color 리스트처럼 , 구분해서 필드들을 모두 넣으세요.(=, >= 등을 사용하기 위해서는 해당 항목을 추가 요망)
                Frm_FilterA.Default_Filter = "code <> '0'"

                If Frm_FilterA.ShowDialog <> Windows.Forms.DialogResult.OK Then Return '//창떳을떄 확인아ㅣ고 취소눌르면 다음을 수행하지않는다는거에요.
                Dim Filter As String = Frm_FilterA.tb_filter.Text   '//값은 아까 그 텍박에 잇구요.
                Try
                    Me.bs.Filter = Filter

                    '//바꾸기값이 있으면 변경 20100618
                    If Frm_FilterA.cmb_fieldc.SelectedIndex >= 0 AndAlso Frm_FilterA.cmb_fieldc.Text.ToLower <> "code" AndAlso _
                    Frm_FilterA.tb_valuec.Text <> "" Then
                        Dim Drow() As DataRow = Me.DT.Select(Filter)
                        For Each Dr As DataRow In Drow
                            Dr(Frm_FilterA.cmb_fieldc.Text) = Frm_FilterA.tb_valuec.Text
                        Next
                        MsgBox("바꾸기 완료", MsgBoxStyle.Information, "확인")
                    End If

                Catch ex As Exception
                    Me.bs.Filter = ""
                End Try
            End If
        End If
    End Sub

    Private Sub dv_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dv.KeyDown
        '//여기보시면   alt+d 누르면  한줄을 경고없이(falsE)삭제하도록 햇어요.. 사실원래 밋alt +d 인데.. ㅎㅎ 잘못해서 ctrl 됫다는
        If Prj.UserAuthType = "ADMIN" OrElse Prj.UserAuthType = "BOTH" OrElse Prj.UserAuthType = "BOTH2" OrElse Prj.UserAuthType = "BOTH1" Then  '//2011.03.08 추가
            Select Case e.KeyCode
                Case Keys.D
                    If e.Alt Then
                        Dbbase.DelCrow(Me.bs, False)
                    End If
                Case Keys.C
                    If e.Control Then
                        Me.SrcDrv = Me.bs.Current
                        If Me.SrcDrv Is Nothing Then
                            MsgBox("저장할 ROW가 없습니다", MsgBoxStyle.Information, "확인")
                            Return
                        End If
                        ' My.Computer.Clipboard.SetData("ZDATA", Drv)
                    End If
                Case Keys.V
                    If e.Control Then
                        If Me.SrcDrv Is Nothing Then Return
                        Me.bt_add.PerformClick()  '//신규추가
                        Dim NewDrv As DataRowView = Me.bs.Current

                        For Each C As DataColumn In Me.DT.Columns
                            If C.ColumnName.ToUpper = "CODE" Then
                            ElseIf C.ColumnName.ToUpper = "설명" Then
                                NewDrv(C.ColumnName) = SrcDrv(C.ColumnName) & "#1"
                            Else
                                NewDrv(C.ColumnName) = SrcDrv(C.ColumnName)
                            End If
                        Next
                        Me.bs.EndEdit()
                        bs.MoveLast()
                    End If
            End Select
        End If
    End Sub

    Private Sub dv_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dv.CellContentClick

    End Sub

    Private Sub chk_헤더적용_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chk_헤더적용.CheckedChanged
        If Me.chk_헤더적용.Checked = True AndAlso Me.chk_개별기기적용.Checked = True Then
            MsgBox("개별기기와 헤더가 모두 체크되었습니다. 둘 중 하나만 체크하시기 바랍니다.", MsgBoxStyle.Information, "확인")
        End If
    End Sub

    Private Sub chk_개별기기적용_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chk_개별기기적용.CheckedChanged
        If Me.chk_개별기기적용.Checked = True AndAlso Me.chk_헤더적용.Checked = True Then
            MsgBox("개별기기와 헤더가 모두 체크되었습니다. 둘 중 하나만 체크하시기 바랍니다.", MsgBoxStyle.Information, "확인")
        End If
    End Sub

    Private Sub Label2_Click(sender As System.Object, e As System.EventArgs) Handles Label2.Click

        If DSET1.tbl_Desc.Rows.Count < 1 Then
            MsgboxE("건물개요가 없습니다")
            Return
        End If


        Dim drdesc As DS.tbl_DescRow = DSET1.tbl_Desc.Rows(0)
        Dim 주거형태 As String = drdesc.isjugo
        If 주거형태 <> "2" Then
            'MsgBox("주거용건축물만 사용 가능 합니다")
            Return
        End If

        '//zone list
        Dim drv As DataRowView = Me.bs.Current
        If drv Is Nothing Then Return
        Dim DR() As DS.tbl_zoneRow = DSET1.tbl_zone.Select("열생산냉방생산기기='" & drv("code").ToString & "'") '//2010.12.02 수정
        If DR.Length < 1 Then
            MsgBox("연결된 존이 없습니다")
            Return
        End If

        Dim 전용면적 As Decimal = 0
        For Each drz As DS.tbl_zoneRow In DR
            If 전용면적 = 0 Then
                전용면적 = drz.면적
            Else
                If 전용면적 <> drz.면적 Then
                    MsgBox("동일하지 않는 면적이 있습니다")
                    Return
                End If
            End If
        Next


        Dim newvalue As Decimal = Math.Round(0.1801 * 전용면적, 3)
        If MsgBox("전용면적(" + 전용면적.ToString() + ") * 0.1801 = " + newvalue.ToString() + vbCrLf + _
                  "냉방효율 : 2.894" + vbCrLf + _
                  "압축식, 실내공조시스템, 멀티분리시스템, on/off제어, 개별기기", MsgBoxStyle.YesNo, "") = MsgBoxResult.Yes Then


            열성능비NTb.Text = "2.894"

            냉동기용량NTb.Text = newvalue 'Math.Round(0.1801 * 전용면적, 3)
            냉동기방식ComboBox.Text = "압축식"
            냉동기종류ComboBox.Text = "실내공조시스템"
            냉동기설비시스템ComboBox.Text = "멀티분리시스템"
            제어방식ComboBox.Text = "on/off제어"
            chk_개별기기적용.Checked = True

            '압축식/실내공조시스템
            '실내기 및 제어방식
            '멀티분리시스템/ON‧OFF제어


        End If
    End Sub

    Private Sub Frm_NaengBang_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
        If DSET1.tbl_Desc.Rows.Count < 1 Then
            'MsgboxE("건물개요가 없습니다")
            Return
        End If
        Dim dr As DS.tbl_DescRow = DSET1.tbl_Desc.Rows(0)
        Dim 주거형태 As String = dr.isjugo
        If 주거형태 <> "2" Then
            Me.Label2.ForeColor = SystemColors.ControlDarkDark
            Me.Label2.Font = Me.Font

            '    Me.Label3.ForeColor = SystemColors.ControlDarkDark
            '    Me.Label3.Font = Me.Font
            'Else
            Me.Label2.ForeColor = Color.Blue
            Me.Label2.Font = New Font(Me.Font.Name, Me.Font.Size, FontStyle.Underline)

            'Me.Label3.ForeColor = Color.Blue
            'Me.Label3.Font = New Font(Me.Font.Name, Me.Font.Size, FontStyle.Underline)
        End If


    End Sub

    Private Sub Label3_Click(sender As System.Object, e As System.EventArgs) Handles Label3.Click

        
    End Sub
End Class