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

📄 unitmainform.cpp

📁 使用C++Builder开发的常住人口管理系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "UnitMainForm.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;


//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
        : TForm(Owner)
{
     
     Parent=false;
     Index=0;
}
//---------------------------------------------------------------------------





void __fastcall TfrmMain::TreeViewChanging(TObject *Sender,
      TTreeNode *Node, bool &AllowChange)
{
        //   Edit1->Text=  TreeView->Items->Count;
          // Edit2->Text =TreeView->Items->Item[27]->Text;
     //     Edit2->Text =  Node->AbsoluteIndex;

     if(Parent)           //如果先前已有显示的面板,则隐藏
     {
         switch (Index)
         {
           case 0:
                   panAbout->Visible=false;
                   break;
           case 1:
                   panChangZhuRYJL->Visible=false ;
                   break;
           case 2:
                   panQianChuRYJL->Visible=false ;
                   break;
           case 3:
                   panSiWangRYJL->Visible=false;
                   break;
           case 4:
                   panZhanZhuZheng->Visible=false;
                   break;
           case 5:
                   panAbout->Visible=false;
                   break;
           case 6:
                   panRYXinXiGL->Visible=false;
                   break;
           case 7:
                   PanRenKouZuHeChaXun->Visible=false;
                   break;
           case 8:
                   panAbout->Visible=false;
                   break;
           case 9:
                   panNianLingTJ->Visible=false;
                   break;
           case 10:
                   panWenHuaChengCiTJ->Visible=false;
                   break;
           case 11:
                   panShouRuShuiPingTJ->Visible=false;
                   break;
           case 12:
                   panRYXingZiTJ->Visible=false;
                   break;
           case 13:
                   panAbout->Visible=false;
                   break;
           case 14:
                   panGuanLi->Visible=false;
                   break;
           case 15:
                   panZhuFangJiTuiFang->Visible=false;
                   break;
           case 16:
                   panChangeRoom->Visible=false;
                   break;
           case 17:
                   panShouFangXinXi->Visible=false;
                   break;
           case 18:
                   panZhuFangXinXi->Visible=false;
                   break;
           case 19:
                   panAbout->Visible=false;
                   break;
           case 20:
                   panGongGaoHaiBao->Visible=false;
                   break;
           case 21:
                   panGongQiuXinXi->Visible=false;
                   break;
           case 22:
                   panShiChangHangQing->Visible=false;
                   break;
           case 23:
                   panDianShiJieMu->Visible=false;
                   break;
           case 24:
                   panRenCaiXuQiu->Visible=false;
                   break;
           case 25:
                   panBBS->Visible=false;
                   break;
           case 26:
                   panAbout->Visible=false;
                   break;
           case 27:
                   PanXiuGaiGuanLiYuanXinXi->Visible=false;
                   break;
           case 28:
                   panUserHelp->Visible=false;
                   break;
           case 29:
                   panAbout->Visible=false;
                   break;
         }
     }


     switch (Node->AbsoluteIndex)            //实现面板的显示
     {
           case 0:
                   panAbout->Visible=true;
                   break;
           case 1:
                   panChangZhuRYJL->Visible=true ;
                   break;
           case 2:
                   panQianChuRYJL->Visible=true ;
                   break;
           case 3:
                   panSiWangRYJL->Visible=true;
                   break;
           case 4:
                   panZhanZhuZheng->Visible=true;
                   break;
           case 5:
                   panAbout->Visible=true;
                   break;
           case 6:
                   panRYXinXiGL->Visible=true;
                   break;
           case 7:
                   PanRenKouZuHeChaXun->Visible=true;
                   break;
           case 8:
                   panAbout->Visible=true;
                   break;
           case 9:
                   panNianLingTJ->Visible=true;
                   break;
           case 10:
                   panWenHuaChengCiTJ->Visible=true;
                   break;
           case 11:
                   panShouRuShuiPingTJ->Visible=true;
                   break;
           case 12:
                   panRYXingZiTJ->Visible=true;
                   break;
           case 13:
                   panAbout->Visible=true;
                   break;
           case 14:
                   panGuanLi->Visible=true;
                   break;
           case 15:
                   panZhuFangJiTuiFang->Visible=true;
                   break;
           case 16:
                   panChangeRoom->Visible=true;
                   break;
           case 17:
                   panShouFangXinXi->Visible=true;
                   break;
           case 18:
                   panZhuFangXinXi->Visible=true;
                   break;
           case 19:
                   panAbout->Visible=true;
                   break;
           case 20:
                   panGongGaoHaiBao->Visible=true;
                   break;
           case 21:
                   panGongQiuXinXi->Visible=true;
                   break;
           case 22:
                   panShiChangHangQing->Visible=true;
                   break;
           case 23:
                   panDianShiJieMu->Visible=true;
                   break;
           case 24:
                   panRenCaiXuQiu->Visible=true;
                   break;
           case 25:
                   panBBS->Visible=true;
                   break;
           case 26:
                   panAbout->Visible=true;
                   break;
           case 27:
                   PanXiuGaiGuanLiYuanXinXi->Visible=true;
                   break;
           case 28:
                   panUserHelp->Visible=true;
                   break;
           case 29:
                   panAbout->Visible=true;
                   break;
     }

     Parent=true;
     Index=Node->AbsoluteIndex;
}
//---------------------------------------------------------------------------



