?? invoiceprintbrowsefrm.pas
字號:
unit InvoicePrintBrowseFrm;
interface
{$I InvPrinter.inc}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SJCustomBrowseFrm, wwDialog, wwfltdlg, ActnList, XPMenu, Menus,
PropStorageEh, Grids, DBGridEh, ExtCtrls, StdCtrls, cxControls, IniFiles,
cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDBEdit, cxCheckBox,
cxDropDownEdit, cxCalendar, cxLookAndFeelPainters, cxButtons,
cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, ImgList, fcLabel,
cxSpinEdit, RM_FormReport, RM_Desgn;
type
TfrmBrowseInvoicePrint = class(TSJCustomBrowseForm)
ControlPanel: TPanel;
Label1: TLabel;
edtCustID: TcxDBMaskEdit;
Label2: TLabel;
Label3: TLabel;
edtInvoice: TcxMaskEdit;
chkStopUpdateInvoice: TcxCheckBox;
Label4: TLabel;
edtPaydate: TcxDateEdit;
Label5: TLabel;
Label6: TLabel;
edtPriorQty: TcxDBMaskEdit;
Label7: TLabel;
edtDerate: TcxDBMaskEdit;
Label8: TLabel;
edtQty: TcxDBMaskEdit;
Label9: TLabel;
btnPrint: TcxButton;
chkShowall: TcxCheckBox;
chkSeriesPrint: TcxCheckBox;
actBrowseLoadSetting: TAction;
cxButton1: TcxButton;
actBrowsePrintSetting: TAction;
L1: TMenuItem;
actBrowseMonthChargeGroupReport: TAction;
T1: TMenuItem;
N6: TMenuItem;
edtName: TcxLookupComboBox;
actBrowsePrintInvoice: TAction;
edtCurrQty: TcxDBMaskEdit;
edtBigAmont: TcxDBMaskEdit;
InvoicePanel: TPanel;
Label10: TLabel;
edtCustomer: TcxLookupComboBox;
Label11: TLabel;
edtInvoiceNO: TcxMaskEdit;
spinYear: TcxSpinEdit;
Label12: TLabel;
spinMonth: TcxSpinEdit;
Label13: TLabel;
spinDay: TcxSpinEdit;
Label14: TLabel;
DBGridEh1: TDBGridEh;
Label18: TLabel;
edtCharge: TcxLookupComboBox;
Label19: TLabel;
Label20: TLabel;
edtCompany: TcxMaskEdit;
btnPrintInvoice: TcxButton;
chkSeriesPrint1: TcxCheckBox;
chkShowAll1: TcxCheckBox;
edtCollector: TcxLookupComboBox;
Panel1: TPanel;
BigAmontPanel: TPanel;
Bevel2: TBevel;
Panel2: TPanel;
Label15: TLabel;
Label16: TLabel;
Shape1: TShape;
AmontPanel: TPanel;
Splitter1: TSplitter;
Panel3: TPanel;
Label17: TLabel;
Bevel4: TBevel;
Shape2: TShape;
labBigAmont: TfcLabel;
fcLabel1: TfcLabel;
Label21: TLabel;
fcLabel2: TfcLabel;
actBrowseBlankoutInvoice: TAction;
B1: TMenuItem;
N7: TMenuItem;
R2: TMenuItem;
N8: TMenuItem;
actBrowseMonthChargeDetailReport: TAction;
procedure FormCreate(Sender: TObject);
procedure edtCustIDExit(Sender: TObject);
procedure chkShowallClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure edtCustIDKeyPress(Sender: TObject; var Key: Char);
procedure actBrowsePrintExecute(Sender: TObject);
procedure actBrowsePrintSettingExecute(Sender: TObject);
procedure actBrowseLoadSettingExecute(Sender: TObject);
procedure actBrowseMonthChargeGroupReportExecute(Sender: TObject);
procedure edtNamePropertiesCloseUp(Sender: TObject);
procedure edtNamePropertiesInitPopup(Sender: TObject);
procedure DBGridEh1ColWidthsChanged(Sender: TObject);
procedure edtCustomerPropertiesChange(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure actBrowseBlankoutInvoiceExecute(Sender: TObject);
private
FPrinting, FopPreview, FopShowDialog: Boolean;
FopInvoiceLength: Integer;
FopCompany, FopAddress, FopItem, FopUnits, FopCollector: string;
FopStartInv, FopEndInv, FopCurrInvoice: string;
procedure LocateRecord;
procedure LoadSetting;
procedure SaveCurrInvoice;
function PrepareData: Boolean;
public
property Item: string read FopItem;
property Units: string read FopUnits;
end;
var
frmBrowseInvoicePrint: TfrmBrowseInvoicePrint;
implementation
uses InvPrintDM, MainFrm, SJInvPrintGlobal, sjUtils, OptionsPropertyFrm,
BlankoutInvoicePropertyFrm, MonthStatReportDialogFrm;
{$R *.dfm}
procedure TfrmBrowseInvoicePrint.FormCreate(Sender: TObject);
begin
inherited;
FPrinting := False;
LoadSetting;
end;
procedure TfrmBrowseInvoicePrint.edtCustIDExit(Sender: TObject);
// 顯示用戶選定的客戶未繳費資料
begin
inherited;
if not edtCustID.EditModified then
Exit;
LocateRecord;
end;
procedure TfrmBrowseInvoicePrint.chkShowallClick(Sender: TObject);
// 顯示所有未打印發票的用水記錄
begin
inherited;
if not {$IFDEF DJSR}chkShowAll1.Checked{$ELSE}chkShowAll.Checked{$ENDIF DJSR} then
with dmInvPrint.AqryPrint do
begin
Close;
SQL.Clear;
SQL.Add('select * from Waterfee where CustID = ''9999999999'' and Payflag = False');
Open;
Exit;
end;
with dmInvPrint.AqryPrint do
try
Screen.Cursor := crHourGlass;
Close;
SQL.Clear;
SQL.Add('select * from Waterfee where Payflag = False order by CustID, WRID');
try
Open;
except
ShowMessage('打開未打印發票的客戶用水資料時失敗,請稍后再試 。');
Exit;
end;
if not IsEmpty then
btnPrint.SetFocus
else
ShowMessage('當前還沒有未打印發票的用水記錄 。');
actBrowsePrint.Enabled := not IsEmpty;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TfrmBrowseInvoicePrint.FormShow(Sender: TObject);
var
Ayear, Amonth, Aday: Word;
begin
inherited;
edtPaydate.Date := Date;
edtCustID.SetFocus;
edtInvoice.Text := FopCurrInvoice;
edtInvoice.Properties.MaxLength := FopInvoiceLength;
// 顯示廣東省商品統一發票相關字段信息
{$IFDEF DJSR}
DecodeDate(Date, Ayear, Amonth, Aday);
spinYear.Value := Ayear;
spinMonth.Value := Amonth;
spinDay.Value := Aday;
edtCharge.EditValue := GUserID;
edtCollector.EditValue := FopCollector;
edtCompany.Text := FopCompany;
edtInvoiceNO.Text := FopCurrInvoice;
edtInvoiceNO.Properties.MaxLength := FopInvoiceLength;
edtCustomer.SetFocus;
{$ENDIF DJSR}
end;
procedure TfrmBrowseInvoicePrint.edtCustIDKeyPress(Sender: TObject;
var Key: Char);
begin
inherited;
if Key = #13 then
edtCustIDExit(Sender);
end;
procedure TfrmBrowseInvoicePrint.actBrowsePrintExecute(Sender: TObject);
// 打印發票
const
ReportTitle = '廣東省商品銷售統一發票';
var
ARepfile, Astr: string;
APrintCount: Integer;
procedure ResetMtabPrint;
// 打開內存表,并清空
begin
with dmInvPrint.mtabPrint do
begin
Close;
Open;
Last;
while not Bof do
begin
Delete; Prior;
end;
end;
end;
function PrintRecord: Boolean;
// 打印一筆用水記錄
var
ARepared: Boolean;
AID: Integer;
Ayear, Amonth, Aday: Word;
APayment: Double;
APaydate: TDateTime;
AInvoice: string;
begin
ResetMtabPrint;
ARepared := PrepareData; // 準備數據
if not ARepared then
begin
Result := ARepared;
Exit;
end;
with dmInvPrint, dmInvPrint.AqryPrint do
begin
AID := FieldByName('WRID').AsInteger;
APayment := FieldByName('Amont').AsFloat;
// 此處沒有考慮多用戶并發操作,嚴格的應該從全局文件中取出當前發票號碼
{$IFDEF DJSR}
Ayear := spinYear.Value;
Amonth := spinMonth.Value;
Aday := spinDay.Value;
APaydate := EncodeDate(Ayear, Amonth, Aday);
AInvoice := edtInvoiceNO.Text;
{$ELSE}
APaydate := edtPaydate.Date;
AInvoice := edtInvoice.Text;
{$ENDIF DJSR}
if not ChargeWaterfee(AID, True, APayment, APaydate, FopCollector, AInvoice) then
begin
ShowMessage('保存打印信息失敗,請稍后再試 。');
Result := False;
Exit;
end;
RMDataSet.DataSet := mtabPrint;
RMReport.Title := ReportTitle + Format(',發票號:%s', [{$IFDEF DJSR}edtInvoiceNO.Text{$ELSE}edtInvoice.Text{$ENDIF DJSR}]);
RMReport.PrepareReport;
// 只在第一次打印時允許用戶進行格式設置
if APrintCount > 1 then
RMReport.PrintPreparedReportDlg
else
if FopPreview then // 預覽
RMReport.ShowReport
else
if FopShowDialog then // 顯示打印對話框
RMReport.PrintReport
else
RMReport.PrintPreparedReportDlg; // 直接打印
// 更新發票號碼,此處沒有考慮多用戶并發操作
if not chkStopUpdateInvoice.Checked then
{$IFDEF DJSR}
edtInvoiceNO.Text := PrefixStr('0', IntToStr(StrToInt(edtInvoiceNO.Text) + 1), FopInvoiceLength);
{$ELSE}
edtInvoice.Text := PrefixStr('0', IntToStr(StrToInt(edtInvoice.Text) + 1), FopInvoiceLength);
{$ENDIF}
end;
Result := True;
end;
procedure RefreshTable;
begin
with dmInvPrint.AqryPrint do
try
Close;
Open;
except
ShowMessage('刷新當前已經打印的資料時失敗 。');
end;
end;
function IsSeriesPrint: Boolean;
// 檢查是否需要連續打印所有發票
begin
Result := {$IFDEF DJSR}chkSeriesPrint1.Checked {$ELSE} chkSeriesPrint.Checked{$ENDIF DJSR};
end;
function CheckInvoice: Boolean;
// 檢查發票號碼是否已經用完
begin
{$IFDEF DJSR}
Result := (StrToInt(edtInvoiceNO.Text) >= StrToInt(FopStartInv)) and (StrToInt(edtInvoiceNO.Text) <= StrToInt(FopEndInv));
{$ELSE}
Result := (StrToInt(edtInvoice.Text) >= StrToInt(FopStartInv)) and (StrToInt(edtInvoice.Text) <= StrToInt(FopEndInv));
{$ENDIF DJSR}
end;
begin
//inherited;
LoadSetting; // 加載打印選項
ARepfile := ExtractFilePath(Application.ExeName) + 'Report\' + ReportTitle + '.rmf';
if not FileExists(ARepfile) then
begin
ShowMessage(Format('發票格式文件 “%s” 丟失,請與系統開發商聯系 。', [ReportTitle]));
Exit;
end;
try
{$IFDEF DJSR}
StrToInt(edtInvoiceNO.Text);
{$ELSE}
StrToInt(edtInvoice.Text);
{$ENDIF DJSR}
except
ShowMessage('你沒有輸入正確的發票號碼,請確認后再試 。');
{$IFDEF DJSR}
edtInvoiceNO.SetFocus;
{$ELSE}
edtInvoice.SetFocus;
{$ENDIF DJSR}
Exit;
end;
if not CheckInvoice then
begin
ShowMessage('您領用的發票已經使用完,請重新設置開始和結束號碼 。');
Exit;
end;
// 詢問用戶是否打印發票
if IsSeriesPrint then
Astr := Format('當前一共有 %d 筆數據,請準備好發票。現在打印嗎?', [dmInvPrint.AqryPrint.RecordCount])
else
Astr := '請準備好發票,現在就打印這筆數據嗎?';
if Application.MessageBox(Pchar(Astr), Pchar('提示'), MB_YESNO) = IDNO then
Exit;
if grdBrowse.DataSource.DataSet.IsEmpty then
begin
ShowMessage('當前沒有待打印的發票資料 。');
Exit;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -