bplan.cpp

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

CPP
334
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma link "RecBaseForm"
#pragma hdrstop
#include "Bplan.h"
#include "KSPurFuc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDGrid"
#pragma link "SDEdit"
#pragma link "SDComboBox"
#pragma link "DateEdit"
#pragma resource "*.dfm"
TfrmBplan *frmBplan;
//---------------------------------------------------------------------------
__fastcall TfrmBplan::TfrmBplan(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
        : TRecBaseForm(Owner,chWnd,MidCode,WhereStr)
{
IsUserCheck=true;

}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::ClearControl(bool BringToNext)
{
    if(BringToNext)
    {
       return;
    }
    seBplanLine->Text           =IntToStr(GetNextNo());
    seBplanGoods->Text          ="";
    seGoodsName->Text           ="";
    seBplanUnit->Text           ="";
    seBplanQty->Text            ="0.0";
    deBplanRDate->Text          ="";
    deBplanDate->Text           =g_sdCurDate;
    seBplanRQty->Text           ="0.0";
    scBplanState->ItemIndex     =0;
    labBplanUser->Caption       =g_sdUserCode;
    chkBplanCheck->Checked      =false;
    seBplanChecker->Text        ="";
    deBplanCheckDate->Text      ="";
    labSystemDate->Caption      ="";
    //新增,工具栏使能
    SetCheckToolbarStatus(false);
   }
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::GetDataFromComObject()
{
    
    seBplanLine->Text =  GetFieldValue("BplanLine");
    sgBplan->LocateGrid(1,GetFieldValue("BplanLine"));
    l_Query->LocateByKey(GetFieldValue("BplanGoods"));
    seBplanGoods->Text=l_Query->FieldByName("GoodsCode");
    seGoodsName->Text=l_Query->FieldByName("GoodsName");
    seBplanUnit->Text =l_Query->FieldByName("GoodsUnitcode");
    seBplanQty->Text          =   GetFieldValue("BplanQty");
    deBplanRDate->Text        =   GetFieldValue("BplanRDate");
    deBplanDate->Text         =   GetFieldValue("BplanDate");
    seBplanRQty->Text         =   GetFieldValue("BplanRQty");
    //modify by lu 2001.12.23  reason:GetFieldValue("BplanState") always return ""(NULL)
    AnsiString bs = GetFieldValue("BplanState");
    if(bs == "")
       bs = "1";
    scBplanState->ItemIndex   =   StrToInt(bs)-1;
    //scBplanState->ItemIndex   =   StrToInt(GetFieldValue("BplanState"))-1;  //old
    //modify over
    chkBplanCheck->Checked    =   GetFieldValue("BplanCheck")=="1";
    seBplanChecker->Text      =   GetFieldValue("BplanChecker");
    deBplanCheckDate->Text    =   GetFieldValue("BplanCheckDate");
    labBplanUser->Caption     =   GetFieldValue("BplanUser");
    labSystemDate->Caption    =   GetFieldValue("BplanSysDate");
    //根据审核状态,设置工具栏
    if(GetFieldValue("BplanCheck")=="1")
     SetCheckToolbarStatus(true);
    else
     SetCheckToolbarStatus(false);

}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::SendDataToComObject()
{
    if(seBplanLine->Text == "")
     throw Exception("请输入计划行号");
     if(deBplanRDate->Text == "")
     throw Exception("请输入需求日期");
    if(seBplanQty->Text == "0.0")
     throw Exception("请输入需求数量");
    if(seBplanRQty->Text == "")
      seBplanRQty->Text="0";
    if(seBplanGoods->Text=="")
    throw Exception ("请输入物料编码");
    SetFieldValue("BplanYear",scBplanYear->Text);
    SetFieldValue("BplanNo",scBplanNo->Text);
    SetFieldValue("BplanLine",seBplanLine->Text);
    SetFieldValue("BplanGoods",seBplanGoods->Text);
    SetFieldValue("BplanUnit",seBplanUnit->Text);
    SetFieldValue("BplanQty",seBplanQty->Text);
    SetFieldValue("BplanRDate",deBplanRDate->Text);
    SetFieldValue("BplanDate",deBplanDate->Text);
    SetFieldValue("BplanRQty",seBplanRQty->Text);
    SetFieldValue("BplanState",IntToStr(scBplanState->ItemIndex+1));
    SetFieldValue("BplanUser",labBplanUser->Caption);
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::WaitUserInput()
{
    seBplanGoods->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmBplan::GetDataToGrid()
{
    AnsiString  s;
    s = "\t" +GetFieldValue("BplanLine");
    s +="\t" + GetFieldValue("BplanGoods");
    s +="\t" + GetFieldValue("BplanUnit");
    s +="\t" + GetFieldValue("BplanQty");
    s +="\t" + GetFieldValue("BplanRDate");
    s +="\t" + GetFieldValue("BplanDate");
    s +="\t" + GetFieldValue("BplanRQty");
    return(s);
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::RefreshGridData(int mAction)
{
    AnsiString ItemStr;
    ItemStr = GetDataToGrid();
    if (mAction ==  0)
    {
        sgBplan->AddItem(ItemStr);
    }
    else if(mAction ==  1)
    {
        int i   =   sgBplan->Row;
        sgBplan->ChangeItem(ItemStr,i);
    }
    else if(mAction ==  2)
    {
        sgBplan->RemoveItem(sgBplan->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::FillGridWithData()
{
    AnsiString ItemStr;
    comServer->MoveFirst();
    sgBplan->RowCount = 1;
    while(comServer->Eof==0)
    {
        ItemStr =   GetDataToGrid();
        sgBplan->AddItem(ItemStr);
        comServer->MoveNext();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::InitEditControl()
{
    ClientGroup->AddComponent(2,true,true,false, sgBplan,sgBplan->Name);
    ClientGroup->AddComponent(2,true,false,false, seBplanGoods,seBplanGoods->Name);
    ClientGroup->AddComponent(2,true,false,false, seBplanQty,seBplanQty->Name);
    ClientGroup->AddComponent(2,true,true,false,  FloatPanel2,FloatPanel2->Name);
    ClientGroup->AddComponent(2,false,false,true, FloatPanel1,FloatPanel1->Name);
    ClientGroup->AddComponent(2,false,false,false, seBplanLine,seBplanLine->Name);
    ClientGroup->AddComponent(2,false,false,true,  seBplanRQty,seBplanRQty->Name);
    ClientGroup->AddComponent(2,true,true,true,  scBplanState,scBplanState->Name);
    ClientGroup->AddComponent(2,true,true,true, gbCheck,gbCheck->Name);
    FillComboBox(Handle,scBplanYear,"select distinct PeriodYear,PeriodType from sdPeriod where PeriodCheck=1 order by PeriodYear desc","PeriodYear","PeriodType");
    scBplanState->ClearAll();
    scBplanState->AddItems("1-初始","1");
    scBplanState->AddItems("2-确认","2");
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::FormShow(TObject *Sender)
{
    l_Query->Close();
    l_Query->Open("select goodsname,goodscode,goodsspec,GoodsTrackSo,GoodsBatch,GoodsUnitCode from sdgoods","goodscode");
    scBplanYearClick(NULL);
    TfrmBplan::ClearControl(false);
    sgBplan->SetFocus();

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


void __fastcall TfrmBplan::seBplanGoodsButtonClick(TObject *Sender)
{
TComResultSet * TempRes = new TComResultSet(Handle,g_ClientHandle);
if(OpenGoodsForm(""))
    {
        seBplanGoods->Text=GetGoodsValue(gtOpenForm,"GoodsCode");
        seGoodsName->Text =GetGoodsValue(gtOpenForm,"GoodsName");
        seBplanUnit->Text =GetGoodsValue(gtOpenForm,"GoodsUnitCode");
        if(IsLegitGU(seBplanGoods->Text,TempRes)==0)
          {
          seBplanGoods->Text="";
          }
     }
delete TempRes;

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


void __fastcall TfrmBplan::RefreshUpdateData(int MsgSrc,int MsgType)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::scBplanYearClick(TObject *Sender)
{
   AnsiString sSQL;
   int iType;
   sSQL ="select PeriodNo,PeriodBDate,PeriodEDate from sdPeriod where Periodyear='"+scBplanYear->Text+"'";
   sSQL+=" order by PeriodNo";
   FillComboBox(Handle,scBplanNo,sSQL,"PeriodNo","PeriodBDate","PeriodEDate");
   iType=StrToIntDef(scBplanYear->ItemData[1],-1);
   switch(iType)
   {
    case 1:
     lblUnit->Caption="天";
     break;
    case 2:
     lblUnit->Caption="周";
     break;
    case 3:
     lblUnit->Caption="旬";
     break;
    case 4:
     lblUnit->Caption="半月";
     break;
    case 5:
     lblUnit->Caption="月";
     break;
    case 6:
     lblUnit->Caption="季";
     break;
    case 7:
     lblUnit->Caption="半年";
     break;
    case 8:
     lblUnit->Caption="年";
     break;
    default:
     lblUnit->Caption="";
   }
   FiltPlan();
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::FiltPlan()
{
    AnsiString sYear,sNo,sFilter;
    lblPeriodDate->Caption=scBplanNo->ItemData[1]+"--"+scBplanNo->ItemData[2];
    sYear=Trim(scBplanYear->Text);
    sNo=Trim(scBplanNo->Text);
    sFilter = " BplanYear = '"+sYear+"' and BplanNo="+sNo;
    comServer->FilterString = AnsiString(sFilter);
    comServer->Query();
    FillGridWithData();
    GetDataFromComObject();
}
//---------------------------------------------------------------------------

void __fastcall TfrmBplan::scBplanNoClick(TObject *Sender)
{

 FiltPlan();
 TfrmBplan::ClearControl(false);
}
//---------------------------------------------------------------------------

void __fastcall TfrmBplan::seBplanLineKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13 && CurrentState==caNormal)
    {
      comServer->LocateByKey(WideString(scBplanYear->Text+ "\t"+scBplanNo->Text+ "\t"+seBplanLine->Text));
      GetDataFromComObject();
    }
}
//---------------------------------------------------------------------------
int __fastcall TfrmBplan::GetNextNo()
{
 int iCurNo;
 if(comServer->RecordCount == 0)
  return(1);
 else
 {
  comServer->MoveLast();
  iCurNo=StrToIntDef(GetFieldValue("BplanLine"),0);
  return(iCurNo+1);
 }
}
//---------------------------------------------------------------------------
bool __fastcall TfrmBplan::BeforeCheck()
{
  SetFieldValue("BplanCheck",1);
  SetFieldValue("BplanChecker",g_sdUserCode);
  SetFieldValue("BplanCheckDate",g_sdCurDate);
  return true;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmBplan::BeforeUnCheck()
{
  SetFieldValue("BplanCheck",0);
  SetFieldValue("BplanChecker",g_sdUserCode);
  SetFieldValue("BplanCheckDate",g_sdCurDate);
  return true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::sgBplanClick(TObject *Sender)
{
AnsiString KeyStr;
if(sgBplan->Row > 0)
    {
     KeyStr=Trim(scBplanYear->Text+"\t"+scBplanNo->Text+"\t"+sgBplan->TextMatrix[sgBplan->Row][1]);
     comServer->LocateByKey(KeyStr);
    }
    GetDataFromComObject();
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::seBplanGoodsExit(TObject *Sender)
{
TComResultSet * TempRes = new TComResultSet(Handle,g_ClientHandle);
if(IsLegitGU(seBplanGoods->Text,TempRes)==0)
{
    seBplanGoods->Text="";
}
delete TempRes;
    l_Query->LocateByKey(seBplanGoods->Text);
    seGoodsName->Text =l_Query->FieldByName("GoodsName");
    seBplanUnit->Text =l_Query->FieldByName("GoodsUnitCode");
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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