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

📄 form.cpp

📁 速达开源ERP系统
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Form.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "RecBaseForm"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmForm *frmForm;
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmForm::GetFieldValue(int FieldIndex)
{
    WideString S;
    S   =   ReadFieldValue(comServer,FieldIndex);
    return(S);
}

void __fastcall TfrmForm::ClearControl(bool BringToNext)
{
    // BringToNext为真时,不清空
    if(!BringToNext)
    {
      seFormName->Text        =   "";
      seFormCaption->Text     =   "";
      seFormDesc->Text        =   "";
      seFormPosition->Text    =   "";
      seFormWindowState->Text =   "";
      seFormHelpIndex->Text   =   "";
      scFormType->Text        =   "";
      seFormID->Text          =   ""; //ID标识
    }
}

void __fastcall TfrmForm::GetDataFromComObject()
{

    seFormName->Text        =   GetFieldValue(fiFormName);
    sgForm->LocateGrid(1,seFormName->Text);
//    scFormClassID->Text     =   GetFieldValue(fiFormClassID);
    seFormCaption->Text     =   GetFieldValue(fiFormCaption);
    seFormDesc->Text        =   GetFieldValue(fiFormDesc);
    seFormPosition->Text    =   GetFieldValue(fiFormPosition);
    seFormWindowState->Text =   GetFieldValue(fiFormWindowState);
    seFormHelpIndex->Text   =   GetFieldValue(fiFormHelpIndex);
    scFormType->LocateKey(GetFieldValue(fiFormType));
    scFormType->Text        =scFormType->ItemData[0];
    seFormID->Text          =   GetFieldValue(fiFormID);
}

void __fastcall TfrmForm::SendDataToComObject()
{
    WriteFieldValue(comServer,fiFormName,         WideString(seFormName->Text));
    WriteFieldValue(comServer,fiFormClassID,      WideString(scFormClassID->Text));
    WriteFieldValue(comServer,fiFormCaption,      WideString(seFormCaption->Text));
    WriteFieldValue(comServer,fiFormDesc,         WideString(seFormDesc->Text));
    WriteFieldValue(comServer,fiFormPosition,     WideString(seFormPosition->Text));
    WriteFieldValue(comServer,fiFormWindowState,  WideString(seFormWindowState->Text));
    WriteFieldValue(comServer,fiFormHelpIndex,    WideString(seFormHelpIndex->Text));
    WriteFieldValue(comServer,fiFormType,         WideString(scFormType->ItemData[1]));
    WriteFieldValue(comServer,fiFormID,           WideString(seFormID->Text));
}

void __fastcall TfrmForm::WaitUserInput()
{
    seFormName->SetFocus();
}

AnsiString __fastcall TfrmForm::GetDataToGrid()
{
    AnsiString  s;

    s   =   "\t" + GetFieldValue(fiFormName)        +
            "\t" + GetFieldValue(fiFormClassID)     +
            "\t" + GetFieldValue(fiFormDesc);

    return(s);
}

void __fastcall TfrmForm::RefreshGridData(int mAction)
{
    AnsiString ItemStr;

    ItemStr =   GetDataToGrid();
    // 新增
    if (mAction ==  0)
    {
        sgForm->AddItem(ItemStr);
    }
    // 修改
    else if(mAction ==  1)
    {
        int i   =   sgForm->Row;
        sgForm->RemoveItem(i);
        sgForm->AddItem(ItemStr,i);
    }
    // 删除
    else if(mAction ==  2)
    {
        sgForm->RemoveItem(sgForm->Row);
    }
}

void __fastcall TfrmForm::FillGridWithData()
{

    AnsiString ItemStr;

    comServer->MoveFirst();
    sgForm->RowCount    =   1;


    while (comServer->Eof   ==  0)
    {
        ItemStr =   GetDataToGrid();
        sgForm->AddItem(ItemStr);
        comServer->MoveNext();
    }

}

void __fastcall TfrmForm::InitEditControl()
{
    ClientGroup->AddComponent(2,false,false,true, FloatPanel1,FloatPanel1->Name);
    ClientGroup->AddComponent(2,true,true,false, sgForm,sgForm->Name);
    ClientGroup->AddComponent(2,true,true,false, scFormClassID,scFormClassID->Name);
    ClientGroup->AddComponent(2,false,false,false,seFormName,seFormName->Name);
    FillComboBox(scFormClassID,"select CLASSID ,CLASSNAME from sdclass order by CLASSID","CLASSID","CLASSNAME");
    scFormType->AddItems("标准单据","1");
    scFormType->AddItems("查询","2");
    scFormType->AddItems("报表","3");
    scFormType->AddItems("对话框","4");
    scFormType->AddItems("信息","5");
    ClearControl(false);
}


__fastcall TfrmForm::TfrmForm(TComponent* Owner)
    : TRecBaseForm(Owner,euSdForm,"")
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmForm::scFormClassIDChange(TObject *Sender)
{
    AnsiString s;
    s = Trim(scFormClassID->Text);
    if(s.IsEmpty())
      return;
    if(LastFormClassID==s)
      return;
    LastFormClassID=s;
    if(scFormClassID->ItemIndex==-1)
    {
      MessageDlg("模块代码 "+scFormClassID->Text+"不存在",mtWarning,TMsgDlgButtons()<<mbOK,0);
      scFormClassID->LocateKey(LastFormClassID);
    }
    else
    {
      scFormClassID->LocateKey(scFormClassID->Text);
      seFormClassIDName->Text=scFormClassID->ItemData[1];
      s = "FormClassID = '" + s + "'";
      comServer->FilterString = WideString(s);
      comServer->Query();
      FillGridWithData();
      comServer->MoveFirst();
      GetDataFromComObject();
     }

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

void __fastcall TfrmForm::seFormNameKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13 && CurrentState==caNormal)
    {
      comServer->LocateByKey(WideString(seFormName->Text));
      GetDataFromComObject();
    }

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

void __fastcall TfrmForm::sgFormClick(TObject *Sender)
{
    if (sgForm->Row    >   0)
         comServer->LocateByKey(WideString(sgForm->TextMatrix[sgForm->Row][1]));
    if (!comServer->Eof)
         GetDataFromComObject();

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

⌨️ 快捷键说明

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