VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Object = "{C4DED68B-C40F-11D6-AD1A-000795CA0957}#50.0#0"; "pry_list.ocx"
Begin VB.Form FCliente_TPC 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Relacion Cliente-TPC (01.310.00)"
   ClientHeight    =   4110
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7815
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   4110
   ScaleWidth      =   7815
   Begin TabDlg.SSTab SSTab1 
      Height          =   6495
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   7815
      _ExtentX        =   13785
      _ExtentY        =   11456
      _Version        =   393216
      Tab             =   2
      TabHeight       =   520
      TabCaption(0)   =   "Cliente"
      TabPicture(0)   =   "0131000.frx":0000
      Tab(0).ControlEnabled=   0   'False
      Tab(0).Control(0)=   "Label1"
      Tab(0).Control(0).Enabled=   0   'False
      Tab(0).Control(1)=   "Label2"
      Tab(0).Control(1).Enabled=   0   'False
      Tab(0).Control(2)=   "Line1"
      Tab(0).Control(2).Enabled=   0   'False
      Tab(0).Control(3)=   "Line2"
      Tab(0).Control(3).Enabled=   0   'False
      Tab(0).Control(4)=   "Label3"
      Tab(0).Control(4).Enabled=   0   'False
      Tab(0).Control(5)=   "lstClientes"
      Tab(0).Control(5).Enabled=   0   'False
      Tab(0).Control(6)=   "lstClienteInfo"
      Tab(0).Control(6).Enabled=   0   'False
      Tab(0).Control(7)=   "lstTPCInfo"
      Tab(0).Control(7).Enabled=   0   'False
      Tab(0).Control(8)=   "cmdAceptar"
      Tab(0).Control(8).Enabled=   0   'False
      Tab(0).Control(9)=   "crCliente_TPC"
      Tab(0).Control(9).Enabled=   0   'False
      Tab(0).Control(10)=   "cmdRelacionar"
      Tab(0).Control(10).Enabled=   0   'False
      Tab(0).ControlCount=   11
      TabCaption(1)   =   "TPC"
      TabPicture(1)   =   "0131000.frx":001C
      Tab(1).ControlEnabled=   0   'False
      Tab(1).Control(0)=   "lstTPC"
      Tab(1).Control(0).Enabled=   0   'False
      Tab(1).ControlCount=   1
      TabCaption(2)   =   "Consulta / Eliminar"
      TabPicture(2)   =   "0131000.frx":0038
      Tab(2).ControlEnabled=   -1  'True
      Tab(2).Control(0)=   "fraBusqueda"
      Tab(2).Control(0).Enabled=   0   'False
      Tab(2).ControlCount=   1
      Begin VB.CommandButton cmdRelacionar 
         Caption         =   "Relacionar"
         Enabled         =   0   'False
         Height          =   735
         Left            =   -68520
         Picture         =   "0131000.frx":0054
         Style           =   1  'Graphical
         TabIndex        =   11
         Top             =   840
         Visible         =   0   'False
         Width           =   735
      End
      Begin Crystal.CrystalReport crCliente_TPC 
         Left            =   -67920
         Top             =   3360
         _ExtentX        =   741
         _ExtentY        =   741
         _Version        =   348160
         PrintFileLinesPerPage=   60
      End
      Begin VB.CommandButton cmdAceptar 
         Caption         =   "Aceptar"
         Enabled         =   0   'False
         Height          =   375
         Left            =   -68400
         TabIndex        =   14
         Top             =   5760
         Width           =   975
      End
      Begin VB.ListBox lstTPCInfo 
         Height          =   840
         Left            =   -71040
         TabIndex        =   13
         Top             =   4800
         Width           =   3615
      End
      Begin VB.ListBox lstClienteInfo 
         Height          =   840
         Left            =   -74760
         TabIndex        =   12
         Top             =   4800
         Width           =   3615
      End
      Begin VB.Frame fraBusqueda 
         Caption         =   "Buscar por"
         Height          =   3255
         Left            =   240
         TabIndex        =   3
         Top             =   600
         Width           =   7335
         Begin Crystal.CrystalReport crReporte 
            Left            =   6360
            Top             =   480
            _ExtentX        =   741
            _ExtentY        =   741
            _Version        =   348160
            PrintFileLinesPerPage=   60
         End
         Begin MSDataGridLib.DataGrid dbDetalle 
            Height          =   1695
            Left            =   240
            TabIndex        =   10
            Top             =   1320
            Width           =   6855
            _ExtentX        =   12091
            _ExtentY        =   2990
            _Version        =   393216
            HeadLines       =   1
            RowHeight       =   15
            BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Caption         =   "[F3]_Eliminar Registro,   Haga Click en cabecera para ordenar"
            ColumnCount     =   2
            BeginProperty Column00 
               DataField       =   ""
               Caption         =   ""
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   3082
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column01 
               DataField       =   ""
               Caption         =   ""
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   3082
                  SubFormatType   =   0
               EndProperty
            EndProperty
            SplitCount      =   1
            BeginProperty Split0 
               BeginProperty Column00 
               EndProperty
               BeginProperty Column01 
               EndProperty
            EndProperty
         End
         Begin VB.CommandButton cmdBusCliente 
            Enabled         =   0   'False
            Height          =   375
            Left            =   5280
            MouseIcon       =   "0131000.frx":035E
            MousePointer    =   99  'Custom
            Picture         =   "0131000.frx":04B0
            Style           =   1  'Graphical
            TabIndex        =   8
            ToolTipText     =   "Buscar Tipo de Ingreso"
            Top             =   720
            Width           =   375
         End
         Begin VB.CommandButton cmdBusTPC 
            Height          =   375
            Left            =   5280
            MouseIcon       =   "0131000.frx":09E2
            MousePointer    =   99  'Custom
            Picture         =   "0131000.frx":0B34
            Style           =   1  'Graphical
            TabIndex        =   6
            ToolTipText     =   "Buscar Tipo de Ingreso"
            Top             =   360
            Width           =   375
         End
         Begin VB.OptionButton optCliente 
            Caption         =   "Cliente"
            Height          =   255
            Left            =   240
            TabIndex        =   5
            Top             =   720
            Width           =   855
         End
         Begin VB.OptionButton optTPC 
            Caption         =   "TPC"
            Height          =   255
            Left            =   240
            TabIndex        =   4
            Top             =   360
            Value           =   -1  'True
            Width           =   735
         End
         Begin MSDataListLib.DataCombo dtcTPC 
            Height          =   315
            Left            =   1200
            TabIndex        =   7
            Top             =   360
            Width           =   3975
            _ExtentX        =   7011
            _ExtentY        =   556
            _Version        =   393216
            Style           =   2
            Text            =   ""
         End
         Begin MSDataListLib.DataCombo dtcCliente 
            Height          =   315
            Left            =   1200
            TabIndex        =   9
            Top             =   720
            Width           =   3975
            _ExtentX        =   7011
            _ExtentY        =   556
            _Version        =   393216
            Enabled         =   0   'False
            Style           =   2
            Text            =   ""
         End
      End
      Begin pry_list.ctrl_listarray lstClientes 
         Height          =   2895
         Left            =   -74520
         TabIndex        =   1
         Top             =   720
         Width           =   6975
         _ExtentX        =   12303
         _ExtentY        =   5106
         Enabled         =   0   'False
      End
      Begin pry_list.ctrl_listarray lstTPC 
         Height          =   3015
         Left            =   -74520
         TabIndex        =   2
         Top             =   720
         Width           =   6975
         _ExtentX        =   12303
         _ExtentY        =   5318
         Enabled         =   0   'False
      End
      Begin VB.Label Label3 
         Caption         =   "Las siguientes relaciones no se pueden efectuar por que ya existen"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   -74760
         TabIndex        =   17
         Top             =   4080
         Width           =   5895
      End
      Begin VB.Line Line2 
         X1              =   -74760
         X2              =   -67440
         Y1              =   6240
         Y2              =   6240
      End
      Begin VB.Line Line1 
         X1              =   -74760
         X2              =   -67440
         Y1              =   3960
         Y2              =   3960
      End
      Begin VB.Label Label2 
         Caption         =   "TPC"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   -69480
         TabIndex        =   16
         Top             =   4560
         Width           =   855
      End
      Begin VB.Label Label1 
         Caption         =   "Cliente"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   -73320
         TabIndex        =   15
         Top             =   4560
         Width           =   1095
      End
   End
