kmbalance.cpp

来自「一个以前收集的基于C/S架构的ERP客户端源代码」· C++ 代码 · 共 277 行

CPP
277
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#include "KmBalance.h"
#include "GlbQF.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "QueryBaseForm"
#pragma link "SDGrid"
#pragma link "KSAdvReport"
#pragma resource "*.dfm"

TfrmKmBalance *frmKmBalance;
TfrmGlbQF   *frmGlbQf;
//---------------------------------------------------------------------------
__fastcall TfrmKmBalance::TfrmKmBalance(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
   : TQueryBaseForm(Owner,chWnd,MidCode,WhereStr)
{
   labMemory->Caption="";
   InitGridControl();
   QueryGrid=sgBalance;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::InitGridControl()
{
   sgBalance->Cells[0][0]="科目代码"; sgBalance->Cells[0][1]="科目代码";
   sgBalance->Cells[1][0]="科目名称"; sgBalance->Cells[1][1]="科目名称";
   sgBalance->Cells[2][1]="借方金额";
   sgBalance->Cells[3][1]="贷方金额";
   sgBalance->Cells[4][1]="借方金额";
   sgBalance->Cells[5][1]="贷方金额";
   sgBalance->Cells[6][1]="借方金额";
   sgBalance->Cells[7][1]="贷方金额";
   sgBalance->Cells[8][1]="借方金额";
   sgBalance->Cells[9][1]="贷方金额";
   sgBalance->Cells[10][1]="借方金额";
   sgBalance->Cells[11][1]="贷方金额";
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::tbQueryClick(TObject *Sender)
{
    if(!ShowQueryWindow())
      return;
    try{
      StartWaitForm("正在查询,请稍候...");
      labMemory->Caption="--"+FBfcmonthInfo+","+FBcurrencyInfo;
      FillGridWithData();
    }
    __finally
    {
      EndWaitForm();
    }
}
//---------------------------------------------------------------------------
bool __fastcall TfrmKmBalance::ShowQueryWindow()
{
    frmGlbQf=new TfrmGlbQF(this);
    frmGlbQf->Caption="科目余额表查询过滤";
    frmGlbQf->ShowModal();
    if(frmGlbQf->CancelQuery)
    {
      delete frmGlbQf;
      return false;
    }
    FilterStr=frmGlbQf->CreateSqlString;
    FBfcmonthInfo=frmGlbQf->FmonthInfo;
    FBcurrencyInfo=frmGlbQf->CurrencyInfo;
    delete frmGlbQf;
    return true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::ClearControl(bool BringToNext)
{
    return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::GetDataFromComObject()
{
    return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::WaitUserInput()
{
    return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::RefreshGridData(int mAction)
{
    return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::DisplayBill()
{
    return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::GetBill(AnsiString BillID)
{
    return;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmKmBalance::GetHeadQueryStr()
{
    AnsiString Selectstr,Fromstr,Wherestr,Orderstr;
    Selectstr="select GlbFmonth,GlbGlkm,GlkmName,GlbLevel,GlbDir,GlbBopAmt,GlbBoyAmt,GlbDopAmt,";
    Selectstr+="GlbCopAmt,GlbDoyAmt,GlbCoyAmt";
    Fromstr=" from sdGlb,sdGlkm";
    if(FilterStr=="")
       Wherestr=" where GlbGlkm=GlkmCode";
    else
       Wherestr=" where GlbGlkm=GlkmCode and "+FilterStr;
    Orderstr=" order by GlbFmonth,GlbGlkm";
    sSQL=Selectstr+Fromstr+Wherestr+Orderstr;
    return(sSQL);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmKmBalance::GetSpace(int iNum)
{
    AnsiString strSpace;
    for(int i=1;i<iNum;i++)
      strSpace=strSpace+AnsiString(" ");
    return strSpace;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::FillGridWithData()
{
    TComResultSet *RsQuery;
    AnsiString ItemStr,sSql;
    double m_Balance;
    sSql=GetHeadQueryStr();  //取Head查询的SQL语句
    if(sSql=="")
      return;
    sgBalance->RowCount=2;
    RecentBillCode="";
    RsQuery=new  TComResultSet(Handle,g_ClientHandle);
    RsQuery->Open(sSql,"");
    RsQuery->MoveFirst();
    ItemStr="";

    double JcBopAmt=0,DcBopAmt=0;
    double cDopAmt=0,cCopAmt=0;
    double JcBoyAmt=0,DcBoyAmt=0;
    double cDoyAmt=0,cCoyAmt=0;
    double JcBalance=0,DcBalance=0;

    while(RsQuery->Eof == 0)
    {
      cDopAmt=cDopAmt+RsQuery->FieldByName("GlbDopAmt").ToDouble();
      cCopAmt=cCopAmt+RsQuery->FieldByName("GlbCopAmt").ToDouble();
      cDoyAmt=cDoyAmt+RsQuery->FieldByName("GlbDoyAmt").ToDouble();
      cCoyAmt=cCoyAmt+RsQuery->FieldByName("GlbCoyAmt").ToDouble();
      if(RsQuery->FieldByName("GlbDir")=="1")
      {
        JcBopAmt=JcBopAmt+RsQuery->FieldByName("GlbBopAmt").ToDouble();
        JcBoyAmt=JcBoyAmt+RsQuery->FieldByName("GlbBoyAmt").ToDouble();
      }
      else
      {
        DcBopAmt=DcBopAmt+RsQuery->FieldByName("GlbBopAmt").ToDouble();
        DcBoyAmt=DcBoyAmt+RsQuery->FieldByName("GlbBoyAmt").ToDouble();
      }
      if(RsQuery->FieldByName("GlbDir")==1)
      {
          m_Balance=RsQuery->FieldByName("GlbBopAmt").ToDouble()+RsQuery->FieldByName("GlbDopAmt").ToDouble()
                   -RsQuery->FieldByName("GlbCopAmt").ToDouble();

          if(m_Balance>0)
          {
            ItemStr=GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlbGlkm")+"\t"+
                    GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlkmName")+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBopAmt").ToDouble())+"\t"+AnsiString("")+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBoyAmt").ToDouble())+"\t"+AnsiString("")+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",m_Balance)+"\t"+AnsiString("");
            JcBalance=JcBalance+m_Balance;
          }
          else
          {
            ItemStr=GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlbGlkm")+"\t"+
                    GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlkmName")+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBopAmt").ToDouble())+"\t"+AnsiString("")+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBoyAmt").ToDouble())+"\t"+AnsiString("")+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCoyAmt").ToDouble())+"\t"+
                    AnsiString("")+"\t"+FormatFloat("#,##0.00",-m_Balance);
            DcBalance=DcBalance+(-m_Balance);
          }
      }
      else
      {
          m_Balance=RsQuery->FieldByName("GlbBopAmt").ToDouble()+RsQuery->FieldByName("GlbCopAmt").ToDouble()
                   -RsQuery->FieldByName("GlbDopAmt").ToDouble();

          if(m_Balance>0)
          {
            ItemStr=GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlbGlkm")+"\t"+
                    GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlkmName")+"\t"+
                    AnsiString("")+"\t"+FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCopAmt").ToDouble())+"\t"+
                    AnsiString("")+"\t"+FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCoyAmt").ToDouble())+"\t"+
                    AnsiString("") + "\t" + FormatFloat("#,##0.00",m_Balance);
            DcBalance=DcBalance+m_Balance;
          }
          else
          {
            ItemStr=GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlbGlkm")+"\t"+
                    GetSpace(RsQuery->FieldByName("GlbLevel").ToInt())+RsQuery->FieldByName("GlkmName")+"\t"+
                    AnsiString("")+"\t"+FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDopAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCopAmt").ToDouble())+"\t"+
                    AnsiString("")+"\t"+FormatFloat("#,##0.00",RsQuery->FieldByName("GlbBoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbDoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",RsQuery->FieldByName("GlbCoyAmt").ToDouble())+"\t"+
                    FormatFloat("#,##0.00",-m_Balance)+"\t"+AnsiString("");
            JcBalance=JcBalance+(-m_Balance);
          }
      }
      sgBalance->AddItem(ItemStr);
      RsQuery->MoveNext();
    }
    ItemStr=AnsiString("")+"\t"+"合计:"+"\t"+FormatFloat("#,##0.00",JcBopAmt)+"\t"+FormatFloat("#,##0.00",DcBopAmt)+"\t";
    ItemStr+= FormatFloat("#,##0.00",cDopAmt)+"\t"+FormatFloat("#,##0.00",cCopAmt)+"\t";
    ItemStr+= FormatFloat("#,##0.00",JcBoyAmt)+"\t"+FormatFloat("#,##0.00",DcBoyAmt)+"\t";
    ItemStr+= FormatFloat("#,##0.00",cDoyAmt)+"\t"+FormatFloat("#,##0.00",cCoyAmt)+"\t";
    ItemStr+= FormatFloat("#,##0.00",JcBalance)+"\t"+FormatFloat("#,##0.00",DcBalance);
    sgBalance->AddItem(ItemStr);
    RsQuery->Close();
    delete RsQuery;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::muFirstClick(TObject *Sender)
{
    if(sgBalance->RowCount > 1)
      sgBalance->Row=2;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::muNextClick(TObject *Sender)
{
    if(sgBalance->RowCount > 1 && sgBalance->Row < sgBalance->RowCount-1)
       sgBalance->Row=sgBalance->Row+1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::muLastClick(TObject *Sender)
{
    if(sgBalance->RowCount > 1)
       sgBalance->Row=sgBalance->RowCount-1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::muPreviousClick(TObject *Sender)
{
    if(sgBalance->RowCount > 1 && sgBalance->Row > 1)
       sgBalance->Row=sgBalance->Row-1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmKmBalance::tbRefreshClick(TObject *Sender)
{
    if(sSQL=="")
       return;
    FillGridWithData();
}
//---------------------------------------------------------------------------

void __fastcall TfrmKmBalance::FormShow(TObject *Sender)
{
    tbQueryClick(this);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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