⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit4.pas

📁 用于家庭养殖的财务进出
💻 PAS
字号:
unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, ComCtrls, StdCtrls, movelabel;

type
  TForm4 = class(TForm)
    Button1: TButton;
    B_exit: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure B_exitClick(Sender: TObject);
//    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
     // Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    Pag:TPageControl;
    TabSheet:array of TTabSheet;
    //button:array of tbutton;
    labelcaption1:array of array of tmovelabel;
    editbox1:array of array of tmovelabel;
    combobox1:array of array of tmovelabel;
    maskedit1:array of array of tmovelabel;
    checkbox1:array of array of tmovelabel;
    memo1:array of array of tmovelabel;
    TabSheet1:array of TTabSheet;
    labcount1:integer;//作为存入数据库的取数依据
    //procedure CreateForm;
  end;

var
  Form4: TForm4;

implementation

uses data_module, Unit_main,unit3,unit_global;

{$R *.dfm}

procedure TForm4.FormCreate(Sender: TObject);
var
  comboboxcount,editboxcount:integer;
  tabsheetcount:integer;
  i,j,k,h:integer;
  sqlstr:string;
  pagenum:integer;
  itop,ileft:integer;
  index:integer;
  sqltmp:string;
  tmpname:string;
  fieldname:string;
begin
  //创建pagecontrol控件
  comboboxcount:=0;
  editboxcount:=0;
  pag:=Tpagecontrol.create(form4);
  pag.Parent:=form4;
  pag.Visible:=true;
  pag.Top:=5;
  pag.Left:=2;
  pag.Width:=630;
  pag.Height:=481;
  //计算页面个数
  sqlstr:='select max(page) as maxnum from field_info';
  with dm.ADOQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add(sqlstr);
    open;
    if not eof=bof then
      tabsheetcount:=fieldbyname('maxnum').AsInteger;
  end;
  setlength(tabsheet1,tabsheetcount);
  setlength(labelcaption1,tabsheetcount);
  setlength(editbox1,tabsheetcount);
  setlength(combobox1,tabsheetcount);
  setlength(maskedit1,tabsheetcount);
  setlength(checkbox1,tabsheetcount);
  setlength(memo1,tabsheetcount);
  for i:=1 to tabsheetcount do            //根据页面来添加控件
  begin
    //创建一个页标签
    comboboxcount:=0;
    editboxcount:=0;
    tabsheet1[i-1]:=TTabSheet.Create(self);
    tabsheet1[i-1].Visible:=true;
    tabsheet1[i-1].PageControl:=pag;
    tabsheet1[i-1].Caption:=inttostr(i);
    itop:=tabsheet1[i-1].Top;
    ileft:=tabsheet1[i-1].Left;
    //找出相应页上的控件的个数
    sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(i);//'select * from field_info where yn=''1''';
    with dm.ADOQuery1 do
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
      open;
      labcount:=recordcount;
    end;
    sqlstr:='select page_name from page_def where page_no='+inttostr(i);//+' and field='+quotedstr(tmpname);
    with dm.ADOQuery1 do
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
      open;
      tabsheet1[i-1].Caption:=fieldbyname('page_name').AsString;
    end;
    setlength(labelcaption1[i-1],labcount);
    setlength(editbox1[i-1],labcount);//editboxcount);
    setlength(combobox1[i-1],labcount);//comboboxcount);
    setlength(maskedit1[i-1],labcount);
    setlength(checkbox1[i-1],labcount);
    setlength(memo1[i-1],labcount);
    sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(i)+' order by field';
    with dm.ADOQuery3 do  //内循环
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
      open;
      first;
      while not eof do //创建label,之后编辑框
      begin
        index:=fieldbyname('ord').AsInteger-1;
        labelcaption1[i-1][index]:=tmovelabel.Create(self);
        labelcaption1[i-1][index].Visible:=true;
        tabsheet1[i-1].InsertControl(labelcaption1[i-1][index]);
        labelcaption1[i-1][index].Font.Size:=8;
        labelcaption1[i-1][index].Caption:=fieldbyname('lab_name').AsString;
        labelcaption1[i-1][index].Top:=strtoint(fieldbyname('x').asstring);//iTop+15;
        labelcaption1[i-1][index].Left:=strtoint(fieldbyname('y').asstring);//ileft;
        labelcaption1[i-1][index].WordWrap:=true;
        labelcaption1[i-1][index].Width:=100;
        labelcaption1[i-1][index].Color:=clGradientInactiveCaption;
        if (fieldbyname('type').AsString='E') or (fieldbyname('type').AsString='UE')  then //or (fieldbyname('type').AsString='D')
        begin
          if index <=labCount then
          begin
            editbox1[i-1][index]:=tmovelabel.Create(self);
            editbox1[i-1][index].Visible:=true;
            tabsheet1[i-1].InsertControl(editbox1[i-1][index]);
            editbox1[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
            editbox1[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
            editbox1[i-1][index].Color:=clwindow;
          end
          else
            raise Exception.Create('EditBox创建出现错误!');
        end;
        if fieldbyname('type').AsString='B' then
        begin
          if index<=labcount then
          begin
            checkbox1[i-1][index]:=tmovelabel.Create(self);
            checkbox1[i-1][index].Visible:=true;
            tabsheet1[i-1].InsertControl(checkbox1[i-1][index]);
            checkbox1[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
            checkbox1[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
            checkbox1[i-1][index].Color:=clwindow;
          end
          else
            raise Exception.Create('Checkbox创建出现错误!');
        end;
        if fieldbyname('type').AsString='D' then
        begin
          if index<=labcount then
          begin
            maskedit1[i-1][index]:=tmovelabel.Create(self);
            maskedit1[i-1][index].Visible:=true;
            tabsheet1[i-1].InsertControl(maskedit1[i-1][index]);//maskedit[i-1][index]
            maskedit1[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
            maskedit1[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
            maskedit1[i-1][index].Color:=clwindow;
          end
          else
            raise Exception.Create('MaskEdit创建出现错误!');
        end;
        if fieldbyname('type').AsString='M' then
        begin
          if index<=labcount then
          begin
            memo1[i-1][index]:=tmovelabel.Create(self);
            memo1[i-1][index].Visible:=true;
            tabsheet1[i-1].InsertControl(memo1[i-1][index]);//maskedit[i-1][index]
            memo1[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
            memo1[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
            memo1[i-1][index].Width:=350;
            memo1[i-1][index].Height:=120;
            memo1[i-1][index].Color:=clwindow;
          end
          else
            raise Exception.Create('Mmemo创建出现错误!');
        end;
        if (fieldbyname('type').AsString='C') or (fieldbyname('type').AsString='N') then
        begin
          if index<=labcount then
          begin
            combobox1[i-1][index]:=tmovelabel.Create(self);
            combobox1[i-1][index].Visible:=true;
            tabsheet1[i-1].InsertControl(combobox1[i-1][index]);
            combobox1[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
            combobox1[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
            combobox1[i-1][index].Color:=clwindow;
          end
          else
            raise Exception.Create('comboboxBox创建出现错误!');
        end;
        itop:=itop+30;
        if itop>(tabsheet1[i-1].Height+tabsheet1[i-1].Top+50) then
        begin
           itop:=tabsheet1[i-1].Top+10;
           ileft:=ileft+220;
        end;
        next;
        tabsheet1[i-1].Update;
      end; // while not eof do的结束
      Pag.ActivePage:=tabsheet1[2];
      Pag.ActivePage:=tabsheet1[0];
    end;
  end;
end;

procedure TForm4.FormDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  accept:=true;
end;


procedure TForm4.Button1Click(Sender: TObject);
var
  sqlstr,sqltmp:string;
  index:integer;
  x,y,compx,compy:string;
  i:integer;
  tabsheetcount:integer;
  lab_name:string;
begin
  frm_main.PageControl1.ActivePageIndex:=0;
  tabsheetcount:= unit3.tabsheetCount;
  for i:=1 to tabsheetcount do            //根据页面来添加控件
  begin
    sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(i);
    with dm.ADOQuery3 do  //内循环
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
      open;
      first;
      while not eof do //创建label,之后编辑框
      begin
        lab_name:=fieldbyname('lab_name').asstring;
        index:=fieldbyname('ord').AsInteger-1;
        x:=inttostr(labelcaption1[i-1][index].Top);
        y:=inttostr(labelcaption1[i-1][index].Left);
        if (fieldbyname('type').AsString='E') or (fieldbyname('type').AsString='UE')  then
        begin
            compx:=inttostr(editbox1[i-1][index].Top);
            compy:=inttostr(editbox1[i-1][index].Left);
        end;
        if fieldbyname('type').AsString='D' then
        begin
            compx:=inttostr(maskedit1[i-1][index].Top);
            compy:=inttostr(maskedit1[i-1][index].Left);
        end;
        if fieldbyname('type').AsString='B' then
        begin
            compx:=inttostr(checkbox1[i-1][index].Top);
            compy:=inttostr(checkbox1[i-1][index].Left);
        end;
        if (fieldbyname('type').AsString='C') or (fieldbyname('type').AsString='N') then
        begin
            compx:=inttostr(combobox1[i-1][index].Top);
            compy:=inttostr(combobox1[i-1][index].Left);
        end;
        if fieldbyname('type').AsString='M' then
        begin
            compx:=inttostr(memo1[i-1][index].Top);
            compy:=inttostr(memo1[i-1][index].Left);
        end;
        sqltmp:='update field_info set x=:x,y=:y,compx=:compx,compy=:compy where ord='+dm.ADOQuery3.fieldbyname('ord').AsString+' and page='+inttostr(i);  //,y=:y,compx=:compx,compy=:compy';
        with dm.ADOQuery2 do
        begin
          close;
          sql.Clear;
          sql.Add(sqltmp);//('update '+dm.ADOQuery3.fieldbyname('table_name').AsString+' set x=:x where ord='+dm.ADOQuery3.fieldbyname('ord').AsString+' and page='+inttostr(i));  //,y=:y,compx=:compx,compy=:compy
          Parameters[0].Value:=x;
          Parameters[1].Value:=y;
          Parameters[2].Value:=compx;
          Parameters[3].Value:=compy;
          execsql;
        end;
        next;
      end; // while not eof do的结束
    end;
  end;//for 结束
  gencode:='';
  frm_main.createform;
  showmessage('界面刷新完毕!');
  form4.Close;
end;


procedure TForm4.B_exitClick(Sender: TObject);
begin
  close;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -