大一下学期---财务管理系统---c部分

大一下财务管理系统----纪念博

今早做java设计,突然想起上学期c语言做了一个财务管理系统用dll实现在wpf中的。
图片大小不一,是因为有些是文档里的,一些事以前做的时候的截图
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
大概是这样的东西,但是源码丢失了= =,有点遗憾,毕竟算是我第一个自己一个人开发的项目,也学了很多东西,算是让我爱上编程的一次经历。剩下的只有c的部分的代码,因为交的文档里有这部分代码

以下贡献C的dll部分

因为是大一写的,水平有点低,大家可以参考一下,但是不要模仿
自己又仔细看了下,真的写的烂,但是我是不会去改的,这是我的第一个项目,就像自己的孩子一样,再丑也不会逼他整容。

头文件

//DLL.h
#pragma once

typedef struct Finance{
	char* time;
	char* money;
	int  number;
	struct Finance *next;
}Finance;

__declspec (dllexport)char* Output();
//__declspec (dllexport)int add(int a,int b);
__declspec (dllexport)int save(char* data, char* file_name);
__declspec (dllexport)int load(char* str, char* file_name);
__declspec (dllimport)int save_data(char* time ,double money);


后端文件

账户的注册功能

int MakeAccount(char * Account ,char *Password) {
	FILE *fp;
	char CmpAccount[20];
	char CmpPassword[20];
	if ((fp = fopen("AccountSave.txt", "rb+")) == NULL)//若已有文件则以读的打开
	{
		if ((fp = fopen("AccountSave.txt", "wb+")) == NULL){ //若没文件则以写的形式打开
			return 1;
		}
		fprintf(fp, "账号     密码");
	}
	fseek(fp, 0L, 0); 
	fscanf(fp, "%s %s ", str_array[0], str_array[1]);
	while(!feof(fp))
	{
		
		fscanf(fp," %s %s ", CmpAccount, CmpPassword); 
		if (strcmp(CmpAccount, Account) == 0) {
			fclose(fp);
			return 2;
			break;
		} 
	}
	fseek(fp, 0L, 2);
	fprintf(fp,"\r\n");
	fprintf(fp," %s %s ", Account, Password);
	fclose(fp);
	return 0;
}

2 账户的登录功能

int LoadIn(char * Account, char *Password) {
	FILE *fp;
	char CmpAccount[20];
	char CmpPassword[20];
	if ((fp = fopen("AccountSave.txt", "rb")) == NULL)
	{
		if ((fp = fopen("AccountSave.txt", "wb+")) == NULL) {
			return 1;
		}
		fprintf(fp, "账号     密码");
	}
	
	fseek(fp, 0, 0);
	fscanf(fp, "%s%s ", str_array[0], str_array[1]);
	while(!feof(fp)){
		fscanf(fp,"%s %s ",CmpAccount,CmpPassword);
		if (strcmp(Account, CmpAccount) == 0) {
			if (strcmp(Password, CmpPassword) == 0) {
				fclose(fp);
				return 0; 
				break;
			}
		}
	}
	fclose(fp);
	return 1;
	}

3 创建账户存档功能

int SetSaveFile(char* FileName) {

	FILE *fp;


	if ((fp = fopen(FileName, "rb+")) == NULL)
	{
		if ((fp = fopen(FileName, "wb+")) == NULL) {	
			return 1;
		}
		fprintf(fp, "流水号      时间      收入金额      支出金额      总金额\r\n");
	}
	

	fclose(fp);

	return 0;
}

4 信息的添加功能

int NewData(char* FileName,double Input,double Output,double AllMoney,char* time){
	
	FILE *fp;

	if ((fp = fopen(FileName,"rb+")) == NULL)
	{
		return 1;
	}

	fseek(fp, 0, 0);
	fscanf(fp, "%s%s%s%s%s", str_array[0], str_array[1], str_array[2], str_array[4], str_array[5]);
	fgetc(fp);
	fgetc(fp);
	while (1) {
		if (feof(fp)) break;
		fscanf(fp,"%d%s%lf%lf%lf", &finance.number, finance.time,&finance.Input,&finance.Output,&finance.AllMoney);
		fgetc(fp);
		fgetc(fp);
	}
	
	number = finance.number + 1;

	fseek(fp, 0, 2);

	fprintf(fp," %d %s %.1lf %.1lf %.1lf\r\n", number, time, Input, Output, AllMoney);

	fclose(fp);

	return 0;
}

