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

📄 press.c

📁 书店管理系统
💻 C
📖 第 1 页 / 共 3 页
字号:
                      a_book->kind=temp.kind;
                      a_book->cursor_name=temp.cursor_name;
                      a_book->name_id=temp.name_id;
                      a_book->lib_num=num;
                      a_book->f_y_n=temp.f_y_n;
                      a_book->g_y_n=temp.g_y_n;    
                      
                      fseek(fp,-sizeof(struct book),1);
                      fwrite(&temp,sizeof(struct book),1,fp);
                      break;
                      
                }   
                case  'E':
                {    
                      for (i=0;i<7;i++)
                      {
                          if (strcmp(temp.kind,press_store[2].kind[i])==0)
                          {
                             break;
                          }
                      }
                      if(i==7)
                      {
                          printf("error in E!\n");
                          return NULL;
                      }
                      //库存不足
                      if (temp.lib_num<num)
                      { 
                        //现存部分全部采购
                        num=temp.lib_num; 
                        temp.lib_num=0;                                           
                        //转再版
                        repress(press_id,cursor_name,num-temp.lib_num);

                        //再版后通知书店来订购
                        store_scrimbe(store_id,press_id,cursor_name,press_store[2].scrimbe_num[i]);
                        
                      }
                      else
                      {
                         temp.lib_num=temp.lib_num-num; 	
                      }
                      
                      a_book->press_id=temp.press_id;
                      a_book->kind=temp.kind;
                      a_book->cursor_name=temp.cursor_name;
                      a_book->name_id=temp.name_id;
                      a_book->lib_num=num;
                      a_book->f_y_n=temp.f_y_n;
                      a_book->g_y_n=temp.g_y_n;    
                      
                      fseek(fp,-sizeof(struct book),1);
                      fwrite(&temp,sizeof(struct book),1,fp);
                      break;
                      
                } 
                default :
                {
                	  printf("this book_store has not licence!!\n");
                }	  
         }//end switch 
         fclose(fp);
         if (work!=NULL)
         {
            fprintf(work,"%c has scrimbe %d %s books from %c press\n",store_id,num,a_book->kind,press_id);
            fclose(work);
         }
         return a_book;
      }//end if
      else if (press_id=='B')
      {
           fp=fopen("book_b","ab+");
           if (fp==NULL)
           {
              printf("%c store cannot open book_b.txt in function scrimber_press\n",store_id);
              pthread_exit(NULL);
           }
           fseek(fp,position,0);
           fread(&temp,sizeof(struct book),1,fp);
           switch (store_id)
           {
                  case  'C':
                  {    
                       int i;
                       for (i=0;i<3;i++)
                       {
                           if (strcmp(temp.kind,press_store[0].kind[i])==0)
                           {
                              break;
                           }
                       }
                       
                       if (i==3)
                       {
                          printf("error in C!\n");
                          return NULL;
                       }
                       
                       //库存不足
                       if (temp.lib_num<num)
                       { 
                         //现存部分全部采购
                         num=temp.lib_num; 
                         temp.lib_num=0;                                           
                         //转再版
                         repress(press_id,cursor_name,num-temp.lib_num);

                         //再版后通知书店来订购
                         store_scrimbe(store_id,press_id,cursor_name,press_store[0].scrimbe_num[i]);
                        
                      }
                      else
                      {
                         temp.lib_num=temp.lib_num-num; 	
                      }
                      
                      a_book->press_id=temp.press_id;
                      a_book->kind=temp.kind;
                      a_book->cursor_name=temp.cursor_name;
                      a_book->name_id=temp.name_id;
                      a_book->lib_num=num;
                      a_book->f_y_n=temp.f_y_n;
                      a_book->g_y_n=temp.g_y_n;    
                      
                      fseek(fp,-sizeof(struct book),1);
                      fwrite(&temp,sizeof(struct book),1,fp);
                      break;
                      
                 }
                 case  'D':
                 {    
                       int i;
                       for (i=0;i<4;i++)
                       {
                           if (strcmp(temp.kind,press_store[1].kind[i])==0)
                           {
                              break;
                           }
                       }
                       
                       if (i==4)
                       {
                          printf("error in D!\n");
                          return NULL;
                       }
                       
                       //库存不足
                      if (temp.lib_num<num)
                      { 
                        //现存部分全部采购
                        num=temp.lib_num; 
                        temp.lib_num=0;                                           
                        //转再版
                        repress(press_id,cursor_name,num-temp.lib_num);

                        //再版后通知书店来订购
                        store_scrimbe(store_id,press_id,cursor_name,press_store[1].scrimbe_num[i]);
                      }
                      else
                      {
                           temp.lib_num=temp.lib_num-num; 	
                      }
                      a_book->press_id=temp.press_id;
                      a_book->kind=temp.kind;
                      a_book->cursor_name=temp.cursor_name;
                      a_book->name_id=temp.name_id;
                      a_book->lib_num=num;
                      a_book->f_y_n=temp.f_y_n;
                      a_book->g_y_n=temp.g_y_n;    

                      fseek(fp,-sizeof(struct book),1);
                      fwrite(&temp,sizeof(struct book),1,fp);
                      break;
                      
                 }   
                 case  'E':
                 {    
                       int i;
                       for (i=0;i<7;i++)
                       {
                           if (strcmp(temp.kind,press_store[2].kind[i])==0)
                           {
                              break;
                           }
                       }
                       
                       if (i==7)
                       {
                          printf("error in E!\n");
                          return NULL;
                       }
                       
                       //库存不足
                      if (temp.lib_num<num)
                      { 
                        //现存部分全部采购
                        num=temp.lib_num; 
                        temp.lib_num=0;                                           
                        //转再版
                        repress(press_id,cursor_name,num-temp.lib_num);

                        //再版后通知书店来订购
                        store_scrimbe(store_id,press_id,cursor_name,press_store[2].scrimbe_num[i]);
                                               
                      }
                      else
                      {
                        temp.lib_num=temp.lib_num-num; 	
                      }
                      
                      a_book->press_id=temp.press_id;
                      a_book->kind=temp.kind;
                      a_book->cursor_name=temp.cursor_name;
                      a_book->name_id=temp.name_id;
                      a_book->lib_num=num;
                      a_book->f_y_n=temp.f_y_n;
                      a_book->g_y_n=temp.g_y_n;    

                      fseek(fp,-sizeof(struct book),1);
                      fwrite(&temp,sizeof(struct book),1,fp);
                      break;
                      
                 }
                 default :
                 {
                	   printf("this book_store has not licence!!\n");
                 }	  
           }//end switch
           fclose(fp);
           if (work!=NULL)
           {
              fprintf(work,"%c has scrimbe %d %s books from %c press\n",store_id,num,a_book->kind,press_id);
              fclose (work);
           }      
           return a_book;
      }//end else if
  
}
 
