?? uform_apart_edit.pas
字號:
unit Uform_apart_edit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, Buttons, ImgList, DB, ADODB;
type
Tform_apart_edit = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
button_add: TBitBtn;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
ImageList1: TImageList;
Label2: TLabel;
Apart_list: TListView;
recordset_temp: TADOQuery;
Label4: TLabel;
Label3: TLabel;
Label1: TLabel;
Bevel1: TBevel;
Image2: TImage;
Image1: TImage;
procedure BitBtn3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure button_addClick(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
intCount:integer;
end;
var
form_apart_edit: Tform_apart_edit;
implementation
uses UForm_apart_input, Uform_main;
{$R *.dfm}
procedure Tform_apart_edit.BitBtn3Click(Sender: TObject);
begin
close;
end;
procedure Tform_apart_edit.FormShow(Sender: TObject);
var
i:integer;
ListItem: TListItem;
p:^integer;
begin
apart_list.Items.Clear ;
recordset_temp.SQL.Clear ;
recordset_temp.SQL.Add ('select * from [APART]');
recordset_temp.Open ;
intCount:=recordset_temp.RecordCount ;
Label4.Caption :=inttostr(intCount) + '個';
for i:=1 to recordset_temp.RecordCount do
begin
listitem:=apart_LIST.Items.Add ;
listitem.Caption :=recordset_temp.Fields[1].AsString ;
listitem.ImageIndex :=0;
new(p);
p^ := recordset_temp.Fields[0].AsInteger ;
listitem.Data :=p;
recordset_temp.Next;
end;
end;
procedure Tform_apart_edit.BitBtn1Click(Sender: TObject);
var
ListItem: TListItem;
p:^integer;
begin
repeat
form_apart_input.Caption :='新建部門';
form_apart_input.Edit1.Text :='';
form_apart_input.Label1.Caption :='新建部門';
form_apart_input.Label2.Caption :='新建部門';
form_apart_input.Label3.caption:=' 請在下面輸入欲添加的部門名稱:';
form_apart_input.Image2.Picture :=form_apart_edit.Image2.Picture ;
form_apart_input.ShowModal ;
if form_apart_input.bYesno =false then exit;
form_main.Dconnect.Execute ('insert into [APART]([APART_NAME]) values(''' + form_apart_input.stringApartname +''')');
recordset_temp.SQL.Clear ;
recordset_temp.SQL.Add ('select * from [APART]');
recordset_temp.Open ;
recordset_temp.Last ;
new(p);
p^:=recordset_temp.Fields[0].AsInteger ;
listitem:=apart_LIST.Items.Add ;
listitem.Caption :=form_apart_input.stringApartname ;
listitem.ImageIndex :=0 ;
listitem.Data:=p;
intCount := intCount+1;
Label4.Caption :=inttostr(intCount) + '個';
until messagebox(self.Handle ,'您是否還要添加新的部門?','標題',MB_YESNO or MB_ICONASTERISK)<> IDYES;
end;
procedure Tform_apart_edit.button_addClick(Sender: TObject);
var
p:^integer;
begin
if apart_list.Selected =nil then exit ;
recordset_temp.SQL.Clear ;
p:=Apart_list.Selected.Data;
recordset_temp.SQL.Add ('select * from [APART] where [APART_ID]=' + inttostr(p^));
recordset_temp.Open ;
if recordset_temp.RecordCount <>0 then
begin
form_apart_input.Edit1.Text :=recordset_temp.Fields[1].AsString ;
form_apart_input.Caption :='修改部門名稱';
form_apart_input.Label1.Caption :='修改部門';
form_apart_input.Label2.Caption :='修改部門';
form_apart_input.Label3.caption:=' 請在下面修改部門的名稱:';
form_apart_input.Image2.Picture :=form_apart_edit.Image2.Picture ;
form_apart_input.ShowModal ;
if form_apart_input.bYesno =true then
begin
form_main.Dconnect.Execute('update [APART] set [APART_NAME]=''' + form_apart_input.stringApartname + ''' where [APART_ID]=' + inttostr(P^));
apart_list.Selected.Caption :=form_apart_input.stringApartname ;
end;
end;
end;
procedure Tform_apart_edit.BitBtn2Click(Sender: TObject);
var
temp:pchar;
p:^integer;
countt:integer;
begin
if apart_list.Selected =nil then exit ;
p:=Apart_list.Selected.Data;
recordset_temp.SQL.Clear ;
recordset_temp.SQL.Add('select count([PJ_ID]) from [PJ] where [PJ_APART_ID]=' + inttostr(p^));
recordset_temp.open;
countt:=recordset_temp.Fields[0].AsInteger ;
recordset_temp.Close ;
temp:=pchar('您是否確定要刪除['+apart_list.Selected.caption + ']'
+ #13 + '如果您刪除此部門,將有' + inttostr(countt) + '條評價將關連刪除');
if messagebox(self.Handle, temp,
'警告',MB_yesno or MB_ICONQUESTION )=IDyes then
begin
form_main.Dconnect.Execute('delete * from [PJ] where [PJ_APART_ID]=' + inttostr(p^));
form_main.Dconnect.Execute('delete * from [APART] where [APART_ID]=' + inttostr(p^));
Dispose(p);
apart_list.Selected.Delete ;
intCount := intCount-1;
Label4.Caption :=inttostr(intCount) + '個';
end;
apart_list.SetFocus ;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -