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

📄 sugh.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "Sugh.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "BillBaseForm"
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmSugh *frmSugh;
//---------------------------------------------------------------------------
__fastcall TfrmSugh::TfrmSugh(TComponent* Owner)
        : TBillBaseForm(Owner,euSdSugh,"")
{
    AutoCtl=seSughCode;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::InitEditControl()
{
   ClientGroup->AddComponent(1,false,false,true,fpSughHead,fpSughHead->Name);
   ClientGroup->AddComponent(1,false,true,false,seSughCode,seSughCode->Name);
   ClientGroup->AddComponent(1,true,true,true,scSughFmonth,scSughFmonth->Name);

   ClientGroup->AddComponent(2,false,false,true,fpSughDetail,fpSughDetail->Name);
   ClientGroup->AddComponent(2,false,true,true,seSugdGoods,seSugdGoods->Name);
   ClientGroup->AddComponent(2,true,true,true,scSugdUnit,scSugdUnit->Name);
   ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
   ClientGroup->AddComponent(2,false,true,true,btnOK,btnOK->Name);
   //h
   FillComboBox(scSughFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
   scSughType->ClearAll();
   scSughType->AddItems("1-销售备货","1");
   scSughType->AddItems("2-生产备货","2");
   scSughType->AddItems("3-其它备货","3");
   //d
   FillComboBox(scSugdUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
   FillEdit(seSugdLoc,"select LocCode,locname from sdLoc order by LocCode","Locname","LocCode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::ClearControl(int Section,bool BringToNext)
{
   if (Section == 1)
   {
      if (!BringToNext)
      {
      seSughCode->Text           ="";          //备货单号
      deSughDate->Text           =g_sdCurDate; // 备货日期
      scSughType->ItemIndex      =0;         //备货类型
      scSughFmonth->Text         =g_sdCMonth;  //月份
      seSughDesc->Text          ="";    //备注
      labSughUser->Caption       =g_sdUserCode;    //操作员
      chkSughCheck->Checked      =false; //审核标志
      labSughChecker->Caption    ="";    //审核人
      chkSughCancel->Checked     =false;  //取消标志
      labSughSysDate->Caption    ="";     //系统日期
      }
      sgSugh->RowCount=1;
   }
   else if (Section==2)
   {
      if (!BringToNext)
      {
      seSugdLine->Text   =AnsiString(comServer->ItemCount+1);  //备货行号
      seSugdGoods->Text  ="";  //物料编码
      seSugdGoodsName->Text ="";//物料名称
      scSugdUnit->ItemIndex =-1;  //计量单位
      seSugdQty->Text       ="0";  //备货数量
      seSugdLoc->ItemIndex  =-1;  //备货货位
      memSugdDesc->Text     ="";  //备货原因
      seSugdRQty->Text      ="0";  //释放数量
      }
   }
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmSugh::GetHeadValue(int Index)
{
    AnsiString S;
    S = ReadFieldValue(comServer,Index);
    return S;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmSugh::GetDetailValue(int Index)
{
    AnsiString S;
    S = ReadItemValue(comServer,Index);
    return S;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::SetHeadValue(int Index ,AnsiString Value)
{
   WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::SetDetailValue(int Index, AnsiString Value)
{
   WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmSugh::GetDataToGrid()
{
    AnsiString s;
    seSugdLoc->LocateKey(GetDetailValue(fiSugdLoc));
    scSugdUnit->LocateKey(GetDetailValue(fiSugdUnit));
    s ="\t" + GetDetailValue(fiSugdLine)    +
       "\t" + GetDetailValue(fiSugdGoods)   +
       "\t" + scSugdUnit->ItemData[0]       +
       "\t" + seSugdLoc->ItemData[0]        +
       "\t" + GetDetailValue(fiSugdQty)     +
       "\t" + GetDetailValue(fiSugdRQty)    ;
    return s;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::RefreshGridData(int mAction)
{
    int i;
    AnsiString ItemStr;
    switch(mAction)
    {
       case 0: // Append
         ItemStr=GetDataToGrid();
         sgSugh->AddItem(ItemStr);
         break;
       case 1: // Modify
         sgSugh->ChangeItem(ItemStr,sgSugh->Row);
         break;
       case 2: // Delete
         sgSugh->RemoveItem(sgSugh->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::GetDataFromComObject(int Section)
{
   if (Section==1)
   {
      seSughCode->Text            = GetHeadValue(fiSughCode);
      deSughDate->Text            = GetHeadValue(fiSughDate);
      scSughType->LocateKey(GetHeadValue(fiSughType));
      scSughType->Text            =scSughType->ItemData[0];
      scSughFmonth->Text          = GetHeadValue(fiSughFmonth);
      seSughDesc->Text           = GetHeadValue(fiSughDesc);
      labSughUser->Caption        = GetHeadValue(fiSughUser);
      chkSughCheck->Checked       =(GetHeadValue(fiSughCheck)=="1"?true:false);
      if(chkSughCheck->Checked)
        SetCheckToolbarStatus(true);
      else
        SetCheckToolbarStatus(false);
      labSughChecker->Caption     = GetHeadValue(fiSughChecker);
      chkSughCancel->Checked      =( GetHeadValue(fiSughCancel)=="1"?true:false);
      labSughSysDate->Caption     = GetHeadValue(fiSughSysDate);
   }
   else
   {
      seSugdLine->Text   = GetDetailValue(fiSugdLine);
      g_sdRsGoods->LocateByKey(WideString(GetDetailValue(fiSugdGoods)));
      seSugdGoods->Text  =GetGoodsValue("GoodsCode");
      seSugdGoodsName->Text=GetGoodsValue("GoodsName");
      scSugdUnit->LocateKey(GetDetailValue(fiSugdUnit));
      scSugdUnit->Text   = scSugdUnit->ItemData[0];
      seSugdQty->Text    = GetDetailValue(fiSugdQty);
      seSugdLoc->LocateKey(GetDetailValue(fiSugdLoc));
      seSugdLoc->Text   =seSugdLoc->ItemData[0];
      memSugdDesc->Text   = GetDetailValue(fiSugdDesc);
      seSugdRQty->Text   = GetDetailValue(fiSugdRQty);
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::SendDataToComObject(int Section)
{
    if (Section==1)  // Head
   {
      SetHeadValue(fiSughCode,seSughCode->Text);
      SetHeadValue(fiSughDate,deSughDate->Text);
      if(scSughType->ItemData[1] == "")
       throw Exception("请选择备货类型");
      SetHeadValue(fiSughType,scSughType->ItemData[1]);
      SetHeadValue(fiSughFmonth,scSughFmonth->Text);
      SetHeadValue(fiSughDesc,seSughDesc->Text);
      SetHeadValue(fiSughUser,labSughUser->Caption);
      SetHeadValue(fiSughCheck,chkSughCheck->Checked?"1":"0");
      SetHeadValue(fiSughChecker,labSughChecker->Caption);
      SetHeadValue(fiSughCancel,chkSughCancel->Checked?"1":"0");
   }
   else
   {
      SetDetailValue(fiSugdCode,seSughCode->Text);
      SetDetailValue(fiSugdLine,seSugdLine->Text);
      SetDetailValue(fiSugdGoods,seSugdGoods->Text);
      SetDetailValue(fiSugdUnit,scSugdUnit->ItemData[1]);
      SetDetailValue(fiSugdQty,seSugdQty->Text);
      SetDetailValue(fiSugdLoc,seSugdLoc->ItemData[1]);
      SetDetailValue(fiSugdDesc,memSugdDesc->Text);
      SetDetailValue(fiSugdRQty,seSugdRQty->Text);
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::WaitUserInput(int Section)
{
   if (Section ==1)
   {
    if(seSughCode->Enabled)
     seSughCode->SetFocus();
   }
   else
   {
     sgSugh->Visible=false;
     fpSughDetail->Visible=true;
     if(seSugdGoods->Enabled)
      seSugdGoods->SetFocus();
   }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::DisplayBill()
{
    if(comServer->RecordCount==0)
       return;
    GetDataFromComObject(1);  // Head
    FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::GetBill(AnsiString BillID)
{
    int iRow;
    iRow=comServer->Find("SughCode='"+BillID+"'");
    if (iRow>0)      //FIND THIS BILL
    {
       DisplayBill();
    }
    else if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
    {
      AddHeadRecord();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::FillGridWithData()
{
    sgSugh->RowCount=1;
    if(comServer->RecordCount > 0)
      for (int i=0;i<comServer->ItemCount;i++)
      {
        comServer->LocateItemByIndex(i);
        RefreshGridData(0); // Append
      }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::ChangeToBrowseState(bool Browse)
{
     sgSugh->Visible=true;
     fpSughDetail->Visible=false;
     if(Browse==false)
      sgSugh->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::sgSughDblClick(TObject *Sender)
{
    int iRow;
    iRow=sgSugh->Row;
    if (iRow == 0)
       return;
    if (!comServer->Eof)
    {
       GetDataFromComObject(2);   // Detail
       sgSugh->Visible=false;
       fpSughDetail->Visible=true;
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmSugh::sgSughSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if (ARow > 0)
       comServer->LocateItemByKey(WideString(sgSugh->TextMatrix[ARow][1]));
    if (!comServer->Eof)
       GetDataFromComObject(2);    // Detail
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::btnOKClick(TObject *Sender)
{
  try
  {
    if (CurrentState==caAddDetail||CurrentState==caAddBill)
    {
       if(DetailState==caAddDetail)
         comServer->AddItem();
       SendDataToComObject(2);
       comServer->AddToObject();
       ClearControl(2,false);
       seSugdLine->SetFocus();
    }
    else
      ChangeToBrowseState();
  }
  catch(Exception &e)
  {
   throw Exception(e.Message);
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::btnCancelClick(TObject *Sender)
{
     CancelChange();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSugh::FormShow(TObject *Sender)
{
    ClearControl(1,false); // Head
    ClearControl(2,false); // Detail
    MoveToFirst();
    ChangeToBrowseState();
}
//---------------------------------------------------------------------------

void __fastcall TfrmSugh::seSugdGoodsButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    TfrmWnQuery *p;
    SqlStr="003[物料编码][物料名称][计量单位]select goodscode ,goodsname,goodsunitcode ";
    SqlStr+=" from  sdGoods where goodsstate=2 order by goodscode  ";
    try{
     StartWaitForm("正在查询,请稍候...");
     p=new TfrmWnQuery(this,"物料查询",SqlStr);
    }
    __finally
    {
     EndWaitForm();
    }
    if(p->ShowModal()==mrOk)
    {
      seSugdGoods->Text=p->ColData[1];
      seSugdGoodsName->Text=p->ColData[2];
      scSugdUnit->LocateKey(p->ColData[3]);
    }
    delete p;

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

void __fastcall TfrmSugh::RefreshUpdateData(int MsgSrc,int MsgType)
{
      switch(MsgSrc)
      {
        case euSdFc:
          if(ShowUpdateMessage(MsgSrc,MsgType))
            FillComboBox(scSughFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
         break;
        case euSdUnit:
          if(ShowUpdateMessage(MsgSrc,MsgType))
           FillComboBox(scSugdUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
         break;
        case euSdLoc:
          if(ShowUpdateMessage(MsgSrc,MsgType))
           FillEdit(seSugdLoc,"select LocCode,locname from sdLoc order by LocCode","Locname","LocCode");
         break;
       default:
         break;
      }
}
//---------------------------------------------------------------------------


void __fastcall TfrmSugh::seSugdGoodsExit(TObject *Sender)
{
  int IsFound=g_sdRsGoods->LocateByKey(WideString(seSugdGoods->Text));
  if(IsFound != 0) //输入无效编码
  {
   seSugdGoods->Text="";
   return;
  }
  seSugdGoods->Text=GetGoodsValue("GoodsCode");
  seSugdGoodsName->Text=GetGoodsValue("GoodsName");
  scSugdUnit->LocateKey(GetGoodsValue("GoodsUnitCode"));
}
//---------------------------------------------------------------------------



void __fastcall TfrmSugh::seSugdLocButtonClick(TObject *Sender)
{
  AnsiString SqlStr;
  SqlStr="002[货位编码][货位名称]select Loccode,LocName from sdLoc,sdLg where LocCode=lgLocCode and lgState=1 and ";
  SqlStr+=" LocType=1 and lggoodscode='"+seSugdGoods->Text+"' order by LocCode";
  TfrmWnQuery *p;
  try
  {
    StartWaitForm("正在查询,请稍候...");
    p=new TfrmWnQuery(this,"备货货位查询",SqlStr);
  }
  __finally
  {
    EndWaitForm();
  }
  if(p->ShowModal()==mrOk)
  {
    seSugdLoc->LocateKey(p->ColData[1]);
  }
  delete p;
}
//---------------------------------------------------------------------------

void __fastcall TfrmSugh::seSughCodeExit(TObject *Sender)
{
    if(CurrentState==caNormal && seSughCode->Text != GetHeadValue(fiSughCode))
    {
      comServer->LocateByKey(WideString(seSughCode->Text));
      DisplayBill();
    }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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