Option Strict Off
Option Explicit On

Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Friend Class frmCadastroMetasIndicadores
    Inherits System.Windows.Forms.Form
    Dim vAno As Integer
    Dim vAnoOld As Integer

#Region "Propriedades"

    Private Sub frmCadMetasIndicadores_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

        Try

            Me.txtAno.Text = Date.Now.Year.ToString()
            cmdBusca_Click(cmdBusca, New System.EventArgs())

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtAno_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtAno.Enter

        Try

            With Me.txtAno
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtAno_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtAno.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try

            If KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtAno.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtAno.Leave


        Try

            With Me.txtAno
                .Text = Format(Convert.ToDouble(IIf(IsNumeric(.Text), .Text, 0)), "#0")
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecAnual_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDecAnual.Enter

        Try

            With Me.txtDecAnual
                .SelectionStart = 0
                .SelectionLength = Convert.ToInt32(Len(.Text))
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecAnual_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtDecAnual.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try

            If KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtDecAnual.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecAnual_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDecAnual.Leave


        Try

            With Me.txtDecAnual
                .Text = Format(Convert.ToDouble(IIf(IsNumeric(.Text), .Text, 0)), "#,##0.00")
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecTri_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDecTri.Enter

        Try

            With Me.txtDecTri
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecTri_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtDecTri.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try

            If KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtDecTri.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecTri_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDecTri.Leave


        Try


            With Me.txtDecTri
                .Text = Format(Convert.ToDouble(IIf(IsNumeric(.Text), .Text, 0)), "#,##0.00")
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecMes_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDecMes.Enter


        Try

            With Me.txtDecMes
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecMes_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtDecMes.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try


            If KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtDecMes.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtDecMes_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDecMes.Leave


        Try

            With Me.txtDecMes
                .Text = Format(Convert.ToDouble(IIf(IsNumeric(.Text), .Text, 0)), "#,##0.00")
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecAnual_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtFecAnual.Enter


        Try

            With Me.txtFecAnual
                .SelectionStart = 0
                .SelectionLength = Convert.ToInt32(Len(.Text))
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecAnual_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtFecAnual.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try

            If KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtFecAnual.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecAnual_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtFecAnual.Leave

        Try

            With Me.txtFecAnual
                .Text = Format(Convert.ToDouble(IIf(IsNumeric(.Text), .Text, 0)), "#,##0.00")
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecTri_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtFecTri.Enter

        Try

            With Me.txtFecTri
                .SelectionStart = 0
                .SelectionLength = Convert.ToInt32(Len(.Text))
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecTri_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtFecTri.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try

            If KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtFecTri.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecTri_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtFecTri.Leave


        Try

            With Me.txtFecTri
                .Text = Format(Convert.ToDouble(IIf(IsNumeric(.Text), .Text, 0)), "#,##0.00")
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecMes_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtFecMes.Enter


        Try

            With Me.txtFecMes
                .SelectionStart = 0
                .SelectionLength = CInt(Len(.Text))
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecMes_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtFecMes.KeyPress

        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        Try


            If KeyAscii = System.Windows.Forms.Keys.Return Then
                TabEnter(KeyAscii, eventArgs)
            ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
                If KeyAscii = System.Windows.Forms.Keys.Delete Then
                    KeyAscii = System.Windows.Forms.Keys.Snapshot
                End If
                If KeyAscii <> System.Windows.Forms.Keys.Snapshot Then
                    KeyAscii = 0
                Else
                    If InStr(1, Me.txtFecMes.Text, ",") > 0 Then
                        KeyAscii = 0
                    End If
                End If
            End If

            eventArgs.KeyChar = Chr(KeyAscii)

            If KeyAscii = 0 Then
                eventArgs.Handled = True
            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub txtFecMes_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtFecMes.Leave


        Try

            With Me.txtFecMes
                .Text = Format(Convert.ToDouble(IIf(IsNumeric(.Text), .Text, 0)), "#,##0.00")
            End With

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub cmdBusca_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBusca.Click

        Dim llngAno As Integer

        Dim vlist

        Dim objICReferencia As New entidadeICReferencia
        Dim repositorioICReferencia As New repositorioICReferencia

        Try

            llngAno = CInt(IIf(IsNumeric(Me.txtAno.Text), Me.txtAno.Text, 0))

            If llngAno > 0 Then

                objICReferencia.ANO = llngAno

                vlist = repositorioICReferencia.Select_1(objICReferencia)

                If vlist.Count > 0 Then

                    For Each objICReferenciaFor As entidadeICReferencia In vlist

                        Me.txtDecAnual.Text = VB6.Format(IIf(IsDBNull(objICReferenciaFor.ID_DEC), 0, objICReferenciaFor.ID_DEC), "#,##0.00")
                        Me.txtFecAnual.Text = VB6.Format(IIf(IsDBNull(objICReferenciaFor.ID_FEC), 0, objICReferenciaFor.ID_FEC), "#,##0.00")
                        Me.txtDecTri.Text = VB6.Format(IIf(IsDBNull(objICReferenciaFor.DEC_TRIMESTRAL), 0, objICReferenciaFor.DEC_TRIMESTRAL), "#,##0.00")
                        Me.txtDecMes.Text = VB6.Format(IIf(IsDBNull(objICReferenciaFor.DEC_MENSAL), 0, objICReferenciaFor.DEC_MENSAL), "#,##0.00")
                        Me.txtFecTri.Text = VB6.Format(IIf(IsDBNull(objICReferenciaFor.FEC_TRIMESTRAL), 0, objICReferenciaFor.FEC_TRIMESTRAL), "#,##0.00")
                        Me.txtFecMes.Text = VB6.Format(IIf(IsDBNull(objICReferenciaFor.FEC_MENSAL), 0, objICReferenciaFor.FEC_MENSAL), "#,##0.00")



                    Next

                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try


    End Sub

    Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click

        Try

            lClose()

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub cmdNovo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNovo.Click

        Try

            lNew()

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

    Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click

        Dim lblnExi As Boolean

        Dim llngAno As Integer

        Dim vlist

        Dim objICReferencia As New entidadeICReferencia
        Dim repositorioICReferencia As New repositorioICReferencia

        Try

            llngAno = CInt(IIf(IsNumeric(Me.txtAno.Text), Me.txtAno.Text, 0))
            lblnExi = False

            If llngAno > 0 Then

                objICReferencia.ANO = llngAno

                vlist = repositorioICReferencia.Select_1(objICReferencia)

                If vlist.Count > 0 Then
                    lblnExi = True
                End If

                vAno = llngAno
                vAnoOld = llngAno - 1

                If Not lblnExi Then

                    objICReferencia.ANO = vAnoOld

                    vlist = repositorioICReferencia.Select_1(objICReferencia)

                    If vlist.Count > 0 Then

                        For Each objICReferenciaFor As entidadeICReferencia In vlist


                            If lInsert() Then
                                MessageBox.Show("Metas de DEC e FEC criadas com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                            Else
                                MessageBox.Show("Metas de DEC e FEC não podem ser criadas!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                                Exit Sub
                            End If

                        Next

                    End If
                Else

                    If lUpdate() Then
                        MessageBox.Show("Metas de DEC e FEC atualizadas com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Else
                        MessageBox.Show("Metas de DEC e FEC não podem ser atualizadas!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Exit Sub
                    End If

                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Ocorreu um Erro Inesperado. Favor, Contate o Administrador do Sistema ou a Equipe de Suporte de sua localidade! ", "Fatal - Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

    End Sub

#End Region

#Region "Métodos"


    Private Sub lNew()

        Try

            lClear()

        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Private Sub lClear()

        Try

            Me.txtDecAnual.Text = String.Empty
            Me.txtDecTri.Text = String.Empty
            Me.txtDecMes.Text = String.Empty
            Me.txtFecAnual.Text = String.Empty
            Me.txtFecTri.Text = String.Empty
            Me.txtFecMes.Text = String.Empty

        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Private Sub lClose()

        Try

            Close()

        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Private Function lInsert() As Boolean

        Dim objICReferencia As New entidadeICReferencia
        Dim repositorioICReferencia As New repositorioICReferencia

        Try

            objICReferencia.ANO = vAno
            objICReferencia.ID_DEC = vAnoOld

            repositorioICReferencia.Insert(objICReferencia)

            Return True
        Catch ex As Exception
            Return False
        End Try

    End Function

    Private Function lUpdate() As Boolean

        Dim objICReferencia As New entidadeICReferencia
        Dim repositorioICReferencia As New repositorioICReferencia


        Try


            objICReferencia.ID_DEC = Convert.ToInt32(CDbl(IIf(IsNumeric(Me.txtDecAnual.Text), Me.txtDecAnual.Text, 0)))
            objICReferencia.ID_FEC = Convert.ToInt32(CDbl(IIf(IsNumeric(Me.txtFecAnual.Text), Me.txtFecAnual.Text, 0)))
            objICReferencia.DEC_TRIMESTRAL = Convert.ToDouble(CDbl(IIf(IsNumeric(Me.txtDecTri.Text), Me.txtDecTri.Text, 0)))
            objICReferencia.DEC_MENSAL = Convert.ToDouble(CDbl(IIf(IsNumeric(Me.txtDecMes.Text), Me.txtDecMes.Text, 0)))
            objICReferencia.FEC_TRIMESTRAL = Convert.ToDouble(CDbl(IIf(IsNumeric(Me.txtFecTri.Text), Me.txtFecTri.Text, 0)))
            objICReferencia.FEC_MENSAL = Convert.ToDouble(CDbl(IIf(IsNumeric(Me.txtFecMes.Text), Me.txtFecMes.Text, 0)))
            objICReferencia.ANO = vAno


            repositorioICReferencia.Update(objICReferencia)

            Return True
        Catch ex As Exception
            Return False
        End Try

    End Function

#End Region



End Class