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

📄 frame.h

📁 一个数据结构的大作业
💻 H
📖 第 1 页 / 共 3 页
字号:
#ifndef FRAME_H
#define FRAME_H
#include <graphics.h>
#include <string.h>
/*#include "c:\MyTele\MyCCode\Common.h"
#include "c:\MyTele\MyCCode\Data.h"*/

#include "e:\Progra~1\MyCCode\Common.h"
#include "e:\Progra~1\MyCCode\List.h"
#include "e:\Progra~1\MyCCode\Edit.h"

#define EDITBACK_COLOR   15
#define EDITCURSOR_COLOR RED
#define EDITTEXT_COLOR   0

int ColumnWidth[7]={ 54,52,46,100,44,100,38 };
char *ColumnText[7]={ "Number","Type","Begin","From","End","To","Cost" };
//|Number52|Type52|Begin44|From  |End44|To  |Cost36| 228 is ruled
//448-228=220 so From is 100 To is 100. allow to input 10 letters.
int totalcount=0;
int findcount=0;
TRAIN *MainHead=NULL;
TRAIN *MainLast=NULL;
TRAIN *FindHead=NULL;
TRAIN *FindLast=NULL;

char tempTrainNumber[6]={'\0','\0','\0','\0','\0','\0'};
char tempKind[6]={'\0','\0','\0','\0','\0','\0'};
char tempBegin[11]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
char tempEnd[11]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
char tempBeginHour[3]={'\0','\0','\0'};
char tempEndHour[3]={'\0','\0','\0'};
char tempBeginMinute[3]={'\0','\0','\0'};
char tempEndMinute[3]={'\0','\0','\0'};
char tempCost[5]={'\0','\0','\0','\0','\0'};

int tab=1;
int Index1=0,Index2=0;
int NowIndexInList1=0,NowIndexInList2=0;
TRAIN atrain;
char FileName[20]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
		   '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
int Modified=0;

int statisticsdata[2][5];
char *statisticstext[5]={"Total Count:",
			 "   TK Train:",
			 "   PK Train:",
			 "   KS Train:",
			 "   GJ Train:"};
/////////////////////////////////////////////////////////
void New(int Load);
void Save();
void LoadBox();
void SaveAsBox();
void Exit();

void AddItem();
void Modify();
void Delete();

void FindByNumber();
void FindByBegin();
void FindByType();
void FindByATB();

void AboutBox();

void DrawStaticsGird(int x,int y);
void UpdateStaticsData(int x,int y,int mof);
void GoThroughList(int which,TRAIN *head);

int MessageBox(int x1,int y1,int x2,int y2,
	       char *title,char *text,int textcolor,int onlyOK);
int InputBox(int x1,int y1,int x2,int y2,
	     char *title,char *text,
	     char Data[],int length);
void ClearGirdText(int x1,int y1,int x2,int CountPerPage);
int GroupBars(int x1,int y1,int x2);
void DrawCaptain(int x1,int y1,int x2,//height is same
		 int color,int textcolor,
		 char *text,int is3dtext);
void DrawWindow(int x1,int y1,int x2,int y2,
		int color,int textcolor,
		char *captain,int is3dtext,
		int borderwidth,int issolid);

void BarText(int x1,int y1,int x2,int y2,
	     int backcolor,int textcolor,
	     char *text);

void DrawTrainList(int x1,int y1,int x2,//height is ruled
		   int SelBarColor,
		   int CountPerPage);
void DrawListGird(int x1,int y1,int x2,int CountPerPage);
void SetTrainListSelBar(int x1,int y1,int x2,
			int SelectColor,
			int NowSelect,int CountPerPage);
void DrawTrainListScrollBar(int x1,int y1,int x2,int y2);
void SetTrainListScrollBar(int x1,int y1,int x2,int y2,
			   int NowPosition,int Count);
void ClearStr(char str[],int count);
void TrainListShowData(int x,int y,
		       TRAIN *head,
		       int BeginIndex,int ShowCount,
		       int textcolor);
