Subject | RE: [IBO] Storing Office Documents in IB DBs; OT: Office Automation |
---|---|
Author | Laurent GILBERT |
Post date | 2001-05-28T13:42:51Z |
My unit :
unit u_gestion_planning_edit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
u_form_gen_niv_2, IB_Components, IB_TransactionSource, ComCtrls,
u_liste_forms,
StdCtrls, Buttons, Db, IBDataset, wwdbdatetimepicker, RzLabel, RzDBLbl,
Mask, DBCtrls, RzDBEdit, RzButton, RzRadChk, RzDBChk, OleServer,
Excel2000;
type
TFORM_GESTION_PLANNING_EDIT = class(TFORM_GEN_NIVEAU_2)
IBOQuery_PLANNING: TIBOQuery;
IBOQuery_PLANNINGTPLANNING_ID: TIntegerField;
IBOQuery_PLANNINGTPLANNING_DATE: TDateField;
IBOQuery_PLANNINGTPLANNING_NO: TIntegerField;
IBOQuery_PLANNINGTPLANNING_DATA: TBlobField;
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE: TSmallintField;
IBOQuery_PLANNINGTPLANNING_EN_ANGLAIS: TSmallintField;
IBOQuery_PLANNINGTPLANNING_NOM: TStringField;
DataSource_PLANNING: TDataSource;
RzDBEdit_NOM: TRzDBEdit;
Label1: TLabel;
Label2: TLabel;
RzDBLabel_NO: TRzDBLabel;
Label3: TLabel;
wwDBDateTimePicker_DATE: TwwDBDateTimePicker;
Label4: TLabel;
RzDBLabel_ID: TRzDBLabel;
RzDBCheckBox_EST_MODIFIABLE: TRzDBCheckBox;
RzDBCheckBox_EN_ANGLAIS: TRzDBCheckBox;
RzBitBtn_excel: TRzBitBtn;
RzBitBtn_verrouiller: TRzBitBtn;
procedure IB_TransactionSource_tsAfterAssignment(
Sender: TIB_TransactionLink; ATransaction: TIB_Transaction);
procedure RzBitBtn_excelClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure RzBitBtn_verrouillerClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Declarations privees }
ExcelApplication_excel: TExcelApplication;
ExcelWorkbook_doc: TExcelWorkbook;
ExcelWorksheet_config: TExcelWorksheet;
cBool_excel_actif : boolean;
cBool_classeur_actif : boolean;
cStr_fichier_en_cours : string;
cBool_classeur_modifie : boolean;
cBool_fermeture_en_cours : boolean;
procedure cproc_fin_excel;
procedure ExcelWorkbook_docBeforeClose(Sender: TObject; var Cancel:
OleVariant);
procedure ExcelWorkbook_docSheetChange(Sender: TObject; var Sh, Target:
OleVariant);
public
{ Declarations publiques }
procedure cproc_ouvrir_datasets; override;
function cfBool_datasets_modifies : boolean; override;
procedure cproc_valider_modifs; override;
procedure cproc_annuler_modifs; override;
end;
procedure pu_gestion_planning_edit_afficher(AOwner : TComponent;
vaListForms_clients_parent : TLIST_FORMS;
vaStr_titre : string; vaInt_cle : integer;
vaInt_groupe, vaInt_no_client : integer;
vaStr_id : string;
vaIBTransaction_t : TIB_Transaction;
vaBool_mode_edition, vaBool_mode_creation,
vaBool_cle_est_origine_dup : boolean);
implementation
{$R *.DFM}
uses
u_help, u_datamodule, u_ibenreg, u_ibdico, u_dboutils, u_init, u_sys,
RzLFName;
procedure pu_gestion_planning_edit_afficher(AOwner : TComponent;
vaListForms_clients_parent : TLIST_FORMS;
vaStr_titre : string; vaInt_cle : integer;
vaInt_groupe, vaInt_no_client : integer;
vaStr_id : string;
vaIBTransaction_t : TIB_Transaction;
vaBool_mode_edition, vaBool_mode_creation,
vaBool_cle_est_origine_dup : boolean);
var
vlForm_f : TFORM_GESTION_PLANNING_EDIT;
begin
if vaListForms_clients_parent.cfBool_montrer_si_existe_grpid(vaInt_groupe,
vaStr_id)
then
exit;
vlForm_f := TFORM_GESTION_PLANNING_EDIT.Create(AOwner,
vaListForms_clients_parent,
vaStr_titre, vaInt_cle,
vaInt_groupe, vaInt_no_client, vaStr_id,
CU_INT_HELP_IDH_FEN_GESTION_PLANNING_EDIT,
vaIBTransaction_t, vaBool_mode_edition,
vaBool_mode_creation, vaBool_cle_est_origine_dup);
with vlForm_f
do begin
Show;
end;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_ouvrir_datasets;
begin
Inherited;
with IBOQuery_PLANNING
do begin
datasource_planning.AutoEdit := cBool_mode_edition;
Active := false;
ReadOnly := not cBool_mode_edition;
Active := true;
if cBool_mode_creation
then begin
if cBool_cle_est_origine_dup
then begin
if locate('TPLANNING_ID', cVar_cle_enreg, []) = false
then
MessageDlg('Enregistrement non trouve !', mtError, [mbOk], 0);
pu_ibenreg_dupliquer(IBOQuery_PLANNING,
[tSetOpts_ibenreg_options_garder_defaut,
tSetOpts_ibenreg_options_copier_blob]);
end else begin
Append;
// On ne peut choisir la langue que lors de la creation
RzDBCheckBox_EN_ANGLAIS.ReadOnly := false;
RzDBCheckBox_EN_ANGLAIS.Color := clWindow;
IBOQuery_PLANNINGTPLANNING_EN_ANGLAIS.AsInteger := 0;
end;
IBOQuery_PLANNINGTPLANNING_DATE.AsDateTime := date;
IBOQuery_PLANNINGTPLANNING_NO.AsInteger := 1;
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger := 1;
end else begin
if VarType(cVar_cle_enreg) > VarNull
then
if locate('TPLANNING_ID', cVar_cle_enreg, []) = false
then
MessageDlg('Enregistrement non trouve !', mtError, [mbOk], 0);
// En mode edition, on doit creer un nouvel enreg si l'enreg
courant a ete verrouille
if cBool_mode_edition
then begin
if IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger = 0
then begin
// Il faut creer une nouvelle version
pu_ibenreg_dupliquer(IBOQuery_PLANNING,
[tSetOpts_ibenreg_options_garder_defaut,
tSetOpts_ibenreg_options_copier_blob]);
IBOQuery_PLANNINGTPLANNING_DATE.AsDateTime := date;
IBOQuery_PLANNINGTPLANNING_NO.AsInteger :=
IBOQuery_PLANNINGTPLANNING_NO.AsInteger + 1;
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger := 1;
// On ne peut pas modifier le nom du planning !!!
IBOQuery_PLANNINGTPLANNING_NOM.ReadOnly := true;
end;
edit;
end;
end;
end;
RzBitBtn_verrouiller.Enabled := cBool_mode_edition;
end;
function TFORM_GESTION_PLANNING_EDIT.cfBool_datasets_modifies : boolean;
begin
if cBool_mode_edition
then begin
IBOQuery_PLANNING.CheckBrowseMode;
Result := IBOQuery_PLANNING.UpdatesPending;
end else
Result := false;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_valider_modifs;
begin
pu_dboutils_saisie_obligatoire(IBOQuery_PLANNINGTPLANNING_NOM, 'le nom');
pu_ibenreg_valider_modifs(IBOQuery_PLANNING);
inherited;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_annuler_modifs;
begin
pu_ibenreg_annuler_modifs(IBOQuery_PLANNING);
inherited;
end;
procedure
TFORM_GESTION_PLANNING_EDIT.IB_TransactionSource_tsAfterAssignment(Sender:
TIB_TransactionLink; ATransaction: TIB_Transaction);
begin
inherited;
IBOQuery_PLANNING.IB_Transaction := ATransaction;
end;
procedure TFORM_GESTION_PLANNING_EDIT.RzBitBtn_excelClick(Sender: TObject);
var
vlStr_NomFichier : String;
vlOLEVar_ReadOnly : OLEVARIANT;
vlRange_r : Range;
begin
inherited;
// Generer un nom de fichier temporaire
vlStr_NomFichier :=
LongFNameFromShort(fuStr_sys_GenNomFichierTemp2('PLANNING','.XLS'));
// Si on est en mode edition et que le blob soit vide
if IBOQuery_PLANNINGTPLANNING_DATA.IsNull and not cBool_mode_edition
then begin
MessageDlg('Le planning n''a pas encore ete cree !', mtError, [mbOk],
0);
Exit;
end else if IBOQuery_PLANNINGTPLANNING_DATA.IsNull
then begin
if RzDBCheckBox_EN_ANGLAIS.Checked
then
pu_sys_CopierFichier(fuStr_init_RepFichier(CE_BASE_TYPEFICHIERS_PLANNING,
'planning_anglais.xls'),
vlStr_NomFichier, true)
else
pu_sys_CopierFichier(fuStr_init_RepFichier(CE_BASE_TYPEFICHIERS_PLANNING,
'planning.xls'),
vlStr_NomFichier, true);
end else begin
IBOQuery_PLANNINGTPLANNING_DATA.SaveToFile(vlStr_NomFichier);
end;
if cBool_mode_edition
then
vlOLEVar_ReadOnly := False
else
vlOLEVar_ReadOnly := True;
try
ExcelApplication_excel := TExcelApplication.Create(self);
with ExcelApplication_excel
do begin
AutoQuit := true;
Connect;
end;
except
MessageDlg('EXCEL n''est pas correctement installe !', mtError, [mbOk],
0);
DeleteFile(vlStr_NomFichier);
Abort;
end;
try
ExcelApplication_excel.Visible[GetUserDefaultLCID] := true;
ExcelApplication_excel.Workbooks.Open(vlStr_NomFichier, EmptyParam,
vlOLEVar_ReadOnly,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, GetUserDefaultLCID);
ExcelWorkbook_doc := TExcelWorkbook.Create(Self);
with ExcelWorkbook_doc
do begin
OnBeforeClose := ExcelWorkbook_docBeforeClose;
OnSheetChange := ExcelWorkbook_docSheetChange;
ConnectTo(ExcelApplication_excel.Workbooks[ExcelApplication_excel.ActiveWork
book.Name]);
end;
ExcelWorkbook_doc.RunAutoMacros(xlAutoOpen);
ExcelWorksheet_config := TExcelWorksheet.Create(Self);
ExcelWorksheet_config.ConnectTo(ExcelWorkbook_doc.Worksheets['CONFIG'] as
_Worksheet);
// Mise a jour de la configuration
with ExcelWorksheet_config
do begin
{FICHIER_BASE}
vlRange_r := Range['FICHIER_BASE', 'FICHIER_BASE'];
vlRange_r.Value := DataModule_GERES.cStr_CheminComplet_GERES;
{UTILISATEUR}
vlRange_r := Range['UTILISATEUR', 'UTILISATEUR'];
vlRange_r.Value := DataModule_GERES.cStr_NomUtilisateurIB;
{MOT_DE_PASSE}
vlRange_r := Range['MOT_DE_PASSE', 'MOT_DE_PASSE'];
vlRange_r.Value := DataModule_GERES.cStr_MotDePasseIB;
end;
// Les modifications de la feuille config ne doivent pas etre prise
pour une modification
// du classeur
ExcelWorkbook_doc.Saved[GetUserDefaultLCID] := true;
except
MessageDlg('Probleme d''acces au planning !', mtError, [mbOk], 0);
ExcelApplication_excel.disconnect;
DeleteFile(vlStr_NomFichier);
Abort;
end;
cBool_fermeture_en_cours := false;
cBool_classeur_modifie := false;
cBool_excel_actif := true;
cBool_classeur_actif := true;
cStr_fichier_en_cours := vlStr_NomFichier;
RzBitBtn_excel.Enabled := false;
end;
procedure TFORM_GESTION_PLANNING_EDIT.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
inherited;
// Si EXCEL pas active, on sort immediatement
if not cBool_excel_actif then exit;
cproc_fin_excel;
end;
procedure TFORM_GESTION_PLANNING_EDIT.ExcelWorkbook_docBeforeClose(Sender:
TObject; var Cancel: OleVariant);
begin
inherited;
cproc_fin_excel;
end;
procedure TFORM_GESTION_PLANNING_EDIT.ExcelWorkbook_docSheetChange(Sender:
TObject; var Sh, Target: OleVariant);
begin
inherited;
cBool_classeur_modifie := true;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_fin_excel;
begin
if cBool_fermeture_en_cours then exit;
// Si le classeur ou excel n'est pas actif, on sort
if not (cBool_excel_actif or cBool_classeur_actif) then exit;
cBool_fermeture_en_cours := true;
if cBool_classeur_actif
then begin
// Fermeture du classeur
try
ExcelWorkbook_doc.RunAutoMacros(xlAutoClose);
if cBool_mode_edition
then
ExcelWorkbook_doc.Save;
ExcelWorkbook_doc.close;
finally
ExcelWorkbook_doc.Disconnect;
ExcelWorkbook_doc.Free;
cBool_classeur_actif := false;
end;
end;
try
ExcelWorksheet_config.Disconnect;
// Sortie d'EXCEL
ExcelApplication_excel.disconnect;
finally
ExcelWorksheet_config.free;
ExcelApplication_excel.free;
cBool_excel_actif := false;
RzBitBtn_excel.Enabled := true;
end;
try
// Importation du fichier si necessaire
if cBool_mode_edition and cBool_classeur_modifie
then begin
Application.BringToFront;
// On demande la confirmation
if MessageDlg('Voulez-vous importer dans GERES le planning ?',
mtConfirmation,
[mbYes, mbNo], 0) = mrYes
then begin
IBOQuery_PLANNINGTPLANNING_DATA.LoadFromFile(cStr_fichier_en_cours);
end;
end;
finally
cBool_classeur_modifie := false;
// Suppression du fichier temporaire
DeleteFile(cStr_fichier_en_cours);
end;
end;
procedure TFORM_GESTION_PLANNING_EDIT.RzBitBtn_verrouillerClick(Sender:
TObject);
begin
inherited;
// On ne peut plus desactiver
if (not cBool_mode_edition) and
(IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger = 0) then Exit;
// Il faut pas avoir le classeur en edition !
if cBool_classeur_actif
then begin
MessageDlg('Classeur en cours d''edition !'#10#10 + 'Verrouillage
impossible...',
mtError, [mbOk], 0);
Exit;
end;
// On doit avoir un blob
if IBOQuery_PLANNINGTPLANNING_DATA.IsNull
then begin
MessageDlg('Mise en version interdite ! Le planning n''est pas defini...',
mtError, [mbOk], 0);
Exit;
end;
// On demande la confirmation
if MessageDlg('Etes-vous sur de vouloir verrouiller ce planning ?',
mtConfirmation, [mbYes, mbNo], 0) = mrNo then Exit;
// Planning verrouiller
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger := 0;
BitBtn_AppliquerClick(BitBtn_Appliquer);
end;
procedure TFORM_GESTION_PLANNING_EDIT.FormCloseQuery(Sender: TObject; var
CanClose: Boolean);
begin
if not cBool_excel_actif
then
CanClose := true
else begin
if MessageDlg('EXCEL n''est pas ferme !'#10#10 +
'Etes-vous sur de vouloir continuer ?', mtConfirmation, [mbYes,
mbNo], 0) = mrNo
then begin
CanClose := false;
Exit;
end else
CanClose := true;
end;
inherited;
end;
end.
unit u_gestion_planning_edit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
u_form_gen_niv_2, IB_Components, IB_TransactionSource, ComCtrls,
u_liste_forms,
StdCtrls, Buttons, Db, IBDataset, wwdbdatetimepicker, RzLabel, RzDBLbl,
Mask, DBCtrls, RzDBEdit, RzButton, RzRadChk, RzDBChk, OleServer,
Excel2000;
type
TFORM_GESTION_PLANNING_EDIT = class(TFORM_GEN_NIVEAU_2)
IBOQuery_PLANNING: TIBOQuery;
IBOQuery_PLANNINGTPLANNING_ID: TIntegerField;
IBOQuery_PLANNINGTPLANNING_DATE: TDateField;
IBOQuery_PLANNINGTPLANNING_NO: TIntegerField;
IBOQuery_PLANNINGTPLANNING_DATA: TBlobField;
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE: TSmallintField;
IBOQuery_PLANNINGTPLANNING_EN_ANGLAIS: TSmallintField;
IBOQuery_PLANNINGTPLANNING_NOM: TStringField;
DataSource_PLANNING: TDataSource;
RzDBEdit_NOM: TRzDBEdit;
Label1: TLabel;
Label2: TLabel;
RzDBLabel_NO: TRzDBLabel;
Label3: TLabel;
wwDBDateTimePicker_DATE: TwwDBDateTimePicker;
Label4: TLabel;
RzDBLabel_ID: TRzDBLabel;
RzDBCheckBox_EST_MODIFIABLE: TRzDBCheckBox;
RzDBCheckBox_EN_ANGLAIS: TRzDBCheckBox;
RzBitBtn_excel: TRzBitBtn;
RzBitBtn_verrouiller: TRzBitBtn;
procedure IB_TransactionSource_tsAfterAssignment(
Sender: TIB_TransactionLink; ATransaction: TIB_Transaction);
procedure RzBitBtn_excelClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure RzBitBtn_verrouillerClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Declarations privees }
ExcelApplication_excel: TExcelApplication;
ExcelWorkbook_doc: TExcelWorkbook;
ExcelWorksheet_config: TExcelWorksheet;
cBool_excel_actif : boolean;
cBool_classeur_actif : boolean;
cStr_fichier_en_cours : string;
cBool_classeur_modifie : boolean;
cBool_fermeture_en_cours : boolean;
procedure cproc_fin_excel;
procedure ExcelWorkbook_docBeforeClose(Sender: TObject; var Cancel:
OleVariant);
procedure ExcelWorkbook_docSheetChange(Sender: TObject; var Sh, Target:
OleVariant);
public
{ Declarations publiques }
procedure cproc_ouvrir_datasets; override;
function cfBool_datasets_modifies : boolean; override;
procedure cproc_valider_modifs; override;
procedure cproc_annuler_modifs; override;
end;
procedure pu_gestion_planning_edit_afficher(AOwner : TComponent;
vaListForms_clients_parent : TLIST_FORMS;
vaStr_titre : string; vaInt_cle : integer;
vaInt_groupe, vaInt_no_client : integer;
vaStr_id : string;
vaIBTransaction_t : TIB_Transaction;
vaBool_mode_edition, vaBool_mode_creation,
vaBool_cle_est_origine_dup : boolean);
implementation
{$R *.DFM}
uses
u_help, u_datamodule, u_ibenreg, u_ibdico, u_dboutils, u_init, u_sys,
RzLFName;
procedure pu_gestion_planning_edit_afficher(AOwner : TComponent;
vaListForms_clients_parent : TLIST_FORMS;
vaStr_titre : string; vaInt_cle : integer;
vaInt_groupe, vaInt_no_client : integer;
vaStr_id : string;
vaIBTransaction_t : TIB_Transaction;
vaBool_mode_edition, vaBool_mode_creation,
vaBool_cle_est_origine_dup : boolean);
var
vlForm_f : TFORM_GESTION_PLANNING_EDIT;
begin
if vaListForms_clients_parent.cfBool_montrer_si_existe_grpid(vaInt_groupe,
vaStr_id)
then
exit;
vlForm_f := TFORM_GESTION_PLANNING_EDIT.Create(AOwner,
vaListForms_clients_parent,
vaStr_titre, vaInt_cle,
vaInt_groupe, vaInt_no_client, vaStr_id,
CU_INT_HELP_IDH_FEN_GESTION_PLANNING_EDIT,
vaIBTransaction_t, vaBool_mode_edition,
vaBool_mode_creation, vaBool_cle_est_origine_dup);
with vlForm_f
do begin
Show;
end;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_ouvrir_datasets;
begin
Inherited;
with IBOQuery_PLANNING
do begin
datasource_planning.AutoEdit := cBool_mode_edition;
Active := false;
ReadOnly := not cBool_mode_edition;
Active := true;
if cBool_mode_creation
then begin
if cBool_cle_est_origine_dup
then begin
if locate('TPLANNING_ID', cVar_cle_enreg, []) = false
then
MessageDlg('Enregistrement non trouve !', mtError, [mbOk], 0);
pu_ibenreg_dupliquer(IBOQuery_PLANNING,
[tSetOpts_ibenreg_options_garder_defaut,
tSetOpts_ibenreg_options_copier_blob]);
end else begin
Append;
// On ne peut choisir la langue que lors de la creation
RzDBCheckBox_EN_ANGLAIS.ReadOnly := false;
RzDBCheckBox_EN_ANGLAIS.Color := clWindow;
IBOQuery_PLANNINGTPLANNING_EN_ANGLAIS.AsInteger := 0;
end;
IBOQuery_PLANNINGTPLANNING_DATE.AsDateTime := date;
IBOQuery_PLANNINGTPLANNING_NO.AsInteger := 1;
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger := 1;
end else begin
if VarType(cVar_cle_enreg) > VarNull
then
if locate('TPLANNING_ID', cVar_cle_enreg, []) = false
then
MessageDlg('Enregistrement non trouve !', mtError, [mbOk], 0);
// En mode edition, on doit creer un nouvel enreg si l'enreg
courant a ete verrouille
if cBool_mode_edition
then begin
if IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger = 0
then begin
// Il faut creer une nouvelle version
pu_ibenreg_dupliquer(IBOQuery_PLANNING,
[tSetOpts_ibenreg_options_garder_defaut,
tSetOpts_ibenreg_options_copier_blob]);
IBOQuery_PLANNINGTPLANNING_DATE.AsDateTime := date;
IBOQuery_PLANNINGTPLANNING_NO.AsInteger :=
IBOQuery_PLANNINGTPLANNING_NO.AsInteger + 1;
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger := 1;
// On ne peut pas modifier le nom du planning !!!
IBOQuery_PLANNINGTPLANNING_NOM.ReadOnly := true;
end;
edit;
end;
end;
end;
RzBitBtn_verrouiller.Enabled := cBool_mode_edition;
end;
function TFORM_GESTION_PLANNING_EDIT.cfBool_datasets_modifies : boolean;
begin
if cBool_mode_edition
then begin
IBOQuery_PLANNING.CheckBrowseMode;
Result := IBOQuery_PLANNING.UpdatesPending;
end else
Result := false;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_valider_modifs;
begin
pu_dboutils_saisie_obligatoire(IBOQuery_PLANNINGTPLANNING_NOM, 'le nom');
pu_ibenreg_valider_modifs(IBOQuery_PLANNING);
inherited;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_annuler_modifs;
begin
pu_ibenreg_annuler_modifs(IBOQuery_PLANNING);
inherited;
end;
procedure
TFORM_GESTION_PLANNING_EDIT.IB_TransactionSource_tsAfterAssignment(Sender:
TIB_TransactionLink; ATransaction: TIB_Transaction);
begin
inherited;
IBOQuery_PLANNING.IB_Transaction := ATransaction;
end;
procedure TFORM_GESTION_PLANNING_EDIT.RzBitBtn_excelClick(Sender: TObject);
var
vlStr_NomFichier : String;
vlOLEVar_ReadOnly : OLEVARIANT;
vlRange_r : Range;
begin
inherited;
// Generer un nom de fichier temporaire
vlStr_NomFichier :=
LongFNameFromShort(fuStr_sys_GenNomFichierTemp2('PLANNING','.XLS'));
// Si on est en mode edition et que le blob soit vide
if IBOQuery_PLANNINGTPLANNING_DATA.IsNull and not cBool_mode_edition
then begin
MessageDlg('Le planning n''a pas encore ete cree !', mtError, [mbOk],
0);
Exit;
end else if IBOQuery_PLANNINGTPLANNING_DATA.IsNull
then begin
if RzDBCheckBox_EN_ANGLAIS.Checked
then
pu_sys_CopierFichier(fuStr_init_RepFichier(CE_BASE_TYPEFICHIERS_PLANNING,
'planning_anglais.xls'),
vlStr_NomFichier, true)
else
pu_sys_CopierFichier(fuStr_init_RepFichier(CE_BASE_TYPEFICHIERS_PLANNING,
'planning.xls'),
vlStr_NomFichier, true);
end else begin
IBOQuery_PLANNINGTPLANNING_DATA.SaveToFile(vlStr_NomFichier);
end;
if cBool_mode_edition
then
vlOLEVar_ReadOnly := False
else
vlOLEVar_ReadOnly := True;
try
ExcelApplication_excel := TExcelApplication.Create(self);
with ExcelApplication_excel
do begin
AutoQuit := true;
Connect;
end;
except
MessageDlg('EXCEL n''est pas correctement installe !', mtError, [mbOk],
0);
DeleteFile(vlStr_NomFichier);
Abort;
end;
try
ExcelApplication_excel.Visible[GetUserDefaultLCID] := true;
ExcelApplication_excel.Workbooks.Open(vlStr_NomFichier, EmptyParam,
vlOLEVar_ReadOnly,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, GetUserDefaultLCID);
ExcelWorkbook_doc := TExcelWorkbook.Create(Self);
with ExcelWorkbook_doc
do begin
OnBeforeClose := ExcelWorkbook_docBeforeClose;
OnSheetChange := ExcelWorkbook_docSheetChange;
ConnectTo(ExcelApplication_excel.Workbooks[ExcelApplication_excel.ActiveWork
book.Name]);
end;
ExcelWorkbook_doc.RunAutoMacros(xlAutoOpen);
ExcelWorksheet_config := TExcelWorksheet.Create(Self);
ExcelWorksheet_config.ConnectTo(ExcelWorkbook_doc.Worksheets['CONFIG'] as
_Worksheet);
// Mise a jour de la configuration
with ExcelWorksheet_config
do begin
{FICHIER_BASE}
vlRange_r := Range['FICHIER_BASE', 'FICHIER_BASE'];
vlRange_r.Value := DataModule_GERES.cStr_CheminComplet_GERES;
{UTILISATEUR}
vlRange_r := Range['UTILISATEUR', 'UTILISATEUR'];
vlRange_r.Value := DataModule_GERES.cStr_NomUtilisateurIB;
{MOT_DE_PASSE}
vlRange_r := Range['MOT_DE_PASSE', 'MOT_DE_PASSE'];
vlRange_r.Value := DataModule_GERES.cStr_MotDePasseIB;
end;
// Les modifications de la feuille config ne doivent pas etre prise
pour une modification
// du classeur
ExcelWorkbook_doc.Saved[GetUserDefaultLCID] := true;
except
MessageDlg('Probleme d''acces au planning !', mtError, [mbOk], 0);
ExcelApplication_excel.disconnect;
DeleteFile(vlStr_NomFichier);
Abort;
end;
cBool_fermeture_en_cours := false;
cBool_classeur_modifie := false;
cBool_excel_actif := true;
cBool_classeur_actif := true;
cStr_fichier_en_cours := vlStr_NomFichier;
RzBitBtn_excel.Enabled := false;
end;
procedure TFORM_GESTION_PLANNING_EDIT.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
inherited;
// Si EXCEL pas active, on sort immediatement
if not cBool_excel_actif then exit;
cproc_fin_excel;
end;
procedure TFORM_GESTION_PLANNING_EDIT.ExcelWorkbook_docBeforeClose(Sender:
TObject; var Cancel: OleVariant);
begin
inherited;
cproc_fin_excel;
end;
procedure TFORM_GESTION_PLANNING_EDIT.ExcelWorkbook_docSheetChange(Sender:
TObject; var Sh, Target: OleVariant);
begin
inherited;
cBool_classeur_modifie := true;
end;
procedure TFORM_GESTION_PLANNING_EDIT.cproc_fin_excel;
begin
if cBool_fermeture_en_cours then exit;
// Si le classeur ou excel n'est pas actif, on sort
if not (cBool_excel_actif or cBool_classeur_actif) then exit;
cBool_fermeture_en_cours := true;
if cBool_classeur_actif
then begin
// Fermeture du classeur
try
ExcelWorkbook_doc.RunAutoMacros(xlAutoClose);
if cBool_mode_edition
then
ExcelWorkbook_doc.Save;
ExcelWorkbook_doc.close;
finally
ExcelWorkbook_doc.Disconnect;
ExcelWorkbook_doc.Free;
cBool_classeur_actif := false;
end;
end;
try
ExcelWorksheet_config.Disconnect;
// Sortie d'EXCEL
ExcelApplication_excel.disconnect;
finally
ExcelWorksheet_config.free;
ExcelApplication_excel.free;
cBool_excel_actif := false;
RzBitBtn_excel.Enabled := true;
end;
try
// Importation du fichier si necessaire
if cBool_mode_edition and cBool_classeur_modifie
then begin
Application.BringToFront;
// On demande la confirmation
if MessageDlg('Voulez-vous importer dans GERES le planning ?',
mtConfirmation,
[mbYes, mbNo], 0) = mrYes
then begin
IBOQuery_PLANNINGTPLANNING_DATA.LoadFromFile(cStr_fichier_en_cours);
end;
end;
finally
cBool_classeur_modifie := false;
// Suppression du fichier temporaire
DeleteFile(cStr_fichier_en_cours);
end;
end;
procedure TFORM_GESTION_PLANNING_EDIT.RzBitBtn_verrouillerClick(Sender:
TObject);
begin
inherited;
// On ne peut plus desactiver
if (not cBool_mode_edition) and
(IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger = 0) then Exit;
// Il faut pas avoir le classeur en edition !
if cBool_classeur_actif
then begin
MessageDlg('Classeur en cours d''edition !'#10#10 + 'Verrouillage
impossible...',
mtError, [mbOk], 0);
Exit;
end;
// On doit avoir un blob
if IBOQuery_PLANNINGTPLANNING_DATA.IsNull
then begin
MessageDlg('Mise en version interdite ! Le planning n''est pas defini...',
mtError, [mbOk], 0);
Exit;
end;
// On demande la confirmation
if MessageDlg('Etes-vous sur de vouloir verrouiller ce planning ?',
mtConfirmation, [mbYes, mbNo], 0) = mrNo then Exit;
// Planning verrouiller
IBOQuery_PLANNINGTPLANNING_EST_MODIFIABLE.AsInteger := 0;
BitBtn_AppliquerClick(BitBtn_Appliquer);
end;
procedure TFORM_GESTION_PLANNING_EDIT.FormCloseQuery(Sender: TObject; var
CanClose: Boolean);
begin
if not cBool_excel_actif
then
CanClose := true
else begin
if MessageDlg('EXCEL n''est pas ferme !'#10#10 +
'Etes-vous sur de vouloir continuer ?', mtConfirmation, [mbYes,
mbNo], 0) = mrNo
then begin
CanClose := false;
Exit;
end else
CanClose := true;
end;
inherited;
end;
end.
> -----Message d'origine-----
> De : Laurent GILBERT [mailto:laurent.gilbert@...]
> Envoye : lun. 28 mai 2001 09:02
> A : IBObjects@yahoogroups.com
> Objet : RE: [IBO] Storing Office Documents in IB DBs; OT: Office
> Automation
> Importance : Haute
>
>
> Hi,
>
> I've just done this with EXCEL 2000.
> I join my unit which opens an EXCEL file, sets some
> configuration cells and
> runs auto macros (VBA code to access IB DATABASE).
>
> Sorry but it's in french.
>
> Bye.
>
> Laurent GILBERT.
>
> > -----Message d'origine-----
> > De : Christian Gutter [mailto:cguetter@...]
> > Envoye : ven. 25 mai 2001 18:52
> > A : 'ibobjects@yahoogroups.com'
> > Objet : [IBO] Storing Office Documents in IB DBs; OT: Office
> > Automation
> >
> >
> > Hi,
> >
> > since December 2000, my company uses an application based
> > on IB/IBO which the users (and me, too) are very satisfied
> > with.
> >
> > For the next major version, I plan to implement a feature
> > that enables the users to store word/excel docs in the
> > DB.
> > It should not just be
> > - save to disk
> > - store as blob in DB.
> >
> > It should be somehow like this:
> > - user opens my app
> > - clicks "create invoice" in my app
> > - my app opens a new window with Microsoft Word in it
> > - my app does some automation like inserting articles,
> > prices, adress, etc.
> > - when the user has finished, the doc is saved to the DB.
> >
> > Unfortunately, I have no idea how to do this.
> > I have look around in the internet for a while and found
> > some pointers, but I think there are some people here who
> > have already done this and perhaps some of them could give
> > some more valuable information :-)
> >
> > Generally, I would like to know:
> > - how to call word etc. as a "child" of my application - some
> > pointers to OLE or whatever
> > - how to use IBO to save the results of the word session (= a
> > document)
> > in the database
> > - some pointers to good howtos about office automation, hints, etc.
> >
> > I know that some of the above points do not really refer to IBO -
> > so if some of your answers get too much OT feel free to e-mail me
> > privately.
> >
> > One more information: I use Delphi4 C/S , IBO 3.6 and Office 2000.
> >
> >
> > TIA for your answers.
> >
> >
> > Christian
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/
> >
> >
> >
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>