Пример #1
0
int edit_product(int index)
{
  //show product
  print_product(good[index]);
  
  struct goods tmp = good[index];


  int q = ask_question_char("\nVad vill du redigera?\n[N]amn\n[B]eskrivning\n[P]ris\n[L]agerhylla\nAn[t]al\n\n[a]vbryt","NBPLta");
  switch (q)
    {
    case 'N': 
      printf("Nuvarande namn:%s\n", good[index].name);
      char *new_name = ask_question_string("Nytt namn:",100);
      free(good[index].name);
      good[index].name = new_name;
      break;
      
    case 'B':
      printf("Nuvarande beskrivning:%s\n", good[index].desc);
      char *new_desc = ask_question_string("Ny beskrivning:",100);
      free(good[index].desc);
      good[index].desc = new_desc;
      break;
      
    case 'P':
      printf("Nuvarande pris:%d\n", good[index].price);
      int new_price = ask_question_int("Nytt pris:");
      good[index].price = new_price;
      break;
      
    case 'L':
      printf("Nuvarande lagerhylla:%s\n", good[index].place);
      char *new_place = ask_for_place("Ny lagerhylla:");
      free(good[index].place);
      good[index].place = new_place;
      break;
      
    case 't':
      printf("Nuvarande antal:%d\n", good[index].count);
      int new_count = ask_question_int("Nytt antal:");
      good[index].count = new_count;
      break;
      
    case 'a':
      
      break;
      
    default:
      edit_product(index);
      break;   
    }
  
  undo.copy = tmp;
  undo.merch = &good[index];
  undo.type = 3;
  return 0;
}
Пример #2
0
void edit_product_interf()
{
  puts("Redigera en vara");
  
  list_products();
  int s = ask_question_int("Välj vara:");
  edit_product(s-1);
}
Пример #3
0
void add_product_interf()
{
  puts("\n...Lägga till produkt...");
  char *name  =   ask_question_string("Namn: ",100);
  char *desc  =   ask_question_string("Beskrivning: ",100);
  char *place =   ask_for_place("Lagerhylla: ");

  int price = ask_question_int("Pris:");
  int count = ask_question_int("Antal:");
     
  puts("\n\nDin produkt:");
  printf("Namn: %s \n Beksrivning:%s \n Lagerhylla:%s \n Pris:%d \n Antal:%d \n", name, desc, place, price, count);
  char q = ask_question_char("Vill du lägga till varan? [J]a,[N]ej,[R]edigera","JNR");

  struct goods god=
    {
      .name  = name,
      .desc  = desc,
      .place = place,
      .price = price,
      .count = count
    };
  
  switch (q)
    {
    case 'J': 
      add_good(god);
      break;

    case 'N':
      free(name);
      free(desc);
      free(place);
      break;

    case 'R':
      add_good(god);
      edit_product(amount-1);
      break;
    }   

  // free(name);
  // free(desc);
  // free(place);
  
}
Пример #4
0
void add_goods(db_t *db){
  ware_t ware;
  printf("=================================\n");
  ask_question_string("Ange namnet på varan: ", ware.name);
  ask_question_string("Beskriv varan: ", ware.description);
  ware.price = ask_question_int("Ange priset för varan: ");
  ware.amount = ask_question_int("Ange antal: ");

  int status = 2;
  while(status == 2){
    ware.storage_location = (storage_location_t){.character=ask_question_char("Ange hylla: "),
						 .number=ask_question_int("Ange plats: ")};
    status = db_search_location(db, &ware);
      if(status == 2)
	puts("Platen är upptagen");
  }
 
  if(status != 1)
    db_insert(db, ware);
}

void remove_goods_aux(db_t *db, int index){
  if(db->current_index == index+1){
    db->copy_flag = REMOVE;
    db->current_index--;
    db->copy_index = db->current_index;
  }
  else{
    db->copy_flag = REMOVE;
    db->copy_ware = db->wares[index];
    db->copy_index = index;

    for(int c=index; c<db->current_index; c++){
      db->wares[c] = db->wares[c+1];
    }
    db->current_index--;
  } 
}