5 信息的查看功能

int LoadData(char *FileName, char *Loaddata){

	FILE *fp;

	char str[20];

	char temp[5][100];

	if ((fp = fopen(FileName,"rb"))== NULL) {
		return 0;
	}
	else{
		fscanf(fp, "%s%s%s%s%s", str_array[0], str_array[1], str_array[2], str_array[3], str_array[4]);
		fgetc(fp);
		fgetc(fp);
		
		int i;

		while (1) {
			
			fscanf(fp, "%s%s%s%s%s", temp[0], temp[1],temp[2], temp[3], temp[4]);
			fgetc(fp);
			fgetc(fp);
			if (feof(fp)) break;
			switch (strlen(temp[1]))
			{
			case 8: strcat(temp[1], "    "); break;
			case 9: strcat(temp[1], "  "); break;
			default: break;
			}



			for (i = 2; i <= 4;i++) {
				switch (strlen(temp[i]))
				{
				case 3: strcat(temp[i], "          "); break;
				case 4: strcat(temp[i], "        "); break;
				case 5: strcat(temp[i], "      "); break;
				case 6: strcat(temp[i], "    "); break;
				case 7: strcat(temp[i], "  "); break;
				default: break;
				}
			}
			for (i = 1; i <= 3; i++) {
				strcat(temp[i], "         ");
			}
	
			strcpy(str, "     ");
			strcat(str, temp[0]);
			strcpy(temp[0], str);
			strcat(temp[0], "         ");

			for (i = 1; i <= 3; i++) {
				strcat(temp[0], temp[i]);
			}

			strcat(temp[4], "\r\n");

			strcat(temp[0], temp[4]);

			strcat(Loaddata, temp[0]);
			i++;
		}
	}
	return  strlen(Loaddata);
}

6 信息的删除功能

int DeleteData(char *Filename, int DeleteNum) {
	
	FILE *fp1,*fp2;
	Finance *info,*before,*head,*last;
	int i = 1;
	int j = 1;

	info = before = head  = last  = NULL;
	head = (Finance*)malloc(sizeof(Finance));

	head->next = last;


	fp1 = fopen(Filename, "rb");
	fseek(fp1, 0, 0);
	fscanf(fp1, "%s%s%s%s%s", str_array[0], str_array[1], str_array[2], str_array[3], str_array[4]);
	fgetc(fp1);
	fgetc(fp1);
	while (1) {
		if (feof(fp1)) break;
		info = (Finance *)malloc(sizeof(Finance));
		fscanf(fp1, "%d %s %lf %lf %lf ", &info->number, info->time, &info->Input, &info->Output, &info->AllMoney);

		info->next = NULL;
		if (info->number != DeleteNum) info->number = j++;


		if (i++ == 1) {
			head->next = info;
		}
		else {
			last->next = info;
		}
		last = info;
	}

	fclose(fp1);


	info = head->next;
	before = head;

	while (info != NULL) {
		if (info->number == DeleteNum) {
			before->next = info->next;
			break;
		}
		else {
			before = info;
			info = info->next;
		}
	}

	info = head->next;

	fp2 = fopen(Filename,"wb"); //重写存档
	fseek(fp2, 0, 0);
	fprintf(fp2, "流水号      时间      收入金额      支出金额      总金额\r\n");
	
	while (info != NULL) {
		fprintf(fp2, " %d %s %.1lf %.1lf %.1lf \r\n", info->number, info->time, info->Input, info->Output, info->AllMoney);
		info = info->next;
	}
	
	fclose(fp2);


	while (head != NULL) {
		info = head;
		head = head->next;
		free(info);
	}

	return 0;
}

7 信息的插入功能

