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

📄 dvdbhfrm.pas

📁 该系统实现了对DVD租赁过程的管理,功能完善,方便实用.
💻 PAS
字号:
unit DVDBhFrm;

interface

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

type
  TFrmDVDBh = class(TForm)
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Image1: TImage;
    StatusBar1: TStatusBar;
    Panel1: TPanel;
    Label2: TLabel;
    edCD_ID: TEdit;
    lbCD_NameCn: TLabel;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    ListBox1: TListBox;
    edStore_ID: TEdit;
    bbtnSave: TBitBtn;
    lbCDNum: TLabel;
    PopupMenu1: TPopupMenu;
    popDel: TMenuItem;
    ADOQuery2: TADOQuery;
    ADOQuery3: TADOQuery;
    N1: TMenuItem;
    popRef: TMenuItem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ShowRecord(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure bbtnSaveClick(Sender: TObject);
    procedure edCD_IDExit(Sender: TObject);
    procedure edStore_IDKeyPress(Sender: TObject; var Key: Char);
    procedure popDelClick(Sender: TObject);
    procedure ClearEdit(Sender: TObject);
    procedure popRefClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmDVDBh: TFrmDVDBh;

implementation

uses MainFrm;
var
  IsExisted : Boolean;
{$R *.dfm}

procedure TFrmDVDBh.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FrmDVDBh.Free;
  FrmMain.sp5 := False;
end;

procedure TFrmDVDBh.ClearEdit(Sender: TObject);
begin
  edCD_ID.Clear;
  lbCD_Namecn.Caption :='';
  ListBox1.Clear;
  lbCDNum.Caption := '';;
  edStore_ID.Clear;
end;

procedure TFrmDVDBh.ShowRecord(Sender: TObject);
begin
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Text := 'Select CD_Store.CD_ID, CD_Info.CD_NameCn,CD_Store.Store_ID from CD_Store,CD_Info';
  ADOQuery1.SQL.Text := ADOQuery1.SQL.Text+ ' Where CD_Info.CD_ID=CD_Store.CD_ID order by CD_Store.Store_ID';
  ADOQuery1.Open;
  StatusBar1.Panels[1].Text := '  现有光盘: ' + IntToStr(ADOQuery1.RecordCount) + ' 套';

end;

procedure TFrmDVDBh.FormCreate(Sender: TObject);
begin
  ShowRecord(Sender);
  IsExisted :=False;
end;

procedure TFrmDVDBh.bbtnSaveClick(Sender: TObject);
var
  i : integer;
begin
  if Length(Trim(edCD_ID.Text))<>10 then
  begin
    Application.MessageBox('没有输入正确的光盘号','错误',MB_ICONWARNING+MB_OK);
    edCD_ID.SetFocus;
    edCD_ID.SelectAll;
    Exit;
  end;
  if ListBox1.Items.Count = 0 then
  begin
    Application.MessageBox('店内编号还没有输入,保存失败!','错误',MB_ICONWARNING+MB_OK);
    edStore_ID.SetFocus;
    edStore_ID.SelectAll;
    Exit;
  end;
  if Not IsExisted then
  begin
    Application.MessageBox(Pchar('编号为 '+edCD_ID.Text+' 的光盘还没有信息,保存失败!'+chr(10)+chr(13)+'请先在“光盘信息管理”中将该光盘编辑入库'),'错误',MB_ICONWARNING+MB_OK);
    edStore_ID.SetFocus;
    edStore_ID.SelectAll;
    Exit;
  end;
  ADOQuery3.Close;
  ADOQuery3.SQL.Clear;
  ADOQuery3.SQL.Text :='Select * From CD_Store';
  ADOQuery3.Open;
  for i:=0 to ListBox1.Items.Count - 1 do //新的店内编号存入数据表
  begin
    ADOQuery3.Append;
      ADOQuery3.FieldByName('CD_ID').AsString := edCD_ID.Text;
      ADOQuery3.FieldByName('Store_ID').AsString := ListBox1.Items[i];
    ADOQuery3.Post;
  end;
  ADOQuery3.Close;  //CD_Info表中增加引进数量
  ADOQuery3.SQL.Clear;
  ADOQuery3.SQL.Text :='Select * From CD_Info Where CD_ID = '''+edCD_ID.Text+'''';
  ADOQuery3.Open;
  ADOQuery3.Edit;
  ADOQuery3.FieldByName('Num_Buy').AsInteger := ADOQuery3.FieldByName('Num_Buy').AsInteger + ListBox1.Items.Count;
  ADOQuery3.Post;
  Application.MessageBox(Pchar('增加 '+IntToStr(ListBox1.Items.Count)+' 条记录成功!'), '成功',MB_OK+MB_ICONINFORMATION);
  ClearEdit(Sender);
  ShowRecord(Sender);
end;

procedure TFrmDVDBh.edCD_IDExit(Sender: TObject);
begin
  ADOQuery2.Close;
  ADOQuery2.SQL.Clear;
  ADOQuery2.SQL.Text :='Select * From CD_Info Where CD_ID = '''+edCD_ID.Text+'''';
  ADOQuery2.Open;
  if ADOQuery2.RecordCount <> 0 then
  begin
    lbCD_NameCn.Caption :='片名:'+ADOQuery2.FieldByName('CD_NameCn').AsString;
    IsExisted := True;
  end
  else
  begin
    lbCD_NameCn.Caption := '数据库中不存在 '+edCD_ID.Text+ ' 的记录';
    IsExisted := False;
  end;
end;

procedure TFrmDVDBh.edStore_IDKeyPress(Sender: TObject; var Key: Char);
var
  i : integer;
  flag : Boolean;
begin
  if key = #13 then
  begin
    if Length(Trim(edStore_ID.Text))= 10 then
    begin
      flag := True;
      for i:=0 to Listbox1.Items.Count - 1 do
        if Listbox1.Items[i] = edStore_ID.Text then
          flag := False;
      if flag then
      begin
        ADOQuery3.Close;
        ADOQuery3.SQL.Clear;
        ADOQuery3.SQL.Text := 'Select * from CD_Store Where Store_ID = '''+edStore_ID.Text+'''';
        ADOQuery3.Open;
        if ADOQuery3.RecordCount = 0 then
        begin
          ListBox1.Items.Add(edStore_ID.Text);
          edStore_ID.Clear;
          lbCDNum.Caption := '当前有 '+IntToStr(ListBox1.Items.Count)+' 条编号记录';
        end
        else
        begin
          Application.MessageBox('改店内编号已经使用,请核查!','错误',MB_ICONWARNING+MB_OK);
          edStore_ID.SetFocus;
          edStore_ID.SelectAll;
        end;
      end
      else
      begin
        Application.MessageBox('改店内编号已经存在,请核查!','错误',MB_ICONWARNING+MB_OK);
        edStore_ID.SetFocus;
        edStore_ID.SelectAll;
      end;
    end
    else
    begin
      Application.MessageBox('没有输入正确的店内编号,编号长度必须10位','错误',MB_ICONWARNING+MB_OK);
      edStore_ID.SetFocus;
      edStore_ID.SelectAll;
    end;
  end;
end;

procedure TFrmDVDBh.popDelClick(Sender: TObject); //删除列表框中的店内编号
var
  i : Integer;
begin
  if ListBox1.Focused then
  begin
    for i := 0 to ListBox1.Items.Count - 1 do
    begin
      if ListBox1.Selected[i] then
      begin
        case Application.MessageBox('确实要删除该店内编号吗?','再次确认',MB_OKCANCEL) of
          1 :
          begin
            ListBox1.Items.Delete(i);
            lbCDNum.Caption := '当前有 '+IntToStr(ListBox1.Items.Count)+' 条编号记录';
          end;
          2 : Exit;
        end; //end Case
        Exit;
      end; // end if
    end; //end for
  end;
  if DBGrid1.Focused then
  begin
    case Application.MessageBox('确实要删除记录吗?', '删除确认',MB_OKCANCEL+MB_ICONINFORMATION) of
    IDCANCEL : ;   //放弃删除
    IDOK:
    begin
      ADOQuery2.Close;
      ADOQuery2.SQL.Clear;
	    ADOQuery2.SQL.Add('Delete * From CD_Store Where Store_ID = ''' +DBGrid1.Fields[0].Text+ '''');
	    ADOQuery2.ExecSQL;

      ADOQuery3.Close;  //CD_Info表中引进数量减1
      ADOQuery3.SQL.Clear;
      ADOQuery3.SQL.Text :='Select * From CD_Info Where CD_ID = '''+DBGrid1.Fields[1].Text+'''';
      ADOQuery3.Open;
      ADOQuery3.Edit;
      ADOQuery3.FieldByName('Num_Buy').AsInteger := ADOQuery3.FieldByName('Num_Buy').AsInteger - 1;
      ADOQuery3.Post;
      Application.MessageBox('删除记录成功!', '成功',MB_OK+MB_ICONINFORMATION);
      ShowRecord(Sender);
    end;
  end; //Case end

  end;
end;

procedure TFrmDVDBh.popRefClick(Sender: TObject);
begin
  if DBGrid1.Focused then
    ShowRecord(Sender);
end;

procedure TFrmDVDBh.FormActivate(Sender: TObject);
begin
  ShowRecord(Sender);
end;

end.

⌨️ 快捷键说明

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