Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Math
Imports System.IO
Imports CEpole.C_Epole

Public Class PrintForm
    '//기본 Datatable 인데 사용하기 편하게 Shadow 한다.
    'Public Shadows srctable As ireaDataSet.Detail_tongsinDataTable
    '//Loadstyle 후에 일련번호를 부여한다. (SetControlIndex)
    Dim IDX_일련번호 As Short
    Dim IDX_전주번호 As Short
    'Dim IDX_전주번호2 As Short
    Dim IDX_간선명 As Short
    Dim IDX_간선명2 As Short
    Dim IDX_시공일 As Short
    Dim IDX_시공자 As Short
    Dim IDX_운용기관 As Short
    Dim IDX_규격 As Short        '2008/07/10
    Dim IDX_중계기명 As Short   '2008/07/10
    Dim IDX_연락처1 As Short '2008/07/10
    Dim IDX_연락처2 As Short '2008/07/10
    Dim IDX_점용허가기관 As Short '2013/12/04
    Dim IDX_점용허가기간 As Short '2013/12/04
    Dim IDX_점용허가번호 As Short '2013/12/04
    Dim IDX_단자함1 As Short
    Dim IDX_단자함2 As Short
    Dim IDX_단자함3 As Short
    Dim IDX_광단자함1 As Short
    Dim IDX_광단자함2 As Short
    Dim IDX_광단자함3 As Short
    Dim IDX_광단자함4 As Short
    Dim IDX_한줄간선명 As Short
    Dim IDX_한줄전주번호 As Short
    
    Dim IDX_한줄단자함 As Short
    Dim IDX_한줄광단자함 As Short

    Dim IDX_고정문자1 As Short
    Dim IDX_고정문자2 As Short
    Dim IDX_고정문자3 As Short
    Dim IDX_고정문자4 As Short
    Dim IDX_고정문자5 As Short
    Dim IDX_고정문자6 As Short
    Dim IDX_고정문자7 As Short


#Region "New Function"
    Public Sub New()
        InitializeComponent()
    End Sub
    Public Sub New(ByRef Src As DataTable, vdev As Boolean, ByVal vDefStyleIndex As Short, Optional ByVal IRow As DataRowView = Nothing, Optional DisWaterMK As Boolean = False)
        InitializeComponent()
        SrcTable = Src  '//가져온 테이블을 임시테이블에 저장을 해두고 사용한다.
        Srcrow = IRow  '//이것은 클릭된 행의 데이터이다.
        Me.Admin = vdev
        Me.DefStyleIndex = vDefStyleIndex
        DisableWaterMark = DisWaterMK '//190208
    End Sub
