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

📄 option.cpp

📁 停车场用
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "option.h"
#include "dido.h"
#include "bdbf.h"
#include "dynamic.h"
#include "param.h"
#include "datetool.h"
#include "CBuilder.h"
#include "syspassword.h"

//---------------------------------------------------------------------------
//读取所有系统密码
static int ReadSysPasswordInAccount(void);
//保存所有系统密码
static int SaveSysPasswordInAccount(void);

#pragma package(smart_init)

//初始化参数
int InitLookParam(void)
 {
  void *pCur;

  InitDynamic();

  ReadAllPrice(GetPriceList());
  ReadAllRoadway(GetRoadwayList());
  ReadAllPark(GetParkList());

  pCur =GetControlerList();
  ReadAllControler(pCur);
  CalcLocalControler(pCur);//计算本地控制器
  SetRoadwayToCR();//获取控制器包含的车道

  return (TRUE);
 }
//关闭参数
int CloseLookParam(void)
 {
  CloseDynamic();

  return(TRUE);
 }
//计算本地控制器
int CalcLocalControler(void *pHead)
 {
  CONTROLER *pCR;
  void *pCur;
  char szComputer[MAX_COMPUTERNAME_LENGTH + 10];
  DWORD nSize;
  int i,rc;

  nSize = sizeof(szComputer);
  GetComputerName(szComputer,&nSize);//获取本地计算机名

  for(i=0;;i++){
    pCur = GetDotOnTList(pHead,i);
    if(pCur==NULL)break;

    pCR = LookControler(pCur);
    if(GetCRUnLinkFlag(pCR))rc=FALSE;//未联线
    else if(pCR->szHostName[0]==0 ||   //宿主机名不存在或等于本地计算机名
        lstrcmpi(pCR->szHostName,szComputer)==0)//保留该节点
      rc=TRUE;//设置在线
    else rc=FALSE;  //设置不在线
    SetCROnLineFlag(pCR,rc);  //设置不在线
   }
  return(i);
 }
//获取标题
char *GetMainTitle(void)
 {
  static char pszTitle[]="停车场管理系统";
  return(pszTitle);
 }
//读取所有系统密码
int ReadSysPasswordInAccount(void)
 {
  TList *pAccList;
  void *pCur;
  ACCOUNT *t;
  int i,rc;

  pAccList= new TList;
  rc=ReadAllSysPassword(pAccList);//读取所有系统密码
  for(i=0;rc>0;i++){
    pCur = GetDotOnTList(pAccList,i);
    if(pCur==NULL)break;

    t = LookAccount(pCur);
    SetSysPassword(t->szPassword,t->nLevel&0x0ff);
   }
  delete pAccList;
  return(i);
 }
//保存所有系统密码
int SaveSysPasswordInAccount(void)
 {
  TList *pAccList;
  ACCOUNT a;
  int i,rc;
  char *p;

  pAccList= new TList;
  for(i=0;;i++){
    p = GetSysPassword(i);
    if(p==NULL)break;

    ZeroMemory(&a,sizeof(a));
    a.nLevel=i;
    lstrcpyn(a.szPassword,p,sizeof(a.szPassword));
    AddContentToTList(pAccList,&a,sizeof(a));
   }
  rc=SaveAllSysPassword(pAccList);//保存所有系统密码
  delete pAccList;
  return(rc);
 }
//设置密码
int ReworkSomeSysPassword(TObject *Owner)
 {
  static char pszText[]="是否还设置\n\n其他级别系统密码?" ;
  int n,rc;

  rc=FALSE;
  while(1){
    n=ReworkSysPassword(Owner);
    if(n)rc=TRUE;
    n = Application->MessageBox(pszText,GetMainTitle(),
           MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL);
    if(n!=IDYES)break;
   }
  if(rc)
     SaveSysPasswordInAccount();//保存密码

  return(rc);
 }
