diff --git a/WsGTin.Aplication.dpr b/WsGTin.Aplication.dpr index fc593f3..8f154d4 100644 --- a/WsGTin.Aplication.dpr +++ b/WsGTin.Aplication.dpr @@ -1,18 +1,24 @@ program WsGTin.Aplication; uses - Vcl.Forms, - main.view in 'src\main.view.pas' {MainView}, - wsHorse in 'src\wsHorse.pas', - main.control in 'src\main.control.pas', - main.basedados in 'src\main.basedados.pas' {BaseDados}; - + Vcl.Forms, + gtin.classes in 'src\gtin.classes.pas', + gtin.consts in 'src\gtin.consts.pas', + gtin.dm in 'src\gtin.dm.pas' {DM: TDataModule}, + gtin.utils in 'src\gtin.utils.pas', + main.control in 'src\main.control.pas', + main.view in 'src\main.view.pas' {MainView}, + wsHorse in 'src\wsHorse.pas'; + {$R *.res} begin + {$IFDEF DEBUG} + ReportMemoryLeaksOnShutdown := True; + {$ENDIF} + Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TMainView, MainView); - Application.CreateForm(TBaseDados, BaseDados); - application.Run; + Application.Run; end. diff --git a/WsGtin.Aplication.dproj b/WsGtin.Aplication.dproj index 0392914..140c290 100644 --- a/WsGtin.Aplication.dproj +++ b/WsGtin.Aplication.dproj @@ -1,1041 +1,1337 @@ - - - {91B0D264-9633-46D9-A661-37D36B990E57} - 18.8 - VCL - WsGTin.Aplication.dpr - True - Release - Win32 - 1 - Application - - - true - - - true - Base - true - - - true - Base - true - - - true - Base - true - - - true - Cfg_1 - true - true - - - true - Base - true - - - true - Cfg_2 - true - true - - - .\$(Platform)\$(Config) - .\$(Platform)\$(Config) - false - false - false - false - false - System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) - $(BDS)\bin\delphi_PROJECTICON.ico - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png - WsGTin_Aplication - modules\.dcp;modules\.dcu;modules;modules\handle-exception\src;modules\horse\src;modules\horse-octet-stream\src;modules\jhonson\src;$(DCC_UnitSearchPath) - - - .\.dcu - DBXSqliteDriver;IndyIPCommon;RESTComponents;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;svnui;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDAC;vcltouch;vcldb;bindcompfmx;svn;FireDACSqliteDriver;FireDACPgDriver;inetdb;FMXTee;soaprtl;DbxCommonDriver;FmxTeeUI;fmx;FireDACIBDriver;fmxdae;xmlrtl;soapmidas;Tee;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;FireDACCommon;IndyIPClient;bindcompvcl;RESTBackendComponents;TeeUI;VCLRESTComponents;soapserver;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;CloudService;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;FireDACCommonDriver;inet;fmxase;$(DCC_UsePackage) - Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) - Debug - true - CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= - 1033 - $(BDS)\bin\default_app.manifest - - - DBXSqliteDriver;IndyIPCommon;RESTComponents;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDAC;vcltouch;vcldb;bindcompfmx;FireDACSqliteDriver;FireDACPgDriver;inetdb;FMXTee;soaprtl;DbxCommonDriver;FmxTeeUI;fmx;FireDACIBDriver;fmxdae;xmlrtl;soapmidas;Tee;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;FireDACCommon;IndyIPClient;bindcompvcl;RESTBackendComponents;TeeUI;VCLRESTComponents;soapserver;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;CloudService;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;FireDACCommonDriver;inet;fmxase;$(DCC_UsePackage) - - - DEBUG;$(DCC_Define) - true - false - true - true - true - - - .\.dcu - 1033 - true - false - true - PerMonitorV2 - - - false - RELEASE;$(DCC_Define) - 0 - 0 - - - .\.dcu - 1033 - true - true - PerMonitorV2 - C:\WEBSERVICES - - - - MainSource - - -
MainView
- dfm -
- - - -
BaseDados
- dfm -
- - Cfg_2 - Base - - - Base - - - Cfg_1 - Base - -
- - Delphi.Personality.12 - Application - - - - WsGTin.Aplication.dpr - - - Microsoft Office 2000 Sample Automation Server Wrapper Components - Microsoft Office XP Sample Automation Server Wrapper Components - Express Cross Platform Library Icon Library by Developer Express Inc. - - - - - - WsGTin_Aplication.exe - true - - - - - WsGtin_Aplication.exe - true - - - - - 1 - - - Contents\MacOS - 1 - - - 0 - - - - - classes - 1 - - - classes - 1 - - - - - res\xml - 1 - - - res\xml - 1 - - - - - library\lib\armeabi-v7a - 1 - - - - - library\lib\armeabi - 1 - - - library\lib\armeabi - 1 - - - - - library\lib\armeabi-v7a - 1 - - - - - library\lib\mips - 1 - - - library\lib\mips - 1 - - - - - - library\lib\armeabi-v7a - 1 - - - library\lib\arm64-v8a - 1 - - - - - library\lib\armeabi-v7a - 1 - - - - - res\drawable - 1 - - - res\drawable - 1 - - - - - res\values - 1 - - - res\values - 1 - - - - - res\values-v21 - 1 - - - res\values-v21 - 1 - - - - - res\values - 1 - - - res\values - 1 - - - - - res\drawable - 1 - - - res\drawable - 1 - - - - - res\drawable-xxhdpi - 1 - - - res\drawable-xxhdpi - 1 - - - - - res\drawable-ldpi - 1 - - - res\drawable-ldpi - 1 - - - - - res\drawable-mdpi - 1 - - - res\drawable-mdpi - 1 - - - - - res\drawable-hdpi - 1 - - - res\drawable-hdpi - 1 - - - - - res\drawable-xhdpi - 1 - - - res\drawable-xhdpi - 1 - - - - - res\drawable-mdpi - 1 - - - res\drawable-mdpi - 1 - - - - - res\drawable-hdpi - 1 - - - res\drawable-hdpi - 1 - - - - - res\drawable-xhdpi - 1 - - - res\drawable-xhdpi - 1 - - - - - res\drawable-xxhdpi - 1 - - - res\drawable-xxhdpi - 1 - - - - - res\drawable-xxxhdpi - 1 - - - res\drawable-xxxhdpi - 1 - - - - - res\drawable-small - 1 - - - res\drawable-small - 1 - - - - - res\drawable-normal - 1 - - - res\drawable-normal - 1 - - - - - res\drawable-large - 1 - - - res\drawable-large - 1 - - - - - res\drawable-xlarge - 1 - - - res\drawable-xlarge - 1 - - - - - res\values - 1 - - - res\values - 1 - - - - - 1 - - - Contents\MacOS - 1 - - - 0 - - - - - Contents\MacOS - 1 - .framework - - - Contents\MacOS - 1 - .framework - - - 0 - - - - - 1 - .dylib - - - 1 - .dylib - - - 1 - .dylib - - - Contents\MacOS - 1 - .dylib - - - Contents\MacOS - 1 - .dylib - - - 0 - .dll;.bpl - - - - - 1 - .dylib - - - 1 - .dylib - - - 1 - .dylib - - - Contents\MacOS - 1 - .dylib - - - Contents\MacOS - 1 - .dylib - - - 0 - .bpl - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - Contents\Resources\StartUp\ - 0 - - - Contents\Resources\StartUp\ - 0 - - - 0 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - - - 1 - - - 1 - - - - - ..\ - 1 - - - ..\ - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - - - ..\ - 1 - - - ..\ - 1 - - - - - Contents - 1 - - - Contents - 1 - - - - - Contents\Resources - 1 - - - Contents\Resources - 1 - - - - - library\lib\armeabi-v7a - 1 - - - library\lib\arm64-v8a - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - Contents\MacOS - 1 - - - Contents\MacOS - 1 - - - 0 - - - - - library\lib\armeabi-v7a - 1 - - - - - 1 - - - 1 - - - - - Assets - 1 - - - Assets - 1 - - - - - Assets - 1 - - - Assets - 1 - - - - - - - - - - - - - - - True - False - - - 12 - - - - -
+ + + {91B0D264-9633-46D9-A661-37D36B990E57} + 19.3 + VCL + WsGTin.Aplication.dpr + True + Debug + Win32 + 3 + Application + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + true + Cfg_2 + true + true + + + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + false + false + false + false + false + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + $(BDS)\bin\delphi_PROJECTICON.ico + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + WsGTin_Aplication + modules\.dcp;modules\.dcu;modules;modules\handle-exception\src;modules\horse\src;modules\horse-octet-stream\src;modules\jhonson\src;$(DCC_UnitSearchPath) + + + .\.dcu + DBXSqliteDriver;IndyIPCommon;RESTComponents;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;svnui;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDAC;vcltouch;vcldb;bindcompfmx;svn;FireDACSqliteDriver;FireDACPgDriver;inetdb;FMXTee;soaprtl;DbxCommonDriver;FmxTeeUI;fmx;FireDACIBDriver;fmxdae;xmlrtl;soapmidas;Tee;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;FireDACCommon;IndyIPClient;bindcompvcl;RESTBackendComponents;TeeUI;VCLRESTComponents;soapserver;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;CloudService;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;FireDACCommonDriver;inet;fmxase;$(DCC_UsePackage) + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + Debug + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + $(BDS)\bin\default_app.manifest + + + DBXSqliteDriver;IndyIPCommon;RESTComponents;bindcompdbx;DBXInterBaseDriver;vcl;IndyIPServer;vclactnband;vclFireDAC;IndySystem;tethering;dsnapcon;FireDACADSDriver;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDAC;vcltouch;vcldb;bindcompfmx;FireDACSqliteDriver;FireDACPgDriver;inetdb;FMXTee;soaprtl;DbxCommonDriver;FmxTeeUI;fmx;FireDACIBDriver;fmxdae;xmlrtl;soapmidas;Tee;fmxobj;vclwinx;rtl;DbxClientDriver;CustomIPTransport;vcldsnap;dbexpress;IndyCore;vclx;bindcomp;appanalytics;dsnap;FireDACCommon;IndyIPClient;bindcompvcl;RESTBackendComponents;TeeUI;VCLRESTComponents;soapserver;dbxcds;VclSmp;adortl;vclie;bindengine;DBXMySQLDriver;CloudService;dsnapxml;FireDACMySQLDriver;dbrtl;IndyProtocols;inetdbxpress;FireDACCommonODBC;FireDACCommonDriver;inet;fmxase;$(DCC_UsePackage) + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace) + Debug + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + $(BDS)\bin\default_app.manifest + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + .\.dcu + 1033 + true + false + true + PerMonitorV2 + + + true + PerMonitorV2 + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + .\.dcu + 1033 + true + true + PerMonitorV2 + C:\WEBSERVICES + + + true + PerMonitorV2 + + + + MainSource + + + + +
DM
+ dfm + TDataModule +
+ + + +
MainView
+ dfm +
+ + + Base + + + Cfg_1 + Base + + + Cfg_2 + Base + +
+ + Delphi.Personality.12 + Application + + + + WsGTin.Aplication.dpr + + + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + Express Cross Platform Library Icon Library by Developer Express Inc. + + + + + + WsGtin_Aplication.exe + true + + + + + WsGtin_Aplication.exe + true + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + classes + 64 + + + classes + 64 + + + + + classes + 1 + + + classes + 1 + + + + + res\xml + 1 + + + res\xml + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\armeabi + 1 + + + library\lib\armeabi + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\mips + 1 + + + library\lib\mips + 1 + + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\values-v21 + 1 + + + res\values-v21 + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-small + 1 + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + res\drawable-xlarge + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + Contents\MacOS + 1 + .framework + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + Contents\Resources\StartUp\ + 0 + + + Contents\Resources\StartUp\ + 0 + + + Contents\Resources\StartUp\ + 0 + + + 0 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + 1 + + + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen + 64 + + + ..\$(PROJECTNAME).launchscreen + 64 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + ..\ + 1 + + + + + Contents + 1 + + + Contents + 1 + + + Contents + 1 + + + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + library\lib\armeabi-v7a + 1 + + + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + + + + + + + + + + + + True + True + + + 12 + + + + +
diff --git a/db/SCRIPT_DB.txt b/db/SCRIPT_DB.txt new file mode 100644 index 0000000..979d9f6 --- /dev/null +++ b/db/SCRIPT_DB.txt @@ -0,0 +1,424 @@ +SET SQL DIALECT 3; + +SET NAMES NONE; + +SET CLIENTLIB 'C:\PROGRAM FILES\FIREBIRD\FIREBIRD_2_5\WOW64\FBCLIENT.DLL'; + +CREATE DATABASE 'LOCALHOST/3050:GTIN' +USER 'SYSDBA' PASSWORD 'MASTERKEY' +PAGE_SIZE 4096 +DEFAULT CHARACTER SET NONE; + + + +/******************************************************************************/ +/*** DOMAINS ***/ +/******************************************************************************/ + +CREATE DOMAIN D_BINARY AS +BLOB SUB_TYPE 0 SEGMENT SIZE 80; + +CREATE DOMAIN D_BOOLEAN AS +SMALLINT; + +CREATE DOMAIN D_CHAR20 AS +CHAR(20); + +CREATE DOMAIN D_DATE AS +DATE; + +CREATE DOMAIN D_DATETIME AS +TIMESTAMP; + +CREATE DOMAIN D_GUID AS +CHAR(32); + +CREATE DOMAIN D_ID AS +INTEGER; + +CREATE DOMAIN D_INTEGER AS +INTEGER; + +CREATE DOMAIN D_MEMO AS +BLOB SUB_TYPE 1 SEGMENT SIZE 80; + +CREATE DOMAIN D_MEMOVARCHAR AS +VARCHAR(32000) CHARACTER SET WIN1252 +COLLATE WIN_PTBR; + +CREATE DOMAIN D_REAL04 AS +NUMERIC(15,4); + +CREATE DOMAIN D_REAL08 AS +NUMERIC(15,8); + +CREATE DOMAIN D_SMALLINT AS +SMALLINT; + +CREATE DOMAIN D_TIME AS +TIME; + +CREATE DOMAIN D_VARCHAR10 AS +VARCHAR(10); + +CREATE DOMAIN D_VARCHAR20 AS +VARCHAR(20); + +CREATE DOMAIN D_VARCHAR255 AS +VARCHAR(255) CHARACTER SET WIN1252 +COLLATE WIN_PTBR; + +CREATE DOMAIN D_VARCHAR32 AS +VARCHAR(32); + +CREATE DOMAIN D_VARCHAR60 AS +VARCHAR(60) CHARACTER SET WIN1252 +COLLATE WIN_PTBR; + + + +/******************************************************************************/ +/*** GENERATORS ***/ +/******************************************************************************/ + +CREATE GENERATOR GEN_CAD_PRODUTOS_ID; +SET GENERATOR GEN_CAD_PRODUTOS_ID TO 0; + +CREATE GENERATOR GEN_CATEGORIA_ID; +SET GENERATOR GEN_CATEGORIA_ID TO 0; + +CREATE GENERATOR GEN_CEST_ID; +SET GENERATOR GEN_CEST_ID TO 0; + +CREATE GENERATOR GEN_EMBALAGEM_ID; +SET GENERATOR GEN_EMBALAGEM_ID TO 0; + +CREATE GENERATOR GEN_FABRICANTE_ID; +SET GENERATOR GEN_FABRICANTE_ID TO 0; + +CREATE GENERATOR GEN_FOTO_ID; +SET GENERATOR GEN_FOTO_ID TO 0; + +CREATE GENERATOR GEN_MARCA_ID; +SET GENERATOR GEN_MARCA_ID TO 0; + +CREATE GENERATOR GEN_NCM_ID; +SET GENERATOR GEN_NCM_ID TO 0; + +CREATE GENERATOR GEN_PRODUTO_ID; +SET GENERATOR GEN_PRODUTO_ID TO 0; + +CREATE GENERATOR GEN_UNIDADE_ID; +SET GENERATOR GEN_UNIDADE_ID TO 0; + +CREATE GENERATOR GEN_UNIDADE_MEDIDA_ID; +SET GENERATOR GEN_UNIDADE_MEDIDA_ID TO 0; + + + +/******************************************************************************/ +/*** TABLES ***/ +/******************************************************************************/ + + + +CREATE TABLE CAD_PRODUTOS ( + ID D_ID NOT NULL, + EAN VARCHAR(20) NOT NULL, + NOME VARCHAR(255) NOT NULL, + NCM INTEGER NOT NULL, + VALOR DOUBLE PRECISION DEFAULT NULL, + AAVG DOUBLE PRECISION DEFAULT NULL, + EX INTEGER DEFAULT 0, + MARCA VARCHAR(255) DEFAULT NULL, + PAIS VARCHAR(100) DEFAULT NULL, + CATEGORIA VARCHAR(255) DEFAULT NULL, + VALOR_MEDIO DOUBLE PRECISION DEFAULT 0, + ATUALIZADO INTEGER DEFAULT 0, + LINK_FOTO D_MEMO DEFAULT NULL, + CEST_CODIGO VARCHAR(7) DEFAULT NULL, + DH_UPDATE D_DATETIME DEFAULT CURRENT_TIMESTAMP, + ERRO INTEGER DEFAULT 0, + EMBALAGEM VARCHAR(10) DEFAULT NULL, + QUANTIDADE_EMBALAGEM DOUBLE PRECISION DEFAULT NULL, + TRIBUTACAO VARCHAR(15) DEFAULT NULL, + PRODUTO_ACENTO VARCHAR(255) DEFAULT NULL, + ID_CATEGORIA D_ID, + PESO DOUBLE PRECISION +); + + +CREATE TABLE CATEGORIA ( + ID INTEGER NOT NULL, + NOME D_VARCHAR255 +); + + +CREATE TABLE CEST ( + ID D_ID NOT NULL, + CODIGO D_VARCHAR20 +); + + +CREATE TABLE EMBALAGEM ( + ID INTEGER NOT NULL, + NOME D_VARCHAR255, + QUANTIDADE D_REAL04, + ALTURA D_REAL04, + LARGURA D_REAL04, + COMPRIMENTO D_REAL04, + PESO D_REAL04 +); + + +CREATE TABLE FABRICANTE ( + ID D_ID NOT NULL, + NOME D_VARCHAR255 +); + + +CREATE TABLE FOTO ( + ID INTEGER NOT NULL, + PRODUTO D_ID, + PATH D_MEMOVARCHAR +); + + +CREATE TABLE MARCA ( + ID INTEGER NOT NULL, + NOME D_VARCHAR255 +); + + +CREATE TABLE NCM ( + ID D_ID NOT NULL, + CODIGO D_VARCHAR20 +); + + +CREATE TABLE PRODUTO ( + ID INTEGER NOT NULL, + GTIN D_VARCHAR20, + GUID D_GUID, + NOME D_VARCHAR255, + DESCRICAO D_VARCHAR255, + UNIDADE D_ID, + NCM D_ID, + CEST D_ID, + MARCA D_ID, + CATEGORIA D_ID, + FABRICANTE D_ID, + EMBALAGEM D_ID, + PRECO D_REAL04, + CBS D_REAL08, + IBS D_REAL08, + PESO D_REAL04, + DATA D_DATETIME DEFAULT CURRENT_TIMESTAMP, + DATA_UPDATE D_DATETIME, + OBSERVACAO D_MEMO, + FICHA_TECNICA D_MEMO, + WEB D_MEMO +); + + +CREATE TABLE UNIDADE ( + ID D_ID NOT NULL, + SIGLA D_VARCHAR10, + NOME D_VARCHAR255 +); + + +CREATE TABLE UNIDADE_MEDIDA ( + ID D_ID NOT NULL, + SIGLA D_VARCHAR10, + NOME D_VARCHAR60 +); + + + + +/******************************************************************************/ +/*** PRIMARY KEYS ***/ +/******************************************************************************/ + +ALTER TABLE CATEGORIA ADD CONSTRAINT PK_CATEGORIA PRIMARY KEY (ID); +ALTER TABLE CEST ADD CONSTRAINT PK_CEST PRIMARY KEY (ID); +ALTER TABLE EMBALAGEM ADD CONSTRAINT PK_EMBALAGEM PRIMARY KEY (ID); +ALTER TABLE FABRICANTE ADD CONSTRAINT PK_FABRICANTE PRIMARY KEY (ID); +ALTER TABLE FOTO ADD CONSTRAINT PK_FOTO PRIMARY KEY (ID); +ALTER TABLE MARCA ADD CONSTRAINT PK_MARCA PRIMARY KEY (ID); +ALTER TABLE NCM ADD CONSTRAINT PK_NCM PRIMARY KEY (ID); +ALTER TABLE PRODUTO ADD CONSTRAINT PK_PRODUTO PRIMARY KEY (ID); +ALTER TABLE UNIDADE ADD CONSTRAINT PK_UNIDADE PRIMARY KEY (ID); +ALTER TABLE UNIDADE_MEDIDA ADD CONSTRAINT PK_UNIDADE_MEDIDA PRIMARY KEY (ID); + + +/******************************************************************************/ +/*** FOREIGN KEYS ***/ +/******************************************************************************/ + +ALTER TABLE FOTO ADD CONSTRAINT FK_FOTO_1 FOREIGN KEY (PRODUTO) REFERENCES PRODUTO (ID) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE PRODUTO ADD CONSTRAINT FK_PRODUTO_1 FOREIGN KEY (UNIDADE) REFERENCES UNIDADE (ID); +ALTER TABLE PRODUTO ADD CONSTRAINT FK_PRODUTO_2 FOREIGN KEY (NCM) REFERENCES NCM (ID); +ALTER TABLE PRODUTO ADD CONSTRAINT FK_PRODUTO_3 FOREIGN KEY (CEST) REFERENCES CEST (ID); +ALTER TABLE PRODUTO ADD CONSTRAINT FK_PRODUTO_4 FOREIGN KEY (CATEGORIA) REFERENCES CATEGORIA (ID); +ALTER TABLE PRODUTO ADD CONSTRAINT FK_PRODUTO_5 FOREIGN KEY (MARCA) REFERENCES MARCA (ID); +ALTER TABLE PRODUTO ADD CONSTRAINT FK_PRODUTO_6 FOREIGN KEY (FABRICANTE) REFERENCES FABRICANTE (ID); +ALTER TABLE PRODUTO ADD CONSTRAINT FK_PRODUTO_7 FOREIGN KEY (EMBALAGEM) REFERENCES EMBALAGEM (ID); + + +/******************************************************************************/ +/*** INDICES ***/ +/******************************************************************************/ + +CREATE INDEX CAD_PRODUTOS_IDX1 ON CAD_PRODUTOS (EAN); +CREATE UNIQUE INDEX PRODUTO_IDX1 ON PRODUTO (GTIN); + + +/******************************************************************************/ +/*** TRIGGERS ***/ +/******************************************************************************/ + + +SET TERM ^ ; + + + +/******************************************************************************/ +/*** TRIGGERS FOR TABLES ***/ +/******************************************************************************/ + + + +/* TRIGGER: CAD_PRODUTOS_BI */ +CREATE TRIGGER CAD_PRODUTOS_BI FOR CAD_PRODUTOS +ACTIVE BEFORE INSERT OR UPDATE POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_CAD_PRODUTOS_ID,1); + + NEW.DH_UPDATE = CURRENT_TIMESTAMP; +END +^ + + +/* TRIGGER: CATEGORIA_BI */ +CREATE TRIGGER CATEGORIA_BI FOR CATEGORIA +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_CATEGORIA_ID,1); +END +^ + + +/* TRIGGER: CEST_BI */ +CREATE TRIGGER CEST_BI FOR CEST +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_CEST_ID,1); +END +^ + + +/* TRIGGER: EMBALAGEM_BI */ +CREATE TRIGGER EMBALAGEM_BI FOR EMBALAGEM +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_EMBALAGEM_ID,1); +END +^ + + +/* TRIGGER: FABRICANTE_BI */ +CREATE TRIGGER FABRICANTE_BI FOR FABRICANTE +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_FABRICANTE_ID,1); +END +^ + + +/* TRIGGER: FOTO_BI */ +CREATE TRIGGER FOTO_BI FOR FOTO +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_FOTO_ID,1); +END +^ + + +/* TRIGGER: MARCA_BI */ +CREATE TRIGGER MARCA_BI FOR MARCA +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_MARCA_ID,1); +END +^ + + +/* TRIGGER: NCM_BI */ +CREATE TRIGGER NCM_BI FOR NCM +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_NCM_ID,1); +END +^ + + +/* TRIGGER: PRODUTO_BI */ +CREATE TRIGGER PRODUTO_BI FOR PRODUTO +ACTIVE BEFORE INSERT OR UPDATE POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_PRODUTO_ID,1); + + IF (NEW.DATA IS NULL) THEN + NEW.DATA = CURRENT_TIMESTAMP; + + IF (NEW.GUID IS NULL) THEN + NEW.GUID = LOWER(REPLACE(UUID_TO_CHAR(GEN_UUID()),'-','')); + + NEW.DATA_UPDATE = CURRENT_TIMESTAMP; +END +^ + + +/* TRIGGER: UNIDADE_BI */ +CREATE TRIGGER UNIDADE_BI FOR UNIDADE +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_UNIDADE_ID,1); +END +^ + + +/* TRIGGER: UNIDADE_MEDIDA_BI */ +CREATE TRIGGER UNIDADE_MEDIDA_BI FOR UNIDADE_MEDIDA +ACTIVE BEFORE INSERT POSITION 0 +AS +BEGIN + IF (NEW.ID IS NULL) THEN + NEW.ID = GEN_ID(GEN_UNIDADE_MEDIDA_ID,1); +END +^ + + +SET TERM ; ^ diff --git a/db/fbclient.dll b/db/fbclient.dll new file mode 100644 index 0000000..113f21d Binary files /dev/null and b/db/fbclient.dll differ diff --git a/db/fbclient64.dll b/db/fbclient64.dll new file mode 100644 index 0000000..2cf2417 Binary files /dev/null and b/db/fbclient64.dll differ diff --git a/db/gtin.fdb b/db/gtin.fdb new file mode 100644 index 0000000..497e636 Binary files /dev/null and b/db/gtin.fdb differ diff --git a/src/gtin.classes.pas b/src/gtin.classes.pas new file mode 100644 index 0000000..689f964 --- /dev/null +++ b/src/gtin.classes.pas @@ -0,0 +1,298 @@ +unit gtin.classes; + +interface + +uses System.SysUtils, System.Classes, + System.JSON.Serializers; + +type + TGTIN_01 = Class + Private + [JsonNameAttribute('Status')] + FStatus : String; + + [JsonNameAttribute('Status_Desc')] + FStatus_Desc : String; + + [JsonNameAttribute('GTIN')] + FGTIN : String; + + [JsonNameAttribute('Nome')] + FNome : String; + + [JsonNameAttribute('Ncm')] + FNCM : String; + + [JsonNameAttribute('Cest_Codigo')] + FCEST : String; + + [JsonNameAttribute('Embalagem')] + FEmbalagem : String; + + [JsonNameAttribute('QuantidadeEmbalagem')] + FQuantidadeEmbalagem : String; + + [JsonNameAttribute('Marca')] + FMarca : String; + + [JsonNameAttribute('id_categoria')] + FID_Categoria : String; + + [JsonNameAttribute('Categoria')] + FCategoria : String; + + [JsonNameAttribute('Peso')] + FPeso : String; + + [JsonNameAttribute('tributacao')] + FTributacao : String; + + Public + property Status : String Read FStatus Write FStatus; + property Status_Desc : String Read FStatus_Desc Write FStatus_Desc; + + property GTIN : String Read FGTIN Write FGTIN; + property Nome : String Read FNome Write FNome; + property NCM : String Read FNCM Write FNCM; + property CEST : String Read FCEST Write FCEST; + property Embalagem : String Read FEmbalagem Write FEmbalagem; + property QuantidadeEmbalagem : String Read FQuantidadeEmbalagem Write FQuantidadeEmbalagem; + property Marca : String Read FMarca Write FMarca; + property Id_Categoria : String Read FID_Categoria Write FID_Categoria; + property Categoria : String Read FCategoria Write FCategoria; + property Peso : String Read FPeso Write FPeso; + property Tributacao : String Read FTributacao Write FTributacao; + End; + + TUnid_01 = Class + Private + [JsonNameAttribute('Status')] + FStatus : String; + + [JsonNameAttribute('Status_Desc')] + FStatus_Desc : String; + + [JsonName('ID')] + FID : String; + + [JsonName('Nome')] + FNome : String; + Public + property Status : String Read FStatus Write FStatus; + property Status_Desc : String Read FStatus_Desc Write FStatus_Desc; + property ID : String Read FID Write FID; + property Nome : String Read FNome Write FNome; + End; + + TStatus = Class + Private + [JsonName('Code')] + FCode : String; + + [JsonName('Description')] + FDescription : String; + Public + property Code : String Read FCode Write FCode; + property Description : String Read FDescription Write FDescription; + End; + + TPicture = Class + Private + [JsonName('Path')] + FPath : String; + + [JsonName('Base64')] + FBase64 : String; + + [JsonName('MD5')] + FMD5 : String; + Public + property Path : String Read FPath Write FPath; + property Base64 : String Read FBase64 Write FBase64; + property MD5 : String Read FMD5 Write FMD5; + End; + + TPictures = TArray; + + TUnid = Class + Private + [JsonName('Short')] + FShort : String; + + [JsonName('Description')] + FDescription : String; + Public + property Short : String Read FShort Write FShort; + property Description : String Read FDescription Write FDescription; + End; + + TPackaging = Class + Private + [JsonName('Description')] + FDescription : String; + + [JsonName('Height')] + FHeight : Extended; + + [JsonName('Width')] + FWidth : Extended; + + [JsonName('Quantity')] + FQuantity : Extended; + + [JsonName('Weight')] + FWeight : Extended; + + [JsonName('Length')] + FLength : Extended; + Public + property Description : String Read FDescription Write FDescription; + property Height : Extended Read FHeight Write FHeight; + property Width : Extended Read FWidth Write FWidth; + property Quantity : Extended Read FQuantity Write FQuantity; + property Weight : Extended Read FWeight Write FWeight; + property Length : Extended Read FLength Write FLength; + End; + + TTributes = Class + Private + [JsonName('NCM')] + FNCM : String; + + [JsonName('CEST')] + FCEST : String; + + [JsonName('CBS')] + FCBS : Extended; + + [JsonName('IBS')] + FIBS : Extended; + Public + property NCM : String Read FNCM Write FNCM; + property CEST : String Read FCEST Write FCEST; + property CBS : Extended Read FCBS Write FCBS; + property IBS : Extended Read FIBS Write FIBS; + End; + + TOthers = Class + Private + [JsonName('Category')] + FCategory : String; + + [JsonName('Producer')] + FProducer : String; + + [JsonName('Observation')] + FObservation : String; + + [JsonName('Datasheet')] + FDataSheet : String; + + [JsonName('Web')] + FWeb : String; + Public + property Category : String Read FCategory Write FCategory; + property Producer : String Read FProducer Write FProducer; + property Observation : String Read FObservation Write FObservation; + property DataSheet : String Read FDataSheet Write FDataSheet; + property Web : String Read FWeb Write FWeb; + End; + + TGTIN_02 = Class + Private + [JsonName('Code')] + FCode : String; + + [JsonName('Description')] + FDescription : String; + + [JsonName('Unid')] + FUnid : TUnid; + + [JsonName('Packaging')] + FPackaging : TPackaging; + + [JsonName('Tributes')] + FTributes : TTributes; + + [JsonName('Others')] + FOthers : TOthers; + + [JsonName('Pictures')] + FPictures : TArray; + + [JsonName('Status')] + FStatus : TStatus; + + procedure PictureClear; + + Public + Constructor Create; + Destructor Destroy; Override; + + procedure PictureAdd(Value : TPicture); + + property Code : String Read FCode Write FCode; + property Description : String Read FDescription Write FDescription; + property Unid : TUnid Read FUnid; + property Packaging : TPackaging Read FPackaging; + property Tributes : TTributes Read FTributes; + property Others : TOthers Read FOthers; + property Pictures : TArray Read FPictures; + + property Status : TStatus Read FStatus; + + function IsPictures : Boolean; + End; + +implementation + +{ TEAN } + +procedure TGTIN_02.PictureAdd(Value: TPicture); +begin + SetLength(FPictures,High(FPictures) + 2); + FPictures[High(FPictures)] := Value; +end; + +procedure TGTIN_02.PictureClear; +var I : Integer; + O : TObject; +begin + For I := High(FPictures) Downto Low(FPictures) Do + Begin + O := FPictures[I]; + FreeAndNil(O); + End; + SetLength(FPictures,0); +end; + +constructor TGTIN_02.Create; +begin + FStatus := TStatus.Create; + FUnid := TUnid.Create; + FPackaging := TPackaging.Create; + FTributes := TTributes.Create; + FOthers := TOthers.Create; + SetLength(FPictures,0); +end; + +destructor TGTIN_02.Destroy; +begin + FreeAndNil(FStatus); + FreeAndNil(FUnid); + FreeAndNil(FPackaging); + FreeAndNil(FTributes); + FreeAndNil(FOthers); + + PictureClear; + + inherited; +end; + +function TGTIN_02.IsPictures: Boolean; +begin + Result := (High(FPictures) > 0); +end; + +end. diff --git a/src/gtin.consts.pas b/src/gtin.consts.pas new file mode 100644 index 0000000..0cc7444 --- /dev/null +++ b/src/gtin.consts.pas @@ -0,0 +1,10 @@ +unit gtin.consts; + +interface + +type + TVersion = (v01, v02); + +implementation + +end. diff --git a/src/gtin.dm.dfm b/src/gtin.dm.dfm new file mode 100644 index 0000000..58297a6 --- /dev/null +++ b/src/gtin.dm.dfm @@ -0,0 +1,43 @@ +object DM: TDM + OnCreate = DataModuleCreate + OnDestroy = DataModuleDestroy + Height = 343 + Width = 410 + PixelsPerInch = 96 + object DBConnectFirebird: TFDConnection + Params.Strings = ( + 'Server=127.0.0.1' + 'User_Name=SYSDBA' + 'Password=masterkey' + 'Database=GTIN' + 'Port=3051' + 'DriverID=FB') + ResourceOptions.AssignedValues = [rvAutoReconnect] + ResourceOptions.AutoReconnect = True + LoginPrompt = False + Left = 51 + Top = 43 + end + object DBConnectMySQL: TFDConnection + Params.Strings = ( + 'Server=127.0.0.1' + 'User_Name=sacfiscal' + 'Password=Abc123abcc#' + 'Database=base_produtos' + 'DriverID=MySQL') + ResourceOptions.AssignedValues = [rvAutoReconnect] + ResourceOptions.AutoReconnect = True + LoginPrompt = False + Left = 243 + Top = 43 + end + object PhysFBDriverLink: TFDPhysFBDriverLink + VendorLib = 'C:\WEBSERVICES\fbclient.dll' + Left = 48 + Top = 104 + end + object PhysMySQLDriverLink: TFDPhysMySQLDriverLink + Left = 240 + Top = 104 + end +end diff --git a/src/gtin.dm.pas b/src/gtin.dm.pas new file mode 100644 index 0000000..35a9030 --- /dev/null +++ b/src/gtin.dm.pas @@ -0,0 +1,406 @@ +unit gtin.dm; + +interface + +uses + System.SysUtils, System.Classes, System.Generics.Collections, + Data.DB, + MidasLib, + FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, + FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, + FireDAC.Phys, FireDAC.Phys.MySQL, FireDAC.Phys.MySQLDef, FireDAC.VCLUI.Wait, + FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, + FireDAC.Comp.DataSet, FireDAC.Comp.Client, FireDAC.Phys.FB, FireDAC.Phys.FBDef, + FireDAC.Phys.IBBase, + + gtin.consts; + +//Ao compilar mudar aqui. definir em qual db conectar. + +{$DEFINE DB_FIREBIRD} +//{$DEFINE DB_MYSQL} + +const + PATH_COSMOS = 'comos\'; + +type + TDM = class(TDataModule) + DBConnectFirebird: TFDConnection; + DBConnectMySQL: TFDConnection; + PhysFBDriverLink: TFDPhysFBDriverLink; + PhysMySQLDriverLink: TFDPhysMySQLDriverLink; + procedure DataModuleCreate(Sender: TObject); + procedure DataModuleDestroy(Sender: TObject); + private + { Private declarations } + DB : TFDConnection; + FPath : String; + + function OpenQry(Value : String) : TDataSet; + + function QryGTIN(Version: TVersion; Value : String) : TDataSet; + function QryFotos(Value : String) : TDataSet; + function QryUndMedida(Version: TVersion; Value : String) : TDataSet; + + function GTIN_01(IsAlpha : Boolean; Value : TDataSet) : TObject; + function GTIN_02(IsAlpha : Boolean; Value : TDataSet) : TObject; + public + { Public declarations } + + function Path(Value : String) : TDM; + + function GetGTIN(Version : TVersion; Value : String) : TObject; + function GetGTIN_Nome(Version : TVersion; Value : String) : String; + function GetGTIN_Unid_Med_Nome(Version : TVersion; Value : String) : String; + function GetGTIN_Unid_Med(Version : TVersion; Value : String) : TObject; + + class function FilePhoto(Value : String) : String; + + end; + +//var +// DM: TDM; + +implementation + +uses gtin.utils, + gtin.classes; + +{%CLASSGROUP 'Vcl.Controls.TControl'} + +{$R *.dfm} + +{ TDM } + +procedure TDM.DataModuleCreate(Sender: TObject); +begin + {$IFDEF DEBUG} + DBConnectFirebird.Params.Values['Port'] := '3051'; + {$ENDIF} + + DB := {$IFDEF DB_FIREBIRD} DBConnectFirebird {$ELSE} DBConnectMySQL {$ENDIF}; +end; + +procedure TDM.DataModuleDestroy(Sender: TObject); +begin + DB.Connected := False; + //DB.Disconnect; +end; + +class function TDM.FilePhoto(Value: String): String; +var F1, F2 : String; +begin + Result := ''; + F1 := Value; + F2 := ExtractFilePath(F1) + PATH_COSMOS + ExtractFileName(F1); + + If FileExists(F1) Then + Result := F1 + Else If FileExists(F2) Then + Result := F2; +end; + +function TDM.GetGTIN(Version: TVersion; Value: String): TObject; +var DS : TDataSet; +begin + Value := TUtils.NumberOnly(Value); + DS := QryGTIN(Version,Value); + Try + Result := nil; + Case Version Of + TVersion.v01 : Result := GTIN_01(True ,DS); + TVersion.v02 : Result := GTIN_02(False,DS); + End; + Finally + FreeAndNil(DS); + End; +end; + +function TDM.GetGTIN_Nome(Version: TVersion; Value: String): String; +var DS : TDataSet; +begin + Value := TUtils.NumberOnly(Value); + DS := QryGTIN(Version,Value); + Try + Result := DS.FieldByName('NOME').AsString; + { + Case Version Of + TVersion.v01 : Result := DS.FieldByName('NOME').AsString; + TVersion.v02 : Result := DS.FieldByName('DESCRICAO').AsString; + End; + } + Finally + FreeAndNil(DS); + End; +end; + +function TDM.GetGTIN_Unid_Med(Version: TVersion; Value: String): TObject; +var DS : TDataSet; + R : TObject; + U1 : TUnid_01; + U : TUnid; + L : TList; +begin + Result := nil; + + R := nil; + DS := QryUndMedida(Version,Value); + Try + If DS.IsEmpty Then + Exit; + + If (Version = TVersion.v01) Then + Begin + U1 := TUnid_01.Create; + U1.Status := '200'; + U1.Status_Desc := 'Ok'; + U1.ID := TUtils.AlphaOnly(DS.FieldbyName('SIGLA').AsString); + U1.Nome := TUtils.AlphaOnly(DS.FieldbyName('NOME').AsString); + + R := U1; + End; + + If (Version = TVersion.v02) Then + Begin + L := TObjectList.Create; + While (not DS.Eof) Do + Begin + U := TUnid.Create; + U.Short := DS.FieldbyName('SIGLA').AsString; + U.Description := DS.FieldbyName('NOME').AsString; + + L.Add(U); + + DS.Next; + End; + R := L; + End; + Finally + FreeAndNil(DS); + End; + + Result := R; +end; + +function TDM.GetGTIN_Unid_Med_Nome(Version: TVersion; Value: String): String; +var DS : TDataSet; +begin + DS := QryUndMedida(Version,Value); + Try + Result := DS.FieldByName('NOME').AsString; + Finally + FreeAndNil(DS); + End; +end; + +function TDM.GTIN_01(IsAlpha : Boolean; Value: TDataSet): TObject; +var O : TGTIN_01; +begin + O := TGTIN_01.Create; + Result := O; + + O.Status := '200'; + O.Status_Desc := 'Ok'; + + If Value.IsEmpty Then + Begin + O.Status := '400'; + O.Status_Desc := 'EAN nao encontrado'; + + Exit; + End; + + O.GTIN := Value.FieldByName('EAN').AsString; + O.NCM := Value.FieldByName('NCM').AsString; + O.CEST := Value.FieldByName('CEST_CODIGO').AsString; + O.Nome := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('NOME').AsString); + O.Embalagem := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('EMBALAGEM').AsString); + O.QuantidadeEmbalagem := Value.FieldByName('QUANTIDADE_EMBALAGEM').AsString; + O.Marca := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('MARCA').AsString); + O.Id_Categoria := Value.FieldByName('ID_CATEGORIA').AsString; + O.Categoria := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('CATEGORIA').AsString); + O.Peso := Value.FieldByName('PESO').AsString; + O.Tributacao := Value.FieldByName('TRIBUTACAO').AsString; +end; + +function TDM.GTIN_02(IsAlpha : Boolean; Value: TDataSet): TObject; +var O : gtin.classes.TGTIN_02; + P : gtin.classes.TPicture; + DS : TDataSet; +begin + O := TGTIN_02.Create; + Result := O; + + O.Status.Code := '200'; + O.Status.Description := 'Ok'; + + If Value.IsEmpty Then + Begin + O.Status.Code := '400'; + O.Status.Description := 'EAN nao encontrado'; + + Exit; + End; + + O.Code := Value.FieldByName('GTIN').AsString; + O.Description := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('NOME').AsString); + + O.Unid.Short := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('U_SIGLA').AsString); + O.Unid.Description := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('U_NOME').AsString); + + O.Packaging.Description := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('E_NOME').AsString); + O.Packaging.Height := Value.FieldByName('E_ALTURA').AsExtended; + O.Packaging.Width := Value.FieldByName('E_LARGURA').AsExtended;; + O.Packaging.Quantity := Value.FieldByName('E_QUANTIDADE').AsExtended;; + O.Packaging.Weight := Value.FieldByName('E_COMPRIMENTO').AsExtended;; + O.Packaging.Length := Value.FieldByName('E_PESO').AsExtended;; + + O.Tributes.NCM := Value.FieldByName('NCM').AsString; + O.Tributes.CEST := Value.FieldByName('CEST').AsString;; + O.Tributes.CBS := Value.FieldByName('CBS').AsExtended; + O.Tributes.IBS := Value.FieldByName('IBS').AsExtended; + + O.Others.Category := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('CATEGORIA').AsString); + O.Others.Producer := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('FABRICANTE').AsString); + O.Others.Observation := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('OBSERVACAO').AsString); + O.Others.DataSheet := TUtils.AlphaOnly(IsAlpha, Value.FieldByName('FICHA_TECNICA').AsString); + O.Others.Web := Value.FieldByName('WEB').AsString; + + DS := QryFotos(Value.FieldByName('ID').AsString); + While (not DS.EOF) Do + Begin + P := gtin.classes.TPicture.Create; + P.Path := DS.FieldByName('PATH').AsString; + O.PictureAdd(P); + End; + + If (not O.IsPictures) And (not FilePhoto(FPath + O.Code + '.png').IsEmpty) Then + Begin + P := gtin.classes.TPicture.Create; + P.Path := 'www.eanpictures.com.br:9000/api/gtin/'+ O.Code; + O.PictureAdd(P); + End; +end; + +function TDM.OpenQry(Value: String): TDataSet; +var Qry : TFDQuery; +begin + Qry := TFDQuery.Create(Self); + Qry.Connection := DB; + + Qry.Close; + Qry.SQL.Text := Value; + Qry.Open; + + Result := Qry; +end; + +function TDM.Path(Value: String): TDM; +begin + Result := Self; + FPath := Value; +end; + +function TDM.QryFotos(Value: String): TDataSet; +var S : String; +begin + S := ' SELECT F.PATH '+ sLineBreak + + ' FROM FOTO F '+ sLineBreak + + ' WHERE (F.PRODUTO = %s) '; + S := Format(S,[Value]); + + Result := OpenQry(S); +end; + +function TDM.QryGTIN(Version: TVersion; Value: String): TDataSet; +var S, S1, S2 : String; +begin + + S1 := ' SELECT P.ID, '+ sLineBreak + + ' P.EAN, '+ sLineBreak + + ' P.NOME, '+ sLineBreak + + ' P.NCM, '+ sLineBreak + + ' P.CEST_CODIGO, '+ sLineBreak + + ' P.EMBALAGEM, '+ sLineBreak + + ' P.QUANTIDADE_EMBALAGEM, '+ sLineBreak + + ' P.TRIBUTACAO, '+ sLineBreak + + ' P.MARCA, '+ sLineBreak + + ' P.CATEGORIA, '+ sLineBreak + + ' P.ID_CATEGORIA, '+ sLineBreak + + ' P.PESO '+ sLineBreak + + ' FROM CAD_PRODUTOS P '+ sLineBreak + + ' WHERE (P.EAN = %S) '; + + S2 := ' SELECT P.ID, '+ sLineBreak + + ' P.GTIN, '+ sLineBreak + + ' P.NOME, '+ sLineBreak + + ' P.DESCRICAO, '+ sLineBreak + + ' P.PRECO, '+ sLineBreak + + ' P.CBS, '+ sLineBreak + + ' P.IBS, '+ sLineBreak + + ' P.PESO, '+ sLineBreak + + ' P.OBSERVACAO, '+ sLineBreak + + ' P.FICHA_TECNICA, '+ sLineBreak + + ' P.WEB, '+ sLineBreak + + ' U.SIGLA AS U_SIGLA, '+ sLineBreak + + ' U.NOME AS U_NOME, '+ sLineBreak + + ' C.CODIGO AS CEST, '+ sLineBreak + + ' N.CODIGO AS NCM, '+ sLineBreak + + ' F.NOME AS FABRICANTE, '+ sLineBreak + + ' C1.NOME AS CATEGORIA, '+ sLineBreak + + ' M.NOME AS MARCA, '+ sLineBreak + + ' E.NOME AS E_NOME, '+ sLineBreak + + ' E.QUANTIDADE AS E_QUANTIDADE, '+ sLineBreak + + ' E.ALTURA AS E_ALTURA, '+ sLineBreak + + ' E.LARGURA AS E_LARGURA, '+ sLineBreak + + ' E.COMPRIMENTO AS E_COMPRIMENTO, '+ sLineBreak + + ' E.PESO AS E_PESO '+ sLineBreak + + ' FROM PRODUTO P '+ sLineBreak + + ' INNER JOIN UNIDADE U ON (U.ID = P.UNIDADE) '+ sLineBreak + + ' LEFT JOIN CEST C ON (C.ID = P.CEST) '+ sLineBreak + + ' LEFT JOIN NCM N ON (N.ID = P.NCM) '+ sLineBreak + + ' LEFT JOIN FABRICANTE F ON (F.ID = P.FABRICANTE) '+ sLineBreak + + ' LEFT JOIN CATEGORIA C1 ON (C1.ID = P.CATEGORIA) '+ sLineBreak + + ' LEFT JOIN MARCA M ON (M.ID = P.MARCA) '+ sLineBreak + + ' LEFT JOIN EMBALAGEM E ON (E.ID = P.EMBALAGEM) '+ sLineBreak + + ' WHERE (P.GTIN = %s) '; + + S := S1; + If (Version = TVersion.v02) Then + S := S2; + + S := Format(S,[QuotedStr(Value)]); + + Result := OpenQry(S); +end; + +function TDM.QryUndMedida(Version: TVersion; Value: String): TDataSet; +var S, S1, S2 : String; +begin + + S1 := ' SELECT U.ID, '+ sLineBreak + + ' U.SIGLA, '+ sLineBreak + + ' U.NOME '+ sLineBreak + + ' FROM UNIDADE_MEDIDA U '; + + S2 := ' SELECT U.ID, '+ sLineBreak + + ' U.SIGLA, '+ sLineBreak + + ' U.NOME '+ sLineBreak + + ' FROM UNIDADE U '; + + If not Value.IsEmpty Then + Begin + S1 := S1 + ' WHERE (U.SIGLA = %s) '; + S2 := S2 + ' WHERE (U.SIGLA = %s) '; + End; + + S := S1; + If (Version = TVersion.v02) Then + S := S2; + + S := Format(S,[QuotedStr(Value)]); + + Result := OpenQry(S); +end; + +end. diff --git a/src/gtin.test.dfm b/src/gtin.test.dfm new file mode 100644 index 0000000..5df3e28 --- /dev/null +++ b/src/gtin.test.dfm @@ -0,0 +1,34 @@ +object Form3: TForm3 + Left = 0 + Top = 0 + Caption = 'Form3' + ClientHeight = 441 + ClientWidth = 624 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -12 + Font.Name = 'Segoe UI' + Font.Style = [] + PixelsPerInch = 96 + TextHeight = 15 + object BitBtn1: TBitBtn + Left = 8 + Top = 8 + Width = 105 + Height = 41 + Caption = 'BitBtn1' + TabOrder = 0 + OnClick = BitBtn1Click + end + object Memo1: TMemo + Left = 8 + Top = 55 + Width = 465 + Height = 297 + Lines.Strings = ( + 'Memo1') + ScrollBars = ssBoth + TabOrder = 1 + end +end diff --git a/src/gtin.test.pas b/src/gtin.test.pas new file mode 100644 index 0000000..b2795e4 --- /dev/null +++ b/src/gtin.test.pas @@ -0,0 +1,74 @@ +unit gtin.test; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons; + +type + TForm3 = class(TForm) + BitBtn1: TBitBtn; + Memo1: TMemo; + procedure BitBtn1Click(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + Form3: TForm3; + +implementation + +uses gtin.classes, + gtin.utils; + +{$R *.dfm} + +procedure TForm3.BitBtn1Click(Sender: TObject); +var O : gtin.classes.TGTIN; + P : gtin.classes.TPicture; +begin + O := TGTIN.Create; + + O.Code := '7894900011517'; + O.Description := 'REFRIG COCA COLA PET 2L'; + + O.Status.Code := '200'; + O.Status.Description := 'Ok. GTIN com dados fixo'; + + O.Unid.Description := 'Unidade'; + + O.Packaging.Height := 20; + O.Packaging.Width := 5; + O.Packaging.Quantity := 2.250; + O.Packaging.Weight := 1.1234; + O.Packaging.Length := 1.5678; + + + O.Tributes.NCM := '22021000'; + O.Tributes.CEST := '00000000'; + O.Tributes.CBS := 12.3456; + O.Tributes.IBS := 7.8901; + + O.Others.Category := 'Bebidas'; + O.Others.Producer := 'Coca-Cola LTDA'; + O.Others.Observation := 'Refrigerante de cola'; + O.Others.DataSheet := '1 - Bebida não alcoolica'+ sLineBreak + + '2 - Embalagem de plástico'; + O.Others.Web := 'https://www.coca-cola.com.br/'; + + P := gtin.classes.TPicture.Create; + P.Path := 'https://www.coca-cola.com.br/share/thumb-site.png'; + O.PictureAdd(P); + + P := gtin.classes.TPicture.Create; + P.Path := 'https://media.cotabest.com.br/media/sku/refrigerante-pet-2-litros-coca-cola-un-1d5188ce75.jpg'; + O.PictureAdd(P); + + Memo1.Text := TUtils.ToJSonString(O,True); +end; + +end. diff --git a/src/gtin.utils.pas b/src/gtin.utils.pas new file mode 100644 index 0000000..11dc7e1 --- /dev/null +++ b/src/gtin.utils.pas @@ -0,0 +1,140 @@ +unit gtin.utils; + +interface + +uses System.Classes, System.SysUtils, + System.JSON, System.JSON.Serializers, System.JSON.Types, + System.Net.HttpClientComponent, System.Net.HttpClient; + +type + TUtils = Class + Public + Class function NumberOnly(Value : String) : String; + Class function AlphaOnly(Value : String) : String; Overload; + Class function AlphaOnly(IsAlpha : Boolean; Value : String) : String; Overload; + + Class function DownloadFile(Value : String) : TStream; Overload; + Class function DownloadFile(Value : String; FileName : TFileName) : TFileName; Overload; + + Class function ToJSonString(Value : TObject; IsIndented : Boolean = False; IsHtml : Boolean = True) : String; + Class function ToJSonValue(Value : TObject) : TJSONValue; + Class function ToValueJSon(Value : String) : T; + End; + +implementation + +{ TUtils } + +class function TUtils.AlphaOnly(Value: String): String; +type + StrAscii20127 = type Ansistring(20127); +begin + Result := String(StrAscii20127(Value)); +end; + +class function TUtils.DownloadFile(Value : String): TStream; +var Http : TNetHTTPClient; +begin + Result := nil; + If Value.IsEmpty Then + Exit; + + Result := TMemoryStream.Create; + + Http := TNetHTTPClient.Create(nil); + Try + Http.Name := 'httpClient_'; + Http.AcceptEncoding := 'raw'; + Http.UserAgent := 'Embarcadero URI Client/1.0'; + Http.SecureProtocols := [THTTPSecureProtocol.TLS12]; + + Result.CopyFrom(IHTTPResponse(Http.Get(Value)).ContentStream); + Finally + FreeAndNil(Http); + End; +end; + +class function TUtils.AlphaOnly(IsAlpha: Boolean; Value: String): String; +begin + Result := Value; + If IsAlpha Then + Result := AlphaOnly(Result); +end; + +class function TUtils.DownloadFile(Value: String; + FileName: TFileName): TFileName; +var S : TMemoryStream; +begin + S := TMemoryStream(DownloadFile(Value)); + If not Assigned(S) Then + Exit; + + Try + S.SaveToFile(FileName); + Finally + FreeAndNil(S); + End; +end; + +class function TUtils.NumberOnly(Value: String): String; +var I : Integer; +begin + Result := ''; + For I := Low(Value) to High(Value) Do + If (Value[I] in ['0' .. '9']) Then + Result := Result + Value[I]; +end; + +class function TUtils.ToJSonString(Value: TObject; IsIndented, IsHtml : Boolean) : String; +var J : TJsonSerializer; +begin + J := TJsonSerializer.Create; + Try + J.Formatting := TJsonFormatting.None; + J.DateFormatHandling := TJsonDateFormatHandling.Iso; + J.DateTimeZoneHandling := TJsonDateTimeZoneHandling.Utc; + + If IsIndented Then + J.Formatting := TJsonFormatting.Indented; + + If IsHtml Then + J.StringEscapeHandling := TJsonStringEscapeHandling.EscapeHtml; + + Result := J.Serialize(Value); + Finally + FreeAndNil(J); + End; +end; + +class function TUtils.ToJSonValue(Value: TObject): TJSONValue; +var S : String; +begin + S := ToJSonString(Value); + Result := TJSONObject.ParseJSONValue(S); +end; + +class function TUtils.ToValueJSon(Value: String): T; +var J : TJsonSerializer; + S : String; +begin + Result := nil; + If S.IsEmpty Or (S = 'null') Then + Exit; + + J := TJsonSerializer.Create; + Try + J.Formatting := TJsonFormatting.None; + J.DateFormatHandling := TJsonDateFormatHandling.Iso; + J.DateTimeZoneHandling := TJsonDateTimeZoneHandling.Utc; + J.StringEscapeHandling := TJsonStringEscapeHandling.EscapeHtml; + Try + Result := J.Deserialize(S); + Except + FreeAndNil(Result); + End; + Finally + FreeAndNil(J); + End; +end; + +end. diff --git a/src/main.control.pas b/src/main.control.pas index 0e5c63a..f6961f4 100644 --- a/src/main.control.pas +++ b/src/main.control.pas @@ -2,91 +2,105 @@ interface -uses - wsHorse, System.Classes; +uses System.Classes, System.SysUtils, System.IOUtils, wsHorse; type TMainControl = class private - FWS: TWsHorse; - FConfig: TStrings; - FFileConfig: String; - function GetWs: TWsHorse; + FWS : TWsHorse; + FConfig : TStrings; + FFileConfig : String; + + function GetWs : TWsHorse; procedure LoadConfig; function GetConfigParams(Key: String): String; - property WS: TWsHorse read GetWs; + property WS : TWsHorse Read GetWs; public - constructor Create; - destructor Destroy; + Constructor Create; + Destructor Destroy; Override; + + property Config : TStrings Read FConfig; + procedure Power; + procedure Log(Value : TProc); + procedure SaveConfig(Values: TStrings); - property Config: TStrings read FConfig; function Active: Boolean; end; implementation -uses - System.IOUtils, System.SysUtils; - { TMainControl } function TMainControl.Active: Boolean; begin - Result := WS.Active; + Result := WS.Active; end; constructor TMainControl.Create; begin - FConfig := TStringList.Create; + FWS := nil; - FFileConfig := TPath.GetDirectoryName(ParamStr(0))+'\config.ini'; - LoadConfig; + FConfig := TStringList.Create; + FFileConfig := TPath.GetDirectoryName(ParamStr(0)) + '\config.ini'; + + LoadConfig; end; destructor TMainControl.Destroy; begin - FConfig.Free; + If Assigned(FWS) Then + FreeAndNil(FWS); + + FreeAndNil(FConfig); + + inherited; end; function TMainControl.GetConfigParams(Key: String): String; begin - result := Config.Values[Key]; + Result := Config.Values[Key]; end; function TMainControl.GetWs: TWsHorse; begin - if not Assigned(FWS) then - FWS := TWsHorse.Create; - Result := FWS; + If not Assigned(FWS) then + FWS := TWsHorse.Create; + Result := FWS; end; procedure TMainControl.LoadConfig; begin - if FileExists( FFileConfig ) then - Config.LoadFromFile( FFileConfig ) - else - begin - Config.AddPair('Path', TPath.GetDirectoryName(FFileConfig) + '\files\' ); - Config.AddPair('Port', '9000' ); - Config.SaveToFile( FFileConfig ); - end; + If FileExists( FFileConfig ) Then + Begin + Config.LoadFromFile( FFileConfig ); + Exit; + End; + + Config.AddPair('Path', TPath.GetDirectoryName(FFileConfig) + '\files\' ); + Config.AddPair('Port', '9000' ); + Config.SaveToFile( FFileConfig ); end; +procedure TMainControl.Log(Value: TProc); +begin + WS.Log(Value); +end; + procedure TMainControl.SaveConfig(Values: TStrings); begin - Config.Assign(Values); - Config.SaveToFile( FFileConfig ); + Config.Assign(Values); + Config.SaveToFile( FFileConfig ); end; procedure TMainControl.Power; begin - if not Active then - begin - WS.Port( GetConfigParams('Port').ToInteger ) - .Path( GetConfigParams('Path') ) - end; - WS.Power; + If (not Active) Then + Begin + WS.Port( GetConfigParams('Port').ToInteger ) + .Path( GetConfigParams('Path') ); + End; + WS.Power; end; end. diff --git a/src/main.view.dfm b/src/main.view.dfm index a2e6b17..bb63078 100644 --- a/src/main.view.dfm +++ b/src/main.view.dfm @@ -1,136 +1,331 @@ -object MainView: TMainView - Left = 0 - Top = 0 - Caption = 'Servidor EanPictures 2.9 - Sac Fiscal | Firedac' - ClientHeight = 571 - ClientWidth = 1008 - Color = clBtnFace - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -11 - Font.Name = 'Tahoma' - Font.Style = [] - OldCreateOrder = False - OnCreate = FormCreate - PixelsPerInch = 96 - TextHeight = 13 - object Panel1: TPanel - Left = 0 - Top = 0 - Width = 1008 - Height = 41 - Align = alTop - Caption = 'Server' - TabOrder = 0 - end - object Panel3: TPanel - Left = 0 - Top = 530 - Width = 1008 - Height = 41 - Align = alBottom - TabOrder = 1 - DesignSize = ( - 1008 - 41) - object btnPower: TBitBtn - Left = 862 - Top = 5 - Width = 142 - Height = 30 - Anchors = [akTop, akRight, akBottom] - Caption = 'Start' - TabOrder = 0 - OnClick = btnPowerClick - end - object btnSaveConfig: TBitBtn - Left = 661 - Top = 5 - Width = 75 - Height = 30 - Anchors = [] - Caption = 'Save Config' - TabOrder = 1 - OnClick = btnSaveConfigClick - end - end - object Panel2: TPanel - Left = 0 - Top = 47 - Width = 1008 - Height = 482 - TabOrder = 2 - object Bevel1: TBevel - Left = 1 - Top = 465 - Width = 1006 - Height = 16 - Align = alBottom - ExplicitTop = 337 - end - object Label1: TLabel - Left = 4 - Top = 419 - Width = 147 - Height = 13 - Caption = 'Total de Resquests resolvidos:' - end - object Label2: TLabel - Left = 4 - Top = 443 - Width = 117 - Height = 13 - Caption = 'Total de Resquests 404:' - end - object ValueListEditor1: TValueListEditor - Left = 1 - Top = 1 - Width = 1006 - Height = 80 - Align = alTop - TabOrder = 0 - ColWidths = ( - 150 - 850) - RowHeights = ( - 18 - 18) - end - object GroupBox3: TGroupBox - Left = 1 - Top = 81 - Width = 1006 - Height = 336 - Align = alTop - Caption = 'Hist'#243'rico' - TabOrder = 1 - object MemoHistorico: TMemo - Left = 2 - Top = 15 - Width = 1002 - Height = 319 - Align = alClient - Lines.Strings = ( - 'MemoOK') - TabOrder = 0 - OnChange = MemoHistoricoChange - end - end - object Edit1: TEdit - Left = 160 - Top = 416 - Width = 121 - Height = 21 - TabOrder = 2 - Text = 'Edit1' - end - object Edit2: TEdit - Left = 160 - Top = 440 - Width = 121 - Height = 21 - TabOrder = 3 - Text = 'Edit1' - end - end -end +object MainView: TMainView + Left = 0 + Top = 0 + Caption = 'Servidor EanPictures 2.9 - Sac Fiscal | Firedac' + ClientHeight = 571 + ClientWidth = 1008 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + Position = poDesktopCenter + OnCreate = FormCreate + OnDestroy = FormDestroy + PixelsPerInch = 96 + TextHeight = 13 + object Panel1: TPanel + AlignWithMargins = True + Left = 2 + Top = 1 + Width = 1004 + Height = 110 + Margins.Left = 2 + Margins.Top = 1 + Margins.Right = 2 + Margins.Bottom = 1 + Align = alTop + BevelInner = bvLowered + TabOrder = 0 + object pnl200: TPanel + AlignWithMargins = True + Left = 7 + Top = 3 + Width = 200 + Height = 104 + Margins.Left = 5 + Margins.Top = 1 + Margins.Right = 5 + Margins.Bottom = 1 + Align = alLeft + BevelKind = bkFlat + BevelOuter = bvNone + TabOrder = 0 + object lbl_200: TLabel + AlignWithMargins = True + Left = 1 + Top = 1 + Width = 194 + Height = 13 + Margins.Left = 1 + Margins.Top = 1 + Margins.Right = 1 + Margins.Bottom = 1 + Align = alTop + Caption = 'Resquests 200 :' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clMedGray + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + ParentColor = False + ParentFont = False + ExplicitWidth = 78 + end + object lbl200: TLabel + AlignWithMargins = True + Left = 1 + Top = 16 + Width = 194 + Height = 83 + Margins.Left = 1 + Margins.Top = 1 + Margins.Right = 1 + Margins.Bottom = 1 + Align = alClient + Caption = '000' + Font.Charset = DEFAULT_CHARSET + Font.Color = clGreen + Font.Height = -53 + Font.Name = 'Tahoma' + Font.Style = [fsBold] + ParentFont = False + Layout = tlCenter + ExplicitWidth = 102 + ExplicitHeight = 64 + end + end + object pnl404: TPanel + AlignWithMargins = True + Left = 217 + Top = 3 + Width = 200 + Height = 104 + Margins.Left = 5 + Margins.Top = 1 + Margins.Right = 5 + Margins.Bottom = 1 + Align = alLeft + BevelKind = bkFlat + BevelOuter = bvNone + TabOrder = 1 + object lbl_404: TLabel + AlignWithMargins = True + Left = 1 + Top = 1 + Width = 194 + Height = 13 + Margins.Left = 1 + Margins.Top = 1 + Margins.Right = 1 + Margins.Bottom = 1 + Align = alTop + Caption = 'Resquests 404 :' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clMedGray + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + ParentColor = False + ParentFont = False + ExplicitWidth = 78 + end + object lbl404: TLabel + AlignWithMargins = True + Left = 1 + Top = 16 + Width = 194 + Height = 83 + Margins.Left = 1 + Margins.Top = 1 + Margins.Right = 1 + Margins.Bottom = 1 + Align = alClient + Caption = '000' + Font.Charset = DEFAULT_CHARSET + Font.Color = clRed + Font.Height = -53 + Font.Name = 'Tahoma' + Font.Style = [fsBold] + ParentFont = False + Layout = tlCenter + ExplicitWidth = 102 + ExplicitHeight = 64 + end + end + object Panel6: TPanel + AlignWithMargins = True + Left = 424 + Top = 3 + Width = 576 + Height = 104 + Margins.Left = 2 + Margins.Top = 1 + Margins.Right = 2 + Margins.Bottom = 1 + Align = alClient + BevelKind = bkFlat + BevelOuter = bvNone + TabOrder = 2 + Visible = False + object lbl_db: TLabel + AlignWithMargins = True + Left = 1 + Top = 1 + Width = 570 + Height = 13 + Margins.Left = 1 + Margins.Top = 1 + Margins.Right = 1 + Margins.Bottom = 1 + Align = alTop + Caption = 'Banco de dados :' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clMedGray + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + ParentColor = False + ParentFont = False + ExplicitWidth = 83 + end + object BitBtn1: TBitBtn + AlignWithMargins = True + Left = 494 + Top = 18 + Width = 75 + Height = 79 + Align = alRight + Caption = 'Refresh' + TabOrder = 0 + end + object StringGrid1: TStringGrid + AlignWithMargins = True + Left = 3 + Top = 18 + Width = 485 + Height = 79 + Align = alClient + ColCount = 2 + TabOrder = 1 + end + end + end + object Panel3: TPanel + Left = 0 + Top = 512 + Width = 1008 + Height = 59 + Align = alBottom + TabOrder = 1 + object btnPower: TBitBtn + AlignWithMargins = True + Left = 854 + Top = 2 + Width = 150 + Height = 51 + Margins.Left = 10 + Margins.Top = 1 + Margins.Bottom = 5 + Align = alRight + Caption = 'Start' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -27 + Font.Name = 'Tahoma' + Font.Style = [fsBold] + ParentFont = False + TabOrder = 0 + OnClick = btnPowerClick + end + object btnSaveConfig: TBitBtn + AlignWithMargins = True + Left = 691 + Top = 2 + Width = 150 + Height = 51 + Margins.Left = 10 + Margins.Top = 1 + Margins.Bottom = 5 + Align = alRight + Caption = 'Save Config' + TabOrder = 1 + OnClick = btnSaveConfigClick + end + object btnTest: TBitBtn + AlignWithMargins = True + Left = 11 + Top = 2 + Width = 38 + Height = 51 + Margins.Left = 10 + Margins.Top = 1 + Margins.Bottom = 5 + Align = alLeft + Caption = 'Test' + TabOrder = 2 + OnClick = btnTestClick + end + object btnClear: TBitBtn + AlignWithMargins = True + Left = 528 + Top = 2 + Width = 150 + Height = 51 + Margins.Left = 10 + Margins.Top = 1 + Margins.Bottom = 5 + Align = alRight + Caption = 'Clear' + TabOrder = 3 + OnClick = btnClearClick + end + end + object Panel2: TPanel + AlignWithMargins = True + Left = 3 + Top = 115 + Width = 1002 + Height = 394 + Align = alClient + TabOrder = 2 + object vlEditor: TValueListEditor + AlignWithMargins = True + Left = 3 + Top = 2 + Width = 996 + Height = 80 + Margins.Left = 2 + Margins.Top = 1 + Margins.Right = 2 + Margins.Bottom = 1 + Align = alTop + TabOrder = 0 + ColWidths = ( + 150 + 840) + RowHeights = ( + 18 + 18) + end + object gbLog: TGroupBox + Left = 1 + Top = 83 + Width = 1000 + Height = 310 + Margins.Left = 2 + Margins.Top = 1 + Margins.Right = 2 + Margins.Bottom = 1 + Align = alClient + Caption = '| Hist'#243'rico |' + TabOrder = 1 + object mmLog: TMemo + AlignWithMargins = True + Left = 5 + Top = 18 + Width = 990 + Height = 287 + Align = alClient + ReadOnly = True + ScrollBars = ssVertical + TabOrder = 0 + OnChange = mmLogChange + end + end + end +end diff --git a/src/main.view.pas b/src/main.view.pas index fc6a48b..912c515 100644 --- a/src/main.view.pas +++ b/src/main.view.pas @@ -14,21 +14,34 @@ TMainView = class(TForm) btnPower: TBitBtn; btnSaveConfig: TBitBtn; Panel2: TPanel; - Bevel1: TBevel; - ValueListEditor1: TValueListEditor; - GroupBox3: TGroupBox; - MemoHistorico: TMemo; - Label1: TLabel; - Label2: TLabel; - Edit1: TEdit; - Edit2: TEdit; + vlEditor: TValueListEditor; + gbLog: TGroupBox; + mmLog: TMemo; + btnTest: TBitBtn; + btnClear: TBitBtn; + pnl200: TPanel; + pnl404: TPanel; + Panel6: TPanel; + lbl_200: TLabel; + lbl200: TLabel; + lbl_404: TLabel; + lbl404: TLabel; + lbl_db: TLabel; + BitBtn1: TBitBtn; + StringGrid1: TStringGrid; procedure FormCreate(Sender: TObject); procedure btnPowerClick(Sender: TObject); procedure btnSaveConfigClick(Sender: TObject); - procedure MemoHistoricoChange(Sender: TObject); + procedure mmLogChange(Sender: TObject); + procedure btnTestClick(Sender: TObject); + procedure btnClearClick(Sender: TObject); + procedure FormDestroy(Sender: TObject); private { Private declarations } - Control: TMainControl; + FControl : TMainControl; + + procedure OnLog(Value : String); + procedure LoadConfigFile; procedure SaveConfigFile; public @@ -37,50 +50,124 @@ TMainView = class(TForm) var MainView: TMainView; - cont404, cont200: integer; -// descerro, descok: integer; -// umerro, umok: integer; + Cont404, Cont200 : Int64; implementation -uses main.basedados; + +uses gtin.consts, + gtin.utils, + gtin.dm; + {$R *.dfm} procedure TMainView.FormCreate(Sender: TObject); begin - Control := TMainControl.Create; - LoadConfigFile; + FControl := TMainControl.Create; + FControl.Log(OnLog); + + LoadConfigFile; end; +procedure TMainView.FormDestroy(Sender: TObject); +begin + FreeAndNil(FControl); +end; + procedure TMainView.btnSaveConfigClick(Sender: TObject); begin - SaveConfigFile; + SaveConfigFile; end; +procedure TMainView.btnTestClick(Sender: TObject); +var D : TDM; + O : TObject; +begin + D := TDM.Create(Self); + + mmLog.Lines.Clear; + + O := D.GetGTIN(TVersion.v01,'7894900011517'); + Try + mmLog.Lines.Add('-> GTIN - Versão 01'); + mmLog.Lines.Add('------------'); + mmLog.Lines.Add(''); + mmLog.Lines.Add( TUtils.ToJSonString(O,True) ); + mmLog.Lines.Add(''); + Finally + FreeAndNil(O); + End; + + O := D.GetGTIN(TVersion.v02,'7894900011517'); + Try + mmLog.Lines.Add('-> GTIN - Versão 02'); + mmLog.Lines.Add('------------'); + mmLog.Lines.Add(''); + mmLog.Lines.Add( TUtils.ToJSonString(O,True) ); + mmLog.Lines.Add(''); + Finally + FreeAndNil(O); + End; + + O := D.GetGTIN_Unid_Med(TVersion.v02,''); + Try + mmLog.Lines.Add('-> Unidade Medida - Versão 02'); + mmLog.Lines.Add('------------'); + mmLog.Lines.Add(''); + mmLog.Lines.Add( TUtils.ToJSonString(O,True) ); + mmLog.Lines.Add(''); + Finally + FreeAndNil(O); + End; + + FreeAndNil(O); +end; + +procedure TMainView.btnClearClick(Sender: TObject); +begin + AtomicIncrement(Cont200,- Cont200); + AtomicIncrement(Cont404,- Cont404); + mmLog.Clear; +end; + procedure TMainView.btnPowerClick(Sender: TObject); begin - Control.Config.Assign( ValueListEditor1.Strings ); - Control.Power; - case Control.Active of - false: btnPower.Caption := 'Start'; - true : btnPower.Caption := 'Stop'; - end; + FControl.Config.Assign( vlEditor.Strings ); + FControl.Power; + + btnPower.Caption := 'Stop'; + If not FControl.Active Then + btnPower.Caption := 'Start'; end; procedure TMainView.LoadConfigFile; begin - ValueListEditor1.Strings.Assign( Control.Config ); + vlEditor.Strings.Assign( FControl.Config ); end; -procedure TMainView.MemoHistoricoChange(Sender: TObject); +procedure TMainView.mmLogChange(Sender: TObject); begin - edit1.Text:=inttostr(cont200); - edit2.Text:=inttostr(cont404); + lbl200.Caption := FormatFloat('000',Cont200); + lbl404.Caption := FormatFloat('000',Cont404); end; +procedure TMainView.OnLog(Value: String); +begin + mmLog.Lines.BeginUpdate; + Try + If (mmLog.Lines.Count > 10000) Then + mmLog.Lines.Clear; + + mmLog.Lines.Add(FormatDateTime('dd/mm/yyyy hh:nn:ss',Now) +' | '+ Value); + + Finally + mmLog.Lines.EndUpdate; + End; +end; + procedure TMainView.SaveConfigFile; begin - Control.SaveConfig(ValueListEditor1.Strings); - LoadConfigFile; + FControl.SaveConfig( vlEditor.Strings ); + LoadConfigFile; end; end. diff --git a/src/wsHorse.pas b/src/wsHorse.pas index 69ab1e6..c1b71c0 100644 --- a/src/wsHorse.pas +++ b/src/wsHorse.pas @@ -2,684 +2,567 @@ interface -uses Horse, Horse.Jhonson, Horse.OctetStream, Horse.HandleException, - System.SysUtils, System.Net.HttpClientComponent, System.Net.HttpClient; +uses System.Classes, System.SysUtils, System.IOUtils, + System.Generics.Collections, System.JSON, + Horse, Horse.Jhonson, Horse.OctetStream, Horse.HandleException; + +// http://localhost:9000/api/desc/78932609 +// http://localhost:9000/api/desc/7894900011517 +// http://localhost:9000/api/desc_ini/7894900011517 + +//http://localhost:9000/api/v2/gtin/7894900011517 type TWsHorse = class private - FHorse: THorse; - FPath: String; + FHorse : THorse; + FPath : String; + FLog : TProc; + + procedure DoLog(Value : String); + function DoCount(Value : Boolean) : Integer; + + procedure DoStatus(Req : THorseRequest; Res : THorseResponse; Status : Integer; MensStatus, Mens, MensLog : String); + + procedure Gtin(Req : THorseRequest; Res : THorseResponse; Next : TProc); + + procedure FotoExiste(Req : THorseRequest; Res : THorseResponse; Next : TProc); + procedure FotoExisteJson(Req : THorseRequest; Res : THorseResponse; Next : TProc); + + procedure Descricao(Req : THorseRequest; Res : THorseResponse; Next : TProc); + procedure DescricaoJSon(Req : THorseRequest; Res : THorseResponse; Next : TProc); + procedure DescricaoJSon200(Req : THorseRequest; Res : THorseResponse; Next : TProc); + procedure DescricaoIni(Req : THorseRequest; Res : THorseResponse; Next : TProc); + + procedure UnidadeMedidaNome(Req : THorseRequest; Res : THorseResponse; Next : TProc); + procedure UnidadeMedidaJSon(Req : THorseRequest; Res : THorseResponse; Next : TProc); + + procedure V2Gtin(Req : THorseRequest; Res : THorseResponse; Next : TProc); + procedure V2UnidadeMedida(Req : THorseRequest; Res : THorseResponse; Next : TProc); + procedure AddMethods; + public - constructor Create; - function Port(Value: Integer): TWsHorse; - function Path(Value: String): TWsHorse; + Constructor Create; + Destructor Destroy; Override; + + function Port(Value : Integer) : TWsHorse; + function Path(Value : String) : TWsHorse; + function Log(Value : TProc) : TWsHorse; + function Active: Boolean; - procedure Power; - function removeacento(const ptext: string):string; - function somentenumero(snum: string): string; - procedure baixacosmos(const ean: string); + procedure Power; end; implementation -uses - System.Classes, System.IOUtils, main.view, main.basedados, system.JSON; +uses gtin.consts, + gtin.utils, + gtin.Classes, + gtin.dm, + main.view; { TWsHorse } function TWsHorse.Active: Boolean; begin - Result := FHorse.IsRunning; + Result := FHorse.IsRunning; end; procedure TWsHorse.AddMethods; begin - with FHorse do - begin - Get('/api/gtin/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var - LFile: String; - LFileSend: TFileReturn; - LStream: TFileStream; - LDisposition: String; - begin - LFile := FPath + somentenumero(Req.Params.Items['id']) + '.png'; - -// if fileexists(lfile) = false then baixacosmos(somentenumero(Req.Params.Items['id'])); - - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - if FileExists(LFile) then - begin - try - LStream := TFileStream.Create(LFile, fmOpenRead); - LFileSend := TFileReturn.Create( TPath.GetFileName(LFile), LStream, False); - Res.Send(LFileSend).Status(200); - inc(cont200); - - mainview.MemoHistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Entregue arquivo: '+lfile); - finally - end; - end - else - begin - //quando pede foto eu nao envio json no retorno para evitar erro na conversao do lado do cliente - inc(cont404); - - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Arquivo nao encontrado: '+lfile); - Res.Send('').Status(404); - end; - end); - - Get('/api/fotoexiste/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var - LFile: String; - begin - LFile := FPath + somentenumero(Req.Params.Items['id']) + '.png'; - - - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - if FileExists(LFile) then - begin - try - Res.Send('Sim').Status(200); - inc(cont200); - - mainview.MemoHistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Consulta Arquivo : '+lfile+' Sim'); - finally - end; - end - else - begin - Res.Send('Nao').Status(200); - inc(cont200); - mainview.MemoHistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Consulta Arquivo : '+lfile+' Nao'); - end; - end); - - Get('/api/fotoexistej/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var - LFile: String; - wjson: tjsonobject; - begin - LFile := FPath + somentenumero(Req.Params.Items['id']) + '.png'; - - - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - - wjson:=tjsonobject.Create; - - - if FileExists(LFile) then - begin - try - wjson.AddPair(tjsonpair.Create('Status','200')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Foto encontrada: '+Req.Params.Items['id'])); - Res.Send(wjson).Status(200);; -// Res.Send('Sim').Status(200); - inc(cont200); - - mainview.MemoHistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Consulta Arquivo : '+lfile+' Sim'); - finally - end; - end - else - begin - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Foto nao encontrada: '+Req.Params.Items['id'])); - Res.Send(wjson).Status(200);; -// Res.Send('Nao').Status(200); - inc(cont200); - mainview.MemoHistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Consulta Arquivo : '+lfile+' Nao'); - end; - end); - - Get('/api/descricao/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var wjson: tjsonobject; - begin - if Req.Params.Items['id'] <> '' then - begin - if basedados.fdConnection1.Connected= false then - basedados.fdConnection1.Connected:=true; - - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - - with BaseDados.fdquery1 do - begin - close; - sql.Clear; -// sql.Add('select nome, ncm, cest_codigo, embalagem, quantidade_embalagem, marca, categoria, tributacao from cad_produtos where ean = :ean'); - sql.Add('select nome, ncm, cest_codigo, embalagem, quantidade_embalagem, marca, categoria from cad_produtos where ean = :ean'); - parambyname('ean').AsString:=Req.Params.Items['id']; - open; - if isempty = false then - begin - Res.Send(fieldbyname('nome').asstring).Status(200); - inc(cont200); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Entregue descricao: '+Req.Params.Items['id']+ '|' +fieldbyname('nome').asstring); - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Descricao nao encontrada para o ean: '+Req.Params.Items['id'])); - Res.Send(wjson).Status(404);; - inc(cont404); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - finally - end; - end; - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Necessario enviar o codigo da mercadoria. Ex: www.eanpictures.com.br:9000/api/descricao/789789789789')); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - finally - end; - end; - - end); - - Get('/api/um2/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var wjson: tjsonobject; - begin - if Req.Params.Items['id'] <> '' then - begin - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - - if basedados.fdConnection1.Connected= false then - basedados.fdConnection1.Connected:=true; - - with BaseDados.fdquery1 do - begin - close; - sql.Clear; - sql.Add('select nome from unidade_medida where id = :id'); - parambyname('id').AsString:=Req.Params.Items['id']; - open; - if isempty = false then - begin - Res.Send(fieldbyname('nome').asstring).Status(200); - inc(cont200); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Entregue descricao unidade medida: '+Req.Params.Items['id']+ '|' +fieldbyname('nome').asstring); - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Descricao nao encontrada para a unidade de medida: '+Req.Params.Items['id'])); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada a unidade de meida: '+Req.Params.Items['id']); - finally - end; - end; - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Necessario enviar o codigo da unidade de medida. Ex: www.eanpictures.com.br:9000/api/um/M3')); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada a unidade de meida: '+Req.Params.Items['id']); - - finally - end; - end; - end); - -//*** - Get('/api/um/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var wjson: tjsonobject; - begin - - if Req.Params.Items['id'] <> '' then - begin - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - - if basedados.fdConnection1.Connected= false then - basedados.fdConnection1.Connected:=true; - - with BaseDados.fdquery1 do - begin - close; - sql.Clear; - sql.Add('select id, nome from unidade_medida where id = :id'); - parambyname('id').AsString:=Req.Params.Items['id']; - open; - if isempty = false then - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','200')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Ok')); - wjson.AddPair(tjsonpair.Create('id',removeacento(fieldbyname('id').asstring))); - wjson.AddPair(tjsonpair.Create('nome',removeacento(fieldbyname('nome').asstring))); - Res.Send(wjson).Status(200);; - - inc(cont200); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Entregue descricao unidade medida: '+Req.Params.Items['id']+ '|' +fieldbyname('nome').asstring); - - finally - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Descricao nao encontrada para a unidade de medida: '+Req.Params.Items['id'])); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada a unidade de meida: '+Req.Params.Items['id']); - finally - end; - end; - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Necessario enviar o codigo da unidade de medida. Ex: www.eanpictures.com.br:9000/api/um/M3')); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada a unidade de meida: '+Req.Params.Items['id']); - - finally - end; - end; - end); - -//**** - - Get('/api/desc/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var wjson: tjsonobject; - begin - if Req.Params.Items['id'] <> '' then - begin - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - - if basedados.fdConnection1.Connected= false then - basedados.fdConnection1.Connected:=true; - with BaseDados.fdquery1 do - begin - close; - sql.Clear; -// sql.Add('SELECT base_produtos.cad_produtos.ean, base_produtos.cad_produtos.nome, base_produtos.cad_produtos.peso,'); - sql.Add('SELECT base_produtos.cad_produtos.ean, base_produtos.cad_produtos.nome, '); - sql.Add('base_produtos.cad_produtos.ncm, base_produtos.cad_produtos.cest_codigo, base_produtos.cad_produtos.embalagem, base_produtos.cad_produtos.quantidade_embalagem,'); -// sql.Add('base_produtos.cad_produtos.marca, base_produtos.cad_produtos.categoria, base_produtos.cad_produtos.id_categoria, base_produtos.cad_produtos.tributacao'); -// sql.Add('base_produtos.cad_produtos.marca, base_produtos.cad_produtos.categoria, base_produtos.cad_produtos.id_categoria'); - sql.Add('base_produtos.cad_produtos.marca, base_produtos.cad_produtos.categoria'); - sql.Add(' FROM base_produtos.cad_produtos'); - sql.Add('where ean = :ean'); - parambyname('ean').AsString:=Req.Params.Items['id']; - open; - - if isempty = false then - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','200')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Ok')); - wjson.AddPair(tjsonpair.Create('Nome',removeacento(fieldbyname('nome').asstring))); - wjson.AddPair(tjsonpair.Create('Ncm',removeacento(fieldbyname('ncm').asstring))); - wjson.AddPair(tjsonpair.Create('Cest_Codigo',removeacento(fieldbyname('cest_codigo').asstring))); - wjson.AddPair(tjsonpair.Create('Embalagem',removeacento(fieldbyname('embalagem').asstring))); - wjson.AddPair(tjsonpair.Create('QuantidadeEmbalagem',removeacento(fieldbyname('quantidade_embalagem').asstring))); - wjson.AddPair(tjsonpair.Create('Marca',removeacento(fieldbyname('marca').asstring))); - wjson.AddPair(tjsonpair.Create('Categoria',removeacento(fieldbyname('categoria').asstring))); -// wjson.AddPair(tjsonpair.Create('Peso',removeacento(fieldbyname('peso').asstring))); - wjson.AddPair(tjsonpair.Create('Peso','')); -// wjson.AddPair(tjsonpair.Create('id_categoria',removeacento(fieldbyname('id_categoria').asstring))); - wjson.AddPair(tjsonpair.Create('id_categoria','')); -// wjson.AddPair(tjsonpair.Create('tributacao',removeacento(fieldbyname('tributacao').asstring))); - wjson.AddPair(tjsonpair.Create('tributacao','')); - Res.Send(wjson).Status(200);; - - inc(cont200); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Entregue json: '+Req.Params.Items['id']+ '|' +fieldbyname('nome').asstring); - finally - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Descricao nao encontrada para o ean: '+Req.Params.Items['id'])); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - finally - end; - end; - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Necessario enviar o codigo da mercadoria. Ex: www.eanpictures.com.br:9000/api/descricao/789789789789')); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - finally - end; - end; - end); - //************ - - Get('/api/desc200/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var wjson: tjsonobject; - begin - if Req.Params.Items['id'] <> '' then - begin - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - - if basedados.fdConnection1.Connected= false then - basedados.fdConnection1.Connected:=true; - with BaseDados.fdquery1 do - begin - close; - sql.Clear; - sql.Add('SELECT base_produtos.cad_produtos.ean, base_produtos.cad_produtos.nome, '); -// sql.Add('SELECT base_produtos.cad_produtos.ean, base_produtos.cad_produtos.nome, base_produtos.cad_produtos.peso,'); - sql.Add('base_produtos.cad_produtos.ncm, base_produtos.cad_produtos.cest_codigo, base_produtos.cad_produtos.embalagem, base_produtos.cad_produtos.quantidade_embalagem,'); -// sql.Add('base_produtos.cad_produtos.marca, base_produtos.cad_produtos.categoria, base_produtos.cad_produtos.id_categoria, base_produtos.cad_produtos.tributacao'); -// sql.Add('base_produtos.cad_produtos.marca, base_produtos.cad_produtos.categoria, base_produtos.cad_produtos.id_categoria'); - sql.Add('base_produtos.cad_produtos.marca, base_produtos.cad_produtos.categoria'); - sql.Add(' FROM base_produtos.cad_produtos'); - sql.Add('where ean = :ean'); - parambyname('ean').AsString:=Req.Params.Items['id']; - open; - - if isempty = false then - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','200')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Ok')); - wjson.AddPair(tjsonpair.Create('Nome',removeacento(fieldbyname('nome').asstring))); - wjson.AddPair(tjsonpair.Create('Ncm',removeacento(fieldbyname('ncm').asstring))); - wjson.AddPair(tjsonpair.Create('Cest_Codigo',removeacento(fieldbyname('cest_codigo').asstring))); - wjson.AddPair(tjsonpair.Create('Embalagem',removeacento(fieldbyname('embalagem').asstring))); - wjson.AddPair(tjsonpair.Create('QuantidadeEmbalagem',removeacento(fieldbyname('quantidade_embalagem').asstring))); - wjson.AddPair(tjsonpair.Create('Marca',removeacento(fieldbyname('marca').asstring))); - wjson.AddPair(tjsonpair.Create('Categoria',removeacento(fieldbyname('categoria').asstring))); -// wjson.AddPair(tjsonpair.Create('Peso',removeacento(fieldbyname('peso').asstring))); - wjson.AddPair(tjsonpair.Create('Peso','')); -// wjson.AddPair(tjsonpair.Create('id_categoria',removeacento(fieldbyname('id_categoria').asstring))); - wjson.AddPair(tjsonpair.Create('id_categoria','')); -// wjson.AddPair(tjsonpair.Create('tributacao',removeacento(fieldbyname('tributacao').asstring))); - wjson.AddPair(tjsonpair.Create('tributacao','')); - Res.Send(wjson).Status(200);; - - inc(cont200); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Entregue json: '+Req.Params.Items['id']+ '|' +fieldbyname('nome').asstring); - finally - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','404')); - wjson.AddPair(tjsonpair.Create('Nome','404')); - wjson.AddPair(tjsonpair.Create('Ncm','404')); - wjson.AddPair(tjsonpair.Create('Cest_Codigo','404')); - wjson.AddPair(tjsonpair.Create('Embalagem','404')); - wjson.AddPair(tjsonpair.Create('QuantidadeEmbalagem','0')); - wjson.AddPair(tjsonpair.Create('Marca','404')); - wjson.AddPair(tjsonpair.Create('Categoria','404')); - wjson.AddPair(tjsonpair.Create('Peso','0')); - wjson.AddPair(tjsonpair.Create('id_categoria','0')); - wjson.AddPair(tjsonpair.Create('tributacao','404')); - Res.Send(wjson).Status(200);; - - inc(cont404); - mainview.memohistorico.lines.add(inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - finally - end; - end; - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Necessario enviar o codigo da mercadoria. Ex: www.eanpictures.com.br:9000/api/descricao/789789789789')); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - - finally - end; - end; - end); - //************ - - - Get('/api/desc_ini/:id', - procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) - var oini: tstringlist; - var wjson: tjsonobject; - begin - if Req.Params.Items['id'] <> '' then - begin - if mainview.MemoHistorico.lines.count > 10000 then - mainview.MemoHistorico.lines.clear; - - if basedados.fdConnection1.Connected= false then - basedados.fdConnection1.Connected:=true; - - - with BaseDados.fdquery1 do - begin - close; - sql.Clear; -// sql.Add('SELECT cad_produtos.ean, cad_produtos.nome, cad_produtos.peso,'); - sql.Add('SELECT cad_produtos.ean, cad_produtos.nome, '); - sql.Add('cad_produtos.ncm, cad_produtos.cest_codigo, cad_produtos.embalagem, cad_produtos.quantidade_embalagem,'); -// sql.Add('cad_produtos.marca, cad_produtos.categoria, cad_produtos.id_categoria, cad_produtos.tributacao'); -// sql.Add('cad_produtos.marca, cad_produtos.categoria, cad_produtos.id_categoria'); - sql.Add('cad_produtos.marca, cad_produtos.categoria'); - sql.Add(' FROM cad_produtos'); - sql.Add('where ean = :ean'); - parambyname('ean').AsString:=Req.Params.Items['id']; - open; - - if isempty = false then - begin - try - oini:=TStringList.Create; - oini.Add('[GENERAL]'); - oini.Add('Nome='+removeacento(fieldbyname('nome').asstring)); - oini.Add('Ncm='+removeacento(fieldbyname('ncm').asstring)); - oini.Add('Cest_Codigo='+removeacento(fieldbyname('cest_codigo').asstring)); - oini.Add('Embalagem='+removeacento(fieldbyname('embalagem').asstring)); - oini.Add('QuantidadeEmbalagem='+removeacento(fieldbyname('quantidade_embalagem').asstring)); - oini.Add('Marca='+removeacento(fieldbyname('marca').asstring)); - oini.Add('Categoria='+removeacento(fieldbyname('categoria').asstring)); - oini.Add('Peso='+''); -// oini.Add('id_categoria='+removeacento(fieldbyname('id_categoria').asstring)); - oini.Add('id_categoria='+''); -// oini.Add('tributacao'+removeacento(fieldbyname('tributacao').asstring)); - oini.Add('tributacao='+''); - Res.Send(oini.TEXT).Status(200); - - freeandnil(oini); - - inc(cont200); - mainview.memohistorico.lines.add(Req.RawWebRequest.RemoteAddr+' | '+inttostr(cont200)+'|'+datetostr(date)+'|'+timetostr(now)+'| Entregue INI: '+Req.Params.Items['id']+ '|' +fieldbyname('nome').asstring); - finally - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Descricao nao encontrada para o ean: '+Req.Params.Items['id'])); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - finally - end; - end; - end; - end - else - begin - try - wjson:=tjsonobject.Create; - wjson.AddPair(tjsonpair.Create('Status','404')); - wjson.AddPair(tjsonpair.Create('Status_Desc','Necessario enviar o codigo da mercadoria. Ex: www.eanpictures.com.br:9000/api/descricao/789789789789')); - Res.Send(wjson).Status(404);; - - inc(cont404); - mainview.memohistorico.lines.add(inttostr(cont404)+'|'+datetostr(date)+'|'+timetostr(now)+'| Descricao nao encontrada para o ean: '+Req.Params.Items['id']); - - finally - end; - end; - end); - //************ + FHorse.Get('/api/gtin/:id' , Gtin); + FHorse.Get('/api/fotoexiste/:id' , FotoExiste); + FHorse.Get('/api/fotoexistej/:id', FotoExisteJson); + FHorse.Get('/api/descricao/:id' , Descricao); + FHorse.Get('/api/desc/:id' , DescricaoJSon); + FHorse.Get('/api/desc200/:id' , DescricaoJSon200); + FHorse.Get('/api/desc_ini/:id' , DescricaoIni); + FHorse.Get('/api/um/:id' , UnidadeMedidaJSon); + FHorse.Get('/api/um2/:id' , UnidadeMedidaNome); - end; + FHorse.Get('/api/v2/gtin/:id' , V2Gtin); + FHorse.Get('/api/v2/um/' , V2UnidadeMedida); + FHorse.Get('/api/v2/um/:id' , V2UnidadeMedida); end; -constructor TWsHorse.Create; +Constructor TWsHorse.Create; begin - FHorse := THorse.Create; - with FHorse do - begin - Use(Jhonson); - Use(OctetStream); - Use(HandleException); - end; - AddMethods; -end; + FLog := nil; + FPath := ''; -function TWsHorse.Port(Value: Integer): TWsHorse; -begin - Result := Self; - FHorse.Port := Value; -end; + FHorse := THorse.Create; + FHorse.Use(Jhonson); + FHorse.Use(OctetStream); + FHorse.Use(HandleException); -function TWsHorse.Path(Value: String): TWsHorse; -begin - Result := Self; - FPath := Value; + AddMethods; end; -procedure TWsHorse.Power; +procedure TWsHorse.Descricao(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LID, S : String; + D : TDM; begin - if FHorse.IsRunning - then FHorse.StopListen - else FHorse.Listen; -end; + LID := TUtils.NumberOnly(Req.Params.Items['id']); + + If LID.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Necessario enviar o GTIN. Ex: www.eanpictures.com.br:9000/api/descricao/789789789789', + '| Descricao | Descricao nao encontrada para o ean: '+ LID); + Exit; + End; + + D := TDM.Create(nil); + Try + S := D.GetGTIN_Nome(TVersion.v01,LID); + If S.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Descricao nao encontrada para o ean: '+ LID, + '| Descricao | Descricao nao encontrada para o ean: '+ LID); + Exit; + End; + + Res.Send(S) + .Status(200); + + DoStatus(Req,Res,0,'200','','| Descricao | Entregue descricao: '+ LID +' | ' + S); + Finally + FreeAndNil(D); + End; +end; + +procedure TWsHorse.DescricaoIni(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LID : String; + O : TGTIN_01; + D : TDM; + S : TStringList; +begin + LID := TUtils.NumberOnly(Req.Params.Items['id']); + + If LID.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Necessario enviar o GTIN. Ex: www.eanpictures.com.br:9000/api/descricao/789789789789', + '| DescricaoJSon | Descricao nao encontrada para o ean: '+ LID); + Exit; + End; + + D := TDM.Create(nil); + Try + O := TGTIN_01( D.GetGTIN(TVersion.v01,LID) ); + Try + If O.GTIN.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Descricao nao encontrada para o ean: '+ LID, + '| DescricaoJSon | Descricao nao encontrada para o ean: '+ LID); + Exit; + End; + + S := TStringList.Create; + Try + S.Add('[GENERAL]'); + S.Add('Nome=' + O.Nome); + S.Add('Ncm=' + O.NCM); + S.Add('Cest_Codigo=' + O.CEST); + S.Add('Embalagem=' + O.Embalagem); + S.Add('QuantidadeEmbalagem=' + O.QuantidadeEmbalagem); + S.Add('Marca=' + O.Marca); + S.Add('Categoria=' + O.Categoria); + S.Add('Peso=' + O.Peso); + S.Add('id_categoria=' + O.Id_Categoria); + S.Add('tributacao=' + O.Tributacao); + + Res.Send(S.Text).Status(200); + Finally + FreeAndNil(S); + End; + + DoStatus(Req,Res,0,'200','','| DescricaoJSon | Entregue descricao: '+ LID +' | ' + O.Nome); + Finally + FreeAndNil(O); + End; + + Finally + FreeAndNil(D); + End; +end; + +procedure TWsHorse.DescricaoJSon(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LID : String; + O : TGTIN_01; + J : TJSONValue; + D : TDM; +begin + LID := TUtils.NumberOnly(Req.Params.Items['id']); + + If LID.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Necessario enviar o GTIN. Ex: www.eanpictures.com.br:9000/api/descricao/789789789789', + '| DescricaoJSon | Descricao nao encontrada para o ean: '+ LID); + Exit; + End; + + D := TDM.Create(nil); + Try + O := TGTIN_01( D.GetGTIN(TVersion.v01,LID) ); + Try + If O.GTIN.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Descricao nao encontrada para o ean: '+ LID, + '| DescricaoJSon | Descricao nao encontrada para o ean: '+ LID); + Exit; + End; + + J := TUtils.ToJSonValue(O); + Try + Res.Send(J).Status(200); + Finally + //FreeAndNil(J); //Horse-> Da o Free no Content + End; + + DoStatus(Req,Res,0,'200','','| DescricaoJSon | Entregue descricao: '+ LID +' | ' + O.Nome); + Finally + FreeAndNil(O); + End; + + Finally + FreeAndNil(D); + End; +end; + +procedure TWsHorse.DescricaoJSon200(Req: THorseRequest; Res: THorseResponse; Next: TProc); +begin + DescricaoJSon(Req, Res, Next); +end; + +destructor TWsHorse.Destroy; +begin + //FreeAndNil(FHorse); + inherited; +end; + +function TWsHorse.DoCount(Value: Boolean): Integer; +begin + If Value Then + Result := AtomicIncrement(Cont200) + Else + Result := AtomicIncrement(Cont404); +end; + +procedure TWsHorse.DoLog(Value: String); +begin + If Assigned(FLog) Then + FLog(Value); +end; + +procedure TWsHorse.FotoExiste(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LFile, LID : String; +begin + LID := TUtils.NumberOnly(Req.Params.Items['id']); + LFile := TDM.FilePhoto(LID); + If LFile.IsEmpty Then + begin + Res.Send('Nao') + .Status(200); -function twshorse.removeacento(const ptext: string):string; -type - usaascii20127 = type ansistring(20127); + DoStatus(Req,Res,0,'200','','| FotoExiste | Arquivo consultado (Nao): '+ LID); + + Exit; + End; + + Res.Send('Sim') + .Status(200); + + DoStatus(Req,Res,0,'200','','| FotoExiste | Arquivo consultado (Sim): '+ LID); +end; + +procedure TWsHorse.FotoExisteJson(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LFile, LID : String; +begin + LID := TUtils.NumberOnly(Req.Params.Items['id']); + LFile := TDM.FilePhoto(LID); + + If LFile.IsEmpty Then + DoStatus(Req,Res,200,'404','Foto encontrada (Nao): '+ LID,'| FotoExisteJson | Consulta arquivo (Nao): ') + Else + DoStatus(Req,Res,200,'200','Foto encontrada (Sim): '+ LID,'| FotoExisteJson | Consulta arquivo (Sim): '+ LFile); +end; + +procedure TWsHorse.Gtin(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LFile, LLink, LID : String; + LFileSend : TFileReturn; + LStream : TFileStream; begin - result:=string(usaascii20127(ptext)); + LID := TUtils.NumberOnly(Req.Params.Items['id']); + LFile := TDM.FilePhoto(LID); + + If LFile.IsEmpty Then + Begin + LFile := FPath + PATH_COSMOS + LID + '.png'; + + LLink := 'https://cdn-cosmos.bluesoft.com.br/products/' + ExtractFileName(LFile); + TUtils.DownloadFile(LLink, LFile); + DoLog('Download : '+ LFile +' | '+ LLink); + End; + + If not FileExists(LFile) Then + Begin + DoStatus(Req,Res,404,'404','','| Gtin | Arquivo nao encontrado: '+ LFile); + Exit; + End; + + LStream := TFileStream.Create(LFile, fmOpenRead); + Try + LFileSend := TFileReturn.Create( TPath.GetFileName(LFile), LStream, False); + Try + Res.Send(LFileSend) + .Status(200); + Finally + //FreeAndNil(LFileSend); //Horse-> Da o Free no Content + End; + + DoStatus(Req,Res,0,'200','','| Gtin | Upload : '+ LFile); + Finally + //FreeAndNil(LStream); //Horse-> Da o Free no Content + End; end; - -function twshorse.somentenumero(snum: string): string; -var s1, s2: string; - i: integer; + +function TWsHorse.Log(Value: TProc): TWsHorse; +begin + Result := Self; + FLog := Value; +end; + +function TWsHorse.Port(Value: Integer): TWsHorse; begin - s1 := snum; - s2 := ''; - for i := 1 to length(s1) do - if s1[i] in ['0' .. '9'] then - s2:=s2 + s1[i]; - result:=s2; + Result := Self; + FHorse.Port := Value; end; -procedure TWsHorse.baixacosmos(const ean: string); -var - Pasta: String; - i: Integer; - // - Client_: TNetHTTPClient; - lfile: string; +function TWsHorse.Path(Value: String): TWsHorse; begin - //nao rodou no windows server - LFile := FPath + 'Cosmos'+'\'+somentenumero(ean) + '.png'; - if directoryexists(FPath + 'Cosmos') = false then - CreateDir(FPath + 'Cosmos'); - - - begin - if EAN.Length > 0 then - if not FileExists(lfile) then - begin - Client_ := TNetHTTPClient.Create(nil); - Client_.Name := 'Client_'; - Client_.AcceptEncoding := 'raw'; - Client_.UserAgent := 'Embarcadero URI Client/1.0'; - Client_.SecureProtocols := [THTTPSecureProtocol.TLS12]; - // - TMemoryStream(IHTTPResponse(Client_.Get('https://cdn-cosmos.bluesoft.com.br/products/' + EAN)).ContentStream).SaveToFile(lfile); - // - Client_.Free; - - mainview.MemoHistorico.lines.ADD('******Baixado arquivo direto da cosmos: '+lfile+' | '+'https://cdn-cosmos.bluesoft.com.br/products/' + EAN); - - end; + Result := Self; + FPath := Value; - end; + If (not DirectoryExists(FPath + PATH_COSMOS)) Then + ForceDirectories(FPath + PATH_COSMOS); end; +procedure TWsHorse.Power; +begin + If FHorse.IsRunning Then + FHorse.StopListen + Else + FHorse.Listen; +end; +procedure TWsHorse.UnidadeMedidaJSon(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LID : String; + O : TUnid_01; + J : TJSONValue; + D : TDM; +begin + LID := TUtils.NumberOnly(Req.Params.Items['id']); + + If LID.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Necessario enviar o codigo da unidade de medida. Ex: www.eanpictures.com.br:9000/api/um/M3', + '| UnidadeMedidaNome | Descricao nao encontrada a unidade de medida: '+ LID); + Exit; + End; + + D := TDM.Create(nil); + Try + O := TUnid_01(D.GetGTIN_Unid_Med(TVersion.v01,LID)); + If not Assigned(O) Then + Begin + DoStatus(Req,Res,404,'404', + 'Descricao nao encontrada para a unidade de medida: '+ LID, + '| UnidadeMedidaNome | Descricao nao encontrada a unidade de medida: '+ LID); + Exit; + End; + + Try + J := TUtils.ToJSonValue(O); + Try + Res.Send(J).Status(200); + Finally + //FreeAndNil(J); //Horse-> Da o Free no Content + End; + + DoStatus(Req,Res,0,'200','','| UnidadeMedidaNome | Entregue descricao unidade medida: '+ LID + ' | ' + O.Nome); + Finally + FreeAndNil(O); + End; + Finally + FreeAndNil(D); + End; +end; + +procedure TWsHorse.UnidadeMedidaNome(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LID, S : String; + D : TDM; +begin + LID := TUtils.NumberOnly(Req.Params.Items['id']); + + If LID.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Necessario enviar o codigo da unidade de medida. Ex: www.eanpictures.com.br:9000/api/um/M3', + '| UnidadeMedidaNome | Descricao nao encontrada a unidade de medida: '+ LID); + Exit; + End; + + D := TDM.Create(nil); + Try + S := D.GetGTIN_Unid_Med_Nome(TVersion.v01,LID); + If S.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Descricao nao encontrada para a unidade de medida: '+ LID, + '| UnidadeMedidaNome | Descricao nao encontrada a unidade de medida: '+ LID); + Exit; + End; + + Res.Send(S) + .Status(200); + + DoStatus(Req,Res,0,'200','','| UnidadeMedidaNome | Entregue descricao unidade medida: '+ LID + ' | ' + S); + Finally + FreeAndNil(D); + End; +end; + +procedure TWsHorse.V2Gtin(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LID : String; + O : TGTIN_02; + J : TJSONValue; + D : TDM; +begin + LID := TUtils.NumberOnly(Req.Params.Items['id']); + + If LID.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Necessario enviar o GTIN. Ex: www.eanpictures.com.br:9000/api/v2/gtin/789789789789', + '| V2Gtin | GTIN : '+ LID); + Exit; + End; + + D := TDM.Create(nil).Path(FPath); + Try + O := TGTIN_02( D.GetGTIN(TVersion.v02,LID) ); + Try + If O.Code.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'GTIN nao encontrada para o ean: '+ LID, + '| V2Gtin | GTIN : '+ LID); + Exit; + End; + + J := TUtils.ToJSonValue(O); + Try + Res.Send(J).Status(200); + Finally + //FreeAndNil(J); //Horse-> Da o Free no Content + End; + + DoStatus(Req,Res,0,'200','','| V2Gtin | GTIN: '+ LID +' | ' + O.Description); + Finally + FreeAndNil(O); + End; + + Finally + FreeAndNil(D); + End; +end; + +procedure TWsHorse.V2UnidadeMedida(Req: THorseRequest; Res: THorseResponse; Next: TProc); +var LID : String; + I, O : TObject; + J : TJSONArray; + D : TDM; +begin + LID := ''; + If (Req.Params.Count <> 0) Then + LID := UpperCase(TUtils.AlphaOnly(Req.Params.Items['id'])); + + { + If LID.IsEmpty Then + Begin + DoStatus(Req,Res,404,'404', + 'Necessario enviar o codigo da unidade de medida. Ex: www.eanpictures.com.br:9000/api/um/M3', + '| UnidadeMedidaNome | Descricao nao encontrada a unidade de medida: '+ LID); + Exit; + End; + } + + D := TDM.Create(nil); + Try + O := D.GetGTIN_Unid_Med(TVersion.v02,LID); + { + If not Assigned(O) Then + Begin + DoStatus(Req,Res,404,'404', + 'Descricao nao encontrada para a unidade de medida: '+ LID, + '| UnidadeMedidaNome | Descricao nao encontrada a unidade de medida: '+ LID); + Exit; + End; + } + + Try + J := TJSONArray.Create; + If Assigned(O) Then + For I in TList(O) Do + J.Add(TJSONObject(TUtils.ToJSonValue(I))); + + Try + Res.Send(J).Status(200); + Finally + //FreeAndNil(J); //Horse-> Da o Free no Content + End; + + DoStatus(Req,Res,0,'200','','| UnidadeMedidaNome | Unidade de Medida: '+ LID); + Finally + If Assigned(O) Then + FreeAndNil(O); + End; + Finally + FreeAndNil(D); + End; +end; + +procedure TWsHorse.DoStatus(Req: THorseRequest; Res: THorseResponse; Status : Integer; MensStatus, Mens, MensLog : String); +var J : TJSONObject; + C : Integer; +Begin + C := DoCount(MensStatus = '200'); + DoLog(Req.RawWebRequest.RemoteAddr +' | '+ FormatFloat('000',C) +' '+ MensLog); + + If (Status <= 0) Then + Exit; + + J := TJSONObject.Create; + Try + J.AddPair('Status' ,MensStatus) + .AddPair('Status_Desc',Mens); + + Res.Send(J).Status(Status); + Finally + //FreeAndNil(J); //Horse-> Da o Free no Content + End; + end; + end.