pohclose.cpp

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

CPP
273
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#include "PohClose.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "DateEdit"
#pragma link "ListBaseForm"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"

TfrmPohClose *frmPohClose;
//---------------------------------------------------------------------------
__fastcall TfrmPohClose::TfrmPohClose(TComponent* Owner, HWND chWnd, AnsiString ClassCode,AnsiString WhereStr)
    : TListBaseForm(Owner,chWnd,ClassCode,WhereStr)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmPohClose::FillHeadObjToGrid()
{
  int i;
  AnsiString HeadStr;
  try
  {
   StartWaitForm("正在获取数据...");

   comServer->FilterString=WideString(WhereStr);
   comServer->Query();
   if(comServer->RecordCount>0)
   {
    sgPohClose->RowCount=1;
    sgPodClose->RowCount=1;
    for (i=0;i<comServer->RecordCount;i++)
    {
      comServer->LocateByIndex(i);
      HeadStr="\t"+AnsiString("  ")+
              "\t"+GetHeadValue("PohCode")+
              "\t"+GetHeadValue("PohDate")+
              "\t"+GetHeadValue("PohSupply")+
              "\t"+ GetHeadValue("PohCurrency")+
              "\t"+GetHeadValue("PohTaxCode")+
              "\t"+GetHeadValue("PohBuyer")+
              "\t"+GetHeadValue("PohContract")+
              "\t"+GetHeadValue("PohSugDate");
      sgPohClose->AddItem(HeadStr);
    }
   }
   else
   {
       sgPohClose->RowCount=1;
       sgPodClose->RowCount=1;
   }
  }
  __finally
  {
   EndWaitForm();
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmPohClose::GetWhereStrToSQL()
{
     WhereStr="PohCheck=1 and PohCancel=0 and PohStop=0 and PohClose=0 and ";

     if(Trim(sePohCodeF->Text).IsEmpty()==false)
        WhereStr=WhereStr+ "PohCode>='"+Trim(sePohCodeF->Text)+"' and ";
     if(Trim(sePohCodeT->Text).IsEmpty()==false)
        WhereStr=WhereStr+ "PohCode<='"+Trim(sePohCodeT->Text)+"' and ";
     if(Trim(dePohDateF->Text).IsEmpty()==false)
        WhereStr=WhereStr+ "PohDate>='"+FormatDateTime("yyyy-mm-dd",dePohDateF->Date)+"' and ";
     if(Trim(dePohDateT->Text).IsEmpty()==false)
        WhereStr=WhereStr+ "PohDate<='"+FormatDateTime("yyyy-mm-dd",dePohDateT->Date)+"' and ";
     if(Trim(scPohBuyerCode->Text).IsEmpty()==false)
        WhereStr=WhereStr+ "PohBuyer like '"+Trim(scPohBuyerCode->ItemData[cbItem2])+"' and ";
     if(Trim(scPohSupplyCode->Text).IsEmpty()==false)
        WhereStr=WhereStr+ "PohSupply like '"+Trim(scPohSupplyCode->ItemData[cbItem2])+"' and ";

     if (WhereStr.Length() > 5)
        WhereStr=WhereStr.SubString(1,WhereStr.Length()-5);
     else
        WhereStr="";
}
//---------------------------------------------------------------------------
void __fastcall TfrmPohClose::InitEditControl()
{
    sgPohClose->RowCount=1;
    sgPodClose->RowCount=1;
    btnClose->Enabled=true;
    sePohCodeF->Text="";
    sePohCodeT->Text="";
    dePohDateF->Text="";
    dePohDateT->Text=dePohDateT->InitDate;
    scPohBuyerCode->Text="";
    scPohSupplyCode->Text="";
}
//---------------------------------------------------------------------------

void __fastcall  TfrmPohClose::ChangeToBrowseState(bool agree)
{
    return;
}
//---------------------------------------------------------------------------

void __fastcall TfrmPohClose::AddDetailObjToGrid(AnsiString s_Code)
{
    int i;
    AnsiString ItemStr,ID;
      sgPodClose->RowCount=1;
    comServer->LocateByKey(WideString(s_Code));
    for (i=0;i<comServer->ItemCount;i++)
    {
        comServer->LocateItemByIndex(i);
        if(GetDetailValue("PodClose")=="1")
            ID="√";
        else
            ID=" ";
        l_Query->LocateByKey(GetDetailValue("PodGoods"));
        ItemStr="\t"+ID+
                "\t"+GetDetailValue("PodCode")+
                "\t"+GetDetailValue("PodLine")+
                "\t"+GetDetailValue("PodGoods")+
                "\t"+l_Query->FieldByName("goodsname")+
                "\t"+l_Query->FieldByName("goodsspec")+
                "\t"+GetDetailValue("PodUnit")+
                "\t"+GetDetailValue("PodRecDate")+
                "\t"+GetDetailValue("PodQty")+
//               "\t"+GetDetailValue("PodThQty")+
//               "\t"+GetDetailValue("PodInvQty")+
                "\t"+GetDetailValue("PodLoc");
        sgPodClose->AddItem(ItemStr);
    }

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

void __fastcall TfrmPohClose::btnClearClick(TObject *Sender)
{
    InitEditControl();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPohClose::btnQueryClick(TObject *Sender)
{
    HavingRight();
    GetWhereStrToSQL();
    FillHeadObjToGrid();
}
//---------------------------------------------------------------------------

void __fastcall TfrmPohClose::FormShow(TObject *Sender)
{
    l_Query->Close();
    l_Query->Open("select goodsname,goodscode,goodsspec from sdgoods","goodscode");
     FillComboBox(Handle,scPohBuyerCode,"select BuyerCode,BuyerName from sdBuyer order By BuyerCode","BuyerName","BuyerCode");
     FillComboBox(Handle,scPohSupplyCode,"select SupplyCode,SupplyName from sdSupply order By SupplyCode","SupplyName","SupplyCode");
     InitEditControl();

}
//---------------------------------------------------------------------------
void __fastcall TfrmPohClose::BitExitClick(TObject *Sender)
{
    frmPohClose->Close();
}
//---------------------------------------------------------------------------


void __fastcall TfrmPohClose::btnCloseClick(TObject *Sender)
{
    btnQueryClick(Sender);
}
//---------------------------------------------------------------------------


void __fastcall TfrmPohClose::sgPohCloseDblClick(TObject *Sender)
{
    if(sgPohClose->RowCount<=1)
    return;
    comServer->LocateByKey(WideString(sgPohClose->TextMatrix[sgPohClose->Row][2]));
    if(sgPohClose->TextMatrix[sgPohClose->Row][1]=="√")
    {
      BillClose(0);//清空主从表的结清标志
      sgPohClose->TextMatrix[sgPohClose->Row][1]="";
      for(int i=1;i<sgPodClose->RowCount;i++)
      sgPodClose->TextMatrix[i][1]="";
      sgPodClose->Enabled=true; //解锁
    }
    else
    {
      BillClose(1);//设置主从表的结清标志
      sgPohClose->TextMatrix[sgPohClose->Row][1]="√";
      for(int i=1;i<sgPodClose->RowCount;i++)
      sgPodClose->TextMatrix[i][1]="√";
      sgPodClose->Enabled=false; //锁定从表不允许修改
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmPohClose::sgPodCloseDblClick(TObject *Sender)
{
      comServer->LocateByKey(WideString(sgPodClose->TextMatrix[sgPodClose->Row][2]));
      comServer->LocateItemByKey(WideString(sgPodClose->TextMatrix[sgPodClose->Row][3]));
      if(sgPodClose->TextMatrix[sgPodClose->Row][1]=="√")
      {
          BillClose(2);//清空从表的结清标志
          sgPodClose->TextMatrix[sgPodClose->Row][1]="";
       }
       else
       {
          BillClose(3);//设置从表的结清标志
          sgPodClose->TextMatrix[sgPodClose->Row][1]="√";
       }
}
//---------------------------------------------------------------------------

void __fastcall TfrmPohClose::BillClose(int iFlag)
{
 try
 {
   switch(iFlag)
   {
    case 0:
     comServer->Close(0);
     for(int i=0;i<comServer->ItemCount;i++)
     {
       comServer->LocateItemByIndex(i);
       SetDetailValue("PodClose","0");
       comServer->AddToObject();
     }
     break;
    case 1:
     comServer->Close(1);
     for(int i=0;i<comServer->ItemCount;i++)
     {
       comServer->LocateItemByIndex(i);
       SetDetailValue("PodClose","1");
       comServer->AddToObject();
     }
     break;
    case 2:
     comServer->Close(2);
     SetDetailValue("PodClose","0");
     comServer->AddToObject();
     break;
    case 3:
     comServer->Close(3);
     SetDetailValue("PodClose","1");
     comServer->AddToObject();
     break;
    default:
     break;
   }
 }
 catch(Exception &e)
 {
  throw Exception("结清采购单出现错误!\n"+e.Message);
 }
}
//---------------------------------------------------------------------------
void __fastcall TfrmPohClose::HavingRight()
{
}
//-------------------------------------------

void __fastcall TfrmPohClose::sgPohCloseClick(TObject *Sender)
{
if(sgPohClose->RowCount > 1 && sgPohClose->Row > 0)
 {
   AddDetailObjToGrid(sgPohClose->Cells[2][sgPohClose->Row]);
 }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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