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

📄 lcxxxg.pas

📁 企业安防管理系统
💻 PAS
字号:
unit lcxxxg;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, StdCtrls, Buttons, Grids, DBGrids, ExtCtrls;

type
  TForm11 = class(TForm)
    Panel2: TPanel;
    Label3: TLabel;
    Panel1: TPanel;
    Label1: TLabel;
    SpeedButton1: TSpeedButton;
    ComboBox1: TComboBox;
    DBGrid1: TDBGrid;
    Panel4: TPanel;
    Edit2: TEdit;
    Edit1: TEdit;
    Panel3: TPanel;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    DataSource1: TDataSource;
    Label4: TLabel;
    Edit3: TEdit;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Label2: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit4: TEdit;
    procedure FormShow(Sender: TObject); 
    Procedure EditValue;
    procedure SpeedButton1Click(Sender: TObject);
    procedure DBGrid1CellClick(Column: TColumn);
    procedure Edit3KeyPress(Sender: TObject; var Key: Char);
    procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form11: TForm11;

implementation
  uses DataModal;
{$R *.dfm}

procedure TForm11.EditValue;
begin
  Edit4.Text := Data.ADOQuery2.FieldByName('楼层编号').Value;
  Edit1.Text := Data.ADOQuery2.FieldByName('楼层名称').Value;
  Edit2.Text := IntToStr(Data.ADOQuery2.FieldByName('楼层').Value);
end;

procedure TForm11.FormShow(Sender: TObject);
begin
  ComboBox1.Clear;
  Edit1.Clear;
  Edit2.Clear;
  with Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Select Distinct 楼层名称 from 楼层信息表');
    Open;
  end;
  if Data.ADOQuery1.RecordCount>0 then
    while Not Data.ADOQuery1.Eof  do
    begin
      ComboBox1.Items.Add(Data.ADOQuery1.FieldByName('楼层名称').Value);
      Data.ADOQuery1.Next;
    end;
end;

procedure TForm11.SpeedButton1Click(Sender: TObject);
begin
  if (CheckBox1.Checked = False)and(CheckBox2.Checked = False) then
  begin
    Application.MessageBox('请选择查询条件.','提示',64);
    Exit;
  end;
  if (CheckBox1.Checked = True)and(Trim(ComboBox1.Text)='') then
  begin
    Application.MessageBox('请选择楼层名称.','提示',64);
    ComboBox1.SetFocus;
    Exit;
  end;
  if (CheckBox2.Checked = True)and(Trim(Edit3.Text)='') then
  begin
    Application.MessageBox('请输入楼层.','提示',64);
    Edit3.SetFocus;
    Exit;
  end;
  with Data.ADOQuery2 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from 楼层信息表 where ');
    if (CheckBox1.Checked)and(Not CheckBox2.Checked) then
    begin
      SQL.Add('楼层名称 = :a');
      Parameters.ParamByName('a').Value := Trim(ComboBox1.Text);
    end
    else if (Not CheckBox1.Checked)and(CheckBox2.Checked)then
    begin
      SQL.Add('楼层 = :a');
      Parameters.ParamByName('a').Value := StrToInt(Edit3.Text);      
    end
    else
    begin
      SQL.Add('楼层名称 = :a and 楼层 = :b');
      Parameters.ParamByName('a').Value := Trim(ComboBox1.Text);
      Parameters.ParamByName('b').Value := StrToInt(Edit3.Text);
    end; 
    Open;
    if RecordCount>0 then
    begin
      DataSource1.DataSet := Data.ADOQuery2;
      BitBtn2.Enabled := True;
      EditValue;
      Edit1.SetFocus;
    end
    else
    begin
      DataSource1.DataSet := Nil;
      BitBtn2.Enabled := False;
      Edit1.Clear;
      Edit2.Clear;
      Edit4.Clear;
      Application.MessageBox('没有符合条件的记录.','提示',64);
    end;      
  end;
end;

procedure TForm11.DBGrid1CellClick(Column: TColumn);
begin
  if Data.ADOQuery2.Active then
    if Data.ADOQuery2.RecordCount>0 then
      EditValue;
end;

procedure TForm11.Edit3KeyPress(Sender: TObject; var Key: Char);
var
  m: Boolean;
begin
  m := (Key<#8)or(Key>#8)and(Key<#49)or(Key>#57);
  if m then
    Key := #0;
end;

procedure TForm11.ComboBox1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = vk_Return then
    Edit3.SetFocus;
end;

procedure TForm11.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = vk_Return then
    Edit2.SetFocus;
end;

procedure TForm11.BitBtn2Click(Sender: TObject);
begin
  if Application.MessageBox(Pchar('确实要修改楼层编号为' + Edit4.Text+ '的楼层信息吗?'),'提示',mb_YesNo)= id_Yes then
  begin
    if (Trim(Edit1.Text)<>'')and(Trim(Edit2.Text)<>'')then
    begin
      Try
        Data.ADOQuery2.Edit;
        Data.ADOQuery2.FieldByName('楼层名称').Value := Trim(Edit1.Text);
        Data.ADOQuery2.FieldByName('楼层').Value := StrToInt(Edit2.Text);
        Data.ADOQuery2.Post;
        Application.MessageBox('修改成功.','提示',64);
        OnShow(Sender);
      Except
        Application.MessageBox('系统出错.','提示',64);
      end;
    end
    else
    begin
      Application.MessageBox('楼层名称或楼层不能为空.','提示',64);
      Edit1.SetFocus;
    end;
  end;
end;

end.

⌨️ 快捷键说明

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