Erweiterung der Datensynchronisierung mit POS – Option 2

Daten in POS exportieren

Es ist möglich, nicht zusammenhängende Daten mit Objekten zu synchronisieren, die in POS erstellt und mit dem ERP-System synchronisiert wurden. Dazu muss die Prozedur Synchronization.ExportCustoms ausgeführt werden. Es ist zu beachten, dass die Struktur in <Customs><Custom> beizubehalten ist, während die Struktur unter dem Knoten <Customs> frei gestaltet werden kann.

Es ist gut, wenn die Struktur der Tabellen, aus denen die Daten ausgewählt werden, die hochzuladen sind, über die Baumstruktur verfügen und die Haupttabelle über folgende Spalten verfügt:

  • GUID – sorgt für Identifikation des Objekts zwischen POS und ERP
  • Id – in Bezug auf die Struktur
  • Type – wenn Sie Daten in DS unterscheiden wollen, vor allem wenn ggf. separate Erweiterungen vorhanden sind
  • WasSentToERP – filtriert Daten, die schon versandt wurden

Gesendete Daten kennzeichnen

Es ist möglich, die Standardmethode zur Kennzeichnung gesendeter Objekte für die Markierung benutzerdefinierter Objekte zu verwenden.

Überladen Sie an dieser Stelle die Service-Methode ISynchronizationRepository (dieser Bereich verfügt über keine Erweiterungspunkte)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public class SynchronizationRepositoryExt : SynchronizationRepository
{
public override void MarkIfWasSentToERP(string xml)
{
base.MarkIfWasSentToERP(xml);
using (var context = new POSDBContext())
{
context.ExecuteProcedure("Synchronization.MarkSentCustomData", xml);
}
}
}
public class SynchronizationRepositoryExt : SynchronizationRepository { public override void MarkIfWasSentToERP(string xml) { base.MarkIfWasSentToERP(xml); using (var context = new POSDBContext()) { context.ExecuteProcedure("Synchronization.MarkSentCustomData", xml); } } }
public class SynchronizationRepositoryExt : SynchronizationRepository
{
   public override void MarkIfWasSentToERP(string xml)
   {
      base.MarkIfWasSentToERP(xml);

      using (var context = new POSDBContext())
      {
         context.ExecuteProcedure("Synchronization.MarkSentCustomData", xml);
      }
   }
}

Sie können auch beispielsweise eine Prozedur intern aufrufen, die die gesendeten Objekte markieren wird.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
CREATE PROCEDURE [Synchronization].[MarkSentCustomData]
@p0 xml
AS
BEGIN
UPDATE CustomSchema.CustomRootTable
SET WasSentToERP = 1
Where GUID in (SELECT xmlData.Col.value('@GUID','varchar(max)') FROM @p0.nodes('/Customs/Custom') xmlData(Col))
END
GO
CREATE PROCEDURE [Synchronization].[MarkSentCustomData] @p0 xml AS BEGIN UPDATE CustomSchema.CustomRootTable SET WasSentToERP = 1 Where GUID in (SELECT xmlData.Col.value('@GUID','varchar(max)') FROM @p0.nodes('/Customs/Custom') xmlData(Col)) END GO
CREATE PROCEDURE [Synchronization].[MarkSentCustomData]
    @p0 xml
AS
BEGIN
    UPDATE CustomSchema.CustomRootTable
    SET WasSentToERP = 1
    Where GUID in (SELECT xmlData.Col.value('@GUID','varchar(max)') FROM @p0.nodes('/Customs/Custom') xmlData(Col))
END
GO

Beispiel für Export

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
CREATE PROCEDURE [Synchronization].[ExportCustoms]
AS
BEGIN
SET NOCOUNT ON;
select
pad.GUID as [@GUID],
pad.Type as [@Type],
pad.Data1 as [@Data1],
Synchronization.GetDatetimeString(pad.ChangeDate) as [@ChangeDate],
(
select
td.Number as [@NumberString],
td.Status as [@Status],
td.Value as [@Value]
from CustomSchema.Table1 td where pad.Id = td.RootId
for xml path('Table1'), root('Tables1'), type
),
(
select
ti.ToPayNet as [@ToPayNet],
ti.Points as [@Points],
ti.ToPay as [@ToPay]
from CustomSchema.Table2 ti where pad.Id = ti.RootId
for xml path('Table2'), root('Tables2'), type
)
from CustomSchema.RootData pad
where pad.WasSentToERP = 0
for xml path('Custom'), root('Customs')
END
GO
CREATE PROCEDURE [Synchronization].[ExportCustoms] AS BEGIN SET NOCOUNT ON; select pad.GUID as [@GUID], pad.Type as [@Type], pad.Data1 as [@Data1], Synchronization.GetDatetimeString(pad.ChangeDate) as [@ChangeDate], ( select td.Number as [@NumberString], td.Status as [@Status], td.Value as [@Value] from CustomSchema.Table1 td where pad.Id = td.RootId for xml path('Table1'), root('Tables1'), type ), ( select ti.ToPayNet as [@ToPayNet], ti.Points as [@Points], ti.ToPay as [@ToPay] from CustomSchema.Table2 ti where pad.Id = ti.RootId for xml path('Table2'), root('Tables2'), type ) from CustomSchema.RootData pad where pad.WasSentToERP = 0 for xml path('Custom'), root('Customs') END GO
CREATE PROCEDURE [Synchronization].[ExportCustoms] 
AS
BEGIN
    SET NOCOUNT ON;

    select
        pad.GUID 			as [@GUID],
        pad.Type as [@Type],
        pad.Data1 		as [@Data1],
        Synchronization.GetDatetimeString(pad.ChangeDate) 							as [@ChangeDate],
        (
            select			
td.Number 			as [@NumberString], 
td.Status	 			as [@Status], 
td.Value 				as [@Value]
            from 				CustomSchema.Table1 td 			where pad.Id = td.RootId
            for xml path('Table1'), root('Tables1'), type
        ),		
        (
            select				
ti.ToPayNet 				as [@ToPayNet], 
                ti.Points				 as [@Points], 
ti.ToPay				as [@ToPay]
            from 			CustomSchema.Table2 ti 			where 								pad.Id = ti.RootId
            for xml path('Table2'), root('Tables2'), type
        )

    from CustomSchema.RootData pad
    where pad.WasSentToERP = 0

    for xml path('Custom'), root('Customs')
    
END
GO

Import in DataService

Der Datenimport erfolgt über den IDataCustomService und die Überladung der Methode SaveCustom. Die Methode erhält jede Custom-Zeile als Argument in Form eines XElement-Objekts.

Um mehrere Erweiterungen zu verarbeiten, müssen Pin-Points für den DataService verwendet werden.

Snippet für den Import

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[DataServiceBusinessModule]
public static class Module
{
[MethodInitializer]
public static void Initialize()
{
var dataCustomService = IoC.Container.Resolve<IDataCustomExtensionPointService>();
dataCustomService.OnSaveCustomEvent += DataCustomService_OnSaveCustomEvent;
}
private static void DataCustomService_OnSaveCustomEvent (object sender, XEEventArgs e)
{
//deserialisieren + Daten speichern
}
}
[DataServiceBusinessModule] public static class Module { [MethodInitializer] public static void Initialize() { var dataCustomService = IoC.Container.Resolve<IDataCustomExtensionPointService>(); dataCustomService.OnSaveCustomEvent += DataCustomService_OnSaveCustomEvent; } private static void DataCustomService_OnSaveCustomEvent (object sender, XEEventArgs e) { //deserialisieren + Daten speichern } }
[DataServiceBusinessModule]
public static class Module    
{
   [MethodInitializer]
   public static void Initialize()        
   {
       var dataCustomService = IoC.Container.Resolve<IDataCustomExtensionPointService>();
       dataCustomService.OnSaveCustomEvent += DataCustomService_OnSaveCustomEvent;
   }
   private static void DataCustomService_OnSaveCustomEvent (object sender, XEEventArgs e)
   {
   //deserialisieren + Daten speichern
   }
}

 

Czy ten artykuł był pomocny?