aprsd.cpp

来自「科思ERP部分源码及控件」· C++ 代码 · 共 234 行

CPP
234
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Aprsd.h"
#include "Aprsh.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "StdBaseForm"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmAprsd *frmAprsd;
//---------------------------------------------------------------------------
__fastcall TfrmAprsd::TfrmAprsd(TComponent* Owner)
        : TStdBaseForm(Owner)
{
    InitControlGroup();
    btnOK->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::GetComObject(TComServer *comServerPtr)
{
    comServer = comServerPtr;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::InitControlGroup()
{
    sgAprsd->RowCount = 1;
    seAprsdCavCode->Text="";
    scAprshDocType->AddItems("退款单","1");
    scAprshDocType->AddItems("红字应付单","2");
    scAprshDocType->AddItems("票据退回","3");

    seAprshDocCode->Text=frmAprsh->seAprshDocCode->Text;
    scAprshDocType->LocateKey(frmAprsh->scAprshDocType->ItemData[1]);
    scAprshDocType->Text=scAprshDocType->ItemData[0];
    seAprshDocAmt->Text=frmAprsh->m_Amt;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::seAprsdCavCodeButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    TfrmWnQuery *p;
    try
    {
        StartWaitForm("正在查询,请稍候...");
        SqlStr="004[核销单号][日期][单据类型][单据号]";
        if(scAprshDocType->ItemData[1]=="1")
        {
         SqlStr+=" select ApcavhCode,ApcavhDate,ApcavhDocType,ApcavhDocCode from sdApcavh ";
         SqlStr+=" where Apcavhcheck=1 and APCAVHDOCCODE ='"+frmAprsh->m_OldCode+"' order by Apcavhcode";
        }
        if(scAprshDocType->ItemData[1]=="2")
        {
         SqlStr+=" select ApcavhCode,ApcavhDate,ApcavhDocType,ApcavhDocCode from sdApcavh ";
         SqlStr+=" where Apcavhcheck=1 and APCAVHDOCCODE='"+frmAprsh->m_OldCode+"' order by Apcavhcode";
        }
        if(scAprshDocType->ItemData[1]=="3")
        {
         SqlStr+=" select ApcavhCode,ApcavhDate,ApcavhDocType,ApcavhDocCode from sdApcavh ";
         SqlStr+=" where Apcavhcheck=1  order by Apcavhcode";
        }
         p=new TfrmWnQuery(this,"核销单查询",SqlStr);
     }
     __finally
     {
       EndWaitForm();
     }
     if(p->ShowModal()==mrOk)
     {
      seAprsdCavCode->Text=p->ColData[1];
      FillGridWithData();
     }
     delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::FillGridWithData()
{
    AnsiString  ItemStr,s_SQL;
    TComResultSet *RsAprsd;
    s_SQL=" select APCAVDLINE,APCAVDCONV,APCAVDCAmt";
    s_SQL+=" from sdApcavd where APCAVDCODE='"+seAprsdCavCode->Text+"'";
    try
    {
      StartWaitForm("正在查询数据,请稍候......");
      RsAprsd=new  TComResultSet(Handle,g_ClientHandle);
      RsAprsd->Open(s_SQL,"");
      while( RsAprsd->Eof == 0)
      {
         ItemStr="\t"+AnsiString("")+
                 "\t"+RsAprsd->FieldByName("APCAVDLINE")+
                 "\t"+"0"+
                 "\t"+RsAprsd->FieldByName("APCAVDCAmt")+
                 "\t"+RsAprsd->FieldByName("APCAVDCONV");
         sgAprsd->AddItem(ItemStr);
        RsAprsd->MoveNext();
      }
      RsAprsd->Close();
    }
    __finally
    {
      EndWaitForm();
    }

}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::sgAprsdDblClick(TObject *Sender)
{
    AnsiString SqlStr;
    int ARow=sgAprsd->Row;
    if (ARow >0)
    {
      if(sgAprsd->Col==1)
      {
        if (sgAprsd->Cells[1][ARow] == "√")
        {
         sgAprsd->Cells[1][ARow] =  "";
         for (int i=1;i<sgAprsd->RowCount;i++)
         {
            if(sgAprsd->Cells[1][i]=="√")
            {
               btnOK->Enabled=true;
               break;
            }
            else
               btnOK->Enabled=false;
         }
        }
        else
        {
          sgAprsd->Cells[1][ARow] =  "√";
          btnOK->Enabled=true;
        }
      }
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::bbSelAllClick(TObject *Sender)
{
    for(int i=1;i<sgAprsd->RowCount;i++)
      sgAprsd->Cells[1][i] = "√";
    btnOK->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::bbSelNoneClick(TObject *Sender)
{
    for(int i=1;i<sgAprsd->RowCount;i++)
      sgAprsd->Cells[1][i] = "";
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::btnOKClick(TObject *Sender)
{
    int ErrNum;
    try
    {
      StartWaitForm("正在生成核销单,请稍候......");
      if(sgAprsd->RowCount>1)
      {
       int j;
       j=comServer->ItemCount-1;
       if(j>=0)
       {
        comServer->LocateItemByIndex(j);
        j=StrToInt(frmAprsh->GetDetailValue("AprsdLine"));
        j=j+1;
       }
       else
        j=1;
       try
       {
        for(int i=1;i<sgAprsd->RowCount;i++)
        {
         if(sgAprsd->Cells[1][i]=="√")
         {
           comServer->AddItem();
           SetDetailValue("AprsdCode",frmAprsh->seAprshCode->Text);
           SetDetailValue("AprsdLine",AnsiString(j));
           SetDetailValue("AprsdCavCode",seAprsdCavCode->Text);
           SetDetailValue("AprsdCavLine",sgAprsd->Cells[2][i]);
           SetDetailValue("AprsdRAmt",sgAprsd->Cells[3][i]);
           SetDetailValue("AprsdCAmt",sgAprsd->Cells[4][i]);
           SetDetailValue("AprsdConv",sgAprsd->Cells[5][i]);
           SetDetailValue("AprsdDesc",sgAprsd->Cells[6][i]);
           comServer->AddToObject();
           j=j+1;
         }
        }
       }
       catch(Exception &e)
       {
        comServer->FreeItem();
        this->ModalResult=0;
        throw Exception(e.Message);
       }
      }
    }
    __finally
    {
     EndWaitForm();
    }
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprsd::btnCancelClick(TObject *Sender)
{
   Close();
}
//---------------------------------------------------------------------------

void __fastcall TfrmAprsd::sgAprsdKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13 )
    {
     AnsiString Temp1,Temp2;
     Temp1=sgAprsd->Cells[3][sgAprsd->Row];
     if(Temp1.IsEmpty())
       return;
     Temp2=sgAprsd->Cells[4][sgAprsd->Row];
     if(Temp2.IsEmpty())
       return;
     sgAprsd->Cells[5][sgAprsd->Row]=AnsiString(Temp1.ToDouble()/Temp2.ToDouble());

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


⌨️ 快捷键说明

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