End
Attribute VB_Name = "FCliente_TPC"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Programador: Edgar Cancho Ruiz
' Empresa Texaco
' Modulo de Relacionamiento de Cliente-TPC
' Fecha : 06/12/2002

Option Explicit

'Variables para el Control de la Barra General
 Public pb_editar As Boolean
 Public pb_agregar As Boolean
 Public pb_primerregistro As Boolean
 Public pb_ultimoregistro As Boolean
 Public pbderecho_agregar As Boolean
 Public pbderecho_consultar As Boolean
 Public pbderecho_editar As Boolean
 Public pbderecho_borrar As Boolean
 Public pbderecho_imprimir As Boolean
 Public pbderecho_anular As Boolean
 Public pbderecho_emitir As Boolean
 Public pb_tiposcreen As String
 
Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String

 
 Public objHist_Pre_Cli As DB_MA_MANTENIMIENTOS.C_HIST_PRE_CLI
 Public objCliente As DB_MA_MANTENIMIENTOS.C_CLIENTE
 
 Dim MatrizCliente
 Dim MatrizTPC
 Private MstrOrden As String
 Private MrsRegistros As ADODB.Recordset

Private Sub cmdaceptar_Click()
    lstClientes.Enabled = True
    lstTPC.Enabled = True
    lstClienteInfo.Clear
    lstTPCInfo.Clear
    Me.Height = 4485
