scmbh.cpp

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

CPP
409
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Scmbh.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"
TfrmScmbh *frmScmbh;
//---------------------------------------------------------------------------
__fastcall TfrmScmbh::TfrmScmbh(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
        : TBillBaseForm(Owner,chWnd,MidCode,WhereStr)
{
  SetAutoCodeString(seScmbhCode,"Acm-018");

}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::InitEditControl()
{
    ClientGroup->AddComponent(1,false,false,true,fpScmbhHead,fpScmbhHead->Name);
    ClientGroup->AddComponent(2,false,false,true,fpScmbhDetail,fpScmbhDetail->Name);
    ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
    ClientGroup->AddComponent(2,false,true,true,btnOK,btnOK->Name);
    ClientGroup->AddComponent(2,true,true,true,scScmbdGoodsUnit,scScmbdGoodsUnit->Name);
    ClientGroup->AddComponent(1,false,true,false,seScmbhCode,seScmbhCode->Name);
    ClientGroup->AddComponent(1,true,true,true,scScmbhFmonth,scScmbhFmonth->Name);
   //h
    FillComboBox(Query,scScmbhFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
   //d
    FillComboBox(Query,scScmbdGoodsUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");

}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::ClearControl(int Section,bool BringToNext)
{
    if (Section == 1)
    {
       if (!BringToNext)
       {
          seScmbhCode->Text         ="";
          deScmbhDate->Text         =g_sdCurDate;
          scScmbhFmonth->Text       =g_sdCMonth;
          seScmbhDesc->Text         ="";
          labScmbhSysDate->Caption  ="";
          chkScmbhCheck->Checked    =false;
          labScmbhChecker->Caption  ="";
          labScmbhCheckDate->Caption="";
          labScmbhUser->Caption     =g_sdUserCode;
       }
     sgScmbh->RowCount=1;      
     }
    else if (Section==2)
    {
        if (!BringToNext)
        {
           seScmbdLine->Text  =AnsiString(comServer->ItemCount+1);
           seScmbdGoods->Text       ="";
           seScmbdOCost->Text         ="";
           seScmbdNCost->Text       ="";
           memScmbdDesc->Text       ="";
           seScmbdGoodsName->Text   ="";
           scScmbdGoodsUnit->Text   ="";

        }
    }

}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::GetDataFromComObject(int Section)
{
    AnsiString s;
    if (Section==1)
    {
        seScmbhCode->Text        = GetHeadValue("ScmbhCode");
        deScmbhDate->Text        = GetHeadValue("ScmbhDate");
        scScmbhFmonth->Text      = GetHeadValue("ScmbhFmonth");
        seScmbhDesc->Text        = GetHeadValue("ScmbhDesc");
        labScmbhSysDate->Caption = GetHeadValue("ScmbhSysDate");
        chkScmbhCheck->Checked=(GetHeadValue("ScmbhCheck")==1)?true:false;
        if(chkScmbhCheck->Checked)
          SetCheckToolbarStatus(true);
        else
          SetCheckToolbarStatus(false);
        labScmbhChecker->Caption  = GetHeadValue("ScmbhChecker");
        labScmbhCheckDate->Caption= GetHeadValue("ScmbhCheckDate");
        labScmbhUser->Caption= GetHeadValue("ScmbhUser");
    }
    else
    {
        seScmbdLine->Text = GetDetailValue("ScmbdLine");

        seScmbdGoods->Text=GetDetailValue("ScmbdCode");   /////
        if(InitRsGoods(WideString(Trim(seScmbdGoods->Text)))) //输入无效编码
        {
         seScmbdGoodsName->Text=GetGoodsValue(gtInitRs,"GoodsName");
          scScmbdGoodsUnit->LocateKey(GetGoodsValue(gtInitRs,"GoodsUnitCode"));
        }
        else
        {
         seScmbdGoodsName->Text="";
         scScmbdGoodsUnit->Text="";
        }

        scScmbdGoodsUnit->Text=scScmbdGoodsUnit->ItemData[0];
        seScmbdOCost->Text =GetDetailValue("ScmbdOCost");
        seScmbdNCost->Text = GetDetailValue("ScmbdNCost");
        memScmbdDesc->Text = GetDetailValue("ScmbdDesc");
    }

}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::SendDataToComObject(int Section)
{
    if (Section==1)  // Head
    {
        SetHeadValue("ScmbhCode",seScmbhCode->Text);
        SetHeadValue("ScmbhDate",deScmbhDate->Text);
        SetHeadValue("ScmbhFmonth",scScmbhFmonth->Text);
        SetHeadValue("ScmbhDesc",seScmbhDesc->Text);
        SetHeadValue("ScmbhUser",labScmbhUser->Caption);
        SetHeadValue("ScmbhCheck",chkScmbhCheck->Checked?"1":"0");
        SetHeadValue("ScmbhChecker",labScmbhChecker->Caption);
    }
    else
    {
        SetDetailValue("ScmbdCode",seScmbhCode->Text);
        SetDetailValue("ScmbdLine",seScmbdLine->Text);
        SetDetailValue("ScmbdGoods",seScmbdGoods->Text);
        SetDetailValue("ScmbdOCost",seScmbdOCost->Text);
        SetDetailValue("ScmbdNCost",seScmbdNCost->Text);
        SetDetailValue("ScmbdDesc",memScmbdDesc->Text);
   }

}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::WaitUserInput(int Section)
{
   if (Section ==1)
   {
        seScmbhDesc->SetFocus();
   }
   else
   {
      sgScmbh->Visible=false;
      fpScmbhDetail->Visible=true;
      seScmbdLine->SetFocus();
   }
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmScmbh::GetDataToGrid()
{
    AnsiString ItemStr;
    ItemStr="\t"+GetDetailValue("ScmbdLine")+
            "\t"+GetDetailValue("ScmbdGoods")+
            "\t"+GetDetailValue("ScmbdOCost")+
            "\t"+GetDetailValue("ScmbdNCost");
    return ItemStr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::RefreshGridData(int mAction)
{
    int i;
    AnsiString ItemStr;
    switch(mAction)
    {
       case 0: // Append
         ItemStr=GetDataToGrid();
         sgScmbh->AddItem(ItemStr);
         break;
       case 1: // Modify
         sgScmbh->ChangeItem(ItemStr,sgScmbh->Row);
         break;
       case 2: // Delete
         sgScmbh->RemoveItem(sgScmbh->Row);
    }

}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::FillGridWithData()
{
    int i;
    AnsiString ItemStr;

    sgScmbh->RowCount=1;
    if(comServer->RecordCount > 0)
      for (i=0;i<comServer->ItemCount;i++)
      {
          comServer->LocateItemByIndex(i);
          RefreshGridData(0); // Append
      }
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::DisplayBill()
{
      if(comServer->RecordCount==0)
         return;
      GetDataFromComObject(1);  // Head
      FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::GetBill(AnsiString BillID)
{
    int iRow;
    iRow=comServer->Find("ScmbhCode='"+BillID+"'");
    if (iRow>0)      //FIND THIS BILL
    {
       DisplayBill();
    }
    else
       if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
       {
          AddHeadRecord();
       }
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::ChangeToBrowseState(bool Browse)
{
     sgScmbh->Visible=true;
     fpScmbhDetail->Visible=false;
     if(Browse==false)
      sgScmbh->SetFocus();
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::sgScmbhDblClick(TObject *Sender)
{
    int iRow;
    iRow=sgScmbh->Row;
    if (iRow == 0)
    {
       return;
    }
    comServer->LocateItemByKey(seScmbhCode->Text+"\t"+sgScmbh->TextMatrix[iRow][2]+"\t");
    if (!comServer->Eof)
    {
       GetDataFromComObject(2);   // Detail
       sgScmbh->Visible=false;
       fpScmbhDetail->Visible=true;
    }

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

void __fastcall TfrmScmbh::sgScmbhSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if (ARow > 0)
    {
       comServer->LocateItemByKey(seScmbhCode->Text+"\t"+sgScmbh->TextMatrix[ARow][2]+"\t");
       GetDataFromComObject(2);    // Detail
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmScmbh::btnOKClick(TObject *Sender)
{
   try
   {
   if(CurrentState==caAddDetail||CurrentState==caAddBill)
    {
       if(DetailState==caAddDetail)
         comServer->AddItem();
       SendDataToComObject(2);
       comServer->AddToObject();
       ClearControl(2,false);
       seScmbdLine->SetFocus();
    }
    else
      ChangeToBrowseState();
   }
   catch(Exception &e)
   {
     throw Exception(e.Message);
   }

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

void __fastcall TfrmScmbh::btnCancelClick(TObject *Sender)
{
     CancelChange();
}
//---------------------------------------------------------------------------

void __fastcall TfrmScmbh::FormShow(TObject *Sender)
{
    ClearControl(1,false); // Head
    ClearControl(2,false); // Detail
    ChangeToBrowseState();
    MoveToFirst();
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::seScmbdGoodsButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    TfrmWnQuery *p;
    SqlStr="004[物料编码][物料名称][计量单位][老成本]select goodscode ,goodsname,goodsunitcode,SCDCOST ";
    SqlStr+=" from sdgoods,sdscd where goodscode=SCDGOODS ";
    try{
     StartWaitForm("正在查询,请稍候...");
     p=new TfrmWnQuery(this,"物料查询",SqlStr);
    }
    __finally
    {
     EndWaitForm();
    }
    if(p->ShowModal()==mrOk)
    {
      seScmbdGoods->Text=p->ColData[1];
      seScmbdGoodsName->Text=p->ColData[2];
      scScmbdGoodsUnit->LocateKey(p->ColData[3]);
      seScmbdOCost->Text=p->ColData[4];
    }
    delete p;





}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::RefreshUpdateData(int MsgSrc,int MsgType)
{
/*
      switch(MsgSrc)
      {
        case euSdFc:
          if(ShowUpdateMessage(MsgSrc,MsgType))
            FillComboBox(Query,scScmbhFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
         break;
        case euSdUnit:
          if(ShowUpdateMessage(MsgSrc,MsgType))
             FillComboBox(Query,scScmbdGoodsUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
         break;
       default:
          break;
      }
*/
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::seScmbhCodeKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13 && CurrentState==caNormal)
    {
      comServer->LocateByKey(seScmbhCode->Text);
      DisplayBill();
    }  
}
//---------------------------------------------------------------------------

void __fastcall TfrmScmbh::seScmbdGoodsKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
   if(Key==13)
   {
      TComResultSet *TResultSet=new  TComResultSet(Handle,g_ClientHandle);
      AnsiString strSQL;
      strSQL="select GOODSCODE,GoodsName,GoodsUnitCode,SCDCOST from sdgoods,sdscd where SCDGOODS =GOODSCODE and GOODSCODE='"+seScmbdGoods->Text+"'";
      TResultSet->Close();
      try
      {
       TResultSet->Open(strSQL,"");
       seScmbdGoodsName->Text=TResultSet->FieldByName("GoodsName");
       scScmbdGoodsUnit->LocateKey(TResultSet->FieldByName("GoodsUnitCode"));
       seScmbdOCost->Text=TResultSet->FieldByName("SCDCOST");
       TResultSet->Close();
      }
      __finally
      {
       delete TResultSet;
      }
   }
}
//---------------------------------------------------------------------------
bool __fastcall TfrmScmbh::BeforeCheck()
{
  SetHeadValue("ScmbhCheck",1);
  SetHeadValue("ScmbhChecker",g_sdUserCode);
  SetHeadValue("ScmbhCheckDate",g_sdCurDate);
  return true;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmScmbh::BeforeUnCheck()
{
  SetHeadValue("ScmbhCheck",0);
  SetHeadValue("ScmbhChecker","");
  SetHeadValue("ScmbhCheckDate",NULL);
  return true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::FormClose(TObject *Sender, TCloseAction &Action)
{
  // delete g_sdRsGoods;
   TBillBaseForm::FormClose(Sender,Action);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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