int InsertData(char *Filename, int InsertNum, char* time, double input,double output,double allmoney) {

	FILE *fp1, *fp2;
	Finance *info, *before, *head, *last,*new;
	int i = 1;
	int j = 1;

	info = before = head = last = new = NULL;
	head = (Finance*)malloc(sizeof(Finance));

	head->next = last;
	

	fp1 = fopen(Filename, "rb");
	fseek(fp1, 0, 0);
	fscanf(fp1, "%s%s%s%s%s", str_array[0], str_array[1], str_array[2], str_array[3], str_array[4]);
	fgetc(fp1);
	fgetc(fp1);
	while (1) {
		if (feof(fp1)) break;
		info = (Finance *)malloc(sizeof(Finance));
		fscanf(fp1, "%d %s %lf %lf %lf ", &info->number, info->time, &info->Input, &info->Output, &info->AllMoney);

		info->next = NULL;
		if (info->number == InsertNum) {
			j = j + 1;
		}
		info->number = j++;

		if (i++ == 1) {
			head->next = info;
		}
		else {
			last->next = info;
		}
		last = info;
	}

	fclose(fp1);


	info = head->next;
	before = head;

	while (info != NULL) {
		if ((info->number - 1) == InsertNum) {
			new = (Finance *)malloc(sizeof(Finance));
			new->number = InsertNum;
			strcpy(new->time, time);
			new->Input = input;
			new->Output = output;
			new->AllMoney = allmoney;
			new->next = before->next;
			before->next = new;
			break;
		}
		else {
			before = info;
			info = info->next;
		}
	}

	info = head->next;

	fp2 = fopen(Filename, "wb"); //重写存档
	fseek(fp2, 0, 0);
	fprintf(fp2, "流水号      时间      收入金额      支出金额      总金额\r\n");

	while (info != NULL) {
		fprintf(fp2, " %d %s %.1lf %.1lf %.1lf \r\n", info->number, info->time, info->Input, info->Output, info->AllMoney);
		info = info->next;
	}

	fclose(fp2);


	while (head != NULL) {
		info = head;
		head = head->next;
		free(info);
	}

	return 0;
}

8 信息的排序功能

double GetAllmoney(char *filename) {

	FILE *fp;
	double Allmoney = 0;
	fp = fopen(filename, "rb");
	if (fp == NULL) return 1;
	fseek(fp, 0, 0);
	fscanf(fp, "%s%s%s%s%s", str_array[0], str_array[1], str_array[2], str_array[3], str_array[4]);
	fgetc(fp);
	fgetc(fp);
	while (1) {
		if (feof(fp)) break;
		fscanf(fp, "%d %s %lf %lf %lf ", &savefinance.number, savefinance.time, &savefinance.Input, &savefinance.Output, &savefinance.AllMoney);
		Allmoney += savefinance.AllMoney;
	}
	return Allmoney;
}

9 信息的获取余额功能

double GetAllmoney(char *filename) {

	FILE *fp;
	double Allmoney = 0;
	fp = fopen(filename, "rb");
	if (fp == NULL) return 1;
	fseek(fp, 0, 0);
	fscanf(fp, "%s%s%s%s%s", str_array[0], str_array[1], str_array[2], str_array[3], str_array[4]);
	fgetc(fp);
	fgetc(fp);
	while (1) {
		if (feof(fp)) break;
		fscanf(fp, "%d %s %lf %lf %lf ", &savefinance.number, savefinance.time, &savefinance.Input, &savefinance.Output, &savefinance.AllMoney);
		Allmoney += savefinance.AllMoney;
	}
	return Allmoney;
}

10 数据文件的读/写功能

void FileChange(char*readfile, char *savefile) {
	FILE *fp, *savefp;
	fp = fopen(readfile, "rb");
	savefp = fopen(savefile, "wb");
	fseek(fp, 0, 0);
	fseek(savefp, 0, 0);
	fscanf(fp, "%s%s%s%s%s", str_array[0], str_array[1], str_array[2], str_array[3], str_array[4]);
	fgetc(fp);
	fgetc(fp);
	fprintf(savefp, "流水号      时间      收入金额      支出金额      总金额\r\n");
	while (1) {
		if (feof(fp)) break;
		fscanf(fp, "%d %s %lf %lf %lf ", &savefinance.number, savefinance.time, &savefinance.Input, &savefinance.Output, &savefinance.AllMoney);
		
		fprintf(savefp, " %d %s %.1lf %.1lf %.1lf \r\n", savefinance.number, savefinance.time, savefinance.Input, savefinance.Output, savefinance.AllMoney);
	}
	fclose(fp);
	fclose(savefp);
}

题外话

因为没有了wpf也没有了实现的机会了,有点难受,以后再也不乱搞BIOS了,就是弄了BIOS才重装系统把文件弄没了。等JAVA版做好了,会把JAVA的源码发出来的,不过要等我们成绩下来先。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值