//获取控制器包含的车道
int SetRoadwayToCR(void)
 {
  void *pCRList,*pRoadList;
  int i,n,nCRNo;
  void *pCur;
  ROADWAY *pRoad;
  CONTROLER *pCR;

  pRoadList = GetRoadwayList();
  pCRList = GetControlerList();
  for(i=0;;i++){
    pCur = GetDotOnTList(pRoadList,i);
    if(pCur==NULL)break;

    pRoad = LookRoadway(pCur);
    nCRNo = pRoad->nCRNo;
    if(nCRNo!=0)//寻找编号为nCRNo的控制器
      pCR = (CONTROLER *)GetCROnListWithNo(pCRList,nCRNo);
    else pCR=NULL;
    if(pCR!=NULL){//存在nCRNo控制器
      n = pCR->nRoads;
      if(n<sizeof(pCR->wzRoadNo)/sizeof(WORD)){
        pCR->wzRoadNo[n++]=pRoad->nNo; //将车道存入控制器中
        pCR->nRoads=n;
       }
     }
   }
  return(TRUE);
 }
//根据编号获取控制器
void *GetCROnListWithNo(void *pList,int nCRNo)
 {
  void *pCur;
  int i;

  for(i=0;;i++){
    pCur = GetDotOnTList(pList,i);
    if(pCur==NULL)break;

    if((int)LookControler(pCur)->nCRNo==nCRNo)break;
   }
  return(LookControler(pCur));
 }
//根据车道号获取控制器
void *GetCRWithRoadNo(void *pCRList,int nRoadNo)
 {
  WORD *pRoadNo;
  int i,j,n;
  void *pCur;

  if(nRoadNo==0)return(NULL);

  for(i=0;;i++){
    pCur = GetDotOnTList(pCRList,i);
    if(pCur==NULL)break;

    n = LookControler(pCur)->nRoads;
    pRoadNo= LookControler(pCur)->wzRoadNo;
    for(j=0;j<n;j++)
      if(nRoadNo==(int)pRoadNo[j])break;
    if(j<n)break;
   }
  return(LookControler(pCur));
 }

//请求保存数据
int AskSaveData(void)
 {
  static char pszText[]="数据还没有保存!\n\n是否保存?";
  int rc;

  rc= Application->MessageBox(pszText,GetMainTitle(),
       MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON1|MB_APPLMODAL);

  if(rc==IDYES)rc=TRUE;
  else rc=FALSE;
  return(rc);
 }
//获取用户类型名称文本
char *GetUserTypeText(char *pszStr,int nID)
 {
  PRICEDATA *t;

  t= (PRICEDATA *)GetPriceWithID(nID);//根据卡号获取人员
  if(t!=NULL) lstrcpy(pszStr,t->szUserType);
  else wsprintf(pszStr,"<%d>",nID);

  return(pszStr);
 }
//获取车道名称文本
char *GetRoadwayNameText(char *pszStr,int nNo)
 {
  void *pRoad;
  char *p;

  pRoad= (ROADWAY *)GetRoadwayWithNo(nNo);//根据卡号获取人员

  p = GetRoadwayNameText(pszStr,pRoad);//获取车道名称文本
  if(pRoad==NULL && nNo!=0)wsprintf(pszStr,"<%d>",nNo);
  return(p);
 }
//获取车道名称文本
char *GetRoadwayNameText(char *pszStr,void *pRoad)
 {
  ROADWAY *t;
  char *p;

  t= (ROADWAY *)pRoad;
  if(t!=NULL){
    p = GetRoadwayType(t->nType);//获取Roadway类型串
    if(p==NULL) lstrcpy(pszStr,t->szName);
    else wsprintf(pszStr,"%s(%s)",t->szName,p);
   }
  else pszStr[0]=0;
  return(pszStr);
 }
//获取控制器名称文本
char *GetCRNameText(char *pszStr,void *pCR)
 {
  CONTROLER *t;

  t = (CONTROLER *)pCR;
  if(t->szName[0]!=0)lstrcpy(pszStr,t->szName);
  else if(t->nAddrID!=0)
    wsprintf(pszStr,"<ID=%d>",t->nAddrID);
  else wsprintf(pszStr,"<No=%d>",t->nCRNo);
  return(pszStr);
 }
//获取编号文本
char *GetNumberText(char *pszStr,int nNo)
 {
  if(nNo!=0)wsprintf(pszStr,"%04d",nNo);
  else pszStr[0]=0;
  return(pszStr);
 }
//获取长整数日期文本
char *GetDWORDDateText(char *pszStr,DWORD nDate)
 {
  if(nDate!=0)DWORDToDateStr(pszStr,nDate);
  else pszStr[0]=0;
  return(pszStr);
 }
