unit uDAGuideWizardForm; {----------------------------------------------------------------------------} { Data Abstract Library - IDE Library { { compiler: Delphi 6 and up, Kylix 3 and up { platform: Win32, Linux { { (c)opyright RemObjects Software. all rights reserved. { { Using this code requires a valid license of the Data Abstract { which can be obtained at http://www.remobjects.com. {----------------------------------------------------------------------------} interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uROIDEPrjWizard, uEWWizard, StdCtrls, Buttons, ComCtrls, ExtCtrls; type TDAGuideWizardForm = class(TEWWizardForm) Label7: TLabel; Label8: TLabel; Label9: TLabel; Label10: TLabel; ts_SM: TTabSheet; ts_Compile: TTabSheet; ts_DataTables: TTabSheet; Label11: TLabel; Label12: TLabel; Label13: TLabel; lbl_SMLaunching: TLabel; Label15: TLabel; Label16: TLabel; Label17: TLabel; lbl_CompileBuilding: TLabel; Label19: TLabel; lbl_CompileClickNext: TLabel; lbl_CompileLaunching: TLabel; Label18: TLabel; Label20: TLabel; Label21: TLabel; lbl_DataTableClickNext: TLabel; ts_FinishMulti: TTabSheet; ts_FinishServer: TTabSheet; Label25: TLabel; Label26: TLabel; Label28: TLabel; lb_Link: TLabel; Label30: TLabel; Label31: TLabel; Label22: TLabel; Label23: TLabel; Label24: TLabel; lbl_SMClickNext: TLabel; procedure lb_LinkClick(Sender: TObject); private fNewProjectInfo: TROIDENewProjectInfo; fTempSchema, fTempConnections: string; protected procedure OnEnterPage(aPage:TTabSheet; aMovingForward:boolean); override; procedure OnLeavePage(aPage:TTabSheet; aMovingForward:boolean); override; public constructor Create(aNewProjectInfo: TROIDENewProjectInfo); reintroduce; destructor Destroy; override; end; var DAGuideWizardForm: TDAGuideWizardForm; implementation uses ShellAPI, uROIDETools, ToolsAPI, uROClasses, uDAIDEMenu, uDAClasses, uDAInterfaces, uDAEngine, uDARemoteDataAdapter, uDADataTableWizards; procedure OnNewProject(aNewProjectInfo: TROIDENewProjectInfo); begin if Pos('DAGuideWizard', aNewProjectInfo.Wizard) <> 1 then exit; //ShowMessage(Uppercase(aNewProjectInfo.TemplateName)); if not assigned(aNewProjectInfo.ClientProject) and (Uppercase(aNewProjectInfo.TemplateName) = 'LOCAL') then aNewProjectInfo.ClientProject := aNewProjectInfo.ServerProject; with TDAGuideWizardForm.Create(aNewProjectInfo) do try ShowModal(); finally Free; end; end; {$R *.dfm} { TTDAGuideWizardForm } constructor TDAGuideWizardForm.Create(aNewProjectInfo: TROIDENewProjectInfo); begin inherited Create(Application); fNewProjectInfo := aNewProjectInfo; fTempSchema := IncludeTrailingPathDelimiter(fNewProjectInfo.ProjectOptions.ProjectDir)+NewGuidAsString()+'.daSchema'; fTempConnections := ChangeFileExt(fTempSchema, '.daConnections'); end; destructor TDAGuideWizardForm.Destroy; begin if FileExists(fTempSchema) then DeleteFile(fTempSchema); if FileExists(fTempConnections) then DeleteFile(fTempConnections); inherited; end; procedure TDAGuideWizardForm.lb_LinkClick(Sender: TObject); begin inherited; ShellExecute(0, 'open', 'http://www.remobjects.com?da',nil, nil,SW_SHOWNORMAL); end; procedure TDAGuideWizardForm.OnEnterPage(aPage: TTabSheet; aMovingForward: boolean); begin inherited; btn_Back.Enabled := false; btn_Cancel.Visible := (aPage <> ts_FinishMulti) and (aPage <> ts_FinishServer); btn_Next.Visible := btn_Cancel.Visible; btn_Finish.Visible := not btn_Next.Visible; SetForegroundWindow(Self.Handle); end; function FindFormEditor(aModule: IOTAModule): IOTAFormEditor; var i: integer; lEditor: IOTAEditor; begin for i := 0 to aModule.ModuleFileCount-1 do begin lEditor := aModule.ModuleFileEditors[i]; if Supports(lEditor, IOTAFormEditor, result) then exit; end; end; function FindFormInProject(aProject: IOTAProject; aName: string): IOTAFormEditor; var i: integer; lModule: IOTAModule; begin for i := 0 to aProject.GetModuleCount-1 do begin if aProject.GetModule(i).Name = aName then begin lModule := aProject.GetModule(i).OpenModule(); result := FindFormEditor(lModule); exit; end end; raise Exception.Create('Could not locate '+aName+' module in project.'); end; function FindComponentOnForm(aForm: IOTAFormEditor; aName: string): TComponent; var lOTAComponent: IOTAComponent; begin lOTAComponent := aForm.FindComponent(aName); if not assigned(lOTAComponent) then raise Exception.Create('Could not locate '+aName+' component.'); result := (lOTAComponent as INTAComponent).GetComponent(); end; procedure TDAGuideWizardForm.OnLeavePage(aPage: TTabSheet; aMovingForward: boolean); var lSMParams: string; lServerDM, lService, lClientDM: IOTAFormEditor; lConnectionManager: TDAConnectionManager; lSchema: TDASchema; lRemoteDataAdapter: TDARemoteDataAdapter; begin inherited; try if (aPage = ts_SM) and aMovingForward then begin lbl_SMClickNext.Visible := false; lbl_SMLaunching.Visible := true; btn_Next.Enabled := false; Application.ProcessMessages(); // locate forms & components lServerDM := FindFormInProject(fNewProjectInfo.ServerProject, 'fServerDataModule'); lService := FindFormInProject(fNewProjectInfo.ServerProject, fNewProjectInfo.ProjectOptions.ServiceName+'_Impl'); lConnectionManager := FindComponentOnForm(lServerDM, 'ConnectionManager') as TDAConnectionManager; lSchema := FindComponentOnForm(lService, 'Schema') as TDASchema; // edit in SM lConnectionManager.SaveToFile(fTempConnections); lSchema.SaveToFile(fTempSchema); lSMParams := Format('/ns /autosave /projectname:"%s" /schemafile:"%s" /connectionsfile:"%s" /platform:Delphi /schemawizard', [fNewProjectInfo.ProjectOptions.ProjectName, fTempSchema, fTempConnections]); LaunchSchemaModeler(fNewProjectInfo.ProjectOptions.ProjectName, lSMParams, true); lConnectionManager.LoadFromFile(fTempConnections); lSchema.LoadFromFile(fTempSchema); lServerDM.MarkModified(); lService.MarkModified(); if not assigned(fNewProjectInfo.ClientProject) then NextPage := ts_FinishServer.PageIndex; //else if DAPackage.Package.DTE.Solution.Projects.Count > 2 then //fNextPage := pc_Pages.Pages.IndexOf(ts_FinishMultiProject); btn_Next.Enabled := true; end else if (aPage = ts_Compile) and aMovingForward then begin lbl_CompileClickNext.Visible := false; lbl_CompileBuilding.Visible := true; btn_Next.Enabled := false; Application.ProcessMessages(); if not fNewProjectInfo.ServerProject.ProjectBuilder.BuildProject(cmOTAMake, true, true) then raise Exception.Create('Failed to compile server project; please check error messages.'); lbl_CompileLaunching.Visible := true; Application.ProcessMessages(); ShellExecute(0, 'open', pchar(GetProjectExe(fNewProjectInfo.ServerProject)), nil, nil, SW_SHOWNORMAL); btn_Next.Enabled := false; end else if (aPage = ts_DataTables) and aMovingForward then begin lbl_DataTableClickNext.Visible := false; Application.ProcessMessages(); // locate forms & components lClientDM := FindFormInProject(fNewProjectInfo.ClientProject, 'fClientDataModule'); lRemoteDataAdapter := FindComponentOnForm(lClientDM, 'RemoteDataAdapter') as TDARemoteDataAdapter; lService := FindFormInProject(fNewProjectInfo.ServerProject, fNewProjectInfo.ProjectOptions.ServiceName+'_Impl'); lSchema := FindComponentOnForm(lService, 'Schema') as TDASchema; // create DTs lClientDM.Show(); TDataTableWizards.CreateDataTables(lClientDM, lRemoteDataAdapter, lSchema, Point(80,8)); lClientDM.MarkModified(); end; except Visible := false; ModalResult := mrCancel; raise; end; end; initialization RegisterGuideWizard(@OnNewProject); finalization UnregisterGuideWizard(@OnNewProject); end.