#End Region
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Left = 100
        Me.Initialize(Me.SrcTable, "StyleTS", My.Application.Info.DirectoryPath & "\epole.ini", DefStyleIndex)
    End Sub

    Public Overrides Sub SetControls()   '//오버라이드됫으며 라벨들을 생성초기화한다.

        AddLog("-> SetControls")
        Dim CtlCnt As Short = 0

        If Me.AllLabels Is Nothing Then ReDim Me.AllLabels(0) '//이건라벨들의 배열이며
        If Me.AllFullLabels Is Nothing Then ReDim Me.AllFullLabels(0) '//이건라벨들의 그룹배열이다. (쪼개지지않은 1개의 아이템을 가지고있다.)

        '//initial...
        Dim FirstIndex As Short = 0
        Dim A_Firstindex As Short = 0


        InitControl(Me.IDX_일련번호, A_Firstindex, FirstIndex, 1, 20, Me.cb_seq, "일련번호", "U", "SEQPATTERN")
        InitControl1(Me.IDX_간선명, A_Firstindex, FirstIndex, 20, 20, Me.chk1, "간선명", "A", "GANSUNPATTERN")
        InitControl(Me.IDX_전주번호, A_Firstindex, FirstIndex, 20, 20, Me.chk2, "전주번호", "B", "JUNJUPATTERN")

        '//간선2 와 번호2는 각각 1번과 통합된다 20090219 다시 되살렸음..
        'InitControl1(Me.IDX_간선명2, A_Firstindex, FirstIndex, 20, 10, Me.chk10, "간선명2", "J", "GANSUN2PATTERN")
        'InitControl(A_Firstindex, FirstIndex, 20, 10, Me.chk11, "전주번호2", "K", "JUNJU2PATTERN")

        InitControl(Me.IDX_시공일, A_Firstindex, FirstIndex, 20, 20, Me.chk3, "시공일", "C", "DATEPATTERN")
        InitControl(Me.IDX_시공자, A_Firstindex, FirstIndex, 1, 20, Me.chk4, "시공자", "D", "MANPATTERN")
        InitControl(Me.IDX_운용기관, A_Firstindex, FirstIndex, 1, 20, Me.chk5, "운용기관", "E", "ORGPATTERN")

        InitControl(Me.IDX_규격, A_Firstindex, FirstIndex, 1, 20, Me.chk6, "규격", "F", "SCAPATTERN")
        InitControl(Me.IDX_중계기명, A_Firstindex, FirstIndex, 1, 20, Me.chk7, "중계기명", "G", "SUNGKPATTERN")
        InitControl(Me.IDX_연락처1, A_Firstindex, FirstIndex, 1, 20, Me.chk8, "연락처1", "H", "TEL1PATTERN")
        InitControl(Me.IDX_연락처2, A_Firstindex, FirstIndex, 1, 20, Me.chk9, "연락처2", "I", "TEL2GPATTERN")

        InitControl(Me.IDX_단자함1, A_Firstindex, FirstIndex, 5, 10, Me.chk12, "단자함1", "L", "DAN1PATTERN")
        InitControl(Me.IDX_단자함2, A_Firstindex, FirstIndex, 5, 10, Me.chk13, "단자함2", "M", "DAN2PATTERN")
        InitControl(Me.IDX_단자함3, A_Firstindex, FirstIndex, 5, 10, Me.chk14, "단자함3", "N", "DAN3PATTERN")

        InitControl(Me.IDX_광단자함1, A_Firstindex, FirstIndex, 5, 10, Me.chk15, "광단자함1", "O", "GDAN1PATTERN")
        InitControl(Me.IDX_광단자함2, A_Firstindex, FirstIndex, 5, 10, Me.chk16, "광단자함2", "P", "GDAN2PATTERN")
        InitControl(Me.IDX_광단자함3, A_Firstindex, FirstIndex, 5, 10, Me.chk17, "광단자함3", "Q", "GDAN3PATTERN")
        InitControl(Me.IDX_광단자함4, A_Firstindex, FirstIndex, 5, 10, Me.chk22, "광단자함4", "W", "GDAN4PATTERN")

        InitControl(Me.IDX_한줄간선명, A_Firstindex, FirstIndex, 1, 10, Me.chk18, "한줄간선명", "R", "OGANPATTERN")
        InitControl(Me.IDX_한줄전주번호, A_Firstindex, FirstIndex, 1, 10, Me.chk19, "한줄전주번호", "S", "OJUNPATTERN")

        InitControl(Me.IDX_고정문자1, A_Firstindex, FirstIndex, 1, 10, Me.chkf1, "고정1", "U1", "STATIC1PATTERN", True)
        InitControl(Me.IDX_고정문자2, A_Firstindex, FirstIndex, 1, 10, Me.chkf2, "고정2", "U2", "STATIC2PATTERN", True)
        InitControl(Me.IDX_고정문자3, A_Firstindex, FirstIndex, 1, 10, Me.chkf3, "고정3", "U3", "STATIC3PATTERN", True)
        InitControl(Me.IDX_고정문자4, A_Firstindex, FirstIndex, 1, 10, Me.chkf4, "고정4", "U4", "STATIC4PATTERN", True)
        InitControl(Me.IDX_고정문자5, A_Firstindex, FirstIndex, 1, 10, Me.chkf5, "고정5", "U5", "STATIC5PATTERN", True)
        InitControl(Me.IDX_고정문자6, A_Firstindex, FirstIndex, 1, 10, Me.chkf6, "고정6", "U6", "STATIC6PATTERN", True)
        InitControl(Me.IDX_고정문자7, A_Firstindex, FirstIndex, 1, 10, Me.chkf7, "고정7", "U7", "STATIC7PATTERN", True)

        InitControl(Me.IDX_한줄단자함, A_Firstindex, FirstIndex, 1, 10, Me.chk23, "한줄단자함", "X", "DANPATTERN")
        InitControl(Me.IDX_한줄광단자함, A_Firstindex, FirstIndex, 1, 10, Me.chk27, "한줄광단자함", "Y", "GDANPATTERN")

        InitControl(Me.IDX_점용허가기관, A_Firstindex, FirstIndex, 1, 20, Me.chk24, "점용허가기관", "JA", "JAPATTERN")
        InitControl(Me.IDX_점용허가기간, A_Firstindex, FirstIndex, 1, 20, Me.chk25, "점용허가기간", "JB", "JBPATTERN")
        InitControl(Me.IDX_점용허가번호, A_Firstindex, FirstIndex, 1, 20, Me.chk26, "점용허가번호", "JC", "JCPATTERN")
    End Sub

    Public Overrides Sub SetControlIndex() '//그룹의 인덱스를 가지고있는 // 나중에 편하게 사용하려고
        AddLog("-> SetControlIndex")
        'Me.IDX_일련번호 = lbl("일련번호")
        'Me.IDX_전주번호 = lbl("전주번호")
        'Me.IDX_간선명 = lbl("간선명")
        'Me.IDX_시공일 = lbl("시공일")
        'Me.IDX_시공자 = lbl("시공자")
        'Me.IDX_운용기관 = lbl("운용기관")
        'Me.IDX_규격 = lbl("규격")
        'Me.IDX_중계기명 = lbl("중계기명")
        'Me.IDX_연락처1 = lbl("연락처1")
        'Me.IDX_연락처2 = lbl("연락처2")
        ''Me.IDX_간선명2 = lbl("간선명2")
        ''Me.IDX_전주번호2 = lbl("전주번호2")

        'Me.IDX_단자함1 = lbl("단자함1")
        'Me.IDX_단자함2 = lbl("단자함2")
        'Me.IDX_단자함3 = lbl("단자함3")

        'Me.IDX_광단자함1 = lbl("광단자함1")
        'Me.IDX_광단자함2 = lbl("광단자함2")
        'Me.IDX_광단자함3 = lbl("광단자함3")
        'Me.IDX_광단자함4 = lbl("광단자함4")

        'Me.IDX_한줄간선명 = lbl("한줄간선명")
        'Me.IDX_한줄전주번호 = lbl("한줄전주번호")

        'Me.IDX_고정문자1 = lbl("고정1")
        'Me.IDX_고정문자2 = lbl("고정2")
        'Me.IDX_고정문자3 = lbl("고정3")
        'Me.IDX_고정문자4 = lbl("고정4")
        'Me.IDX_고정문자5 = lbl("고정5")
        'Me.IDX_고정문자6 = lbl("고정6")
        'Me.IDX_고정문자7 = lbl("고정7")

        'Me.IDX_한줄단자함 = lbl("한줄단자함")
        'Me.IDX_한줄광단자함 = lbl("한줄광단자함")
    End Sub

    '//메인함수다(오버라이드) 값을 분석하고 표시하는 총괄을 담당한다.
    Public Overrides Sub GeTviewData(ByVal index As Integer, ByVal previewWindow As Boolean, Optional ByRef 번호패턴검사 As Integer = -1)
        Dim 전주번호, 전주번호2 As String
        Dim 간선명, 간선명2 As String
        Dim 단자함1, 단자함2, 단자함3, 한줄단자함 As String
        Dim 광단자함1, 광단자함2, 광단자함3, 광단자함4, 한줄광단자함 As String
        Dim 일련번호 As String
        한줄단자함 = ""
        한줄광단자함 = ""

        AddLog(">> 오버라이드된 함수 GetTviewData 진입")

        If Dv.Count <= 0 OrElse index < 0 OrElse index > Dv.Count Then
            AddLog(">> 데이터인덱스가 없거나 문제가 있어서 GettviewData를 리턴합니다")
            Return '//잘못된 인덱스는 리턴
        End If

        '//DataRow_Value -> Group Label
        전주번호 = GetSpread(index, "전주번호")
        전주번호2 = GetSpread(index, "전주번호2")
        간선명 = GetSpread(index, "간선명")
        간선명2 = GetSpread(index, "간선명2")

        단자함1 = GetSpread(index, "단자함1")
        단자함2 = GetSpread(index, "단자함2")
        단자함3 = GetSpread(index, "단자함3")

        광단자함1 = GetSpread(index, "광단자함1")
        광단자함2 = GetSpread(index, "광단자함2")
        광단자함3 = GetSpread(index, "광단자함3")
        광단자함4 = GetSpread(index, "광단자함4")

        일련번호 = GetSpread(index, "번호")

        QRCODE1 = GetSpread(index, "QRCODE")
        QRCODE2 = GetSpread(index, "QRCODE2")
        QRCODE3 = GetSpread(index, "QRCODE3")
        QRCODE4 = GetSpread(index, "QRCODE4")

        Me.AllFullLabels(Me.IDX_전주번호).text = 전주번호 & 전주번호2
        'Me.AllFullLabels(Me.IDX_전주번호2).text = 전주번호2
        Me.AllFullLabels(Me.IDX_일련번호).text = 일련번호
        Me.AllFullLabels(Me.IDX_간선명).text = 간선명 & 간선명2
        'Me.AllFullLabels(Me.IDX_간선명2).text = 간선명2
        Me.AllFullLabels(Me.IDX_시공일).text = GetSpread(index, "시공일")
        Me.AllFullLabels(Me.IDX_시공자).text = GetSpread(index, "시공자")
        Me.AllFullLabels(Me.IDX_운용기관).text = GetSpread(index, "운용기관")
        Me.AllFullLabels(Me.IDX_규격).text = GetSpread(index, "규격")
        Me.AllFullLabels(Me.IDX_중계기명).text = GetSpread(index, "중계기명")
        Me.AllFullLabels(Me.IDX_연락처1).text = GetSpread(index, "연락처1")
        Me.AllFullLabels(Me.IDX_연락처2).text = GetSpread(index, "연락처2")

        Me.AllFullLabels(Me.IDX_점용허가기관).text = GetSpread(index, "점용허가기관")
        Me.AllFullLabels(Me.IDX_점용허가기간).text = GetSpread(index, "점용허가기간")
        Me.AllFullLabels(Me.IDX_점용허가번호).text = GetSpread(index, "점용허가번호")

        Me.AllFullLabels(Me.IDX_단자함1).text = 단자함1
        Me.AllFullLabels(Me.IDX_단자함2).text = 단자함2
        Me.AllFullLabels(Me.IDX_단자함3).text = 단자함3
        Me.AllFullLabels(Me.IDX_광단자함1).text = 광단자함1
        Me.AllFullLabels(Me.IDX_광단자함2).text = 광단자함2
        Me.AllFullLabels(Me.IDX_광단자함3).text = 광단자함3
        Me.AllFullLabels(Me.IDX_광단자함4).text = 광단자함4

        Me.AllFullLabels(Me.IDX_한줄간선명).text = 간선명 & 간선명2
        Me.AllFullLabels(Me.IDX_한줄전주번호).text = 전주번호 & 전주번호2

        한줄단자함 = 단자함1 & "-" & 단자함2 & "-" & 단자함3
        한줄광단자함 = 광단자함1 & "-" & 광단자함2 & "-" & 광단자함3 & "-" & 광단자함4

        If 한줄단자함 = "--" Then 한줄단자함 = ""
        If 한줄광단자함 = "---" Then 한줄광단자함 = ""

        Me.AllFullLabels(Me.IDX_한줄단자함).text = 한줄단자함
        Me.AllFullLabels(Me.IDX_한줄광단자함).text = 한줄광단자함

        Me.AllFullLabels(Me.IDX_고정문자1).text = Me.Fixed(0)
        Me.AllFullLabels(Me.IDX_고정문자2).text = Me.Fixed(1)
        Me.AllFullLabels(Me.IDX_고정문자3).text = Me.Fixed(2)
        Me.AllFullLabels(Me.IDX_고정문자4).text = Me.Fixed(3)
        Me.AllFullLabels(Me.IDX_고정문자5).text = Me.Fixed(4)
        Me.AllFullLabels(Me.IDX_고정문자6).text = Me.Fixed(5)
        Me.AllFullLabels(Me.IDX_고정문자7).text = Me.Fixed(6)


        AddLog(">> DataRow_Value -> Group Label_text")

        '//Show WindowTitle
        Me.Text = "출력작업(전주:" & 전주번호 & 전주번호2 & Space(1) & "간선:" & 간선명 & 간선명2 & ")"

        '=====================================================================
        Me.Parse_LineBatch(New Short() { _
        Me.IDX_일련번호, _
        Me.IDX_간선명, _
        Me.IDX_간선명2, _
        Me.IDX_전주번호, _
        Me.IDX_시공일, _
        Me.IDX_시공자, _
        Me.IDX_운용기관, _
        Me.IDX_규격, _
        Me.IDX_중계기명, _
        Me.IDX_연락처1, _
        Me.IDX_연락처2, _
        Me.IDX_점용허가기관, _
        Me.IDX_점용허가기간, _
        Me.IDX_점용허가번호, _
        Me.IDX_단자함1, _
        Me.IDX_단자함2, _
        Me.IDX_단자함3, _
        Me.IDX_광단자함1, _
        Me.IDX_광단자함2, _
        Me.IDX_광단자함3, _
        Me.IDX_광단자함4, _
        Me.IDX_한줄간선명, _
        Me.IDX_한줄전주번호, _
        Me.IDX_고정문자1, _
        Me.IDX_고정문자2, _
        Me.IDX_고정문자3, _
        Me.IDX_고정문자4, _
        Me.IDX_고정문자5, _
        Me.IDX_고정문자6, _
        Me.IDX_고정문자7, _
        Me.IDX_한줄단자함, _
        Me.IDX_한줄광단자함})
        '======================== 기타 =================================================
        If previewWindow Then Me.preview_window() '//이건 기본폼에 정의되어있다.
        '휴 끝났다.......................................................
    End Sub
    
