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

📄 train_booking_attach.c

📁 火车定标系统...用VC编译通过的
💻 C
📖 第 1 页 / 共 2 页
字号:

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	检测文件或目录是否存在	ok
//
// 函数参数:	data_dir:待检测的文件或目录相对于执行程序所在目录的路径
//				notice:是否回馈信息,1是,0否
//
/////////////////////////////////////////////////////////////////////////////
status check_data(char *data_dir, char notice)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;			// 检测数据句柄
	char msg[MAX_MSG_LEN];

	// 检测存放回复数据的目录是否存在
	hFind = FindFirstFile(data_dir, &FindFileData);
	if (hFind == INVALID_HANDLE_VALUE) 
	{
		if (notice)		// 没有则生成并输出错误信息
		{
			strcpy(msg, "");
			strcpy(msg, "文件或目录");
			strcat(msg, data_dir);
			strcat(msg, "无效或不存在!");
			message(ERROR, msg, WC);
		}

		return FAIL;
	} 

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	检测系统配置文件的完整性
//
// 函数说明:	本函数只能单纯地检验基本文件是否存在,不能对文件的内容与扩展
//				文件的内容进行校验。
//				基本文件:runtrain.ini settings.ini regusr.ini
//
/////////////////////////////////////////////////////////////////////////////
status check_system_data(void)
{
	int check_a, check_b, check_c;
	char filepath[MAX_FILE_PATH_LEN];

	check_a = check_b = check_c = 0;

	// 检测系统信息文件
	strcpy(filepath, "");
	strcpy(filepath, SYS_INFO_DIR);
	strcat(filepath, "\\");
	strcat(filepath, SYS_INFO_FILE);
	check_a = check_data(filepath, 0);

	// 检测车次信息文件
	strcpy(filepath, "");
	strcpy(filepath, SYS_INFO_DIR);
	strcat(filepath, "\\");
	strcat(filepath, SQ_INFO_FILE);
	check_b = check_data(filepath, 0);

	// 检测用户信息文件
	strcpy(filepath, "");
	strcpy(filepath, SYS_INFO_DIR);
	strcat(filepath, "\\");
	strcat(filepath, PSNGR_ITEM_FILE);
	check_c = check_data(filepath, 0);

	if ((!check_a) || (!check_b) || (!check_c))
	{
		return FAIL;
	}

	return OK;
}



