Convert Basic to Ultimate & mklink images data

mklink /J "C:\Link To Folder" "C:\Users\Name\Original Folder"

Example:

mklink /J "D:\WORKSPACE\TIS.CPK.ULTIMATE\TIS.CPK.Resources\Data_Image" "D:\Data_Image\Data_Image"

To create junction link

Convert Cardtypes

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[CardTypes] ON;

INSERT INTO [TIS.CPK.ULTIMATE].[dbo].[CardTypes]
([Id]
      ,[Name]
      ,[Status]
      ,[ServiceId]
      ,[CreatedTime]
      ,[CreatedUser]
      ,[ModifiedTime]
      ,[ModifiedUser]
      ,[CompanyId]
      ,[SyncTime]
      ,[Uid]
      ,[Type]
      ,[CardTypeSap]
      ,[ProfilerRequire])

	  SELECT [Id]
      ,[Name]
      ,[Status]
      ,ID as [ServiceId]
      ,CreatedDate AS [CreatedTime]
      ,CreatedBy as [CreatedUser]
      ,UpdatedDate as [ModifiedTime]
      ,UpdatedBy as [ModifiedUser]
      ,1 as [CompanyId]
      ,getdate() as [SyncTime]
      ,newid() as [Uid]
      ,(case id
	  when 1 then 2
	  when 2 then 2
	  when 3 then 7
	  when 4 then 5
	  when 5 then 5
	  when 6 then 1
	  when 7 then 1
	  end) as Type
      ,NULL as [CardTypeSap]
      ,
	  (case id
		when 1 then 1
		when 2 then 0
		when 3 then 0
		when 4 then 1
		when 5 then 0
		when 6 then 1
		when 7 then 0
		end) as [ProfilerRequire]
	  FROM [CPK_V3].[dbo].[CardType]

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[CardTypes] OFF;

Convert Services

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[Services] ON;

INSERT INTO [TIS.CPK.ULTIMATE].[dbo].[Services] (
[Id]
      ,[Name]
      ,[Description]
      ,[Status]
      ,[ApplyToZoneId]
      ,[CreatedTime]
      ,[CreatedUser]
      ,[ModifiedTime]
      ,[ModifiedUser]
      ,[CompanyId]
      ,[SyncTime]
      ,[Uid])

	  SELECT [Id]
      ,[Name]
      ,name as [Description]
      ,[Status]
      ,NULL as [ApplyToZoneId]
      ,CreatedDate as [CreatedTime]
      ,CreatedBy as [CreatedUser]
      ,UpdatedDate as [ModifiedTime]
      ,UpdatedBy as [ModifiedUser]
      ,1 AS [CompanyId]
      ,getdate() as [SyncTime]
      ,newid() as [Uid]
FROM [CPK_V3].[dbo].[CardType]

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[Services] OFF;

Convert Cards

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[Cards] ON;

INSERT INTO [TIS.CPK.ULTIMATE].[dbo].[Cards] 
([CardTypeId]
      ,[CardNo]
      ,[CardSerial]
      ,[Status]
      ,[StartTime]
      ,[EndTime]
      ,[Note]
      ,[Mode]
      ,[CreatedTime]
      ,[CreatedUser]
      ,[ModifiedTime]
      ,[ModifiedUser]
      ,[CompanyId]
      ,[SyncTime]
      ,[Uid]
      ,[Hidden])

	  SELECT [CardTypeId]
      ,CardSerial as [CardNo]
      ,id as [CardSerial]
      ,[Status]
      ,NULL as [StartTime]
      ,NULL as [EndTime]
      ,'Converted From Basic' as [Note]
      ,1 as [Mode]
      ,CreatedDate as [CreatedTime]
      ,CreatedBy as [CreatedUser]
      ,UpdatedDate as [ModifiedTime]
      ,UpdatedBy as [ModifiedUser]
      ,1 as [CompanyId]
      ,getdate() as [SyncTime]
      ,newid() as [Uid]
      ,NULL as [Hidden]
	  FROM [CPK_V3].[dbo].[Card] where status<2

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[Cards] OFF;

Convert Customer Group

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[CustomerGroups] ON;

INSERT INTO [TIS.CPK.ULTIMATE].[dbo].[CustomerGroups]
([Id]
      ,[Name]
      ,[CompanyId]
      ,[ParentId]
      ,[Description]
      ,[CreatedTime]
      ,[CreatedUser]
      ,[ModifiedTime]
      ,[ModifiedUser])
SELECT [Id]
      ,[Name]
      ,1 as [CompanyId]
      ,0 as [ParentId]
      ,[Description]
      ,CreatedDate
      ,CreatedBy
      ,UpdatedDate
      ,UpdatedBy FROM [CPK_V3].[dbo].[ProfileType];

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[CustomerGroups] OFF;

Convert Customers

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[Customers] ON;

INSERT INTO [TIS.CPK.ULTIMATE].[dbo].[Customers]
([Id]
      ,[Name]
      ,[FullName]
      ,[Email]
      ,[Status]
      ,[Phone]
      ,[Address]
      ,[CreatedTime]
      ,[CreatedUser]
      ,[ModifiedTime]
      ,[ModifiedUser]
      ,[CompanyId]
      ,[SyncTime]
      ,[Uid]
      ,[CustomerGroupId]
      ,[ApartmentId]
      ,[ExtraId]
      ,[UserVinId])
	  	  
	  SELECT
	  [Id]
      ,[Name]
      ,[Name]
      ,NULL AS Email
      ,1 AS [Status]
      ,Telephone
      ,[Address]
      ,CreatedDate
      ,CreatedBy
      ,UpdatedDate
      ,UpdatedBy
      ,1 AS [CompanyId]
      ,getdate() AS [SyncTime]
      ,newid() AS [Uid]
      ,ProfileTypeID
      ,0 AS [ApartmentId]
      ,0 AS [ExtraId]
      ,NULL AS [UserVinId]
FROM [CPK_V3].[dbo].[Profile];

SET IDENTITY_INSERT [TIS.CPK.ULTIMATE].[dbo].[Customers] OFF;

Convert Transportations

INSERT INTO [TIS.CPK.ULTIMATE].[dbo].[Transportations]
		([CustomerId]
      ,[ZoneId]
      ,[CardId]
      ,[ServiceId]
      ,[Type]
      ,[LicensePlate]
      ,[Status]
      ,[Description]
      ,[StartTime]
      ,[EndTime]
      ,[CreatedTime]
      ,[CreatedUser]
      ,[ModifiedTime]
      ,[ModifiedUser]
      ,[CompanyId]
      ,[SyncTime]
      ,[Uid]
      ,[AutoPass]
      ,[CheckInOut]
      ,[Hidden]
      ,[CheckCharger]
      ,[StartTimeCharger]
      ,[EndTimeCharger]
      ,[UnitPrice])

SELECT a.ProfileID as [CustomerId]
      ,(case a.TransportTypeID
	  when 1 then 1
	  when 2 then 2
	  when 3 then 1
	  end)
	  AS [ZoneId]
      ,b.Id as [CardId]
      ,b.CardTypeId as [ServiceId]
      ,(case a.TransportTypeID
	  when 1 then 2
	  when 2 then 1
	  when 3 then 5
	  end)
	  AS [Type]
      ,a.CarNumber AS [LicensePlate]
      ,a.[Status]
      ,a.TransportLabel AS [Description]
      ,a.FromDate AS [StartTime]
      ,a.ToDate AS [EndTime]
      ,a.CreatedDate AS [CreatedTime]
      ,a.CreatedBy AS [CreatedUser]
      ,a.UpdatedDate AS [ModifiedTime]
      ,a.UpdatedBy AS [ModifiedUser]
      ,1 AS [CompanyId]
      ,getdate() AS [SyncTime]
      ,newid() AS [Uid]
      ,a.[AutoPass]
      ,0 as [CheckInOut]
      ,NULL AS [Hidden]
      ,0 AS [CheckCharger]
      ,NULL AS [StartTimeCharger]
      ,NULL AS [EndTimeCharger]
      ,NULL AS [UnitPrice] 
	   FROM [CPK_V3].[dbo].[Account] AS a INNER JOIN [TIS.CPK.ULTIMATE].[dbo].[Cards] AS b ON a.CardID=b.CardSerial
	   AND a.Status<2

	   /*
	   select * from TransportType;
  type : 2 XM
  1 OTO
  3 OTO_DIEN
  4 XM_DIEN
  5 XE DAP
  6 XDD
  */

Create Fn trimming special chars


/*
USE [CPK_V3]

CREATE FUNCTION dbo.RemoveSpecialCharacters( @str VARCHAR(MAX))
RETURNS VARCHAR(MAX) AS
BEGIN
DECLARE @expres  VARCHAR(max) = '%[^a-zA-Z0-9 ]%'

WHILE PATINDEX( @expres, @str ) > 0
SET @str = Replace(REPLACE( @str, SUBSTRING( @str, PATINDEX( @expres, @str ), 1 ),''),'-',' ')
RETURN @str
END

*/

Convert ServiceUsings

insert into [TIS.CPK.ULTIMATE].[dbo].[ServiceUsings] ([CardId]
      ,[CardTypeId]
      ,[ServiceId]
      ,[CustomerId]
      ,[LicensePlateIn]
      ,[LicensePlateOut]
      ,[LicensePlateFormatIn]
      ,[LicensePlateFormatOut]
      ,[TimeIn]
      ,[TimeOut]
      ,[ImageLicensePlateIn]
      ,[ImageLicensePlateOut]
      ,[ImageOverviewIn]
      ,[ImageOverviewOut]
      ,[TransportBrand]
      ,[DeviceIdIn]
      ,[DeviceIdOut]
      ,[ZoneIdIn]
      ,[ZoneIdOut]
      ,[Synchoronized]
      ,[NightCount]
      ,[Note]
      ,[CreatedTime]
      ,[CreatedUser]
      ,[ModifiedTime]
      ,[ModifiedUser]
      ,[CompanyId]
      ,[Uid]
      ,[LocalId]
      ,[SyncTime]
      ,[SyncZoneId]
      ,[SyncDeviceId]
      ,[ImageFaceIn]
      ,[ImageFaceOut]
      ,[Hidden])

SELECT  b.Id
      ,b.CardTypeId
      ,b.CardTypeId
      ,0
      ,a.CarNumber
      ,''
      ,dbo.RemoveSpecialCharacters(a.CarNumber)
      ,''
      ,a.DateIn
      ,a.DateIn
      ,'\'+a.PictureCarIn
      ,''
      ,'\'+a.PictureViewIn
      ,''
      ,0
      ,d.Id
      ,0
      ,
	  (case b.CardTypeId
		when 2 then 1
		when 5 then 1
		when 7 then 2
		end) as [ZoneIdIn]
      ,0
      ,0
      ,0
      ,''
      ,a.CreatedDate
      ,a.CreatedBy
      ,a.UpdatedDate
      ,a.UpdatedBy
      ,0
      ,newid()
      ,0
      ,a.CreatedDate
      ,
	  (case b.CardTypeId
		when 2 then 1
		when 5 then 1
		when 7 then 2
		end) as [SyncZoneId]
      ,0
      ,''
      ,''
      ,NULL
  FROM [CPK_V3].[dbo].[UsingCardDetail] as a inner join [TIS.CPK.ULTIMATE].[dbo].Cards as b on a.CardID=b.CardSerial
  inner join Computer as c on a.ComputerInID=c.ID
  inner join [TIS.CPK.ULTIMATE].dbo.Devices as d on c.Name=d.Name
    where InCarPark=1 and AccountID=0

Leave a Comment