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

📄 myprint.cpp

📁 企业员工考勤和工资管理系统
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MyPrint.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMyPrint *FormMyPrint;
//---------------------------------------------------------------------------
__fastcall TFormMyPrint::TFormMyPrint(TComponent* Owner)
        : TForm(Owner)
{
  for(int i=0;i<50;i++)
     {
      Label[i]= NULL;
      Text[i]= NULL;
      CLine[i]= NULL;
      DLine[i]= NULL;
     }
}

//--------------------------------------------------------------------
__fastcall TFormMyPrint::~TFormMyPrint()
{
      for(int i = 0; i < 50; i++)
      {
        if(Text[i])
        {
          delete Text[i];

        }
        if(Label[i])
        {
          delete Label[i];

        }
        if(CLine[i])
        {
          delete CLine[i];

        }
        if(DLine[i])
        {
          delete DLine[i];

        }
      }
}

//------------------------------------------------------
void __fastcall TFormMyPrint::SetLabel(TDBGrid * pGrid,TDataSet *pDataSet)
{
   int nRow,nLeft;
   //nColumnHeight,nDetailHeight;
   nRow = 0;
   nLeft = 0;
   //nColumnHeight = nDetailHeight = 0;

   for(int m = 0; m < 50; m++)
      {
        if(Text[m])
        {
          delete Text[m];
          Text[m] = NULL;
        }
        if(Label[m])
        {
          delete Label[m];
          Label[m] = NULL;
        }
        if(CLine[m])
        {
          delete CLine[m];
          CLine[m] = NULL;
        }
        if(DLine[m])
        {
          delete DLine[m];
          DLine[m] = NULL;
        }
      }

   QuickRep1->DataSet = pDataSet;

   column->Height =  pGrid->Columns->Items[0]->Title->Font->Height * -1 + 18 ;
   detail->Height =  pGrid->Columns->Items[0]->Font->Height * -1 + 5;


   for(int i=0;i<pGrid->Columns->Count;i++)
   {
     if (pGrid->Columns->Items[i]->Visible == false) continue;

     Label[nRow] =new TQRLabel(this);
     Label[nRow]->Parent = column;
     Label[nRow]->Alignment=taCenter;
     Label[nRow]->Caption = pGrid->Columns->Items[i]->Title->Caption;
     Label[nRow]->Font->Assign(pGrid->Columns->Items[i]->Title->Font);
     Label[nRow]->AutoSize = false;
     Label[nRow]->Top = 5;
     Label[nRow]->Left = nLeft + 1;
     Label[nRow]->Width = pGrid->Columns->Items[i]->Width;
     /*if (nColumnHeight == 0)
     {
      nColumnHeight = Label[nRow]->Height;
      column->Height = nColumnHeight + 10;
     } */

     Text[nRow] =new TQRDBText(this);
     Text[nRow]->Parent = detail;
     Text[nRow]->DataSet = pDataSet;
     Text[nRow]->DataField = pGrid->Columns->Items[i]->FieldName;

     Text[nRow]->Font->Assign(pGrid->Columns->Items[i]->Font);
     Text[nRow]->AutoSize= false;
     /*if (nDetailHeight == 0)
     {
     nDetailHeight = Text[nRow]->Height;
     detail->Height = nDetailHeight + 5;
     } */
     /*if (pDataSet->FieldByName(Text[nRow]->DataField)->DataType == ftFloat || pDataSet->FieldByName(Text[nRow]->DataField)->DataType == ftInteger)
        {
        Text[nRow]->Alignment=taRightJustify;
        }
      else
        Text[nRow]->Alignment=taLeftJustify;
     */
     if (pDataSet->FieldByName(Text[nRow]->DataField)->DataType == ftString)
     Text[nRow]->Alignment=taLeftJustify;
     else Text[nRow]->Alignment=taRightJustify;

     Text[nRow]->Top = 0;
     Text[nRow]->Left = nLeft + 1;
     Text[nRow]->Width = pGrid->Columns->Items[i]->Width;
     Text[nRow]->Height = pGrid->Columns->Items[i]->Font->Height * -1;

     nLeft = nLeft + pGrid->Columns->Items[i]->Width + 2;

     CLine[nRow] = new TQRShape(this);
     CLine[nRow]->Parent = column;
     CLine[nRow]->Shape=qrsVertLine;
     CLine[nRow]->Width = 1;
     CLine[nRow]->Height = column->Height;
     CLine[nRow]->Top = 0;
     CLine[nRow]->Left = nLeft;

     DLine[nRow] = new TQRShape(this);
     DLine[nRow]->Parent = detail;
     DLine[nRow]->Shape=qrsVertLine;
     DLine[nRow]->Width = 1;
     DLine[nRow]->Height = detail->Height;
     DLine[nRow]->Top = -2;
     DLine[nRow]->Left = nLeft;

     nLeft = nLeft + 1;
     nRow++;
   }
   QRShapeCLeft->Left = 0;
   QRShapeCLeft->Height = column->Height;
   QRShapeCLeft->Top =0;

   QRShapeDLeft->Left = 0;
   QRShapeDLeft->Height = detail->Height;
   QRShapeDLeft->Top =-1;

   QRShapeCTop->Top = 0;
   QRShapeCTop->Left = 0;
   QRShapeCTop->Width = nLeft -1;

   QRShapeCBottom->Top = column->Height -5;
   QRShapeCBottom->Left = 0;
   QRShapeCBottom->Width = nLeft -1;

   QRShapeDBottom->Top = Text[0]->Top + Text[0]->Height +2;
   QRShapeDBottom->Left = 0;
   QRShapeDBottom->Width = nLeft -1;

   QRLabelTitle1->Left = (nLeft - QRLabelTitle1->Width)/2;

}
//---------------------------------------------

void __fastcall TFormMyPrint::repPreview()
{
  QuickRep1->Preview();
}

//-----------------------------------------------------------
void __fastcall TFormMyPrint::repPrint()
{
  QuickRep1->Print();
}

//---------------------------------------------------------------------------
void __fastcall TFormMyPrint::SetTitle(AnsiString sTitle,TPersistent *pFont)
{
  QRLabelTitle1->Caption = sTitle;
  QRLabelTitle1->Font->Assign(pFont);
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -