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

📄 addpartmentform.~cpp

📁 该源代码是一个关于电力设备和电力行业操作管理的管理系统
💻 ~CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <ComCtrls.hpp>

#include "AddPartmentForm.h"
#include "PersonForm.h"
#include "DataMod.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TAdd_partment *Add_partment;
//---------------------------------------------------------------------------
__fastcall TAdd_partment::TAdd_partment(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TAdd_partment::Button1Click(TObject *Sender)
{

      String ParentStr;
      AnsiString ErrorMsg,Depmc;
      AnsiString mSql,TemSql,selectSql;
      ParentStr = ComboBox1->Text;
      Depmc = Edit2->Text;


      mSql="select * from tb_department where department_id='" + Edit1->Text+"'";
      Datam->department_qry->Close();
      Datam->department_qry->SQL->Clear();
      Datam->department_qry->SQL->Add(mSql);
      Datam->department_qry->Prepare();
      Datam->department_qry->Open();
      int m_count=Datam->department_qry->RecordCount;
      Datam->department_qry->Close();
      if(m_count>0)
      {
           ErrorMsg = "已存该部门ID“"+ Edit1->Text+"”,请重新输入!";
           MessageBox(Handle,ErrorMsg.c_str() ,"错误",MB_ICONERROR);
           return;
      }

      mSql = "insert into tb_department(department_id,";
      TemSql = "values('"+Edit1->Text+"','";
      mSql = mSql+"department_name,";
      TemSql = TemSql+Edit2->Text+"','";
      mSql = mSql+"parent_department_id)";
      TemSql = TemSql+ParentStr+"')";

      mSql = mSql+TemSql;
      q_exesql(mSql);

      Datam->Table2->Active = false;
      Datam->Table2->Active = true;
      DBGrid1->Refresh();

      PersonFrm->ListBox1->Items->Append(Edit2->Text);
      PersonFrm->ComboBox4->Items->Append(Edit2->Text);
      ComboBox1->Items->Add(Depmc);
      Close();
}
//---------------------------------------------------------------------------

void TAdd_partment::q_exesql(AnsiString mSql)
{
    Datam->department_qry->SQL->Clear();
    Datam->department_qry->SQL->Add(mSql);
    Datam->department_qry->ExecSQL();
    Datam->department_qry->Close();
}
//---------------------------------------------------------------------------
void __fastcall TAdd_partment::Button2Click(TObject *Sender)
{
     Close();        
}
//---------------------------------------------------------------------------
void __fastcall TAdd_partment::FormCreate(TObject *Sender)
{
      int i,Count;
      if(!Datam->Table2->Active) Datam->Table2->Open();
      Count =  PersonFrm->iCount;
      Datam->Table2->First();
      for(i=0;i<Count;i++)
      {
          ComboBox1->Items->Append(Datam->Table2->FieldByName("department_name")->AsString);
          Datam->Table2->Next();
      }

      ComboBox1->Text = "----请选择----";
}
//---------------------------------------------------------------------------

void __fastcall TAdd_partment::FormClose(TObject *Sender,
      TCloseAction &Action)
{
     if(Datam->Table2->Active) Datam->Table2->Close();        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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