?? invoiceprintbrowsefrm.pas
字號:
// 程序默認從用戶選擇的當前位置開始打印
Screen.Cursor := crHourGlass;
APrintCount := 1;
with dmInvPrint, dmInvPrint.AqryPrint do
try
FPrinting := True;
DisableControls;
RMReport.FileName := ARepfile;
RMReport.Title := ReportTitle;
RMReport.ShowProgress := False;
RMReport.ShowPrintDialog := FopShowDialog;
RMReport.LoadFromFile(ARepfile);
// 逐條打印發票
while not Eof do
begin
if not PrintRecord then
if RecordCount > 1 then
begin
if Application.MessageBox(Pchar(Format('打印第 %d 張發票失敗,號碼為:%s ,要繼續打印余下的發票嗎?',
[APrintCount, edtInvoice.Text])), Pchar('提示'), MB_YESNO) = IDNO then
Break;
end else
ShowMessage(Format('打印第 %d 張發票失敗,號碼為:%s ,要繼續打印余下的發票嗎?', [APrintCount, edtInvoice.Text]));
if not IsSeriesPrint then // 如果不是連續打印則退出
Break;
RMReport.ShowPrintDialog := False;
APrintCount := APrintCount + 1;
Next;
end;
RefreshTable;
finally
EnableControls;
FPrinting := False;
Screen.Cursor := crDefault;
end;
end;
procedure TfrmBrowseInvoicePrint.LoadSetting;
// 加載系統選項
var
Afilename: string;
begin
Afilename := ExtractFilePath(Application.ExeName) + 'DjsrInvPrinter.ini';
if not FileExists(Afilename) then
begin
FopCompany := '';
FopAddress := '';
FopCollector := '00000';
FopItem := '自來水';
FopUnits := '立方米';
FopPreview := True;
FopStartInv := '00000001';
FopEndInv := '99999999';
FopCurrInvoice := '';
FopInvoiceLength := 8;
Exit;
end;
with TIniFile.Create(Afilename) do
try
// 單位信息
if SectionExists('Normal') then
begin
if ValueExists('Normal', 'Company') then
FopCompany := ReadString('Normal', 'Company', '');
if ValueExists('Normal', 'Address') then
FopAddress := ReadString('Normal', 'Address', '');
end;
// 發票信息
if SectionExists('Invoice') then
begin
if ValueExists('Invoice', 'InvoiceLength') then
FopInvoiceLength := ReadInteger('Invoice', 'InvoiceLength', 8);
if ValueExists('Invoice', 'StartInv') then
FopStartInv := ReadString('Invoice', 'StartInv', '00000001');
if ValueExists('Invoice', 'EndInv') then
FopEndInv := ReadString('Invoice', 'EndInv', '99999999');
if ValueExists('Invoice', 'CurrInvoice') then
FopCurrInvoice := ReadString('Invoice', 'CurrInvoice', '');
end;
// 打印信息
if SectionExists('Print') then
begin
if ValueExists('Print', 'Collector') then
FopCollector := ReadString('Print', 'Collector', '00000');
if ValueExists('Print', 'Units') then
FopUnits := ReadString('Print', 'Units', '立方米');
if ValueExists('Print', 'Item') then
FopItem := ReadString('Print', 'Item', '自來水銷售');
if ValueExists('Print', 'Preview') then
FopPreview := ReadBool('Print', 'Preview', True);
if ValueExists('Print', 'ShowDialog') then
FopShowDialog := ReadBool('Print', 'ShowDialog', True);
end;
finally
Free;
end;
end;
procedure TfrmBrowseInvoicePrint.actBrowsePrintSettingExecute(
Sender: TObject);
// 打印設置
begin
inherited;
with TfrmPropertyOptions.Create(Application) do
try
PageControl.ActivePageIndex := 1;
ShowModal;
LoadSetting;
finally
Free;
end;
end;
procedure TfrmBrowseInvoicePrint.actBrowseLoadSettingExecute(
Sender: TObject);
// 加載打印選項
begin
inherited;
LoadSetting;
end;
function TfrmBrowseInvoicePrint.PrepareData: Boolean;
// 準備打印數據,此處假設在調用函數時已經清空內存表
var
Ayear, Amonth, Aday: Word;
function GetPaydate: TDateTime;
// 獲取當前開票日期
begin
{$IFDEF DJSR}
Ayear := spinYear.Value;
Amonth := spinMonth.Value;
Aday := spinDay.Value;
Result := EnCodeDate(Ayear, Amonth, Aday);
{$ELSE}
Result := edtPaydate.Date;
{$ENDIF DJSR}
end;
function GetCharge: string;
// 開票人
begin
{$IFDEF DJSR}
Result := edtCharge.Text;
{$ELSE}
Result := GUserName;
{$ENDIF DJSR}
end;
begin
Result := False;
with dmInvPrint, dmInvPrint.mtabPrint do
try
Append;
FieldByName('CustID').AsString := AqryPrint.FieldByName('CustID').AsString;
FieldByName('Name').AsString := AqryPrint.FieldByName('Name').AsString;
FieldByName('Address').AsString := AqryPrint.FieldByName('Address').AsString;
FieldByName('Item').AsString := FopItem;
FieldByName('Units').AsString := FopUnits;
FieldByName('Qty').AsFloat := AqryPrint.FieldByName('Quantity').AsFloat;
FieldByName('Amont').AsCurrency := AqryPrint.FieldByName('Amont').AsCurrency;
FieldByName('Price').AsCurrency := AqryPrint.FieldByName('sPrice').AsCurrency;
FieldByName('BigAmont').AsString := AqryPrint.FieldByName('BigAmont').AsString;
FieldByName('Username').AsString := GetCharge;
FieldByName('Collector').AsString := {$IFDEF DJSR}edtCollector.Text{$ELSE}GetUserName(FopCollector){$ENDIF DJSR};
FieldByname('Paydate').AsDateTime := GetPaydate;
FieldByName('Company').AsString := {$IFDEF DJSR}edtCompany.Text{$ELSE}FopCompany{$ENDIF DJSR};
Post;
except
end;
Result := True;
end;
procedure TfrmBrowseInvoicePrint.actBrowseMonthChargeGroupReportExecute(
Sender: TObject);
var
ARepfile, ReportTitle: string;
AYear, Amonth, Aday: Word;
Adate1, Adate2: TDateTime;
begin
inherited;
ReportTitle := '每月供水銷售%s匯總表';
case TAction(Sender).Tag of
1 : ReportTitle := Format(ReportTitle, ['分組']);
2 : ReportTitle := Format(ReportTitle, ['明細']);
end;
ARepfile := ExtractFilePath(Application.ExeName) + 'Report\' + ReportTitle + '.rmf';
if not FileExists(ARepfile) then
begin
ShowMessage('發票格式文件丟失,請與系統開發商聯系 。');
Exit;
end;
// 顯示打印日期對話框
DecodeDate(Date, Ayear, Amonth, Aday);
Adate1 := EncodeDate(Ayear, Amonth, 1);
Adate2 := EncodeDate(Ayear, Amonth, DaysPerMonth(Ayear, Amonth));
with TfrmDialogMonthStatReport.Create(Application) do
try
edtStartdate.Date := Adate1;
edtEnddate.Date := Adate2;
if ShowModal = mrCancel then
Exit;
Adate1 := edtStartdate.Date;
Adate2 := edtEnddate.Date;
finally
Free;
end;
Screen.Cursor := crHourGlass;
with dmInvPrint, dmInvPrint.AqryMonthChargeReport do
try
Close;
SQL.Clear;
case TAction(Sender).Tag of
1 : SQL.Add('select * from Waterfee where Payflag = True and Paydate between :Paydate1 and :Paydate2 order by Blankoutflag, Invoice, Paydate');
2 : SQL.Add('select * from Waterfee where Payflag = True and Paydate between :Paydate1 and :Paydate2 order by Invoice, Paydate');
end;
Parameters.ParamByName('Paydate1').Value := Adate1;
Parameters.ParamByName('Paydate2').Value := Adate2;
try
Open;
except
ShowMessage('打開本月數據時失敗,請稍后再試 。');
Exit;
end;
// 預覽報表
RMDataSet.DataSet := AqryMonthChargeReport;
RMReport.FileName := ARepfile;
RMReport.Title := ReportTitle;
RMReport.LoadFromFile(ARepfile);
RMReport.PrepareReport;
RMReport.ShowReport;
finally
Close;
Screen.Cursor := crDefault;
end;
end;
procedure TfrmBrowseInvoicePrint.edtNamePropertiesCloseUp(Sender: TObject);
// 查詢當前客戶用水記錄
begin
inherited;
{$IFDEF DJSR}
edtCustID.Text := edtCustomer.EditValue;
{$ELSE}
edtCustID.Text := edtName.EditValue;
{$ENDIF DJSR}
LocateRecord;
end;
procedure TfrmBrowseInvoicePrint.edtNamePropertiesInitPopup(
Sender: TObject);
// 如果沒有打開數據庫,則打開它
begin
inherited;
with dmInvPrint.AtabCustomer do
if not Active then
Open;
end;
procedure TfrmBrowseInvoicePrint.LocateRecord;
// 顯示用戶選定的客戶未繳費資料
var
Aid: string;
begin
try
StrToInt(edtCustID.Text);
except
ShowMessage('您輸入的客戶編號不合法,請重新輸入。'#13#10'正確的形式為:001, 2864023');
Exit;
end;
Aid := PrefixStr('0', Trim(edtCustID.Text), 8);
Screen.Cursor := crHourGlass;
with dmInvPrint.AqryPrint do
try
Close;
SQL.Clear;
SQL.Add(Format('select * from Waterfee where CustID = ''%s'' and Payflag = False', [Aid]));
try
Open;
except
ShowMessage('打開客戶未打印發票資料時失敗,請稍后再試 。');
Exit;
end;
if not IsEmpty then
{$IFDEF DJSR}
btnPrintInvoice.SetFocus
{$ELSE}
btnPrint.SetFocus;
{$ENDIF DJSR}
else begin
ShowMessage('當前的客戶目前還沒有未打印發票的用水記錄 。');
{$IFDEF DJSR}
edtCustomer.SetFocus;
{$ELSE}
edtCustID.SetFocus;
{$ENDIF DJSR}
end;
//actBrowsePrint.Enabled := not IsEmpty;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TfrmBrowseInvoicePrint.DBGridEh1ColWidthsChanged(
Sender: TObject);
begin
inherited;
with DBGridEh1 do
BigAmontPanel.Width := Columns[0].Width + Columns[1].Width + Columns[2].Width +
Columns[3].Width + 4;
end;
procedure TfrmBrowseInvoicePrint.edtCustomerPropertiesChange(
Sender: TObject);
begin
inherited;
{$IFDEF DJSR}
edtCustID.Text := edtCustomer.EditValue;
LocateRecord;
{$ENDIF DJSR}
end;
procedure TfrmBrowseInvoicePrint.SaveCurrInvoice;
// 保存當前發票號碼
var
Afilename: string;
begin
Afilename := ExtractFilePath(Application.ExeName) + 'DjsrInvPrinter.ini';
with TIniFile.Create(Afilename) do
try
{$IFDEF DJSR}
if Trim(edtInvoiceNO.Text) <> '' then
WriteString('Invoice', 'CurrInvoice', edtInvoiceNO.Text);
{$ELSE}
if Trim(edtInvoice.Text) <> '' then
WriteString('Invoice', 'CurrInvoice', edtInvoice.Text);
{$ENDIF DJSR}
finally
Free;
end;
end;
procedure TfrmBrowseInvoicePrint.FormDestroy(Sender: TObject);
begin
inherited;
SaveCurrInvoice;
end;
procedure TfrmBrowseInvoicePrint.actBrowseBlankoutInvoiceExecute(
Sender: TObject);
// 作廢發票
begin
inherited;
with TfrmPropertyBlankoutInvoice.Create(Application) do
try
ShowModal;
finally
Free;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -