/* * Permet de lancer la production de Toys d'une Factory */ private void btnProductionToys_Click(object sender, EventArgs e) { if (user.capital >= factoryType.toy_production_price) { try { using (FactoryIFACClient proxyFactory = new FactoryIFACClient()) { // Date actuelle + 1 heure DateTime now = Utilities.getDate(); DateTime now1Hours = now.AddHours(Utilities.productionTime); factory.toy_production_time = now1Hours; factory.toy_current_production = Utilities.getRandomInt(); proxyFactory.productToys(factory, user); } this.Dispose(); frmVillage.reload(user); MessageBox.Show("Production Launched !"); } catch (Exception) { throw; } } }
/* * Ajout d'une factory */ private void btnAdd_Click(object sender, EventArgs e) { try { FactoryBO factory = new FactoryBO(); ManageFactoryBO manageFactory = new ManageFactoryBO(); List<ManageVillageBO> manageVillageList = new List<ManageVillageBO>(); UserBO user = new UserBO(); int price = Int32.Parse(lblFactoryPrice.Text); int capital; // Récupération de l'user et calcul du capital final using (UserIFACClient proxyUser = new UserIFACClient()) { user = proxyUser.findById(id_user); capital = user.capital - price; } /* * Si capital calculé plus grand que la capital minimum (500) * True: Création factory, création lien factory->village, update user * False: Afficher message "Plus assez d'argent..." */ if (Utilities.checkCapital(capital)) { // Création et récupération factory using (FactoryIFACClient proxyFactory = new FactoryIFACClient()) { factory.type = Int32.Parse(cbxFactoryType.SelectedValue.ToString()); factory.factory_location = position; factory.toy_production_time = DateTime.Now; factory.status = "false"; proxyFactory.createFactory(factory); factory = proxyFactory.getLastFactory(); } // Création du lien factory->village using (ManageFactoryIFACClient proxyManageFactory = new ManageFactoryIFACClient()) { manageFactory.id_village = id_village; manageFactory.id_factory = factory.id_factory; proxyManageFactory.createManageFactory(manageFactory); } // Update de l'user et rechargement de la Form Village using (UserIFACClient proxyUser = new UserIFACClient()) { user.capital = capital; proxyUser.updateUser(user); frmVillage.reload(user); } this.Dispose(); MessageBox.Show("Factory successfully created."); } else { this.Dispose(); MessageBox.Show("Vous n'avez plus assez d'argent, économisez !"); } } catch (Exception) { throw; } }
/* * Suppression de la Factory */ private void btnDelete_Click(object sender, EventArgs e) { try { /* * Si capital > capitalMinimum -> suppression * Sinon: Message "Votre capital ne permet pas la suppression." */ if (Utilities.checkCapital(user.capital)) { // Suppression du lien Factory -> Village using (ManageFactoryIFACClient proxyManageFactory = new ManageFactoryIFACClient()) { proxyManageFactory.deleteManageFactory(factory.id_factory); } // Suppression de la Factory using (FactoryIFACClient proxyFactory = new FactoryIFACClient()) { proxyFactory.deleteFactory(factory.id_factory); } frmVillage.reload(user); } else { MessageBox.Show("Votre capital ne permet pas la suppression."); } } catch (Exception) { throw; } }
/* * Permet de vendre les jouets en stock */ private void btnSale_Click(object sender, EventArgs e) { /* * Vérifier que stock est plus grand que 0 * Si oui: Affiche "Votre profit est de: prix" * Sinon: Affiche "Votre stock est vide !" */ if (factory.factory_stock != 0) { try { // Calcul du prix de vente int sales = factory.factory_stock * factoryType.toy_sales_prices; using (FactoryIFACClient proxyFactory = new FactoryIFACClient()) { proxyFactory.salesProduct(factory, user); } MessageBox.Show("Votre profit est de: " + sales.ToString()); this.Dispose(); frmVillage.reload(user); } catch (Exception) { throw; } } else { MessageBox.Show("Votre stock est vide !"); } }
/* * Chargement de la Form frmFactoryManage */ private void frmFactoryManage_Load(object sender, EventArgs e) { try { // Update status Factory si la date de prod + 1 heure est passée ou pas using (FactoryIFACClient proxyFactory = new FactoryIFACClient()) { factory = proxyFactory.findFactory(factory.id_factory); /* * Check le status de Factory * Si true: Vérifie que la date de production est passée -> oui: factory_stock = toy_current_production, toy_current_production = 0 et status updaté + affichage Jouets produits * -> non: les boutons Launch Production et Sale Stock sont bloqués * Sinon: ne fait rien */ if (proxyFactory.checkStatus(factory)) { DateTime timeNow = Utilities.getDate(); DateTime timeProd = (DateTime)factory.toy_production_time; if (Utilities.compareDate(timeProd, timeNow)) { btnProduct.Enabled = false; btnProduct.Text = STATUS_PRODUCTION; btnSale.Enabled = false; btnSale.Text = STATUS_PRODUCTION; } else { String production_result = factory.toy_current_production.ToString(); factory.factory_stock = factory.factory_stock + factory.toy_current_production; factory.toy_current_production = 0; factory.status = STATUS_OK; proxyFactory.updateFactory(factory); MessageBox.Show("Votre usine a produit " + production_result + " jouets."); } } } // Affiche les informations: Nom Jouets, Prix Production, Stock et Prix Vente using (FactoryTypeIFACClient proxyFactoryType = new FactoryTypeIFACClient()) { listFactoryType = new List<FactoryTypeBO>(); listFactoryType = proxyFactoryType.selectAll(); factoryType = listFactoryType.Find(type => type.id_factory_type == factory.type); lblToys.Text = factoryType.name; lblProductionPrice.Text = factoryType.toy_production_price.ToString(); lblStock.Text = factory.factory_stock.ToString(); lblSalesPrice.Text = factoryType.toy_sales_prices.ToString(); } } catch (Exception) { throw; } }