void remove_goods(db_t *db){
  remove_goods_aux(db, ask_question_int("Ange ett nummer: _")-1);
}
Пример #5
0
void edit_goods(db_t *db){
  bool running = true;
  int value = ask_question_int("Ange numret på den vara du vill ändra:_ ");

  if(value > db->current_index || value < 0){
    puts("Varan finns ej.");
    return;
  }

  print_ware(&db->wares[value-1]);

  db->copy_flag = EDIT;
  db->copy_ware = db->wares[value-1];
  db->copy_index = value-1;

  while(running){
    char answer = ask_question_char("Välj vad du vill redigera\n[N]amn\n[B]eskrivning\n[P]ris\n[L]agerhylla\nAn[t]al\neller [A]vbryt:_");
    switch(answer){
    case 'N':
      printf("Nuvarande namn: %s\n", db->wares[value-1].name);
      ask_question_string("Nytt namn:_", db->wares[value-1].name);
      break;
    case 'B':
      printf("Nuvarande beskrivning: %s\n", db->wares[value-1].description);
      ask_question_string("Ny beskrivning:_", db->wares[value-1].description);
      break;
    case 'P':
      printf("Nuvarande pris: %i\n", db->wares[value-1].price);
      db->wares[value-1].price = ask_question_int("Nytt pris:_");
      break;
    case 'L':
      printf("Nuvarande lagerhylla: %c%i\n", db->wares[value-1].storage_location.character, db->wares[value-1].storage_location.number);

      int status = 2;
      while(status == 2){
	db->wares[value-1].storage_location = (storage_location_t){.character=ask_question_char("Ange hylla: "),
								   .number=ask_question_int("Ange plats: ")};
	status = db_search_location(db, &db->wares[value-1]);
	if(status == 2){
	  puts("Platsen är upptagen");
	}
	else if(status == 1){
	  puts("Varan finns redan på den platsen, antalet ökat.");
	  remove_goods_aux(db, (value-1));
	}
      }
      break;
	
    case 'T':
      printf("Nuvarande antal: %i\n", db->wares[value-1].amount);
      db->wares[value-1].amount = ask_question_int("Nytt antal:_");
      break;
    case 'A': running = false;
      break;
    }
  }
}

void undo_goods(db_t *db){
  if(db->copy_flag == UNCHANGED){
    puts("Du måste göra något innan du kan ångra.");
  }
  else if(db->copy_flag == ADD){
    printf("Ångrade %s.\n", db->wares[db->copy_index].name);
    remove_goods_aux(db, db->copy_index);
  }
  else if(db->copy_flag == EDIT){
    printf("Ångrade %s.\n", db->wares[db->copy_index].name);
    db->wares[db->copy_index] = db->copy_ware;
  }
  else if(db->copy_flag == REMOVE){
    printf("Ångrade %s.\n", db->copy_ware.name);
    if(db->copy_flag == db->current_index)
      db->current_index++;
    else{
      for(int c=db->current_index; c>db->copy_index; c--){
	db->wares[c] = db->wares[c-1];
      }
      db->wares[db->copy_index] = db->copy_ware;
      db->current_index++;
    }
  }

  db->copy_flag = UNCHANGED;
}

void list_goods(db_t *db){
  bool running = true;
  int  index = 0;
  char answer;
  bool next_page_exists;
  while(running){
    next_page_exists = db_print_threaded(db, index, index + 19);    
    
    answer = ask_question_char("=================================\n[V]älj ett nummer för att visa mer information om varan.\nVisa [m]er\n[A]vsluta.\n_ ");
    
    if(answer == 'A'){
      running = false;
    }
    else if(answer == 'M'){
      if(next_page_exists)
	index += 20;
      else
	puts("Finns ej fler varor");
    }
    else if(answer == 'V'){
      int value = ask_question_int("Ange ett nummer _");
      if(value > db->current_index || value < 0){
	puts("Varan finns ej.");
	return;
      }
      print_ware(&db->wares[value-1]);
    }
  }
}