supplygoodsquery.cpp

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

CPP
542
字号
  }
  sOrder=" order by GoodsPmpcCode,GoodsType,GoodsCode ";
  sSQL=sSelect+sWhere+sOrder;//
  return sSQL;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSupplyGoodsQuery::FillGridWithData()
{
  AnsiString ItemStr;
  sgGoods->RowCount=1;
  btnOK->Enabled=false;
  btnQuery->Enabled=true;
  try
  {
    StartWaitForm("正在查询,请稍候...");
    RsGoodsQuery->Close();
    RsGoodsQuery->Open(GetQueryStr(),"goodscode");
    sgGoods->ScrollBars=ssNone; //取消滚动条,防止屏幕滚动
    while( RsGoodsQuery->Eof == 0)
    {
      ItemStr=RsGoodsQuery->FieldByName("GoodsCode")+
          "\t"+RsGoodsQuery->FieldByName("GoodsName")+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsSpec"))+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsPmpcCode"))+  //类型
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsUnitCode"))+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsCurrencyCode"))+
          //"\t"+AnsiString((RsGoodsQuery->FieldByName("GoodsFrom")=="1")?"采购":"制造")+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsMaxQty"))+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsSafeQty")) ;

      sgGoods->AddItem(ItemStr);
      RsGoodsQuery->MoveNext();
    }
    sgGoods->ScrollBars=ssBoth;//设置滚动条
  }
  __finally
  {
    EndWaitForm();
  }
  if(sgGoods->RowCount > 1)
  {
    sgGoods->Row=1;
    btnOK->Enabled=true;
  }
  lbQueryCount->Caption=sgGoods->RowCount-1;
}
//---------------------------------------------------------------------------
/*
bool __fastcall TfrmGoodsQuery::IsSimilar(AnsiString str,AnsiString substr)
{
//name     : IsSimilar
//function : 判断字串str是否包含字串substr
//parameter: str 为母串,substr为字串
//return   : 包含则返回true,否则返回false
  char *pTemp;
  int iBegin,iCount,iLen,iType,i;
  if((str == "")||(substr == "")||(str.Length()<substr.Length()))
   return(false);
  iBegin=1;
  iCount=0;
  iType=1;
  iLen=substr.Length();
  pTemp=substr.c_str();
  if(*pTemp == '\\')  //首字母是转义字符
  {
   substr=substr.SubString(2,iLen-1); //去除转义字符
   iType=1;
  }
  else
   if(*pTemp == '*')  //首字母是多字母匹配符
   {
    substr=substr.SubString(2,iLen-1); //去除匹配符
    iType=2;
    }
   else
    if(*pTemp == '#')  //首字母是单字母匹配符
    {
     iCount=1;
     i=1;
     while(i < iLen)   //统计字串首部连续单字母匹配符的个数
     {
      if(*(pTemp+i) == '#')
      {
       iCount++;
       i++;
      }
      else
       break;
     }
     iBegin=iCount+1; //串匹配的开始位置
     substr=substr.SubString(iBegin,iLen-iCount); //去除匹配符
     iType=3;
    }
  switch(iType)
  {
   case 1:  //首部匹配
    if(substr=="")
     return(false);
    if (UpperCase(str).Pos(UpperCase(substr))==1)
      return(true);
    else
      return(false);
   case 2: //包含匹配
    if(substr=="")
     return(false);
    if (UpperCase(str).Pos(UpperCase(substr))>0)
      return(true);
    else
      return(false);
   case 3: //从iBegin处开始匹配
    if(substr=="")
     if(str.Length()==iCount)
       return(true);
     else
       return(false);
    else
     if (UpperCase(str).Pos(UpperCase(substr))==iBegin)
       return(true);
     else
       return(false);
   default:
    return(false);
  }
 }
 */
