/* * 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; } }
/* * 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; } }
/* * 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; } }
// 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); } }