?? dvdbhfrm.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 + -