//出版社的再版
void repress(char press_id,int cursor_name,int num)
{
     long position=cursor_name * sizeof(struct book);
     struct book temp;
     FILE * work;
     FILE * fp;
     if (press_id=='A')	
     { 
        fp=fopen("book_a","ab+");
        if (fp==NULL)
        {
             printf("%c store cannot open book_a.txt in function search_press\n",press_id);
             pthread_exit(NULL);
        }
     	fseek(fp,position,0);
        fread(&temp,sizeof(struct book),1,fp);
        if (num<=500)
        {
        	 temp.lib_num=temp.lib_num+500;
        }
        else 
        {
             num=num/1000+1;        	
             temp.lib_num=temp.lib_num+num*1000;	
        }	
        fseek(fp,-sizeof(struct book),1);
        fwrite(&temp,sizeof(struct book),1,fp);
        fclose(fp);
     	
     }
     else if (press_id=='B')
     {
        fp=fopen("book_b","ab+");
        if (fp==NULL)
        {
             printf("%c press  cannot open book_a.txt in function search_press\n",press_id);
             pthread_exit(NULL);
        }
        fseek(fp,position,0);
        fread(&temp,sizeof(struct book),1,fp);
        if (num<=500)
        {
        	 temp.lib_num=temp.lib_num+500;
        }
        else 
        {
             num=num/1000+1;        	
             temp.lib_num=temp.lib_num+num*1000;	
        }	
        fseek(fp,-sizeof(struct book),1);
        fwrite(&temp,sizeof(struct book),1,fp);
        fclose(fp);
     }
     if ((work=fopen("work.txt","a+"))!=NULL)
     {
        fprintf(work,"%c press has repressed %d %s books\n",press_id,num,temp.kind);
        fclose(work);
     }		  
}

⌨️ 快捷键说明

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