void TwoListFunction();
/////////////////////////////////////////////////////////
void AboutBox()
{
 FILE *fp;
 int i,k;
 int width,height;
 void *pimage;
 char bitmap[40][40];
 int x=185,y=185;
 if((fp=fopen("run5.drw","r"))==NULL)
 {
  MessageBox(200,180,410,260,
	     "Error","Icon file can't open.",
	     RED,1);
  return;
 }
 else
 {
  rewind(fp);
  width=fgetc(fp);
  height=fgetc(fp);
  for(i=0;i<height;i++)
   for(k=0;k<width;k++)
    bitmap[k][i]=fgetc(fp);
  fclose(fp);
 }
 pimage=malloc(imagesize(180,170,410,250));
 getimage(180,170,410,250,pimage);
 DrawWindow(180,170,410,250,
	    FRAME_COLOR,ACTIVE_COLOR,
	    "About...",1,1,1);
 for(i=0;i<height;i++)
  for(k=0;k<width;k++)
  {
   if(bitmap[k][i]==15) continue;
   putpixel(x+k,y+i,3/*bitmap[k][i]*/);
  }
 for(i=0;i<height;i++)
  for(k=0;k<width;k++)
  {
   if(bitmap[k][i]==15) continue;
   putpixel(x+k+1,y+i+1,1/*bitmap[k][i]*/);
  }
 setcolor(0);
 outtextxy(230,188,"Designed by Dengxiao.");
 outtextxy(230,203,"HighSpeed Studio.");
 outtextxy(230,218,"All right reserved.");
 outtextxy(285,235,"<OK>");
 setcolor(15);
 outtextxy(229,187,"Designed by Dengxiao.");
 outtextxy(229,202,"HighSpeed Studio.");
 outtextxy(229,217,"All right reserved.");
 outtextxy(284,234,"<OK>");
 PostKeybrdMessage();
 while((KeyboardMessage[1]!=CTRL_KEY_ENTER)&&
       (KeyboardMessage[1]!=CTRL_KEY_ESC))
 {
  PostKeybrdMessage();
 }
 putimage(180,170,pimage,COPY_PUT);
 free(pimage);
}
void DrawStaticsGird(int x,int y)
{
 int i;
 int liney=y+20;
 for(i=0;i<5;i++)
 {
   setcolor(0);
   outtextxy(x+5,liney+3,statisticstext[i]);
   setcolor(15);
   outtextxy(x+4,liney+2,statisticstext[i]);
  liney+=25;
 }
}
void UpdateStaticsData(int x,int y,int mof) /*0 is main,1 is find.*/
{
 int i,k;
 int liney=y+20;
 char number[10];
 if(!mof) k=0;
 else k=1;
 setfillstyle(SOLID_FILL,FRAME_COLOR);
 setcolor(MENUTEXT_COLOR);
 for(i=0;i<5;i++)
 {
  bar(x+104,liney+3,x+154,liney+10);
  sprintf(number,"%d",statisticsdata[k][i]);
  outtextxy(x+104,liney+3,number);
  liney+=25;
 }
}
void GoThroughList(int which,TRAIN *head)
{
 int i;
 int k;
 TRAIN *pt;
 if(!which) i=totalcount;
 else i=findcount;
 for(k=1;k<5;k++)
  statisticsdata[which][k]=0;
 statisticsdata[which][0]=i;
 for(k=0;k<i;k++)
 {
  pt=GetAt(head,k);
  if(strcmp(pt->Kind,"tk")==0)
   statisticsdata[which][1]++;
  else if(strcmp(pt->Kind,"pk")==0)
	statisticsdata[which][2]++;
       else if(strcmp(pt->Kind,"ks")==0)
	     statisticsdata[which][3]++;
	    else if(strcmp(pt->Kind,"gj")==0)
		  statisticsdata[which][4]++;
 }
}
void FindByATB()
{
 void *imagebuf;
 int ImageSize;
 char Begin[11];
 char End[11];
 int i;
 int showcount,selcolor;
 TRAIN *pt,*padd,*ptrain;
 ClearStr(Begin,11);
 ClearStr(End,11);
 ImageSize=imagesize(200,169,470,250);
 imagebuf=malloc(ImageSize);
 getimage(200,169,470,250,imagebuf);
 DrawWindow(200,169,470,250,
	    FRAME_COLOR,ACTIVE_COLOR,
	    "Find by A to B",1,
	    1,1);
 setcolor(MENUTEXT_COLOR);
 outtextxy(210,194,"A and B:");
 outtextxy(210,220,"<Enter> for YES.");
 outtextxy(210,230,"< ESC > for CANCEL.");
 setfillstyle(SOLID_FILL,EDITBACK_COLOR);
 DrawEdgeTwo(274,193,357,204);
 bar(275,194,354,203);
 setcolor(MENUTEXT_COLOR);
 outtextxy(360,194,"TO");
 DrawEdgeTwo(376,193,459,204);
 bar(377,194,458,203);
 if(EditBar(275,194,
	    EDITBACK_COLOR,EDITTEXT_COLOR,Begin,11,0)==0) goto last;
 if(EditBar(377,194,
	    EDITBACK_COLOR,EDITTEXT_COLOR,End,11,0)==0) goto last;
 findcount=0;
 DeleteAll(&FindHead);
 FindLast=NULL;
 ClearGirdText(3,293,447,13);
 NowIndexInList2=0;
 Index2=0;
 for(i=0;i<totalcount;i++)
 {
  pt=GetAt(MainHead,i);
  if((strcmp(pt->Begin,Begin)==0)&&(strcmp(pt->End,End)==0))
  {
   padd=(TRAIN*)malloc(sizeof(TRAIN));
   memcpy(padd,pt,sizeof(TRAIN));
   if(findcount==0)
   {
    FindHead=CreatList((*padd));
    FindLast=FindHead;
   }
   else
   {
    ptrain=AddTail(FindLast,*padd);
    FindLast=ptrain;
   }
   findcount++;
  }
 }
 GoThroughList(1,FindHead);
 UpdateStaticsData(451,280,1);
last:
 putimage(200,169,imagebuf,COPY_PUT);
 free(imagebuf);
 if(findcount>0)
 {
  if(findcount>13) showcount=13;
  else showcount=findcount;
  TrainListShowData(3,306,FindHead,
		    NowIndexInList2,showcount,
		    GIRD_TEXTCOLOR2);
 }
 if(tab)
  selcolor=SLEEP_COLOR;
 else
  selcolor=ACTIVE_COLOR;
 SetTrainListSelBar(3,293,447,selcolor,Index2,13);
 SetTrainListScrollBar(438,306,447,306+13*13,
		       NowIndexInList2+13,findcount);
}
int InputBox(int x1,int y1,int x2,int y2,
	     char *title,char *text,
	     char Data[],int length)
{
 void *imagebuf;
 int ImageSize;
 int length1,length2;
 char temp[100];
 ClearStr(temp,100);
 strcpy(temp,Data);
 ImageSize=imagesize(x1,y1,x2,y2);
 imagebuf=malloc(ImageSize);
 getimage(x1,y1,x2,y2,imagebuf);
 DrawWindow(x1,y1,x2,y2,
	    FRAME_COLOR,ACTIVE_COLOR,
	    title,1,
	    1,1);
 length1=strlen(text)*8;
 length2=length*8+5;
 setcolor(MENUTEXT_COLOR);
 outtextxy(x1+10,y1+25,text);
 outtextxy(x1+10,y2-30,"<Enter> for YES.");
 outtextxy(x1+10,y2-20,"< ESC > for CANCEL.");
 DrawEdgeTwo(x1+10+length1,y1+24,x1+length1+length2,y1+35);
 if(EditBar(x1+11+length1,y1+25,
	    EDITBACK_COLOR,EDITTEXT_COLOR,temp,length,0)==1)
 {
  strcpy(Data,temp);
  putimage(x1,y1,imagebuf,COPY_PUT);
  free(imagebuf);
  return 1;
 }
 else
 {
  putimage(x1,y1,imagebuf,COPY_PUT);
  free(imagebuf);
  return 0;
 }
}
void FindByType()
{
 int i;
 TRAIN *pt,*ptrain;
 TRAIN *padd;
 char Type[20];
 int showcount;
 int selcolor;
 ClearStr(Type,20);
 if(InputBox(200,169,430,250,
	     "Find by Type","Type:",Type,20)==1)
 {
  findcount=0;
  DeleteAll(&FindHead);
  FindLast=NULL;
  ClearGirdText(3,293,447,13);
  NowIndexInList2=0;
  Index2=0;
  for(i=0;i<totalcount;i++)
  {
   pt=GetAt(MainHead,i);
   if(strcmp(pt->Kind,Type)==0)
   {
    padd=(TRAIN*)malloc(sizeof(TRAIN));
    memcpy(padd,pt,sizeof(TRAIN));
    if(findcount==0)
    {
     FindHead=CreatList((*padd));
     FindLast=FindHead;
    }
    else
    {
     ptrain=AddTail(FindLast,*padd);
     FindLast=ptrain;
    }
    findcount++;
   }
  }
  if(findcount>0)
  {
   if(findcount>13) showcount=13;
   else showcount=findcount;
   TrainListShowData(3,306,FindHead,
		     NowIndexInList2,showcount,
		     GIRD_TEXTCOLOR2);
  }
  GoThroughList(1,FindHead);
  UpdateStaticsData(451,280,1);
  if(tab)
    selcolor=SLEEP_COLOR;
  else
    selcolor=ACTIVE_COLOR;
  SetTrainListSelBar(3,293,447,selcolor,Index2,13);
  SetTrainListScrollBar(438,306,447,306+13*13,
			NowIndexInList2+13,findcount);
 }
}
void FindByNumber()
{
 int i;
 TRAIN *pt,*ptrain;
 TRAIN *padd;
 char Number[20];
 int showcount;
 int selcolor;
 ClearStr(Number,20);
 if(InputBox(200,169,430,250,
	     "Find by Number","Number:",Number,20)==1)
 {
  findcount=0;
  DeleteAll(&FindHead);
  FindLast=NULL;
  ClearGirdText(3,293,447,13);
  NowIndexInList2=0;
  Index2=0;
  for(i=0;i<totalcount;i++)
  {
   pt=GetAt(MainHead,i);
   if(strcmp(pt->TrainNumber,Number)==0)
   {
    padd=(TRAIN*)malloc(sizeof(TRAIN));
    memcpy(padd,pt,sizeof(TRAIN));
    if(findcount==0)
    {
     FindHead=CreatList((*padd));
     FindLast=FindHead;
    }
    else
    {
     ptrain=AddTail(FindLast,*padd);
     FindLast=ptrain;
    }
    findcount++;
   }
  }
  if(findcount>0)
  {
   if(findcount>13) showcount=13;
   else showcount=findcount;
   TrainListShowData(3,306,FindHead,
		     NowIndexInList2,showcount,
		     GIRD_TEXTCOLOR2);
  }
  GoThroughList(1,FindHead);
  UpdateStaticsData(451,280,1);
  if(tab)
    selcolor=SLEEP_COLOR;
  else
    selcolor=ACTIVE_COLOR;
  SetTrainListSelBar(3,293,447,selcolor,Index2,13);
  SetTrainListScrollBar(438,306,447,306+13*13,
			NowIndexInList2+13,findcount);
 }
}
void FindByBegin()
{
 int i;
 TRAIN *pt,*ptrain;
 TRAIN *padd;
 char Begin[20];
 int showcount;
 int selcolor;
 ClearStr(Begin,20);
 if(InputBox(200,169,430,250,
	     "Find by Begin","Begin:",Begin,20)==1)
 {
  findcount=0;
  DeleteAll(&FindHead);
  FindLast=NULL;
  ClearGirdText(3,293,447,13);
  NowIndexInList2=0;
  Index2=0;
  for(i=0;i<totalcount;i++)

⌨️ 快捷键说明

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