/////////////////////////////////////////////////////////////////////////////
// 函数功能:	取得当前时间,同时以标准时间和日历时间返回
//
// 函数参数:	tm_pt:待返回日历时间的时间结构体指针
//				std_tm:待返回标准时间量
//
/////////////////////////////////////////////////////////////////////////////
status get_current_time(struct tm *tm_pt, time_t *std_tm)
{
	time_t myt;
	struct tm *temp_time;

	// 取得当前日历时间
	myt = time(NULL);
	temp_time = localtime(&myt);
	tm_pt->tm_year = temp_time->tm_year + 1900;
	tm_pt->tm_mon = temp_time->tm_mon + 1;
	tm_pt->tm_mday = temp_time->tm_mday;
	tm_pt->tm_hour = temp_time->tm_hour;
	tm_pt->tm_min = temp_time->tm_min;
	tm_pt->tm_sec = temp_time->tm_sec;
	tm_pt->tm_wday = temp_time->tm_wday;
	tm_pt->tm_yday = temp_time->tm_yday;
	tm_pt->tm_isdst = temp_time->tm_isdst;

	// 取得当前标准时间
	*std_tm = mktime(tm_pt);

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	确认字符串输入(是否为空串,是则视为放弃输入)
//
// 函数参数:	description:对此输入的描述
//				input_str:输入的字串
//				min_len:字串要求的最小长度
//				max_len:字串要求的最大长度
//				
/////////////////////////////////////////////////////////////////////////////
status get_str(char *description, char *input_str, int min_len, int max_len)
{
	char tmp[128];

input:
	{
		printf("【提示】请输入%s(直接回车则返回):", description);

		gets(tmp);
	}

	if (!tmp[0])		// 如果输入值为空串
	{
		printf("【警告】放弃输入%s!\n", description);
		WAIT;

		return FAIL;
	}
	else if (strlen(tmp) > max_len)		// 长度过长
	{
		printf("【警告】输入的字串不得超过最大长度%d英文字符!\n", max_len);
		WAIT;
		goto input;
	}
	else if (strlen(tmp) < min_len)		// 长度过短
	{
		printf("【警告】输入的字串不得少于最小长度%d英文字符!\n", min_len);
		WAIT;
		goto input;
	}
	else
	{
		strcpy(input_str, tmp);
	}

	return OK;
}

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	确认字符串输入(是否为空串,是则视为放弃输入)
//
// 函数参数:	description:对此输入的描述
//				input_str:输入的字串
//				
/////////////////////////////////////////////////////////////////////////////
status get_float(char *description, float *input_float)
{
	float tmp;

	printf("【提示】请输入%s(输入0返回):", description);

	scanf("%f", &tmp);

	if (0 == tmp)		// 如果输入值为0
	{
		printf("【警告】放弃输入%s!\n", description);
		WAIT;

		return FAIL;
	}
	else
	{
		*input_float = tmp;
	}

	return OK;
}

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	确认整型量输入(是否为空串,是则视为放弃输入)
//
// 函数参数:	description:对此输入的描述
//				input_int:输入的字串
//				
/////////////////////////////////////////////////////////////////////////////
status get_int(char *description, int *input_int)
{
	int tmp;

	printf("【提示】请输入%s(输入0返回):", description);

	scanf("%d", &tmp);

	if (0 == tmp)		// 如果输入值为0
	{
		printf("【警告】放弃输入%s!\n", description);
		WAIT;

		return FAIL;
	}
	else
	{
		*input_int = tmp;
	}

	return OK;
}

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	设置函数小标题
//
// 函数参数:	body:标题文字
//				
/////////////////////////////////////////////////////////////////////////////
status actitle(char *body)
{
	printf("【%s】\n\n", body);

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	一级路径目录创建函数
//
// 函数参数:	dir_i:第一级目录名
//				filename:NULL:只创建目录;非NULL:在已创建的目录下创建此文件
//
/////////////////////////////////////////////////////////////////////////////
status build_i_dir(char *dir_i, char *filename)
{
	char dir[128];
	FILE *fp;

	strcpy(dir, "md ");
	strcat(dir, dir_i);
	system(dir);

	if (!(NULL == filename))
	{
		strcpy(dir, dir_i);
		strcat(dir, "\\");
		strcat(dir, filename);
		fp = fopen(dir, "wb");
		fclose(fp);
	}

	return OK;
}

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	二级路径目录创建函数
//
// 函数参数:	dir_i:第一级目录名
//				dir_ii:第二级目录名
//				filename:NULL:只创建目录;非NULL:在已创建的目录下创建此文件
//
/////////////////////////////////////////////////////////////////////////////
status build_ii_dir(char *dir_i, char *dir_ii, char *filename)
{
	char dir[128];
	FILE *fp;

	strcpy(dir, "md ");
	strcat(dir, dir_i);
	strcat(dir, "\\");
	strcat(dir, dir_ii);
	system(dir);

	if (!(NULL == filename))
	{
		strcpy(dir, dir_i);
		strcat(dir, "\\");
		strcat(dir, dir_ii);
		strcat(dir, "\\");
		strcat(dir, filename);
		fp = fopen(dir, "wb");
		fclose(fp);
	}

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	三级路径目录创建函数
//
// 函数参数:	dir_i:第一级目录名
//				dir_ii:第二级目录名
//				dir_iii:第三级目录名
//				filename:NULL:只创建目录;非NULL:在已创建的目录下创建此文件
//
/////////////////////////////////////////////////////////////////////////////
status build_iii_dir(char *dir_i, char *dir_ii, char *dir_iii, char *filename)
{
	char dir[128];
	FILE *fp;

	strcpy(dir, "md ");
	strcat(dir, dir_i);
	strcat(dir, "\\");
	strcat(dir, dir_ii);
	strcat(dir, "\\");
	strcat(dir, dir_iii);
	system(dir);

	if (!(NULL == filename))
	{
		strcpy(dir, dir_i);
		strcat(dir, "\\");
		strcat(dir, dir_ii);
		strcat(dir, "\\");
		strcat(dir, dir_iii);
		strcat(dir, "\\");
		strcat(dir, filename);
		fp = fopen(dir, "wb");
		fclose(fp);
	}

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	车票费用收取
//
// 函数参数:	this_cost:返回所求费用
//				price_per_km:每公里票价
//				distance:路程
//
/////////////////////////////////////////////////////////////////////////////
status pay_bill(int *this_cost, int price_per_km, int distance)
{
	*this_cost = price_per_km * distance;
	printf("【信息】您必须付 %ld 来预订你需要的车票!\n", *this_cost);
	message(TIP, "需要现金支付!", W);
	{
		WAIT;
	}
	message(INFO, "收款成功!谢谢您的惠顾!", WC);

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	校验参数日历时间与当前时间的顺序
// 
// 函数参数:	chk_tm_pt:待校验的日历时间结构体指针
//
// 函数说明:	若校验时间在当前时间之后,返回OK,否则返回FAIL
//
/////////////////////////////////////////////////////////////////////////////
status check_cal_time(struct tm *ck_tm_pt)
{
	time_t std_current_time;
	time_t std_chk_time;

	std_chk_time = mktime(ck_tm_pt);	// 转换参数日历时间为标准时间
	std_current_time = time(NULL);		// 取得当前时间

	if (std_chk_time < std_current_time)
	{
		return FAIL;
	}

	return OK;
}

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	校验参数标准时间与当前时间的顺序
// 
// 函数参数:	chk_std_tm:待校验的标准时间
//
// 函数说明:	若校验时间在当前时间之后,返回OK,否则返回FAIL
//
/////////////////////////////////////////////////////////////////////////////
status check_std_time(time_t *std_chk_time)
{
	time_t std_current_time;

	std_current_time = time(NULL);

	if (std_chk_time < std_current_time)
	{
		return FAIL;
	}

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	检测子串是否在主串中存在
//
// 函数参数:	main:主串
//				sub:子串
//
/////////////////////////////////////////////////////////////////////////////
status check_string(char *main, char *sub)
{
	if (strstr(main, sub))
	{
		return OK;
	}

	return FAIL;
}


/////////////////////////////////////////////////////////////////////////////
#endif

⌨️ 快捷键说明

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