Ver Mensaje Individual
  #4  
Antiguo 21-10-2013
Avatar de José Luis Garcí
[José Luis Garcí] José Luis Garcí is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Las Palmas de G.C.
Posts: 1.372
Reputación: 25
José Luis Garcí Va camino a la fama
Hola JXJ, en primer lugar te encontraras con componentes que encontraras en el club, están este y este, a continuación te pongo 2 imágenes y el código de cada modulo, el 1º es crear plano, te lo pondré en dos respuesta por el limite de tamaño. Es importante que tengas en cuenta que no están terminados pero puedes hacerte una idea, de como queda +/-



Código Delphi [-]
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
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FCrearPlano: TFCrearPlano;
  VarSNameComp:string;
  dir, Fichero: string;              //Directorio po
  ini: TIniFile;          //Archivo Ini

implementation

{$R *.dfm}

uses UDM, Fun;

function CaseOfString(s: string; a: array of string): Integer;
//------------------------------------------------------------------------------
// Para usar String en un case
// Bajada de http://www.swissdelphicenter.ch/torr...de.php?id=2330
//  01/10/2013
{//Ejemplo--------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
  case CaseOfString(Edit1.Text, ['42', '23', 'nerd alert', 'hello world']) of
    0: Label1.Caption := 'What is six times nine?';
    1: Label1.Caption := 'Nichts ist, wie es scheint...';
    2: Label1.Caption := 'BATMAAAAAAAN!';
    3: Label1.Caption := 'Hello people.';
    else
      Label1.Caption := '?';
  end;
end;}
//------------------------------------------------------------------------------
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   //Contamos el número de speedbutton
      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); //TSpeedButtonTPV(Panel2.Controls[i]).Free;
      end;
      for I := 0 to sl.Count - 1 do
      begin
//         ShowMessage(sl[i]);
        (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     //Quitar el 0 en   Statup0
       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;  //Asignamos el evento creado, para ello
         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;  //Asignamos el evento creado, para ello
       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;    //Al grabar en el Ini Será 1 para true y 0 para false
   Ancho: Integer;
   Fecha: TDate;
   Hora: TTime;
   ButonStile:Integer;
   i,o,U, mitipo: Integer;
begin


    ///Falta al grabar si no hay imaghen del plano poner none y al leerlo dejarlo en blanco


   o:=0;
   u:=0;
   for i:= 0 to Panel2.ControlCount - 1 do   //Contamos el número de speedbutton
   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');    //Cremoas El Ini si no existe
   try
      ini.WriteString('Startup', 'Rutap', dir);                  //Valor = a dir
      ini.WriteDate('Statup','Fecha',Now);                       //Fecha de grabación
      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.
__________________
Un saludo desde Canarias, "El abuelo Cebolleta"
Responder Con Cita