?? realtyc211.pas
字號:
unit RealtyC211;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, dbcgrids, Grids, DBGrids, DB, ADODB, StdCtrls, Buttons, ExtCtrls,
StrUtils, ExtDlgs, ComCtrls, math, Menus, ImgList, ToolWin;
type
Tf_RealtyC211 = class(TForm)
L1: TLabel;
Label2: TLabel;
Label9: TLabel;
Label1: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit5: TEdit;
combobox1: TComboBox;
Button5: TButton;
Button7: TButton;
ComboBox2: TComboBox;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure combobox1Select(Sender: TObject);
procedure N25Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button7Click(Sender: TObject);
procedure getid;
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
bOK:bool;
bsuccess:bool;
end;
var
f_RealtyC211: Tf_RealtyC211;
sNum:string;
implementation
uses data, main, RealtyA14,RealtyC21;
{$R *.dfm}
procedure Tf_RealtyC211.FormCreate(Sender: TObject);
Var
query:TADOQuery;
s:string;
i:integer;
begin
Query:=TADOQuery.Create(nil);
Query.Connection:=DataModuleADO.ADOConnection1;
query.sql.add('select * from 輔助資料 where 類別='''+'收費項目類別'+'''');
query.Open;
while not query.eof do
begin
Combobox1.Items.Add(query.fieldbyname('名稱').Value);
query.Next;
end;
if f_realtyC21.bMod=false then
begin
getid;
end;
query.SQL.Clear;
query.SQL.Add('select * from 儀表種類');
query.Open;
while not query.eof do
begin
Combobox2.Items.Add(query.fieldbyname('名稱').Value);
query.Next;
end;
if f_realtyC21.bMod=true then
begin
if f_RealtyC21.ListView1.Selected.Subitems[1]='抄表收費項目' then
begin
combobox2.Enabled:=true;
end
else combobox2.Enabled:=false;
edit1.Text:=f_RealtyC21.ListView1.Selected.Caption;
edit5.Text:=f_RealtyC21.ListView1.Selected.Subitems[0];
combobox1.ItemIndex:=combobox1.Items.IndexOf(f_RealtyC21.ListView1.Selected.Subitems[1]);
combobox2.ItemIndex:=combobox2.items.IndexOf(f_RealtyC21.ListView1.Selected.Subitems[2]);
edit2.Text:=f_RealtyC21.ListView1.Selected.Subitems[3];
end;
Query.Close;
Query.Free;
end;
procedure Tf_RealtyC211.getid;
Var
query:TADOQuery;
s:string;
i:integer;
begin
Query:=TADOQuery.Create(nil);
Query.Connection:=DataModuleADO.ADOConnection1;
s := 'select top 1 * from 收費項目 ORDER BY 編號 DESC';
Query.SQL.Add(s);
Query.Open ;
if query.recordcount > 0 then
begin
s:= Query.Fieldbyname('編號').AsString;
s:= Copy(S, 1, 4);
i:= strtoint(s)+1;
if i<10 then edit1.text := '000'+inttostr(i)
else if (i > 9) and (i<100) then edit1.text := '00'+inttostr(i)
else if (i > 99) and (i<1000) then edit1.text := '0'+inttostr(i)
else if i>999 then edit1.text := inttostr(i);
end
else edit1.text := '0001';
Query.Close;
Query.Free;
end;
//Tab
procedure Tf_RealtyC211.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then
Begin
key:=0;
perform(WM_NEXTDLGCTL,0,0);
end
else if key=VK_ESCAPE then close;
end;
//關閉
procedure Tf_RealtyC211.combobox1Select(Sender: TObject);
begin
combobox2.Items.Clear;
if Combobox1.text='抄表收費項目' then
begin
combobox2.Enabled:=true;
Combobox2.Items.Add('水表');
combobox2.Items.Add('電表');
end
else
begin
combobox2.Enabled:=false;
end;
end;
procedure Tf_RealtyC211.N25Click(Sender: TObject);
begin
close ;
end;
procedure Tf_RealtyC211.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
bok:=false;
action:=cafree;
end;
procedure Tf_RealtyC211.Button7Click(Sender: TObject);
Var
query:TADOQuery;
s,s1:String;
i:integer;
begin
//1
if edit1.Text='' then
begin
showmessage('請輸入編號!');
edit1.SetFocus;
exit;
end;
if edit5.Text='' then
begin
showmessage('請輸入名稱!');
edit5.SetFocus;
exit;
end;
if combobox1.Text='' then
begin
showmessage('請輸入費用項目類型!');
combobox1.SetFocus;
exit;
end;
//數據完整
s1:='-';
if combobox2.Text<>'' then s1:=combobox2.Text;
if edit2.Text='' then edit2.Text:='-';
//3
query:=TADOquery.Create(nil);
query.Connection:=DataModuleADO.ADOConnection1;
//4修改
if f_RealtyC21.bMod=true then
begin
//1判斷
if Edit1.Text<>f_RealtyC21.ListView1.Selected.Caption then
begin
query.SQL.Add('select * from 收費項目 where 編號='''+edit1.Text+'''');
query.Open;
if query.RecordCount>0 then
begin
showmessage('編號重復');
query.Close;
query.Free;
exit;
end;
end;
//2存儲數據
s:='update 收費項目 set 編號='''+edit1.Text;
s:=s+''',名稱='''+edit5.Text;
s:=s+''',費用項目類型='''+combobox1.Text;
s:=s+''',儀表種類='''+s1;
s:=s+''',說明='''+edit2.Text;
s:=s+''' where 編號='''+f_RealtyC21.ListView1.Selected.Caption;
s:=s+'''';
DataModuleADO.ADOConnection1.BeginTrans;
query.sql.clear;
query.SQL.Text:=s;
query.ExecSQL;
DataModuleADO.ADOConnection1.CommitTrans;
//3更新列表顯示
query.SQL.Clear;
query.SQL.Add('select * from 收費項目 where 編號='''+edit1.Text+'''');
query.Open;
if query.RecordCount>0 then
begin
with f_RealtyC21.listview1.Selected do
begin
Caption:=query.fieldbyname('編號').Value;
subitems[0]:=query.fieldbyname('名稱').Value;
subitems[1]:=query.fieldbyname('費用項目類型').Value;
subitems[2]:=query.fieldbyname('儀表種類').Value;
subitems[3]:=query.fieldbyname('說明').Value;
end;
end;
//4關閉連接,釋放內存
query.Close;
query.Free;
//5修改保存后關閉自己
close;
end;
//5新增數據
if f_RealtyC21.bMod=false then
begin
//1判斷是否符合數據存儲條件
query.sql.clear;
query.SQL.Add('select * from 收費項目 where 編號='''+edit1.Text+'''');
query.Open;
if query.RecordCount>0 then
begin
showmessage('編號重復');
query.Close;
query.Free;
exit;
end;
//2將數據寫入數據庫
s:='insert into 收費項目 (編號,名稱,費用項目類型,儀表種類,說明)';
s:=s+'values(:s1,:s2,:s3,:s4,:s5)';
query.sql.clear;
query.SQL.Add(s);
query.Parameters.ParamByName('s1').Value:=edit1.Text;
query.Parameters.ParamByName('s2').Value:=edit5.Text;
query.Parameters.ParamByName('s3').Value:=combobox1.Text;
query.Parameters.ParamByName('s4').Value:=s1;
query.Parameters.ParamByName('s5').Value:=edit2.text;
DataModuleADO.ADOConnection1.BeginTrans;
query.ExecSQL;
DataModuleADO.ADOConnection1.CommitTrans;
//3更新上個窗口的列表顯示
query.SQL.Clear;
query.SQL.Add('select * from 收費項目 where 編號='''+edit1.Text+'''');
query.Open;
if query.RecordCount>0 then
begin
with f_RealtyC21.listview1.Items.Add do
begin
Caption:=query.fieldbyname('編號').value;
SubItems.Add(query.fieldbyname('名稱').Value);
SubItems.Add(query.fieldbyname('費用項目類型').Value);
SubItems.Add(Query.FieldByName('儀表種類').Value);
SubItems.Add(Query.FieldByName('說明').Value);
end;
end;
//4關閉數據連接,釋放內存
query.Close;
query.Free;
//5清空數據,編號累加
getid;
edit2.text:='';
combobox2.ItemIndex:=combobox2.Items.IndexOf('');
edit5.text:='';
combobox1.ItemIndex:=combobox1.Items.IndexOf('');
Edit1.SetFocus;
end;
end;
procedure Tf_RealtyC211.Button5Click(Sender: TObject);
begin
close;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -