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

📄 sgd.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Sgd.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "RecBaseForm"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmSgd *frmSgd;
AnsiString __fastcall TfrmSgd::GetFieldValue(int FieldIndex)
{
    WideString S;
    S   =   ReadFieldValue(comServer,FieldIndex);
    return(S);
}

void __fastcall TfrmSgd::ClearControl(bool BringToNext)
{
    // BringToNext为真时,不清空
    if(BringToNext)
        return;

    seSgdCode->Text         =   "";
    seSgdName->Text         =   "";
    seSgdGoods->Text    =   "";
}

void __fastcall TfrmSgd::GetDataFromComObject()
{
    seSgdCode->Text         =   GetFieldValue(fiSgdCode);
    seSgdName->Text         =   GetFieldValue(fiSgdName);
    seSgdGoods->Text    =   GetFieldValue(fiSgdGoodsCode);
    sgSgd->LocateGrid(2,seSgdCode->Text);    
}

void __fastcall TfrmSgd::SendDataToComObject()
{
    AnsiString s;

    WriteFieldValue(comServer,fiSgdClientCode,WideString(cbSgdClientCode->ItemData[cbItem2]));
    WriteFieldValue(comServer,fiSgdCode,WideString(seSgdCode->Text));
    WriteFieldValue(comServer,fiSgdName,WideString(seSgdName->Text));
    WriteFieldValue(comServer,fiSgdGoodsCode,WideString(seSgdGoods->Text));
 }

void __fastcall TfrmSgd::WaitUserInput()
{
    if(seSgdGoods->Enabled)
    seSgdGoods->SetFocus();
}

AnsiString __fastcall TfrmSgd::GetDataToGrid()
{
    AnsiString  s;

    s   =   "\t" + GetFieldValue(fiSgdGoodsCode)+
            "\t" + GetFieldValue(fiSgdCode) +
            "\t" + GetFieldValue(fiSgdName);
    return(s);
}

void __fastcall TfrmSgd::RefreshGridData(int mAction)
{
    AnsiString ItemStr;

    ItemStr =   GetDataToGrid();
    // 新增
    if (mAction ==  0)
    {
        sgSgd->AddItem(ItemStr);
        sgSgd->Row=sgSgd->RowCount-1;
    }
    // 修改
    else if(mAction ==  1)
    {
     sgSgd->ChangeItem(ItemStr,sgSgd->Row);
     }
    // 删除
    else if(mAction ==  2)
    {
        sgSgd->RemoveItem(sgSgd->Row);
    }
    sgSgd->LocateGrid(1,seSgdGoods->Text);
}



void __fastcall TfrmSgd::FillGridWithData()
{
    AnsiString ItemStr;

    comServer->MoveFirst();
    sgSgd->RowCount    =   1;

    while (comServer->Eof   ==  0)
    {
        ItemStr =   GetDataToGrid();
        sgSgd->AddItem(ItemStr);
        comServer->MoveNext();
    }
}


void __fastcall TfrmSgd::InitEditControl()
{
    ClientGroup->AddComponent(2,true,true,false, sgSgd,sgSgd->Name);
    ClientGroup->AddComponent(2,false,false,true, FloatPanel1,FloatPanel1->Name);
    ClientGroup->AddComponent(2,true,true,false, FloatPanel2,FloatPanel2->Name);
//    FillComboBox(scSgdGoodsCode,"","GoodsCode","GoodsName");
}

__fastcall TfrmSgd::TfrmSgd(TComponent* Owner)
    : TRecBaseForm(Owner,euSdSgd,"")
{
   FillComboBox(cbSgdClientCode,"select ClientCode,ClientName from sdClient where ClientCancel=0 order by ClientCode","ClientName","ClientCode");
}
//---------------------------------------------------------------------------





void __fastcall TfrmSgd::cbSgdClientCodeClick(TObject *Sender)
{
   if(cbSgdClientCode->ItemData[cbItem2]!=ClientValue)
     {
         WideString s;

          s   =   "SgdClientCode = '" + cbSgdClientCode->ItemData[cbItem2] + "'";
          comServer->FilterString =   s;
          comServer->Query();

          FillGridWithData();
          comServer->MoveFirst();
          GetDataFromComObject();
          ClientValue=cbSgdClientCode->ItemData[cbItem2];
      }
}
//---------------------------------------------------------------------------


void __fastcall TfrmSgd::SetClientValue(AnsiString value)
{
        if(FClientValue != value) {
                FClientValue = value;
        }
}
AnsiString __fastcall TfrmSgd::GetClientValue()
{
        return FClientValue;
}
void __fastcall TfrmSgd::FormShow(TObject *Sender)
{
  cbSgdClientCodeClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TfrmSgd::sgSgdClick(TObject *Sender)
{
    if (sgSgd->Row    >   0)
         comServer->LocateByKey(WideString(cbSgdClientCode->ItemData[cbItem2]+sgSgd->TextMatrix[sgSgd->Row][1]));
    if (!comServer->Eof)
         GetDataFromComObject();

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

void __fastcall TfrmSgd::seSgdGoodsButtonClick(TObject *Sender)
{
 OpenGoodsQuery("Select * from sdGoods where GoodsSale=1 and GoodsCancel=0 order by GoodsCode");
 if(QueryStatus==1)
  {
  seSgdGoods->Text=GetGoodsValue("GoodsCode");
  seSgdCode->Text=seSgdGoods->Text;
  seSgdName->Text=GetGoodsValue("GoodsName");
  }
}
//---------------------------------------------------------------------------

void __fastcall TfrmSgd::seSgdGoodsExit(TObject *Sender)
{
 if(!seSgdGoods->Text.IsEmpty())
 {
  if(g_sdRsGoods->LocateByKey(WideString(seSgdGoods->Text))==0)
  {
  if(GetGoodsValue("GoodsSale")=="0")
     throw Exception("该物料不可销售");
  if(GetGoodsValue("GoodsCancel")=="1")
     throw Exception("该物料已取消");
  seSgdCode->Text=seSgdGoods->Text;
  seSgdName->Text=GetGoodsValue("GoodsName");
  }
  }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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