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

📄 sohclose.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "SohClose.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ListBaseForm"
#pragma link "DateEdit"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmSohClose *frmSohClose;
//---------------------------------------------------------------------------
__fastcall TfrmSohClose::TfrmSohClose(TComponent* Owner)
        :TListBaseForm(Owner,euSdSoh,"")
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmSohClose::InitEditControl()
{
 FillComboBox(scSohSaler,"Select userCode,UserName from sdUser where UserCode in (select SalerCode from SdSaler)","UserName","UserCode");
 FillComboBox(scSohClient,"Select ClientCode,ClientName from sdClient where ClientCancel=0","ClientName","ClientCode");
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::ClearControl()
{
           seSohCodeF->Text            ="";
           seSohCodeT->Text            ="";
           deSohDateF->Text            ="";
           deSohDateT->Text            ="";
           scSohClient->ItemIndex      =-1;
           scSohSaler->ItemIndex       =-1;

           SohGrid->RowCount=1;
           SodGrid->RowCount=1;
           btnClose->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::GetDataFromComObject(int Section)
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::SendDataToComObject(int Section)
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::WaitUserInput(int Section)
{
}
void __fastcall TfrmSohClose::ChangeToBrowseState(bool Browse)
{
  ClearControl();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSohClose::DisplayBill()
{
        FillHeadGridWithData();
        comServer->MoveFirst();
        FillDetailGridWithData();
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::GetBill(AnsiString WhereStr)
{
    comServer->FilterString=WideString(WhereStr);
    comServer->Query();
    if (comServer->RecordCount!=0)      //Found it
       {
         btnClose->Enabled=true;
         DisplayBill();
       }
       else
        ShowMessageWindow("在数据库中没有查到记录或已完成所有,请重新输入条件",mwsInformation);
   RecodCount->Caption="查询单据数为:"+IntToStr(comServer->RecordCount);
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::FillDetailGridWithData()
{
      int i;
      AnsiString ItemStr,ID;
      SodGrid->RowCount=1;
      for (i=0;i<comServer->ItemCount;i++)
      {
          comServer->LocateItemByIndex(i);
          if(GetDetailValue(fiSodClose)=="1")
              ID="*";
          else
            { if(GetDetailValue(fiSodState)=="8")
                 ID="√";
              else
                 ID=" ";
             }
          ItemStr="\t"+ID+"\t"+GetDetailValue(fiSodLine)+"\t"+
                    GetDetailValue(fiSodGoods)+"\t"+GetDetailValue(fiSodUnit)+"\t"+
                    GetDetailValue(fiSodPrice)+"\t"+GetDetailValue(fiSodDisc)+"\t"+
                    GetDetailValue(fiSodQty)+"\t"+GetDetailValue(fiSodRecDate)+"\t"+
                    GetDetailValue(fiSodSQty);
          SodGrid->AddItem(ItemStr);
      }
}
void __fastcall TfrmSohClose::FillHeadGridWithData()
{
      int i;
      AnsiString HeadStr;
      SohGrid->RowCount=1;
      for (i=0;i<comServer->RecordCount;i++)
      {
          comServer->LocateByIndex(i);
          HeadStr="\t"+AnsiString("  ")+"\t"+GetHeadValue(fiSohCode)+"\t"+GetHeadValue(fiSohContract)+"\t"+
                       GetHeadValue(fiSohClient)+"\t"+GetHeadValue(fiSohDate)+"\t"+
                       GetHeadValue(fiSohCurrency)+"\t"+GetHeadValue(fiSohSettleMode)+"\t"+
                       GetHeadValue(fiSohSaler);
          SohGrid->AddItem(HeadStr);
      }

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

AnsiString __fastcall TfrmSohClose::GetHeadValue(int Index)
{
        WideString S;
        S = ReadFieldValue(comServer,Index);
        return S;
}
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmSohClose::GetDetailValue(int Index)
{
        WideString S;
        S = ReadItemValue(comServer,Index);
        return S;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSohClose::SetHeadValue(int Index,AnsiString Value)
{
       WriteFieldValue(comServer,Index,WideString(Value));
}

//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::SetDetailValue(int Index,AnsiString Value)
{
       WriteItemValue(comServer,Index,WideString(Value));
}
//---------------------------------------------------------------------------



void __fastcall TfrmSohClose::FormShow(TObject *Sender)
{
//       InitEditControl();
       ClearControl();
       ChangeToBrowseState(true);

}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmSohClose::GetWhereSQLString()
{
     AnsiString WhereStr;
     WhereStr="SohClose=0 and SohCancel=0 and SohCheck=1";
     WhereStr=WhereStr+" and SohClient in(select ClientCode from sdClient where ClientCancel=0)";
     if(!seSohCodeF->Text.IsEmpty())
        WhereStr=WhereStr+" and SohCode>='"+Trim(seSohCodeF->Text)+"'";
     if(!seSohCodeT->Text.IsEmpty())
        WhereStr=WhereStr+" and SohCode<='"+Trim(seSohCodeT->Text)+"'";
     if(!scSohSaler->Text.IsEmpty())
        WhereStr=WhereStr+" and SohSaler='"+Trim(scSohSaler->ItemData[1])+"'";
     if(!deSohDateF->Text.IsEmpty())
        WhereStr=WhereStr+" and SohDate>='"+FormatDateTime("YYYY-MM-DD",deSohDateF->Date)+"'";
     if(!deSohDateT->Text.IsEmpty())
        WhereStr=WhereStr+" and SohDate<='"+FormatDateTime("YYYY-MM-DD",deSohDateT->Date)+"'";
     if(!scSohClient->Text.IsEmpty())
        WhereStr=WhereStr+" and SohClient='"+Trim(scSohClient->ItemData[1])+"'";
   return(WhereStr);
}


void __fastcall TfrmSohClose::btnClearClick(TObject *Sender)
{
       ClearControl();
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::btnQueryClick(TObject *Sender)
{
           SohGrid->RowCount=1;
           SodGrid->RowCount=1;
           btnClose->Enabled=false;

  AnsiString WhereStr=GetWhereSQLString();
  GetBill(WhereStr);
}
//---------------------------------------------------------------------------



void __fastcall TfrmSohClose::SohGridClick(TObject *Sender)
{
    if(SohGrid->Row>0)
    {
     comServer->LocateByKey(WideString(SohGrid->TextMatrix[SohGrid->Row][2]));
    if(SohGrid->Col == 1)
     {
      AnsiString State;
     if(SohGrid->TextMatrix[SohGrid->Row][1]=="√")
        {
           SohGrid->TextMatrix[SohGrid->Row][1]="";
           State="9";
         }
        else
         {
           SohGrid->TextMatrix[SohGrid->Row][1]="√";
           State="8";
         }
      for(int i=0;i<comServer->ItemCount;i++)
        {
         comServer->LocateItemByIndex(i);
         SetDetailValue(fiSodState,State);
         comServer->AddToObject();
        }
      }
      FillDetailGridWithData();
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::btnCloseClick(TObject *Sender)
{
  for(int i=1; i<SohGrid->RowCount;i++)
  {
  comServer->LocateByKey(WideString(SohGrid->TextMatrix[i][2]));
  if(SohGrid->TextMatrix[i][1]=="√")  //结单头
   {
    try{
       comServer->Close(1);
    }
    catch(Exception &e)
    {
     throw Exception(e.Message);
    }
   }
  else
    {
    for(int i=0;i<comServer->ItemCount;i++)
      {
       comServer->LocateItemByIndex(i);
       if(GetDetailValue(fiSodState)=="8")   //结明细项
        {
        try{
          comServer->Close(3);
           }
         catch(Exception &e)
           {
             throw Exception(e.Message);
            }
        }
      }
    }
   }
  ClearControl();
  btnQueryClick(Sender);
}
//---------------------------------------------------------------------------


void __fastcall TfrmSohClose::BitBtn4Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSohClose::SodGridClick(TObject *Sender)
{
  if((SodGrid->TextMatrix[SodGrid->Row][1]!="*")&&(SodGrid->Col == 1)&&(SodGrid->Row>0))
      {
       comServer->LocateItemByKey(WideString(SodGrid->TextMatrix[SodGrid->Row][2]));
        if(SodGrid->TextMatrix[SodGrid->Row][1]=="√")
        {
           SodGrid->TextMatrix[SodGrid->Row][1]="";
           SohGrid->TextMatrix[SohGrid->Row][1]="";
           SetDetailValue(fiSodState,"9");
         }
        else
          {
           SodGrid->TextMatrix[SodGrid->Row][1]="√";
           SetDetailValue(fiSodState,"8");
           }
       comServer->AddToObject();
      //假设已全部结清明细;
      SohGrid->TextMatrix[SohGrid->Row][1]="√";
      for(int i=0;i<comServer->ItemCount;i++)
        {
        comServer->LocateItemByIndex(i);
        if((GetDetailValue(fiSodClose)=="0")&&(GetDetailValue(fiSodState)!="8"))
           {
            //明细没有全部结清,则单头不能结清;
            SohGrid->TextMatrix[SohGrid->Row][1]="";
           }
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmSohClose::SodGridMouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
   int Column,Row;
   SodGrid->MouseToCell(X,Y,Column,Row);
   if(Column==1&&Row>0)
      SodGrid->Cursor=crHandPoint;
   else
      SodGrid->Cursor=crDefault;

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


void __fastcall TfrmSohClose::SohGridMouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
   int Column,Row;
   SohGrid->MouseToCell(X,Y,Column,Row);
   if(Column==1&&Row>0)
      SohGrid->Cursor=crHandPoint;
   else
      SohGrid->Cursor=crDefault;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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