Skip to content

Commit

Permalink
Fixed several bugs and fully implemented update system. everything sh…
Browse files Browse the repository at this point in the history
…ould now be functional in the admin panel
  • Loading branch information
Evan Langlais authored and Evan Langlais committed Apr 6, 2017
1 parent 0c2ed83 commit b72ba04
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 152 deletions.
3 changes: 3 additions & 0 deletions Enigma/Enigma.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@
<ItemGroup>
<None Include="Resources\lonely_sun_by_butterflypics-d8orr9a.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\ring-alt.gif" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
1 change: 0 additions & 1 deletion Enigma/Popups/AddPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private void AddPopup_Load(object sender, EventArgs e)
private void addButton_Click(object sender, EventArgs e)
{
returnValue = value1Textbox.Text;
MessageBox.Show(returnValue);
DialogResult = DialogResult.OK;
Close();
}
Expand Down
10 changes: 10 additions & 0 deletions Enigma/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Enigma/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@
<data name="lonely_sun_by_butterflypics-d8orr9a" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\lonely_sun_by_butterflypics-d8orr9a.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ring-alt" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ring-alt.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added Enigma/Resources/ring-alt.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
312 changes: 167 additions & 145 deletions Enigma/StationsGUI/AdminStationView.Designer.cs

Large diffs are not rendered by default.

165 changes: 159 additions & 6 deletions Enigma/StationsGUI/AdminStationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ private void drawAllData()
}

private void drawMenus() {
startLoading();
menuSelectionBox.Items.Clear();
menuListBox.Items.Clear();
menuDisplayedOnListBox.ClearSelected();
menuDisplayedOnListBox.Items.Clear();
menuTitleTextBox.ResetText();
foreach (EnigmaMenu menu in enigmaMenus)
{
Expand All @@ -68,47 +69,57 @@ private void drawMenus() {
foreach (Station station in enigmaStations) {
menuDisplayedOnListBox.Items.Add(station);
}
stopLoading();
}

private void drawMenuItems()
{
startLoading();
menuItemListBox.Items.Clear();
foreach (EnigmaMenuItem item in enigmaMenuItems)
{
menuItemListBox.Items.Add(item);
}
stopLoading();
}

private void drawStations()
{
startLoading();
stationListBox.Items.Clear();
foreach (Station station in enigmaStations)
{
stationListBox.Items.Add(station);
}
stopLoading();
}

private void drawEmployees()
{
startLoading();
employeeListBox.Items.Clear();
foreach (Employee employee in enigmaEmployees)
{
employeeListBox.Items.Add(employee);
}
stopLoading();
}

private void loadMenus() {
startLoading();
enigmaMenus.Clear();
DBConnect db = new DBConnect();
List<Dictionary<string, string>> menus = db.ReadCommand("SELECT * FROM Menus", "id", "title", "items");
foreach (Dictionary<string, string> menu in menus) {
EnigmaMenu enigmaMenu = new EnigmaMenu(Convert.ToInt32(menu["id"]), menu["title"], EnigmaMenu.stringToItemList(menu["items"]));
enigmaMenus.Add(enigmaMenu);
}
stopLoading();
}

private void loadMenuItems()
{
startLoading();
enigmaMenuItems.Clear();
DBConnect db = new DBConnect();
List<Dictionary<string, string>> result = db.ReadCommand("SELECT * FROM MenuItems", "id", "title", "description", "price", "category", "printingStation");
Expand All @@ -117,10 +128,12 @@ private void loadMenuItems()
EnigmaMenuItem menuItem = new EnigmaMenuItem(Convert.ToInt32(row["id"]), row["title"], row["description"], float.Parse(row["price"]), (MenuItemType)Enum.Parse(typeof(MenuItemType), row["category"]), (PrintingStationType)Enum.Parse(typeof(PrintingStationType), row["printingStation"]));
enigmaMenuItems.Add(menuItem);
}
stopLoading();
}

private void loadEmployees()
{
startLoading();
enigmaEmployees.Clear();
DBConnect db = new DBConnect();
List<Dictionary<string, string>> employees = db.ReadCommand("SELECT * FROM Users", "id", "first", "last", "role", "pin");
Expand All @@ -129,10 +142,12 @@ private void loadEmployees()
Employee employee = new Employee(Convert.ToInt32(row["id"]), row["first"], row["last"], Employee.getRoles(row["role"]), Convert.ToInt32(row["pin"]));
enigmaEmployees.Add(employee);
}
stopLoading();
}

