-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInventory.cs
More file actions
142 lines (124 loc) · 3.26 KB
/
Inventory.cs
File metadata and controls
142 lines (124 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections;
class Inventory {
string name;
double cost;
int onhand;
int id;
public Inventory(string n, double c, int h, int k) {
name = n;
cost = c;
onhand = h;
id = k;
}
public override string ToString() {
return
String.Format("{0,-10}Cost: {1,6:C} On hand: {2} ID: {3}",
name, cost, onhand, id);
}
}
// Class to display inventory
public class displayInventory {
public static void Main() {
ArrayList inv = new ArrayList();
Random rand = new Random(100);
int code= rand.Next(000000000, 999999999);
Console.WriteLine(code);
// Add elements to the list
inv.Add(new Inventory("Apples", 5.95, 3, code));
inv.Add(new Inventory("Oranges", 8.29, 2, code));
inv.Add(new Inventory("Banana", 3.50, 4, code));
inv.Add(new Inventory("Avocado", 19.88, 8, code));
Console.WriteLine("Inventory list:");
foreach(Inventory i in inv) {
Console.WriteLine(" " + i);
}
}
}
//Enumeration for ITEM TYPE
public enum ItemType {
RENTAL = 0,
NONRENTAL = 1,
}
public class Invent {
private static Inventory inventory = null;
ArrayList inv = new ArrayList();
var myList = new List<KeyValuePair<string, Item>>();
private ItemType type;
private string itemName;
private int itemCode;
private DateTime rentaldate;
private DateTime expirydate;
//Creating Instance for Inventory
public static Inventory getInstance()
{
if (inventory == null)
inventory = new Inventory();
return inventory;
}
/*Remove the item from inventory (only when completely out of the item)*/
public void removeFromInventory(String code)
{
if(isRental(code)){
rented.put(code, myList.get(code));
}
myList.remove(code);
}
//function to find out the typeofItem
public ItemT(String name, String type)
{
id = itemid;
this.name = name;
if(type.equals("rental"))
{
this.type = ItemType.RENTAL;
}
else {
this.type = ItemType.NONRENTAL;
}
}
//function to get details of Rental Item
public void getRentalItem()
{
return itemName;
}
//function to set the expirydate
public void setexpirydate(DateTime d)
{
expirydate = d;
}
//function to set rentaldate
public void setrentaldate(DateTime d)
{
rentaldate = d;
}
//function to get rental date
public DateTime getRentalDueDate()
{
return rentaldate;
}
//function to get expiry date
public DateTime getExpiryDate()
{
return expirydate;
}
//function to add item in the inventory
public void addItem(string code,Item item)
{
myList.Add(new KeyValuePair<code, Item>('234543678','fdkjfdk'));
}
//function to reduce quantity from the inventory
public void reduceItemQuantity(String code, double noofitems) {
var myItem = (from c in myList where item.id == code select c).FirstOrDefault();
quantity=item.getcount()-noofitems;
}
//function to increase quantity in the inventory
public void increaseItemQuantity(String code, double quantity){
var myItem = (from c in myList where item.id == code select c).FirstOrDefault();
quantity=item.getcount()+noofitems;
}
//Function to check if the Item is available in the inventory
public List<String, ArrayList<Item>> getAvailableItems() {
return stock;
}
}