Ir al contenido


Foto

trabajar sin conexion en aplicacion datasnap


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 giulichajari

giulichajari

    Advanced Member

  • Miembros
  • PipPipPip
  • 477 mensajes

Escrito 31 marzo 2015 - 10:03

Estoy realizando mi aplicacion cliente servidor, y el caso es que hice un state-less(por si no hay internet), en realidad una vez por dia al iniciar la aplicacion guardo un fichero xml de productos y otro de clientes (esto es solo un TPV), lo mismo con el ticket. Estos luego son enviados. Para lo mismo en el Source del .exe (ejecutable), primero creo el clientmodule que conecta al datasnap.

 

Trabajo con mysqlWorkbench y delphi. Pero tambien uso componenetes ZeosLib para traer datos, tengo entendido zeoslib accede directamente a la base de datos, es decir no tengo procedimientos en el server para cargar productos y clientes.

 

Entonces la aplciacion larga un cartel "trabajando sin conexion" y se abre el form sin problemas, amenos que el servicio de mysql (mysqld.exe) no este corriendo. entonces dice project1.exe ha detectado un problema y debe cerrarse.

 

En el source del exe:

 



php
  1. Application.Initialize;
  2.   Application.MainFormOnTaskbar := True;
  3.   TStyleManager.TrySetStyle('Iceberg Classico');
  4.  
  5.  
  6.   Application.CreateForm(TClientModule1, ClientModule1);
  7.   ScreenWidth:=screen.DesktopWidth;
  8.   ScreenHeight:=screen.DesktopHeight;
  9.   Application.CreateForm( TForm2, Form2);
  10.  // Unit9.ScaleForm(Form2,ScreenWidth, ScreenHeight);
  11.   Application.CreateForm(TForm1, Form1);
  12.   Application.CreateForm(TForm3, Form3);
  13.   Application.CreateForm(TForm4, Form4);
  14.  // Unit9.ScaleForm(Form4,ScreenWidth, ScreenHeight);
  15.   Application.CreateForm(TForm5, Form5);
  16.   Application.CreateForm(TCLIENTES, CLIENTES);
  17.   Application.CreateForm(TForm7, Form7);
  18.   Application.CreateForm(TForm8, Form8);
  19.   Application.Run;

y en el "OnCreate" del clientmodule(trato de conectar sino cargo los ultimos xml):


php
  1. procedure TClientModule1.DataModuleCreate(Sender: TObject);
  2.  
  3. var
  4. admin:TIniFile;
  5. nombre,destino,hoy,hoycli:string;
  6. i,x:integer;
  7. ultimo:string;
  8. fecha:TDateTime;
  9. begin
  10.  
  11. admin:=TIniFile.Create(ExtractFilePath(Application.ExeName )+ 'caja.ini');
  12. try
  13. with ClientModule1.SQLConnection1 do
  14. begin
  15. Close;
  16. Params.Values['DriverName']:=admin.ReadString('admin','DriverName','');
  17. Params.Values['HostName']:=admin.ReadString('admin','HostName','');
  18. Params.Values['Port']:=admin.ReadString('admin','Port','211');
  19.  
  20.  
  21. Connected:=True;
  22. end;
  23.  
  24. with ClientModule1.ZConnection1 do
  25. begin
  26.  
  27. Catalog := admin.ReadString('admintablas','Catalog','');
  28. Database := admin.ReadString('admintablas','Database','');
  29. HostName := admin.ReadString('admintablas','HostName','');
  30. Password := admin.ReadString('admintablas','Password','');
  31. Port := admin.ReadInteger('admintablas','Port',3306);
  32. Protocol := admin.ReadString('admintablas','Protocol','');
  33. User := admin.ReadString('admintablas','User','');
  34. Connected:=True;
  35.  
  36. end;
  37. begin
  38. for i := 0 to ComponentCount -1 do
  39. begin
  40. if Components[i] is TZTable then
  41.  
  42. TZTable(Components[i]).Active :=True;
  43.  
  44. end;
  45. for i := 0 to ComponentCount -1 do
  46. begin
  47. if Components[i] is TZQuery then
  48. TZQuery(Components[i]).Active :=True;
  49. end;
  50. end;
  51. if (ClientModule1.SQLConnection1.Connected) then
  52. begin
  53. hoy:=ExtractFilePath(Application.ExeName)+ 'productos'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
  54. hoycli:=ExtractFilePath(Application.ExeName)+ 'clientes'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
  55. if FileExists(hoy) then
  56. begin
  57. ShowMessage('datos ya copiados');
  58. else
  59. begin
  60. with ClientModule1.cdsprod do
  61. begin
  62. Active:=True;
  63. nombre:='productos'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
  64. destino:=ExtractFilePath(Application.ExeName) + nombre;
  65. ClientModule1.cdsprod.SaveToFile(destino,dfXMLUTF8);
  66.  
  67. end;
  68. end;
  69. if FileExists(hoycli) then
  70. begin
  71. ShowMessage('datos ya copiados');
  72. else
  73. begin
  74. with cdsclientes do
  75. begin
  76. Active:=True;
  77. nombre:='clientes'+FormatDateTime('dd-mm-yyyy',Now) + '.xml';
  78. destino:=ExtractFilePath(Application.ExeName) + nombre;
  79. ClientModule1.cdsclientes.SaveToFile(destino,dfXMLUTF8);
  80.  
  81. end;
  82. end;
  83.  
  84.  
  85. end;
  86. except
  87.  
  88. begin
  89.  
  90. if FileExists(hoy) then
  91. begin
  92. cdsprod.LoadFromFile(hoy);
  93. ShowMessage('archivo de hoy');
  94. else
  95. begin
  96. while not (FileExists(ultimo)) do
  97.  
  98. begin
  99. ultimo:=ExtractFilePath(Application.ExeName)+ 'productos'+ FormatDateTime('dd-mm-yyyy',IncDay(Now,x)) + '.xml';
  100. Dec(x);
  101. end;
  102. end;
  103. end;
  104. ShowMessage('trabajando sin conexion');
  105.  
  106. end;
  107.  
  108.  

Si es el servicio de mysql pueden ser los componentes zeos que de haber conexion los conecto?

 

 


  • 0




IP.Board spam blocked by CleanTalk.