End Sub

Private Sub cmdBusCliente_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "CUSTIDSS"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1500
    ArrayBusqueda(2, 1) = "CUSTNAME"
    ArrayBusqueda(2, 2) = "Nombre "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasMa.GObtenerRegistros objCliente.ListarClientesAyudaTPC, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcCliente.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdBusTPC_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "PRCLVLCUSTID"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1500
    ArrayBusqueda(2, 1) = "DESCR"
    ArrayBusqueda(2, 2) = "Descripcion "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasMa.GObtenerRegistros objHist_Pre_Cli.SeleccionaListaTPC, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcTPC.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdRelacionar_Click()
'On Error GoTo errhandler
Dim i As Integer, j As Integer

    If lstClientes.nseleccionados = 0 Then
        MsgBox "Seleccione al menos un cliente", vbExclamation, "Faltan Datos"
        SSTab1.Tab = 0
        Exit Sub
    End If
    If lstTPC.nseleccionados = 0 Then
        MsgBox "Seleccione al menos un TPC", vbExclamation, "Faltan Datos"
        SSTab1.Tab = 1
        Exit Sub
    End If
        
    MatrizCliente = lstClientes.llenar_matrizseleccionados
    MatrizTPC = lstTPC.llenar_matrizseleccionados
    
    ' SE VALIDA QUE NO SE INGRESE UNA RELACION EXISTENTE
    For i = 1 To lstClientes.nseleccionados
        For j = 1 To lstTPC.nseleccionados
            If objHist_Pre_Cli.ExisteClienteTPC(CStr(MatrizCliente(i, 1)), CStr(MatrizTPC(j, 1))) Then
                lstClienteInfo.AddItem MatrizCliente(i, 2)
                lstTPCInfo.AddItem MatrizTPC(j, 2)
            End If
        Next j
    Next i

    ' SE VALIDA QUE SE REPITA UN ARTICULO DENTRO DE UNA RELACION TPC-ALMACEN PARA UN CLIENTE
    If lstClienteInfo.ListCount = 0 Then
        For i = 1 To lstClientes.nseleccionados
           If Not valida_datos(CStr(MatrizCliente(i, 1)), lstTPC.listar_codigos_seleccionados) Then
                FMensajeTPC.McodCliente = CStr(MatrizCliente(i, 1))
                FMensajeTPC.MdesCliente = CStr(MatrizCliente(i, 2))
                FMensajeTPC.Mcadena = lstTPC.listar_codigos_seleccionados
                FMensajeTPC.Show vbModal
                Exit Sub
           End If
        Next i
    Else
        MsgBox "Error insertando relaciones ", vbInformation, "Cliente-TPC"
        Me.Height = 6720
        
        Exit Sub
    End If

    For i = 1 To lstClientes.nseleccionados
        For j = 1 To lstTPC.nseleccionados
            objHist_Pre_Cli.AgregarClienteTPC CStr(MatrizCliente(i, 1)), CStr(MatrizTPC(j, 1)), GCUSERID
        Next j
    Next i


    pb_agregar = False
    pb_editar = False
    Call gactualiza_barra(Me) 'frm.pb_editar, frm.pb_primerregistro, frm.pb_ultimoregistro)
    Call gHabilitarReg(Me, pb_editar)
    Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
    MsgBox "Relacionamiento Realizado con éxito ", vbInformation, "Cliente-TPC"

    
