// Initialize public AdminEditOrders(string id, string pass) { InitializeComponent(); admin_id = id; password = pass; display = AdminFunctions.list_orders(id, pass); }
// Edit order status private void button1_Click(object sender, EventArgs e) { int index = dataGridView1.SelectedRows[0].Index; string new_status = Microsoft.VisualBasic.Interaction.InputBox("Enter the new status\n'0' = Pending\n'1' = Delivering\n'2' = Delivered", "Input", display[index].int_status.ToString(), 0, 0); bool status = AdminFunctions.edit_order_status(admin_id, password, display[index].id, Int32.Parse(new_status)); if (status) { display[index].int_status = Int32.Parse(new_status); display[index].init(); dataGridView1.Invalidate(); dataGridView1.Refresh(); } }
// listen for add button click private void button2_Click(object sender, EventArgs e) { string input = Microsoft.VisualBasic.Interaction.InputBox("Enter category name", "Input", "", 0, 0); bool status = AdminFunctions.add_category(admin_id, password, System.Uri.EscapeDataString(input)); if (status) { categories = UserRequest.list_categories(); listBox1.Items.Clear(); foreach (var c in categories) { listBox1.Items.Add(Uri.UnescapeDataString(c.name)); } } }
// Add product private void button2_Click(object sender, EventArgs e) { string name = Microsoft.VisualBasic.Interaction.InputBox("Enter product name", "Input", "", 0, 0); string price = Microsoft.VisualBasic.Interaction.InputBox("Enter product price", "Input", "", 0, 0); bool status = AdminFunctions.add_product(admin_id, password, System.Uri.EscapeDataString(name), float.Parse(price), category_id); if (status) { products = UserRequest.list_products(category_id); listBox1.Items.Clear(); foreach (var c in products) { listBox1.Items.Add(Uri.UnescapeDataString(c.name) + "\t" + c.price.ToString()); } } }
// listens for delete button click private void button4_Click(object sender, EventArgs e) { int index = listBox1.SelectedIndex; if (index == -1) { return; } bool status = AdminFunctions.delete_category(admin_id, password, categories[index].id); if (status) { categories = UserRequest.list_categories(); listBox1.Items.Clear(); foreach (var c in categories) { listBox1.Items.Add(Uri.UnescapeDataString(c.name)); } } }
// Listens for edit button click private void button3_Click(object sender, EventArgs e) { int index = listBox1.SelectedIndex; if (index == -1) { return; } string input = Microsoft.VisualBasic.Interaction.InputBox("Enter the new name", "Input", "", 0, 0); bool status = AdminFunctions.edit_category(admin_id, password, categories[index].id, System.Uri.EscapeDataString(input)); if (status) { categories = UserRequest.list_categories(); listBox1.Items.Clear(); foreach (var c in categories) { listBox1.Items.Add(Uri.UnescapeDataString(c.name)); } } }
// Delete product from database private void button4_Click(object sender, EventArgs e) { //Delete int index = listBox1.SelectedIndex; if (index == -1) { return; } bool status = AdminFunctions.delete_product(admin_id, password, category_id, products[index].id); if (status) { products = UserRequest.list_products(category_id); listBox1.Items.Clear(); foreach (var c in products) { listBox1.Items.Add(Uri.UnescapeDataString(c.name) + "\t" + c.price.ToString()); } } }
// Edit product details private void button3_Click(object sender, EventArgs e) { int index = listBox1.SelectedIndex; if (index == -1) { return; } string name = Microsoft.VisualBasic.Interaction.InputBox("Enter the new name", "Input", products[index].name, 0, 0); string price = Microsoft.VisualBasic.Interaction.InputBox("Enter the new price", "Input", products[index].price.ToString(), 0, 0); bool status = AdminFunctions.edit_product(admin_id, password, name, float.Parse(price), category_id, products[index].id); if (status) { products = UserRequest.list_products(category_id); listBox1.Items.Clear(); foreach (var c in products) { listBox1.Items.Add(Uri.UnescapeDataString(c.name) + "\t" + c.price.ToString()); } } }