📄 mc_sdfsq.~pas
字号:
unit MC_SDFSQ;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, DBGrids, StdCtrls, Buttons, ComCtrls;
type
TSDFSQ = class(TForm)
DataSource1: TDataSource;
BitBtn2: TBitBtn;
Query2: TQuery;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
BitBtn1: TBitBtn;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
StringGrid3: TStringGrid;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid2KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid3KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid3KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure BitBtn1Click(Sender: TObject);
private
X,Y:integer;
{ Private declarations }
public
{ Public declarations }
end;
var
SDFSQ: TSDFSQ;
implementation
uses MC_MainForm;
{$R *.DFM}
procedure TSDFSQ.FormShow(Sender: TObject);
begin
//定义水费收取表
StringGrid1.Cells[1,0]:='水表编号';
StringGrid1.Cells[2,0]:='户主姓名';
StringGrid1.Cells[3,0]:='标准金额';
StringGrid1.Cells[4,0]:='起始日期';
StringGrid1.Cells[5,0]:='终止日期';
StringGrid1.Cells[6,0]:='上月读数';
StringGrid1.Cells[7,0]:='本月读数';
StringGrid1.Cells[8,0]:='使用数';
StringGrid1.Cells[9,0]:='应收金额';
StringGrid1.Cells[10,0]:='实收金额';
StringGrid1.Cells[11,0]:='本月余额';
//定义电费收取表
StringGrid2.Cells[1,0]:='电表编号';
StringGrid2.Cells[2,0]:='户主姓名';
StringGrid2.Cells[3,0]:='标准金额';
StringGrid2.Cells[4,0]:='起始日期';
StringGrid2.Cells[5,0]:='终止日期';
StringGrid2.Cells[6,0]:='上月读数';
StringGrid2.Cells[7,0]:='本月读数';
StringGrid2.Cells[8,0]:='使用数';
StringGrid2.Cells[9,0]:='应收金额';
StringGrid2.Cells[10,0]:='实收金额';
StringGrid2.Cells[11,0]:='本月余额';
//定义煤气费费收取表
StringGrid3.Cells[1,0]:='煤气表编号';
StringGrid3.Cells[2,0]:='户主姓名';
StringGrid3.Cells[3,0]:='标准金额';
StringGrid3.Cells[4,0]:='起始日期';
StringGrid3.Cells[5,0]:='终止日期';
StringGrid3.Cells[6,0]:='上月读数';
StringGrid3.Cells[7,0]:='本月读数';
StringGrid3.Cells[8,0]:='使用数';
StringGrid3.Cells[9,0]:='应收金额';
StringGrid3.Cells[10,0]:='实收金额';
StringGrid3.Cells[11,0]:='本月余额';
if MainForm.Query1.Locate('使用选项','水电煤气费收取',[loCaseInsensitive]) then
begin
if MainForm.Query1.FieldByName('读写').AsString='读' then
begin
bitbtn1.Enabled:=False;
end;
end;
end;
procedure TSDFSQ.StringGrid1KeyUp(Sender: TObject; var Key: Word;Shift: TShiftState);
begin
x:=StringGrid1.Row;
y:=StringGrid1.Col;
If y = 7 Then begin //当输入水费本月读数时,自动计算本月使用数、应收金额
Try
StringGrid1.Cells[8,x]:=IntToStr(StrToInt(StringGrid1.Cells[7,x])-StrToInt(StringGrid1.Cells[6,x]));
StringGrid1.Cells[9,x]:=FloatToStr(StrToInt(StringGrid1.Cells[8,x])*StrToFloat(StringGrid1.Cells[3,x]));
Except
begin
Abort;
end;
end;
end;
If y = 10 Then begin //当输入使用水费实收金额时,自动计算本月余额
Try
StringGrid1.Cells[11,x]:=FloatToStr(StrToInt(StringGrid1.Cells[10,x])-StrToFloat(StringGrid1.Cells[9,x]));
Except
Abort;
end;
end;
end;
procedure TSDFSQ.StringGrid2KeyUp(Sender: TObject; var Key: Word;Shift: TShiftState);
begin
x:=StringGrid2.Row;
y:=StringGrid2.Col;
If y = 7 Then begin //当输入电费本月读数时,自动计算电费使用数、应收金额
Try
StringGrid2.Cells[8,x]:=IntToStr(StrToInt(StringGrid2.Cells[7,x])-StrToInt(StringGrid2.Cells[6,x]));
StringGrid2.Cells[9,x]:=FloatToStr(StrToInt(StringGrid2.Cells[8,x])*StrToFloat(StringGrid2.Cells[3,x]));
Except
begin
Abort;
end;
end;
end;
If y = 10 Then begin //当输入电费实收金额时,自动计算本月余额
Try
StringGrid2.Cells[11,X]:=FloatToStr(StrToInt(StringGrid2.Cells[10,x])-StrToFloat(StringGrid2.Cells[9,x]));
Except
begin
Abort;
end;
end;
end;
end;
procedure TSDFSQ.StringGrid3KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
x:=StringGrid3.Row;
y:=StringGrid3.Col;
If y = 7 Then begin //当输入煤气费本月读数时,自动计算煤气费使用数、应收金额
Try
StringGrid3.Cells[8,x]:=IntToStr(StrToInt(StringGrid3.Cells[7,x])-StrToInt(StringGrid3.Cells[6,x]));
StringGrid3.Cells[9,x]:=FloatToStr(StrToInt(StringGrid3.Cells[8,x])*StrToFloat(StringGrid3.Cells[3,x]));
Except
begin
Abort;
end;
end;
end;
If y = 10 Then begin //当输入实收煤气费时,自动计算本月余额
Try
StringGrid3.Cells[11,x]:=FloatToStr(StrToInt(StringGrid3.Cells[10,x])-StrToFloat(StringGrid3.Cells[9,x]));
Except
begin
Abort;
end;
end;
end;
end;
procedure TSDFSQ.BitBtn1Click(Sender: TObject);var a:integer; //将以上费用信息处理后依次返回表中
begin
if MessageDlg('是否更新水费信息?',mtCustom,[mbYes,mbNo],0)=mrYes then
begin
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('Update 水费 Set 计费终止日期=:A,本月读数=:B,使用数=:C,应收金额=:D,实收金额=:E,本月余额=:G');
Query2.SQL.Add('Where 水表编号=:F');
For a:=1 to StringGrid1.RowCount-1 do
begin
Query2.Close;
Try //更新水费
Query2.ParamByName('F').AsString:=StringGrid1.Cells[1,a];
Query2.ParamByName('A').AsDateTime:=StrToDate(StringGrid1.Cells[5,a]);
Query2.ParamByName('B').AsInteger:=StrToInt(StringGrid1.Cells[7,a]);
Query2.ParamByName('C').AsInteger:=StrToInt(StringGrid1.Cells[8,a]);
Query2.ParamByName('D').AsFloat:=StrToFloat(StringGrid1.Cells[9,a]);
Query2.ParamByName('E').AsFloat:=StrToFloat(StringGrid1.Cells[10,a]);
Query2.ParamByName('G').AsFloat:=StrToFloat(StringGrid1.Cells[11,a]);
Query2.ExecSQL;
Except
ShowMessage('编号为['+StringGrid1.Cells[1,a]+']的费用信息数据有误,没有保存!');
Abort;
End;
end;
end;
if MessageDlg('是否更新电费信息?',mtCustom,[mbyes,mbNo],0)=mrYes then
begin
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('Update 电费 Set 计费终止日期=:A,本月读数=:B,使用数=:C,应收金额=:D,实收金额=:E,本月余额=G');
Query2.SQL.Add('Where 电表编号=:F');
For a:=1 to StringGrid2.RowCount-1 do
begin
Query2.Close;
Try //更新电费
Query2.ParamByName('F').AsString:=StringGrid2.Cells[1,a];
Query2.ParamByName('A').AsDateTime:=StrToDate(StringGrid2.Cells[5,a]);
Query2.ParamByName('B').AsInteger:=StrToInt(StringGrid2.Cells[7,a]);
Query2.ParamByName('C').AsInteger:=StrToInt(StringGrid2.Cells[8,a]);
Query2.ParamByName('D').AsFloat:=StrToFloat(StringGrid2.Cells[9,a]);
Query2.ParamByName('E').AsFloat:=StrToFloat(StringGrid2.Cells[10,a]);
Query2.ParamByName('G').AsFloat:=StrToFloat(StringGrid2.Cells[11,a]);
Query2.ExecSQL;
Except
ShowMessage('编号为['+StringGrid2.Cells[1,a]+']的费用信息数据有误,没有保存!');
Abort;
End;
end;
end;
if MessageDlg('是否更新气费信息?',mtCustom,[mbYes,mbNo],0)=mryes then
begin
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('Update 煤气费 Set 计费终止日期=:A,本月读数=:B,使用数=:C,应收金额=:D,实收金额=:E,本月余额=:G');
Query2.SQL.Add('Where 煤气表编号=:F');
For a:=1 to StringGrid1.RowCount-1 do
begin
Query2.Close;
Try //更新煤气费
Query2.ParamByName('F').AsString:=StringGrid3.Cells[1,a];
Query2.ParamByName('A').AsDateTime:=StrToDate(StringGrid3.Cells[5,a]);
Query2.ParamByName('B').AsInteger:=StrToInt(StringGrid3.Cells[7,a]);
Query2.ParamByName('C').AsInteger:=StrToInt(StringGrid3.Cells[8,a]);
Query2.ParamByName('D').AsFloat:=StrToFloat(StringGrid3.Cells[9,a]);
Query2.ParamByName('E').AsFloat:=StrToFloat(StringGrid3.Cells[10,a]);
Query2.ParamByName('G').AsFloat:=StrToFloat(StringGrid3.Cells[11,a]);
Query2.ExecSQL;
Except
ShowMessage('编号为['+StringGrid1.Cells[1,a]+']的费用信息数据有误,没有保存!');
Abort;
End;
end;
end;
ShowMessage('更新完毕!!');
end;
procedure TSDFSQ.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SDFSQ.Release;
SDFSQ:=Nil;
end;
procedure TSDFSQ.BitBtn2Click(Sender: TObject);
begin
Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -