Infiniti_Inter

start

May 5th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.92 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.IO;
  7.  
  8. public class Date
  9. {
  10.     public int dd;
  11.     public int mm;
  12.     public int yy;
  13.     public Date() { dd = mm = yy = -1; }
  14.     public Date(int dd, int mm, int yy)
  15.     {
  16.         this.dd = dd;
  17.         this.mm = mm;
  18.         this.yy = yy;
  19.     }
  20.  
  21.     public void Clear()
  22.     {
  23.         dd = mm = yy = -1;
  24.     }
  25.     public string Show()
  26.     {
  27.         return String.Join(" ", dd, mm, yy) + "\n";
  28.     }
  29.     public static Date Now
  30.     {
  31.         get
  32.         {
  33.             DateTime t = DateTime.Now;
  34.             Date result = new Date(t.Day, t.Month, t.Year);
  35.             return result;
  36.         }
  37.     }
  38.     public Date AddDays(int value)
  39.     {
  40.         DateTime t = DateTime.Now.AddDays(value);
  41.         Date result = new Date(t.Day, t.Month, t.Year);
  42.         return result;
  43.     }
  44.     public static int Compare(Date a, Date b)
  45.     {
  46.         DateTime first = new DateTime(a.yy, a.mm, a.dd);
  47.         DateTime second = new DateTime(b.yy, b.mm, b.dd);
  48.         return DateTime.Compare(first, second);
  49.     }
  50.     public static bool Equal(Date a, Date b)
  51.     {
  52.         if (a.dd == b.dd && a.mm == b.mm && a.yy == b.yy)
  53.             return true;
  54.         return false;
  55.     }
  56.     public override string ToString()
  57.     {
  58.         string d;
  59.         string m;
  60.         if (dd < 10)
  61.             d = "0" + dd.ToString();
  62.         else
  63.             d = dd.ToString();
  64.         if (mm < 10)
  65.             m = "0" + dd.ToString();
  66.         else
  67.             m = mm.ToString();
  68.  
  69.  
  70.  
  71.         return String.Join(".", d, m, yy);
  72.     }
  73. }
  74.  
  75.  
  76. class Product : IComparable<Product>
  77. {
  78.     string name; //название продукции
  79.     double cost; //стоимость за единицу
  80.     int amt; // количество
  81.  
  82.     string made; // изготовитель
  83.  
  84.     Date date; // дата поступления
  85.     Date disposal; // дата утилизации
  86.     Date shipment; // дата отгрузки
  87.  
  88.     public int CompareTo(Product subject)
  89.     {
  90.         if (name == subject.name && cost == subject.cost && made == subject.made)
  91.             return 0;
  92.         return -1;
  93.     }
  94.     public void SetName(string value)
  95.     {
  96.         name = value;
  97.     }
  98.     public void SetCost(double value)
  99.     {
  100.         cost = value;
  101.     }
  102.     public void SetAmt(int value)
  103.     {
  104.         amt = value;
  105.     }
  106.     public void SetMade(string value)
  107.     {
  108.         made = value;
  109.     }
  110.  
  111.     public string GetName()
  112.     {
  113.         return name;
  114.     }
  115.     public double GetCost()
  116.     {
  117.         return cost;
  118.     }
  119.     public int GetAmt()
  120.     {
  121.         return amt;
  122.     }
  123.     public string GetMade()
  124.     {
  125.         return made;
  126.     }
  127.  
  128.     public Date GetDate()
  129.     {
  130.         return date;
  131.     }
  132.     public Date GetDisposal()
  133.     {
  134.         return disposal;
  135.     }
  136.     public Date GetShipment()
  137.     {
  138.         return shipment;
  139.     }
  140.  
  141.     public bool IsDispose;
  142.     public bool IsShip;
  143.     public void ClearShip()
  144.     {
  145.         shipment.Clear();
  146.         IsShip = false;
  147.     }
  148.     public void ClearDispose()
  149.     {
  150.         disposal.Clear();
  151.         IsShip = true;
  152.         IsDispose = false;
  153.     }
  154.  
  155.     public void Ship(Date when)
  156.     {
  157.         shipment = when;
  158.         IsDispose = false;
  159.     }
  160.     public void Dispose(Date when)
  161.     {
  162.         disposal = when;
  163.         IsDispose = true;
  164.         IsShip = false;
  165.     }
  166.  
  167.     public string Show()
  168.     {
  169.         return String.Join("\n", "Name : " + name, "Cost : " + cost, "AMT : " + amt, "made from : " + made,
  170.             "Date : " + date + "\n" + new string('=', 20));
  171.     }
  172.  
  173.  
  174.     public Product(string name, double cost, int amt, string made, Date date)
  175.     {
  176.         this.name = name;
  177.         this.cost = cost;
  178.         this.amt = amt;
  179.         this.made = made;
  180.         this.date = date;
  181.     }
  182. }
  183. class Warehouse
  184. {
  185.     public List<Product> All = new List<Product>();
  186.     public SortedDictionary<Product, Date> Dispose = new SortedDictionary<Product, Date>();
  187.     public SortedDictionary<Product, Date> Shipment = new SortedDictionary<Product, Date>();
  188.  
  189.     public int FindIdx(string name)
  190.     {
  191.         Refresh();
  192.         for (int i = 0; i < All.Count; ++i)
  193.         {
  194.             if (All[i].GetName() == name)
  195.                 return i;
  196.         }
  197.         return -1;
  198.  
  199.     }
  200.     public void FindDate(Date when)
  201.     {
  202.         Console.WriteLine("Search results : ");
  203.         for (int i = 0; i < All.Count; ++i)
  204.         {
  205.             if (Date.Equal(All[i].GetDate(), when))
  206.                 Console.WriteLine(All[i].Show());
  207.         }
  208.         Console.WriteLine("End of searching");
  209.         Console.WriteLine();
  210.     }
  211.     public void FindDispose(Date when)
  212.     {
  213.         Refresh();
  214.         Console.WriteLine("Search results : ");
  215.         if (Date.Compare(when, Date.Now) < 0)
  216.         {
  217.             Console.WriteLine("This information is no longer available\n");
  218.             return;
  219.         }
  220.         foreach (var v in Dispose)
  221.         {
  222.             if (Date.Equal(when, v.Value))
  223.                 Console.WriteLine(v.Key.Show());
  224.         }
  225.  
  226.         Console.WriteLine("End of searching");
  227.         Console.WriteLine();
  228.  
  229.     }
  230.  
  231.     public void FindShipment(Date when)
  232.     {
  233.         Refresh();
  234.         Console.WriteLine("Search results : ");
  235.         if (Date.Compare(when, Date.Now) < 0)
  236.         {
  237.             Console.WriteLine("This information is no longer available\n");
  238.             return;
  239.         }
  240.         foreach (var v in Shipment)
  241.         {
  242.             if (Date.Equal(when, v.Value))
  243.                 Console.WriteLine(v.Key.Show());
  244.         }
  245.         Console.WriteLine("End of searching");
  246.         Console.WriteLine();
  247.  
  248.     }
  249.  
  250.     public void addProduct(Product obj)
  251.     {
  252.         All.Add(obj);
  253.         Console.WriteLine("item added");
  254.     }
  255.     public void addProduct(string name, double cost, int amt, string made, Date date)
  256.     {
  257.         addProduct(new Product(name, cost, amt, made, date));
  258.     }
  259.  
  260.     public void ProductDispose(Product obj, Date when)
  261.     {
  262.         obj.Dispose(when);
  263.         Dispose.Add(obj, when);
  264.         if (Shipment.ContainsKey(obj))
  265.             Shipment.Remove(obj);
  266.         Console.WriteLine("Item added to scrap(dispose)");
  267.     }
  268.     public void ProductShip(Product obj, Date when)
  269.     {
  270.         obj.Ship(when);
  271.         Shipment.Add(obj, when);
  272.         if (Dispose.ContainsKey(obj))
  273.             Dispose.Remove(obj);
  274.         Console.WriteLine("Item added to shipment");
  275.     }
  276.     public void ShowAll()
  277.     {
  278.         Console.WriteLine("Result \"Show all\": ");
  279.         Refresh();
  280.         foreach (var v in All)
  281.         {
  282.             Console.WriteLine(v.Show());
  283.             if (v.IsShip)
  284.                 Console.WriteLine("Shipment : " + v.GetShipment().Show());
  285.             if (v.IsDispose)
  286.                 Console.WriteLine("Dispose : " + v.GetDisposal().Show());
  287.         }
  288.         Console.WriteLine("End of showing");
  289.         Console.WriteLine();
  290.     }
  291.     public void ShowShipment()
  292.     {
  293.         Console.WriteLine("Result \"Show Shipment\": ");
  294.         Refresh();
  295.         foreach (var v in Shipment)
  296.         {
  297.             Console.WriteLine(v.Key.Show());
  298.         }
  299.         Console.WriteLine("End of showing");
  300.         Console.WriteLine();
  301.     }
  302.  
  303.     public void ShowDisposel()
  304.     {
  305.         Console.WriteLine("Result \"Show Disposel\": ");
  306.         Refresh();
  307.         foreach (var v in Dispose)
  308.         {
  309.             Console.WriteLine(v.Key.Show());
  310.         }
  311.         Console.WriteLine("End of showing");
  312.         Console.WriteLine();
  313.     }
  314.  
  315.  
  316.     void Clear()
  317.     {
  318.         foreach (var v in Shipment)
  319.             if (Date.Compare(v.Value, Date.Now) < 0)
  320.                 Shipment.Remove(v.Key);
  321.         foreach (var v in Dispose)
  322.             if (Date.Compare(v.Value, Date.Now) < 0)
  323.                 Dispose.Remove(v.Key);
  324.     }
  325.     public void ClearAll()
  326.     {
  327.         foreach (var v in All)
  328.         {
  329.             if (Date.Compare(v.GetDisposal(), Date.Now) < 0)
  330.             {
  331.                 All.Remove(v);
  332.                 continue;
  333.             }
  334.             if (Date.Compare(v.GetShipment(), Date.Now) < 0)
  335.                 All.Remove(v);
  336.         }
  337.     }
  338.     void Refresh()
  339.     {
  340.         Clear();
  341.         List<Product> DeleteShip = new List<Product>();
  342.         List<Product> DeleteDispose = new List<Product>();
  343.         foreach (var v in All)
  344.         {
  345.             if (v.IsDispose && Dispose.ContainsKey(v) == false)
  346.                 Dispose.Add(v, v.GetDisposal());
  347.             if (v.IsShip && Shipment.ContainsKey(v) == false)
  348.                 Shipment.Add(v, v.GetShipment());
  349.         }
  350.         foreach (var v in Shipment)
  351.         {
  352.             if (v.Key.IsDispose && Dispose.ContainsKey(v.Key) == false)
  353.                 Dispose.Add(v.Key, v.Key.GetDisposal());
  354.             if (v.Key.IsShip == false)
  355.                 DeleteShip.Add(v.Key);
  356.         }
  357.         foreach (var v in Dispose)
  358.         {
  359.             if (v.Key.IsShip && Shipment.ContainsKey(v.Key) == false)
  360.                 Shipment.Add(v.Key, v.Key.GetDisposal());
  361.             if (v.Key.IsDispose == false)
  362.                 DeleteDispose.Add(v.Key);
  363.         }
  364.         foreach (var v in DeleteShip)
  365.         {
  366.             Shipment.Remove(v);
  367.         }
  368.         foreach (var v in DeleteDispose)
  369.         {
  370.             Dispose.Remove(v);
  371.         }
  372.  
  373.     }
  374.  
  375. }
  376.  
  377.  
  378.  
  379.  
  380.  
  381. class Program
  382. {
  383.     static void Main(string[] args)
  384.     {
  385.         Warehouse warehouse = new Warehouse();
  386.         Product a = new Product("PC", 25411, 12, "acer", Date.Now);
  387.         warehouse.addProduct(a);
  388.         a.Dispose(Date.Now.AddDays(10));
  389.         warehouse.addProduct("Console #2", 30000, 1000, "Microsoft", Date.Now);
  390.         warehouse.ShowDisposel();
  391.         int t = warehouse.FindIdx("Console #2");
  392.         if (t != -1)
  393.             warehouse.ProductShip(warehouse.All[t], Date.Now);
  394.         warehouse.ShowAll();
  395.     }
  396.  
  397. }
Add Comment
Please, Sign In to add comment