vw_mrp.cpp

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

CPP
540
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "VW_Mrp.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "QueryBaseForm"
#pragma link "SDGrid"
#pragma link "KSAdvReport"
#pragma resource "*.dfm"
#define ParaCode "111"   //计划管理参数代码
TfrmVW_Mrp *frmVW_Mrp;
//---------------------------------------------------------------------------
__fastcall TfrmVW_Mrp::TfrmVW_Mrp(TComponent* Owner, HWND chWnd, AnsiString ClassCode,AnsiString WhereStr)
        : TQueryBaseForm(Owner,chWnd,ClassCode,WhereStr)
{
   Initiate();
}
//---------------------------------------------------------------------------
__fastcall TfrmVW_Mrp::TfrmVW_Mrp(TComponent* Owner,AnsiString wherestr)
        : TQueryBaseForm(Owner)
{
 Initiate();

 tbControl->Enabled=false;
 TBorderIcons tempBI = BorderIcons;
 tempBI >> biMinimize;
 BorderIcons = tempBI;
 FilterStr=wherestr;
 FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::Initiate()
{
 int BeginColNum;
 FilterStr="";
 sSQL="";
 GetParaValue();
 sgMrp->ColCount=10+zx_ColNum+jh_ColNum+xq_ColNum;
 sgMrp->RowCount=1;
 QueryGrid=sgMrp;
 sgMrp->Cells[0][0]="物料编码";
 sgMrp->Cells[1][0]="物料名称";
 sgMrp->Cells[2][0]="批量";
 sgMrp->Cells[3][0]="提前期";
 sgMrp->Cells[4][0]="当前库存";
 sgMrp->Cells[5][0]="安全库存";
 sgMrp->Cells[6][0]="已分配量";
 sgMrp->Cells[7][0]="低层码";
 sgMrp->Cells[8][0]="需求来源";
 sgMrp->Cells[9][0]="需求类型";
//sgMrp->Cells[10][0]="当期";
/*
 if(zx_ColNum+jh_ColNum+xq_ColNum > 20)
 {
  tbMainBar->Enabled=false;
  throw Exception("系统参数定义的总列数超限");
 }
*/
 BeginColNum=10; //起始周期列数
/* for(int i=0;i<zx_ColNum;i++)
 {
  sgMrp->Cells[BeginColNum+i][0]="执行"+IntToStr(i+1)+"区";
 }
 BeginColNum+=zx_ColNum;
 for(int i=0;i<jh_ColNum;i++)
 {
//  sgMrp->Columns[BeginColNum+i].ColumnFont->Color=clRed;
  sgMrp->Cells[BeginColNum+i][0]="计划"+IntToStr(i+1)+"区";
 }
 BeginColNum+=jh_ColNum;
 for(int i=0;i<xq_ColNum;i++)
 {
  sgMrp->Cells[BeginColNum+i][0]="需求"+IntToStr(i+1)+"区";
 } */

 AnsiString LCurDate=g_sdCurDate;
 AnsiString LCurDateZ;
 int m,n=0;
 for(int i=0;i<zx_ColNum;i++)
 {
  LCurDateZ = FormatDateTime("mm.dd",StrToDate(LCurDate)+(n));
  sgMrp->Cells[BeginColNum+i][0]="执行区"+LCurDateZ+""; //"+IntToStr(i+1)+"
  n=n+zx_ColPer ;
 }
   BeginColNum+=zx_ColNum;
  m=n;
  n=0;
 for(int i=0;i<jh_ColNum;i++)
 {
 LCurDateZ = FormatDateTime("mm.dd",StrToDate(LCurDate)+(m+n));
//  sgMrp->Columns[BeginColNum+i].ColumnFont->Color=clRed;
  sgMrp->Cells[BeginColNum+i][0]="需求区"+LCurDateZ+"";//"+IntToStr(i+1)+"
  n=n+jh_ColPer;
 }
 BeginColNum+=jh_ColNum;
 m=m+n;
 n=0;
 for(int i=0;i<xq_ColNum;i++)
 {
  LCurDateZ = FormatDateTime("mm.dd",StrToDate(LCurDate)+(m+n));
  sgMrp->Cells[BeginColNum+i][0]="计划区"+LCurDateZ+"";//"+IntToStr(i+1)+"
  n=n+jh_ColPer;
 } //xq_ColPer








}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::tbQueryClick(TObject *Sender)
{
  if(!ShowQueryWindow())
    return;
  try{
    StartWaitForm("正在查询,请稍候...");
    FillGridWithData();
  }
  __finally
  {
    EndWaitForm();
  }
}
//---------------------------------------------------------------------------
bool __fastcall TfrmVW_Mrp::ShowQueryWindow()
{
/*
  TfrmQuForm *FQuery=new TfrmQuForm(this,this->Name);
  FQuery->ShowModal();
  if(FQuery->CancelQuery)
    return false;
  FilterStr=FQuery->CreateSqlString;
  delete FQuery;  */
  return true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::ClearControl(bool BringToNext)
{
 return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::GetDataFromComObject()
{
 return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::WaitUserInput()
{
 return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::RefreshGridData(int mAction)
{
 return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::DisplayBill()
{
 return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::GetBill(AnsiString BillID)
{
 return;
}
//---------------------------------------------------------------------------
//获取查询语句
AnsiString __fastcall TfrmVW_Mrp::GetQueryStr()
{
 AnsiString Selectstr,Fromstr,Wherestr,Orderstr;
 Selectstr =" select * ";
 Fromstr=" from SDVW_Mrp ";
 Wherestr=" where MrpdRDate >= '"+g_sdCurDate+"'";
 if(FilterStr!="")
  Wherestr+=" and "+FilterStr;
 Orderstr=" order by MrpLlc,MrpGoods,MrpdType,MrpdRDate";
 sSQL=Selectstr+Fromstr+Wherestr+Orderstr;
 return(sSQL);
}
//---------------------------------------------------------------------------
void __fastcall TfrmVW_Mrp::FillGridWithData()
{
  TComResultSet *RsQuery;
  AnsiString ItemStr,sSql;
  AnsiString Tempstr,Tempstr1,Tempstr2;
  AnsiString sRDate;
  double iQty;
  //获取查询语句
  sSql=GetQueryStr();
  if(sSql=="")
    return;
  try
  {
//   StartWaitForm("正在执行查询...");
    sgMrp->RowCount=1;
    RsQuery=new  TComResultSet(Handle,g_ClientHandle);
    RsQuery->Open(sSql,"");
    RsQuery->MoveFirst();
    Tempstr1="";
    Tempstr2="";
    sgMrp->ScrollBars=ssNone; //取消滚动条,防止屏幕滚动
    while( RsQuery->Eof == 0)
    {
      Tempstr=     RsQuery->FieldByName("MrpGoods");
      if(Tempstr!=Tempstr1) //不同物料
      {
        Tempstr1=Tempstr;
        Tempstr2=   RsQuery->FieldByName("MrpdType");

        ItemStr=    RsQuery->FieldByName("MrpGoods")+
            "\t"+RsQuery->FieldByName("GoodsName")+
            "\t"+RsQuery->FieldByName("MrpEoq")+
            "\t"+RsQuery->FieldByName("MrpLt")+
            "\t"+RsQuery->FieldByName("MrpCiq")+
            "\t"+RsQuery->FieldByName("MrpSiq")+
            "\t"+RsQuery->FieldByName("MrpDiq")+
            "\t"+RsQuery->FieldByName("MrpLlc")+
            "\t"+DataConvert("MrpFrom",RsQuery->FieldByName("MrpFrom"))+
            "\t"+DataConvert("MrpdType",RsQuery->FieldByName("MrpdType"))+
            "\t"+AnsiString("0");
        sgMrp->AddItem(ItemStr);
        sgMrp->Row=sgMrp->RowCount-1;
        sRDate=RsQuery->FieldByName("MrpdRDate");
        iQty=StrToFloat(RsQuery->FieldByName("MrpdQty"));
        WriteMrpQty(sgMrp->Row,sRDate,iQty);
      }
      else    //相同物料
      {
        Tempstr=    RsQuery->FieldByName("MrpdType");
        if(Tempstr!=Tempstr2) //相同物料,不同需求类型
        {
          Tempstr2=Tempstr;
          ItemStr=   AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+AnsiString(" ")+
            "\t"+DataConvert("MrpdType",RsQuery->FieldByName("MrpdType"))+
            "\t"+AnsiString("0");
          sgMrp->AddItem(ItemStr);
          sgMrp->Row=sgMrp->RowCount-1;
          sRDate=RsQuery->FieldByName("MrpdRDate");
          iQty=StrToFloat(RsQuery->FieldByName("MrpdQty"));
          WriteMrpQty(sgMrp->Row,sRDate,iQty);
        }
        else                  //相同物料,相同需求类型,不同的需求日期
        {
          sRDate=RsQuery->FieldByName("MrpdRDate");
          iQty=StrToFloat(RsQuery->FieldByName("MrpdQty"));
          WriteMrpQty(sgMrp->Row,sRDate,iQty);
        }
      }
      RsQuery->MoveNext();
    }
    RsQuery->Close();
    sgMrp->ScrollBars=ssBoth;//设置滚动条
  }
  __finally
  {
//    EndWaitForm();

⌨️ 快捷键说明

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