⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invoiceprintbrowsefrm.pas

📁 供水营销打印程序源码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  // 程序默认从用户选择的当前位置开始打印
  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 + -