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

📄 glb.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "Glb.h"
#include "GlbBa.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RecBaseForm"
#pragma link "fpanel"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmGlb *frmGlb;
#define PARAMETCODE "10702"
//---------------------------------------------------------------------------
__fastcall TfrmGlb::TfrmGlb(TComponent* Owner)
        : TRecBaseForm(Owner,euSdGlb,"")
{
    pKmSet=NewResultSet();
    pExE=NewResultSet();
    m_Balance=false;
    m_Qy="";
    m_Wc="";
    m_AllRowt=0;

}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::InitEditControl()
{
    FillComboBox(scKm,"select Glkmcode,glkmname from sdglkm order By glkmcode","glkmName","glkmCode");
    FillComboBox(scGlbCurrency,"select  CurrencyCode,Currencyname from sdCurrency order By CurrencyCode","CurrencyName","CurrencyCode");
    FillComboBox(scGlbUnit,"select unitcode,unitname from sdunit order By unitcode","unitName","unitCode");
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGlb::GetFieldValue(int FieldIndex)
{
    WideString S;
    S = ReadFieldValue(comServer,FieldIndex);
    return(S);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::SetFieldValue(int Index,AnsiString Value)
{
    WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::ClearControl(bool BringToNext)
{
  //
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::GetDataFromComObject()
{
//
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::SendDataToComObject()
{
  //
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::WaitUserInput()
{
 //
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGlb::GetDataToGrid()
{
   return("");
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::RefreshGridData(int mAction)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::FillGridWithData()
{
    AnsiString  strSQL,TempAsRes,ItemStr;
    strSQL="select GLBGLKM,GlbDir,GlbCurrency,GlbUnit,GlbBopQty,GlbBopAmt,GlbBopWbAmt,GlbMx,GlbLevel,GlbUpperCode from sdglb order by GLBGLKM";
    pKmSet->Close();
    pKmSet->Open(strSQL,"GLBGLKM");
    pKmSet->MoveFirst();
    sgGlb->RowCount    =   1;
    m_AllRowt=0;
    for(int i=1;i<=pKmSet->RecordCount;i++)
    {
      if(pKmSet->FieldByName("GlbMx")=="1")
      {
       scKm->LocateKey(pKmSet->FieldByName("GLBGLKM"));
       scGlbCurrency->LocateKey(pKmSet->FieldByName("GlbCurrency"));
       scGlbUnit->LocateKey(pKmSet->FieldByName("GlbUnit"));
       ItemStr="\t"+pKmSet->FieldByName("GLBGLKM")+
              "\t"+scKm->ItemData[0]+
              "\t"+(pKmSet->FieldByName("GlbDir")=="1"? "借方":"贷方")+
              "\t"+scGlbCurrency->ItemData[0]+
              "\t"+scGlbUnit->ItemData[0]+
              "\t"+pKmSet->FieldByName("GlbBopQty")+
              "\t"+pKmSet->FieldByName("GlbBopAmt")+
              "\t"+pKmSet->FieldByName("GlbBopWbAmt");
       sgGlb->AddItem(ItemStr);
       m_AllRowt++;
      }
      pKmSet->MoveNext();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::FillGridWithDataFormGlKm()
{
    AnsiString  strSQL,TempAsRes,ItemStr;
    strSQL="select GLKMCODE,GLKMNAME,GLKMDIR,GLKMCURRENCY,GLKMUNIT,GLKMLEVEL,GlkmMx,GlkmLevel,GlkmUpperCode from sdglkm order by glkmcode";
    pKmSet->Close();
    pKmSet->Open(strSQL,"GLKMCODE");
    pKmSet->MoveFirst();
     sgGlb->RowCount    =   1;
    m_AllRowt=0;
    for(int i=1;i<=pKmSet->RecordCount;i++)
    {
      if(pKmSet->FieldByName("GlkmMx")=="1")
      {
       scGlbCurrency->LocateKey(pKmSet->FieldByName("GLKMCURRENCY"));
       scGlbUnit->LocateKey(pKmSet->FieldByName("GLKMUNIT"));
       ItemStr="\t"+pKmSet->FieldByName("GLKMCODE")+
               "\t"+pKmSet->FieldByName("GLKMNAME")+
               "\t"+(pKmSet->FieldByName("GLKMDIR")=="1"? "借方":"贷方")+
               "\t"+scGlbCurrency->ItemData[0]+
               "\t"+pKmSet->FieldByName("GLKMUNIT")+
               "\t"+"0"+
               "\t"+"0"+
               "\t"+"0";
       sgGlb->AddItem(ItemStr);
       m_AllRowt++;
      }
      pKmSet->MoveNext();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::FormShow(TObject *Sender)
{
    TComResultSet *pResultSet=NewResultSet();
    AnsiString  strSQL;
    strSQL="select PARAMETERVALUE from sdparameter where parametercode='10704'";
    try
    {
     pResultSet->Close();
     pResultSet->Open(strSQL,"");
     m_Wc=pResultSet->FieldByName("PARAMETERVALUE");
     if(m_Wc=="Y")
     {
      FillGridWithData();
     }
     else
     {
      FillGridWithDataFormGlKm();
     }
     strSQL="select PARAMETERVALUE from sdparameter where parametercode='10702'";
     pResultSet->Close();
     pResultSet->Open(strSQL,"");
     m_Qy=pResultSet->FieldByName("PARAMETERVALUE");
     if(m_Qy=="Y")
     {
       tbAddHead->Enabled=false;
       tbGenrate->Enabled=false;
     }
     else
     {
       tbAddHead->Enabled=true;
       tbGenrate->Enabled=true;
     }
    }
    __finally
    {
      delete pResultSet;
    }  
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::tbCheckClick(TObject *Sender)
{                         //试算
    double AllZc=0,AllFz=0,AllQy=0;
    AnsiString m_GlkmCd,TempValue,FlagW;
     for(int i=1;i<=pKmSet->RecordCount;i++)
    {
      m_GlkmCd=sgGlb->Cells[1][i];
      m_GlkmCd=m_GlkmCd.SubString(1,1);
      pKmSet->LocateByKey(sgGlb->Cells[1][i]);
      if(m_Wc=="Y")
       FlagW=pKmSet->FieldByName("GlbMx");
      else
       FlagW=pKmSet->FieldByName("GlkmMx");

      if(m_GlkmCd=="1"&&FlagW=="1")
       {
           TempValue=sgGlb->Cells[7][i];
           AllZc=AllZc+TempValue.ToDouble();
       }
      if(m_GlkmCd=="2"&&FlagW=="1")
       {
           TempValue=sgGlb->Cells[7][i];
           AllFz=AllFz+TempValue.ToDouble();
       }
      if(m_GlkmCd=="3"&&FlagW=="1")
      {
         TempValue=sgGlb->Cells[7][i];
         AllQy=AllQy+TempValue.ToDouble();
      }
     }
    if(AllZc==AllFz+AllQy)
       m_Balance=true;
    TfrmGlbBa  *tempGlbBa= new  TfrmGlbBa(this,AllZc,AllFz,AllQy);
    tempGlbBa->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TfrmGlb::tbGenrateClick(TObject *Sender)
{
     if(m_Balance)
      {
       pExE->Execute("update sdparameter set PARAMETERVALUE='Y' where PARAMETERCODE='10702'");
       pExE->Execute("update sdglb set GlbFmonth='"+g_sdFMonth+"'");
      }
     else
     {
       ::MessageBox(Handle,"借贷不平衡!不能启用。","错误",MB_OK|MB_ICONSTOP);
        return;
     }
     tbAddHead->Enabled=false;
     tbGenrate->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::muSaveClick(TObject *Sender)
{
                   //完成初始化
    StartWaitForm("正在进行初始化...,请稍候!");
    pExE->Execute("delete sdglb");
    comServer->Query();
    for(int i=1;i<=m_AllRowt;i++)
    {
      comServer->AddNew();
      WriteFieldValue(comServer,fiGlbGlkm,sgGlb->Cells[1][i]);
      WriteFieldValue(comServer,fiGlbFmonth,g_sdFMonth);
      WriteFieldValue(comServer,fiGlbDir,sgGlb->Cells[3][i]=="借方"? "1":"2");
      WriteFieldValue(comServer,fiGlbCurrency,sgGlb->Cells[4][i]);
      WriteFieldValue(comServer,fiGlbUnit,sgGlb->Cells[5][i]);
      WriteFieldValue(comServer,fiGlbBopQty,sgGlb->Cells[6][i]);
      WriteFieldValue(comServer,fiGlbBopAmt,sgGlb->Cells[7][i]);
      WriteFieldValue(comServer,fiGlbBopWbAmt,sgGlb->Cells[8][i]);
      pKmSet->LocateByKey(sgGlb->Cells[1][i]);
      if(m_Wc=="Y")
      {
       WriteFieldValue(comServer,fiGlbMx,pKmSet->FieldByName("GlbMx"));
       WriteFieldValue(comServer,fiGlbLevel,pKmSet->FieldByName("GlbLevel"));
       WriteFieldValue(comServer,fiGlbUpperCode,pKmSet->FieldByName("GlbUpperCode"));
      }
      else
      {
       WriteFieldValue(comServer,fiGlbMx,pKmSet->FieldByName("GlkmMx"));
       WriteFieldValue(comServer,fiGlbLevel,pKmSet->FieldByName("GlkmLevel"));
       WriteFieldValue(comServer,fiGlbUpperCode,pKmSet->FieldByName("GlkmUpperCode"));
      }
      SaveComObject();
     }
    for(int i=1;i<=pKmSet->RecordCount;i++)
    {
      pKmSet->LocateByIndex(i-1);
      if(m_Wc=="Y"&&pKmSet->FieldByName("GlbMx")!="1")
      {
       comServer->AddNew();
       WriteFieldValue(comServer,fiGlbGlkm,pKmSet->FieldByName("GlbGlkm"));
       WriteFieldValue(comServer,fiGlbFmonth,g_sdFMonth);
       WriteFieldValue(comServer,fiGlbDir,pKmSet->FieldByName("GlbDir"));
       WriteFieldValue(comServer,fiGlbCurrency,pKmSet->FieldByName("GlbCurrency"));
       WriteFieldValue(comServer,fiGlbUnit,pKmSet->FieldByName("GlbUnit"));
       WriteFieldValue(comServer,fiGlbMx,pKmSet->FieldByName("GlbMx"));
       WriteFieldValue(comServer,fiGlbLevel,pKmSet->FieldByName("GlbLevel"));
       WriteFieldValue(comServer,fiGlbUpperCode,pKmSet->FieldByName("GlbUpperCode"));
       SaveComObject();
      }
      if(m_Wc!="Y"&&pKmSet->FieldByName("GlkmMx")!="1")
      {
       comServer->AddNew();
       WriteFieldValue(comServer,fiGlbGlkm,pKmSet->FieldByName("GLKMCODE"));
       WriteFieldValue(comServer,fiGlbFmonth,g_sdFMonth);
       WriteFieldValue(comServer,fiGlbDir,pKmSet->FieldByName("GLKMDIR"));
       WriteFieldValue(comServer,fiGlbCurrency,pKmSet->FieldByName("GLKMCURRENCY"));
       WriteFieldValue(comServer,fiGlbUnit,pKmSet->FieldByName("GLKMUNIT"));
       WriteFieldValue(comServer,fiGlbMx,pKmSet->FieldByName("GlkmMx"));
       WriteFieldValue(comServer,fiGlbLevel,pKmSet->FieldByName("GlkmLevel"));
       WriteFieldValue(comServer,fiGlbUpperCode,pKmSet->FieldByName("GlkmUpperCode"));
       SaveComObject();
      }
     }
     pExE->Execute("update sdparameter set PARAMETERVALUE='Y' where PARAMETERCODE='10704'");
     pExE->Execute("EXEC sdGlb_InitInv");
     EndWaitForm();
     SetControlState(caSave);
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::muAddDetailClick(TObject *Sender)
{
      SetControlState(caAddDetail);
      sgGlb->ReadOnly=false;
      sgGlb->Columns->Items[6]->EditType=sdEdit;
      sgGlb->Columns->Items[7]->EditType=sdEdit;
      sgGlb->Columns->Items[8]->EditType=sdEdit;
      sgGlb->Columns->Items[6]->AddListItem("LocCode",1);
      sgGlb->Columns->Items[6]->AddListItem("Locdfdde",2);



}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::muCancelClick(TObject *Sender)
{
      SetControlState(caSave);
      if(m_Wc=="Y")
      {
       FillGridWithData();
      }
      else
      {
       FillGridWithDataFormGlKm();
      }
      sgGlb->ReadOnly=true;
      sgGlb->Columns->Items[6]->EditType=sdNone;
      sgGlb->Columns->Items[7]->EditType=sdNone;
      sgGlb->Columns->Items[8]->EditType=sdNone;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::muFirstClick(TObject *Sender)
{
   if( sgGlb->Row>1)
    sgGlb->Row=1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::muPreviousClick(TObject *Sender)
{
   if( sgGlb->Row < sgGlb->RowCount-1)
    sgGlb->Row--;

}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::muNextClick(TObject *Sender)
{
   if( sgGlb->Row < sgGlb->RowCount-1)
    sgGlb->Row++;

}
//---------------------------------------------------------------------------
void __fastcall TfrmGlb::muLastClick(TObject *Sender)
{
   if(sgGlb->RowCount > 1)
    sgGlb->Row=sgGlb->RowCount-1;

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

void __fastcall TfrmGlb::FormClose(TObject *Sender, TCloseAction &Action)
{
   TRecBaseForm::FormClose(Sender,Action);
   delete pKmSet;
   delete pExE;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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