//根据编号获取用户收费类型
int GetPriceChargeWithID(int nID)
 {
  PRICEDATA *t;
  int n;

  t= (PRICEDATA *)GetPriceWithID(nID);//根据卡号获取人员
  if(t!=NULL)n=t->nChargeType;
  else n=-1;
  return(n);
 }
//用户即时扣款
int UserPayMoneyOnNow(void *pUser,int nNowDate)
 {
  int rc,nPaidType,nPaidDate;
  float f;
  USERDATA *t;
  PRICEDATA *pPrice;

  rc=FALSE;
  t = (USERDATA* )pUser;
  //根据编号获取用户收费
  pPrice = (PRICEDATA *)GetPriceWithID(t->nUserType);
  if(pPrice!=NULL){
    nPaidType = pPrice->nChargeType;
    nPaidDate = t->nPaidDate;
    if(nPaidType==PAID_MONTH) //"按月收费",
      f=GetParkPriceInMonth(pPrice,nPaidDate,nNowDate);

    else if(nPaidType==PAID_QUARTER)  "按季收费",
      f=GetParkPriceInQuarter(pPrice,nPaidDate,nNowDate);

    else if(nPaidType==PAID_YEAR)  "按年收费",
      f=GetParkPriceInYear(pPrice,nPaidDate,nNowDate);
    else f=0.0f;

    if(f>1.0e-2f && t->fMoney>=f){//须付款
      t->fMoney -= f;
      t->nPaidDate=nNowDate;
      rc=TRUE;
     }
   }
  return(rc);
 }
//用户下次需要付款金额
float GetUserNextPaid(int nUserType)
 {
  PRICEDATA *pPrice;
  int nPaidType;
  float f;

  //根据编号获取用户收费
  pPrice = (PRICEDATA *)GetPriceWithID(nUserType);
  if(pPrice!=NULL){
     nPaidType = pPrice->nChargeType;
     if(nPaidType!=PAID_NEVER && nPaidType!=PAID_FOREVER)//需要按时交费类型
        f = pPrice->fPriceValue;
    }
  else f=0.0f;
  return(f);
 }

//获取"按次收费"停车金额
float GetParkPriceInNumber(void *pPrice,int nParkTime)
 {
  PRICEDATA *t;
  float f;
  int nDate,nTime;

  f = 0.0f;
  t = (PRICEDATA *)pPrice;
  nTime = LOWORD(nParkTime);
  nDate = HIWORD(nParkTime);
  if(nTime>=t->nNeverTime)
     f = t->fPriceValue; //每次收费
  if(nDate!=0 && t->fNightPrice>1.0e-2f)
      f += t->fNightPrice*nDate; //过夜收费
  return(f);
 }
//获取"按时收费"停车金额
float GetParkPriceInPeriod(void *pPrice,int nParkTime)
 {
  PRICEDATA *t;
  float f,fMax;
  int nTime,nDate,nSecTime;

  f=0.0f;
  t = (PRICEDATA *)pPrice;
  nTime = LOWORD(nParkTime);
  nDate = HIWORD(nParkTime);
  nTime = (nDate-1)*24*60+nTime;
  if(nTime>=t->nNeverTime){
    f = t->fFirstPrice; //首次时间收费
    nTime = nTime-t->nFirstTime;
    nSecTime = t->nSecondTime;
    if(nTime>0 && nSecTime>0){  //超过时间收费
      nTime = (nTime +nSecTime-1)/nSecTime;
      f = f+nTime*t->fSecondPrice;
     }
   }
  if(nDate!=0 && t->fNightPrice>1.0e-2f)
     f += t->fNightPrice*nDate; //过夜收费
  fMax = t->fPriceValue; //最高限额
  if(fMax>1.0e-2f && f>fMax)f=fMax; //定义了最高限额

  return(f);
 }
//获取"按日收费"停车金额(nPaidDate=上次付款日期)
float GetParkPriceInDay(void *pPrice,int nPaidDate,int nNowDate,int nParkTime)
 {
  float f,fMax;
  int nDate;

  f=0.0f;
  if(nNowDate>nPaidDate){//当天还未付款
    nDate = HIWORD(nParkTime);
    if(nDate<=0)nDate=1;  else nDate=nDate+1;
    f = ((PRICEDATA *)pPrice)->fPriceValue*nDate;
   }
  return(f);
 }
