#include <stdio.h>
#include <string.h>
#include <conio.h>
#define SIZE 300
struct product
{char id[3];
char name[10];
char gysh[10];
char lb[11];
char dwsl[11];
char dj[10];
char kcp[5];
char dgl[6];
char zdgl[6];
char zz[5];}
pro[SIZE];
void myprint();
void product();
void myprint1();
void mycreate();
void mydisplay();
void mysearch();
void sch_num (FILE *fp);
void mymodify();
void myadd();
void mysave();
void mydelete();
void del_num(FILE *fp);
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include<stdio.h>
#include<stdlib.h>
#include <conio.h>
#include <malloc.h>
#define NULL 0
void cliread();
void clichoose();
void cliprintmenu();
void clidisplay();
void cliadd();
void clisearch();
void climodify();
void clireturn();
void clidel();
typedef struct client
{
char id[8]; /*客户编号*/
char name[25]; /*客户名称*/
struct client *next;
}CLI;
FILE *fpc;
CLI *Chead;
int transfer1(char *p,int n)
{int i,j;
long sum=0,qu;
for(i=0;i<n;i++)
{for(j=n-1-i,qu=1;j>0;j--)
qu=10*qu;
sum=sum+(*(p+i)-'0')*qu;}
return(sum+1);}
/*float transfer2(char *ca)
{float val,power,sum; int i=0,j;char s[20];
printf("%s\n",*ca);
for(i=0,j=0;i<13;i++)
if(*(ca+i)='.'||(*(ca+i)>='0'&&*(ca+i)<='9')) s[j++]=*(ca+i);
s[j]='\0';j=0;
for(val=0;s[j]>='0'&&s[j]<='9';j++)
val=10*val+s[j]-'0';
if(s[j]=='.') j++;
for(power=1;s[j]>='0'&&s[j]<='9';i++)
{val=10*val+s[j]-'0'; power*=10;}
sum=val/power;
printf("%f\n",sum);
}*/
void print()
{FILE *pf;
int n,i,j,l,cout=0;
long k;
char *ps;
struct order *p;
pf=fopen("d:\\dzs\\order3.txt","rb");
fseek(pf,0l,2);
k=ftell(pf); l=28; printf("k1=%ld\n",k);ps=(char *)malloc(k);
fseek(pf,0l,0); fread(ps,1,k,pf);
printf(" order\n");
for(i=0;i<k;i=i+28)
{for(j=i;j<26+i;j++)
putchar(*(ps+j));
printf("\n");}
printf("\n");
printf(" ****请按回车****\n");
getchar();
fclose(pf);
pf=fopen("d:\\dzs\\ordet.txt","rb");
fseek(pf,0l,2);
k=ftell(pf);printf("k2=%ld\n",k); l=44; ps=(char*)malloc(k);
fseek(pf,0l,0); fread(ps,1,k,pf);
printf(" order detail\n");
for(i=0;i<k;i=i+44)
{for(j=i;j<42+i;j++)
putchar(*(ps+j));
printf("\n");}
printf("\n");
printf(" ****请按回车****\n");
}
void add()
{struct order{a[28];};
struct ordet{a[44];};
struct order *or;
struct ordet *ot;
char *temp,*or1,*or2;
int i;
long number;
FILE *fp1,*fp2;
if((fp1=fopen("d:\\dzs\\order3.txt","rb+"))==NULL)
printf("error\n");
fseek(fp1,-28l,2);
temp=(char *)malloc(6);
for(i=0;i<5;i++)
*(temp+i)=fgetc(fp1);
*(temp+i)='\0';
number=transfer1(temp,5);
printf("请输入订单信息:\n");
printf("您将使用以下客户ID(请按以下方式输入:五个字符、三个空格):%ld\n",number);
gets(or1);
for(i=26;i<28;i++) *(or1+i)='\0';
fclose(fp1);
if((fp1=fopen("d:\\dzs\\order3.txt","ab+"))==NULL)
printf("error\n");
fwrite(or1,1,28,fp1);
fclose(fp1);
printf("please input order detail data:\n");
printf("please write down your orderID:%d\n",number);
printf("input orderID(5 bits and 7 space)\n");
printf("input pro_name(13 bits)\n");
printf("input price(13bits)\n");
printf("input amount(4bits):\n");
or2=(char *)malloc(44);
gets(or2);
for(i=42;i<44;i++) *(or2+i)='\0';
if((fp2=fopen("d:\\dzs\\ordet.txt","ab+"))==NULL)
printf("error\n");
fwrite(or2,1,44,fp2);
fclose(fp2);printf(" Sucess!\n");
print();
getchar();
clrscr();
}
void search()
{FILE *p1,*p2;
int i,j,tag1=0,tag2=0,l1,l2;
long k1,k2;
int num[20];
char *ex,*ps1,*ps2;
struct order {char ord[5];
char spa1[3];
char cus[5];
char spa2[3];
char dat[12];};
struct ordet {char ord[5];
char spa[7];
char pro[13];
char pri[13];
char amo[6];};
struct order *or;
struct ordet *ot;
if((p1=fopen("d:\\dzs\\order3.txt","rb"))==NULL)
printf("error\n");
printf("请输入客户ID:\n");
ex=(char *)malloc(6);gets(ex);clrscr();
fseek(p1,0l,2);k1=ftell(p1);ps1=(char *)malloc(k1);
fseek(p1,0l,0);fread(ps1,1,k1,p1);l1=k1/28;
for(i=0;i<l1;i++)
{*(ps1+26+i*28)='\0';*(ps1+27+i*28)='\0';*(ps1+5+i*28)='\0';
*(ps1+7+i*28)='\0';*(ps1+13+i*28)='\0';*(ps1+15+i*28)='\0';}
or=(struct order *)ps1;
for(i=0,j=0;i<l1;i++)
if(strcmp(ex,(or+i)->cus)==0) {tag1=tag1+1;num[j++]=i;} fclose(p1);
if(tag1!=0)
{if((p2=fopen("d:\\dzs\\ordet.txt","rb"))==NULL)
printf("error\n");
fseek(p2,0l,2);k2=ftell(p2);ps2=(char *)malloc(k2);
fseek(p2,0l,0);fread(ps2,1,k2,p2);l2=k2/44;
for(i=0;i<l2;i++)
{*(ps2+42+i*44)='\0';*(ps2+43+i*44)='\0';*(ps2+5+i*44)='\0';
*(ps2+11+i*44)='\0';*(ps2+24+i*44)='\0';*(ps2+32+i*44)='\0';*(ps2+37+i*44)='\0';}
ot=(struct ordet *)ps2;
printf("********************************************************************************\n");
printf(" 您的订单和订单明细如下\n");
printf("\n");
printf("********************************************************************************\n");
for(j=0;j<tag1;j++)
for(i=0;i<l2;i++)
if(strcmp((ot+i)->ord,(or+num[j])->ord)==0)
{printf("%s %s %s %s %s %s %s\n",(or+num[j])->ord,(or+num[j])->cus,(or+num[j])->dat,(ot+i)->pro,(ot+i)->pri,(ot+i)->amo);
tag2=tag2+1;}
if(tag2==0) printf("您没有订单\n");
fclose(p2);}
else if(tag1==0) printf("客户ID不存在\n");
getchar();
clrscr();
}
void calculate()
{FILE *p1,*p2;
int i,j,t,m,tag1=0,tag2=0,l1,l2;
long k1,k2;
int num[20];
char *ex,*ps1,*ps2,*tt;
float sum=0,a,b;
struct order {char ord[5];
char spa1[3];
char cus[5];
char spa2[3];
char dat[12];};
struct ordet {char ord[5];
char spa[7];
char pro[13];
char pri[13];
char amo[6];};
struct order *or;
struct ordet *ot;
if((p1=fopen("d:\\dzs\\order3.txt","rb"))==NULL)
printf("error\n");
printf("请输入客户ID:\n");
ex=(char *)malloc(6);gets(ex);clrscr();
fseek(p1,0l,2);k1=ftell(p1);ps1=(char *)malloc(k1);
fseek(p1,0l,0);fread(ps1,1,k1,p1);l1=k1/28;
for(i=0;i<l1;i++)
{/**(ps1+26+i*28)='\0';*/*(ps1+27+i*28)='\0';*(ps1+5+i*28)='\0';
*(ps1+7+i*28)='\0';*(ps1+13+i*28)='\0';*(ps1+15+i*28)='\0';/**(ps1+24+i*28)='\0';*/}
or=(struct order *)ps1;
for(i=0,j=0;i<l1;i++)
if(strcmp(ex,(or+i)->cus)==0) {tag1=tag1+1;num[j++]=i;} fclose(p1);
if(tag1!=0)
{if((p2=fopen("d:\\dzs\\ordet.txt","rb"))==NULL)
printf("error\n");
fseek(p2,0l,2);k2=ftell(p2);ps2=(char *)malloc(k2);
fseek(p2,0l,0);fread(ps2,1,k2,p2);l2=k2/44;
for(i=0;i<l2;i++)
{*(ps2+42+i*44)='\0';*(ps2+43+i*44)='\0';*(ps2+5+i*44)='\0';
*(ps2+11+i*44)='\0';*(ps2+24+i*44)='\0';*(ps2+32+i*44)='\0';*(ps2+37+i*44)='\0';}
ot=(struct ordet *)ps2;
printf("********************************************************************************\n");
printf(" 您的订单和订单明细如下\n");
printf("\n");
printf("********************************************************************************\n");
for(j=0;j<tag1;j++)
for(i=0;i<l2;i++)
if(strcmp((ot+i)->ord,(or+num[j])->ord)==0)
{printf("%s %s %s %s %s %s %s\n",(or+num[j])->ord,(or+num[j])->cus,(or+num[j])->dat,(ot+i)->pro,(ot+i)->pri,(ot+i)->amo);
b=atof((ot+i)->amo);a=atof((ot+i)->pri);
sum=sum+a*b;
tag2=tag2+1;}
if(tag2==0) printf("您没有订单\n");
else {printf("\n");
printf("\n");
printf("\n");
printf("总成本为 %f\n",sum);}
fclose(p2);}
else if(tag1==0) printf("客户ID不存在\n");
getchar();
clrscr();
}
void menu()
{char x;
do
{printf("\n 订单菜单 \n");
printf("