aprih.cpp

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

CPP
416
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Aprih.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "BillBaseForm"
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmAprih *frmAprih;
//---------------------------------------------------------------------------
__fastcall TfrmAprih::TfrmAprih(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
        : TBillBaseForm(Owner,chWnd,MidCode,WhereStr)
{  SetAutoCodeString(seAprihCode,"Acm-56");
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::ClearControl(int Section,bool BringToNext)
{
   if (Section == 1)
   {
      if (!BringToNext)
      {

        deAprihDate->Text   =g_sdCurDate;  //日期
        lbAprihUser->Caption=g_sdUserCode;  //操作员
        chkAprihCheck->Checked   =false;  //审核标志
        lbAprihChecker->Caption  ="";  //审核人
        lbAprihCheckDate->Caption="";  //审核日期
        memAprihDesc->Text   ="";  //备注
        lbAprihSysDate->Caption   ="";  //系统日期
      }
      sgAprih->RowCount=1;
   }
   else if (Section==2)
   {
      if (!BringToNext)
      {
        seApridLine->Text   =AnsiString(comServer->ItemCount+1);
        seApridApiCode->Text   ="";  //发票号
        seApridApiLine->Text   ="";  //发票行号
        seApridCavCode->Text   ="";  //核销单号
        seApridCavLine->Text   ="";  //核销行号
        seApridAmt->Text   ="";  //金额
        memApridDesc->Text   ="";  //备注
      }
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::InitEditControl()
{
   ClientGroup->AddComponent(1,false,false,true,fpAprihHead,fpAprihHead->Name);
   ClientGroup->AddComponent(2,false,false,true,fpAprihDetail,fpAprihDetail->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,seAprihCode,seAprihCode->Name);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmAprih::GetDataToGrid()
{
    AnsiString  s;
   s = "\t" + GetDetailValue("ApridLine")    +
       "\t" + GetDetailValue("ApridApiCode") +
       "\t" + GetDetailValue("ApridApiLine") +
       "\t" + GetDetailValue("ApridCavCode") +
       "\t" + GetDetailValue("ApridCavLine") +
       "\t" + GetDetailValue("ApridAmt")    ;
    return s;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::RefreshGridData(int mAction)
{
    int i;
    AnsiString ItemStr;
    switch(mAction)
    {
       case 0: // Append
         ItemStr=GetDataToGrid();
         sgAprih->AddItem(ItemStr);
         break;
       case 1: // Modify
         sgAprih->ChangeItem(ItemStr,sgAprih->Row);
         break;
       case 2: // Delete
         sgAprih->RemoveItem(sgAprih->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::GetDataFromComObject(int Section)
{
   if (Section==1)
   {
      seAprihCode->Text   = GetHeadValue("AprihCode");
      deAprihDate->Text   = GetHeadValue("AprihDate");
      lbAprihUser->Caption   = GetHeadValue("AprihUser");
      chkAprihCheck->Checked = (GetHeadValue("AprihCheck")=="1"?true:false);
      if(chkAprihCheck->Checked)
        SetCheckToolbarStatus(true);
      else
        SetCheckToolbarStatus(false);
      lbAprihChecker->Caption = GetHeadValue("AprihChecker");
      lbAprihCheckDate->Caption= GetHeadValue("AprihCheckDate");
      memAprihDesc->Text   = GetHeadValue("AprihDesc");
      lbAprihSysDate->Caption   = GetHeadValue("AprihSysDate");
   }
   else
   {
      seApridLine->Text      = GetDetailValue("ApridLine");
      seApridApiCode->Text   =GetDetailValue("ApridApiCode");
      seApridApiLine->Text   =GetDetailValue("ApridApiLine");
      seApridCavCode->Text   = GetDetailValue("ApridCavCode");
      seApridCavLine->Text   =GetDetailValue("ApridCavLine");
      seApridAmt->Text       = GetDetailValue("ApridAmt");
      memApridDesc->Text     = GetDetailValue("ApridDesc");
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::SendDataToComObject(int Section)
{
    if (Section==1)  // Head
   {
      SetHeadValue("AprihCode",seAprihCode->Text);
      SetHeadValue("AprihDate",deAprihDate->Text);
      SetHeadValue("AprihUser",lbAprihUser->Caption);
      SetHeadValue("AprihDesc",memAprihDesc->Text);
   SetHeadValue("AprihSysDate",lbAprihSysDate->Caption);
   }
   else
   {
      SetDetailValue("ApridCode",seAprihCode->Text);
      SetDetailValue("ApridLine",seApridLine->Text);
      SetDetailValue("ApridApiCode",seApridApiCode->Text);
      SetDetailValue("ApridApiLine",seApridApiLine->Text);
      SetDetailValue("ApridCavCode",seApridCavCode->Text);
      SetDetailValue("ApridCavLine",seApridCavLine->Text);
      SetDetailValue("ApridAmt",seApridAmt->Text);
      SetDetailValue("ApridDesc",memApridDesc->Text);
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::WaitUserInput(int Section)
{
   if (Section ==1)
   {
     if(CurrentState==caAddHead)
       seAprihCode->SetFocus();
       lbAprihSysDate->Caption=g_sdSysDate;
   }
   else
   {
     sgAprih->Visible=false;
     fpAprihDetail->Visible=true;
     seApridLine->SetFocus();
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::DisplayBill()
{
    if(comServer->RecordCount==0)
       return;
    GetDataFromComObject(1);  // Head
    FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::GetBill(AnsiString BillID)
{
    int iRow;
    comServer->Find("AprihCode='"+BillID+"'");
    if (iRow>0)      //FIND THIS BILL
    {
       DisplayBill();
    }
    else if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
    {
      AddHeadRecord();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::FillGridWithData()
{
    sgAprih->RowCount=1;
    if(comServer->RecordCount > 0)
      for (int i=0;i<comServer->ItemCount;i++)
      {
        comServer->LocateItemByIndex(i);
        RefreshGridData(0); // Append
      }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::ChangeToBrowseState(bool Browse)
{
     sgAprih->Visible=true;
     fpAprihDetail->Visible=false;
     if(Browse==false)
      sgAprih->SetFocus();
}
//---------------------------------------------------------------------------


void __fastcall TfrmAprih::sgAprihDblClick(TObject *Sender)
{
    int iRow;
    iRow=sgAprih->Row;
    if (iRow == 0)
    {
       return;
    }
    comServer->LocateItemByKey(seAprihCode->Text+"\t"+sgAprih->TextMatrix[iRow][1]+"\t");
    if (comServer->ItemCount>0)
    {
       GetDataFromComObject(2);   // Detail
       sgAprih->Visible=false;
       fpAprihDetail->Visible=true;
    }

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

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

}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::btnCancelClick(TObject *Sender)
{
     CancelChange();

}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::FormShow(TObject *Sender)
{
    ClearControl(1,false); // Head
    ClearControl(2,false); // Detail
    MoveToFirst();
    ChangeToBrowseState();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::seApridApiCodeButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    TfrmWnQuery *p;
    try
    {
        StartWaitForm("正在查询,请稍候...");
        SqlStr="003[应付红字发票号][日期][供应商]";
        SqlStr+=" select ApivhCode,ApivhDate,ApivhSupply from sdApivh";
        SqlStr+=" where apivhcheck=1 and apivhred=-1 order by ApivhCode";
        p=new TfrmWnQuery(this,"应付红字发票查询",SqlStr);
     }
     __finally
     {
       EndWaitForm();
     }
     if(p->ShowModal()==mrOk)
     {
      seApridApiCode->Text=p->ColData[1];
      seApridCavCode->Text="";
      seApridCavLine->Text="0";
      seApridAmt->Text="0";
     }
     delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::seApridApiLineButtonClick(TObject *Sender)
{
    if(seApridApiCode->Text.IsEmpty())
      throw Exception("请输入发票号");
    AnsiString SqlStr;
    TfrmWnQuery *p;
    try
    {
        StartWaitForm("正在查询,请稍候...");
        SqlStr="004[应付红字发票行号][数量][单价][总额]";
        SqlStr+=" select ApivdLine,ApivdQty,ApivdPrice,ApivdAmt from sdApivd ";
        SqlStr+=" where apivdcode='"+seApridApiCode->Text+"' order by ApivdCode";
        p=new TfrmWnQuery(this,"应付红字发票明细查询",SqlStr);
     }
     __finally
     {
       EndWaitForm();
     }
     if(p->ShowModal()==mrOk)
     {
      seApridApiLine->Text=p->ColData[1];
      seApridAmt->Text=p->ColData[4];
      getApcavdCodeLine();
     }
     delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::getApcavdCodeLine()
{
    TComResultSet *Rs=new  TComResultSet(Handle,g_ClientHandle);
    AnsiString Sql;
    Sql=" select APIVDDOCCODE,APIVDDOCLINE from sdapivd ";
    Sql+=" where Apivdcode='"+seApridApiCode->Text +"' and ApivdLine='"+seApridApiLine->Text +"'" ;
    try
    {
      Rs->Close();
      Rs->Open(Sql,"");         //获取发票中的退货单号和行号
      Sql=" select PRETDPRECCODE,PRETDPRECDLINE from sdPRETD";
      Sql+=" where PRETDCODE='"+Rs->FieldByName("APIVDDOCCODE")+"' and PRETDLINE='"+Rs->FieldByName("APIVDDOCLINE")+"'";
      Rs->Close();              //获取发票中的收货单号和行号
      Rs->Open(Sql,"");
      Sql=" select APIVDCODE,APIVDLINE from sdapivd ";
      Sql+=" where APIVDDOCCODE='"+Rs->FieldByName("PRETDPRECCODE")+"' and APIVDDOCLINE='"+Rs->FieldByName("PRETDPRECDLINE")+"'";
      Rs->Close();               //获取发票中的核销单号和行号
      Rs->Open(Sql,"");
      Sql=" select Apcavdcode,ApcavdLine  from sdApcavd ";
      Sql+=" where ApcavdDocCode='"+Rs->FieldByName("ApivdCode")+"' and ApcavdDocLine='"+Rs->FieldByName("Apivdline")+"'";
      Rs->Close();               //获取发票中的核销单号和行号
      Rs->Open(Sql,"");
      seApridCavCode->Text=Rs->FieldByName("Apcavdcode");
      seApridCavLine->Text=Rs->FieldByName("Apcavdline");
      Rs->Close();
      delete Rs;

     }
     catch(Exception &e)
     {
       delete Rs;
       throw Exception("该退货单未有相应的收货单,或未有相应的核销单");
     }
}
//---------------------------------------------------------------------------
void __fastcall TfrmAprih::seAprihCodeExit(TObject *Sender)
{
    if(CurrentState==caNormal&&seAprihCode->Text!=GetHeadValue("AprihCode"))
    {
      comServer->LocateByKey(seAprihCode->Text);
      DisplayBill();
    }
}
//---------------------------------------------------------------------------
bool __fastcall TfrmAprih::BeforeCheck()
{
  SetHeadValue("AprihCheck",1);
  SetHeadValue("AprihChecker",g_sdUserCode);
  SetHeadValue("AprihCheckDate",g_sdCurDate);
  return true;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmAprih::BeforeUnCheck()
{
  SetHeadValue("AprihCheck",0);
  SetHeadValue("AprihChecker","");
  SetHeadValue("AprihCheckDate",NULL);
  return true;
}
//---------------------------------------------------------------------------

void __fastcall TfrmAprih::seApridCavCodeButtonClick(TObject *Sender)
{ // if(seApridCavCode->Text.IsEmpty())
   //   throw Exception("请输入核销单号");
    AnsiString SqlStr;
    TfrmWnQuery *p;
    try
    {
        StartWaitForm("正在查询,请稍候...");
        SqlStr="002[核销单号][核销单行号]";
        SqlStr+=" select AprsdCavCode,AprsdCavLine from sdAprsd ";
      
        p=new TfrmWnQuery(this,"应付红字核销单查询",SqlStr);
     }
     __finally
     {
       EndWaitForm();
     }
     if(p->ShowModal()==mrOk)
     {
      seApridCavCode->Text=p->ColData[1];
      seApridCavLine->Text=p->ColData[2];   

     }
     delete p;

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

⌨️ 快捷键说明

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