forked from larrychong/DimSumProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Specials.cs
151 lines (128 loc) · 4.5 KB
/
Specials.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace COMPortTerminal
{
public partial class Specials : Form
{
//spcials from the file
private SpcList CurSpc = new SpcList();
//order file list
public SpcList OrdSpc = new SpcList();
private bool Admin = false;
private string tableNum = null;
public Specials(bool isAdmin, string TabNum)
{
InitializeComponent();
Admin = isAdmin;
tableNum = TabNum;
}
//public Specials()
//{
// InitializeComponent();
//}
//read the specals file and add populate the array
private void Specials_Load(object sender, EventArgs e)
{
//if it is ordering time resize the from and add controls
if (!Admin)
{
this.Size = new System.Drawing.Size(319+40, 265+70);
}
//get desktop path
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Specials";
//ensure directory exists, if not create it
if (!(Directory.Exists(path)))
{
DirectoryInfo di = Directory.CreateDirectory(path);
}
path += "\\Specials.txt";
// Determine whether the File exists.
if (!(File.Exists(path)))
{
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fs.Close();
// DialogResult Message = MessageBox.Show(this, "There are no Specials at this time", "Sorry");
}
CurSpc = CurSpc.FileToList(path);
boxSpcList.DataSource = CurSpc.toStringList();
if (CurSpc.Count != 0)
{
boxSpcList.SetSelected(0, false);
}
boxSpcList.Refresh();
}
private void boxSpcList_SelectedIndexChanged(object sender, EventArgs e)
{
if (Admin == false)
{
return;
}
//DialogResult adf = MessageBox.Show(this, "Checkpoint");
}
private void Add_Click(object sender, EventArgs e)
{
if (boxSpcList.SelectedIndex == -1)
{
return;
}
OrdSpc.Add(CurSpc[boxSpcList.SelectedIndex]);
boxOrders.DataSource = OrdSpc.toStringList();
if (OrdSpc.Count != 0)
{
boxOrders.SetSelected(0, false);
boxSpcList.SetSelected(0, false);
}
boxOrders.Refresh();
}
private void Remove_Click(object sender, EventArgs e)
{
if (boxOrders.SelectedIndex == -1)
{
return;
}
OrdSpc.RemoveAt(boxOrders.SelectedIndex);
boxOrders.DataSource = OrdSpc.toStringList();
if (OrdSpc.Count != 0)
{
boxOrders.SetSelected(0, false);
boxSpcList.SetSelected(0, false);
}
boxOrders.Refresh();
}
private void Done_Click(object sender, EventArgs e)
{
//Write the the OrdSpc list to the Request file
try
{
//get desktop path
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Tables";
if (!(Directory.Exists(path)))
{
DirectoryInfo di = Directory.CreateDirectory(path);
}
path += "\\Request.txt";
// Create file if it is not there
if (!File.Exists(path))
{
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fs.Close();
}
OrdSpc.ListToFile(path, tableNum, true);
}
catch (Exception exc)
{
Console.WriteLine("The process failed: {0}", exc.ToString());
// DialogResult result = MessageBox.Show(this, "The process failed: " + exc.ToString(), "Error");
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}