📄 invoice10kv_f.pas
字号:
unit Invoice10KV_F;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Transfer_Frm, Grids, DBGrids, StdCtrls, ppDBPipe, ppComm, ppRelatv,
ppProd, ppClass, ppReport, ppCtrls, ppPrnabl, ppBands, ppCache, Mask,
DBCtrls, Db, DBTables, ppStrtch, ppSubRpt, ppRegion, ppEndUsr, ppModule,
raCodMod, ppVar, myChkBox, ppParameter, ppDB;
type
TF_Invoice10kv = class(TForm)
GroupBox1: TGroupBox;
Bt_PrintInvoice: TButton;
Bt_Return: TButton;
DBG_House: TDBGrid;
R_Invoice: TppReport;
D_Invoice: TppDesigner;
Bt_Edit: TButton;
ppParameterList1: TppParameterList;
E_Search: TEdit;
Bt_Search: TButton;
CB_Preview: TCheckBox;
Label2: TLabel;
DBT_Amount: TDBText;
Label3: TLabel;
E_Gathering: TEdit;
Label4: TLabel;
E_GiveChange: TEdit;
Memo1: TMemo;
DBP_10KV: TppDBPipeline;
Bt_Charge: TButton;
Bt_Switch: TButton;
DBE_House_No: TDBEdit;
E_InvoiceName: TEdit;
Bt_Update: TButton;
DBE_House_Name: TDBEdit;
ppHeaderBand3: TppHeaderBand;
ppDetailBand4: TppDetailBand;
ppDBText18: TppDBText;
ppDBText19: TppDBText;
ppDBText21: TppDBText;
ppDBText22: TppDBText;
ppDBText23: TppDBText;
ppDBText24: TppDBText;
ppDBText33: TppDBText;
ppLabel81: TppLabel;
ppLabel82: TppLabel;
ppLabel86: TppLabel;
ppL_UpperCash: TppLabel;
ppLabel90: TppLabel;
ppLabel91: TppLabel;
ppLabel92: TppLabel;
ppLabel93: TppLabel;
ppDBText1: TppDBText;
ppDBText2: TppDBText;
ppDBText3: TppDBText;
ppDBText4: TppDBText;
ppDBText5: TppDBText;
ppDBText6: TppDBText;
ppDBText7: TppDBText;
ppDBText8: TppDBText;
ppDBText9: TppDBText;
ppDBText10: TppDBText;
ppDBText11: TppDBText;
ppDBText12: TppDBText;
ppDBText13: TppDBText;
ppDBText14: TppDBText;
ppDBText15: TppDBText;
ppDBText16: TppDBText;
ppDBText20: TppDBText;
ppDBText25: TppDBText;
ppDBText26: TppDBText;
ppDBText27: TppDBText;
ppDBText28: TppDBText;
ppDBText29: TppDBText;
ppDBText30: TppDBText;
ppDBText31: TppDBText;
ppL_G11: TppLabel;
ppL_G13: TppLabel;
ppL_G16: TppLabel;
ppDBText32: TppDBText;
ppDBText34: TppDBText;
ppDBText35: TppDBText;
ppL_Charge1: TppLabel;
ppL_Charge2: TppLabel;
ppL_Charge3: TppLabel;
ppL_Iron_Used: TppLabel;
ppSystemVariable1: TppSystemVariable;
ppDBText17: TppDBText;
ppLabel1: TppLabel;
ppDBText36: TppDBText;
ppDBText37: TppDBText;
ppFooterBand4: TppFooterBand;
CB_GatheringMode: TComboBox;
Label1: TLabel;
procedure Bt_PrintInvoiceClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Bt_ReturnClick(Sender: TObject);
procedure Bt_EditClick(Sender: TObject);
procedure ppLabel89GetText(Sender: TObject; var Text: String);
procedure ppLabel87GetText(Sender: TObject; var Text: String);
procedure ppLabel88GetText(Sender: TObject; var Text: String);
procedure ppL_UpperCashGetText(Sender: TObject; var Text: String);
procedure ppLabel1GetText(Sender: TObject; var Text: String);
procedure ppLabel2GetText(Sender: TObject; var Text: String);
procedure ppDetailBand4BeforePrint(Sender: TObject);
procedure Bt_SearchClick(Sender: TObject);
procedure E_SearchKeyPress(Sender: TObject; var Key: Char);
procedure DBG_HouseDblClick(Sender: TObject);
procedure E_SearchClick(Sender: TObject);
procedure DBG_HouseCellClick(Column: TColumn);
procedure E_SearchDblClick(Sender: TObject);
procedure CB_PreviewClick(Sender: TObject);
procedure E_GatheringChange(Sender: TObject);
procedure Bt_ChargeClick(Sender: TObject);
procedure Bt_SwitchClick(Sender: TObject);
procedure Bt_UpdateClick(Sender: TObject);
procedure DBE_House_NoChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
//根据单价得到收费名称
Function f_GetChargeName(Price: Currency):String;
public
{ Public declarations }
end;
var
F_Invoice10kv: TF_Invoice10kv;
implementation
uses Comm, CommFee, UpperMoney_U, CommSMDLJF, ppTypes, Invoice400v_F,
DataModule_10KV;
{$R *.DFM}
procedure TF_Invoice10kv.Bt_PrintInvoiceClick(Sender: TObject);
begin
R_Invoice.Template.FileName := gRootPath + '10KV发票.RTM';
R_Invoice.Template.LoadFromFile();
R_Invoice.PassSetting := psTwoPass;
R_Invoice.ShowPrintDialog := False;
If Sender <> Nil Then//用户按键
If CB_Preview.Checked Then
R_Invoice.DeviceType := dtScreen
Else
R_Invoice.DeviceType := dtPrinter
Else
R_Invoice.DeviceType := dtPrinter;
R_Invoice.Print();
end;
procedure TF_Invoice10kv.FormShow(Sender: TObject);
begin
//当表号为空时应无表底
DM_10KV.Q_Update.SQL.Clear();
DM_10KV.Q_Update.SQL.Text := 'Update "10KV" Set B15=null, B16=null Where B14 = ""';
DM_10KV.Q_Update.ExecSQL();
DM_10KV.Q_Update.SQL.Text := 'Update "10KV" Set B12=null, B13=null Where B11 = ""';
DM_10KV.Q_Update.ExecSQL();
DM_10KV.Q_Update.SQL.Text := 'Update "10KV" Set B18=null, B19=null Where B17 = ""';
DM_10KV.Q_Update.ExecSQL();
//无功表应只有一只,必须设置在第一只表位 3->2 2->1
DM_10KV.Q_Update.SQL.Text := 'Update "10KV" Set B24=B27, B25=B28, B26=B29, B27=null, B28=null, B29=null Where B24 = ""';
DM_10KV.Q_Update.ExecSQL();
DM_10KV.Q_Update.SQL.Text := 'Update "10KV" Set B21=B24, B22=B25, B23=B26, B24=null, B25=null, B26=null Where B21 = ""';
DM_10KV.Q_Update.ExecSQL();
//无表号时置表底为空
DM_10KV.Q_Update.SQL.Text := 'Update "10KV" Set B22=null, B23=null Where B21 = ""';
DM_10KV.Q_Update.ExecSQL();
P_OpenTable(DM_10KV.Q_10KV);
E_Search.SetFocus();
end;
procedure TF_Invoice10kv.Bt_ReturnClick(Sender: TObject);
begin
Close();
end;
procedure TF_Invoice10kv.Bt_EditClick(Sender: TObject);
begin
R_Invoice.Template.FileName := gRootPath + '10KV发票.RTM';
R_Invoice.Template.LoadFromFile();
D_Invoice.ShowModal();
If Application.MessageBox('存储报表吗?','系统提示',MB_YESNO) = IDYES Then
R_Invoice.Template.SaveToFile();
end;
procedure TF_Invoice10kv.ppLabel89GetText(Sender: TObject; var Text: String);
begin
Text := Default_Auditing;//审核
end;
procedure TF_Invoice10kv.ppLabel87GetText(Sender: TObject; var Text: String);
begin
Text := Default_Fee;//收费
end;
procedure TF_Invoice10kv.ppLabel88GetText(Sender: TObject; var Text: String);
begin
Text := Default_Use;//开票
end;
procedure TF_Invoice10kv.ppL_UpperCashGetText(Sender: TObject; var Text: String);
begin
//大写金额
Text := UpperMoney(DM_10KV.Q_10KV['G18']);
end;
procedure TF_Invoice10kv.ppLabel1GetText(Sender: TObject; var Text: String);
begin
Text := CurrentYear;
end;
procedure TF_Invoice10kv.ppLabel2GetText(Sender: TObject; var Text: String);
begin
Text := CurrentMonth;
end;
procedure TF_Invoice10kv.ppDetailBand4BeforePrint(Sender: TObject);
Var
Iron_Used: Integer;
begin
//大写金额
ppL_UpperCash.Caption := UpperMoney(DM_10KV.Q_10KV['G18']);
ppL_Charge1.Caption := F_GetChargeName(DM_10KV.Q_10KV['A29']);
ppL_Charge2.Caption := F_GetChargeName(DM_10KV.Q_10KV['A37']);
Try//城区所第三单价为A60, 但其他所A60是供电所编号
ppL_Charge3.Caption := F_GetChargeName(DM_10KV.Q_10KV['A60']);
Except
ppL_Charge3.Caption := F_GetChargeName(DM_10KV.Q_10KV['A73']);
ppDBText28.DataField := 'A73';
End;
If DM_10KV.Q_10KV['G11'] = 0 Then
ppL_G11.Caption := ''
Else
ppL_G11.Caption := '基本电费';
If DM_10KV.Q_10KV['G13'] = 0 Then
ppL_G13.Caption := ''
Else
ppL_G13.Caption := '力率电费';
If DM_10KV.Q_10KV['G16'] = 0 Then
ppL_G16.Caption := ''
Else
ppL_G16.Caption := '加价电费';
//变耗计算
If (DM_10KV.Q_10KV['A25'] = 0) And (DM_10KV.Q_10KV['A26'] = 0) And (DM_10KV.Q_10KV['A47'] = '') Then
Begin
Iron_Used := Int(DM_10KV.Q_10KV['A41'] * DM_10KV.Q_10KV['A22'] / 30.0 + 0.5)
+ DM_10KV.Q_10KV['A25']
+ Int((DM_10KV.Q_10KV['A50'] + DM_10KV.Q_10KV['A48'] - DM_10KV.Q_10KV['A57']) * 0.01 + 0.5);
ppL_Iron_Used.Caption := IntToStr(Iron_Used);
End
Else
ppL_Iron_Used.Caption := '';
end;
procedure TF_Invoice10kv.Bt_SearchClick(Sender: TObject);
Var
SqlStr:String;
SearchStr:String[12];
begin
DM_10KV.Q_10KV.Close();
DM_10KV.Q_10KV.SQL.Clear();
DM_10KV.Q_10KV.SQL.Add('Select * From "10KV.DBF"');
SearchStr := E_Search.Text;
If SearchStr <> '' Then
Begin
If (SearchStr[1] >= 'A') And (SearchStr[2] <= 'Z') Then//Is Alpha
If Length(SearchStr) >= 8 Then//户号足位
SqlStr := Format('Where A11 = "%s"',[SearchStr])
Else
SqlStr := Format('Where A11 Like "%s%%"',[SearchStr])
Else//认为是户名
SqlStr := Format('Where A12 Like "%s%%"',[SearchStr]);
End;
DM_10KV.Q_10KV.SQL.Add(SqlStr);
DM_10KV.Q_10KV.Open();
If DM_10KV.Q_10KV.Eof Or (DM_10KV.Q_10KV.RecordCount <> 1) Then//未找到
Begin
E_Search.SetFocus();
Beep();
Exit;
End;
//收款额输入
E_Gathering.Text := '';
E_GiveChange.Text := '';
E_Gathering.SetFocus();
end;
procedure TF_Invoice10kv.E_SearchKeyPress(Sender: TObject; var Key: Char);
begin
If Key = #13 Then
Bt_SearchClick(Nil);
end;
procedure TF_Invoice10kv.DBG_HouseDblClick(Sender: TObject);
begin
E_Search.Text := DBE_House_No.Text;
Bt_SearchClick(Nil);
end;
procedure TF_Invoice10kv.E_SearchClick(Sender: TObject);
begin
E_Search.SelectAll();
end;
procedure TF_Invoice10kv.DBG_HouseCellClick(Column: TColumn);
begin
E_Search.Text := DBE_House_No.Text;
end;
procedure TF_Invoice10kv.E_SearchDblClick(Sender: TObject);
begin
E_Search.Text := '';
end;
procedure TF_Invoice10kv.CB_PreviewClick(Sender: TObject);
begin
If CB_Preview.Checked Then
R_Invoice.DeviceType := dtScreen
Else
R_Invoice.DeviceType := dtPrinter;
end;
procedure TF_Invoice10kv.E_GatheringChange(Sender: TObject);
Var
Gathering, GiveChange, Amount: Currency;
begin
Amount := StrToCurr(DBT_Amount.Field.AsString);
Try
Gathering := StrToCurr(E_Gathering.Text);
GiveChange := Gathering - Amount;
E_GiveChange.Text := CurrToStrF(GiveChange, ffGeneral, 2);
Bt_Charge.Enabled := GiveChange >= 0;//收款金额足够
Except
E_GiveChange.Text := '';
Bt_Charge.Enabled := False;
End;
end;
procedure TF_Invoice10kv.Bt_ChargeClick(Sender: TObject);
Var
//实收 本期余额 找零 收款
ActualReceive, GiveChange, Gathering: Currency;
HouseNo: String[8];
HouseName: String[30];
ChargeDate: String[20];
begin
//各种金额
GiveChange := StrToCurr(E_GiveChange.Text);
Gathering := StrToCurr(E_Gathering.Text);
ActualReceive := Gathering - GiveChange;
HouseNo := DBE_House_No.Text;
HouseName := DBE_House_Name.Text;
ChargeDate := DateToStr(Now());
//存储收款记录
DM_10KV.IBSQL.SQL.Clear();
DM_10KV.IBSQL.SQL.Add('Insert Into Tb_10KV_Gathering (f_House_No, f_House_Name, f_Receiver, f_Charge_Date, f_Gathering, f_Give_Change, f_Actual_Receive)');
DM_10KV.IBSQL.SQL.Add(Format(' Values (''%s'', ''%s'', ''%s'', ''%s'', %.2f, %.2f, %.2f)',[HouseNo, HouseName, LoginNo, ChargeDate, Gathering, GiveChange, ActualReceive]));
Try
DM_10KV.IBSQL.ExecQuery();
Except
ShowMessage('此户今日已有收费记录, 原有收费记录将被替换,工作中请仔细!');
DM_10KV.IBSQL.SQL.Clear();
DM_10KV.IBSQL.SQL.Add(Format('Update Tb_10KV_Gathering Set f_House_No = ''%s'', f_House_Name = ''%s'', f_Receiver = ''%s'', f_Gathering = %.2f, f_Give_Change = %.2f, f_Actual_Receive = %.2f',[HouseNo, HouseName, LoginNo, Gathering, GiveChange, ActualReceive]));
DM_10KV.IBSQL.SQL.Add(Format(' Where f_House_No = ''%s'' And f_Charge_Date = ''%s''', [HouseNo, ChargeDate]));
DM_10KV.IBSQL.ExecQuery();
End;
If DM_10KV.IBT_Fee.InTransaction Then
Begin
DM_10KV.IBT_Fee.Commit();
DM_10KV.IBT_Fee.Active := True;//提交后必须激活事务以备后用
End;
Bt_Charge.Enabled := False;//收费完成
If Application.MessageBox('收费完成, 您要立即打印发票吗?','系统提示',MB_YESNO) = IDYES Then
Bt_PrintInvoiceClick(Nil)
Else
Bt_PrintInvoice.Enabled := True;
end;
//根据单价得到收费名称
Function TF_Invoice10kv.f_GetChargeName(Price: Currency):String;
Begin
If Price <> 0 Then
Begin
DM_10KV.IBQ_Price.Close();
DM_10KV.IBQ_Price.ParamByName('Price').AsFloat := Price;
DM_10KV.IBQ_Price.Open();
Result := DM_10KV.IBQ_Price.FieldByName('f_Name').AsString;
if Result = '' Then
ShowMessage(Format('错误:库中未找到单价为 %.3f 的用电类别',[Price]));
End
Else
Result := '';
End;
procedure TF_Invoice10kv.Bt_SwitchClick(Sender: TObject);
begin
F_Invoice400V.Show();
end;
procedure TF_Invoice10kv.Bt_UpdateClick(Sender: TObject);
begin
DM_10KV.Q_Update.SQL.Text := Format('Update "10KV.DBF" Set A12="%s" Where A11="%s"',[E_InvoiceName.Text, DBE_House_No.Text]);
DM_10KV.Q_Update.ExecSQL();
Bt_SearchClick(Nil);
end;
procedure TF_Invoice10kv.DBE_House_NoChange(Sender: TObject);
begin
E_InvoiceName.Text := DM_10KV.Q_10KV.FieldByName('A12').AsString;
end;
procedure TF_Invoice10kv.FormCreate(Sender: TObject);
begin
MyOpenDataset(DM_10KV.Q_10KV);
end;
procedure TF_Invoice10kv.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
MyCloseDataset(DM_10KV.Q_10KV);
MyReleaseForm(TForm(F_Invoice10KV));
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -