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

📄 bplan.cpp

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

#include "Bplan.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RecBaseForm"
#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)
    : TRecBaseForm(Owner,euSdBplan,"")
{
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmBplan::GetFieldValue(int FieldIndex)
{
    WideString S;
    S = ReadFieldValue(comServer,FieldIndex);
    return(AnsiString(S));
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::SetFieldValue(int Index,AnsiString Value)
{
    WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::ClearControl(bool BringToNext)
{
    if(BringToNext)
    {
       return;
    }
    seBplanLine->Text           =IntToStr(GetNextNo());
    seBplanGoods->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(fiBplanLine);
    sgBplan->LocateGrid(1,GetFieldValue(fiBplanLine));
    if(g_sdRsGoods->LocateByKey(WideString(GetFieldValue(fiBplanGoods)))==0)
    {
     seBplanGoods->Text        =   GetGoodsValue("GoodsCode");
     seBplanUnit->Text         =   GetFieldValue(fiBplanUnit);
    }
    else
    {
     seBplanGoods->Text        =   "";
     seBplanUnit->ItemIndex    =   -1;
    }
    seBplanQty->Text          =   GetFieldValue(fiBplanQty);
    deBplanRDate->Text        =   GetFieldValue(fiBplanRDate);
    deBplanDate->Text         =   GetFieldValue(fiBplanDate);
    seBplanRQty->Text         =   GetFieldValue(fiBplanRQty);
    scBplanState->ItemIndex   =   StrToInt(GetFieldValue(fiBplanState))-1;
    chkBplanCheck->Checked    =   GetFieldValue(fiBplanCheck)=="1";
    seBplanChecker->Text      =   GetFieldValue(fiBplanChecker);
    deBplanCheckDate->Text    =   GetFieldValue(fiBplanCheckDate);
    labBplanUser->Caption     =   GetFieldValue(fiBplanUser);
    labSystemDate->Caption    =   GetFieldValue(fiBplanSysDate);
    //根据审核状态,设置工具栏
    if(GetFieldValue(fiBplanCheck)=="1")
     SetCheckToolbarStatus(true);
    else
     SetCheckToolbarStatus(false);
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::SendDataToComObject()
{
    SetFieldValue(fiBplanYear,scBplanYear->Text);
    if(scBplanNo->Text == "")
     throw Exception("请选择计划周期号");
    SetFieldValue(fiBplanNo,scBplanNo->Text);
    if(seBplanLine->Text == "")
     throw Exception("请输入计划行号");
    SetFieldValue(fiBplanLine,seBplanLine->Text);
    SetFieldValue(fiBplanGoods,seBplanGoods->Text);
    SetFieldValue(fiBplanUnit,seBplanUnit->Text);
    if(seBplanQty->Text == "")
     throw Exception("请输入需求数量");
    SetFieldValue(fiBplanQty,seBplanQty->Text);
    SetFieldValue(fiBplanRDate,deBplanRDate->Text);
    SetFieldValue(fiBplanDate,deBplanDate->Text);
    if(seBplanRQty->Text == "")
     seBplanRQty->Text="0";
    SetFieldValue(fiBplanRQty,seBplanRQty->Text);
    SetFieldValue(fiBplanState,IntToStr(scBplanState->ItemIndex+1));
    SetFieldValue(fiBplanUser,labBplanUser->Caption);
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::WaitUserInput()
{
    seBplanGoods->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmBplan::GetDataToGrid()
{
    AnsiString  s;
    s = "\t" +GetFieldValue(fiBplanLine);
    s = s + "\t" + GetFieldValue(fiBplanGoods);
    s = s + "\t" + GetFieldValue(fiBplanUnit);
    s = s + "\t" + GetFieldValue(fiBplanQty);
    s = s + "\t" + GetFieldValue(fiBplanRDate);
    s = s + "\t" + GetFieldValue(fiBplanDate);
    s = s + "\t" + GetFieldValue(fiBplanRQty);
    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,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,true,true,true,  seBplanRQty,seBplanRQty->Name);
    ClientGroup->AddComponent(2,true,true,true,  scBplanState,scBplanState->Name);
    ClientGroup->AddComponent(2,true,true,true, gbCheck,gbCheck->Name);
    FillComboBox(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::FormClose(TObject *Sender, TCloseAction &Action)
{
    TRecBaseForm::FormClose(Sender,Action);
    //AnsiString FormIniFile = "D:\Test.Ini";
    //WriteGridWidth(Name,sgBplan,FormIniFile);
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::FormCreate(TObject *Sender)
{
    //AnsiString FormIniFile="D:\Test.Ini";
    //SetGridWidth(Name,sgBplan,FormIniFile);
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::FormShow(TObject *Sender)
{
    ClearControl(false);
    scBplanYearClick(NULL);
    sgBplan->SetFocus();
}
//---------------------------------------------------------------------------


void __fastcall TfrmBplan::seBplanGoodsButtonClick(TObject *Sender)
{
  AnsiString SqlStr;
  SqlStr="003[物料编码][物料名称][计量单位]";
  SqlStr+=" select GoodsCode,GoodsName,GoodsUnitCode from sdgoods where ";
  SqlStr+=" goodstype<>1 and goodstype<>2 and goodsfrom=1 and goodsstate=2 and goodscancel=0 ";
  SqlStr+=" order by GoodsCode";
  TfrmWnQuery *p;
  try
  {
    StartWaitForm("正在查询,请稍候...");
    p=new TfrmWnQuery(this,"物料查询",SqlStr);
  }
  __finally
  {
    EndWaitForm();
  }
  if(p->ShowModal()==mrOk)
  {
    seBplanGoods->Text=p->ColData[1];
    seBplanUnit->Text=p->ColData[3];
  }
  delete p;
}
//---------------------------------------------------------------------------

void __fastcall TfrmBplan::sgBplanClick(TObject *Sender)
{
    AnsiString KeyStr;
    int ARow=sgBplan->Row;
    if(ARow > 0)
    {
     KeyStr=sgBplan->TextMatrix[ARow][1];
     comServer->LocateByKey(WideString(scBplanYear->Text+scBplanNo->Text+KeyStr));
    }
    if(!comServer->Eof)
         GetDataFromComObject();
}
//---------------------------------------------------------------------------

void __fastcall TfrmBplan::seBplanGoodsExit(TObject *Sender)
{
 if(Trim(seBplanGoods->Text)!="")
 {
  g_sdRsGoods->LocateByKey(WideString(Trim(seBplanGoods->Text)));
  seBplanGoods->Text=GetGoodsValue("GoodsCode");
  seBplanUnit->Text=GetGoodsValue("GoodsUnitCode");
 }
}
//---------------------------------------------------------------------------
void __fastcall TfrmBplan::RefreshUpdateData(int MsgSrc,int MsgType)
{
  switch(MsgSrc)
  {
   case euSdPeriod:
    if(ShowUpdateMessage(MsgSrc,MsgType))
    {
     FillComboBox(scBplanYear,"select distinct PeriodYear,PeriodType from sdPeriod where PeriodCheck=1 order by PeriodYear desc","PeriodYear","PeriodType");
     scBplanYearClick(NULL);
    }
    break;
   default:
    break;
  }
}
//---------------------------------------------------------------------------
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(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 = WideString(sFilter);
    comServer->Query();
    FillGridWithData();
    comServer->MoveFirst();
    GetDataFromComObject();
}
//---------------------------------------------------------------------------

void __fastcall TfrmBplan::scBplanNoClick(TObject *Sender)
{
 FiltPlan();
}
//---------------------------------------------------------------------------

void __fastcall TfrmBplan::seBplanLineKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13 && CurrentState==caNormal)
    {
      comServer->LocateByKey(WideString(scBplanYear->Text+scBplanNo->Text+seBplanLine->Text));
      GetDataFromComObject();
    }
}
//---------------------------------------------------------------------------
int __fastcall TfrmBplan::GetNextNo()
{
 int iCurNo;
 if(comServer->RecordCount == 0)
  return(1);
 else
 {
  comServer->MoveLast();
  iCurNo=StrToIntDef(GetFieldValue(fiBplanLine),0);
  return(iCurNo+1);
 }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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