void __fastcall TfrmMain::SysTimerTimer(TObject *Sender)
{
  AnsiString NodeName;
  
  //显示时间
  TDateTime  DateTime =Time ( );
  StaBar->Panels->Items[1]->Text = "时间:"+TimeToStr (DateTime);
  StaBar->Panels->Items[0]->Text = "当前位置:"+TreeView->Items->Item[Index]->Text;
}
//---------------------------------------------------------------------------



void __fastcall TfrmMain::FormClose(TObject *Sender, TCloseAction &Action)
{

  frmMain->Visible=false;
  frmLogin->Visible=true;
  Global::SaveIndexToFile(pCZRYHead,"Index.db");//将常住人员索引表保存到index文件中
  Global::FreeLinker(pCZRYHead);  //释放常住人员索引链表

  Global::SaveIndexToFile(pSWRYHead,"SWRYIndex.db");//将死亡人员索引表保存到swryindex文件中
  Global::FreeLinker(pSWRYHead);  //释放死亡人员索引链表

  Global::SaveIndexToFile(pQCRYHead,"QCRYIndex.db");//将迁出人员索引表保存到qcryindex文件中
  Global::FreeLinker(pQCRYHead);  //释放迁出人员索引链表

  Global::SaveIndexToFile(pZZRYHead,"ZZRYIndex.db");//将暂住人员索引表保存到zzryindex文件中
  Global::FreeLinker(pZZRYHead);  //释放暂住人员索引链表

  //保存用户评论区信息
  memoBBSYiJian->Lines->SaveToFile("BBS.db");
  memoRCXQXQ->Lines->SaveToFile("RCXQ.db");
  memoDSJMDan->Lines->SaveToFile("DSJM.db");
  memoSCHQHQ->Lines->SaveToFile("SCHQ.db");
  memoGQXXGQ->Lines->SaveToFile("GQXX.db");
  memoGGHBGG->Lines->SaveToFile("GGHB.db");

  Global::WriteRenKouTJToFile("RenKouTJ.db",RenKouTJ);//保存人口统计结构到文件中
  delete RenKouTJ;
  
  Admin=false;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::btnCZRYJLAddClick(TObject *Sender)
{
    if (edtCZRYJLName->Text.IsEmpty())
   {
       ShowMessage("名字不能为空!");
       return;
   }

    //strcpy(pIndex->SfzID,Edit1->Text.c_str());
    //pHead=Global::AddPerson(pHead,pIndex);
    if(SysUtil::JudgeSfzID(edtCZRYJLSID->Text))
    {
        //判断身份证是否存在

         //修改!!!!
        if((Global::SearchIndex(pCZRYHead,edtCZRYJLSID->Text.c_str()))!=-1L)
        {
           ShowMessage("此身份证号码已在常住及迁入记录中存在,请检查你的输入!");
           return ;
        }
        if((Global::SearchIndex(pQCRYHead,edtCZRYJLSID->Text.c_str()))!=-1L)
        {
           ShowMessage("此身份证号码已在迁出记录中存在,请检查你的输入!");
           return ;
        }
        if((Global::SearchIndex(pSWRYHead,edtCZRYJLSID->Text.c_str()))!=-1L)
        {
           ShowMessage("此身份证号码已在死亡记录中存在,请检查你的输入!");
           return ;
        }
        if((Global::SearchIndex(pZZRYHead,edtCZRYJLSID->Text.c_str()))!=-1L)
        {
           ShowMessage("此身份证号码已在暂住记录中存在,请检查你的输入!");
           return ;
        }




        //判断数字是否合法


        if (!SysUtil::IsNumberString(edtCZRYJLAge->Text))
        {
           ShowMessage("你输入的年龄不是一个合法的整数");
           return;
        }
        else
        {
           if (edtCZRYJLAge->Text.ToInt()<1 || edtCZRYJLAge->Text.ToInt() > 150)
           {
               ShowMessage("你输入的年龄不是一个有效的年龄段");
               return;
           }

        }

        //修补BUG
        int QRtime,birth;
        QRtime=DTCZRYJLQianRuTime->DateTime.operator int();
        birth=DTCZRYJLBirthday->DateTime.operator int();
        if (QRtime<birth)
        {
           ShowMessage("出生日期与迁入时间不匹配!");
           return ;
        }

     
        //添加新的索引节点
        UserIndex *pIndex=new UserIndex;
        strcpy(pIndex->SfzID,edtCZRYJLSID->Text.c_str());
        pCZRYHead=Global::AddPerson(pCZRYHead,pIndex);
        //delete pIndex;//delete *pIndex

        PerInfo *per=new PerInfo;

        strcpy(per->Name,edtCZRYJLName->Text.c_str());
        per->Sex=RGCZRYJLSex->ItemIndex;
        per->Birthday=DTCZRYJLBirthday->DateTime.operator int();
        strcpy(per->JiGuan,edtCZRYJLJiGuan->Text.c_str());
        strcpy(per->MinZu,edtCZRYJLMinZu->Text.c_str());
        per->QianRuShiJian=DTCZRYJLQianRuTime->DateTime.operator int();

        per->ZengZhi=comBxCZRYJLZZMM->ItemIndex;
        per->Age=edtCZRYJLAge->Text.ToInt();
        per->HunYin=comBxCZRYJLHunYin->ItemIndex;
        per->WenHua=comBxCZRYJLWenHua->ItemIndex;
        per->ShouRu=comBxCZRYJLShouRu->ItemIndex;
        per->XingZhi=comBxCZRYJLXingZhi->ItemIndex;

        //身份证
        strcpy(per->SfzID,edtCZRYJLSID->Text.c_str());
        strcpy(per->SheHuiGuanXi,edtCZRYJLSheHuiGuanXi->Text.c_str());
        strcpy(per->Address,edtCZRYJLAddress->Text.c_str());
        strcpy(per->QianRuDiDian,edtCZRYJLQianRuAddress->Text.c_str());
        strcpy(per->QianRuYuanYin,edtCZRYJLQianRuYuanYin->Text.c_str());
        per->ZhongDian=RGCZRYJLZhongDian->ItemIndex;

        if (!Global::WritePerInfoToFile("Person.db",pIndex->Index,per))
        {
           ShowMessage("你成功添加了一条信息!");
        }
        Global::AddJieGouMes(RenKouTJ,per->Age,per->WenHua,per->ShouRu,per->XingZhi);
        delete per;


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



void __fastcall TfrmMain::FormShow(TObject *Sender)
{
   pCZRYHead=Global::ReadIndexFromFile("Index.db");//创建常住人员索引表头
   pSWRYHead=Global::ReadIndexFromFile("SWRYIndex.db");//创建死亡人员索引表头
   pQCRYHead=Global::ReadIndexFromFile("QCRYIndex.db");//创建迁出人员索引表头
   pZZRYHead=Global::ReadIndexFromFile("ZZRYIndex.db");//创建暂住人员索引表头



   //读取信息管理文件
   memoBBSYiJian->Lines->LoadFromFile("BBS.db");
   memoRCXQXQ->Lines->LoadFromFile("RCXQ.db");
   memoDSJMDan->Lines->LoadFromFile("DSJM.db");
   memoSCHQHQ->Lines->LoadFromFile("SCHQ.db");
   memoGQXXGQ->Lines->LoadFromFile("GQXX.db");
   memoGGHBGG->Lines->LoadFromFile("GGHB.db");

   //初始化房屋编号
   edtGLRoomNum->Text=1+Global::GetLastRoomNumber("ROOM.db");
   FILE *fp;
   if((fp=fopen("userhelp.rtf","rb+"))==NULL)                 //不存在则新建一个

⌨️ 快捷键说明

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