'Exit Sub
'errhandler:
'    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"
'
End Sub

Private Sub dbDetalle_HeadClick(ByVal ColIndex As Integer)
  If ColIndex = 0 Then
    MrsRegistros.Sort = "Codigo " & MstrOrden
  Else
    If optTPC.Value Then
        MrsRegistros.Sort = "Nombre " & MstrOrden
    Else
        MrsRegistros.Sort = "Descripcion " & MstrOrden
    End If
  End If
  
  If MstrOrden = "ASC" Then
     MstrOrden = "DESC"
  Else
     MstrOrden = "ASC"
  End If
End Sub

Private Sub DBDetalle_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF3 And pbderecho_borrar Then
        If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
            
            If MsgBox("Esta Seguro Que Desea Eliminar el Registro. ", vbQuestion + vbYesNo, "Eliminar") = vbNo Then
                Exit Sub
            Else
                If optCliente.Value Then
                    objHist_Pre_Cli.EliminarRelacion_Cliente_TPC dtcCliente.BoundText, DBDetalle.Columns(0).Text
                    Carga_TPC_Cliente
                Else
                    objHist_Pre_Cli.EliminarRelacion_Cliente_TPC DBDetalle.Columns(0).Text, dtcTPC.BoundText
                    Carga_Clientes_TPC
                End If
                Exit Sub
            End If
        End If
    End If
End Sub

Private Sub dtcCliente_Change()
   Carga_TPC_Cliente
End Sub

Private Sub dtcCliente_Click(Area As Integer)
    Carga_TPC_Cliente
End Sub

Private Sub dtcTPC_Change()
  Carga_Clientes_TPC
End Sub

Private Sub dtcTPC_Click(Area As Integer)
    Carga_Clientes_TPC
End Sub

Private Sub Form_Activate()
    Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
    Call gactualiza_barra(Me)
    If pbderecho_consultar = False Then
       Unload Me
    End If
End Sub

Private Sub Form_Load()
Screen.MousePointer = 11

  Call gseguridad(Me)
  If pbderecho_consultar Then
   
    MstrOrden = "ASC"
    SSTab1.Tab = 0
    Set objHist_Pre_Cli = New DB_MA_MANTENIMIENTOS.C_HIST_PRE_CLI
    Set objCliente = New DB_MA_MANTENIMIENTOS.C_CLIENTE
    
    Call CargaDataCombo(dtcCliente, objCliente.ListarClientesAyudaTPC, "CUSTIDSS", "CUSTNAME")
    Call CargaDataCombo(dtcTPC, objHist_Pre_Cli.SeleccionaListaTPC, "PRCLVLCUSTID", "DESCR")
    
    Carga_TPC_Cliente
    CargaListas
    'Call gHabilitarReg(Me, False)
    
  Else
     MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
     Screen.MousePointer = 0
     Exit Sub
  End If


        Me.Top = 100
        Me.Left = (Screen.Width - Me.Width) / 2
          
