apcavh.cpp

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

CPP
412
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Apcavh.h"
#include "Apcavd.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "BillBaseForm"
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "GenBaseForm"
#pragma resource "*.dfm"
TfrmApcavh *frmApcavh;
//---------------------------------------------------------------------------
__fastcall TfrmApcavh::TfrmApcavh(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
        : TGenBaseForm(Owner,chWnd,MidCode,WhereStr)
{
SetAutoCodeString(seApcavhCode,"Acm-55");
   m_Amt="0";
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::ClearControl(int Section,bool BringToNext)
{
   if (Section == 1)
   {
      if (!BringToNext)
      {
        seApcavhCode->Text   ="";  //核销单号
        deApcavhDate->Text   =g_sdCurDate;  //日期
        scApcavhDocType->ItemIndex=0;  //单据类型
        seApcavhDocCode->Text   ="";  //单据号
        memApcavhDesc->Text   ="";  //备注
        lbApcavhUser->Caption =g_sdUserCode;  //操作员
        chkApcavhCheck->Checked     =false;  //审核标志
        lbApcavhChecker->Caption    ="";  //审核人
        lbApcavhCheckDate->Caption  ="";  //审核日期
        lbApcavhSysDate->Caption    ="";  //系统日期
      }
      sgApcavh->RowCount=1;
   }
   else if (Section==2)
   {
      if (!BringToNext)
      {
        seApcavdLine->Text   =AnsiString(comServer->ItemCount+1);  //行号
        scApcavdDocType->ItemIndex=-1;  //单据类型
        seApcavdDocCode->Text   ="";  //单据号
        seApcavdDocLine->Text   ="";  //单据行号
        seApcavdConv->Text   ="";  //换算系数
        seApcavdPAmt->Text   ="";  //付款数
        seApcavdCAmt->Text   ="";  //核销额
        memApcavdDesc->Text   ="";  //备注
      }
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::InitEditControl()
{
   ClientGroup->AddComponent(1,false,false,true,fpApcavhHead,fpApcavhHead->Name);
   ClientGroup->AddComponent(2,true,true,true,fpApcavhDetail,fpApcavhDetail->Name);
   ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
   ClientGroup->AddComponent(2,false,true,true,btnOK,btnOK->Name);
   ClientGroup->AddComponent(1,false,true,false,seApcavhCode,seApcavhCode->Name);
   ClientGroup->AddComponent(1,false,true,true,scApcavhDocType,scApcavhDocType->Name);
   ClientGroup->AddComponent(1,false,true,true,seApcavhDocCode,seApcavhDocCode->Name);

   scApcavdDocType->AddItems("应付发票","1");
   scApcavdDocType->AddItems("应付单","2");

   scApcavhDocType->AddItems("付款单","1");
   scApcavhDocType->AddItems("预付单","2");
   scApcavhDocType->AddItems("票据付款","3");

}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmApcavh::GetDataToGrid()
{
    AnsiString  s;
   s = "\t" + GetDetailValue("ApcavdLine")    +
       "\t" + GetDetailValue("ApcavdDocCode")    +
       "\t" + GetDetailValue("ApcavdDocLine")    +
       "\t" + GetDetailValue("ApcavdConv")    +
       "\t" + GetDetailValue("ApcavdPAmt")    +
       "\t" + GetDetailValue("ApcavdCAmt")    ;
    return s;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::RefreshGridData(int mAction)
{
    int i;
    AnsiString ItemStr;
    switch(mAction)
    {
       case 0: // Append
         ItemStr=GetDataToGrid();
         sgApcavh->AddItem(ItemStr);
         break;
       case 1: // Modify
         sgApcavh->ChangeItem(ItemStr,sgApcavh->Row);
         break;
       case 2: // Delete
         sgApcavh->RemoveItem(sgApcavh->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::GetDataFromComObject(int Section)
{
   if (Section==1)
   {
      seApcavhCode->Text   = GetHeadValue("ApcavhCode");
      deApcavhDate->Text   = GetHeadValue("ApcavhDate");
      scApcavhDocType->LocateKey(GetHeadValue("ApcavhDocType"));
      scApcavhDocType->Text   =scApcavhDocType->ItemData[0];
      seApcavhDocCode->Text   = GetHeadValue("ApcavhDocCode");
      memApcavhDesc->Text   = GetHeadValue("ApcavhDesc");
      lbApcavhUser->Caption   =GetHeadValue("ApcavhUser");
      chkApcavhCheck->Checked = (GetHeadValue("ApcavhCheck")=="1"?true:false);
      if(chkApcavhCheck->Checked)
        SetCheckToolbarStatus(true);
      else
        SetCheckToolbarStatus(false);
      lbApcavhChecker->Caption = GetHeadValue("ApcavhChecker");
      lbApcavhCheckDate->Caption= GetHeadValue("ApcavhCheckDate");
      lbApcavhSysDate->Caption = GetHeadValue("ApcavhSysDate");
   }
   else
   {
      seApcavdLine->Text   = GetDetailValue("ApcavdLine");
      scApcavdDocType->LocateKey(GetDetailValue("ApcavdDocType"));
      scApcavdDocType->Text   = scApcavdDocType->ItemData[0];
      seApcavdDocCode->Text   = GetDetailValue("ApcavdDocCode");
      seApcavdDocLine->Text   = GetDetailValue("ApcavdDocLine");
      seApcavdConv->Text   = GetDetailValue("ApcavdConv");
      seApcavdPAmt->Text   = GetDetailValue("ApcavdPAmt");
      seApcavdCAmt->Text   = GetDetailValue("ApcavdCAmt");
      memApcavdDesc->Text   = GetDetailValue("ApcavdDesc");
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::SendDataToComObject(int Section)
{
    if (Section==1)  // Head
   {
      SetHeadValue("ApcavhCode",seApcavhCode->Text);
      SetHeadValue("ApcavhDate",deApcavhDate->Text);
      SetHeadValue("ApcavhDocType",scApcavhDocType->ItemData[1]);
      SetHeadValue("ApcavhDocCode",seApcavhDocCode->Text);
      SetHeadValue("ApcavhDesc",memApcavhDesc->Text);
      SetHeadValue("ApcavhUser",lbApcavhUser->Caption);
   }
   else
   {
      SetDetailValue("ApcavdCode",seApcavhCode->Text);
      SetDetailValue("ApcavdLine",seApcavdLine->Text);
      SetDetailValue("ApcavdDocType",scApcavdDocType->ItemData[1]);
      SetDetailValue("ApcavdDocCode",seApcavdDocCode->Text);
      SetDetailValue("ApcavdDocLine",seApcavdDocLine->Text);
      SetDetailValue("ApcavdConv",seApcavdConv->Text);
      SetDetailValue("ApcavdPAmt",seApcavdPAmt->Text);
      SetDetailValue("ApcavdCAmt",seApcavdCAmt->Text);
      SetDetailValue("ApcavdDesc",memApcavdDesc->Text);
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::WaitUserInput(int Section)
{
   if (Section ==1)
   {
     if(CurrentState==caAddHead)
       seApcavhCode->SetFocus();
   }
   else
   {
     sgApcavh->Visible=false;
     fpApcavhDetail->Visible=true;
     seApcavdLine->SetFocus();
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::DisplayBill()
{
    if(comServer->RecordCount==0)
       return;
    GetDataFromComObject(1);  // Head
    FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::GetBill(AnsiString BillID)
{
    int iRow;
    comServer->Find("ApcavhCode='"+BillID+"'");
    if (iRow>0)      //FIND THIS BILL
    {
       DisplayBill();
    }
    else if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
    {
      AddHeadRecord();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::FillGridWithData()
{
    sgApcavh->RowCount=1;
    if(comServer->RecordCount > 0)
      for (int i=0;i<comServer->ItemCount;i++)
      {
        comServer->LocateItemByIndex(i);
        RefreshGridData(0); // Append
      }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::ChangeToBrowseState(bool Browse)
{
     sgApcavh->Visible=true;
     fpApcavhDetail->Visible=false;
     if(Browse==false)
      sgApcavh->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TfrmApcavh::sgApcavhDblClick(TObject *Sender)
{
    int iRow;
    iRow=sgApcavh->Row;
    if (iRow == 0)
    {
       return;
    }
    comServer->LocateItemByKey(seApcavhCode->Text+"\t"+sgApcavh->TextMatrix[iRow][1]+"\t");
    if (comServer->ItemCount>0)
    {
       GetDataFromComObject(2);   // Detail
       sgApcavh->Visible=false;
       fpApcavhDetail->Visible=true;
    }

}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::sgApcavhSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if (ARow > 0)
       comServer->LocateItemByKey(seApcavhCode->Text+"\t"+sgApcavh->TextMatrix[ARow][1]+"\t");
    if (!comServer->Eof)
       GetDataFromComObject(2);    // Detail

}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::btnOKClick(TObject *Sender)
{
   try
   {
    if (CurrentState==caAddDetail||CurrentState==caAddBill)
    {
       if(DetailState==caAddDetail)
         comServer->AddItem();
       SendDataToComObject(2);
       comServer->AddToObject();
       ClearControl(2,false);
       seApcavdLine->SetFocus();
    }
    else
      ChangeToBrowseState();
   }
   catch(Exception &e)
   {
     throw Exception(e.Message);
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::btnCancelClick(TObject *Sender)
{
     CancelChange();

}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::FormShow(TObject *Sender)
{
    ClearControl(1,false); // Head
    ClearControl(2,false); // Detail
    MoveToFirst();
    ChangeToBrowseState();

}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::seApcavhDocCodeButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    TfrmWnQuery *p;
    try
    {
        StartWaitForm("正在查询,请稍候...");
        SqlStr="004[预付单号][供应商][币种][金额]";
        if(scApcavhDocType->ItemData[1]=="1")
        {
         SqlStr+=" select APPBCODE ,APPbSupply,AppbCurrency,Amt=(APPBAMT-APPBCAMT) from sdappb ";
         SqlStr+=" where APPBCHECK=1 and APPBAMT>APPBCAMT order by APPBCODE ";
         p=new TfrmWnQuery(this,"付款单查询",SqlStr);
        }
        if(scApcavhDocType->ItemData[1]=="2")
        {
          SqlStr+=" select PrepBCODE ,PrePbSupply,PrePbCurrency,AMT=(PREPBAMT-PREPBCAMT) from sdprepb ";
          SqlStr+=" where PrePBCHECK=1  and PREPBAMT>PREPBCAMT order by PrePBCODE ";
          p=new TfrmWnQuery(this,"预付单查询",SqlStr);
        }
        if(scApcavhDocType->ItemData[1]=="3")
        {
          SqlStr+=" select ApnpCODE,ApnpSupply,ApnpCurrency,AMT=(ApnpAmt-ApnpCAmt) from sdApnp ";
          SqlStr+=" where ApnpCheck=1 and ApnpAmt>ApnpCAmt and ApnpState=2 order by ApnpCODE ";
          p=new TfrmWnQuery(this,"付款票据查询",SqlStr);
        }
     }
     __finally
     {
       EndWaitForm();
     }
     if(p->ShowModal()==mrOk)
     {
      seApcavhDocCode->Text=p->ColData[1];
      m_Amt=p->ColData[4];
     }
     delete p;

}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::GenrateBill()
{
    int TempCount;
    TempCount = comServer->ItemCount;
    StartWaitForm("正在启动生成界面");
    TfrmApcavd *p=new TfrmApcavd(this);
      p->GetComObject(comServer);
      EndWaitForm();
      p->ShowModal();
      if (TempCount < comServer->ItemCount)
        TGenBaseForm::SaveRecord();
      else
        CancelChange();

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

void __fastcall TfrmApcavh::seApcavdPAmtKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13 )
    {
     AnsiString Temp1,Temp2;
     Temp1=seApcavdPAmt->Text;
     if(Temp1.IsEmpty())
       return;
     Temp2=seApcavdCAmt->Text;
     if(Temp2.IsEmpty())
       return;
     seApcavdConv->Text=AnsiString(Temp1.ToDouble()/Temp2.ToDouble());

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

void __fastcall TfrmApcavh::seApcavdCAmtKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13 )
    {
     AnsiString Temp1,Temp2;
     Temp1=seApcavdPAmt->Text;
     if(Temp1.IsEmpty())
       return;
     Temp2=seApcavdCAmt->Text;
     if(Temp2.IsEmpty())
       return;
     seApcavdConv->Text=AnsiString(Temp1.ToDouble()/Temp2.ToDouble());

    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmApcavh::seApcavhCodeExit(TObject *Sender)
{
    if(CurrentState==caNormal&&seApcavhCode->Text!=GetHeadValue("ApcavhCode"))
    {
      comServer->LocateByKey(seApcavhCode->Text);
      DisplayBill();
    }
}
//---------------------------------------------------------------------------
bool __fastcall TfrmApcavh::BeforeCheck()
{
  SetHeadValue("ApcavhCheck",1);
  SetHeadValue("ApcavhChecker",g_sdUserCode);
  SetHeadValue("ApcavhCheckDate",g_sdCurDate);
  return true;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmApcavh::BeforeUnCheck()
{
  SetHeadValue("ApcavhCheck",0);
  SetHeadValue("ApcavhChecker","");
  SetHeadValue("ApcavhCheckDate",NULL);
  return true;
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

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