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

📄 unit6.pas

📁 一个简单的图书管理系统
💻 PAS
字号:
unit Unit6;

interface

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

type
  TForm6 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    DBGrid1: TDBGrid;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ADODataSet1: TADODataSet;
    ADOCommand1: TADOCommand;
    DataSource1: TDataSource;
    ADODataSet2: TADODataSet;
    ADODataSet3: TADODataSet;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}
uses unit1,unit4;

procedure TForm6.FormCreate(Sender: TObject);
var
  lbbianhao:string;
begin
  xinleibie_show:=True;
  //显示已存在的小类别
  Adodataset1.Active:=False;
  adodataset1.CommandText:='select id as 类别标示,mincheng as 类别名称 from '+form1.leibie_num+' order by id ASC';
  Adodataset1.Active:=True;

  //计算小类别的编号
  adodataset2.Active:=false;
  Adodataset2.CommandText:='select * from '+form1.leibie_num+' order by id DESC';
  //showmessage(adodataset2.commandtext);
  Adodataset2.Active:=True;

  if adodataset2.RecordCount<>0 then
    begin
      //将数据集指针移到最后
      while Adodataset2.Eof do
      Adodataset2.Next;
      lbbianhao:=inttostr(strtoint(Adodataset2.fields[0].asstring)+1);
    end
  else
  lbbianhao:='100001';
  
  edit2.Text:=lbbianhao;

end;

procedure TForm6.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  action:=caFree;
  xinleibie_show:=False;
end;

procedure TForm6.Button2Click(Sender: TObject);
begin
  close;
end;

procedure TForm6.Button3Click(Sender: TObject);
var
  i:integer;
begin
  if edit1.Text<>'' then
    begin
      Adocommand1.CommandText:='insert into '+ form1.leibie_num+' values ('''+Trim(edit2.Text)+''','''+Trim(edit1.Text)+''')';
      //showmessage(adocommand1.CommandText);
      Adocommand1.Execute;

      //为更新combobox2作字符数组准备
      Adodataset3.Active:=False;
      Adodataset3.CommandText:='select * from '+Form1.leibie_num+' order by id ASC';
      Adodataset3.Active:=True;

      if Adodataset3.Recordcount<>0 then
        begin
          for i:=0 to 99  do
            Form1.combobox_1[i]:='';
          form1.stringlength_1:=0;

          for i:=0 to Adodataset3.RecordCount-1 do
            begin
              form1.combobox_1[i]:=Adodataset3.Fields[1].AsString;
              Adodataset3.Next;
             end;

           form1.stringlength_1:=i;


          //还原和计算两个文本框
          edit1.Text:='';
          edit2.Text:=inttostr((strtoint(edit2.Text)+1));

         //刷新dbgrid
         Adodataset1.Active:=False;
         Adodataset1.Active:=True;
        end
      else
          messagedlg('该编号已存在!',mtwarning,[mbok],0);
    end
  else
      messagedlg('相关内容不能为空!',mtwarning,[mbok],0);
end;

procedure TForm6.Button1Click(Sender: TObject);
begin
  if (messagedlg('你确实要删除吗?',mtwarning,[mbyes,mbno],0)=mrYes) then
     begin
       Adocommand1.CommandText:='delete from '+form1.leibie_num+' where id='''+dbgrid1.Fields[0].AsString+'''';
       //showmessage(Adocommand1.CommandText);
       Adocommand1.Execute;

       //刷新dbgrid
       adodataset1.Active:=False;
       Adodataset1.Active:=True;
     end
end;

end.


//此源码由程序太平洋收集整理发布,任何人都可自由转载,但需保留本站信息
//╭⌒╮┅~ ¤ 欢迎光临程序太平洋╭⌒╮
//╭⌒╭⌒╮╭⌒╮~╭⌒╮  ︶  ,︶︶
//,︶︶︶︶,''︶~~ ,''~︶︶  ,''
//╔ ╱◥███◣═╬╬╬╬╬╬╬╬╬╗
//╬ ︱田︱田 田 ︱          ╬
//╬       http://www.5ivb.net ╬
//╬  ╭○╮●                     ╬
//╬  /■\/■\                    ╬
//╬   <| ||    有希望,就有成功! ╬
//╬                 ╬
//╚╬╬╬╬╬╬╬╬╬╬╗  ╔╬╬╬╬╝
//
//说明:
//专业提供VB、.NET、Delphi、ASP、PB源码下载
//包括:程序源码,控件,商业源码,系统方案,开发工具,书籍教程,技术文档

⌨️ 快捷键说明

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