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

📄 rwt.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "Rwt.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RecBaseForm"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "DateEdit"
#pragma resource "*.dfm"
TfrmRwt *frmRwt;

//---------------------------------------------------------------------------
__fastcall TfrmRwt::TfrmRwt(TComponent* Owner)
        : TRecBaseForm(Owner,euSdRwt,"")
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::InitEditControl()
{
    ClientGroup->AddComponent(2,true,true,false, sgRwt,sgRwt->Name);
    ClientGroup->AddComponent(2,true,true,false, scRwtLoc,scRwtLoc->Name);
    ClientGroup->AddComponent(2,false,false,true, FloatPanel1,FloatPanel1->Name);
    ClientGroup->AddComponent(2,true,false,true, deRwtIdate,deRwtIdate->Name);
    ClientGroup->AddComponent(2,true,true,true,scRwtUnit,scRwtUnit->Name);
    ClientGroup->AddComponent(2,true,true,true,scRwtUser,scRwtUser->Name);
    FillComboBox(scRwtLoc,"select LocCode,locname from sdLoc order by LocCode","LocCode","Locname");
    FillComboBox(scRwtUser,"select UserCode,UserName from sdUser order By UserCode","UserName","UserCode");
    FillComboBox(scRwtUnit,"SELECT UnitCode,Unitname FROM sdUnit","UnitName","UnitCode");

}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmRwt::GetFieldValue(int FieldIndex)
{
    WideString S;
    S = ReadFieldValue(comServer,FieldIndex);
    return(S);
}