Screen.MousePointer = 0
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
pb_agregar = False
pb_editar = False
Call gHabilitarReg(Me, pb_editar)
Call gactualiza_barra(Me) 'frm.pb_editar, frm.pb_primerregistro, frm.pb_ultimoregistro)
Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
Call gdesactiva_barra

End Sub

Private Sub CargaListas()
    lstClientes.llena_lista objCliente.ListarClientesAyudaTPC
    lstTPC.llena_lista objHist_Pre_Cli.SeleccionaListaTPC
    lstClientes.Size 15, 35
    lstTPC.Size 15, 30
    
End Sub


Public Sub CargaDataCombo(objDataCombo As DataCombo, rsSource As Recordset, istrCampo1 As String, istrCampo2 As String)

    Set objDataCombo.DataSource = rsSource
    objDataCombo.DataField = istrCampo2
    Set objDataCombo.RowSource = rsSource
    objDataCombo.ListField = istrCampo2
    objDataCombo.BoundColumn = istrCampo1
    
    If Not rsSource.EOF Then
        objDataCombo.BoundText = rsSource.Fields(istrCampo2)
    End If

End Sub

Private Sub lstClienteInfo_Click()
    lstTPCInfo.ListIndex = lstClienteInfo.ListIndex
End Sub

Private Sub lstTPCInfo_Click()
    lstClienteInfo.ListIndex = lstTPCInfo.ListIndex
End Sub

Private Function valida_datos(CODIGO_CLIENTE As String, CODIGOS_TPC As String) As Boolean
    Dim rsTemporal As ADODB.Recordset

    Set rsTemporal = objHist_Pre_Cli.ValidaClienteTPC(CODIGO_CLIENTE, CODIGOS_TPC)
    valida_datos = False
    
    If rsTemporal.EOF Then
        valida_datos = True
    End If
    
End Function


Private Sub Carga_Clientes_TPC()
    Set MrsRegistros = objHist_Pre_Cli.ObtieneClientes_Por_TPC(dtcTPC.BoundText)
    Set DBDetalle.DataSource = MrsRegistros
    FormatoGrilla
    DBDetalle.Refresh
End Sub

Private Sub Carga_TPC_Cliente()
    Set MrsRegistros = objHist_Pre_Cli.ObtieneTPC_Por_Cliente(dtcCliente.BoundText)
    Set DBDetalle.DataSource = MrsRegistros
    FormatoGrilla
    DBDetalle.Refresh
End Sub

Private Sub FormatoGrilla()
    DBDetalle.Columns(0).Width = 1500
    DBDetalle.Columns(1).Width = 4000
End Sub

Private Sub optCliente_Click()
    Call CargaDataCombo(dtcCliente, objCliente.ListarClientesAyudaTPC, "CUSTIDSS", "CUSTNAME")
    Call CargaDataCombo(dtcTPC, objHist_Pre_Cli.SeleccionaListaTPC, "PRCLVLCUSTID", "DESCR")
    dtcCliente.Enabled = True
    cmdBusCliente.Enabled = True
    dtcTPC.Enabled = False
    cmdBusTPC.Enabled = False
    Carga_TPC_Cliente
End Sub

Private Sub optTPC_Click()
    Call CargaDataCombo(dtcTPC, objHist_Pre_Cli.SeleccionaListaTPC, "PRCLVLCUSTID", "DESCR")
    Call CargaDataCombo(dtcCliente, objCliente.ListarClientesAyudaTPC, "CUSTIDSS", "CUSTNAME")
    dtcCliente.Enabled = False
    cmdBusCliente.Enabled = False
    dtcTPC.Enabled = True
    cmdBusTPC.Enabled = True
    Carga_Clientes_TPC
End Sub

Public Sub borrar_registro()

On Error GoTo errhandler

        If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
            If optCliente.Value Then
                objHist_Pre_Cli.EliminarRelacion_Cliente_TPC dtcCliente.BoundText, DBDetalle.Columns(0).Text
                Carga_TPC_Cliente
            Else
                objHist_Pre_Cli.EliminarRelacion_Cliente_TPC DBDetalle.Columns(0).Text, dtcTPC.BoundText
                Carga_Clientes_TPC
            End If
        End If

