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

📄 zthclose.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "ZthClose.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"

TfrmZthClose *frmZthClose;
//---------------------------------------------------------------------------
__fastcall TfrmZthClose::TfrmZthClose(TComponent* Owner)
    : TListBaseForm(Owner,euSdZth,"")
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmZthClose::FillHeadObjToGrid()
{
  int i;
  AnsiString HeadStr;
  try
  {
   StartWaitForm("正在获取数据...");

   comServer->FilterString=WideString(WhereStr);
   comServer->Query();
   if(comServer->RecordCount>0)
   {
    sgZthClose->RowCount=1;
    sgZtdClose->RowCount=1;
    for (i=0;i<comServer->RecordCount;i++)
    {
      comServer->LocateByIndex(i);
      HeadStr="\t\t"+GetHeadValue(fiZthCode)+
              "\t"+GetHeadValue(fiZthDate)+
              "\t"+GetHeadValue(fiZthSupply)+
              "\t"+GetHeadValue(fiZthUser);
      sgZthClose->AddItem(HeadStr);
    }
   }
   else
   {
       sgZthClose->RowCount=1;
       sgZtdClose->RowCount=1;
   }
  }
  __finally
  {
   EndWaitForm();
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmZthClose::GetWhereStrToSQL()
{
     WhereStr="zthCheck=1 and zthCancel=0 and zthClose=0 and ";

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

     if (WhereStr.Length() > 5)
        WhereStr=WhereStr.SubString(1,WhereStr.Length()-5);
     else
        WhereStr="";
}
//---------------------------------------------------------------------------
void __fastcall TfrmZthClose::InitEditControl()
{
    sgZthClose->RowCount=1;
    sgZtdClose->RowCount=1;
    btnClose->Enabled=true;
    sePohCodeF->Text="";
    sePohCodeT->Text="";
    dePohDateF->Text="";
    dePohDateT->Text=dePohDateT->InitDate;
    scPohBuyerCode->Text="";
    scPohSupplyCode->Text="";
    sbBar->Panels->Items[1]->Text="操作员:"+g_sdUserCode;
    sbBar->Panels->Items[2]->Text=g_sdCompanyName;
    sbBar->Panels->Items[3]->Text=g_sdCurDate;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmZthClose::GetHeadValue(int Index)
{
    return ReadFieldValue(comServer,Index);
}
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmZthClose::GetDetailValue(int Index)
{
    return ReadItemValue(comServer,Index);
}
//---------------------------------------------------------------------------

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

void __fastcall TfrmZthClose::AddDetailObjToGrid(AnsiString s_Code)
{
    int i;
    AnsiString ItemStr,ID;
    sgZtdClose->RowCount=1;
    comServer->LocateByKey(WideString(s_Code));
    for (i=0;i<comServer->ItemCount;i++)
    {
        comServer->LocateItemByIndex(i);
        if(GetDetailValue(fiZtdClose)=="1")
            ID="√";
        else
            ID="";
        ItemStr="\t"+ID+
                "\t"+GetDetailValue(fiZtdCode)+
                "\t"+GetDetailValue(fiZtdLine)+
                "\t"+GetDetailValue(fiZtdPoCode)+
                "\t"+GetDetailValue(fiZtdPodLine)+
                "\t"+GetDetailValue(fiZtdGoods)+
                "\t"+GetDetailValue(fiZtdUnit)+
                "\t"+GetDetailValue(fiZtdQty)+
                "\t"+GetDetailValue(fiZtdRQty);
        sgZtdClose->AddItem(ItemStr);
    }
}
//---------------------------------------------------------------------------

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

void __fastcall TfrmZthClose::FormShow(TObject *Sender)
{
    FillComboBox(scPohBuyerCode,"select UserCode,UserName from sdUser order By UserCode","UserName","UserCode");
    FillComboBox(scPohSupplyCode,"select SupplyCode,SupplyName from sdSupply order By SupplyCode","SupplyName","SupplyCode");
    InitEditControl();
}
//---------------------------------------------------------------------------
void __fastcall TfrmZthClose::BitExitClick(TObject *Sender)
{
    frmZthClose->Close();
}
//---------------------------------------------------------------------------


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

void __fastcall TfrmZthClose::sgZthCloseSelectCell(TObject *Sender,
      int ACol, int ARow, bool &CanSelect)
{
 if(sgZthClose->RowCount > 1 && ARow > 0)
 {
   AddDetailObjToGrid(sgZthClose->Cells[2][ARow]);
 }
}
//---------------------------------------------------------------------------

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

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

void __fastcall TfrmZthClose::BillClose(int iFlag)
{
 switch(iFlag)
 {
  case 0:
   comServer->Close(0);
   for(int i=0;i<comServer->ItemCount;i++)
   {
     comServer->LocateItemByIndex(i);
     WriteItemValue(comServer,fiZtdClose,"0");
     comServer->AddToObject();
   }
   break;
  case 1:
   comServer->Close(1);
   for(int i=0;i<comServer->ItemCount;i++)
   {
     comServer->LocateItemByIndex(i);
     WriteItemValue(comServer,fiZtdClose,"1");
     comServer->AddToObject();
   }
   break;
  case 2:
   comServer->Close(2);
   WriteItemValue(comServer,fiZtdClose,"0");
   comServer->AddToObject();
   break;
  case 3:
   comServer->Close(3);
   WriteItemValue(comServer,fiZtdClose,"1");
   comServer->AddToObject();
   break;
  default:
   break;
 }

}
//---------------------------------------------------------------------------
void __fastcall TfrmZthClose::HavingRight()
{
 TComResultSet *RsTemp;
 AnsiString sSQL;
 sSQL=" select buyercode from sdbuyer where buyerclose=1 and buyercode='"
     +g_sdUserCode+"'";
 RsTemp=NewResultSet();
 RsTemp->Open(sSQL,"");
 if(RsTemp->RecordCount <= 0)
 {
  RsTemp->Close();
  throw Exception("当前用户没有结清/反结清权限");
 }
 else
  RsTemp->Close();
 delete RsTemp; 
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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