Curso de Software de Ventas Parte 25, Ventana Clientes

Continuando con el Curso de Software de Ventas, esta ves vamos a trabajar la ventana de Clientes, para Crear Modificar Clientes.

En este vídeo se creo el formulario de Clientes y de Buscar Cliente.

Los clientes son necesario a la hora de crear facturas a crédito, por eso es parte importante antes de entrar a la parte de ventas.

Procedimiento para Limpiar los campos del formulario:

Sub Limpiar()
    txtRazonS.Text = ""
    txtNitCliente.Text = "0"
    txtTelefonosCliente.Text = "0"
    txtDireccionCliente.Text = "-"
    txtCupo.Text = "0"
    chkFactVenciM.Value = 0
End Sub

Primero se trabajo la parte de Guardar Cliente, para esto se creo un procedimiento llamado Guardar Cliente:

Sub GuardarCliente()
    
    If txtRazonS.Text = "" Then
       MsgBox "Error - El Campo Nombre / Razón Social no puede estar vacío", vbExclamation, "Error"
       Exit Sub
    End If
    If txtNitCliente.Text = "" Then
       MsgBox "Error - El Campo Identifiación no puede estar vacío", vbExclamation, "Error"
       Exit Sub
    End If
    If txtTelefonosCliente.Text = "" Then
       MsgBox "Error - El Campo Teléfonos no puede estar vacío", vbExclamation, "Error"
       Exit Sub
    End If
    If txtDireccionCliente.Text = "" Then
       MsgBox "Error - El Campo Dirección no puede estar vacío", vbExclamation, "Error"
       Exit Sub
    End If
    If txtFechaCumple.Text = "" Then
       MsgBox "Error - El Campo Fecha de Nacimiento no puede estar vacío", vbExclamation, "Error"
       Exit Sub
    End If
    If IsDate(txtFechaCumple.Text) = False Then
       MsgBox "Error - El Campo Fecha de Nacimiento no tiene una fecha válida", vbExclamation, "Error"
       Exit Sub
    End If
    If txtEmail.Text = "" Then
       MsgBox "Error - El Campo Email no puede estar vacío", vbExclamation, "Error"
       Exit Sub
    End If
    If txtCupo.Text = "" Then
       MsgBox "Error - El Campo Cupo Autorizado no puede estar vacío", vbExclamation, "Error"
       Exit Sub
    End If
    
    If CodigoCliente = 0 Then
       IdCliente = UltimoIdTabla("tblClientes", "IdCliente")
       
       If chkFactVenciM.Value = 1 Then
          FacVec = "S"
       Else
          FacVec = "N"
       End If
       
       Sql = "Insert Into tblClientes (IdCliente, NombreApellidos_cli, Identificacion_cli, Telefonos_cli, Direccion_cli, Fecha_Naci_cli, Email_cli, CupoAutorizado_cli,  FacturarVecidos) Values (" _
            & IdCliente & ", '" & txtRazonS & "', '" & txtNitCliente & "', '" & txtTelefonosCliente & "', '" & txtDireccionCliente & "', '" & txtFechaCumple & "', '" & txtEmail & "', '" & txtCupo & "', '" & FacVec & "')"
            
       ConexionADO.Execute Sql
       MsgBox "Cliente Guardado", vbInformation, "Guardar"
    Else
       Sql = "Update tblClientes SET NombreApellidos_cli = '" & txtRazonS & "', Identificacion_cli = '" & txtNitCliente & "', Telefonos_cli = '" & txtTelefonosCliente & "', Direccion_cli = '" & txtDireccionCliente & "', Fecha_Naci_cli = '" & txtFechaCumple & "', Email_cli = '" & txtCupo & "', CupoAutorizado_cli = '" & txtCupo & "',  FacturarVecidos = '" & FacVec & "' Where IdCliente = " & CodigoCliente
       ConexionADO.Execute Sql
       MsgBox "Cliente Actualizado", vbInformation, "Guardar"
       
    End If
End Sub

Ya para la parte de Edición de Clientes, en otras palabras la modificación de Datos del Clientes primero se creo el procedimiento que carga los datos del cliente:

Dim CodigoCliente
Sub LLenarDatosCliente()
    Dim RecorsetTemp As New ADODB.Recordset
    
    Sql = "Select * From tblClientes Where IdCliente = " & CodigoCliente
    Set RecorsetTemp = ConexionADO.Execute(Sql)
    
    If RecorsetTemp.RecordCount > 0 Then
       txtRazonS.Text = RecorsetTemp("NombreApellidos_cli")
       txtNitCliente = RecorsetTemp("Identificacion_cli")
       txtTelefonosCliente = RecorsetTemp("Telefonos_cli")
       txtDireccionCliente = RecorsetTemp("Direccion_cli")
       txtFechaCumple = RecorsetTemp("Fecha_Naci_cli")
       txtEmail = RecorsetTemp("Email_cli")
       txtCupo = RecorsetTemp("CupoAutorizado_cli")
       FacV = RecorsetTemp("FacturarVecidos")
       If FacV = "S" Then
          chkFactVenciM.Value = 1
       Else
          chkFactVenciM.Value = 0
       End If
    End If
    Call DesactivarCampos
    
End Sub

Y se creo dos procedimiento para controlar la modificación de los clientes uno es para Desactivar los controles del formulario para que no se pueda modificar y el otro es para activarlos nuevamente:

Sub DesactivarCampos()
     txtRazonS.Enabled = False
     txtNitCliente.Enabled = False
     txtTelefonosCliente.Enabled = False
     txtDireccionCliente.Enabled = False
     txtFechaCumple.Enabled = False
     txtEmail.Enabled = False
     txtCupo.Enabled = False
     Me.chkFactVenciM.Enabled = False
End Sub

Sub ActivarCampos()
     txtRazonS.Enabled = True
     txtNitCliente.Enabled = True
     txtTelefonosCliente.Enabled = True
     txtDireccionCliente.Enabled = True
     txtFechaCumple.Enabled = True
     txtEmail.Enabled = True
     txtCupo.Enabled = True
     chkFactVenciM.Enabled = True
End Sub

El Botón Nuevo del Formulario lleva el siguiente Código:

Private Sub cmdNuevo_Click()
    CodigoCliente = 0
    Call Limpiar
    Call ActivarCampos
End Sub

El botón guardar y el botón modificar:

Private Sub cmdGuardar_Click()
    Call GuardarCliente
End Sub

Private Sub cmdModificar_Click()
    Call ActivarCampos
End Sub

El botón Nuevo:

Private Sub cmdNuevo_Click()
    CodigoCliente = 0
    Call Limpiar
    Call ActivarCampos
End Sub

El Evento Load del formulario:

Private Sub Form_Load()
    Call Limpiar
    If glob_ModificarCliente = True Then
       CodigoCliente = frmBuscarCliente.msGrid.TextMatrix(frmBuscarCliente.msGrid.Row, 1)
       Call LLenarDatosCliente
       Call DesactivarCampos
    Else
       Call ActivarCampos
    End If
End Sub

Evento Unload del formulario necesario para modificar la variable que controla la edición del formulario:

Private Sub Form_Unload(Cancel As Integer)
    glob_ModificarCliente = False
End Sub

Siguiente Lección Curso de Software de Ventas Parte 26, Ventana de Ventas Parte 1

 

 

 

Total Page Visits: 4048 - Today Page Visits: 2

Deja una respuesta