private void loadStations()
{
startLoading();
enigmaStations.Clear();
DBConnect db = new DBConnect();
List<Dictionary<string, string>> result = db.ReadCommand("SELECT * FROM Stations", "stationid", "type");
Expand All @@ -141,6 +156,7 @@ private void loadStations()
Station station = new Station((StationTypeDef)Enum.Parse(typeof(StationTypeDef), row["type"]), row["stationid"]);
enigmaStations.Add(station);
}
stopLoading();
}

private void adminTabControl_SelectedIndexChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -246,8 +262,8 @@ private void menuSaveButton_Click(object sender, EventArgs e)
{
EnigmaMenu menu = enigmaMenus[menuSelectionBox.SelectedIndex];
menu.Title = menuTitleTextBox.Text;
menu.Items = menuItemListBox.SelectedItems.Cast<EnigmaMenuItem>().ToList();
drawMenus();
menu.Items = menuListBox.SelectedItems.Cast<EnigmaMenuItem>().ToList();
uploadMenus();
}

private void itemsSaveButton_Click(object sender, EventArgs e)
Expand All @@ -258,7 +274,7 @@ private void itemsSaveButton_Click(object sender, EventArgs e)
item.PrintingType = (PrintingStationType)itemPrintingListBox.SelectedIndex;
item.Title = itemNameTextBox.Text;
item.Price = float.Parse(itemPrice.Value.ToString());
drawMenuItems();
uploadMenuItems();
}

private void metroButton4_Click(object sender, EventArgs e)
Expand All @@ -268,14 +284,14 @@ private void metroButton4_Click(object sender, EventArgs e)
employee.LastName = employeeLastNameTextBox.Text;
employee.Pin = Convert.ToInt32(employeePinNumber.Value);
employee.Roles = employeeRoleListBox.SelectedItems.Cast<EmployeeRole>().ToList();
drawEmployees();
uploadEmployee();
}

private void stationSaveButton_Click(object sender, EventArgs e)
{
Station station = enigmaStations[stationListBox.SelectedIndex];
station.StationType = (StationTypeDef)stationTypeListBox.SelectedIndex;
drawStations();
uploadStation();
}

private void metroButton1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -336,5 +352,142 @@ private void stationAddButton_Click(object sender, EventArgs e)
stationListBox.SetSelected(stationListBox.Items.Count - 1, true);
}
}

private void metroButton3_Click(object sender, EventArgs e)
{
EnigmaMenu menu = enigmaMenus[menuSelectionBox.SelectedIndex];
DBConnect db = new DBConnect();
MySqlCommand cmd = new MySqlCommand("DELETE FROM Menus WHERE id=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", menu.Id);
db.WriteCommand(cmd);
loadMenus();
drawMenus();
}

private void itemRemoveButton_Click(object sender, EventArgs e)
{
EnigmaMenuItem item = enigmaMenuItems[menuItemListBox.SelectedIndex];
DBConnect db = new DBConnect();
MySqlCommand cmd = new MySqlCommand("DELETE FROM MenuItems WHERE id=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", item.Id);
db.WriteCommand(cmd);
loadMenuItems();
drawMenuItems();
}

private void removeEmployeeButton_Click(object sender, EventArgs e)
{
Employee employee = enigmaEmployees[employeeListBox.SelectedIndex];
DBConnect db = new DBConnect();
MySqlCommand cmd = new MySqlCommand("DELETE FROM Users WHERE id=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", employee.Id);
db.WriteCommand(cmd);
loadEmployees();
drawEmployees();
}

