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

📄 property.cpp

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

#include <vcl.h>
#pragma hdrstop
#include "GoodsPpt.h"
#include "ProPerty.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RecBaseForm"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmProPerty *frmProPerty;
//---------------------------------------------------------------------------
__fastcall TfrmProPerty::TfrmProPerty(TComponent* Owner)
        : TRecBaseForm(Owner,euSdProperty,"")
{
    m_PropertyPpt=g_sdGoodsPpt;
    PageProPerty->Pages[0]->Caption=g_sdProperty1Name;
    PageProPerty->Pages[1]->Caption=g_sdProperty2Name;
    SetSheetState();
    PageProPerty->ActivePage=TProPerty1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmProPerty::SetSheetState()
{
 switch(m_PropertyPpt)
 {
  case 0: //无须状态管理
   tbMainBar->Enabled=false;
   break;
  case 1:
   TProPerty1->TabVisible=true;
   TProPerty2->TabVisible=false;
   break;
  case 2:
   TProPerty1->TabVisible=true;
   TProPerty2->TabVisible=true;
   break;
  default:
   break;
 }
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmProPerty::GetFieldValue(int FieldIndex)
{
    WideString S;
    S   =   ReadFieldValue(comServer,FieldIndex);
    return(S);
}
//----------------------------------------------------------------------------
void __fastcall TfrmProPerty::ClearControl(bool BringToNext)
{
    if(!BringToNext)
    {
      if( PageProPerty->ActivePage==TProPerty1)
      {
       seProperty1ID->Text      ="";         //ID字段
       seProperty1Name->Text    ="";         //状态名称
       seProperty1Desc->Text    ="";         //状态描述
      }else
      {
       seProperty2ID->Text      ="";         //ID字段
       seProperty2Name->Text    ="";         //状态名称
       seProperty2Desc->Text    ="";         //状态描述
      }
    }
}
//----------------------------------------------------------------------------
void __fastcall TfrmProPerty::InitEditControl()
{
     ClientGroup->AddComponent(2,false,false,true,FloatPanel1,FloatPanel1->Name);
     ClientGroup->AddComponent(2,true,true,false, sgProPerty1,sgProPerty1->Name);
//    if(m_PropertyPpt==2)
//    {
     ClientGroup->AddComponent(2,false,false,true,FloatPanel2,FloatPanel2->Name);
     ClientGroup->AddComponent(2,true,true,false, sgProPerty2,sgProPerty2->Name);
//    }
}
//----------------------------------------------------------------------------
void __fastcall TfrmProPerty::GetDataFromComObject()
{
      if(GetFieldValue(fiPropertyPpt)=="1")
      {
       seProperty1ID->Text=GetFieldValue(fiPropertyID);
       sgProPerty1->LocateGrid(1,seProperty1ID->Text);
       seProperty1Name->Text=GetFieldValue(fiPropertyName);
       seProperty1Desc->Text=GetFieldValue(fiPropertyDesc);
      }
//      if(GetFieldValue(fiPropertyPpt)=="2"&& m_PropertyPpt==2)
      if(GetFieldValue(fiPropertyPpt)=="2")
      {
       seProperty2ID->Text=GetFieldValue(fiPropertyID);
       sgProPerty2->LocateGrid(1,seProperty2ID->Text);
       seProperty2Name->Text=GetFieldValue(fiPropertyName);
       seProperty2Desc->Text=GetFieldValue(fiPropertyDesc);
      }
}
//----------------------------------------------------------------------------
void __fastcall TfrmProPerty::SendDataToComObject()
{
    if( PageProPerty->ActivePage==TProPerty1)
    {
     WriteFieldValue(comServer,fiPropertyPpt,WideString("1"));
     WriteFieldValue(comServer,fiPropertyID,WideString(seProperty1ID->Text));
     WriteFieldValue(comServer,fiPropertyName,WideString(seProperty1Name->Text));
     WriteFieldValue(comServer,fiPropertyDesc,WideString(seProperty1Desc->Text));
    }
    else
    {
     WriteFieldValue(comServer,fiPropertyPpt,WideString("2"));
     WriteFieldValue(comServer,fiPropertyID,WideString(seProperty2ID->Text));
     WriteFieldValue(comServer,fiPropertyName,WideString(seProperty2Name->Text));
     WriteFieldValue(comServer,fiPropertyDesc,WideString(seProperty2Desc->Text));
     }
}
//----------------------------------------------------------------------------
void __fastcall TfrmProPerty::WaitUserInput()
{
   if( PageProPerty->ActivePage==TProPerty1)
    seProperty1ID->SetFocus();
   if( PageProPerty->ActivePage==TProPerty2)
    seProperty2ID->SetFocus();

}
//----------------------------------------------------------------------------
AnsiString __fastcall TfrmProPerty::GetDataToGrid()
{
    AnsiString  s;
    s   = "\t"   + GetFieldValue(fiPropertyID)+
          "\t"   + GetFieldValue(fiPropertyName)+
          "\t"   + GetFieldValue(fiPropertyDesc);
    return (s);
}
//----------------------------------------------------------------------------
void __fastcall TfrmProPerty::RefreshGridData(int mAction)
{
    AnsiString ItemStr;
    ItemStr =   GetDataToGrid();
   if( PageProPerty->ActivePage==TProPerty1)
   {
     if (mAction ==  0)     //Add
     {
       sgProPerty1->AddItem(ItemStr);
     }
     else if(mAction ==  1) //Chg
     {
       int i   =   sgProPerty1->Row;
       sgProPerty1->RemoveItem(i);
       sgProPerty1->AddItem(ItemStr,i);
     }
     else if(mAction ==  2) //Del
     {
       sgProPerty1->RemoveItem(sgProPerty1->Row);
     }
   }
   else
   {
     if (mAction ==  0)     //Add
     {
       sgProPerty2->AddItem(ItemStr);
     }
     else if(mAction ==  1) //Chg
     {
       int i   =   sgProPerty2->Row;
       sgProPerty2->RemoveItem(i);
       sgProPerty2->AddItem(ItemStr,i);
     }
     else if(mAction ==  2) //Del
     {
       sgProPerty2->RemoveItem(sgProPerty2->Row);
     }
   }
}
//----------------------------------------------------------------------------
void __fastcall TfrmProPerty::FillGridWithData()
{
    AnsiString ItemStr, m_Ppt;
    comServer->MoveFirst();
    sgProPerty1->RowCount    =   1;
    while (comServer->Eof   ==  0)
    {
       m_Ppt=   GetFieldValue(fiPropertyPpt);
      ItemStr = GetDataToGrid();
      if(m_Ppt=="1")
        sgProPerty1->AddItem(ItemStr);
//      if(m_Ppt=="2"&& m_PropertyPpt==2)
      if(m_Ppt=="2")
        sgProPerty2->AddItem(ItemStr);
      comServer->MoveNext();
    }
}
void __fastcall TfrmProPerty::FormShow(TObject *Sender)
{
      FillGridWithData();
      comServer->MoveFirst();
      GetDataFromComObject();
/*
      if( m_PropertyPpt==2)
      {
         while (comServer->Eof   ==  0)
        {
          if(GetFieldValue(fiPropertyPpt)=="2")
          {
           GetDataFromComObject();
           break;
          }
          comServer->MoveNext();
        }
      }
*/
     PageProPerty->ActivePage=TProPerty1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmProPerty::sgProPerty2Click(TObject *Sender)
{
        if (sgProPerty2->Row  > 0)
             comServer->LocateByKey(WideString("2"+sgProPerty2->TextMatrix[sgProPerty2->Row][1]));
        if (!comServer->Eof)
             GetDataFromComObject();
}
//---------------------------------------------------------------------------
void __fastcall TfrmProPerty::sgProPerty1Click(TObject *Sender)
{
        if (sgProPerty1->Row  > 0)
             comServer->LocateByKey(WideString("1"+sgProPerty1->TextMatrix[sgProPerty1->Row][1]));
        if (!comServer->Eof)
             GetDataFromComObject();

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


void __fastcall TfrmProPerty::muFirstClick(TObject *Sender)
{
 if(PageProPerty->ActivePage == TProPerty1)
 {
  if(sgProPerty1->RowCount > 1)
  {
   sgProPerty1->Row=1;
   sgProPerty1Click(NULL);
  }
 }
 if(PageProPerty->ActivePage == TProPerty2)
 {
  if(sgProPerty2->RowCount > 1)
  {
   sgProPerty2->Row=1;
   sgProPerty2Click(NULL);
  }
 }
}
//---------------------------------------------------------------------------

void __fastcall TfrmProPerty::muPreviousClick(TObject *Sender)
{
 if(PageProPerty->ActivePage == TProPerty1)
 {
  if(sgProPerty1->RowCount > 1 && sgProPerty1->Row > 1)
  {
   sgProPerty1->Row=sgProPerty1->Row-1;
   sgProPerty1Click(NULL);
  }
 }
 if(PageProPerty->ActivePage == TProPerty2)
 {
  if(sgProPerty2->RowCount > 1 && sgProPerty2->Row > 1)
  {
   sgProPerty2->Row=sgProPerty2->Row-1;
   sgProPerty2Click(NULL);
  }
 }
}
//---------------------------------------------------------------------------

void __fastcall TfrmProPerty::muNextClick(TObject *Sender)
{
 if(PageProPerty->ActivePage == TProPerty1)
 {
  if(sgProPerty1->RowCount > 1 && sgProPerty1->Row < sgProPerty1->RowCount-1)
  {
   sgProPerty1->Row=sgProPerty1->Row+1;
   sgProPerty1Click(NULL);
  }
 }
 if(PageProPerty->ActivePage == TProPerty2)
 {
  if(sgProPerty2->RowCount > 1 && sgProPerty2->Row < sgProPerty2->RowCount-1)
  {
   sgProPerty2->Row=sgProPerty2->Row+1;
   sgProPerty2Click(NULL);
  }
 }
}
//---------------------------------------------------------------------------

void __fastcall TfrmProPerty::muLastClick(TObject *Sender)
{
 if(PageProPerty->ActivePage == TProPerty1)
 {
  if(sgProPerty1->RowCount > 1)
  {
   sgProPerty1->Row=sgProPerty1->RowCount-1;
   sgProPerty1Click(NULL);
  }
 }
 if(PageProPerty->ActivePage == TProPerty2)
 {
  if(sgProPerty2->RowCount > 1)
  {
   sgProPerty2->Row=sgProPerty2->RowCount-1;
   sgProPerty2Click(NULL);
  }
 }
}
//---------------------------------------------------------------------------






⌨️ 快捷键说明

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