-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgramInput.cs
169 lines (151 loc) · 5.36 KB
/
ProgramInput.cs
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Text;
namespace ManajemenKasirMccRanur
{
public class ProgramInput
{
public static int InputIndex { get; set; }
public static int Limite { get; set; }
private static List<ProgramInputProduct> product =new List<ProgramInputProduct>();
public static Display print = new Display(60, "left", "space");
static String[] listForm = { "Name Product", "Price Product", "Stock Product" };
public ProgramInput() {
InputIndex = 0;
Limite = 1;
InputOptions();
}
public ProgramInput(int inputIndex, int limite)
{
InputIndex = inputIndex;
Limite = limite;
InputOptions();
}
public ProgramInput(int inputIndex)
{
InputIndex = inputIndex;
InputOptions();
}
public static void InputOptions() {
switch (InputIndex)
{
case 0:
//inputproduk
for (int i = 0; i < Limite; i++)
{
if (EntryProduct()) {
break;
}
}
ShowUpList(0,"Product List :");
break;
default:
//inputjual
break;
}
}
public static bool EntryProduct()
{
bool statet = false;
String name = "";
Double price = 0;
int stock = 0;
for (int i = 0; i < Limite; i++)
{
for (int index = 0; index < listForm.Length ; index++) {
bool rentry = false;
String get = "";
try
{
Console.Write($"\nInput {listForm[index]} :");
get = Console.ReadLine();
if (get.ToLower() == "q")
{
print.Content("Process was stoped");
statet = true;
break;
}
else
{
switch (index)
{
case 0:
name = get;
break;
case 1:
try
{
price = Convert.ToDouble(get);
}
catch (Exception e)
{
ExecptionsMessages(get,listForm[index],e);
index -= 1;
}
break;
case 2:
try
{
InsertProduct(name,price,Convert.ToInt32(get));
}
catch (Exception e)
{
ExecptionsMessages(get, listForm[index], e);
index -= 1;
}
break;
}
}
}
catch (FormatException e)
{
Console.WriteLine("");
Console.WriteLine("\t\t ! ~Erros Messages " + e.Message);
rentry = true;
}
}
if (statet) {
break;
}
}
statet = true;
return statet;
}
private static void InsertProduct(string name, double price, int stock)
{
ProgramInputProduct inProduct = new ProgramInputProduct();
inProduct.productName = name;
inProduct.productPrice = price;
inProduct.productStock = stock;
product.Add(inProduct);
}
private static void ShowUpList(int menu,string title)
{
switch (menu)
{
case 0:
ExtrakData(product, title);
break;
default:
//extrak data order
break;
}
}
private static void ExtrakData(List<ProgramInputProduct> v, String title)
{
print.Box("");
print.Content(title);
for (int i = 0; i < product.Count; i++)
{
product[i].DisplayProduct(i+1);
}
}
private static void ExecptionsMessages(string get, string v, Exception e)
{
Console.WriteLine("");
Console.WriteLine($"{get} Wrong typing !! ~ {v} it must a number type");
Console.WriteLine($"Eror Exception: {e.Message}");
Console.WriteLine("");
}
}
}