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

📄 rep.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Rep.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "RecBaseForm"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "DateEdit"
#pragma resource "*.dfm"

TfrmRep *frmRep;
AnsiString OldRepPgoods;
//---------------------------------------------------------------------------
__fastcall TfrmRep::TfrmRep(TComponent* Owner)
        : TRecBaseForm(Owner,euSdRep,"")
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmRep::InitEditControl()
{
    ClientGroup->AddComponent(2,false,false,true,FloatPanel1,FloatPanel1->Name);
    ClientGroup->AddComponent(2,false,false,true,FloatPanel3,FloatPanel3->Name);
    ClientGroup->AddComponent(2,true,true,false, sgRep,sgRep->Name);
    ClientGroup->AddComponent(2,true,false,true, chkRepCheck,chkRepCheck->Name);
    ClientGroup->AddComponent(2,true,true,false, FloatPanel2,FloatPanel2->Name);
    ClientGroup->AddComponent(2,true,true,true, Panel1,Panel1->Name);
    ClientGroup->AddComponent(2,true,true,true, seRepLlc,seRepLlc->Name);
    ClientGroup->AddComponent(2,true,true,true, seRepPGoodsName,seRepPGoodsName->Name);
    ClientGroup->AddComponent(2,false,true,true, scRepOGoods,scRepOGoods->Name);
    ClientGroup->AddComponent(2,true,true,true, seRepOGoodsName,seRepOGoodsName->Name);

    FillComboBox(scRepUnit,"select UnitCode,UnitName From sdUnit order by UnitCode","UnitName","UnitCode");
    FillComboBox(scRepProcess,"select memo=ProcessCode+space(1)+'('+ProcessName+')',ProcessCode From sdProcess order by ProcessCode","memo","ProcessCode");
    FillComboBox(scRepPGoods,"Select BomhGoods,GoodsName,memo=BomhGoods+space(1)+'('+GoodsName+')' from sdBomh,sdGoods where BomhGoods=GoodsCode Order by BomhGoods","memo","BomhGoods","GoodsName");
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmRep::GetFieldValue(int FieldIndex)
{
    return ReadFieldValue(comServer,FieldIndex);
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::SetFieldValue(int FieldIndex,AnsiString Value)
{
    WriteFieldValue(comServer,FieldIndex,Value);
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::ClearControl(bool BringToNext)
{
    if(!BringToNext)
    {
      scRepOGoods->ItemIndex=   -1;
      seRepOGoodsName->Text =   "";
      seRepNGoods->Text= "";
      seRepNGoodsName->Text =   "";
      seRepVer->Text        =   "";
      seRepModel->Text      =   "";
      scRepType->ItemIndex  =   0;
      scRepFrom->ItemIndex  =   0;
      scRepUnit->ItemIndex  =   -1;
      seRepQty->Text        =   "0.00";
      seRepShl->Text        =   "0.00";
      scRepProcess->ItemIndex=  -1;
      scRepCfg->ItemIndex   =   0;
      seRepLot->Text        =   "0";
      seRepLlc->Text        =   "1";
      scRepPp->ItemIndex    =   0;
      scRepOp->ItemIndex    =   0;
      deRepEdate->Text      =   g_sdCurDate;
      deRepIdate->Text      =   "";
      chkRepCheck->Checked  =   false;
      labChecker->Caption   =   "";
      labCheckDate->Caption =   "";
      labUserCode->Caption  =   g_sdUserCode;
      memRepDesc->Text      =   "";
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmRep::GetDataFromComObject()
{
    scRepOGoods->LocateKey(GetFieldValue(fiRepOgoods));
    seRepOGoodsName->Text=scRepOGoods->ItemData[2];
    g_sdRsGoods->LocateByKey(WideString(GetFieldValue(fiRepNgoods)));
    seRepNGoods->Text = GetGoodsValue("GoodsCode");
    seRepNGoodsName->Text = GetGoodsValue("GoodsName");
    seRepVer->Text = GetGoodsValue("GoodsVer");
    seRepModel->Text = GetGoodsValue("GoodsModel");
    if(GetGoodsValue("GoodsType")!="")
       scRepType->ItemIndex = StrToInt(GetGoodsValue("GoodsType"))-1;
    else
       scRepType->ItemIndex =-1;
    if(GetGoodsValue("GoodsFrom")!="")
       scRepFrom->ItemIndex = StrToInt(GetGoodsValue("GoodsFrom"))-1;
    else
       scRepFrom->ItemIndex =-1;
    scRepUnit->LocateKey(GetGoodsValue("GoodsUnitCode"));
    seRepQty->Text = GetFieldValue(fiRepQty);
    seRepShl->Text = GetFieldValue(fiRepShl);
    scRepProcess->LocateKey(GetFieldValue(fiRepProcess));
    scRepCfg->ItemIndex   =   StrToInt(GetFieldValue(fiRepCfg))-1;
    seRepLot->Text        =   GetFieldValue(fiRepLot);
    chkRepCheck->Checked  =   GetFieldValue(fiRepCheck)=="1";
    //设置check时的操作状态
    if(chkRepCheck->Checked)
       SetCheckToolbarStatus(true);
    else
       SetCheckToolbarStatus(false);
    labChecker->Caption   =   GetFieldValue(fiRepChecker);
    labCheckDate->Caption =   GetFieldValue(fiRepCheckDate);
    labUserCode->Caption  =   GetFieldValue(fiRepUser);
    seRepLlc->Text        =   GetFieldValue(fiRepLlc);
    scRepPp->ItemIndex    =   StrToInt(GetFieldValue(fiRepPp))-1;
    scRepOp->ItemIndex    =   StrToInt(GetFieldValue(fiRepOp))-1;
    deRepEdate->Text      =   GetFieldValue(fiRepEdate);
    deRepIdate->Text      =   GetFieldValue(fiRepIdate);
    memRepDesc->Text      =   GetFieldValue(fiRepDesc);
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::SendDataToComObject()
{
    SetFieldValue(fiRepPgoods,scRepPGoods->ItemData[1]);
    //-----------------------------------------------------------
    SetFieldValue(fiRepOgoods,scRepOGoods->ItemData[1]);
    SetFieldValue(fiRepNgoods,seRepNGoods->Text);
    SetFieldValue(fiRepQty,seRepQty->Text);
    SetFieldValue(fiRepShl,seRepShl->Text);
    SetFieldValue(fiRepProcess,scRepProcess->ItemData[cbItem2]);
    SetFieldValue(fiRepCfg,IntToStr(scRepCfg->ItemIndex+1));
    SetFieldValue(fiRepLot,seRepLot->Text);
    SetFieldValue(fiRepLlc,seRepLlc->Text);
    SetFieldValue(fiRepOp,IntToStr(scRepOp->ItemIndex+1));
    SetFieldValue(fiRepPp,IntToStr(scRepPp->ItemIndex+1));
    SetFieldValue(fiRepEdate,deRepEdate->Text);
    SetFieldValue(fiRepIdate,deRepIdate->Text);
    SetFieldValue(fiRepCheck,chkRepCheck->Checked ? "1":"0");
    if(chkRepCheck->Checked){
       SetFieldValue(fiRepChecker,labChecker->Caption);
       SetFieldValue(fiRepCheckDate,labCheckDate->Caption);
    }
    SetFieldValue(fiRepUser,g_sdUserCode);
    SetFieldValue(fiRepDesc,memRepDesc->Text);
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::WaitUserInput()
{
    PageControl1->ActivePage=BaseInfo;
    if(scRepPGoods->Text == "")
       scRepPGoods->SetFocus();
    else
       if(scRepOGoods->Enabled)
          scRepOGoods->SetFocus();
}
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmRep::GetDataToGrid()
{
    AnsiString  s,s1;
    s1= GetFieldValue(fiRepUnit);
    scRepUnit->LocateKey(s1);
    s = GetFieldValue(fiRepOgoods)+
        "\t" + GetFieldValue(fiRepNgoods)+
        "\t" + scRepUnit->ItemData[0]+
        "\t" + GetFieldValue(fiRepQty)+
        "\t" + GetFieldValue(fiRepShl);
    return(s);
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::RefreshGridData(int mAction)
{
    AnsiString ItemStr;
    ItemStr = GetDataToGrid();
    // 新增
    if(mAction == 0)
    {
        sgRep->AddItem(ItemStr);
        sgRep->Row=sgRep->RowCount-1;
    }
    // 修改
    else if(mAction == 1)
    {
        sgRep->ChangeItem(ItemStr,sgRep->Row);
    }
    // 删除
    else if(mAction == 2)
    {
        sgRep->RemoveItem(sgRep->Row);
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::FillGridWithData()
{
    AnsiString ItemStr;
    comServer->MoveFirst();
    sgRep->RowCount = 1;
    while(comServer->Eof == 0)
    {
        ItemStr = GetDataToGrid();
        sgRep->AddItem(ItemStr);
        comServer->MoveNext();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmRep::FormClose(TObject *Sender, TCloseAction &Action)
{
    TRecBaseForm::FormClose(Sender,Action);
/*
    AnsiString FormIniFile = "D:\Test.Ini";
    WriteGridWidth(Name,sgRep,FormIniFile);
*/
}
//---------------------------------------------------------------------------
void __fastcall TfrmRep::FormCreate(TObject *Sender)
{
/*
    AnsiString FormIniFile="D:\Test.Ini";
    SetGridWidth(Name,sgRep,FormIniFile);
*/
}
//---------------------------------------------------------------------------
void __fastcall TfrmRep::FormShow(TObject *Sender)
{
    tbCheck->Visible=true;
    ClearControl(false);
    PageControl1->ActivePage=BaseInfo;

    scRepPGoods->SetFocus();
    if(scRepPGoods->Items->Count>0)
    {
      scRepPGoods->ItemIndex=0;
       scRepPGoodsClick(this);
    }
    else
       comServer->FilterString=WideString("");
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::RefreshUpdateData(int MsgSrc,int MsgType)
{
    try
    {
       switch (MsgSrc)
       {
         case euSdUnit:
           if(ShowUpdateMessage(MsgSrc,MsgType)){ 
				      StartWaitForm("正在刷新引用数据!");
				      FillComboBox(scRepUnit,"select UnitCode,UnitName From sdUnit order by UnitCode","UnitName","UnitCode");
				      EndWaitForm();
				      break;
           } 
         case euSdProcess:
           if(ShowUpdateMessage(MsgSrc,MsgType)){ 
              StartWaitForm("正在刷新引用数据!");
		          FillComboBox(scRepProcess,"select memo=ProcessCode+space(1)+'('+ProcessName+')',ProcessCode From sdProcess order by ProcessCode","memo","ProcessCode");
		          EndWaitForm();
		          break;
           }
         case euSdBomh:
           if(ShowUpdateMessage(MsgSrc,MsgType)){ 
              StartWaitForm("正在刷新引用数据!");
              FillComboBox(scRepPGoods,"Select BomhGoods,GoodsName,memo=BomhGoods+space(1)+'('+GoodsName+')' from sdBomh,sdGoods where BomhGoods=GoodsCode Order by BomhGoods","memo","BomhGoods","GoodsName");
              EndWaitForm();
              break;
           }   
         default:
           break;
       }
    }
    __finally
    {
       //AddCode;
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::sgRepSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if(ARow > 0)
       comServer->LocateByKey(WideString(scRepPGoods->ItemData[1]+sgRep->TextMatrix[ARow][0]+sgRep->TextMatrix[ARow][1]));
    if(!comServer->Eof)
       GetDataFromComObject();
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::scRepPGoodsClick(TObject *Sender)
{
    AnsiString s,m_Sql;
    if(scRepPGoods->ItemIndex!=-1)
    {
      s=scRepPGoods->ItemData[1];
      if(OldRepPgoods==s)
         return;
      else
         OldRepPgoods=scRepPGoods->ItemData[1];
      seRepPGoodsName->Text = scRepPGoods->ItemData[2];
      m_Sql="Select memo=BomdGoods+space(1)+'('+GoodsName+')',BomdGoods,GoodsName from sdBomd,sdGoods where BomdGoods=GoodsCode and BomdPgoods='"+s+"'";
      FillComboBox(scRepOGoods,m_Sql,"memo","BomdGoods","GoodsName");
      s = "RepPGoods = '" + s + "'";
      comServer->FilterString = WideString(s);
      PageControl1->ActivePage=BaseInfo;
      comServer->Query();
      if(comServer->RecordCount>0)
      {
        FillGridWithData();
        comServer->MoveFirst();
        GetDataFromComObject();
      }
      else
      {
        sgRep->RowCount = 1;
        ClearControl(false);
      }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::seRepNGoodsButtonClick(TObject *Sender)
{
    OpenGoodsQuery("Select * from sdGoods where GoodsType<>1 order by GoodsCode");
    if(QueryStatus==1)
    {
        seRepNGoods->Text=GetGoodsValue("GoodsCode");
        seRepNGoodsName->Text=GetGoodsValue("GoodsName");
        seRepVer->Text=GetGoodsValue("GoodsVer");
        seRepModel->Text=GetGoodsValue("GoodsModel");
        scRepType->ItemIndex=StrToInt(GetGoodsValue("GoodsType"))-1;
        scRepFrom->ItemIndex=StrToInt(GetGoodsValue("GoodsFrom"))-1;
        scRepUnit->LocateKey(GetGoodsValue("GoodsUnitCode"));
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::scRepOGoodsClick(TObject *Sender)
{
    AnsiString s;
    s = Trim(scRepOGoods->Text);
    if(!s.IsEmpty())
       seRepOGoodsName->Text=scRepOGoods->ItemData[2];
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::muAddDetailClick(TObject *Sender)
{
    if(scRepPGoods->ItemIndex==-1)
    {
        ::MessageBox(Handle,"请先选择或输入一个父件物料编码,再点增加操作。","操作错误",MB_OK|MB_ICONSTOP);
        return;
    }
    TRecBaseForm::muAddDetailClick(Sender);

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

void __fastcall TfrmRep::seRepNGoodsExit(TObject *Sender)
{
    AnsiString tempS;
    tempS=seRepNGoods->Text;
    if(!tempS.IsEmpty())
    {
       if(g_sdRsGoods->LocateByKey(WideString(tempS))==0)
       {
          seRepNGoodsName->Text=GetGoodsValue("GoodsName");
          seRepVer->Text=GetGoodsValue("GoodsVer");
          seRepModel->Text=GetGoodsValue("GoodsModel");
          scRepType->ItemIndex=StrToInt(GetGoodsValue("GoodsType"))-1;
          scRepFrom->ItemIndex=StrToInt(GetGoodsValue("GoodsFrom"))-1;
          scRepUnit->LocateKey(GetGoodsValue("GoodsUnitCode"));
       }
       else
          ::MessageBox(Handle,"输入的物料编码不存在!","错误提示",MB_OK|MB_ICONSTOP);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmRep::muFirstClick(TObject *Sender)
{
    if(sgRep->RowCount > 1)
      sgRep->Row=1;
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::muPreviousClick(TObject *Sender)
{
    if(sgRep->RowCount > 1 && sgRep->Row > 1)
       sgRep->Row=sgRep->Row-1;
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::muNextClick(TObject *Sender)
{
    if(sgRep->RowCount > 1 && sgRep->Row < sgRep->RowCount-1)
       sgRep->Row=sgRep->Row+1;
}
//---------------------------------------------------------------------------

void __fastcall TfrmRep::muLastClick(TObject *Sender)
{
    if(sgRep->RowCount > 1)
       sgRep->Row=sgRep->RowCount-1;
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

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