Exit Sub

errhandler:
    MsgBox MensajedeError(ERR.Number, ERR.Description), vbDefaultButton1 + vbCritical, "Error"

End Sub

Public Sub grabar_registro()
    cmdRelacionar_Click
    lstClientes.Enabled = False
    lstTPC.Enabled = False
    optCliente.Enabled = True
    optTPC.Enabled = True
    optTPC_Click
End Sub
Public Sub actualizar_registro()
'    Call obtener_datos
'    Call asigna_campos
End Sub
Public Sub agregar_registro()
    lstClientes.Enabled = True
    lstTPC.Enabled = True
    Call gagregar_registro(Me, lstClientes)
    fraBusqueda.Enabled = True
    optTPC_Click
End Sub
Public Sub modificar_registro()
    'Call gmodificar_registro(Me, txtCodigo)
End Sub
Public Sub descartar_registro()
    Call gdescartar_registro(Me)
    lstClientes.Enabled = False
    lstTPC.Enabled = False
    cmdaceptar_Click
    fraBusqueda.Enabled = True
    optCliente.Enabled = True
    optTPC.Enabled = True
    optTPC_Click
End Sub

Sub salir_formulario()
    MDIFMaestros.Toolbar1.Buttons(18).Caption = "Salir"    ' boton salir
    Unload Me
End Sub

Sub imprimir()
    
    crReporte.ReportFileName = GstrReportesInv + "rpt_Relacion_TPC_Cliente.rpt"
    If optCliente.Value Then
        If dtcCliente.BoundText = Empty Then
            MsgBox "Seleccione un Cliente", vbExclamation, "Mensaje"
            SSTab1.Tab = 2
            dtcCliente.SetFocus
            Exit Sub
        End If
        crReporte.WindowTitle = "REPORTE DE TPC POR CLIENTE"
        crReporte.Formulas(0) = "formTitulo=stringvar strTitulo; strTitulo:='REPORTE DE TPC POR CLIENTE'"
        crReporte.Formulas(1) = "formParametro=stringvar strParam; strParam:='Cliente: '"
        crReporte.Formulas(2) = "formLabel=stringvar strLabel; strLabel:=' TPC'"
        crReporte.Formulas(3) = "formValor=stringvar strValor; strValor:='" & dtcCliente.Text & "'"
    Else
        If dtcTPC.BoundText = Empty Then
            MsgBox "Seleccione una TPC", vbExclamation, "Mensaje"
            SSTab1.Tab = 2
            dtcTPC.SetFocus
            Exit Sub
        End If
        crReporte.WindowTitle = "REPORTE DE CLIENTES POR TPC"
        crReporte.Formulas(0) = "formTitulo=stringvar strTitulo; strTitulo:='REPORTE DE CLIENTES POR TPC'"
        crReporte.Formulas(1) = "formParametro=stringvar strParam; strParam:='TPC: '"
        crReporte.Formulas(2) = "formLabel=stringvar strLabel; strLabel:=' Cliente'"
        crReporte.Formulas(3) = "formValor=stringvar strValor; strValor:='" & dtcTPC.Text & "'"
    End If
    
    crReporte.Formulas(4) = "formusuario=stringvar strusuario; strusuario:='" & GCUSERID & "'"
    crReporte.Formulas(5) = "formscreen=stringvar strscreen; strscreen:='01.310.00'"
    
    crReporte.StoredProcParam(0) = IIf(GVDATO(dtcCliente.BoundText) = Empty, " ", dtcCliente.BoundText)
    crReporte.StoredProcParam(1) = IIf(GVDATO(dtcTPC.BoundText) = Empty, " ", dtcTPC.BoundText)
    crReporte.StoredProcParam(2) = IIf(optCliente.Value, 1, 0)
    
    crReporte.WindowState = crptMaximized
    crReporte.WindowShowPrintSetupBtn = True
    crReporte.Action = 1
    crReporte.Reset
End Sub
