Public Class Frm_V20091231_Profile
    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 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_profile"
            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("잠시만 기다려주세요")

        'CEnergy.ARINCLASS.SaveLoad_FrmSetting(Me)
        '//공유데이터셋에 연결한다.
        Me.bs.DataSource = DSET1

        AddHandler DSET1.tbl_profile.TableNewRow, AddressOf AddNewDataRow_Profile
        AddHandler DSET1.tbl_profile.ColumnChanging, AddressOf AddNewDataRow_Zone_Changed2

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

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

        If Prj.UserAuthType = "ADMIN" OrElse Prj.UserAuthType = "BOTH2" Then  '//2010.11.22 추가
            Me.SplitContainer1.Panel2.Enabled = True
            Me.bn_all.Visible = True
        Else
            Me.SplitContainer1.Panel2.Enabled = False
            Me.bn_all.Visible = False
        End If

        If System.Diagnostics.Debugger.IsAttached Then
            Me.bn_all.Visible = True
            Me.SplitContainer1.Panel2.Enabled = True
        End If

        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 AddNewDataRow_Profile(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        e.Row.Item("code") = GetMaxCode(DSET1.tbl_profile)
    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 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 사용시작시간NTb_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles tb_t1.GotFocus
        CType(sender, TextBox).SelectAll()
    End Sub

    Private Sub tb_t1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tb_t1.KeyDown
        If Prj.UserAuthType = "ADMIN" OrElse Prj.UserAuthType = "BOTH" OrElse Prj.UserAuthType = "BOTH2" OrElse Prj.UserAuthType = "BOTH1" Then  '//2011.03.08 추가
            If e.KeyCode = Keys.V And e.Control Then

                e.Handled = True
                e.SuppressKeyPress = True
                '//클립보드붙여넣기
                Dim CB() As String = My.Computer.Clipboard.GetText.Split(CChar(vbCrLf))
                If CB.GetUpperBound(0) <> 59 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(Me.bs.Current, DataRowView)("설명") = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 0 + 1
                                Me.tb_일급탕요구량.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 1 + 1 '//공란
                            Case 2 + 1  '//면적
                                Me.tb_t1.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 3 + 1
                                Me.tb_t2.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 4 + 1
                                Me.tb_t3.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 5 + 1
                                Me.tb_t4.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 6 + 1
                                Me.tb_t5.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 7 + 1
                                Me.tb_t6.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 8 + 1
                                ' Me.tb_t7.Text = CB(i).Trim
                            Case 9
                                ' Me.tb_t8.Text = CB(i).Trim
                            Case 10
                                ' Me.tb_t9.Text = CB(i).Trim
                            Case 11
                                ' Me.tb_t10.Text = CB(i).Trim
                            Case 12
                                ' Me.tb_공냉난시간.Text = CB(i).Trim

                            Case 13 + 1
                            Case 14 + 1

                            Case 15 '//요구조도
                                ' Me.tb_t12.Text = CB(i).Trim
                            Case 16
                                'Me.tb_t13.Text = CB(i).Trim
                            Case 17
                                'Me.tb_t14.Text = CB(i).Trim
                            Case 18
                                'Me.tb_t15.Text = CB(i).Trim
                            Case 19
                                'Me.tb_t16.Text = CB(i).Trim
                            Case 20 '//부분운전계수
                                'Me.tb_t17.Text = CB(i).Trim

                            Case 21
                            Case 22

                            Case 23 + 1 '//최소도입외기량
                                Me.tb_t18.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 24
                                '  Me.tb_t19.Text = CB(i).Trim

                            Case 25
                            Case 26

                            Case 27 + 1
                                Me.tb_t20.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 28 + 1 '//작업보조기기
                                Me.tb_t21.Text = CB(i).Split(CChar(vbTab))(ii).Trim

                            Case 29
                            Case 30

                            Case 31 + 1 '//실내공기온도
                                'Me.TabControl11.SelectedIndex = 1
                                Me.tB_t22.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 32 + 1
                                Me.tb_t23.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 33 + 1
                                Me.tb_t24.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 34 + 1
                                Me.tb_t25.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 35 + 1
                                ' Me.tb_t26.Text = CB(i).Trim
                            Case 36 '//최소설정온도 냉방
                                'Me.tb_t27.Text = CB(i).Trim

                            Case 37
                            Case 38

                            Case 39
                                ' Me.tb_t28.Text = CB(i).Trim
                            Case 40
                                'Me.tb_t29.Text = CB(i).Trim
                            Case 41
                                ' Me.tb_t30.Text = CB(i).Trim
                            Case 42
                                ' Me.tb_t31.Text = CB(i).Trim
                            Case 43
                                ' Me.tb_t32.Text = CB(i).Trim

                            Case 44
                            Case 45
                            Case 46

                            Case 40 + 7 + 1
                                Me.tb_tm1.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 41 + 7 + 1
                                Me.tb_tm2.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 42 + 7 + 1
                                Me.tb_tm3.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 43 + 7 + 1
                                Me.tb_tm4.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 44 + 7 + 1
                                Me.tb_tm5.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 45 + 7 + 1
                                Me.tb_tm6.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 46 + 7 + 1
                                Me.tb_tm7.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 47 + 7 + 1
                                Me.tb_tm8.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 48 + 7 + 1
                                Me.tb_tm9.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 49 + 7 + 1
                                Me.tB_tm10.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 50 + 7 + 1
                                Me.tb_tm11.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                            Case 51 + 7 + 1
                                Me.tb_tm12.Text = CB(i).Split(CChar(vbTab))(ii).Trim
                        End Select
                    Next
                    If bs.Position < bs.Count Then bs.Position += 1 '//위치이동
                Next
                Me.bs.EndEdit()
            End If
        End If
    End Sub


    Private Sub bt_Del_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles bt_Del.MouseDown
        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
                If MsgBox("전체삭제를 하시겠습니까?", MsgBoxStyle.Information Or MsgBoxStyle.OkCancel, "확인") = MsgBoxResult.Ok Then
                    Dim dR() As DataRow = DSET1.tbl_profile.Select(Me.bs.Filter, "")
                    For i As Integer = dR.GetUpperBound(0) To 0 Step -1
                        dR(i).Delete()
                    Next
                    DSET1.tbl_profile.AcceptChanges()
                End If
            End If
        End If
    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 = ""
                If Frm_FilterA.ShowDialog <> Windows.Forms.DialogResult.OK Then Return '//창떳을떄 확인아ㅣ고 취소눌르면 다음을 수행하지않는다는거에요.
                Dim Filter As String = Frm_FilterA.tb_filter.Text   '//값은 아까 그 텍박에 잇구요.
                Try
                    Me.bs.Filter = Filter
                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 Frm_V20091231_Profile_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Select Case e.KeyCode
            Case Keys.F12
                ShowHistory()
        End Select
    End Sub
    Private Sub ShowHistory()
        Dim drv As DataRowView = Me.bs.Current
        Dim f As New Frm_History("tbl_profile", 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
End Class
