private void loginBtn_Click(object sender, EventArgs e) { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { try { bool userOK = shopProxy.CheckUserAuthentication(userField.Text, passField.Text); if (userOK) { Shop shop = new Shop(userField.Text, passField.Text); shop.Show(); this.Hide(); } else { alert.Text = "username/password is incorrect."; } } catch (EndpointNotFoundException y) { alert.Text = "service ofline"; } } }
private void registerBtn_Click(object sender, EventArgs e) { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { string newUser = shopProxy.SaveNewUser(userField.Text); alert.Text = newUser; } }
private void LoadUserBalance() { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { currentUser = shopProxy.GetUserByName(username, password); } balanceLabel.Text = "Balance: " + currentUser.balance; }
private void LoadProducts() { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { products = shopProxy.GetAllProducts(username, password); foreach (Product p in products) { productsBox.Items.Add($"{p.name} \t | ${p.price}"); } } }
private void productsBox_SelectedIndexChanged(object sender, EventArgs e) { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { int index = productsBox.SelectedIndex + 1; Product p = shopProxy.GetProductById(index, username, password); productName.Text = p.name; productPrice.Text = "$" + p.price; ProductDesc.Text = p.description; selectedProduct = p; } }
private void SendOrder_Click(object sender, EventArgs e) { if (total < currentUser.balance) { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { shopProxy.SaveNewOrder(currentUser, orderList.ToArray(), username, password); } orderProducts.Items.Clear(); this.Close(); } else { alertLabel.Text = "Not enough balance."; } }
private void ordersBox_SelectedIndexChanged(object sender, EventArgs e) { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { selectedBox.Items.Clear(); OrderProductDTO[] orderProducts = shopProxy.GetProductsFromOrder(Int32.Parse(ordersBox.SelectedItem.ToString()), username, password); double total = 0; foreach (var op in orderProducts) { Product p = shopProxy.GetProductById(op.product, username, password); total += p.price * op.quantity; selectedBox.Items.Add($"{p.name} \t| {op.quantity} \t ${p.price}"); } totalLabel.Text = "total: $" + total; } }
public MyOrders(string u, string p) { username = u; password = p; InitializeComponent(); using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { currentUser = shopProxy.GetUserByName(username, password); int[] orders = shopProxy.GetAllOrdersByCustomerID(currentUser.Id, username, password); foreach (var o in orders) { ordersBox.Items.Add($"{o}"); } } }
public NewOrder(string u, string p, List <Order_Product> o) { username = u; password = p; orderList = o; using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { currentUser = shopProxy.GetUserByName(username, password); } InitializeComponent(); orderProducts.Items.Clear(); foreach (var op in orderList) { total += op.Product.price * op.quantity; orderProducts.Items.Add($"{op.Product.name} \t | {op.quantity} \t | $ {op.Product.price * op.quantity}"); } totalLabel.Text = "total: $" + total; balanceLabel.Text = "your balance: $" + currentUser.balance; alertLabel.Text = ""; }
static void Main(string[] args) { using (IwebshopServiceClient shopProxy = new IwebshopServiceClient()) { Console.WriteLine(shopProxy.CheckUserAuthentication("yeet", "yeet69")); Console.WriteLine("\n----------------| USER |---------------------------------\n"); Console.WriteLine("new user? [y/n]"); var newU = Console.ReadLine(); if (newU.Equals("y")) { Console.WriteLine("Name: "); string uName = Console.ReadLine(); Console.WriteLine(shopProxy.SaveNewUser(uName)); } //LOGIN //Console.Write("username:"******"Jeff263"; //Console.Write("\npassword:"******"Fukm*GK8"; User currenUser = shopProxy.GetUserByName(username, password); var users = shopProxy.GetAllUsers(username, password); foreach (User u in users) { Console.WriteLine($"\nname: {u.name},\npassword: {u.password},\nbalance: {u.balance}"); } Console.WriteLine("\n----------------| PRODUCT |---------------------------------\n"); //Add new product Console.WriteLine("new product? [y/n]"); var newP = Console.ReadLine(); if (newP.Equals("y")) { Console.WriteLine("Name: "); string name = Console.ReadLine(); Console.WriteLine("Description: "); string description = Console.ReadLine(); Console.WriteLine("Stock: "); Int32 quantity = Int32.Parse(Console.ReadLine()); Console.WriteLine("Price: "); NumberFormatInfo provider = new NumberFormatInfo(); provider.NumberDecimalSeparator = ", "; provider.NumberGroupSeparator = "."; double price = Convert.ToDouble(Console.ReadLine(), provider); shopProxy.SaveProduct(name, description, quantity, price); } var pList = shopProxy.GetAllProducts(username, password); foreach (Product pGet in pList) { Console.WriteLine($"\nname: {pGet.name},\ndecription: {pGet.description}, \nPrice: {pGet.price},\nStock: {pGet.stock}."); } var pd = shopProxy.GetProductById(1, username, password); Console.WriteLine($"\nname: {pd.name}"); Console.ReadKey(); Console.WriteLine("\n----------------| ORDER |---------------------------------\n"); var p1 = shopProxy.GetProductById(1, username, password); var p2 = shopProxy.GetProductById(2, username, password); Order_Product op1 = new Order_Product { quantity = 7, Product = p1 }; Order_Product op2 = new Order_Product { quantity = 8, Product = p2 }; Order_Product[] opList = new Order_Product[] { op1, op2 }; shopProxy.SaveNewOrder(currenUser, opList, username, password); //Order foundOrder = shopProxy.GetOrderByID(1, username, password); //Console.WriteLine($"order:\ncustomer: {foundOrder.User.name}"); } }