Exemplo n.º 1
0
 /*
  * Initialisation de la Form frmFactoryManage
  */
 public frmFactoryManage(frmVillage frmVillage, UserBO user, FactoryBO factory)
 {
     InitializeComponent();
     this.frmVillage = frmVillage;
     this.user = user;
     this.factory = factory;
 }
Exemplo n.º 2
0
        /*
         * Deconnection du compte User
         */
        private void deconnectMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Form activeChild = this.ActiveMdiChild;
                frmVillage objfrmVillage = (frmVillage)activeChild;

                UserBO user = new UserBO();
                user = objfrmVillage.userVillage;

                using (UserIFACClient proxy = new UserIFACClient())
                {
                    proxy.disconnect(user);
                }

                objfrmVillage.Dispose();
                deconnectMenuItem.Visible = false;
                connexionMenuItem.Visible = true;
                quitMenuItem.Visible = true;
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
 // Implémentation méthode checkUniqueUsername Interface User
 public bool checkUniqueUsername(UserBO user)
 {
     try
     {
         return UserBL.checkUniqueUsername(user);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 4
0
        /*
         * Initialisation de la Form frmFactory avec Factory en paramètre
         */
        public frmFactory(frmVillage frmVillage, UserBO user, FactoryBO factory)
        {
            InitializeComponent();
            this.frmVillage = frmVillage;
            this.user = user;
            this.factory = factory;

            btnAdd.Visible = false;

            pictureBox.Image = Resource.Factory;
            pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
        }
Exemplo n.º 5
0
        /*
         * Permet au User de se Connecter
         */
        private void btnConnexion_Click(object sender, EventArgs e)
        {
            try
            {
                /*
                 * Vérification si les champs sont remplis
                 * Si oui:                 -> ok: Affiche "Welcome back #username !"
                 *                         -> erreur: Affiche "Errur: #erreur"
                 * Sinon: Affiche "Veuillez remplir les champs."
                 */
                if (!string.IsNullOrWhiteSpace(tbxUsername.Text) && !string.IsNullOrWhiteSpace(tbxPassword.Text))
                {
                    using (UserIFACClient proxy = new UserIFACClient())
                    {
                        user = new UserBO();
                        user.username = tbxUsername.Text;
                        user.password = tbxPassword.Text;
                        String message = proxy.connexion(user);

                        if (message == "Ok")
                        {
                            UserBO newUser = new UserBO();
                            newUser = proxy.searchUser(user);

                            frmVillage objfrmVillage = new frmVillage(newUser, objfrmWelcome);
                            objfrmVillage.MdiParent = objfrmWelcome;
                            objfrmVillage.Show();

                            this.Dispose();
                            MessageBox.Show("Welcome back " + newUser.username + " !");

                        }
                        else
                        {
                            tbxUsername.Clear();
                            tbxPassword.Clear();
                            MessageBox.Show("Erreur: " + message);
                        }
                    }
                }
                else
                {
                    tbxUsername.Clear();
                    tbxPassword.Clear();
                    MessageBox.Show("Veuillez remplir les champs.");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        /*
         * Initialisation de la Form frmFactory avec position en paramètre
         */
        public frmFactory(frmVillage frmVillage, UserBO user, int position)
        {
            InitializeComponent();
            this.frmVillage = frmVillage;
            this.user = user;
            this.position = position;

            btnManage.Visible = false;
            btnDelete.Visible = false;
            lblFactory.Visible = false;

            pictureBox.Image = Resource.ForSale;
            pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
        }
Exemplo n.º 7
0
 // Implémentation méthode connexion Interface User
 public String connexion(UserBO user)
 {
     try
     {
         /*
          * Retourne un String en fonction de recherche de l'User
          * Si null: Retourne "Utilisateur inconnu."
          * Si Username et password correspondent: Retourne "Ok"
          * Si status user == "true": Retourne "Utilisateur déjà connecté."
          * Si username OK, mais pas password: Retourne "Mot de passe erroné"
          */
         userFAC = new UserBO();
         userFAC = UserBL.SearchByName(user);
         if (userFAC == null)
         {
             return "Utilisateur inconnu.";
         }
         else if (userFAC.username == user.username && userFAC.password == user.password && userFAC.status == USER_STATUS_NOK)
         {
             userFAC.status = USER_STATUS_OK;
             UserBL.Update(userFAC);
             return "Ok";
         }
         else if (userFAC.status == USER_STATUS_OK)
         {
             return "Utilisateur déjà connecté.";
         }
         else if (userFAC.username == user.username && userFAC.password != user.password)
         {
             return "Mot de passe erroné";
         }
         else
         {
             return "Default";
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 8
0
        // Implémentation méthode productToys Interface Factory
        public void productToys(FactoryBO factory, UserBO user)
        {
            try
            {
                // Recherche FactoryType en fonction de Factory
                FactoryTypeBO factoryType = new FactoryTypeBO();
                factoryType = FactoryTypeBL.FindById(factory.type);

                // Update du capital en fonction des info FactoryType
                int newCapital = user.capital - factoryType.toy_production_price;
                user.capital = newCapital;
                UserBL.Update(user);

                // Update du status Factory
                factory.status = "true";
                FactoryBL.Update(factory);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 9
0
 // Implémentation méthode createUser Interface User
 public void createUser(UserBO user)
 {
     try
     {
         user.status = USER_STATUS_NOK;
         UserBL.Insert(user);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 10
0
 // Implémentation méthode updateUser Interface User
 public void updateUser(UserBO user)
 {
     try
     {
         UserBL.Update(user);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 11
0
 // Implémentation méthode searchUser Interface User
 public UserBO searchUser(UserBO user)
 {
     try
     {
         userFAC = new UserBO();
         userFAC = UserBL.SearchByName(user);
         return userFAC;
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 12
0
 // Implémentation méthode findById Interface User
 public UserBO findById(int id_user)
 {
     try
     {
         userFAC = new UserBO();
         userFAC = UserBL.SearchById(id_user);
         return userFAC;
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 13
0
 // Implémentation méthode disconnect Interface User
 public void disconnect(UserBO user)
 {
     try
     {
         user.status = USER_STATUS_NOK;
         UserBL.Update(user);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 14
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;
            }
        }
Exemplo n.º 15
0
        // Implémentation méthode salesProduct Interface Factory
        public void salesProduct(FactoryBO factory, UserBO user)
        {
            try
            {
                // Recherche FactoryType en fonction de Factory
                FactoryTypeBO factoryType = new FactoryTypeBO();
                factoryType = FactoryTypeBL.FindById(factory.type);

                // Update du capital en fonction des info FactoryType et du stock
                int newCapital = user.capital + factory.factory_stock * factoryType.toy_sales_prices;
                user.capital = newCapital;
                UserBL.Update(user);

                // Remise à zéro du stock
                factory.factory_stock = 0;
                FactoryBL.Update(factory);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 16
0
        // Permet d'enregistrer l'User lors du clic sur "Confirm"
        private void btnValidate_Click(object sender, EventArgs e)
        {
            try
            {
                // Vérification que les champs sont rempli
                if (!string.IsNullOrWhiteSpace(tbxUsername.Text) && !string.IsNullOrWhiteSpace(tbxPassword.Text) && !string.IsNullOrWhiteSpace(tbxEmail.Text))
                {
                    using (UserIFACClient proxyUser = new UserIFACClient())
                    {
                        UserBO user = new UserBO();
                        user.username = tbxUsername.Text;
                        user.password = tbxPassword.Text;
                        user.email = tbxEmail.Text;
                        user.capital = Utilities.capitalDefault;

                        // Vérification de la disponnibilté de l'Username
                        if (proxyUser.checkUniqueUsername(user))
                        {
                            // Création User
                            proxyUser.createUser(user);

                            UserBO newUser = new UserBO();
                            newUser = proxyUser.searchUser(user);

                            using (VillageIFACClient proxyVillage = new VillageIFACClient())
                            {
                                // Création du Village
                                VillageBO village = new VillageBO();
                                village.name = nameVillage + newUser.id_user.ToString();
                                proxyVillage.createVillage(village);

                                VillageBO newVillage = new VillageBO();
                                newVillage = proxyVillage.findVillage(village.name);

                                // Création du lien Village -> User
                                using (ManageVillageIFACClient proxyManageVillage = new ManageVillageIFACClient())
                                {
                                    ManageVillageBO manageVillage = new ManageVillageBO();
                                    manageVillage.id_user = newUser.id_user;
                                    manageVillage.id_village = newVillage.id_village;
                                    proxyManageVillage.createManageVillage(manageVillage);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("L'username existe déjà.");
                        }
                    }
                    this.Dispose();
                }
                else
                {
                    MessageBox.Show("Veuillez remplir les champs.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }