| 
					
				 | 
			
			
				@@ -3,8 +3,9 @@ unit rpgGatherData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 interface 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 uses 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  ADODB, ProjGather, rpgGatherProjDm, rpgBillsDm, rpgBillsCalcDm, Classes, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  ScAutoUpdateUnit, ProjGatherTree, GatherProjInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ADODB, Classes, ProjGather, ScAutoUpdateUnit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ProjGatherTree, GatherProjInfo, ProjGatherDealPay, ProjGatherProperties, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  rpgGatherProjDm, rpgBillsDm, rpgBillsCalcDm, rpgDealPayDm; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   TrpgGatherData = class 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -22,6 +23,12 @@ type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure SaveBillsProjCalc(ATree: TProjGatherTree; AProjIndex: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure SaveBillsSpecialProjCalc(ATree: TProjGatherTree; AProjType: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    procedure SaveDealPayGatherData(ADealPay: TProjGatherDealPayList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    procedure SaveDealPayProjData(ADealPay: TProjGatherDealPayList; AProjIndex: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    procedure SaveDealPaySpecialProjData(ADealPay: TProjGatherDealPayList; AProjType: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    procedure SaveGatherProjProperties(AProperties: TProjGatherProperties); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure CalcDgnData(const ATableName: string); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure CalcOtherData(AProjCount, ASProjCount: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -29,6 +36,7 @@ type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     function GetCacheProjFile(AProj: TGatherProjInfo): string; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure CopyBGLData(const AFileName: string; AProjIndex, AProjType: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    procedure CopyProjProperty(const AFileName: string; AProjIndex, AProjType: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     procedure CopyProjRelaGatherData(AProj: TGatherProjInfo; AProjIndex: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     function GetCurSpecialProjCount: Integer; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -63,14 +71,27 @@ var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   iProj: Integer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   AUpdater.AddTableDef(SGatherProj, @tdGatherProj, Length(tdGatherProj), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   AUpdater.AddTableDef(SBills, @tdBills, Length(tdBills), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   AUpdater.AddTableDef(SBills_Gather, @tdBills_Calc, Length(tdBills_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   for iProj := 0 to AProjCount - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     AUpdater.AddTableDef(SBills_Proj+IntToStr(iProj+1), @tdBills_Calc, Length(tdBills_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   AUpdater.AddTableDef(SBills_TransProj, @tdBills_Calc, Length(tdBills_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   for iProj := 0 to ASProjCount - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     AUpdater.AddTableDef(SBills_SProj+IntToStr(iProj+1), @tdBills_Calc, Length(tdBills_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   AUpdater.AddTableDef(SBGL_TransProj, @tdBGL_TransProj, Length(tdBGL_TransProj), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  AUpdater.AddTableDef(SDealPay_Gather, @tdDealPay_Calc, Length(tdDealPay_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  for iProj := 0 to AProjCount - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    AUpdater.AddTableDef(SDealPay_Proj+IntToStr(iProj+1), @tdDealPay_Calc, Length(tdDealPay_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  AUpdater.AddTableDef(SDealPay_TransProj, @tdDealPay_Calc, Length(tdDealPay_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  for iProj := 0 to ASProjCount - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    AUpdater.AddTableDef(SDealPay_SProj+IntToStr(iProj+1), @tdDealPay_Calc, Length(tdDealPay_Calc), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  AUpdater.AddTableDef(SProjProperties_TransProj, @tdProjProperties_TransProj, Length(tdProjProperties_TransProj), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  AUpdater.AddTableDef(SProjPropertied_Gather, @tdProjProperties_TransProj, Length(tdProjProperties_TransProj), False, False); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 procedure TrpgGatherData.CalcDgnData(const ATableName: string); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -146,6 +167,7 @@ begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   try 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     sTempFile := GetCacheProjFile(AProj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     CopyBGLData(sTempFile, AProjIndex, AProj.ProjType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    CopyProjProperty(sTempFile, AProjIndex, AProj.ProjType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   finally 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if FileExists(sTempFile) then 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       DeleteFile(sTempFile); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -295,17 +317,28 @@ var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   SaveGatherProjInfo(AGather.CommonProj, AGather.SpecialProj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   SaveBills(AGather.Tree); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   SaveBillsGatherCalc(AGather.Tree); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  SaveDealPayGatherData(AGather.DealPay); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  SaveGatherProjProperties(AGather.Properties); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   for iProj := 0 to AGather.CommonProj.Count - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     SaveBillsProjCalc(AGather.Tree, iProj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ExecuteSql(FConnection, Format(sInsert, [SBills_TransProj, SBills_Proj+IntToStr(iProj+1)])); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     CopyProjRelaGatherData(TGatherProjInfo(AGather.CommonProj.Items[iProj]), iProj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    SaveDealPayProjData(AGather.DealPay, iProj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ExecuteSql(FConnection, Format(sInsert, [SDealPay_TransProj, SDealPay_Proj+IntToStr(iProj+1)])); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   for iProj := 0 to AGather.Tree.SpecialProjCount - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    SaveBillsSpecialProjCalc(AGather.Tree, iProj+1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  for iProj := 0 to AGather.SpecialProj.Count - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    SaveBillsSpecialProjCalc(AGather.Tree, iProj+1);      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     CopyProjRelaGatherData(TGatherProjInfo(AGather.SpecialProj.Items[iProj]), -3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    SaveDealPaySpecialProjData(AGather.DealPay, iProj+1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 procedure TrpgGatherData.SaveGatherProjInfo(AProjs, ASProjs: TList); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -327,7 +360,10 @@ var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   iProj: Integer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   for iProj := 0 to AProjCount - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ExecuteSql(FConnection, Format(sInsert, [SBills_TransProj, SBills_Proj+IntToStr(iProj+1)])); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ExecuteSql(FConnection, Format(sInsert, [SDealPay_TransProj, SDealPay_Proj+IntToStr(iProj+1)])); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 procedure TrpgGatherData.UpdateDataBase(ASpecialProjTypes: TStrings); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -425,6 +461,7 @@ var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   for iProj := 0 to AGather.CommonProj.Count - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     CopyProjRelaGatherData(TGatherProjInfo(AGather.CommonProj.Items[iProj]), iProj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   for iProj := 0 to AGather.SpecialProj.Count - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     CopyProjRelaGatherData(TGatherProjInfo(AGather.SpecialProj.Items[iProj]), -3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -446,4 +483,72 @@ begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     vProjData.SaveTempDataBaseFile(Result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+procedure TrpgGatherData.SaveDealPayGatherData( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ADealPay: TProjGatherDealPayList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  vDealPayData: TrgpDealPayData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  vDealPayData := TrgpDealPayData.Create(FConnection); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  try 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    vDealPayData.SaveGatherDataTo(ADealPay, SDealPay_Gather); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  finally 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    vDealPayData.Free; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+procedure TrpgGatherData.SaveDealPayProjData( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ADealPay: TProjGatherDealPayList; AProjIndex: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  vDealPayData: TrgpDealPayData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  vDealPayData := TrgpDealPayData.Create(FConnection); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  try 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    vDealPayData.SaveProjDataTo(ADealPay, AProjIndex, SDealPay_Proj+IntToStr(AProjIndex+1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  finally 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    vDealPayData.Free; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+procedure TrpgGatherData.SaveDealPaySpecialProjData( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ADealPay: TProjGatherDealPayList; AProjType: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  vDealPayData: TrgpDealPayData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  vDealPayData := TrgpDealPayData.Create(FConnection); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  try 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    vDealPayData.SaveSpecialProjDataTo(ADealPay, AProjType, SDealPay_SProj+IntToStr(AProjType)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  finally 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    vDealPayData.Free; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+procedure TrpgGatherData.CopyProjProperty(const AFileName: string; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  AProjIndex, AProjType: Integer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  sCopy = 'Insert Into r_ProjProperties_TransProj' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          '  Select ID, %d As ProjID, %d As ProjType,' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          '    Name, PropValue' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          '  From ProjProperties In ''%s'''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ExecuteSql(FConnection, Format(sCopy, [AProjIndex, AProjType, AFileName])); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+procedure TrpgGatherData.SaveGatherProjProperties( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  AProperties: TProjGatherProperties); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  procedure SaveProperty(ID: Integer; AProperty: TProjGatherProperty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  const 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    sInsertSql = 'Insert Into r_ProjProperties_Gather (ID, ProjID, ProjType, Name, PropValue) ' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 '  Values (%d, -2, 0, ''%s'', ''%s'')'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ExecuteSql(FConnection, Format(sInsertSql, [ID, UpperCase(AProperty.Name), AProperty.Value])); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+var 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  i: Integer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+begin 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  for i := 0 to AProperties.Count - 1 do 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    SaveProperty(i, AProperties.PgProperty[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+end; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 end. 
			 |