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

📄 sjxr.pas

📁 本系统是基于企业局域网平台针对企业安防
💻 PAS
字号:
unit sjxr;

interface

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

type
  TForm21 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    ComboBox1: TComboBox;
    Label2: TLabel;
    ComboBox2: TComboBox;
    Label3: TLabel;
    ComboBox3: TComboBox;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    MSComm1: TMSComm;
    Panel3: TPanel;
    c1: TRadioButton;
    c2: TRadioButton;
    c3: TRadioButton;
    Label4: TLabel;
    procedure FormShow(Sender: TObject);
    Procedure FindNext;
    procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    Function InspectSJ: Boolean;//检查数据是否合法
    Procedure Clear;
    procedure ComboBox3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BitBtn1Click(Sender: TObject);
    procedure ComboBox3KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form21: TForm21;
  xmsj: String;// 记录项目数据
  lcsj: String;//记录楼层数据
implementation
  uses DataModal;
{$R *.dfm}

procedure TForm21.FormShow(Sender: TObject);

begin
  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.Fields[0].Value);
    Data.ADOQuery1.Next;
  end;
  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
    ComboBox2.Items.Add(Data.ADOQuery1.Fields[0].Value);
    Data.ADOQuery1.Next;
  end;
   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
    ComboBox3.Items.Add(Data.ADOQuery1.Fields[0].Value);
    Data.ADOQuery1.Next;
  end;
  Clear;
end;

procedure TForm21.FindNext;
begin
  if FindNextControl(ActiveControl,True,False,False)is TComboBox then
    TComboBox(FindNextControl(ActiveControl,True,False,False)).SetFocus
end;

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

procedure TForm21.ComboBox3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key =vk_Return then
    BitBtn1.SetFocus;
end;

procedure TForm21.BitBtn1Click(Sender: TObject);
begin
  if c1.Checked then
    MSComm1.CommPort := 1
  else if c2.Checked then
    MSComm1.CommPort := 2
  else
    MSComm1.CommPort := 3;
  Try
    MSComm1.PortOpen := True;
  Except
    Application.MessageBox('打开端口错误.','提示',64);
    Exit;
  end;
  if Trim(ComboBox1.Text)='' then
  begin
    Application.MessageBox('请选择设备名称.','提示',64);
    ComboBox1.SetFocus;
    Exit;
  end;
  if Trim(ComboBox2.Text)='' then
  begin
    Application.MessageBox('请选择楼层名称.','提示',64);
    ComboBox2.SetFocus;
    Exit;
  end;
    if Trim(ComboBox3.Text)='' then
  begin
    Application.MessageBox('请选择楼层.','提示',64);
    ComboBox3.SetFocus;
    Exit;
  end;
  if inspectsj= False then
  begin
    Try
      MSComm1.Output := lcsj + xmsj;
      with Data.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('insert 设备数据表 values(:a,:b,:c)');
        Parameters.ParamByName('a').Value := Trim(ComboBox1.Text);
        Parameters.ParamByName('b').Value := Trim(lcsj);
        Parameters.ParamByName('c').Value :=Trim(lcsj)+ Trim(xmsj);
        ExecSQL;
      end;
      Application.MessageBox('操作成功.','提示',64);
      Clear;
    Except
      Application.MessageBox('系统出错.','提示',64);
    end;
  end;
end;

Function TForm21.InspectSJ: Boolean;
var
  Temp1: String;
begin
  Result := False;
  with Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    Temp1 := Trim(ComboBox1.Text);
    SQL.Add('select * from 报警项目表 where 项目名称 in ( select 报警项目 from 报警设备表 where 设备名称 ='+''''+Temp1+''''+')');
    Open;
  end;
  if Data.ADOQuery1.RecordCount>0 then
    xmsj := Data.ADOQuery1.Fields[0].Value 
  else
  begin
    Application.MessageBox('设备名称有误.','提示',64);
    Result := True;
    exit;
  end;
  with Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    Temp1 := Trim(ComboBox2.Text);
    SQL.Add('select 楼层编号 from 楼层信息表 where 楼层名称 = '+''''+Temp1+''''+' and 楼层 = :a');
    Parameters.ParamByName('a').Value := StrToInt(ComboBox3.Text);
    Open;
  end;
  if Data.ADOQuery1.RecordCount>0 then
    lcsj := Data.ADOQuery1.Fields[0].Value
  else
  begin
    Application.MessageBox('楼层名称所对应的楼层不存在.','提示',64);
    result := True;
    Exit;
  end;
end;

procedure TForm21.Clear;

begin
  ComboBox1.Text := '';
  ComboBox2.Text :='';
  ComboBox3.Text := '';
  ComboBox1.SetFocus;
  with Data.ADOQuery2 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select 楼层名称,楼层,b.设备名称,报警项目 from 设备数据表 a inner join  报警设备表 b on a.设备名称 = b.设备名称 inner join  楼层信息表 c on a.楼层编号 = c.楼层编号');
    open;
  end;
  if Data.ADOQuery2.RecordCount>0 then
    DataSource1.DataSet := Data.ADOQuery2
  else
    DataSource1.DataSet := Nil;
end;

procedure TForm21.ComboBox3KeyPress(Sender: TObject; var Key: Char);
var
  i: Boolean;
begin
  i := (Key<#8)or(Key>#8)and(Key<#48)or(Key>#57);
  if i then
    Key := #0;
end;

end.

⌨️ 快捷键说明

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