Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.BaseImpl
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Configuration
Imports DevExpress.Data.Filtering
Imports DevExpress.Xpo
Imports System.IO
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.ExpressApp.CloneObject
Public Class SQLImportsVC
    Inherits DevExpress.ExpressApp.ViewController
    Dim _WaitFormClass As New WaitFormClass
    Dim _Maximum As Long
    Public Sub New()
        MyBase.New()
        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()

        If View.Id = "SQLImports_LiquidAssets_Cassa_ListView" Or _
            View.Id = "SQLImports_LiquidAssets_Compensation_ListView" Or _
            View.Id = "SQLImports_LiquidAssets_SpecTran_ListView" Or _
            View.Id = "SQLImports_BankInformation_ListView" Then
            Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of DeleteObjectsViewController).Active.SetItemValue("", False)
            Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", False)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", False)
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", False)
            Frame.GetController(Of ModificationsController).Active.SetItemValue("", False)
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "SQLImports_LiquidAssets_Cassa_ListView" Or _
            View.Id = "SQLImports_LiquidAssets_Compensation_ListView" Or _
            View.Id = "SQLImports_LiquidAssets_SpecTran_ListView" Or _
            View.Id = "SQLImports_BankInformation_ListView" Then
            Frame.GetController(Of NewObjectViewController).Active.SetItemValue("", True)
            Frame.GetController(Of DeleteObjectsViewController).Active.SetItemValue("", True)
            Frame.GetController(Of LinkUnlinkController).Active.SetItemValue("", True)
            Frame.GetController(Of CloneObjectViewController).Active.SetItemValue("", True)
            Frame.GetController(Of ListViewProcessCurrentObjectController).Active.SetItemValue("", True)
            Frame.GetController(Of ModificationsController).Active.SetItemValue("", True)
        End If
    End Sub
    Private Sub Import_Customers_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Customers.Execute
        '-- Ügyfelek és a hozzátartozó kapcsolatok importálása
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", False)



        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim connstr As String


        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _Customers As Customers
        Dim _CustomersOrder As CustomersOrder
        Dim _CustomersFrom As CustomersFrom
        Dim _Address As Address
        Dim _CountryExtend As CountryExtend
        Dim _CustomersGLParameters As CustomersGLParameters
        Dim _CustomerBankAccounts As CustomerBankAccounts

        Dim sArray As String()
        Dim i As Long
        Dim _PhoneNumber As PhoneNumber

        _Maximum = 0

        mSQL = "select DB=count(*)"
        mSQL = mSQL & " from Ügyféltörzs t1 left join "
        mSQL = mSQL & " Ügyféltörzs_Kapcsolat t2 on"
        mSQL = mSQL & " t1.Ügyfélszám=t2.Ügyfélszám"
        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()

        mSQL = "select Ügyfélszám=isnull(t1.Ügyfélszám,0),Név=isnull(t1.Név,''),Országjel=isnull(t1.Országjel,''),"
        mSQL = mSQL & " Irányítószám=isnull(t1.Irányítószám,''), Város=isnull(t1.Város,''), Utca=isnull(t1.Utca,''), "
        mSQL = mSQL & " Bankszámlaszám=isnull(t1.Bankszámlaszám,''),AdószámEU=isnull(t1.AdószámEU,''),"
        mSQL = mSQL & " Adószám=isnull(t1.Adószám,''),Leírás=isnull(t3.Leírás,''),Tipus=isnull(t1.Tipus,0),"
        mSQL = mSQL & " Beszállító=case when t4.Ügyfélszám is null then 0 else 1 end,"
        mSQL = mSQL & " Hitelkeret_Összeg=isnull(t1.Hitelkeret_Összeg,0),Hitelkeret_Nap=isnull(t1.Hitelkeret_Nap,0),"
        mSQL = mSQL & " Telefon=isnull(t1.Telefon,''),Fax=isnull(t1.Fax,''),EMail=isnull(t1.EMail,''),WEB=isnull(t1.WEB,'')"

        mSQL = mSQL & " from Ügyféltörzs t1 left join "
        mSQL = mSQL & " Ügyféltörzs_Kapcsolat t2 on"
        mSQL = mSQL & " t1.Ügyfélszám=t2.Ügyfélszám left join Ügyféltörzs_Mode t3 on"
        mSQL = mSQL & " t1.Mode=t3.Mode left join "

        mSQL = mSQL & " (select Ügyfélszám=t2.Ügyfélszám"
        mSQL = mSQL & " from sql_Main..Rendelés_Lezárt t1 left join sql_Main..vv_Ügyféltörzs_Telephely2 t2 on"
        mSQL = mSQL & " t1.Ügyfélszám = t2.Ügyfélszámx10"
        mSQL = mSQL & " group by t2.Ügyfélszám) t4 on"

        mSQL = mSQL & " t1.Ügyfélszám=t4.Ügyfélszám"

        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.InitWork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                If dr("Tipus") = 4 Then
                    _CustomersFrom = _uow.FindObject(Of CustomersFrom)(CriteriaOperator.Parse("CustomerNumber=?", CStr(dr("Ügyfélszám"))), True)
                    If _CustomersFrom Is Nothing Then _CustomersFrom = New CustomersFrom(_uow)


                    _CustomersFrom.CustomerNumber = dr("Ügyfélszám").ToString
                    _CustomersFrom.Name = dr("Név")
                    _CustomersFrom.FullName = dr("Név")

                    _CountryExtend = _uow.FindObject(Of CountryExtend)(CriteriaOperator.Parse("ShortName=?", dr("Országjel")))
                    _Address = _uow.FindObject(Of Address)(CriteriaOperator.Parse("City=? and ZipPostal=? and Street=? and Country=?", _
                        dr("Város"), dr("Irányítószám"), dr("Utca"), TryCast(_CountryExtend, Country)))
                    If _CustomersFrom.Address1 Is Nothing Then
                        If _Address Is Nothing Then _Address = New Address(_uow)
                        _Address.Country = TryCast(_CountryExtend, Country)
                        _Address.City = dr("Város").ToString
                        _Address.ZipPostal = dr("Irányítószám").ToString
                        _Address.Street = dr("Utca").ToString

                        _CustomersFrom.Address1 = _Address
                    Else
                        _CustomersFrom.Address1.Country = TryCast(_CountryExtend, Country)
                    End If
                    _CustomersFrom.VATNumber = dr("Adószám").ToString
                    _CustomersFrom.VATNumberEU = dr("AdószámEU").ToString
                    _CustomersFrom.Email = dr("EMail")
                    _CustomersFrom.WebSite = dr("WEB")
                    _CustomersGLParameters = _uow.FindObject(Of CustomersGLParameters)(CriteriaOperator.Parse("ShortName=?", dr("Leírás")))

                    _CustomersFrom.CustomersGLParameters = _CustomersGLParameters

                    _CustomersFrom.Save()
                Else
                    If dr("Beszállító") = 1 Then
                        _CustomersOrder = _uow.FindObject(Of CustomersOrder)(CriteriaOperator.Parse("CustomerNumber=?", CStr(dr("Ügyfélszám"))), True)
                        If _CustomersOrder Is Nothing Then _CustomersOrder = New CustomersOrder(_uow)


                        _CustomersOrder.CustomerNumber = dr("Ügyfélszám").ToString
                        _CustomersOrder.Name = dr("Név")
                        _CustomersOrder.FullName = dr("Név")

                        _CountryExtend = _uow.FindObject(Of CountryExtend)(CriteriaOperator.Parse("ShortName=?", dr("Országjel")))
                        _Address = _uow.FindObject(Of Address)(CriteriaOperator.Parse("City=? and ZipPostal=? and Street=? and Country=?", _
                            dr("Város"), dr("Irányítószám"), dr("Utca"), TryCast(_CountryExtend, Country)))
                        If _CustomersOrder.Address1 Is Nothing Then
                            If _Address Is Nothing Then _Address = New Address(_uow)
                            _Address.Country = TryCast(_CountryExtend, Country)
                            _Address.City = dr("Város").ToString
                            _Address.ZipPostal = dr("Irányítószám").ToString
                            _Address.Street = dr("Utca").ToString

                            _CustomersOrder.Address1 = _Address
                        Else
                            _CustomersOrder.Address1.Country = TryCast(_CountryExtend, Country)
                        End If
                        _CustomersOrder.VATNumber = dr("Adószám").ToString
                        _CustomersOrder.VATNumberEU = dr("AdószámEU").ToString
                        _CustomersOrder.Email = dr("EMail")
                        _CustomersOrder.WebSite = dr("WEB")

                        _CustomersGLParameters = _uow.FindObject(Of CustomersGLParameters)(CriteriaOperator.Parse("ShortName=?", dr("Leírás")))
                        _CustomersOrder.CustomersGLParameters = _CustomersGLParameters

                        _CustomersOrder.CreditlineAmountHUF = dr("Hitelkeret_Összeg")
                        _CustomersOrder.CreditlineDay = dr("Hitelkeret_Nap")

                        _CustomersOrder.Save()

                        _Customers = TryCast(_CustomersOrder, Customers)
                    Else
                        _Customers = _uow.FindObject(Of Customers)(CriteriaOperator.Parse("CustomerNumber=?", CStr(dr("Ügyfélszám"))), True)
                        If _Customers Is Nothing Then _Customers = New Customers(_uow)


                        _Customers.CustomerNumber = dr("Ügyfélszám").ToString
                        _Customers.Name = dr("Név")
                        _Customers.FullName = dr("Név")

                        _CountryExtend = _uow.FindObject(Of CountryExtend)(CriteriaOperator.Parse("ShortName=?", dr("Országjel")))
                        _Address = _uow.FindObject(Of Address)(CriteriaOperator.Parse("City=? and ZipPostal=? and Street=? and Country=?", _
                            dr("Város"), dr("Irányítószám"), dr("Utca"), TryCast(_CountryExtend, Country)))
                        If _Customers.Address1 Is Nothing Then
                            If _Address Is Nothing Then _Address = New Address(_uow)
                            _Address.Country = TryCast(_CountryExtend, Country)
                            _Address.City = dr("Város").ToString
                            _Address.ZipPostal = dr("Irányítószám").ToString
                            _Address.Street = dr("Utca").ToString

                            _Customers.Address1 = _Address
                        Else
                            _Customers.Address1.Country = TryCast(_CountryExtend, Country)
                        End If
                        _Customers.VATNumber = dr("Adószám").ToString
                        _Customers.VATNumberEU = dr("AdószámEU").ToString
                        _Customers.Email = dr("EMail")
                        _Customers.WebSite = dr("WEB")

                        _CustomersGLParameters = _uow.FindObject(Of CustomersGLParameters)(CriteriaOperator.Parse("ShortName=?", dr("Leírás")))

                        _Customers.CustomersGLParameters = _CustomersGLParameters
                        _Customers.CreditlineAmountHUF = dr("Hitelkeret_Összeg")
                        _Customers.CreditlineDay = dr("Hitelkeret_Nap")

                        _Customers.Save()
                    End If
                End If

                '_uow.Delete(_Customers.CustomerBankAccounts)
                'If LTrim(RTrim(dr("Bankszámlaszám"))) <> "" Then
                '    _CustomerBankAccounts = _uow.FindObject(Of CustomerBankAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                '                                            CriteriaOperator.Parse("AccountNumber=? and Customers.Oid=?", dr("Bankszámlaszám"), _Customers.Oid))
                '    If _CustomerBankAccounts Is Nothing Then
                '        _CustomerBankAccounts = New CustomerBankAccounts(_uow)
                '        _CustomerBankAccounts.Customers = _Customers
                '        _CustomerBankAccounts.AccountNumber = dr("Bankszámlaszám")
                '    End If
                'End If
                '_uow.Delete(_Customers.PhoneNumbers)
                'If dr("Telefon") <> "" Then
                '    sArray = dr("Telefon").ToString.Split(vbNewLine)
                '    For i = LBound(sArray) To UBound(sArray)
                '        _PhoneNumber = New PhoneNumber(_uow)
                '        _PhoneNumber.Number = sArray(i)
                '        _Customers.PhoneNumbers.Add(_PhoneNumber)
                '    Next
                'End If
                'If dr("Fax") <> "" Then
                '    sArray = dr("Fax").ToString.Split(vbNewLine)
                '    For i = LBound(sArray) To UBound(sArray)
                '        _PhoneNumber = New PhoneNumber(_uow)
                '        _PhoneNumber.Number = sArray(i)
                '        _Customers.PhoneNumbers.Add(_PhoneNumber)
                '    Next
                'End If
                _uow.CommitChanges()
            End While
        End If
        _WaitFormClass.FinalWork()
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
    End Sub
    Private Sub Import_Country_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Country.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _CountryExtend As CountryExtend
        Dim _Country As Country


        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Ügyféltörzs_Országjel"
            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Megnevezés,t1.Országjel"
            mSQL = mSQL & " from Ügyféltörzs_Országjel t1 "

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _CountryExtend = _uow.FindObject(Of CountryExtend)(CriteriaOperator.Parse("ShortName=?", dr("Országjel")), True)
                    If _CountryExtend Is Nothing Then
                        _CountryExtend = New CountryExtend(_uow)
                        _CountryExtend.Name = dr("Megnevezés")
                        _CountryExtend.ShortName = dr("Országjel")

                        _CountryExtend.Save()
                    Else

                    End If
                    _WaitFormClass.DoWork()
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_Controlling_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Controlling.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _Controlling As Controlling
        Dim _Controlling_Parent As Controlling
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Controlling"
            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Megnevezés,Megnevezés_Parent=t2.Megnevezés"
            mSQL = mSQL & " from Controlling t1 left join Controlling t2 on"
            mSQL = mSQL & " t1.ParentID=t2.ID"
            mSQL = mSQL & " order by t1.LevelID,t1.Megnevezés"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _Controlling = _uow.FindObject(Of Controlling)(CriteriaOperator.Parse("Name=?", dr("Megnevezés")))
                    _Controlling_Parent = _uow.FindObject(Of Controlling)(CriteriaOperator.Parse("Name=?", dr("Megnevezés_Parent")))
                    If _Controlling Is Nothing Then
                        _Controlling = New Controlling(_uow)
                    End If

                    _Controlling.Name = dr("Megnevezés")
                    If _Controlling_Parent Is Nothing Then
                    Else
                        _Controlling.Parent = _Controlling_Parent
                    End If
                    _Controlling.Save()
                    _WaitFormClass.DoWork()
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception

        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_ChartsOfAccounts_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_ChartsOfAccounts.Execute
        '-- Számlatükör importálása meglévõ SQL szerverrõl
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String = String.Format(" User ID={0}; ", _SQLImports.SQLUser)
        connstr &= String.Format(" Password={0};", _SQLImports.SQLPassword)
        connstr &= " Pooling=false;"
        connstr &= String.Format(" Data Source={0};", _SQLImports.SQLServer)
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _ChartOfAccounts As ChartOfAccounts
        Dim _ChartOfAccounts_P As ChartOfAccounts

        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Költségek"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Számlaszám,t1.Megnevezés,Megnevezés_Parent=t2.Megnevezés"
            mSQL = mSQL & " from Költségek t1 left join Költségek t2 on"
            mSQL = mSQL & " t1.ParentID=t2.ID"
            mSQL = mSQL & " order by t1.Megnevezés"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()

            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _ChartOfAccounts = _uow.FindObject(Of ChartOfAccounts)(1, CriteriaOperator.Parse("Name=?", dr("Megnevezés")))
                    _ChartOfAccounts_P = _uow.FindObject(Of ChartOfAccounts)(1, CriteriaOperator.Parse("Name=?", dr("Megnevezés_Parent")))
                    If _ChartOfAccounts Is Nothing Then
                        _ChartOfAccounts = New ChartOfAccounts(_uow)
                    End If
                    If _ChartOfAccounts_P Is Nothing Then
                    Else
                        _ChartOfAccounts.Parent = _ChartOfAccounts_P
                    End If
                    _ChartOfAccounts.Name = dr("Megnevezés")
                    _ChartOfAccounts.AccountNumber = dr("Számlaszám")
                    _ChartOfAccounts.Save()
                    _WaitFormClass.DoWork()
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_Storage_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Storage.Execute
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", False)
        '-- Raktárkészlet importálása
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _Storage As Storage
        Dim _NumberGeneratorGroups As NumberGeneratorGroups
        Dim _NumberGenerator As NumberGenerator

        '-- Elõször a raktár importálása
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Raktár_Tipus"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select *"
            mSQL = mSQL & " from Raktár_Tipus"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _Storage = _uow.FindObject(Of Storage)(CriteriaOperator.Parse("ShortName=?", dr("Megnevezés")), True)
                    If _Storage Is Nothing Then
                        _Storage = New Storage(_uow)
                        _NumberGeneratorGroups = _uow.FindObject(Of NumberGeneratorGroups)(CriteriaOperator.Parse("ShortName='Raktár'"))
                        If _NumberGeneratorGroups Is Nothing Then
                            _NumberGeneratorGroups = New NumberGeneratorGroups(_uow)
                            _NumberGeneratorGroups.Description = "Raktár"
                            _NumberGeneratorGroups.ShortName = "Raktár"
                        End If

                        '-- Sorszám generálása
                        _NumberGenerator = New NumberGenerator(_uow)
                        _NumberGenerator.MonthAfterYear = False
                        _NumberGenerator.NewNumberPerYear = True
                        _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
                        _NumberGenerator.PrefixString = "R-BE-" & AlignStr(LTrim(RTrim(dr("ID").ToString)), eDirection.Left, "0", 2)
                        _NumberGenerator.PrefixTag = "-"
                        _NumberGenerator.SerialNumber = 1
                        _NumberGenerator.SerialNumberDigit = 4
                        _NumberGenerator.SerialNumberPlace = ePlace.Right
                        _NumberGenerator.ShortName = "Betárolás : " & dr("Megnevezés")
                        _NumberGenerator.SuffixString = "-"
                        _NumberGenerator.SuffixTag = ""
                        _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

                        _Storage.NumberGeneratorIn = _NumberGenerator

                        _NumberGenerator = New NumberGenerator(_uow)
                        _NumberGenerator.MonthAfterYear = False
                        _NumberGenerator.NewNumberPerYear = True
                        _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
                        _NumberGenerator.PrefixString = "R-BES-" & AlignStr(LTrim(RTrim(dr("ID").ToString)), eDirection.Left, "0", 2)
                        _NumberGenerator.PrefixTag = "-"
                        _NumberGenerator.SerialNumber = 1
                        _NumberGenerator.SerialNumberDigit = 4
                        _NumberGenerator.SerialNumberPlace = ePlace.Right
                        _NumberGenerator.ShortName = "Betárolás stornó : " & dr("Megnevezés")
                        _NumberGenerator.SuffixString = "-"
                        _NumberGenerator.SuffixTag = ""
                        _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

                        _Storage.NumberGeneratorInS = _NumberGenerator

                        _NumberGenerator = New NumberGenerator(_uow)
                        _NumberGenerator.MonthAfterYear = False
                        _NumberGenerator.NewNumberPerYear = True
                        _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
                        _NumberGenerator.PrefixString = "R-KI-" & AlignStr(LTrim(RTrim(dr("ID").ToString)), eDirection.Left, "0", 2)
                        _NumberGenerator.PrefixTag = "-"
                        _NumberGenerator.SerialNumber = 1
                        _NumberGenerator.SerialNumberDigit = 4
                        _NumberGenerator.SerialNumberPlace = ePlace.Right
                        _NumberGenerator.ShortName = "Kitárolás : " & dr("Megnevezés")
                        _NumberGenerator.SuffixString = "-"
                        _NumberGenerator.SuffixTag = ""
                        _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

                        _Storage.NumberGeneratorOut = _NumberGenerator

                        _NumberGenerator = New NumberGenerator(_uow)
                        _NumberGenerator.MonthAfterYear = False
                        _NumberGenerator.NewNumberPerYear = True
                        _NumberGenerator.NumberGeneratorGroups = _NumberGeneratorGroups
                        _NumberGenerator.PrefixString = "R-KIS-" & AlignStr(LTrim(RTrim(dr("ID").ToString)), eDirection.Left, "0", 2)
                        _NumberGenerator.PrefixTag = "-"
                        _NumberGenerator.SerialNumber = 1
                        _NumberGenerator.SerialNumberDigit = 4
                        _NumberGenerator.SerialNumberPlace = ePlace.Right
                        _NumberGenerator.ShortName = "Kitárolás stornó : " & dr("Megnevezés")
                        _NumberGenerator.SuffixString = "-"
                        _NumberGenerator.SuffixTag = ""
                        _NumberGenerator.YearFormat = eYearFormat.YearTwoDigit

                        _Storage.NumberGeneratorOutS = _NumberGenerator


                    End If
                    _Storage.ShortName = dr("Megnevezés")
                    _Storage.Description = dr("Leírás")
                    _Storage.CustomersFrom = _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid)

                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
        '-- Utána a nyitott készlet importálása
        '_WaitFormClass.InitWork
        'Try
        '    mSQL = "select DB=count(*)"
        '    mSQL = mSQL & " from Raktár_Új t1 join ET t2 on"
        '    mSQL = mSQL & " t1.Cikkszám=t2.Cikkszám"
        '    mSQL = mSQL & " Where round(t1.Bevett,4) > round(t1.Kiírt,0)"

        '    cmd.CommandTimeout = 60
        '    cmd.Connection = conn
        '    cmd.CommandType = CommandType.Text
        '    cmd.CommandText = mSQL
        '    conn.Open()
        '    If conn.State = ConnectionState.Open Then
        '        dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
        '        While dr.Read
        '            _form.ProgressBarControl1.Properties.Maximum = dr("DB")
        '        End While
        '    End If
        '    conn.Close()

        '    mSQL = "select t1.Megnevezés,Megnevezés_Parent=t2.Megnevezés"
        '    mSQL = mSQL & " from Controlling t1 left join Controlling t2 on"
        '    mSQL = mSQL & " t1.ParentID=t2.ID"
        '    mSQL = mSQL & " order by t1.LevelID,t1.Megnevezés"

        '    cmd.CommandTimeout = 60
        '    cmd.Connection = conn
        '    cmd.CommandType = CommandType.Text
        '    cmd.CommandText = mSQL
        '    conn.Open()



        '    If conn.State = ConnectionState.Open Then
        '        dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
        '        While dr.Read
        '            _StorageInHeader = New StorageInHeader(TryCast(View.ObjectSpace, Xpo.XPObjectSpace).Session)



        '            _WaitFormClass.DoWork
        '            View.ObjectSpace.CommitChanges()
        '            System.Windows.Forms.Application.DoEvents()
        '        End While
        '    End If
        'Catch ex As Exception

        'End Try
        '_WaitFormClass.Finalwork
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
    End Sub
    Private Sub Import_Procucts_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Procucts.Execute
        '-- Terméktörzs importálása
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String = String.Format(" User ID={0}; ", _SQLImports.SQLUser)
        connstr &= String.Format(" Password={0};", _SQLImports.SQLPassword)
        connstr &= " Pooling=false;"
        connstr &= String.Format(" Data Source={0};", _SQLImports.SQLServer)
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _Products As Products
        Dim _ProductsGroups As ProductsGroups
        Dim _ProductsGroupsP As ProductsGroups
        Dim _Units As Units
        Dim _VAT As VAT
        Dim _CustomsTariffs As CustomsTariffs
        Dim _CustomersOrderPriority As CustomersOrderPriority
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from  ET "

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = ""
            mSQL += "select Cikkszám=isnull(t1.Cikkszám,''),"
            mSQL += "       Megnevezés=isnull(t1.Megnevezés,''),"
            mSQL += "       Megnevezés_Angol=isnull(t1.Megnevezés_Angol,''),"
            mSQL += "       Csoport=isnull(t1.Csoport,'<Nincs>'),"
            mSQL += "       CsoportMegnevezés=isnull(t2.Megnevezés,'-'),"
            mSQL += "       FőCsoport=isnull(t2.FőCsoport,'<Nincs>'),"
            mSQL += "       MEgys=isnull(t1.MEgys,''),"
            mSQL += "       Description=isnull(t1.Description,''),"
            mSQL += "       Description_Belső=isnull(t1.Description_Belső,''),"
            mSQL += "       Ár=isnull(t1.Ár,0),"
            mSQL += "       DevizásÁr=isnull(t1.DevizásÁr,0),"
            mSQL += "       Ár_Deviza=isnull(t1.Ár_Deviza,0),"
            mSQL += "       Vonalkód=isnull(t1.Vonalkód,''),"
            mSQL += "       Áfahiv=isnull(t1.Áfahiv,''),"
            mSQL += "       ITJ=isnull(t1.ITJ,''),"
            mSQL += "       CsEgys=isnull(t1.CsEgys,0),"
            mSQL += "       BeszCsEgys=isnull(t1.BeszCsEgys,0),"
            mSQL += "       Termékkód=isnull(t1.Termékkód,''),"
            mSQL += "       StratégiaiKód=isnull(t1.StratégiaiKód,''),"
            mSQL += "       Beszállító1=isnull(t4.Ügyfélszám,0), "
            mSQL += "       Beszállító2=isnull(t5.Ügyfélszám,0), "
            mSQL += "       Beszállító3=isnull(t6.Ügyfélszám,0), "
            mSQL += "       Súly=isnull(t1.Súly,0), "
            mSQL += "       ITJ_Leírás=isnull(t7.Leírás,''), "
            mSQL += "       Devizanem=isnull(t1.Devizanem,''), "
            mSQL += "       Származás=isnull(t1.Származás,'') "

            mSQL += " from ET t1 left join Főcsoportok t2 on"
            mSQL += " t1.Csoport=t2.Csoport left join FőCsoportokM t3 on"
            mSQL += " t2.FőCsoport=t3.FőCsoport left join vv_Ügyféltörzs_Telephely2 t4 on"
            mSQL += " t1.Ügyfélszám_Beszállító1=t4.ÜgyfélszámX10 left join vv_Ügyféltörzs_Telephely2 t5 on"
            mSQL += " t1.Ügyfélszám_Beszállító2=t5.ÜgyfélszámX10 left join vv_Ügyféltörzs_Telephely2 t6 on"
            mSQL += " t1.Ügyfélszám_Beszállító3=t6.ÜgyfélszámX10 left join sql_Auto..Auto_VSZ t7 on"
            mSQL += " t1.ID_Auto_VSZ=t7.ID"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _ProductsGroupsP = _uow.FindObject(Of ProductsGroups)(CriteriaOperator.Parse("ShortName=?", dr("FőCsoport")))
                    If _ProductsGroupsP Is Nothing Then
                        _ProductsGroupsP = New ProductsGroups(_uow)
                        _ProductsGroupsP.ShortName = dr("FőCsoport")
                        _ProductsGroupsP.Description = dr("FőCsoport")
                        _ProductsGroupsP.Name = dr("FőCsoport")
                    End If
                    _ProductsGroups = _uow.FindObject(Of ProductsGroups)(CriteriaOperator.Parse("ShortName=?", dr("Csoport")))
                    If _ProductsGroups Is Nothing Then
                        _ProductsGroups = New ProductsGroups(_uow)
                        _ProductsGroups.ShortName = dr("Csoport")
                        _ProductsGroups.Description = dr("CsoportMegnevezés")
                        _ProductsGroups.Parent = _ProductsGroupsP
                        _ProductsGroups.Name = dr("Csoport")
                    End If

                    _Units = _uow.FindObject(Of Units)(CriteriaOperator.Parse("ShortName=?", dr("MEgys")))
                    If _Units Is Nothing Then
                        _Units = New Units(_uow)
                        _Units.ShortName = dr("MEgys")
                    End If
                    _CustomsTariffs = _uow.FindObject(Of CustomsTariffs)(CriteriaOperator.Parse("CustomsTariffNumber=?", dr("ITJ")))
                    If _CustomsTariffs Is Nothing Then
                        _CustomsTariffs = New CustomsTariffs(_uow)
                    End If
                    _CustomsTariffs.CustomsTariffNumber = dr("ITJ")
                    _CustomsTariffs.Description = dr("ITJ_Leírás")

                    _Products = _uow.FindObject(Of Products)(CriteriaOperator.Parse("ProductNumber=?", dr("Cikkszám")))
                    If _Products Is Nothing Then
                        _Products = New Products(_uow)
                    End If
                    _VAT = _uow.FindObject(Of VAT)(CriteriaOperator.Parse("ShortName=?", dr("Áfahiv")))

                    _Products.ProductGroups = _ProductsGroups
                    _Products.ProductNumber = dr("Cikkszám")
                    _Products.ShortName = dr("Megnevezés")
                    _Products.ShortName_Gb = dr("Megnevezés_Angol")
                    _Products.Description = dr("Description")
                    _Products.Description_Private = dr("Description_Belső")
                    _Products.Units = _Units
                    _Products.ListPriceOutHUF = dr("Ár")
                    _Products.Barcode = dr("Vonalkód")
                    _Products.VAT = _VAT
                    _Products.CustomsTariff = _CustomsTariffs
                    _Products.PacketUnitIn = dr("BeszCsEgys")
                    _Products.PacketUnitOut = dr("CsEgys")
                    _Products.ProductCode = dr("Termékkód")
                    _Products.ProductStrategyCode = dr("StratégiaiKód")
                    _Products.NettoWeight = dr("Súly")
                    _Products.ListPriceInDEV = dr("DevizásÁr")
                    _Products.ListPriceOutDEV = dr("Ár_Deviza")
                    _Products.CurrencyName = _uow.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName=?", dr("Devizanem")))
                    _Products.CountryFrom = TryCast(_uow.FindObject(Of CountryExtend)(CriteriaOperator.Parse("ShortName=?", dr("Származás"))), Country)
                    _Products.Save()

                    If dr("Beszállító1") > 0 Then
                        _CustomersOrderPriority = _uow.FindObject(Of CustomersOrderPriority)(CriteriaOperator.Parse("CustomersOrder.CustomerNumber=? and Products=?", dr("Beszállító1").ToString, _Products))
                        If _CustomersOrderPriority Is Nothing Then
                            _CustomersOrderPriority = New CustomersOrderPriority(_uow)
                            _CustomersOrderPriority.Products = _Products
                            _CustomersOrderPriority.CustomersOrder = _uow.FindObject(Of CustomersOrder)(CriteriaOperator.Parse("CustomerNumber=?", dr("Beszállító1").ToString))
                            _CustomersOrderPriority.RowIndex = 1
                        End If
                    End If
                    If dr("Beszállító2") > 0 Then
                        _CustomersOrderPriority = _uow.FindObject(Of CustomersOrderPriority)(CriteriaOperator.Parse("CustomersOrder.CustomerNumber=? and Products=?", dr("Beszállító2").ToString, _Products))
                        If _CustomersOrderPriority Is Nothing Then
                            _CustomersOrderPriority = New CustomersOrderPriority(_uow)
                            _CustomersOrderPriority.Products = _Products
                            _CustomersOrderPriority.CustomersOrder = _uow.FindObject(Of CustomersOrder)(CriteriaOperator.Parse("CustomerNumber=?", dr("Beszállító2").ToString))
                            _CustomersOrderPriority.RowIndex = 2
                        End If
                    End If
                    If dr("Beszállító3") > 0 Then
                        _CustomersOrderPriority = _uow.FindObject(Of CustomersOrderPriority)(CriteriaOperator.Parse("CustomersOrder.CustomerNumber=? and Products=?", dr("Beszállító3").ToString, _Products))
                        If _CustomersOrderPriority Is Nothing Then
                            _CustomersOrderPriority = New CustomersOrderPriority(_uow)
                            _CustomersOrderPriority.Products = _Products
                            _CustomersOrderPriority.CustomersOrder = _uow.FindObject(Of CustomersOrder)(CriteriaOperator.Parse("CustomerNumber=?", dr("Beszállító3").ToString))
                            _CustomersOrderPriority.RowIndex = 3
                        End If
                    End If
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_ProcuctsGroups_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_ProcuctsGroups.Execute
        '-- Termékcsoport importálása
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _ProductsGroups As ProductsGroups
        Dim _ProductsGroupsM As ProductsGroups

        '---- Elõször a FõcsoportokM táblából betöltjük a FõCsoportokat
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from FõcsoportokM "

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select * "
            mSQL = mSQL & " from FõCsoportokM"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _ProductsGroups = _uow.FindObject(Of ProductsGroups)(CriteriaOperator.Parse("ShortName=?", dr("FõCsoport")))
                    If _ProductsGroups Is Nothing Then
                        _ProductsGroups = New ProductsGroups(_uow)
                    End If
                    _ProductsGroups.ShortName = dr("FõCsoport")
                    _ProductsGroups.Name = dr("FõCsoport")
                    _ProductsGroups.Description = dr("Leírás")
                    _ProductsGroups.Save()
                    _WaitFormClass.DoWork()
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
        conn.Close()
        '---- Most a termékcsoportok a fõcsoport hierarchia alá !

        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Fõcsoportok "

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select * "
            mSQL = mSQL & " from FõCsoportok"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _ProductsGroupsM = _uow.FindObject(Of ProductsGroups)(CriteriaOperator.Parse("ShortName=?", dr("FõCsoport")))
                    _ProductsGroups = _uow.FindObject(Of ProductsGroups)(CriteriaOperator.Parse("ShortName=?", dr("Csoport")))
                    If _ProductsGroups Is Nothing Then
                        _ProductsGroups = New ProductsGroups(_uow)
                    End If
                    _ProductsGroups.Parent = _ProductsGroupsM
                    _ProductsGroups.ShortName = dr("Csoport")
                    _ProductsGroups.Name = dr("Megnevezés")
                    _ProductsGroups.Description = dr("Megnevezés")
                    _ProductsGroups.Save()
                    _WaitFormClass.DoWork()
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_CustomersGLParameters_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_CustomersGLParameters.Execute
        '-- Partner fõkönyvi kategóriák másolása
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim connstr As String

        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _CustomersGLParameters As CustomersGLParameters
        Dim _ChartOfAccounts As ChartOfAccounts

        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", False)

        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Ügyféltörzs_Mode "
            mSQL = mSQL & " Where LastLevel=1"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Leírás,InC=isnull(t2.Számlaszám,''),OutC=isnull(t3.Számlaszám,'')"
            mSQL = mSQL & " from Ügyféltörzs_Mode t1 left join sql_Cassa.dbo.Költségek t2 on"
            mSQL = mSQL & " t1.KöltségIDIn=t2.ID left join sql_Cassa.dbo.Költségek t3 on"
            mSQL = mSQL & " t1.KöltségIDOut=t3.ID "


            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read

                    _CustomersGLParameters = _uow.FindObject(Of CustomersGLParameters)(CriteriaOperator.Parse("ShortName=?", dr("Leírás").ToString), True)
                    If _CustomersGLParameters Is Nothing Then _CustomersGLParameters = New CustomersGLParameters(_uow)
                    _CustomersGLParameters.ShortName = dr("Leírás")

                    _ChartOfAccounts = _uow.FindObject(Of ChartOfAccounts)(CriteriaOperator.Parse("AccountNumber=?", dr("InC")))
                    '_CustomersGLParameters.ChartOfAccountsIn = _ChartOfAccounts
                    _ChartOfAccounts = _uow.FindObject(Of ChartOfAccounts)(CriteriaOperator.Parse("AccountNumber=?", dr("OutC")))
                    '_CustomersGLParameters.ChartOfAccountsOut = _ChartOfAccounts

                    _CustomersGLParameters.Save()
                    _uow.CommitChanges()

                    _WaitFormClass.DoWork()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
    End Sub
    Private Sub Import_LiquidAssets_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_LiquidAssets.Execute
        '-- Pénzeszközök importálása
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _CustomersFrom As CustomersFrom = _uow.FindObject(Of CustomersFrom)(CriteriaOperator.Parse("Oid=Oid"))
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim connstr As String

        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _ChartOfAccounts As ChartOfAccounts
        Dim _LiquidAssets As LiquidAssets
        Dim _CurrencyName As CurrencyName
        Dim _BankInformation As BankInformation
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", False)
        _Maximum = 0

        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Cassa "
            mSQL = mSQL & " Where CégSzám=1"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Comment,t1.Deviza,t1.Tipus,t2.Számlaszám,t1.Bankszámlaszám"
            mSQL = mSQL & " from Cassa t1 left join Költségek t2 on"
            mSQL = mSQL & " t1.KöltségID=t2.ID"


            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _LiquidAssets = _uow.FindObject(Of LiquidAssets)(CriteriaOperator.Parse("ShortName=?", dr("Comment")), True)
                    If _LiquidAssets Is Nothing Then
                        _LiquidAssets = New LiquidAssets(_uow)
                    End If
                    _LiquidAssets.ShortName = dr("Comment")
                    _CurrencyName = _uow.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName=?", dr("Deviza")), True)

                    Select Case dr("Tipus")
                        Case 0
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.NormalCheckout
                        Case 1
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.NormalBank

                            '-- Fel kell vinni a bankszámlaszámokat
                            _BankInformation = _uow.FindObject(Of BankInformation)(CriteriaOperator.Parse("AccountNumber=?", dr("Bankszámlaszám")))
                            If _BankInformation Is Nothing Then
                                _BankInformation = New BankInformation(_uow)
                            End If
                            _BankInformation.AccountNumber = dr("Bankszámlaszám")
                            _BankInformation.LiquidAssests = _LiquidAssets
                            _BankInformation.CurrencyName = _CurrencyName

                            Dim _CustomerBankAccounts As CustomerBankAccounts = _uow.FindObject(Of CustomerBankAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                CriteriaOperator.Parse("Customers.Oid=? and AccountNumber=?", _CustomersFrom.Oid, dr("Bankszámlaszám")))
                            If _CustomerBankAccounts Is Nothing Then
                                _CustomerBankAccounts = New CustomerBankAccounts(_uow)
                                _CustomerBankAccounts.Customers = TryCast(_CustomersFrom, Customers)
                            End If
                            _CustomerBankAccounts.AccountNumber = dr("Bankszámlaszám")

                        Case 2
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.DepositCheckout
                        Case 3
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.Compensatory
                        Case 4
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.CurrencyCheckout
                        Case 5
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.SpecialTransaction
                        Case 6
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.TechnicalTransaction
                        Case 7
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.SimpleReceipt
                        Case 8
                            _LiquidAssets.LiquidAssetsType = eLiquidAssetsType.Virtual
                    End Select
                    _LiquidAssets.CurrencyName = _CurrencyName
                    _LiquidAssets.CustomerFrom = _CustomersFrom

                    Dim _LiquidAssetsYear As LiquidAssetsYear

                    _LiquidAssetsYear = _uow.FindObject(Of LiquidAssetsYear)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                             CriteriaOperator.Parse("LiquidAssets=? and AccountYear=2010"))
                    If _LiquidAssetsYear Is Nothing Then
                        _LiquidAssetsYear = New LiquidAssetsYear(_uow)
                    End If
                    _LiquidAssetsYear.AccountYear = 2010
                    _LiquidAssetsYear.LiquidAssets = _LiquidAssets
                    _LiquidAssetsYear.ChartOfAccounts = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2010", dr("Számlaszám")))


                    _LiquidAssetsYear = _uow.FindObject(Of LiquidAssetsYear)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                             CriteriaOperator.Parse("LiquidAssets=? and AccountYear=2011"))
                    If _LiquidAssetsYear Is Nothing Then
                        _LiquidAssetsYear = New LiquidAssetsYear(_uow)
                    End If
                    _LiquidAssetsYear.AccountYear = 2011
                    _LiquidAssetsYear.LiquidAssets = _LiquidAssets
                    _LiquidAssetsYear.ChartOfAccounts = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2011", dr("Számlaszám")))


                    _LiquidAssetsYear = _uow.FindObject(Of LiquidAssetsYear)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                             CriteriaOperator.Parse("LiquidAssets=? and AccountYear=2012"))
                    If _LiquidAssetsYear Is Nothing Then
                        _LiquidAssetsYear = New LiquidAssetsYear(_uow)
                    End If
                    _LiquidAssetsYear.AccountYear = 2012
                    _LiquidAssetsYear.LiquidAssets = _LiquidAssets
                    _LiquidAssetsYear.ChartOfAccounts = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2012", dr("Számlaszám")))

                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
        Frame.GetController(Of DevExpress.ExpressApp.Validation.PersistenceValidationController)().Active.SetItemValue("", True)
    End Sub
    Private Sub Import_VAT_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_VAT.Execute
        '-- ÁFA kódok importálása
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim connstr As String

        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _ChartOfAccounts As ChartOfAccounts
        Dim _VAT As VAT
        _Maximum = 0

        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from VAT "
            mSQL = mSQL & " Where CégSzám=1"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select ShortName=isnull(t1.ShortName,''),"
            mSQL += " Description=isnull(t1.Description,''),"
            mSQL += " Value=isnull(t1.Value,0),"
            mSQL += " CIn=isnull(t2.Számlaszám,''),"
            mSQL += " COut=isnull(t3.Számlaszám,''),"
            mSQL += " Fordított=isnull(t1.Fordított,0),"
            mSQL += " FordítottKulcs=isnull(t1.FordítottKulcs,0),"
            mSQL += " Igényelhető=isnull(t1.Igényelhető,0)"

            mSQL = mSQL & " from VAT t1 left join Költségek t2 on"
            mSQL = mSQL & " t1.KöltségIDIn=t2.ID left join Költségek t3 on"
            mSQL = mSQL & " t1.KöltségIDOut=t3.ID"


            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _VAT = _uow.FindObject(Of VAT)(CriteriaOperator.Parse("ShortName=?", dr("ShortName")), True)
                    If _VAT Is Nothing Then
                        _VAT = New VAT(_uow)
                    End If
                    _VAT.ShortName = dr("ShortName")
                    _VAT.Description = dr("Description")
                    _VAT.KeyValue = dr("Value")

                    _VAT.InversState = dr("Fordított")
                    _VAT.InversKeyValue = dr("FordítottKulcs")
                    _VAT.ClaimState = dr("Igényelhető")

                    Dim _VATYear As VATYear

                    _VATYear = _uow.FindObject(Of VATYear)(PersistentCriteriaEvaluationBehavior.InTransaction, CriteriaOperator.Parse("VAT=? and AccountYear=2010", _VAT))
                    If _VATYear Is Nothing Then
                        _VATYear = New VATYear(_uow)
                    End If
                    _VATYear.AccountYear = 2010
                    _VATYear.ChartOfAccountsIn = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2010", dr("CIn")))
                    _VATYear.ChartOfAccountsOut = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2010", dr("COut")))
                    _VATYear.VAT = _VAT

                    _VATYear = _uow.FindObject(Of VATYear)(PersistentCriteriaEvaluationBehavior.InTransaction, CriteriaOperator.Parse("VAT=? and AccountYear=2011", _VAT))
                    If _VATYear Is Nothing Then
                        _VATYear = New VATYear(_uow)
                    End If
                    _VATYear.AccountYear = 2011
                    _VATYear.ChartOfAccountsIn = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2011", dr("CIn")))
                    _VATYear.ChartOfAccountsOut = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2011", dr("COut")))
                    _VATYear.VAT = _VAT


                    _VATYear = _uow.FindObject(Of VATYear)(PersistentCriteriaEvaluationBehavior.InTransaction, CriteriaOperator.Parse("VAT=? and AccountYear=2012", _VAT))
                    If _VATYear Is Nothing Then
                        _VATYear = New VATYear(_uow)
                    End If
                    _VATYear.AccountYear = 2012
                    _VATYear.ChartOfAccountsIn = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2012", dr("CIn")))
                    _VATYear.ChartOfAccountsOut = _uow.FindObject(Of ChartOfAccounts)(PersistentCriteriaEvaluationBehavior.InTransaction, _
                                                                                            CriteriaOperator.Parse("AccountNumber=? and AccountYear=2012", dr("COut")))
                    _VATYear.VAT = _VAT

                    _uow.CommitChanges()
                    _WaitFormClass.DoWork()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_GL_Execute(ByVal sender As System.Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_GL.Execute
        '// Az eljárás a teljes főkönyvet beolvassa a régi rendszerből

        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim _connstr As String
        Dim i As Long = 0

        _connstr = " User ID=" & _SQLImports.SQLUser & "; "
        _connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        _connstr &= " Pooling=false;"
        _connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        _connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(_connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        _Maximum = 0

        mSQL = " select DB=count(*) "
        mSQL = mSQL & " from FKBizonylatok t1  "

        mSQL = mSQL & " where t1.Feladásból=0 and "
        mSQL = mSQL & " t1.ED <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.ED >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"


        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()


        mSQL = " select ID=t1.ID "
        mSQL = mSQL & " from FKBizonylatok t1  "

        mSQL = mSQL & " where t1.Feladásból=0 and "
        mSQL = mSQL & " t1.ED <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.ED >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
        mSQL = mSQL & " order by t1.ID"




        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.InitWork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                i += 1
                BaseImport.Import_GLMixed(dr("ID"), _uow, _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid), _connstr)
                If i Mod 1000 Then _uow.CommitChanges()
            End While
        End If

        _uow.CommitChanges()
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_Invoices_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Invoices.Execute
        '// A rutin az egyedi számlákat importálja

        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim connstr As String

        Dim _i As Long = 0
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader


        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Bill_Sum "
            mSQL = mSQL & " Where CégSzám=1"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()
            _WaitFormClass.InitWork(1, 1, _Maximum)
            mSQL = "select t1.ShortName,t1.Description,t1.Value,CIn=t2.Számlaszám,COut=t3.Számlaszám"
            mSQL = mSQL & " from VAT t1 left join Költségek t2 on"
            mSQL = mSQL & " t1.KöltségIDIn=t2.ID left join Költségek t3 on"
            mSQL = mSQL & " t1.KöltségIDOut=t3.ID"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _i += 1


                    If _i Mod 100 Then _uow.CommitChanges()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _uow.CommitChanges()
        _WaitFormClass.Finalwork()

    End Sub
#Region "GL"
    Private Sub Import_GLAccounts_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_GLAccounts.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim _connstr As String
        Dim i As Long = 0


        _connstr = " User ID=" & _SQLImports.SQLUser & "; "
        _connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        _connstr &= " Pooling=false;"
        _connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        _connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(_connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        _Maximum = 0

        mSQL = "select DB=count(*)"
        mSQL = mSQL & " from Folyó_Bizonylatok t1"
        mSQL = mSQL & " Where  t1.TD <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.TD >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()

        mSQL = "select t1.ID "
        mSQL = mSQL & " from Folyó_Bizonylatok t1"
        mSQL = mSQL & " Where  t1.TD <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.TD >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
        'mSQL = mSQL & " Where t1.Bizonylatszám='AM8SB 7315242'"

        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.Initwork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                i += 1
                BaseImport.Import_GLAccounts(dr("ID"), _uow, _SQLImports.CustomersFrom, _connstr)
                If i Mod 1000 Then _uow.CommitChanges()
            End While
        End If

        _uow.CommitChanges()
        _WaitFormClass.FinalWork()
    End Sub
    Private Sub Import_GCassa_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_GCassa.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim _connstr As String
        Dim i As Long = 0
        Dim _ListView As ListPropertyEditor = TryCast(View, DetailView).FindItem("LiquidAssets_Cassa")
        Dim _LiquidAssets_Cassa As LiquidAssets = TryCast(_ListView.ListView.SelectedObjects(0), LiquidAssets)

        If _LiquidAssets_Cassa Is Nothing Then Exit Sub

        _connstr = " User ID=" & _SQLImports.SQLUser & "; "
        _connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        _connstr &= " Pooling=false;"
        _connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        _connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(_connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        _Maximum = 0

        mSQL = " select DB=count(*) from "
        mSQL = mSQL & " (select t2.Comment"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"
        mSQL = mSQL & " where(t2.Tipus = 1) and "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and"
        mSQL = mSQL & " t2.Comment='" & _LiquidAssets_Cassa.ShortName & "'"
        mSQL = mSQL & " group by t2.Comment,t1.LinkNumber) t1"


        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()


        mSQL = " select t1.Cassa,t2.Comment,t1.LinkNumber"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"

        mSQL = mSQL & " where(t2.Tipus = 1) and "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and "
        mSQL = mSQL & " t2.Comment='" & _LiquidAssets_Cassa.ShortName & "'"

        mSQL = mSQL & " group by t1.Cassa,t2.Comment,t1.LinkNumber"
        mSQL = mSQL & " order by t1.Cassa,t2.Comment,t1.LinkNumber"



        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.Initwork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                i += 1
                BaseImport.Import_GLCassa(dr("Cassa"), _uow.GetObjectByKey(Of LiquidAssets)(_LiquidAssets_Cassa.Oid), LTrim(RTrim(CStr(dr("LinkNumber")))), _
                                          _uow, _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid), _connstr)
                If i Mod 1000 Then _uow.CommitChanges()
            End While
        End If

        _uow.CommitChanges()
        _WaitFormClass.FinalWork()
    End Sub
    Private Sub Import_GLBank_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_GLBank.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim _connstr As String
        Dim i As Long = 0
        Dim _ListView As ListPropertyEditor = TryCast(View, DetailView).FindItem("BankInformation")
        Dim _BankInformation As BankInformation = TryCast(_ListView.ListView.SelectedObjects(0), BankInformation)

        If _BankInformation Is Nothing Then Exit Sub

        _connstr = " User ID=" & _SQLImports.SQLUser & "; "
        _connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        _connstr &= " Pooling=false;"
        _connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        _connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(_connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        _Maximum = 0

        mSQL = " select DB=count(*) from "
        mSQL = mSQL & " (select t2.Comment"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"
        mSQL = mSQL & " where  "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and "
        mSQL = mSQL & " t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and "
        mSQL = mSQL & " t2.Comment='" & _BankInformation.LiquidAssests.ShortName & "'"
        mSQL = mSQL & " group by t2.Comment,convert(varchar(10),t1.Date,111)) t1"


        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()


        mSQL = " select t1.Cassa,t2.Comment,Date=convert(varchar(10),t1.Date,111),max(t1.TömbSorszám)"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"

        mSQL = mSQL & " where  "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and "
        mSQL = mSQL & " t2.Comment='" & _BankInformation.LiquidAssests.ShortName & "'"

        mSQL = mSQL & " group by t1.Cassa,t2.Comment,convert(varchar(10),t1.Date,111)"
        mSQL = mSQL & " order by t1.Cassa,t2.Comment,convert(varchar(10),t1.Date,111)"



        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.Initwork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                i += 1
                BaseImport.Import_GLBank(dr("Cassa"), _uow.GetObjectByKey(Of LiquidAssets)(_BankInformation.LiquidAssests.Oid), dr("Date"), _uow, _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid), _connstr)
                If i Mod 1000 Then _uow.CommitChanges()
            End While
        End If

        _uow.CommitChanges()
        _WaitFormClass.FinalWork()
    End Sub
    Private Sub Import_GCompensation_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_GCompensation.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim _connstr As String
        Dim i As Long = 0
        Dim _ListView As ListPropertyEditor = TryCast(View, DetailView).FindItem("LiquidAssets_Compensation")
        Dim _LiquidAssets_Main As LiquidAssets = TryCast(_ListView.ListView.SelectedObjects(0), LiquidAssets)

        If _LiquidAssets_Main Is Nothing Then Exit Sub

        _connstr = " User ID=" & _SQLImports.SQLUser & "; "
        _connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        _connstr &= " Pooling=false;"
        _connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        _connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(_connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        _Maximum = 0

        mSQL = " select DB=count(*) from "
        mSQL = mSQL & " (select t2.Comment"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"
        mSQL = mSQL & " where  "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and"
        mSQL = mSQL & " t2.Comment='" & _LiquidAssets_Main.ShortName & "'"
        mSQL = mSQL & " group by t2.Comment,t1.LinkNumber) t1"


        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()


        mSQL = " select t1.Cassa,t2.Comment,t1.LinkNumber"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"

        mSQL = mSQL & " where  "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and "
        mSQL = mSQL & " t2.Comment='" & _LiquidAssets_Main.ShortName & "'"

        mSQL = mSQL & " group by t1.Cassa,t2.Comment,t1.LinkNumber"
        mSQL = mSQL & " order by t1.Cassa,t2.Comment,t1.LinkNumber"



        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.Initwork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                i += 1
                BaseImport.Import_GLCompensation(dr("Cassa"), _uow.GetObjectByKey(Of LiquidAssets)(_LiquidAssets_Main.Oid), LTrim(RTrim(CStr(dr("LinkNumber")))), _
                                          _uow, _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid), _connstr)
                If i Mod 1000 Then _uow.CommitChanges()
            End While
        End If
        _uow.CommitChanges()
        _WaitFormClass.FinalWork()
    End Sub
#End Region
    Private Sub Import_UniqueObject_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_UniqueObject.Execute
        '-- Egyedi azonosítók importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _UniqueObjects As UniqueObjects
        Dim _UniqueObjects_Parent As UniqueObjects
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Egyedi"
            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Megnevezés,Megnevezés_Parent=t2.Megnevezés"
            mSQL = mSQL & " from Egyedi t1 left join Egyedi t2 on"
            mSQL = mSQL & " t1.ParentID=t2.ID"
            mSQL = mSQL & " order by t1.LevelID,t1.Megnevezés"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _UniqueObjects = _uow.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", dr("Megnevezés")))
                    _UniqueObjects_Parent = _uow.FindObject(Of UniqueObjects)(CriteriaOperator.Parse("Name=?", dr("Megnevezés_Parent")))
                    If _UniqueObjects Is Nothing Then
                        _UniqueObjects = New UniqueObjects(_uow)
                    End If

                    _UniqueObjects.Name = dr("Megnevezés")
                    If _UniqueObjects_Parent Is Nothing Then
                    Else
                        _UniqueObjects.Parent = _UniqueObjects_Parent
                    End If
                    _UniqueObjects.Save()
                    _WaitFormClass.DoWork()
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception

        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_Invoices_Business_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Invoices_Business.Execute
        '// Az sql_Main-ban kiállított vevõi számlákat tölti át.
        '// Elõtte kell a fõkönyvi teljes áttöltés

        On Error GoTo CheckError

        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String = String.Format(" User ID={0}; ", _SQLImports.SQLUser)
        connstr &= String.Format(" Password={0};", _SQLImports.SQLPassword)
        connstr &= " Pooling=false;"
        connstr &= String.Format(" Data Source={0};", _SQLImports.SQLServer)
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim cmd1 As New SqlCommand
        Dim dr As SqlDataReader
        Dim dr1 As SqlDataReader

        Dim _InvoiceHeader As InvoiceHeader
        Dim _InvoiceRows As InvoiceRows
        _Maximum = 0

        mSQL = "select DB=count(*)"
        mSQL = mSQL & " from Számlaössz"
        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()

        mSQL = "select *"
        mSQL = mSQL & " from Számlaössz"
        mSQL = mSQL & " order by ID asc"

        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.InitWork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()

                _InvoiceHeader = _uow.FindObject(Of InvoiceHeader)(CriteriaOperator.Parse("DocumentNumber=? and CustomersFrom.Oid=?", dr("Bizonylatszám"), _SQLImports.CustomersFrom.Oid))

                mSQL = "select * from Számla"
                mSQL = mSQL & " Where Bizonylatszám=1" & dr("Bizonylatszám") & "'"
                cmd1.CommandTimeout = 60
                cmd1.Connection = conn
                cmd1.CommandType = CommandType.Text
                cmd1.CommandText = mSQL

                If conn.State = ConnectionState.Open Then
                    dr1 = cmd1.ExecuteReader(CommandBehavior.SingleResult)
                    While dr1.Read

                    End While
                End If
            End While
        End If
        _WaitFormClass.Finalwork()
        Exit Sub
CheckError:

        If Err.Number = 91 Then Resume Next
        If Err.Number = 13 Then Resume Next

    End Sub
    Private Sub Import_CostHolder_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_CostHolder.Execute
        '-- Egyedi azonosítók importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _CostHolder As CostHolder
        Dim _CostHolder_Parent As CostHolder
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Költségviselő"
            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Megnevezés,Megnevezés_Parent=t2.Megnevezés"
            mSQL = mSQL & " from Költségviselő t1 left join Költségviselő t2 on"
            mSQL = mSQL & " t1.ParentID=t2.ID"
            mSQL = mSQL & " order by t1.LevelID,t1.Megnevezés"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _CostHolder = _uow.FindObject(Of CostHolder)(CriteriaOperator.Parse("Name=?", dr("Megnevezés")))
                    _CostHolder_Parent = _uow.FindObject(Of CostHolder)(CriteriaOperator.Parse("Name=?", dr("Megnevezés_Parent")))
                    If _CostHolder Is Nothing Then
                        _CostHolder = New CostHolder(_uow)
                    End If

                    _CostHolder.Name = dr("Megnevezés")
                    If _CostHolder_Parent Is Nothing Then
                    Else
                        _CostHolder.Parent = _CostHolder_Parent
                    End If
                    _CostHolder.Save()
                    _uow.CommitChanges()
                End While
            End If
        Catch ex As Exception

        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub Import_CostPlace_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_CostPlace.Execute
        '-- Költséghely azonosítók importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _CostPlace As CostPlace
        Dim _CostPlace_Parent As CostPlace
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Költséghely"
            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Megnevezés,Megnevezés_Parent=t2.Megnevezés"
            mSQL = mSQL & " from Költséghely t1 left join Költséghely t2 on"
            mSQL = mSQL & " t1.ParentID=t2.ID"
            mSQL = mSQL & " order by t1.LevelID,t1.Megnevezés"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _CostPlace = _uow.FindObject(Of CostPlace)(CriteriaOperator.Parse("Name=?", dr("Megnevezés")))
                    _CostPlace_Parent = _uow.FindObject(Of CostPlace)(CriteriaOperator.Parse("Name=?", dr("Megnevezés_Parent")))
                    If _CostPlace Is Nothing Then
                        _CostPlace = New CostPlace(_uow)
                    End If

                    _CostPlace.Name = dr("Megnevezés")
                    If _CostPlace_Parent Is Nothing Then
                    Else
                        _CostPlace.Parent = _CostPlace_Parent
                    End If
                    _CostPlace.Save()
                    _uow.CommitChanges()
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception

        End Try
        _WaitFormClass.Finalwork()
    End Sub
    Private Sub JobNumberObject_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles JobNumberObject.Execute
        '-- Munkaszámok importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _JobNumberObjects As JobNumberObjects
        Dim _JobNumberObjects_Parent As JobNumberObjects
        _Maximum = 0
        Try
            mSQL = "select DB=count(*)"
            mSQL = mSQL & " from Munkaszám"
            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select t1.Megnevezés,Megnevezés_Parent=t2.Megnevezés"
            mSQL = mSQL & " from Munkaszám t1 left join Munkaszám t2 on"
            mSQL = mSQL & " t1.ParentID=t2.ID"
            mSQL = mSQL & " order by t1.LevelID,t1.Megnevezés"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            _WaitFormClass.InitWork(1, 1, _Maximum)
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _JobNumberObjects = _uow.FindObject(Of JobNumberObjects)(CriteriaOperator.Parse("Name=?", dr("Megnevezés")))
                    _JobNumberObjects_Parent = _uow.FindObject(Of JobNumberObjects)(CriteriaOperator.Parse("Name=?", dr("Megnevezés_Parent")))
                    If _JobNumberObjects Is Nothing Then
                        _JobNumberObjects = New JobNumberObjects(_uow)
                    End If
                    _JobNumberObjects.Name = dr("Megnevezés")
                    If _JobNumberObjects_Parent Is Nothing Then
                    Else
                        _JobNumberObjects.Parent = _JobNumberObjects_Parent
                    End If
                    _JobNumberObjects.Save()
                    _uow.CommitChanges()
                End While
            End If
        Catch ex As Exception

        End Try
        _WaitFormClass.Finalwork()
    End Sub


    Private Sub Import_SpecTran_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_SpecTran.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim _connstr As String
        Dim i As Long = 0
        Dim _ListView As ListPropertyEditor = TryCast(View, DetailView).FindItem("LiquidAssets_SpecTran")
        Dim _LiquidAssets_Main As LiquidAssets = TryCast(_ListView.ListView.SelectedObjects(0), LiquidAssets)

        If _LiquidAssets_Main Is Nothing Then Exit Sub

        _connstr = " User ID=" & _SQLImports.SQLUser & "; "
        _connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        _connstr &= " Pooling=false;"
        _connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        _connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(_connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        _Maximum = 0

        mSQL = " select DB=count(*) from "
        mSQL = mSQL & " (select t2.Comment"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"
        mSQL = mSQL & " where "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and"
        mSQL = mSQL & " t2.Comment='" & _LiquidAssets_Main.ShortName & "'"
        mSQL = mSQL & " group by t2.Comment,t1.LinkNumber) t1"


        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()


        mSQL = " select t1.Cassa,t2.Comment,t1.LinkNumber"

        mSQL = mSQL & " from Cassa_Sum t1 join Cassa t2 on"
        mSQL = mSQL & " t1.Cassa = t2.Cassa"

        mSQL = mSQL & " where "
        mSQL = mSQL & " t1.Date <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t1.Date >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "' and "
        mSQL = mSQL & " t2.Comment='" & _LiquidAssets_Main.ShortName & "'"

        mSQL = mSQL & " group by t1.Cassa,t2.Comment,t1.LinkNumber"
        mSQL = mSQL & " order by t1.Cassa,t2.Comment,t1.LinkNumber"



        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.InitWork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                i += 1
                Dim _LinkNumber As String = ""
                _LinkNumber = LTrim(RTrim(CStr(dr("LinkNumber"))))
                _LinkNumber = "130000260"
                BaseImport.Import_GLCompensation(dr("Cassa"), _uow.GetObjectByKey(Of LiquidAssets)(_LiquidAssets_Main.Oid), _LinkNumber, _
                                          _uow, _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid), _connstr)
                If i Mod 1000 Then _uow.CommitChanges()
            End While
        End If
        _uow.CommitChanges()
        _WaitFormClass.Finalwork()
    End Sub

    Private Sub Import_Contacts_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Contacts.Execute
        '-- Kapcsolattartók importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String
        Dim connstr As String

        On Error GoTo CheckError

        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _Contacts As Contacts
        Dim _Customers As Customers
        Dim _ImportedID As Long

        _Maximum = 0

        mSQL = "select DB=count(*)"
        mSQL = mSQL & " from Ügyféltörzs_Kapcsolat t1 "
        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            While dr.Read
                _Maximum = dr("DB")
            End While
        End If
        conn.Close()

        mSQL = "select ID=t1.ID,Keresztnév=isnull(t1.Keresztnév,''),Vezetéknév=isnull(t1.Vezetéknév,''),Beosztás=isnull(t1.Beosztás,''), "
        mSQL = mSQL & " Egyéb=isnull(t1.Egyéb,''),EMail=isnull(isnull(t1.EMail,t2.EMail),''),"
        mSQL = mSQL & " Fax=case when ltrim(rtrim(isnull(isnull(t1.Fax,t2.Fax),'')))='' then isnull(t2.Fax,'') else ltrim(rtrim(isnull(isnull(t1.Fax,t2.Fax),''))) end,"
        mSQL = mSQL & " Telefon=case when ltrim(rtrim(isnull(isnull(t1.Telefon,t2.Telefon),'')))='' then isnull(t2.Telefon,'') else ltrim(rtrim(isnull(isnull(t1.Telefon,t2.Telefon),''))) end,"
        mSQL = mSQL & " Mobil=isnull(t1.Mobil,''),Ügyfélszám=t1.Ügyfélszám"

        mSQL = mSQL & " from Ügyféltörzs_Kapcsolat t1 left join Ügyféltörzs t2 on"
        mSQL = mSQL & " t1.Ügyfélszám=t2.Ügyfélszám"



        cmd.CommandTimeout = 60
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = mSQL
        conn.Open()
        If conn.State = ConnectionState.Open Then
            dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
            _WaitFormClass.InitWork(1, 1, _Maximum)
            While dr.Read
                _WaitFormClass.DoWork()
                _ImportedID = dr("ID")
                _Contacts = _uow.FindObject(Of Contacts)(CriteriaOperator.Parse("ImportedID=?", _ImportedID))
                If _Contacts Is Nothing Then
                    _Contacts = _uow.FindObject(Of Contacts)(CriteriaOperator.Parse("FirstName=? and LastName=? and Customers.CustomerNumber=?", dr("Keresztnév"), dr("Vezetéknév"), dr("Ügyfélszám")))
                    If _Contacts Is Nothing Then
                        _Contacts = New Contacts(_uow)
                        _Contacts.FirstName = dr("Keresztnév")
                        _Contacts.LastName = dr("Vezetéknév")
                        _Contacts.Position = dr("Beosztás")
                        _Contacts.Email = dr("EMail")
                        _uow.Delete(_Contacts.PhoneNumbers)
                        Dim _OfficePhone As DevExpress.Persistent.BaseImpl.PhoneNumber = New PhoneNumber(_uow)
                        _OfficePhone.PhoneType = "OfficePhone"
                        _OfficePhone.Number = dr("Telefon")
                        _Contacts.PhoneNumbers.Add(_OfficePhone)

                        Dim _Fax As DevExpress.Persistent.BaseImpl.PhoneNumber = New PhoneNumber(_uow)
                        _Fax.PhoneType = "Fax"
                        _Fax.Number = dr("Fax")
                        _Contacts.PhoneNumbers.Add(_Fax)

                        Dim _MobilePhone As DevExpress.Persistent.BaseImpl.PhoneNumber = New PhoneNumber(_uow)
                        _MobilePhone.PhoneType = "MobilePhone"
                        _MobilePhone.Number = dr("Mobil")
                        _Contacts.PhoneNumbers.Add(_MobilePhone)

                        _Customers = _uow.FindObject(Of Customers)(CriteriaOperator.Parse("CustomerNumber=?", dr("Ügyfélszám")))
                        _Contacts.Customers = _Customers
                        _Contacts.MobileTelephoneNumber = dr("Mobil")
                        _Contacts.BusinessTelephoneNumber = dr("Telefon")
                        _Contacts.BusinessFaxNumber = dr("Fax")


                        '// Cím1-be menjen bele az ügyfél címe
                        If _Contacts.Customers.Address1 IsNot Nothing Then
                            _Contacts.Address1 = _Contacts.Customers.Address1
                        End If
                        _Contacts.ImportedID = _ImportedID
                        _Contacts.Save()

                    Else
                        _Contacts.ImportedID = _ImportedID
                        _Contacts.Save()
                    End If
                End If

                _uow.CommitChanges()
            End While
        End If

        _WaitFormClass.Finalwork()
        Exit Sub
CheckError:

        If Err.Number = 91 Then Resume Next
        If Err.Number = 13 Then Resume Next


    End Sub

    Private Sub Import_HRPerson_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_HRPerson.Execute
        '-- Terméktörzs importálása
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String = String.Format(" User ID={0}; ", _SQLImports.SQLUser)
        connstr &= String.Format(" Password={0};", _SQLImports.SQLPassword)
        connstr &= " Pooling=false;"
        connstr &= String.Format(" Data Source={0};", _SQLImports.SQLServer)
        connstr &= " Initial Catalog=sql_Permission"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim _HRPerson As HRPerson
        Dim _HRGroups As HRGroups
        Dim _Address As Address = Nothing
        Dim _User As User
        Dim _Role As Role = _uow.FindObject(Of Role)(CriteriaOperator.Parse("Name='Administrators'"))
        Dim _FirstName As String = ""
        Dim _LastName As String = ""
        Dim sArray As String()
        _Maximum = 0

        Try
            mSQL = "select DB=count(*)"
            mSQL += " from  Személyzet t1"
            mSQL += " Where isnull(t1.Törölve,0)=0"

            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = ""
            mSQL += "select "
            mSQL += " Név=isnull(t1.Név,''),"
            mSQL += " Cím=isnull(t1.Cím,''),"
            mSQL += " Telefon=isnull(t1.Telefon,''),"
            mSQL += " Mobil=isnull(t1.Mobil,''),"
            mSQL += " Fax=isnull(t1.Fax,''),"
            mSQL += " EMail=isnull(t1.EMail,''),"
            mSQL += " Munkacsoport=isnull(t1.Munkacsoport,''),"
            mSQL += " Munkakör=isnull(t1.Munkakör,''),"
            mSQL += " Vonalkód=isnull(t1.Vonalkód,''),"
            mSQL += " UserName=isnull(t1.UserName,'')"

            mSQL += " from Személyzet t1"

            mSQL += " Where isnull(t1.Törölve,0)=0 and replace(isnull(t1.Név,''),' ','')<>''"
            mSQL += " order by isnull(Név,'')"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    sArray = dr("Név").ToString.Split(" ")
                    If UBound(sArray) = 2 Then
                        _FirstName = sArray(2)
                        _LastName = String.Format("{0} {1}", sArray(0), sArray(1))
                    End If
                    If UBound(sArray) = 1 Then
                        _FirstName = sArray(1)
                        _LastName = sArray(0)
                    End If
                    If UBound(sArray) = 0 Then
                        _FirstName = ""
                        _LastName = sArray(0)
                    End If
                    _FirstName = LTrim(RTrim(_FirstName))
                    _LastName = LTrim(RTrim(_LastName))
                    If _FirstName <> "" Or _LastName <> "" Then
                        _HRPerson = _uow.FindObject(Of HRPerson)(CriteriaOperator.Parse("FirstName=? and LastName=?", _FirstName, _LastName))
                        If _HRPerson Is Nothing Then
                            _HRPerson = New HRPerson(_uow)
                            _HRPerson.FirstName = _FirstName
                            _HRPerson.LastName = _LastName
                        End If
                        _HRPerson.Email = dr("EMail")
                        _uow.Delete(_HRPerson.HRGroups)
                        _HRGroups = _uow.FindObject(Of HRGroups)(CriteriaOperator.Parse("ShortName=?", dr("Munkacsoport")))
                        If _HRGroups Is Nothing Then
                            _HRGroups = New HRGroups(_uow)

                        End If
                        _HRGroups.ShortName = dr("Munkacsoport")
                        _HRGroups.Description = dr("Munkacsoport")
                        _HRPerson.HRGroups.Add(_HRGroups)

                        _HRPerson.Barcode = dr("Vonalkód")
                        _HRPerson.Post = dr("Munkakör")

                        _uow.Delete(_HRPerson.PhoneNumbers)
                        Dim _OfficePhone As DevExpress.Persistent.BaseImpl.PhoneNumber = New PhoneNumber(_uow)
                        _OfficePhone.PhoneType = "OfficePhone"
                        _OfficePhone.Number = dr("Telefon")
                        _HRPerson.PhoneNumbers.Add(_OfficePhone)

                        Dim _Fax As DevExpress.Persistent.BaseImpl.PhoneNumber = New PhoneNumber(_uow)
                        _Fax.PhoneType = "Fax"
                        _Fax.Number = dr("Fax")
                        _HRPerson.PhoneNumbers.Add(_Fax)

                        Dim _MobilePhone As DevExpress.Persistent.BaseImpl.PhoneNumber = New PhoneNumber(_uow)
                        _MobilePhone.PhoneType = "MobilePhone"
                        _MobilePhone.Number = dr("Mobil")
                        _HRPerson.PhoneNumbers.Add(_MobilePhone)

                        If dr("UserName") <> "" Then
                            _User = _uow.FindObject(Of User)(CriteriaOperator.Parse("UserName=?", dr("UserName")))
                            If _User Is Nothing Then
                                _User = New User(_uow)
                                _User.UserName = dr("UserName")
                                _User.FirstName = _FirstName
                                _User.LastName = _LastName
                                _User.ChangePasswordOnFirstLogon = True
                                _User.Roles.Add(_Role)
                            End If
                            _HRPerson.User = _User
                        End If

                        _uow.CommitChanges()
                    End If
                    System.Windows.Forms.Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub

    Private Sub Import_OrderOut_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_OrderOut.Execute
        '-- Kimenő rendelés importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim conn_row As New SqlConnection(connstr)
        Dim cmd_row As New SqlCommand
        Dim dr_row As SqlDataReader

        Dim _Products As Products = Nothing
        Dim _OrderOutHeader As OrderOutHeader = Nothing
        Dim _OrderOutRows As OrderOutRows = Nothing
        Dim _CustomersOrder As CustomersOrder = Nothing
        Dim _CurrencyName As CurrencyName = Nothing
        _Maximum = 0
        Try
            mSQL = " select DB=COUNT(*) from ("
            mSQL = mSQL & "  select Ügyfélszám,RendSzám,TömbSorszám"
            mSQL = mSQL & " from Rendelés_Lezárt "
            mSQL = mSQL & " where Ügyfélszám > 0 "
            mSQL = mSQL & " and  Time <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and Time >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
            mSQL = mSQL & " group by Ügyfélszám,RendSzám,TömbSorszám) t1"


            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select Ügyfélszám,RendSzám,TömbSorszám=case when ltrim(rtrim(isnull(TömbSorszám,'')))='' then 'BR-'+convert(varchar(10),RendSzám) else TömbSorszám end ,"
            mSQL = mSQL & " Time=MAX(Time),Deviza=max(Deviza),ÖsszesenHUF=SUM((ÁrS-AES)*(Rendelt+Foglalt)),ÖsszesenDEV=SUM((DÁrS-DAES)*(Rendelt+Foglalt))"
            mSQL = mSQL & " from Rendelés_Lezárt"
            mSQL = mSQL & " where Ügyfélszám > 0 and Megjött<Rendelt+Foglalt and Megjött>=0"
            mSQL = mSQL & " and  Time <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and Time >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
            mSQL = mSQL & " group by Ügyfélszám,RendSzám,TömbSorszám"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _CustomersOrder = _uow.FindObject(Of CustomersOrder)(CriteriaOperator.Parse("CustomerNumber=?", dr("Ügyfélszám").ToString))
                    _CurrencyName = _uow.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName=?", dr("Deviza")))
                    If _CustomersOrder IsNot Nothing Then
                        _OrderOutHeader = _uow.FindObject(Of OrderOutHeader)(CriteriaOperator.Parse("CustomersOrder=? and DocumentNumber=?", _CustomersOrder, dr("TömbSorszám")))
                        If _OrderOutHeader Is Nothing Then
                            _OrderOutHeader = New OrderOutHeader(_uow)
                        End If

                        _OrderOutHeader.CurrencyName = _CurrencyName
                        _OrderOutHeader.CustomersFrom = _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid)

                        _OrderOutHeader.CustomersOrder = _CustomersOrder

                        _OrderOutHeader.DateCreated = dr("Time")
                        _OrderOutHeader.DateExecution = dr("Time")
                        _OrderOutHeader.DocumentNumber = dr("TömbSorszám")


                        _OrderOutHeader.IsEditable = False
                        _OrderOutHeader.IsStorno = False
                        _OrderOutHeader.PaymentOption = _uow.FindObject(Of PaymentOption)(CriteriaOperator.Parse("PayMode='InTransfer'"))
                        _OrderOutHeader.TotalNettoHUF = dr("ÖsszesenHUF")
                        _OrderOutHeader.TotalNettoDEV = dr("ÖsszesenDEV")

                        mSQL = "select   Cikkszám=isnull(Cikkszám,''),"
                        mSQL = mSQL & "  Rendelt=isnull(Rendelt+Foglalt,0),"
                        mSQL = mSQL & "  ÁrS=isnull(ÁrS,0),"
                        mSQL = mSQL & "  AES=isnull(ÁrS,0),"
                        mSQL = mSQL & "  RM=isnull(Rendelt+Foglalt,0),"
                        mSQL = mSQL & "  DÁrS=isnull(DÁrS,0),"
                        mSQL = mSQL & "  DAES=isnull(DÁrS,0),"
                        mSQL = mSQL & "  Perc=isnull(case when ÁrS<>0 then round(AES/ÁrS ,4) end,0)  "


                        mSQL = mSQL & " from Rendelés_Lezárt"
                        mSQL = mSQL & " Where Ügyfélszám=" & dr("Ügyfélszám").ToString & " and RendSzám=" & dr("RendSzám").ToString '& " and TömbSorszám='" & dr("TömbSorszám").ToString & "'"
                        cmd_row.CommandTimeout = 60
                        cmd_row.Connection = conn_row
                        cmd_row.CommandType = CommandType.Text
                        cmd_row.CommandText = mSQL
                        conn_row.Open()
                        If conn_row.State = ConnectionState.Open Then
                            dr_row = cmd_row.ExecuteReader(CommandBehavior.SingleResult)
                            While dr_row.Read

                                _OrderOutRows = New OrderOutRows(_uow)
                                _OrderOutRows.DiscountPercent = dr_row("Perc")
                                _OrderOutRows.ListPriceDEV() = dr_row("DÁrS")
                                _OrderOutRows.ListPriceHUF() = dr_row("ÁrS")
                                _OrderOutRows.OrderOutHeader = _OrderOutHeader
                                _OrderOutRows.Products = _uow.FindObject(Of Products)(CriteriaOperator.Parse("ProductNumber=?", dr_row("Cikkszám")))
                                _OrderOutRows.QTT = dr_row("Rendelt")
                            End While
                        End If
                        conn_row.Close()

                        _uow.CommitChanges()
                    End If
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub

    Private Sub Import_Circulation_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Circulation.Execute
        '// Fogyások áttöltése
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader



        Dim _Products As Products = Nothing
        Dim _Storage As Storage = Nothing
        Dim _StorageOutCirculation As StorageOutCirculation = Nothing
        Dim _YearExecution As Long
        _Maximum = 0
        Try
            mSQL = " select DB=COUNT(*) from ("

            mSQL = mSQL & " select Raktár=''"
            mSQL = mSQL & " from Számla_Bevétel t1 join Számlaössz t2 on"
            mSQL = mSQL & " t1.Bizonylatszám=t2.Bizonylatszám join Raktár_Új t3 on"
            mSQL = mSQL & " t1.RaktáriSzám=t3.RaktáriSzám join Raktár_Tipus t4 on"
            mSQL = mSQL & " t3.Raktár = t4.Raktár"
            mSQL = mSQL & " and  t2.TD <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t2.TD >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
            mSQL = mSQL & " group by t4.megnevezés,t1.Cikkszám,CONVERT(varchar(7),t2.TD,111)) t1"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = " select Raktár=t4.Megnevezés,Cikkszám=t1.Cikkszám,Dátum=CONVERT(varchar(7),t2.TD,111),Mennyiség=isnull(SUM(t1.Mennyiség),0),"
            mSQL = mSQL & " YearExecution=MAX(YEAR(t2.TD)),MonthExecution=MAX(month(t2.TD))"
            mSQL = mSQL & " from Számla_Bevétel t1 join Számlaössz t2 on"
            mSQL = mSQL & " t1.Bizonylatszám=t2.Bizonylatszám join Raktár_Új t3 on"
            mSQL = mSQL & " t1.RaktáriSzám=t3.RaktáriSzám join Raktár_Tipus t4 on"
            mSQL = mSQL & " t3.Raktár = t4.Raktár"
            mSQL = mSQL & " and  t2.TD <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and t2.TD >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
            mSQL = mSQL & " group by t4.megnevezés,t1.Cikkszám,CONVERT(varchar(7),t2.TD,111)"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()

                    _Storage = _uow.FindObject(Of Storage)(CriteriaOperator.Parse("ShortName=?", dr("Raktár")))
                    _Products = _uow.FindObject(Of Products)(CriteriaOperator.Parse("ProductNumber=?", dr("Cikkszám")))

                    If _Storage IsNot Nothing AndAlso _Products IsNot Nothing Then
                        _StorageOutCirculation = _uow.FindObject(Of StorageOutCirculation) _
                            (CriteriaOperator.Parse("Storage=? and Products=? and CirculationType='eAccaount' and YearExecution=?", _
                                                _Storage, _Products, dr("YearExecution")))
                        If _StorageOutCirculation Is Nothing Then
                            _StorageOutCirculation = New StorageOutCirculation(_uow)

                        End If
                        _StorageOutCirculation.CirculationType = eCirculationType.eAccaount
                        _StorageOutCirculation.Storage = _Storage
                        _StorageOutCirculation.Products = _Products
                        _StorageOutCirculation.YearExecution = dr("YearExecution")
                        Select Case dr("MonthExecution")
                            Case 1
                                _StorageOutCirculation.Month01 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 2
                                _StorageOutCirculation.Month02 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 3
                                _StorageOutCirculation.Month03 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 4
                                _StorageOutCirculation.Month04 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 5
                                _StorageOutCirculation.Month05 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 6
                                _StorageOutCirculation.Month06 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 7
                                _StorageOutCirculation.Month07 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 8
                                _StorageOutCirculation.Month08 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 9
                                _StorageOutCirculation.Month09 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 10
                                _StorageOutCirculation.Month10 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 11
                                _StorageOutCirculation.Month11 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                            Case 12
                                _StorageOutCirculation.Month12 = dr("Mennyiség")
                                _StorageOutCirculation.Total += dr("Mennyiség")
                        End Select

                        _uow.CommitChanges()

                    End If
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub

    Private Sub Import_Operations_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Operations.Execute
        '// Műveletek áttöltése
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader



        Dim _Operations As Operations

        _Maximum = 0
        Try
            mSQL = " select DB=COUNT(*) from Egyedi Where   (ParentID = 126) AND (Active = 1)"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = " select Megnevezés"
            mSQL &= " from Egyedi Where   (ParentID = 126) AND (Active = 1)"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _Operations = _uow.FindObject(Of Operations)(_uow.ParseCriteria("ShortName=?", dr("Megnevezés")))
                    If _Operations Is Nothing Then
                        _Operations = New Operations(_uow)
                        _Operations.ShortName = dr("Megnevezés")
                    End If
                    _uow.CommitChanges()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub

    Private Sub Import_Offers_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles Import_Offers.Execute
        '// Műveletek áttöltése
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Cassa"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader



        Dim _OfferAskIn As OfferAskIn

        _Maximum = 0
        Try
            mSQL = " select DB=COUNT(*) from (select t1.ID "
            mSQL = mSQL & " from Iktatás_Mark t1 join IktatóRendszer t2 on"
            mSQL = mSQL & " t1.ID_IktatóRendszer = t2.ID"
            mSQL = mSQL & " where t2.IktatóTipus = 3) t1"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = " select t1.ID,IktatóSzám=isnull(t2.IktatóSzám,''),t2.ÜgyfélszámFrom,t2.ÜgyfélszámTo,t2.IktatóTipus,"
            mSQL = mSQL & " Mark01=isnull(t1.Mark01,''),"
            mSQL = mSQL & " Mark02=isnull(t1.Mark02,''),"
            mSQL = mSQL & " Mark03=isnull(t1.Mark03,''),"
            mSQL = mSQL & " Mark04=isnull(t1.Mark04,''),"
            mSQL = mSQL & " Mark05=isnull(t1.Mark05,''),"
            mSQL = mSQL & " Mark06=isnull(t1.Mark06,''),"
            mSQL = mSQL & " Mark07=isnull(t1.Mark07,''),"
            mSQL = mSQL & " Mark08=isnull(t1.Mark08,''),"
            mSQL = mSQL & " Mark09=isnull(t1.Mark09,''),"
            mSQL = mSQL & " Mark10=isnull(t1.Mark10,''),"
            mSQL = mSQL & " Mark11=isnull(t1.Mark11,'')"

            mSQL = mSQL & " from Iktatás_Mark t1 join IktatóRendszer t2 on"
            mSQL = mSQL & " t1.ID_IktatóRendszer = t2.ID"
            mSQL = mSQL & " where t2.IktatóTipus = 3"


            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _OfferAskIn = _uow.FindObject(Of OfferAskIn)(CriteriaOperator.Parse("DocumentNumber=?", dr("IktatóSzám")))
                    If _OfferAskIn Is Nothing Then
                        _OfferAskIn = New OfferAskIn(_uow)
                        _OfferAskIn.CustomersFrom = _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid)
                    End If
                    _OfferAskIn.DocumentNumber = dr("IktatóSzám")
                    _OfferAskIn.CustomersName = dr("Mark05")
                    _OfferAskIn.ContactsName = dr("Mark06")
                    _OfferAskIn.ContactsPhone = dr("Mark07")
                    _OfferAskIn.ContactsEMail = dr("Mark08")
                    _OfferAskIn.JobNumberName = dr("Mark09")
                    _OfferAskIn.DateValid = dr("Mark02")

                    Select Case dr("Mark01")
                        Case "01-Döntésre vár"
                            _OfferAskIn.OfferAskInState = eOfferAskInState.eWaitDecisions
                        Case "01-Feldolgozás alatt"
                            _OfferAskIn.OfferAskInState = eOfferAskInState.eInProgress
                        Case "01-Következő körös"
                            _OfferAskIn.OfferAskInState = eOfferAskInState.eNextStep
                        Case "01-Visszajelzést várunk"
                            _OfferAskIn.OfferAskInState = eOfferAskInState.eWait
                        Case "02-Lemondott"
                            _OfferAskIn.OfferAskInState = eOfferAskInState.eRejected
                        Case "02-Lezárult elvesztett"
                            _OfferAskIn.OfferAskInState = eOfferAskInState.eLost
                        Case "02-Lezárult megnyert"
                            _OfferAskIn.OfferAskInState = eOfferAskInState.eWin
                    End Select
                    _uow.CommitChanges()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub

    Private Sub aScriptUpdate_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aScriptUpdate.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=Nuvolar"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader



        Dim _RegistryHeader As RegistryHeader

        _Maximum = 0
        Try
            mSQL = " select DB=COUNT(*) from (select t2.ImportedRegistryHeader"
            mSQL = mSQL & " from GLRows t1 join GLHeader t2 on"
            mSQL = mSQL & " t1.GLHeader = t2.Oid"
            mSQL = mSQL & " where t2.ImportedRegistryHeader Is Not null And t1.RegistryRowsFinancialControlling Is null And t1.Controlling Is null And t2.GCRecord Is null And t1.PartnerType = 1 "
            mSQL = mSQL & " group by t2.ImportedRegistryHeader) t1"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = " select t2.ImportedRegistryHeader "
            mSQL = mSQL & " from GLRows t1 join GLHeader t2 on"
            mSQL = mSQL & " t1.GLHeader = t2.Oid"
            mSQL = mSQL & " where t2.ImportedRegistryHeader Is Not null And t1.RegistryRowsFinancialControlling Is null And t1.Controlling Is null And t2.GCRecord Is null And t1.PartnerType = 1 "
            mSQL = mSQL & " group by t2.ImportedRegistryHeader"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()

                    _RegistryHeader = _uow.FindObject(Of RegistryHeader)(CriteriaOperator.Parse("Oid=?", dr("ImportedRegistryHeader")))

                    If _RegistryHeader IsNot Nothing Then
                        _RegistryHeader.BookEntryRemove(_RegistryHeader, _uow)
                        _RegistryHeader.BookEntry(1, _RegistryHeader, _uow)
                    End If

                    _uow.CommitChanges()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub

    Private Sub Import_OrderIn_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles Import_OrderIn.Execute
        '// Bejövő megrendelések importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim conn_row As New SqlConnection(connstr)
        Dim cmd_row As New SqlCommand
        Dim dr_row As SqlDataReader

        Dim _Customers As Customers
        Dim _Products As Products = Nothing
        Dim _OrderInHeader As OrderInHeader
        Dim _OrderInRows As OrderInRows
        Dim _CurrencyName As CurrencyName = Nothing
        _Maximum = 0
        Try
            mSQL = " select DB=COUNT(*) from ("
            mSQL = mSQL & "  select MegbSzám"
            mSQL = mSQL & " from Megbízás_Új "
            mSQL = mSQL & " where MegbMode in (1,4) and Deviza='HUF' "
            mSQL = mSQL & " and  DátumA <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and DátumA >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
            mSQL = mSQL & " ) t1"


            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select DátumA,MegbSzám,Ügyfélszám,Deviza"
            mSQL = mSQL & " "
            mSQL = mSQL & " from Megbízás_Új"
            mSQL = mSQL & " where MegbMode in (1,4) and Deviza='HUF'"
            mSQL = mSQL & " and  DátumA <='" & Replace(Format(_SQLImports.DateTo, "yyyy/MM/dd"), ".", "/") & "' and DátumA >='" & Replace(Format(_SQLImports.DateFrom, "yyyy/MM/dd"), ".", "/") & "'"
            mSQL = mSQL & " "



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _Customers = _uow.FindObject(Of Customers)(CriteriaOperator.Parse("CustomerNumber=?", dr("Ügyfélszám").ToString))
                    _CurrencyName = _uow.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName=?", dr("Deviza")))
                    If _Customers IsNot Nothing Then
                        _OrderInHeader = _uow.FindObject(Of OrderInHeader)(CriteriaOperator.Parse("Customers=? and DocumentNumber=?", _Customers, dr("MegbSzám")))
                        If _OrderInHeader Is Nothing Then
                            _OrderInHeader = New OrderInHeader(_uow)
                        End If

                        _OrderInHeader.Customers = _Customers
                        _OrderInHeader.CustomersFrom = _uow.GetObjectByKey(Of CustomersFrom)(_SQLImports.CustomersFrom.Oid)
                        _OrderInHeader.DateCreated = dr("DátumA")
                        _OrderInHeader.DateExecution = dr("DátumA")
                        _OrderInHeader.DocumentNumber = dr("MegbSzám")
                        _OrderInHeader.IsEditable = True
                        _OrderInHeader.IsStorno = False
                        _OrderInHeader.OrderInParameters = _uow.FindObject(Of OrderInParameters)(CriteriaOperator.Parse("CurrencyName.ShortName=?", dr("Deviza")))


                        mSQL = "select   Cikkszám=isnull(Cikkszám,''),"
                        mSQL = mSQL & "  Megjegyzés=isnull(Megjegyzés,''),"
                        mSQL = mSQL & "  DAE=isnull(DAE,0),"
                        mSQL = mSQL & "  AE=isnull(AE,0),"
                        mSQL = mSQL & "  Ár=isnull(Ár,0),"
                        mSQL = mSQL & "  Kiírt=isnull(Kiírt,0),"
                        mSQL = mSQL & "  Áfahiv=isnull(Áfahiv,''),"
                        mSQL = mSQL & "  DÁr=isnull(DÁr,0)"


                        mSQL = mSQL & " from Megbízás_Alkatrész"
                        mSQL = mSQL & " Where MegbSzám='" & dr("MegbSzám").ToString & "'"
                        cmd_row.CommandTimeout = 60
                        cmd_row.Connection = conn_row
                        cmd_row.CommandType = CommandType.Text
                        cmd_row.CommandText = mSQL
                        conn_row.Open()
                        If conn_row.State = ConnectionState.Open Then
                            dr_row = cmd_row.ExecuteReader(CommandBehavior.SingleResult)
                            While dr_row.Read

                                _OrderInRows = New OrderInRows(_uow)
                                _OrderInRows.OrderInHeader = _OrderInHeader

                                _OrderInRows.Description = dr_row("Megjegyzés")
                                _OrderInRows.DiscountPriceDEV = dr_row("DAE")
                                _OrderInRows.DiscountPriceHUF = dr_row("AE")
                                _OrderInRows.ListPriceDEV = dr_row("DÁr")
                                _OrderInRows.ListPriceHUF = dr_row("Ár")
                                _OrderInRows.ListPriceOriginalHUF = dr_row("Ár") - dr_row("AE")
                                _OrderInRows.Products = _uow.FindObject(Of Products)(CriteriaOperator.Parse("ProductNumber=?", dr_row("Cikkszám")))
                                _OrderInRows.QTT = dr_row("Kiírt")
                                _OrderInRows.VAT = _uow.FindObject(Of VAT)(CriteriaOperator.Parse("ShortName=?", dr_row("Áfahiv")))

                            End While
                        End If
                        conn_row.Close()

                        _uow.CommitChanges()
                    End If
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()

    End Sub

    Private Sub Import_Pricing_Execute(sender As Object, e As SimpleActionExecuteEventArgs) Handles Import_Pricing.Execute
        '// Árképzés importja
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _uow As UnitOfWork = New UnitOfWork(_ocur.Session.DataLayer)
        Dim _SQLImports As SQLImports = TryCast(View.SelectedObjects(0), SQLImports)
        Dim mSQL As String

        Dim connstr As String
        connstr = " User ID=" & _SQLImports.SQLUser & "; "
        connstr &= " Password=" & _SQLImports.SQLPassword & ";"
        connstr &= " Pooling=false;"
        connstr &= " Data Source=" & _SQLImports.SQLServer & ";"
        connstr &= " Initial Catalog=sql_Main"

        Dim conn As New SqlConnection(connstr)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        Dim conn_row As New SqlConnection(connstr)
        Dim cmd_row As New SqlCommand
        Dim dr_row As SqlDataReader

        Dim _Customers As Customers
        Dim _Products As Products = Nothing
        Dim _Pricing As Pricing
        Dim _PricingFix As PricingFix
        Dim _ShortName As String
        _Maximum = 0
        Try
            mSQL = " select DB=COUNT(*) from Ügyféltörzs_Ármátrix"


            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()
            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                While dr.Read
                    _Maximum = dr("DB")
                End While
            End If
            conn.Close()

            mSQL = "select Ár, Cikkszám, Devizanem, DevizásÁr, FM, ID, LM, Ügyfélszám, Ügyintéző"
            mSQL = mSQL & " "
            mSQL = mSQL & " from Ügyféltörzs_Ármátrix"



            cmd.CommandTimeout = 60
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = mSQL
            conn.Open()



            If conn.State = ConnectionState.Open Then
                dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
                _WaitFormClass.InitWork(1, 1, _Maximum)
                While dr.Read
                    _WaitFormClass.DoWork()
                    _Customers = _uow.FindObject(Of Customers)(CriteriaOperator.Parse("CustomerNumber=?", dr("Ügyfélszám").ToString))
                    If _Customers IsNot Nothing Then
                        _ShortName = dr("Ügyfélszám").ToString & " árképzése"
                        _Pricing = _uow.FindObject(Of Pricing)(CriteriaOperator.Parse("ShortName=?", _ShortName))
                        If _Pricing Is Nothing Then
                            _Pricing = New Pricing(_uow)
                        End If
                        _Customers.Pricing = _Pricing
                        _Pricing.ShortName = _ShortName
                        _Pricing.PartnerType = ePartnerType.eReceivables

                        _PricingFix = _uow.FindObject(Of PricingFix)(CriteriaOperator.Parse("Pricing=? and Products.ProductNumber=?", _Pricing, dr("Cikkszám")))
                        If _PricingFix Is Nothing Then
                            _PricingFix = New PricingFix(_uow)
                        End If
                        _PricingFix.Pricing = _Pricing
                        _PricingFix.CurrencyName = _uow.FindObject(Of CurrencyName)(CriteriaOperator.Parse("ShortName=?", dr("Devizanem")))
                        _PricingFix.Products = _uow.FindObject(Of Products)(CriteriaOperator.Parse("ProductNumber=?", dr("Cikkszám")))
                        If dr("Devizanem") = "HUF" Then
                            _PricingFix.PriceNetto = dr("Ár")
                        Else
                            _PricingFix.PriceNetto = dr("DevizásÁr")
                        End If
                    End If
                    _uow.CommitChanges()
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        _WaitFormClass.Finalwork()
    End Sub
End Class
