unit UCrearPlano;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBCtrls, Grids, DBGrids, StdCtrls, Buttons, SPBBC, ExtCtrls, DB,
IBCustomDataSet, IBQuery, ExtDlgs, Clipbrd, SBTPV, UCCDBaseComp,
UCCDSelectOnRunTime, Mneweditjl, NewSpinEdit, IniFiles;
type
TFCrearPlano = class(TForm)
Panel2: TPanel;
Imagen: TImage;
Panel3: TPanel;
Panel1: TPanel;
ButSalir: TSpeedButtonBC;
Label1: TLabel;
ButCargarImagenLibre: TSpeedButtonBC;
Label2: TLabel;
ButSeleccionarPlano: TSpeedButtonBC;
ButCrearElemento: TSpeedButtonBC;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
DBNavigator1: TDBNavigator;
DSSituacion: TDataSource;
DBNavigator2: TDBNavigator;
DSUbicacion: TDataSource;
IBQUbicacion: TIBQuery;
OpenPictureDialog1: TOpenPictureDialog;
SpeedButtonTPV1: TSpeedButtonTPV;
ButBajar: TSpeedButtonBC;
ButSubir: TSpeedButtonBC;
ButDerecha: TSpeedButtonBC;
ButIzquierda: TSpeedButtonBC;
Saltos: TNewSpinEdit;
DsTipo: TDataSource;
DBImage1: TDBImage;
ButCrearTodosLosElementos: TSpeedButtonBC;
ButDestruirElemento: TSpeedButtonBC;
TamanoButon: TNewSpinEdit;
Label5: TLabel;
Label6: TLabel;
ButGrabarConfiSituacion: TSpeedButtonBC;
CheckBox1: TCheckBox;
procedure ButSeleccionarPlanoClick(Sender: TObject);
procedure ButCargarImagenLibreClick(Sender: TObject);
procedure ButCrearElementoClick(Sender: TObject);
procedure ButDerechaClick(Sender: TObject);
procedure ButIzquierdaClick(Sender: TObject);
procedure ButSubirClick(Sender: TObject);
procedure ButBajarClick(Sender: TObject);
procedure ButDestruirElementoClick(Sender: TObject);
procedure ButCrearTodosLosElementosClick(Sender: TObject);
procedure SpeedButtonTPV1Click(Sender: TObject);
procedure MiOnClick(Sender: TObject);
procedure ButGrabarConfiSituacionClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButSalirClick(Sender: TObject);
private
public
end;
var
FCrearPlano: TFCrearPlano;
VarSNameComp:string;
dir, Fichero: string; ini: TIniFile;
implementation
{$R *.dfm}
uses UDM, Fun;
function CaseOfString(s: string; a: array of string): Integer;
begin
Result := 0;
while (Result < Length(a)) and (a[Result] <> s) do
Inc(Result);
if a[Result] <> s then
Result := -1;
end;
procedure TFCrearPlano.MiOnClick(Sender: TObject);
begin
VarSNameComp:=(Sender as TSpeedButtonTPV).Name;
Panel3.Caption:='Elemento seleccionado:= [ '+VarSNameComp+' ]';
end;
procedure TFCrearPlano.ButCargarImagenLibreClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
Fichero:=OpenPictureDialog1.FileName;
Imagen.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
end;
procedure TFCrearPlano.ButSeleccionarPlanoClick(Sender: TObject);
var i,VarIContadorLista:Integer;
varStipo:string;
Lista:TList;
sl: TStringList;
begin
ActQuery(IBQUbicacion,'Select * From UBICADOS where SITUACION='+QuotedStr(DSSituacion.DataSet.FieldByName('SITUACION').AsString));
Caption:='Crear Plano [ '+ DSSituacion.DataSet.FieldByName('SITUACION').AsString+' ]';
sl := TStringList.Create;
try
for i:= 0 to (Panel2.ControlCount - 1) do begin
if Panel2.Controls[i] is TImage then TImage(Panel2.Controls[i]).Picture:=nil;
if (Panel2.Controls[i] is TSpeedButtonTPV) then Sl.Add((Panel2.Controls[i]).Name); end;
for I := 0 to sl.Count - 1 do
begin
(FindComponent(sl[i]) as TSpeedButtonTPV).Free;
end;
finally
sl.Free;
end;
dir := ExtractFilePath(ParamStr(0));
if FileExists(dir + DSSituacion.DataSet.FieldByName('SITUACION').AsString +'.ini') then
begin
ini := TIniFile.Create(dir + DSSituacion.DataSet.FieldByName('SITUACION').AsString +'.ini');
Imagen.Picture.LoadFromFile(ini.ReadString('Plano','Fichero',''));
for I := 0 to ini.ReadInteger('Statup','Numero de elementos',0)-1 do begin
with TSpeedButtonTPV.Create(SElf)do
begin
Name:=ini.ReadString('Boton'+inttostr(I),'Name','');
Parent:=Panel2;
Width:=ini.ReadInteger('Boton'+inttostr(I),'Width',0);
Height:=ini.ReadInteger('Boton'+inttostr(I),'Height',0);
Top:=ini.ReadInteger('Boton'+inttostr(I),'Top',0);
Left:=ini.ReadInteger('Boton'+inttostr(I),'Left',0);
ButonStyle:=SbtImagenColor;
ImagenTop:=ini.ReadInteger('Boton'+inttostr(I),'ImagenTop',0);
ImagenLeft:=ini.ReadInteger('Boton'+inttostr(I),'ImagenLeft',0);
ImageLong:=ini.ReadInteger('Boton'+inttostr(I),'ImageLong',0);
LeftQuad:=ini.ReadInteger('Boton'+inttostr(I),'LeftQuad',0);
LongQuad:=ini.ReadInteger('Boton'+inttostr(I),'LongQuad',0);
case ini.ReadInteger('Boton'+inttostr(I),'MYType',0) of
0:begin
MYType:=MMesa;
varStipo:='MMesa';
end;
1:begin
MYType:=MTaburete;
varStipo:='MTaburete';
end;
2:begin
MYType:=MTerraza;
varStipo:='MTerraza';
end;
3:begin
MYType:=MBanco;
varStipo:='MBanco';
end;
4:begin
MYType:=MSofa;
varStipo:='MSofa';
end;
5:begin
MYType:=Motros;
varStipo:='Motros';
end;
end;
ColorUsed:=clLime;
UsedQuad:=True;
if DsTipo.DataSet.Locate('MTIPOS',varStipo,[loPartialKey,loCaseInsensitive]) then Glyph:=DBImage1.Picture.Bitmap;
OnClick:=MiOnClick; end;
end;
end;
end;
procedure TFCrearPlano.ButCrearElementoClick(Sender: TObject);
begin
VarSNameComp:='But'+DSUbicacion.DataSet.FieldByName('TIPO').AsString+DSUbicacion.DataSet.FieldByName ('CODIGO').AsString;
if not ((FindComponent(VarSNameComp) as TSpeedButtonTPV).Caption=VarSNameComp ) then
begin
with TSpeedButtonTPV.Create(SElf)do
begin
Name:=VarSNameComp;
Parent:=Panel2;
Width:=TamanoButon.Value;
Height:=TamanoButon.Value;
Top:=0;
Left:=0;
ButonStyle:=SbtImagenColor;
ImagenTop:=10;
ImagenLeft:=10;
ImageLong:=TamanoButon.Value-17;
LeftQuad:=Width-15;
LongQuad:=Width div 4;
if DsTipo.DataSet.Locate('CODIGO',DSUbicacion.DataSet.FieldByName('TIPO').AsString,[loPartialKey,loCaseInsensitive]) then Glyph:=DBImage1.Picture.Bitmap;
case CaseOfString(DsTipo.DataSet.FieldByName('MTIPOS').AsString,['MBanco','Motros','MMesa','MSofa','MTaburete','MTerraza']) of
0:MYType:=MBanco;
1:MYType:=Motros;
2:MYType:=MMesa;
3:MYType:=MSofa;
4:MYType:=MTaburete;
5:MYType:=MTerraza;
end;
ColorUsed:=clLime;
UsedQuad:=True;
OnClick:=MiOnClick; end;
Panel3.Caption:='Elemento seleccionado:= [ '+VarSNameComp+' ]';
if CheckBox1.Checked then DSUbicacion.DataSet.Next;
end else ShowMessage('Ya existe');
end;
procedure TFCrearPlano.ButSalirClick(Sender: TObject);
begin
Close;
end;
procedure TFCrearPlano.ButBajarClick(Sender: TObject);
begin
if not ((FindComponent(VarSNameComp) as TSpeedButtonTPV).Caption=VarSNameComp ) then
begin
(FindComponent(VarSNameComp) as TSpeedButtonTPV).Top:=(FindComponent(VarSNameComp) as TSpeedButtonTPV).Top+Saltos.Value;
end;
end;
procedure TFCrearPlano.ButSubirClick(Sender: TObject);
begin
if not ((FindComponent(VarSNameComp) as TSpeedButtonTPV).Caption=VarSNameComp ) then
begin
(FindComponent(VarSNameComp) as TSpeedButtonTPV).Top:=(FindComponent(VarSNameComp) as TSpeedButtonTPV).Top-Saltos.Value;
end;
end;
procedure TFCrearPlano.ButDerechaClick(Sender: TObject);
begin
if not ((FindComponent(VarSNameComp) as TSpeedButtonTPV).Caption=VarSNameComp ) then
begin
(FindComponent(VarSNameComp) as TSpeedButtonTPV).Left:=(FindComponent(VarSNameComp) as TSpeedButtonTPV).Left+Saltos.Value;
end;
end;
procedure TFCrearPlano.ButIzquierdaClick(Sender: TObject);
begin
if not ((FindComponent(VarSNameComp) as TSpeedButtonTPV).Caption=VarSNameComp ) then
begin
(FindComponent(VarSNameComp) as TSpeedButtonTPV).Left:=(FindComponent(VarSNameComp) as TSpeedButtonTPV).Left-Saltos.Value;
end;
end;
procedure TFCrearPlano.SpeedButtonTPV1Click(Sender: TObject);
begin
VarSNameComp:=TSpeedButtonTPV(Sender).Name;
end;
procedure TFCrearPlano.ButCrearTodosLosElementosClick(Sender: TObject);
begin
DSUbicacion.DataSet.First;
while not DSUbicacion.DataSet.Eof do
begin
ButCrearElementoClick(Sender);
DSUbicacion.DataSet.Next;
end;
end;
procedure TFCrearPlano.ButDestruirElementoClick(Sender: TObject);
begin
(FindComponent(VarSNameComp) as TSpeedButtonTPV).Free;
end;
procedure TFCrearPlano.ButGrabarConfiSituacionClick(Sender: TObject);
var
Ruta:string;
VerMEmo: Boolean; Ancho: Integer;
Fecha: TDate;
Hora: TTime;
ButonStile:Integer;
i,o,U, mitipo: Integer;
begin
o:=0;
u:=0;
for i:= 0 to Panel2.ControlCount - 1 do begin
if Panel2.Controls[i] is TSpeedButtonTPV then U:=U+1;
end;
dir := ExtractFilePath(ParamStr(0));
ini := TIniFile.Create(dir + DSSituacion.DataSet.FieldByName('SITUACION').AsString +'.ini'); try
ini.WriteString('Startup', 'Rutap', dir); ini.WriteDate('Statup','Fecha',Now); ini.WriteInteger('Statup','Numero de elementos',U);
if Fichero<>'' then ini.WriteString('Plano','Fichero',Fichero);
for i:= 0 to Panel2.ControlCount - 1 do
begin
if Panel2.Controls[i] is TSpeedButtonTPV then
begin
ini.WriteString('Boton'+inttostr(o),'Name',Panel2.Controls[i].Name);
ini.WriteInteger('Boton'+inttostr(o),'Width',Panel2.Controls[i].Width);
ini.WriteInteger('Boton'+inttostr(o),'Height',Panel2.Controls[i].Height);
ini.WriteInteger('Boton'+inttostr(o),'Top',Panel2.Controls[i].Top);
ini.WriteInteger('Boton'+inttostr(o),'Left',Panel2.Controls[i].Left);
ini.WriteInteger('Boton'+inttostr(o),'ImagenTop',(FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).ImagenTop );
ini.WriteInteger('Boton'+inttostr(o),'ImagenLeft',(FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).ImagenLeft);
ini.WriteInteger('Boton'+inttostr(o),'ImageLong',(FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).ImageLong);
ini.WriteInteger('Boton'+inttostr(o),'LeftQuad',(FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).LeftQuad);
ini.WriteInteger('Boton'+inttostr(o),'LongQuad',(FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).LongQuad);
mitipo:=-1;
if (FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).MYType=MMesa then mitipo:=0;
if (FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).MYType=MTaburete then mitipo:=1;
if (FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).MYType=MTerraza then mitipo:=2;
if (FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).MYType=MBanco then mitipo:=3;
if (FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).MYType=MSofa then mitipo:=4;
if (FindComponent(Panel2.Controls[i].Name) as TSpeedButtonTPV).MYType=Motros then mitipo:=5;
ini.WriteInteger('Boton'+inttostr(o),'MYType',mitipo);
o:=o+1;
end;
end;
ShowMessage('Archivo creado');
finally
ini.Free;
end;
end;
procedure TFCrearPlano.FormCreate(Sender: TObject);
begin
Fichero:='';
end;
end.