123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using System;
- using Lab18.Models;
- namespace Lab18
- {
- public class Recorder
- {
- Goods[] list_Goods; //ссылка на массив товаров
- Supplier[] list_Supplier; //ссылка на массив поставщиков
- GSRecords gsr_GSRecords; //ссылка на объект класса GSRecords
- int cur_sp; //текущее количество поставщиков
- int cur_gd; //текущее количество товаров
- int max_sp; //максимальное количество поставщиков
- int max_gd; //максимальное количество товаров
- /// <summary>
- /// Массив подсчёта количества поставщиков для товаров. Индексы этого
- /// массива совпадают с индексами в list_Goods
- /// </summary>
- private int[] goodsSupplierCount;
- //Описаниесвойств
- public Goods[] List_Goods
- {
- get { return list_Goods; }
- }
- public Supplier[] List_Supplier
- {
- get { return list_Supplier; }
- }
- public GSRecords Gsr_GSRecords
- {
- get { return gsr_GSRecords; }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="T:Lab18.Recorder"/> class.
- /// </summary>
- /// <param name="max_gd">Максимум товаров</param>
- /// <param name="max_sp">Максимум поставщиков</param>
- /// <param name="max_records">Максимум связей поставщиков с товарами</param>
- public Recorder(int max_gd, int max_sp, int max_records)
- {
- list_Goods = new Goods[max_gd];
- list_Supplier = new Supplier[max_sp];
- cur_sp = 0;
- this.max_sp = max_sp;
- cur_gd = 0;
- this.max_gd = max_gd;
- gsr_GSRecords = new GSRecords(max_records);
- goodsSupplierCount = new int[max_records];
- }
- //добавляем поставщика в массив поставщиков
- public bool AddSupplier(string name, int num_sp)
- {
- Supplier temp = new Supplier(name, num_sp); //проверяем, есть ли такой поставщика
- int i = 0;
- while ((i < cur_sp) && !temp.Equals(list_Supplier[i])) i++;
- if ((i != cur_sp) || (cur_sp == max_sp))
- {
- // Уже есть либо слишком много
- return false;
- }
- list_Supplier[cur_sp++] = temp;
- return true;
- }
- //выводспискапоставщиков
- public void St_Display()
- {
- for (int i = 0; i < cur_sp; i++)
- {
- Console.WriteLine(list_Supplier[i].S_name + " " + list_Supplier[i].S_id);
- }
- }
- //добавляемтоварвмассивтоваров
- public bool AddGoods(string name, int num_gd)
- {
- Goods temp = new Goods(name, num_gd); //проверяем, есть ли такой товар
- int i = 0;
- while ((i < cur_gd) && !temp.Equals(list_Goods[i])) i++;
- if ((i != cur_gd) /*нашли*/ || (cur_gd == max_gd) /*слишкоммноготоваров*/) return false;
- list_Goods[cur_gd] = temp;
- goodsSupplierCount[cur_gd] = 0;
- cur_gd++;
- return true;
- }
- //выводспискатоваров
- public void Cs_Display()
- {
- Console.WriteLine("Списоктоваров:");
- for (int i = 0; i < cur_gd; i++)
- {
- Console.WriteLine("Goods: " + list_Goods[i].G_name + " " + list_Goods[i].G_id);
- }
- }
- //регистрация поставщика
- public bool Recording(int SupplierID, int GoodsID)
- {
- int i = 0, j = 0;
- //естьлитакойпоставщик
- while ((i < cur_sp) && (SupplierID != list_Supplier[i].S_id)) i++;
- if (i == cur_sp) return false;
- //есть ли такой товар
- while ((j < cur_gd) && (GoodsID != list_Goods[j].G_id)) j++;
- if (j == cur_gd) return false;
- //нашли поставщика и товар в соотвествующих массивах, регистрируем поставщика товара
- goodsSupplierCount[j]++;
- return gsr_GSRecords.AddRecord(SupplierID, GoodsID);
- }
- public bool AddSupply(int goodID, int count, int supplierID)
- {
- return gsr_GSRecords.AddSupply(goodID, count, supplierID);
- }
- public void DisplayGoodsSuppliersCount()
- {
- Console.WriteLine("Количества поставщиков для товаров:");
- for (int i = 0; i < cur_gd; i++)
- {
- Console.WriteLine($"Для товара {list_Goods[i].G_name} количество поставщиков = {goodsSupplierCount[i]}");
- }
- }
- public void DisplayMaxGood()
- {
- int goodID;
- int goodCount;
- gsr_GSRecords.GetGoodCountsData(out goodID, out goodCount);
- Console.WriteLine($"Товар с максимумом количества - {goodID}. Количество - {goodCount}");
- }
- }
- }
|