Ejemplo n.º 1
0
        /*
         * 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;
            }
        }
Ejemplo n.º 2
0
        /*
         * 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;
            }
        }