locked
Create Generic Class RRS feed

  • Question

  • Hi, i've created a UserCode on SL Client named Albaran .

    I would like to call this class from a details screen, to make operations in database. With this class i call from many screens.

    In a details Screen i have a function with this code:

    Try
                                Dim result = From contador In Me.DataWorkspace.GESTION.series
                            Where contador.EMPRESA = empresa And contador.SERIE = serie And contador.TIPODOC = tipodocumento
                            Select contador
                                albaranencurso = result.Single().CONTADOR
                                siguientealbaran = result.Single().CONTADOR
                                result.Single().CONTADOR = result.Single().CONTADOR + 1
                                If depuración = True Then ShowMessageBox("1.1")
                            Catch ex As Exception
                                ShowMessageBox("Atención Error al seleccionar número de Albarán :" & ex.Message)
                            End Try

    But, in my new class, i'm unable to get access to make this similar function.

    I've imported on my class: 

    Imports System.Windows
    Imports Microsoft.LightSwitch.Threading
    Imports System.Reflection
    Imports System
    Imports System.Runtime.InteropServices.Automation
    Imports System.Globalization
    Imports System.Text.RegularExpressions

    Namespace LightSwitchApplication
    Public Class Albaran
    Function contador(a As String) As Char
    Try
                    'FIRST OPTION....
                Dim tablacontadores As LightSwitchApplication.seriesItem1 (((((((Cannot ACCESS TO ENTITIES)))))
                    'SECOND
                    Dim result = From contador In LightSwitchApplication.  (((((((Cannot ACCESS TO ENTITIES)))))
                Where contador.EMPRESA = empresa And contador.SERIE = serie And contador.TIPODOC = tipodocumento
                Select contador
                    albaranencurso = result.Single().CONTADOR
                    siguientealbaran = result.Single().CONTADOR
                    result.Single().CONTADOR = result.Single().CONTADOR + 1
                Catch ex As Exception
                    '  ShowMessageBox("Atención Error al seleccionar número de Albarán :" & ex.Message)
                End Try
            End Function
        End Class
    End Namespace

    How can i access from my code to database to make operations?

    Tuesday, June 23, 2015 1:30 PM

Answers

  • Solved ;)

    I created a button to test:

     Dim util As New Albaran()
     Dim pruebas = util.Contador(Me.DataWorkspace)

    Result of pruebas it's needed value.

    • Marked as answer by Ivan Martinez Wednesday, June 24, 2015 10:16 PM
    Wednesday, June 24, 2015 10:16 PM

All replies

  • I've solved to access to entities with this code:

     Function contador(res As DataWorkspace) As Char
                Dim albaranencurso, siguientealbaran As String
                Try
                    Dim result = From ww In res.GESTION.series
                Where ww.empresa = "" And ww.serie = "" And ww.tipodoc = 1
                Select ww
                    albaranencurso = result.Single().contador
                    siguientealbaran = result.Single().contador
                    result.Single().contador = result.Single().contador + 1

                Catch ex As Exception

                End Try
                Return siguientealbaran
            End Function

    Then, in Client Screen i've imported (Imports LightSwitchApplication.Albaran)

    Albaran is new class.

    I need to call the class, and then read result siguientealbaran

    How can i call the function?

    Thanks.


    Wednesday, June 24, 2015 9:01 PM
  • Solved ;)

    I created a button to test:

     Dim util As New Albaran()
     Dim pruebas = util.Contador(Me.DataWorkspace)

    Result of pruebas it's needed value.

    • Marked as answer by Ivan Martinez Wednesday, June 24, 2015 10:16 PM
    Wednesday, June 24, 2015 10:16 PM
  • Solved ;)

    I created a button to test:

     Dim util As New Albaran()
     Dim pruebas = util.Contador(Me.DataWorkspace)

    Result of pruebas it's needed value.

    Glad that you have solved this issue, and thanks for sharing your solution with us.

    With regards,

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 25, 2015 2:01 AM