Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- public class Date
- {
- public int dd;
- public int mm;
- public int yy;
- public Date() { dd = mm = yy = -1; }
- public Date(int dd, int mm, int yy)
- {
- this.dd = dd;
- this.mm = mm;
- this.yy = yy;
- }
- public void Clear()
- {
- dd = mm = yy = -1;
- }
- public string Show()
- {
- return String.Join(" ", dd, mm, yy) + "\n";
- }
- public static Date Now
- {
- get
- {
- DateTime t = DateTime.Now;
- Date result = new Date(t.Day, t.Month, t.Year);
- return result;
- }
- }
- public Date AddDays(int value)
- {
- DateTime t = DateTime.Now.AddDays(value);
- Date result = new Date(t.Day, t.Month, t.Year);
- return result;
- }
- public static int Compare(Date a, Date b)
- {
- DateTime first = new DateTime(a.yy, a.mm, a.dd);
- DateTime second = new DateTime(b.yy, b.mm, b.dd);
- return DateTime.Compare(first, second);
- }
- public static bool Equal(Date a, Date b)
- {
- if (a.dd == b.dd && a.mm == b.mm && a.yy == b.yy)
- return true;
- return false;
- }
- public override string ToString()
- {
- string d;
- string m;
- if (dd < 10)
- d = "0" + dd.ToString();
- else
- d = dd.ToString();
- if (mm < 10)
- m = "0" + dd.ToString();
- else
- m = mm.ToString();
- return String.Join(".", d, m, yy);
- }
- }
- class Product : IComparable<Product>
- {
- string name; //название продукции
- double cost; //стоимость за единицу
- int amt; // количество
- string made; // изготовитель
- Date date; // дата поступления
- Date disposal; // дата утилизации
- Date shipment; // дата отгрузки
- public int CompareTo(Product subject)
- {
- if (name == subject.name && cost == subject.cost && made == subject.made)
- return 0;
- return -1;
- }
- public void SetName(string value)
- {
- name = value;
- }
- public void SetCost(double value)
- {
- cost = value;
- }
- public void SetAmt(int value)
- {
- amt = value;
- }
- public void SetMade(string value)
- {
- made = value;
- }
- public string GetName()
- {
- return name;
- }
- public double GetCost()
- {
- return cost;
- }
- public int GetAmt()
- {
- return amt;
- }
- public string GetMade()
- {
- return made;
- }
- public Date GetDate()
- {
- return date;
- }
- public Date GetDisposal()
- {
- return disposal;
- }
- public Date GetShipment()
- {
- return shipment;
- }
- public bool IsDispose;
- public bool IsShip;
- public void ClearShip()
- {
- shipment.Clear();
- IsShip = false;
- }
- public void ClearDispose()
- {
- disposal.Clear();
- IsShip = true;
- IsDispose = false;
- }
- public void Ship(Date when)
- {
- shipment = when;
- IsDispose = false;
- }
- public void Dispose(Date when)
- {
- disposal = when;
- IsDispose = true;
- IsShip = false;
- }
- public string Show()
- {
- return String.Join("\n", "Name : " + name, "Cost : " + cost, "AMT : " + amt, "made from : " + made,
- "Date : " + date + "\n" + new string('=', 20));
- }
- public Product(string name, double cost, int amt, string made, Date date)
- {
- this.name = name;
- this.cost = cost;
- this.amt = amt;
- this.made = made;
- this.date = date;
- }
- }
- class Warehouse
- {
- public List<Product> All = new List<Product>();
- public SortedDictionary<Product, Date> Dispose = new SortedDictionary<Product, Date>();
- public SortedDictionary<Product, Date> Shipment = new SortedDictionary<Product, Date>();
- public int FindIdx(string name)
- {
- Refresh();
- for (int i = 0; i < All.Count; ++i)
- {
- if (All[i].GetName() == name)
- return i;
- }
- return -1;
- }
- public void FindDate(Date when)
- {
- Console.WriteLine("Search results : ");
- for (int i = 0; i < All.Count; ++i)
- {
- if (Date.Equal(All[i].GetDate(), when))
- Console.WriteLine(All[i].Show());
- }
- Console.WriteLine("End of searching");
- Console.WriteLine();
- }
- public void FindDispose(Date when)
- {
- Refresh();
- Console.WriteLine("Search results : ");
- if (Date.Compare(when, Date.Now) < 0)
- {
- Console.WriteLine("This information is no longer available\n");
- return;
- }
- foreach (var v in Dispose)
- {
- if (Date.Equal(when, v.Value))
- Console.WriteLine(v.Key.Show());
- }
- Console.WriteLine("End of searching");
- Console.WriteLine();
- }
- public void FindShipment(Date when)
- {
- Refresh();
- Console.WriteLine("Search results : ");
- if (Date.Compare(when, Date.Now) < 0)
- {
- Console.WriteLine("This information is no longer available\n");
- return;
- }
- foreach (var v in Shipment)
- {
- if (Date.Equal(when, v.Value))
- Console.WriteLine(v.Key.Show());
- }
- Console.WriteLine("End of searching");
- Console.WriteLine();
- }
- public void addProduct(Product obj)
- {
- All.Add(obj);
- Console.WriteLine("item added");
- }
- public void addProduct(string name, double cost, int amt, string made, Date date)
- {
- addProduct(new Product(name, cost, amt, made, date));
- }
- public void ProductDispose(Product obj, Date when)
- {
- obj.Dispose(when);
- Dispose.Add(obj, when);
- if (Shipment.ContainsKey(obj))
- Shipment.Remove(obj);
- Console.WriteLine("Item added to scrap(dispose)");
- }
- public void ProductShip(Product obj, Date when)
- {
- obj.Ship(when);
- Shipment.Add(obj, when);
- if (Dispose.ContainsKey(obj))
- Dispose.Remove(obj);
- Console.WriteLine("Item added to shipment");
- }
- public void ShowAll()
- {
- Console.WriteLine("Result \"Show all\": ");
- Refresh();
- foreach (var v in All)
- {
- Console.WriteLine(v.Show());
- if (v.IsShip)
- Console.WriteLine("Shipment : " + v.GetShipment().Show());
- if (v.IsDispose)
- Console.WriteLine("Dispose : " + v.GetDisposal().Show());
- }
- Console.WriteLine("End of showing");
- Console.WriteLine();
- }
- public void ShowShipment()
- {
- Console.WriteLine("Result \"Show Shipment\": ");
- Refresh();
- foreach (var v in Shipment)
- {
- Console.WriteLine(v.Key.Show());
- }
- Console.WriteLine("End of showing");
- Console.WriteLine();
- }
- public void ShowDisposel()
- {
- Console.WriteLine("Result \"Show Disposel\": ");
- Refresh();
- foreach (var v in Dispose)
- {
- Console.WriteLine(v.Key.Show());
- }
- Console.WriteLine("End of showing");
- Console.WriteLine();
- }
- void Clear()
- {
- foreach (var v in Shipment)
- if (Date.Compare(v.Value, Date.Now) < 0)
- Shipment.Remove(v.Key);
- foreach (var v in Dispose)
- if (Date.Compare(v.Value, Date.Now) < 0)
- Dispose.Remove(v.Key);
- }
- public void ClearAll()
- {
- foreach (var v in All)
- {
- if (Date.Compare(v.GetDisposal(), Date.Now) < 0)
- {
- All.Remove(v);
- continue;
- }
- if (Date.Compare(v.GetShipment(), Date.Now) < 0)
- All.Remove(v);
- }
- }
- void Refresh()
- {
- Clear();
- List<Product> DeleteShip = new List<Product>();
- List<Product> DeleteDispose = new List<Product>();
- foreach (var v in All)
- {
- if (v.IsDispose && Dispose.ContainsKey(v) == false)
- Dispose.Add(v, v.GetDisposal());
- if (v.IsShip && Shipment.ContainsKey(v) == false)
- Shipment.Add(v, v.GetShipment());
- }
- foreach (var v in Shipment)
- {
- if (v.Key.IsDispose && Dispose.ContainsKey(v.Key) == false)
- Dispose.Add(v.Key, v.Key.GetDisposal());
- if (v.Key.IsShip == false)
- DeleteShip.Add(v.Key);
- }
- foreach (var v in Dispose)
- {
- if (v.Key.IsShip && Shipment.ContainsKey(v.Key) == false)
- Shipment.Add(v.Key, v.Key.GetDisposal());
- if (v.Key.IsDispose == false)
- DeleteDispose.Add(v.Key);
- }
- foreach (var v in DeleteShip)
- {
- Shipment.Remove(v);
- }
- foreach (var v in DeleteDispose)
- {
- Dispose.Remove(v);
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Warehouse warehouse = new Warehouse();
- Product a = new Product("PC", 25411, 12, "acer", Date.Now);
- warehouse.addProduct(a);
- a.Dispose(Date.Now.AddDays(10));
- warehouse.addProduct("Console #2", 30000, 1000, "Microsoft", Date.Now);
- warehouse.ShowDisposel();
- int t = warehouse.FindIdx("Console #2");
- if (t != -1)
- warehouse.ProductShip(warehouse.All[t], Date.Now);
- warehouse.ShowAll();
- }
- }
Add Comment
Please, Sign In to add comment