药物管理系统-C语言02
{
printf("-\n");
int t;
scanf("%d", &t);
struct Drug* p1,*p2;
while (head != NULL && (head->id == t))
{
p1 = head;
head = head->next;
free(p1);
}
if (head == NULL)
return NULL;
p2 = head;
p1 = head->next;
while (p1 != NULL)
{
if (p1->id==t)
{
p2->next = p1->next;
free(p1);
}
else
{
p2 = p1;
}
p1 = p2->next;
}
return head;
}
void Warehousing(struct Drug* head)
{
struct Drug* p=head;
int t, num,flag=0;
printf("-\n");
scanf("%d", &t);
if (t == -1)
return;
while (t != -1)
{
printf("-\n");
scanf("%d", &num);
while (p != NULL)
{
if (p->id == t)
{
p->num += num;
flag = 1;
}
p = p->next;
}
if (flag)
printf("-\n");
else
printf("-\n", t);
scanf("%d", &t);
}
return;
}
void ExWarehousing(struct Drug* head)
{
struct Drug* p = head;
int t, num, flag = 0;
printf("-\n");
scanf("%d", &t);
if (t == -1)
return;
while (t != -1)
{
printf("-\n");
scanf("%d", &num);
while (p != NULL)
{
if (p->id == t&&p->num>=num)
{
p->num -= num;
flag = 1;
}
p = p->next;
}
if (flag)
printf("-\n");
else
printf("-\n", t, t);
scanf("%d", &t);
}
return;
}
void Stock(struct Drug* head)
{
struct Drug* p=head;
int t = 0;
while (p != NULL)
{
if (t == 0)
printf("-\n");
t++;
printf("%d\t%s\t%s\t%d\t%d\t%d\n", p->id, p->name,
p->manufacturer, p->specs, p->price, p->num);
p = p->next;
}
if (t == 0)
printf("-\n");
return;
}
void Save(struct Drug* head)
{
FILE* fp;
struct Drug* p=head;
char wjname[50];
printf("");
scanf("%s", wjname);
if ((fp = fopen(wjname, "w")) == NULL)
{
printf("\n");
return;
}
printf(".\n");
int i = 0;
while(p!=NULL)
{
printf(".\n", ++i);
fprintf(fp, "%d %s %s %s %d %d %d\n",
p->id,p->type,p->name, p->manufacturer,
p->specs,p->price,p->num);
p = p->next;
}
printf("\n");
fclose(fp);
system("pause");
system("cls");
}
void TransferIn(struct Drug* head)
{
char wjname[50];
printf("");
scanf("%s", wjname);
FILE* fp = fopen(wjname, "r");
if (!fp)
{
printf("\n");
return;
}
struct Drug* s;
s = (struct Drug*)malloc(sizeof(struct Drug));
printf("调入中...\n");
int ans = 0;
while (fscanf(fp, "%d%s%s%s%d%d%d", &s->id,s->type,s->name,s->manufacturer,
&s->specs,&s->price,&s->num) != EOF)
{
ans++;
printf(".\n", ans);
if (head == NULL)
{
head = s;
head->next = NULL;
}
else
{
s->next = head;
head = s;
}
s = (struct Drug*)malloc(sizeof(struct Drug));
}
printf("\n");
system("pause");
fclose(fp);
system("cls");
}