//---------------------------------------------------------------------------
void __fastcall TfrmSupplyGoodsQuery::sgGoodsClick(TObject *Sender)
{

   TComResultSet *RsMacc;
   AnsiString l_GoodsCode,l_maccSql;
   if(sgGoods->Row<1)
     return;

   l_GoodsCode = sgGoods->Cells[0][sgGoods->Row] ;
   try
   {
   RsMacc = new TComResultSet(Handle,l_ClientHandle);
    if (scLoc->ItemData[1].IsEmpty())
       l_maccSql=" select maccgoods,Sum(maccfopqty) as maccfopqty from sdmacc  where maccgoods ='"+l_GoodsCode+"' and maccfmonth= (select CscmMonth from sdcscm where CscmClassid='inventory') group by maccgoods ";
     else
       l_maccSql=" select maccgoods,Sum(maccfopqty) as maccfopqty from sdmacc  where maccgoods ='"+l_GoodsCode+"' and maccfmonth= (select CscmMonth from sdcscm where CscmClassid='inventory') and maccloc = '"+scLoc->ItemData[1]+"' group by maccgoods ";
   RsMacc->Open(WideString(l_maccSql),WideString(""));
   if((RsMacc->FieldByName("maccfopqty")).IsEmpty())
   {
     et_FopQty->Caption="0";
   }
   else
   {
     et_FopQty->Caption=AnsiString(RsMacc->FieldByName("maccfopqty"));
   }
   RsMacc->Close() ;
   btnOK->Enabled=true;
   }
   __finally
   {
     if(RsMacc)delete RsMacc;
   }
 
}
//---------------------------------------------------------------------------
void __fastcall TfrmSupplyGoodsQuery::tvGoodsChange(TObject *Sender,
      TTreeNode *Node)
{
    AnsiString m;
    if(Node == tvGoods->Items->Item[0])
     return;
    if(tvGoods->Selected==NULL)
     return;
    if(tvGoods->Selected->StateIndex == 0)
     return;
    m = Node->Text;
    l_TvSelect = m.SubString(2,m.AnsiPos(")")-2);
    FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSupplyGoodsQuery::edtLocateKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
 if(Key == 13)
 {
  sbLocateClick(Sender);
 }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSupplyGoodsQuery::sbLocateClick(TObject *Sender)
{ /* TODO : 加入物料定位时仅从传入的条件里查询所有的记录 */
//-------
  AnsiString LocateSQLStr,ItemStr,LocCodeStr;

  LocCodeStr=Trim(edtLocate->Text);
  if(LocCodeStr.IsEmpty())
  {
    sgGoods->RowCount=1; 
    return;//为空时返回
  }
  ClearCondition();//清空除传入的where外的所有条件先
  LocateSQLStr="select * from sdgoods ";
  if(!Trim(l_WhereStr).IsEmpty())
  {
    LocateSQLStr=LocateSQLStr+" where "+l_WhereStr;//传入条件
    if(!LocCodeStr.IsEmpty())
    {
      if(LocCodeStr!="*")//*为所有的记录
      {
        LocateSQLStr=LocateSQLStr+" and "+" GoodsCode like "+QuotedStr(LocCodeStr+"%");//定位条件
      }
    }
  }
  else
  {
    if(!LocCodeStr.IsEmpty())
    {
      if(LocCodeStr!="*")//*为所有的记录
      {
        LocateSQLStr=LocateSQLStr+" where "+" GoodsCode like "+QuotedStr(LocCodeStr+"%");
      }
    }
  }
  try//填充所有的符合条件的数据
  {
    StartWaitForm("正在查询,请稍候...");
    RsGoodsQuery->Close();
    RsGoodsQuery->Open(LocateSQLStr,"goodscode");
    sgGoods->ScrollBars=ssNone; //取消滚动条,防止屏幕滚动
    while( RsGoodsQuery->Eof == 0)
    {
      ItemStr=RsGoodsQuery->FieldByName("GoodsCode")+
          "\t"+RsGoodsQuery->FieldByName("GoodsName")+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsSpec"))+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsPmpcCode"))+  //类型
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsUnitCode"))+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsCurrencyCode"))+
          //"\t"+AnsiString((RsGoodsQuery->FieldByName("GoodsFrom")=="1")?"采购":"制造")+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsMaxQty"))+
          "\t"+AnsiString(RsGoodsQuery->FieldByName("GoodsSafeQty")) ;

      sgGoods->AddItem(ItemStr);
      RsGoodsQuery->MoveNext();
    }
    sgGoods->ScrollBars=ssBoth;//设置滚动条
    lbQueryCount->Caption=sgGoods->RowCount-1;
  }
  __finally
  {
    EndWaitForm();
    edtLocate->Text=LocCodeStr;
  }
}
//---------------------------------------------------------------------------

void __fastcall TfrmSupplyGoodsQuery::RadioGroup1Click(TObject *Sender)
{
  if(RadioGroup1->ItemIndex==0)//tsNormal
  {
    plExtend->Visible=false;
  }
  else
  {
    plExtend->Visible=true;
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSupplyGoodsQuery::btnCancelClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

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