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

📄 bookkind.~pas

📁 1、系统环境要求:WindowsXP/2000 2、DELPHI7.0企业版 3、如果数据库为SQL Server数据库
💻 ~PAS
字号:
unit bookkind;

interface

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

type
  Tf_bookkind = class(Tf_baseform)
    Label1: TLabel;
    Panel1: TPanel;
    Label2: TLabel;
    Kind: TEdit;
    Panel3: TPanel;
    Add: TButton;
    Update: TButton;
    Delete: TButton;
    Cancel: TButton;
    Grid1: TDBGrid;
    Panel2: TPanel;
    Label6: TLabel;
    Label7: TLabel;
    Field: TComboBox;
    Value: TEdit;
    Query: TButton;
    Source: TDataSource;
    procedure CancelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure QueryClick(Sender: TObject);
    procedure AddClick(Sender: TObject);
    procedure UpdateClick(Sender: TObject);
    procedure DeleteClick(Sender: TObject);
    procedure Grid1CellClick(Column: TColumn);
  private
    { Private declarations }
  public
    Function KindIsMore(kindname: String): Boolean;//判断操作员是否重复
    { Public declarations }
  end;

var
  f_bookkind: Tf_bookkind;

implementation
  uses Data;
{$R *.dfm}

procedure Tf_bookkind.CancelClick(Sender: TObject);
begin
  inherited;
  Kind.Clear;
  With t_Data.Operator do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Select * From tb_bookkinds');
    Open;
  end;
  if t_data.Operator.RecordCount>0 then
    Source.DataSet := t_data.Operator
  else
  begin
    Source.DataSet := Nil;
    t_data.Operator.Close;
  end;
end;

procedure Tf_bookkind.FormShow(Sender: TObject);
begin
  inherited;
  Cancel.Click;
end;

function Tf_bookkind.KindIsMore(kindname: String): Boolean;
begin
  Result := False;
  With t_data.Query1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * From tb_bookkinds where kinds = :name');
    Parameters.ParamByName('name').Value := Trim(kindname);
    Open;                                                 
  end;
  if t_data.Query1.RecordCount>0 then
    Result := True;
  t_data.Query1.Close;
end;

procedure Tf_bookkind.QueryClick(Sender: TObject);
begin
  inherited;
  if (Field.Text<>'')and(Trim(Value.Text)<>'')then
  begin
    With t_data.Operator do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * From tb_bookkinds where ');
      SQL.Add('kinds = :FieldValue');
      Parameters.ParamByName('FieldValue').Value := Trim(Value.Text);
      Open;
    end;
    if t_data.Operator.RecordCount<1 then
    begin
      Application.MessageBox('没有找到符合条件的记录.','提示',64);
      Cancel.Click;
    end;
  end;
end;

procedure Tf_bookkind.AddClick(Sender: TObject);
begin
  inherited;
  if Trim(Kind.Text)<>'' then
  begin
    if KindIsMore(Trim(Kind.Text)) = False then
    begin
      Try
        With t_data.Insert1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('Insert into tb_bookkinds Values(:kind)');
          Parameters.ParamByName('kind').Value := Trim(kind.Text);
          ExecSQL;
        end;
        Application.MessageBox('操作成功.','提示',64);
      Except
        Application.MessageBox('操作失败.','提示',64);
      End;
      Cancel.Click;
    end
    else
    begin
      Application.MessageBox('该信息已经存在','提示',64);
      Kind.SetFocus;
    end;
  end
  else
    Application.MessageBox('信息不能为空.','提示',64);
end;

procedure Tf_bookkind.UpdateClick(Sender: TObject);
begin
  inherited;
  if t_data.Operator.Active then
  begin
    if Trim(Kind.Text)<>'' then
    begin
      if Application.MessageBox('确实要修改当前信息吗?','提示',mb_yesno)= id_yes then
      begin
        if Trim(Kind.Text)<>Trim(t_data.Operator.FieldByName('Kinds').AsString) then
        begin
          With t_data.Query1 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('select * from tb_bookkinds where kinds = :kind');
            Parameters.ParamByName('kind').Value := Trim(Kind.Text);
            Open;
          end;
          if t_data.Query1.RecordCount>0 then
          begin
            Application.MessageBox('该信息已经存在.','提示',64);
            Exit;
          end;
        end
        else
          Exit;
        Try
          With t_data.Update1 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('Update tb_bookkinds set kinds = :kind where kinds = :oldkinds');
            Parameters.ParamByName('kind').Value := Trim(kind.Text);
            Parameters.ParamByName('oldkinds').Value := Trim(t_data.Operator.FieldByName('kinds').AsString);
            ExecSQL;
          end;
          Application.MessageBox('操作成功.','提示',64);
        Except
          Application.MessageBox('操作失败.','提示',64);
        End;
        Cancel.Click;
      end;
    end
    else
      Application.MessageBox('信息不能为空.','提示',64);
  end
  else
    Application.MessageBox('当前没有可修改的信息.','提示',64);
end;

procedure Tf_bookkind.DeleteClick(Sender: TObject);
begin
  inherited;
  if t_data.Operator.Active then
  begin
    if Application.MessageBox('确实要删除当前信息吗?','提示',mb_yesno)= ID_Yes then
    begin
      Try
        t_data.Operator.Delete;
        Cancel.Click;
        Application.MessageBox('删除成功.','提示',64);
      Except
        Application.MessageBox('操作失败.','提示',64);
      End;
    end;
  end
  else
    Application.MessageBox('当前没有可删除的信息.','提示',64);
end;

procedure Tf_bookkind.Grid1CellClick(Column: TColumn);
begin
  inherited;
  if t_data.Operator.Active then
  begin
    Kind.Text := Trim(t_data.Operator.FieldByName('Kinds').AsString);
  end;
end;

end.

⌨️ 快捷键说明

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