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

📄 gmth_r.cpp

📁 科思ERP部分源码及控件
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Gmth_R.h"
#include "Gmth_Rd.h"
#include "Dml.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "GenBaseForm"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmGmth_R *frmGmth_R;
//---------------------------------------------------------------------------
__fastcall TfrmGmth_R::TfrmGmth_R(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
    : TGenBaseForm(Owner,chWnd,MidCode,WhereStr)
{
    AutoCtl=seGmthCode;
    //SetAutoCodeString(seGmthCode,"ACM-009");
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::InitEditControl()
{
    ClientGroup->AddComponent(1,false,false,true,PnlGmth,PnlGmth->Name);
    ClientGroup->AddComponent(1,true,true,true,scGmthType,scGmthType->Name);
    ClientGroup->AddComponent(1,false,true,false,seGmthCode,seGmthCode->Name);
    ClientGroup->AddComponent(1,false,true,true,seGmthWo,seGmthWo->Name);
    ClientGroup->AddComponent(1,true,true,true,scGmthFmonth,scGmthFmonth->Name);
    ClientGroup->AddComponent(2,true,true,true,PnlGmtd,PnlGmtd->Name);
    //
    scGmthType->ClearAll();
    scGmthType->AddItems("R-工单定额领料","1");
    scGmthType->AddItems("W-工单自由领料","2");
    scGmthType->AddItems("A-工单工序补料","3");
    scGmthType->AddItems("C-共用材料领料","4");
    scGmthType->AddItems("D-部门直接领料","5");
    //
    FillComboBox(Handle,scGmthFmonth,"SELECT FcMonth FROM sdFc order by FcMonth","FcMonth");
    FillComboBox(Handle,scGmthPosType,"SELECT PosTypeCode,PosTypeName FROM sdPosType where PosTypeFlg=3 order by PosTypeCode","PosTypeName","PosTypeCode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::RefreshUpdateData(int MsgSrc,int MsgType)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::ClearControl(int Section,bool BringToNext)
{
    if(Section == 1){
       if(!BringToNext){
          seGmthCode->Text="";
          deGmthDate->Text=g_sdCurDate;
          scGmthFmonth->LocateKey(g_sdMMonth);
          scGmthPosType->ItemIndex=-1;
          scGmthType->ItemIndex=0;
          seGmthWo->Text="";
          labUser->Caption=g_sdUserCode;
          chkGmthCheck->Checked=false;
          labChecker->Caption="";
          labCheckDate->Caption="";
          memGmthDesc->Text="";
       }
       sgGmth->RowCount=1;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::GetDataFromComObject(int Section)
{
    if(Section==1)
    {
      seGmthCode->Text=GetHeadValue("GmthCode");
      deGmthDate->Text=GetHeadValue("GmthDate");
      scGmthFmonth->LocateKey(GetHeadValue("GmthFmonth"));
      scGmthPosType->LocateKey(GetHeadValue("GmthPosType"));
      scGmthType->LocateKey(GetHeadValue("GmthType"));
      seGmthWo->Text=GetHeadValue("GmthWoCode");
      memGmthDesc->Text=GetHeadValue("GmthDesc");
      labUser->Caption=GetHeadValue("GmthUser");
      chkGmthCheck->Checked=GetHeadValue("GmthCheck")=="1";
      if(chkGmthCheck->Checked)
         SetCheckToolbarStatus(true);
      else
         SetCheckToolbarStatus(false);
      labChecker->Caption=GetHeadValue("GmthChecker");
      labCheckDate->Caption=GetHeadValue("GmthCheckDate");

    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::SendDataToComObject(int Section)
{
    if(Section==1){
       SetHeadValue("GmthCode",seGmthCode->Text);
       SetHeadValue("GmthDate",deGmthDate->Text);
       SetHeadValue("GmthFmonth",scGmthFmonth->Text);
       SetHeadValue("GmthPosType",scGmthPosType->ItemData[1]);
       SetHeadValue("GmthWoCode",seGmthWo->Text);
       SetHeadValue("GmthUser",labUser->Caption);
       SetHeadValue("GmthDesc",memGmthDesc->Text);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::WaitUserInput(int Section)
{
    if (Section ==1){
      if(CurrentState==caAddHead)
         seGmthCode->SetFocus();
      else
         deGmthDate->SetFocus();
    }
    else
      sgGmth->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGmth_R::GetDataToGrid()
{
    AnsiString ItemStr;
//    ItemStr=AnsiString("√");
    ItemStr= GetDetailValue("GmtdLine")+
             "\t"+GetDetailValue("GmtdGoods")+
             "\t"+GetDetailValue("GmtdGoodsName")+
             "\t"+GetDetailValue("GmtdGoodsSpec")+
             "\t"+GetDetailValue("GmtdUnit")+
             "\t"+GetDetailValue("GmtdPQty")+
             "\t"+GetDetailValue("GmtdCQty")+
             "\t"+GetDetailValue("GmtdQty")+
             "\t"+GetDetailValue("GmtdSLoc");
    return ItemStr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::RefreshGridData(int mAction)
{
    int i;
    AnsiString ItemStr=GetDataToGrid();
    switch(mAction)
    {
       case 0: //Add
         sgGmth->AddItem(ItemStr);
         sgGmth->Row=sgGmth->RowCount-1;
         break;
       case 1: //Edit
         sgGmth->ChangeItem(ItemStr,sgGmth->Row);
         break;
       case 2: //Delete
         sgGmth->RemoveItem(sgGmth->Row);
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::FillGridWithData()
{
    int i;
    AnsiString ItemStr;
    sgGmth->RowCount=1;
    if(comServer->RecordCount>0){
      for(i=0;i<comServer->ItemCount;i++){
         comServer->LocateItemByIndex(i);
         RefreshGridData(0);
      }
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::DisplayBill()
{
    if(comServer->RecordCount>0){
       GetDataFromComObject(1);
       FillGridWithData();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::GetBill(AnsiString BillID)
{
    bool iRow;
    iRow=comServer->Find("GmthCode='"+BillID+"'");
    if(iRow)      //FIND THIS BILL
       DisplayBill();
    else
    {
       if(ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
          AddHeadRecord();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::FormShow(TObject *Sender)
{
    //单据不能删除行
    tbAddDetail->Visible=false;
    tbEditDetail->Visible=false;
    tbDeleteDetail->Visible=false;
    tbEditAll->Visible=true;
    sgGmth->ReadOnly=true;
    ClearControl(1,false);
    MoveToFirst();
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::ChangeToBrowseState(bool t_browse)
{
    sgGmth->ReadOnly=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::GenrateBill()
{
    int TempCount;
    TempCount = comServer->ItemCount;
    SetControlState(caAddBill);
    StartWaitForm("正在启动生成界面");
    TfrmGmth_Rd *p=new TfrmGmth_Rd(this,g_ClientHandle, "","", comServer);
    //try
    //{
      EndWaitForm();
      p->ShowModal();
    //}
    //__finally
    //{
    //   delete p;
    //}
   if (TempCount < comServer->ItemCount)
      TGenBaseForm::tbSaveClick(NULL);
//        TGenBaseForm::SaveRecord();
    else
      CancelChange();
     tbGenDetail->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::EditBill()
{
    if(sgGmth->RowCount>1)
    {
       sgGmth->SetFocus();
       sgGmth->ReadOnly=false;
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::SendAllDetailValue()
{
    if(sgGmth->RowCount>1)
    {
       for(int i=1;i<sgGmth->RowCount;i++)
       {
         if(sgGmth->Cells[0][i]=="√")
         {
           AnsiString Keystr;
           Keystr=seGmthCode->Text+"\t"+sgGmth->Cells[1][i];
           comServer->LocateItemByKey(Keystr);
           comServer->EditItem();
           SetDetailValue("GmtdQty",sgGmth->Cells[6][i]);
           SetDetailValue("GmtdSLoc",sgGmth->Cells[7][i]);
           try
           {
              comServer->AddToObject();
           }
           catch(Exception &e)
           {
              throw Exception(e.Message);
           }
         }
       }
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::sgGmthClick(TObject *Sender)
{
    if (sgGmth->Row > 0)
    {
       comServer->LocateItemByKey(GetHeadValue("GmthCode")+"\t"+sgGmth->TextMatrix[sgGmth->Row][0])+"\t";
       GetDataFromComObject(2);    // Detail
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::sgGmthDblClick(TObject *Sender)
{
    int ARow=sgGmth->Row;
    int ACol=sgGmth->Col;

    if(sgGmth->Cells[0][ARow]!="√" || comServer->ItemCount<=0)
       return;
    if(ARow>0 && ACol==2)
    {
       TfrmDml *Dmlfrm;
       try{
          StartWaitForm("正在启动<工序材料分摊>界面...");
          comServer->LocateItemByKey(seGmthCode->Text+"\t"+sgGmth->Cells[1][ARow]);
          AnsiString t_GmthCode=GetDetailValue("GmtdCode");
          AnsiString t_GmthCheck=GetHeadValue("GmthCheck");
          AnsiString t_GmtdLine=GetDetailValue("GmtdLine");
          AnsiString t_GmtdWo=GetDetailValue("GmtdWoCode");
          AnsiString t_GmtdGoods=GetDetailValue("GmtdGoods");
          AnsiString t_GmtdQty=GetDetailValue("GmtdQty");
          AnsiString FWhereString,FParamString;
          FWhereString="DmlGmtCode='"+t_GmthCode+"' and DmlGmtdLine='"+t_GmtdLine+"'";
          FParamString=t_GmthCode+"\t"+t_GmthCheck+"\t"+t_GmtdLine+"\t"+t_GmtdWo+"\t"+t_GmtdGoods+"\t"+t_GmtdQty;
          Dmlfrm=new TfrmDml(this,g_ClientHandle,"1061101",FWhereString,FParamString);
          EndWaitForm();
          Dmlfrm->ShowModal();
       }
       __finally{
          delete Dmlfrm;
       }
    }

    if(ARow>0 && ACol==7 && CurrentState!=caNormal)
    {
      AnsiString SqlStr;
      SqlStr="007[当前月份][货位编码][货位名称][物料编码][物料名称][计量单位][当前数量]";
      SqlStr+="select MaccFmonth,MaccLoc,LocName,MaccGoods,MaccGoodsName=GoodsName,MaccUnit=GoodsUnitCode,";
      SqlStr+=" MaccAoyQty from sdMacc,sdGoods,sdLg,sdLoc where LocCode=lgLocCode and LocCode=MaccLoc";
      SqlStr+=" and LgGoodsCode=MaccGoods and GoodsCode=MaccGoods and MaccFmonth='"+g_sdMMonth+"'";
      SqlStr+=" and MaccGoods='"+sgGmth->Cells[2][ARow]+"' and LocType=1 order by LocCode";
      TfrmWnQuery *p;
      try
      {
         StartWaitForm("正在查询,请稍候...");
         p=new TfrmWnQuery(this,"发料货位查询",SqlStr);
      }
      __finally
      {
         EndWaitForm();
      }
      if(p->ShowModal()==mrOk)
      {
         sgGmth->Cells[7][ARow]=p->ColData[2];
      }
      delete p;
    }
}
//---------------------------------------------------------------------------
/*void __fastcall TfrmGmth_R::sgGmthSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    if(ARow > 0)
    {
       FCurRow=ARow;
       comServer->LocateItemByKey(seGmthCode->Text+"\t"+sgGmth->TextMatrix[ARow][1]);
    }
}*/
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::seGmthCodeKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    AnsiString tempS=seGmthCode->Text;
    if(Key==13 && CurrentState==caNormal && !tempS.IsEmpty())
    {
       comServer->LocateByKey(WideString(tempS));
       DisplayBill();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_R::seGmthWoButtonClick(TObject *Sender)
{
    AnsiString SqlStr;
    SqlStr="006[加工单号][加工件码][要求数量][要求日期][订单单号][订单行号]SELECT WoCode,WoGoods,WoQty,WoRDate,";
    SqlStr=SqlStr+"WoSoCode,WoSodLine from sdWo where WoCheck=1 and WoClose=0 and exists(select * from sdWsgm where WsgmWo=WoCode and WsgmPQty>WsgmGQty) ORDER BY WoCode";
    TfrmWnQuery *p;
    try
    {
       StartWaitForm("正在查询,请稍候...");
       p=new TfrmWnQuery(this,"加工订单查询",SqlStr);
    }
    __finally
    {
       EndWaitForm();
    }
    if(p->ShowModal()==mrOk)
    {
       seGmthWo->Text=p->ColData[1];
    }
    delete p;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmGmth_R::BeforeCheck()
{
  SetHeadValue("GmthCheck",1);
  SetHeadValue("GmthChecker",g_sdUserCode);
  SetHeadValue("GmthCheckDate",g_sdCurDate);
  return true;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmGmth_R::BeforeUnCheck()
{
  SetHeadValue("GmthCheck",0);
  SetHeadValue("GmthChecker","");
  SetHeadValue("GmthCheckDate",NULL);
  return true;
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

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