private void stationRemoveButton_Click(object sender, EventArgs e)
{
Station station = enigmaStations[stationListBox.SelectedIndex];
DBConnect db = new DBConnect();
MySqlCommand cmd = new MySqlCommand("DELETE FROM Stations WHERE stationid=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", station.StationID);
db.WriteCommand(cmd);
loadStations();
drawStations();
}

private void uploadMenus() {
DBConnect db = new DBConnect();
foreach (EnigmaMenu menu in enigmaMenus) {
MySqlCommand cmd = new MySqlCommand("UPDATE Menus SET title=@Title, items=@Items WHERE id=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", menu.Id);
cmd.Parameters.AddWithValue("@Title", menu.Title);
cmd.Parameters.AddWithValue("@Items", EnigmaMenu.itemListToString(menu.Items));
db.WriteCommand(cmd);
}
loadMenus();
drawMenus();
}

private void uploadMenuItems()
{
DBConnect db = new DBConnect();
foreach (EnigmaMenuItem item in enigmaMenuItems)
{
MySqlCommand cmd = new MySqlCommand("UPDATE MenuItems SET title=@Title, description=@Description, price=@Price, category=@Category, printingStation=@Printing WHERE id=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", item.Id);
cmd.Parameters.AddWithValue("@Title", item.Title);
cmd.Parameters.AddWithValue("@Description", item.Description);
cmd.Parameters.AddWithValue("@Price", item.Price.ToString());
cmd.Parameters.AddWithValue("@Category", item.ItemType.ToString());
cmd.Parameters.AddWithValue("@Printing", item.PrintingType.ToString());
db.WriteCommand(cmd);
}
loadMenuItems();
drawMenuItems();
}

private void uploadEmployee() {
DBConnect db = new DBConnect();
foreach (Employee employee in enigmaEmployees)
{
MySqlCommand cmd = new MySqlCommand("UPDATE Users SET first=@First, last=@Last, role=@Role, pin=@Pin WHERE id=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", employee.Id);
cmd.Parameters.AddWithValue("@First", employee.FirstName);
cmd.Parameters.AddWithValue("@Last", employee.LastName);
cmd.Parameters.AddWithValue("@Role", string.Join(",", Array.ConvertAll(employee.Roles.ToArray(), value => value.ToString())));
cmd.Parameters.AddWithValue("@Pin", employee.Pin);
db.WriteCommand(cmd);
}
loadEmployees();
drawEmployees();
}

private void uploadStation() {
DBConnect db = new DBConnect();
foreach (Station station in enigmaStations)
{
MySqlCommand cmd = new MySqlCommand("UPDATE Stations SET type=@Type WHERE stationid=@Id LIMIT 1");
cmd.Parameters.AddWithValue("@Id", station.StationID);
cmd.Parameters.AddWithValue("@Type", station.StationType.ToString());
db.WriteCommand(cmd);
}
loadStations();
drawStations();
}

private void menuRevertButton_Click(object sender, EventArgs e)
{
drawMenus();
}

private void itemsRevertButton_Click(object sender, EventArgs e)
{
drawMenuItems();
}

private void metroButton5_Click(object sender, EventArgs e)
{
drawEmployees();
}

private void stationRevertButton_Click(object sender, EventArgs e)
{
drawStations();
}

private void startLoading()
{

loadingImage.Visible = true;

}

private void stopLoading()
{
loadingImage.Visible = false;
}

}
}
11 changes: 11 additions & 0 deletions EnigmaX/Classes/EnigmaMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public static List<EnigmaMenuItem> stringToItemList(string items) {
return itemList;
}

public static string itemListToString(List<EnigmaMenuItem> itemList) {
string result = "";
foreach (EnigmaMenuItem item in itemList) {
result += item.Id + "|";
}
if (result.Length > 0) {
result = result.Remove(result.Length - 1);
}
return result;
}

public override string ToString()
{
return _id + ": " + _title;
Expand Down

0 comments on commit b72ba04

Please sign in to comment.