//获取"按月收费"停车金额(nPaidDate=上次付款日期)
float GetParkPriceInMonth(void *pPrice,int nPaidDate,int nNowDate)
 {
  int nYear1,nMonth1,nDay1;
  int nYear2,nMonth2,nDay2;
  int n;
  float f;

  f=0.0f;
  if(nNowDate>nPaidDate+100){//当月还未付款
    GetDateOnDWORD(nPaidDate,&nYear1,&nMonth1,&nDay1);
    GetDateOnDWORD(nNowDate,&nYear2,&nMonth2,&nDay2);
    n = (nYear2-nYear1)*12+nMonth2-nMonth1;
    if(nDay2<nDay1)n--;//不满一个月
    if(n>0)f=((PRICEDATA *)pPrice)->fPriceValue*n;
   }
  return(f);
 }
//获取"按季收费"停车金额(nPaidDate=上次付款日期)
float GetParkPriceInQuarter(void *pPrice,int nPaidDate,int nNowDate)
 {
  int nYear1,nMonth1,nDay1;
  int nYear2,nMonth2,nDay2;
  int n;
  float f;

  f=0.0f;
  if(nNowDate>nPaidDate+300){//当季还未付款
    GetDateOnDWORD(nPaidDate,&nYear1,&nMonth1,&nDay1);
    GetDateOnDWORD(nNowDate,&nYear2,&nMonth2,&nDay2);
    n = (nYear2-nYear1)*12+nMonth2-nMonth1;
    if(nDay2<nDay1)n--;//不满一个月
    if(n>=3){
      n = n/3;
      f=((PRICEDATA *)pPrice)->fPriceValue*n;
     }
   }
  return(f);
 }
//获取"按年收费"停车金额(nPaidDate=上次付款日期)
float GetParkPriceInYear(void *pPrice,int nPaidDate,int nNowDate)
 {
  int nYear1,nMonth1,nDay1;
  int nYear2,nMonth2,nDay2;
  int n;
  float f;

  f=0.0f;
  if(nNowDate>nPaidDate+10000){//当年还未付款
    GetDateOnDWORD(nPaidDate,&nYear1,&nMonth1,&nDay1);
    GetDateOnDWORD(nNowDate,&nYear2,&nMonth2,&nDay2);
    n = (nYear2-nYear1)*12+nMonth2-nMonth1;
    if(nDay2<nDay1)n--;//不满一个月
    if(n>=12){
      n = n/12;
      f=((PRICEDATA *)pPrice)->fPriceValue*n;
     }
   }
  return(f);
 }
//保存停车记录到链表中等候人工比对
int SaveParkrecToManaul(void *pParkrec)
 {
  void *pHead,*pCur;

  pHead = GetManualParkrecList();

  //增加内容到TList链末尾
  pCur = AddContentToTList(pHead,pParkrec,sizeof(PARKREC));
  if(pCur!=NULL){
    LookParkrec(pCur)->pInPhoto= CopyBlobData(((PARKREC *)pParkrec)->pInPhoto);
    LookParkrec(pCur)->pOutPhoto= CopyBlobData(((PARKREC *)pParkrec)->pOutPhoto);
   }
  return((int)pCur);
 }
//删除链上的第nIndex个PARKREC节点
int DelParkrecDotOnTList(void *pHead,int nIndex)
 {
  void *pCur;
  int rc;

  pCur=GetDotOnTList(pHead,nIndex);
  if(pCur==NULL)return(FALSE);

  DeleteBlobData(LookParkrec(pCur)->pInPhoto);
  DeleteBlobData(LookParkrec(pCur)->pOutPhoto);

  //删除LOOKLIST链上的nIndex节点
  rc=DelDotOnTList(pHead,nIndex);

  return(rc);
 }
//删除PARKREC链表
int DelParkrecList(void *pHead)
 {
   //连续删除链上的第0个PARKREC节点
  while(DelParkrecDotOnTList(pHead,0));
  return(TRUE);
 }




⌨️ 快捷键说明

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