unit P_impexp;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,p_module, Buttons, backup, FileCtrl, ComCtrls, RzButton,
  IvDictio, IvMulti, Mask, ToolEdit, DBTables, Db, AHMTLookupEdit,
  AHMTFolderLookup;

type
  Tf_impexp = class(TForm)
    Label1: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    l_file: TLabel;
    prog: TProgressBar;
    list: TListBox;
    Back: TBackupFile;
    BitBtn3: TBitBtn;
    IvTranslator1: TIvTranslator;
    fomcomp: TFilenameEdit;
    sourceitems: TQuery;
    bmitems: TBatchMove;
    destitems: TTable;
    sourceinv: TQuery;
    bminv: TBatchMove;
    destinv: TTable;
    fromdate: TDateEdit;
    todate: TDateEdit;
    fff: TAHMFolderLookup;
    Label2: TLabel;
    sourceitems2: TQuery;
    bmitems2: TBatchMove;
    destitems2: TTable;
    CheckBox1: TCheckBox;
    procedure BitBtn2Click(Sender: TObject);
    procedure BackProgress(Sender: TObject; Filename: String;
      Percent: TPercentage; var Continue: Boolean);
    procedure BitBtn3Click(Sender: TObject);
    procedure BackRestoreFile(Sender: TObject; var Filename: String;
      FA: Integer; var DoRestore: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_impexp: Tf_impexp;

implementation

uses p_posmodule;



{$R *.DFM}

procedure Tf_impexp.BitBtn2Click(Sender: TObject);
var s:string;
begin


   try
      mkdir(EXTRACTFILEPATH(application.ExeName) +'export');
   except
   end;
   try

   try

sourceinv.ParamByName('fromdate').asdate:=strtodate(fromdate.text);
sourceinv.ParamByName('todate').asdate:=strtodate(todate.text);
sourceitems.ParamByName('fromdate').asdate:=strtodate(fromdate.text);
sourceitems.ParamByName('todate').asdate:=strtodate(todate.text);

sourceitems2.ParamByName('fromdate').asdate:=strtodate(fromdate.text);
sourceitems2.ParamByName('todate').asdate:=strtodate(todate.text);

sourceinv.open;
sourceitems.open;
TRY
if CheckBox1.checked then
SOURCEITEMS2.OPEN;

EXCEPT
END;
bminv.Execute;

bmitems.Execute;
TRY
if CheckBox1.checked then
BMITEMS2.Execute;
EXCEPT
END;


except
end;
sourceinv.close;
sourceitems.close;
destinv.close;
destitems.close;
SOURCEITEMS2.CLOSE;


   list.Clear;

   list.Items.Add(EXTRACTFILEPATH(application.ExeName) +'export\*.db');


   back.Backup(list.Items,fff.Text+'\'+posmodule.CONFIGSSN.AsString+FormatDateTime('ddmmyyyy',date)+'.dsz');
  except
showmessage('Error to export..');
  end;
  prog.Position:=0;
showmessage('Export To File Is Done..');
try
posmodule.Free;
except
end;
application.Terminate;
  end;

procedure Tf_impexp.BackProgress(Sender: TObject; Filename: String;
  Percent: TPercentage; var Continue: Boolean);
begin
l_file.Caption:=filename;
prog.Position:=percent;
end;

procedure Tf_impexp.BitBtn3Click(Sender: TObject);
var s,s1:string;
begin

if  (trim(fomcomp.FileName)='') then
begin
showmessage('Import file incorrect!!!')     ;
exit;
end;



posmodule.stock.close;
posmodule.locstock.close;
try

posmodule.tosub.close;

except
end;

try
posmodule.tocomp.close;
except
end;

try
posmodule.tocontact.close;
except
end;

try
posmodule.tostock.close;
except
end;
try
posmodule.touser.close;
except
end;
try
posmodule.tocurr.close;

except
end;
try
posmodule.todescr.close;
except
end;

try
posmodule.tobar.close;
except
end;
try
deletefile('user_.db');
deletefile('user_.val');
except
end;

   s:=EXTRACTFILEPATH(application.ExeName);
  try


  {
   TRY
   mkdir(EXTRACTFILEPATH(application.ExeName)+'RESTORE\')
   EXCEPT
   END;
  }
   back.restore(fomcomp.FileName,s);


except
showmessage('Error to Import..');
  end;
  prog.Position:=0;
showmessage('Import from file Is Done..');

try
posmodule.Free;
except
end;
application.Terminate;


end;

procedure Tf_impexp.BackRestoreFile(Sender: TObject; var Filename: String;
  FA: Integer; var DoRestore: Boolean);
begin
l_file.Caption:=filename;
prog.Position:=fa;
end;

procedure Tf_impexp.FormCreate(Sender: TObject);
var ff:textfile;s,s2:string;
begin
fromdate.text:=datetostr(date-3);
todate.text:=datetostr(date);
try
assignfile(ff,extractfilepath(application.ExeName)+'dpath.txt');
reset(ff);
readln(ff,s);

closefile(ff);

fff.Text:=s;

except
end;




end;

end.