//---------------------------------------------------------------------------
void __fastcall TfrmRwt::ClearControl(bool BringToNext)
{
     if(!BringToNext)
    {
       seRwtGoods->Text="";
       seRwtGoodsName->Text="";
       seRwtTime->Text ="0";
       scRwtUnit->Text ="";
       deRwtEdate->Text=g_sdCurDate;
       deRwtIdate->Text="";
       scRwtUser->LocateKey(g_sdUserCode);
   }

}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::GetDataFromComObject()
{
    g_sdRsGoods->LocateByKey(GetFieldValue(fiRwtGoods));
    seRwtGoods->Text=GetGoodsValue("GoodsCode");
    sgRwt->LocateGrid(1,seRwtGoods->Text);
    seRwtGoodsName->Text=GetGoodsValue("GoodsName");
    scRwtUnit->LocateKey(GetFieldValue(fiRwtUnit));
    scRwtUnit->Text=scRwtUnit->ItemData[0];
    seRwtTime->Text         =   GetFieldValue(fiRwtTime);
    deRwtEdate->Text        =   GetFieldValue(fiRwtEdate);
    deRwtIdate->Text        =   GetFieldValue(fiRwtIdate);
    scRwtUser->LocateKey(GetFieldValue(fiRwtUser));
    scRwtUser->Text         =    scRwtUser->ItemData[0];

}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::SendDataToComObject()
{
    WriteFieldValue(comServer,fiRwtGoods,seRwtGoods->Text);
    WriteFieldValue(comServer,fiRwtLoc,scRwtLoc->Text);
    WriteFieldValue(comServer,fiRwtTime,seRwtTime->Text);
    WriteFieldValue(comServer,fiRwtUnit,scRwtUnit->ItemData[1]);
    WriteFieldValue(comServer,fiRwtEdate,deRwtEdate->Text);
    WriteFieldValue(comServer,fiRwtIdate,deRwtIdate->Text);
    WriteFieldValue(comServer,fiRwtUser,scRwtUser->ItemData[1]);
}     
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::WaitUserInput()
{
  seRwtGoods->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmRwt::GetDataToGrid()
{

    scRwtUnit->LocateKey(GetFieldValue(fiRwtUnit));
    AnsiString  s;
    s = "\t" +GetFieldValue(fiRwtGoods)+
        "\t" + scRwtUnit->ItemData[0]+
        "\t" + GetFieldValue(fiRwtTime);
    return(s);

}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::RefreshGridData(int mAction)
{
    AnsiString ItemStr;
    ItemStr =   GetDataToGrid();
    // 新增
    if (mAction ==  0)
    {
        sgRwt->AddItem(ItemStr);
    }
    // 修改
    else if(mAction == 1)
    {
        int i = sgRwt->Row;
        sgRwt->RemoveItem(i);
        sgRwt->AddItem(ItemStr,i);
    }
    // 删除    0
    else if(mAction ==  2)
    {
        sgRwt->RemoveItem(sgRwt->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::FillGridWithData()
{
    AnsiString ItemStr;
    comServer->MoveFirst();
    sgRwt->RowCount  = 1;
    while(comServer->Eof == 0)
    {
        ItemStr=GetDataToGrid();
        sgRwt->AddItem(ItemStr);
        comServer->MoveNext();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::scRwtLocClick(TObject *Sender)
{
    AnsiString s;
    s = scRwtLoc->Text;
    if(s.IsEmpty())
      return;
    if(LastRwtLoc==s)
      return;
    LastRwtLoc=s;
    if(scRwtLoc->ItemIndex==-1)
    {
      MessageDlg("货位代码 "+scRwtLoc->Text+"不存在",mtWarning,TMsgDlgButtons()<<mbOK,0);
      scRwtLoc->LocateKey(LastRwtLoc);
    }
    else
    {
      scRwtLoc->LocateKey(scRwtLoc->Text);
      seRwtLocName->Text=scRwtLoc->ItemData[1];
      s = " RwtLoc = '" + s + "'";
      comServer->FilterString = s;
      comServer->Query();
      FillGridWithData();
      comServer->MoveFirst();
      GetDataFromComObject();
     }
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::seRwtGoodsButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    TfrmWnQuery *p;
    SqlStr="003[物料编码][物料名称][计量单位]SELECT goodscode,goodsname,goodsunitcode  FROM sdGoods ,sdlg " ;
    SqlStr+=" where ( goodstype='1' or goodstype='2') and GOODSCODE=LGGOODSCODE and LGLOCCODE='"+scRwtLoc->Text+"' order by goodscode";
    try{
     StartWaitForm("正在查询,请稍候...");
     p=new TfrmWnQuery(this,"物料查询",SqlStr);
    }
    __finally
    {
     EndWaitForm();
    }
    if(p->ShowModal()==mrOk)
    {
      seRwtGoods->Text=p->ColData[1];
      seRwtGoodsName->Text=p->ColData[2];
      scRwtUnit->LocateKey(p->ColData[3]);
    }
    delete p;

}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::RefreshUpdateData(int MsgSrc,int MsgType)
{
      switch(MsgSrc)
      {
        case euSdLoc:
          if(ShowUpdateMessage(MsgSrc,MsgType))
             FillComboBox(scRwtLoc,"select LocCode,locname from sdLoc order by LocCode","LocCode","Locname");
         break;
        case euSdUser:
          if(ShowUpdateMessage(MsgSrc,MsgType))
             FillComboBox(scRwtUser,"select UserCode,UserName from sdUser order By UserCode","UserName","UserCode");
         break;
        case euSdUnit:
          if(ShowUpdateMessage(MsgSrc,MsgType))
             FillComboBox(scRwtUnit,"SELECT UnitCode,Unitname FROM sdUnit","UnitName","UnitCode");
         break;
       default:
         break;
      }
}
//---------------------------------------------------------------------------

void __fastcall TfrmRwt::seRwtGoodsKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13)
    {
      TComResultSet *TResultSet=NewResultSet();
      AnsiString strSQL;
      strSQL="SELECT * FROM sdGoods ,sdlg where ( goodstype='1' or goodstype='2') and GOODSCODE=LGGOODSCODE and GOODSCODE='"+seRwtGoods->Text+"' and LGLOCCODE='"+scRwtLoc->Text+"'";
      TResultSet->Close();
      try
      {
       TResultSet->Open(strSQL,"");
       if(TResultSet->RecordCount<1)
       throw  Exception("物料"+seRwtGoods->Text+"'不存在、不在该货位或不是成品、半成品");
        seRwtGoodsName->Text=TResultSet->FieldByName("GoodsName");
       scRwtUnit->LocateKey(TResultSet->FieldByName("GoodsUnitCode"));
       TResultSet->Close();
       }
       __finally
       {
         delete TResultSet;
       }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmRwt::sgRwtClick(TObject *Sender)
{
    if (sgRwt->Row > 0)
    {
     comServer->LocateByKey(sgRwt->TextMatrix[sgRwt->Row][1]+scRwtLoc->Text);
    if (!comServer->Eof)
     GetDataFromComObject();
     }

}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::FormShow(TObject *Sender)
{
      scRwtLoc->LocateKey(scRwtLoc->Text);
      seRwtLocName->Text=scRwtLoc->ItemData[1];
      comServer->FilterString = " RwtLoc = '" + scRwtLoc->Text + "'";
      comServer->Query();
      FillGridWithData();
      comServer->MoveFirst();
      GetDataFromComObject();

}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::muEditDetailClick(TObject *Sender)
{
    scRwtUser->LocateKey(g_sdUserCode);
    TRecBaseForm::muEditDetailClick(Sender);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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