#Region "자주 바꿀일없는 부분"

    Private Sub BindingNavigatorPositionItem_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles BindingNavigatorPositionItem.KeyUp
        '//현재위치에서 엔터켯을경우 데이터베이스 위치값을 변경한다.(position)
        If e.KeyCode = Keys.Enter Then
            If IsNumeric(Me.BindingNavigatorPositionItem.Text) Then Me.GeTviewData(Me.BindingNavigatorPositionItem.Text - 1, True)
        End If
    End Sub

    Private Sub BindingNavigatorPositionItem_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorPositionItem.MouseEnter
        Me.BindingNavigatorPositionItem.Focus()
        Me.BindingNavigatorPositionItem.SelectAll()
    End Sub

#End Region
#Region "자주안고치는것"

    ''' <summary>
    ''' 데이터표시항목아래의 모든 아이템의 클릭이벤트에  지정된 프로시져를 할당한다.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Sub SetEventHandler()
        For Each MI As ToolStripMenuItem In Me.m_viewdata.DropDownItems
            AddHandler MI.Click, AddressOf ViewCheck_Click
        Next
    End Sub

    Private Sub PrintForm_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles Me.Scroll

    End Sub

    ''' <summary>
    ''' 개체가 선택되었을때 의 이벤트
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <remarks></remarks>
    Private Sub PrintForm_tongsin_SelectedControl(ByVal obj As CEpole.C_label) Handles Me.SelectedControl
        '//특정개체가 선택되었을때 (부모그룹에서 패턴적용여부를 찾아표시한다.)
        AddLog("##다음개체가 선택되었습니다(" & obj.Desc & " 태그=" & obj.Tag & ")")
        Me.lb_selcon.Text = "[" & obj.Desc & "]"
    End Sub

    Private Sub ToolStripButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_close.Click
        Me.Close()
    End Sub
    Private Sub m_shortkey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_shortkey.Click
        Me.Show_ShortKey()
    End Sub

#End Region
  
   
   
    Private Sub bt_savestyle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_savestyle.Click

    End Sub

    Private Sub BS_CurrentChanged(sender As System.Object, e As System.EventArgs) Handles BS.CurrentChanged

    End Sub

    Private Sub bt_savelen_Click(sender As System.Object, e As System.EventArgs) Handles bt_savelen.Click

    End Sub
End Class


