コード例 #1
0
 void buttonParticipate_Click(object sender, EventArgs e)
 {
     if (buttonParticipate.Text.Equals("Participar")) //Participate on activity
     {
         if (ActivityManager.NumberOfParticipants < ActivityManager.GetCurrentActivity().MaxPeople)
         {
             const string statement =
                 "INSERT INTO `user_has_activity` (`User_id`, `Activity_id`) VALUES (@0, @1)";
             object[] values =
             {
                 AccountsManager.GetLoggedUser().Id,
                 ActivityManager.GetCurrentActivity().Id
             };
             Db.ExecuteSql(statement, values);
             FillUsersTable(ActivityManager.GetCurrentActivity(), AccountsManager.GetLoggedUser());
         }
         else
         {
             MessageBox.Show("A atividade está cheia!");
         }
     }
     else //Remove participation
     {
         const string statement =
             "DELETE FROM `user_has_activity` WHERE `user_has_activity`.`User_id` = @0 AND `user_has_activity`.`Activity_id` = @1";
         object[] values =
         {
             AccountsManager.GetLoggedUser().Id,
             ActivityManager.GetCurrentActivity().Id
         };
         Db.ExecuteSql(statement, values);
         FillUsersTable(ActivityManager.GetCurrentActivity(), AccountsManager.GetLoggedUser());
     }
 }
コード例 #2
0
        void buttonCreate_Click(object sender, EventArgs e)
        {
            var activityName = nameActivity.Text;
            var local        = localization.Text;
            var dateTime     = dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:[00]");
            var maxPeople    = this.maxPeople.Text;
            var descriptions = description.Text;

            bool verify = Verifications();

            if (!verify)
            {
                return;
            }

            Category categorySelected = (Category)comboBoxCategory.SelectedItem;

            if (FormManager.CreateEditOption.Equals("Create activity"))
            {
                var statement =
                    "INSERT INTO `activity` (`id`, `Category_id`, `User_id`, `name`, `localization`, `date`, `description`, `max_people`) VALUES (NULL, @0, @1, @2, @3 ,@4, @5, @6)";
                object[] values =
                {
                    categorySelected.Id,
                    AccountsManager.GetLoggedUser().Id,
                    activityName,
                    local,
                    dateTime,
                    descriptions,
                    maxPeople
                };
                Db.ExecuteSql(statement, values);
                MessageBox.Show("Atividade inserida");
                FormManager.OpenActivitiesCreatedForm();
            }
            else //Edit activity
            {
                var statement =
                    "UPDATE `activity` SET `Category_id` = @0, `name` = @1, `localization` = @2, `date` = @3, `description` = @4, `max_people` = @5 WHERE `activity`.`id` = @6";
                object[] values =
                {
                    categorySelected.Id,
                    activityName,
                    local,
                    dateTime,
                    descriptions,
                    maxPeople,
                    ActivityManager.GetCurrentActivity().Id
                };
                Db.ExecuteSql(statement, values);
                MessageBox.Show("Atividade editada");
                FormManager.OpenActivitiesCreatedForm();
            }
        }
コード例 #3
0
        void PreSelectFields()
        {
            var currentActivity = ActivityManager.GetCurrentActivity();

            nameActivity.Text     = currentActivity.Name;
            localization.Text     = currentActivity.Location;
            dateTimePicker1.Value = currentActivity.Date;
            maxPeople.Text        = currentActivity.MaxPeople.ToString();
            description.Text      = currentActivity.Description;


            foreach (Category category in comboBoxCategory.Items)
            {
                if (category.Id == currentActivity.Category.Id)
                {
                    comboBoxCategory.SelectedItem = category;
                }
            }
        }
コード例 #4
0
        void buttonDelete_Click(object sender, EventArgs e)
        {
            var confirmResult = MessageBox.Show("Tem a certeza que quer eliminar esta atividade?",
                                                "Atividade removida!",
                                                MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                object[] values = { ActivityManager.GetCurrentActivity().Id };

                var statement =
                    "DELETE FROM `user_has_activity` WHERE `user_has_activity`.`Activity_id` = @0";
                Db.ExecuteSql(statement, values);

                statement = "DELETE FROM `activity` WHERE `activity`.`id` = @0";
                Db.ExecuteSql(statement, values);

                MessageBox.Show("Atividade eliminada");
                FormManager.GoBack();
            }
        }
コード例 #5
0
        void ActivityProfile_form_Load(object sender, EventArgs e)
        {
            var activityId = ActivityManager.GetCurrentActivity().Id;
            var activity   = ActivityManager.CreateActivityId(activityId);

            FillUsersTable(ActivityManager.GetCurrentActivity(), AccountsManager.GetLoggedUser());

            activity_name.Text = activity.Name;
            category.Text      = activity.Category.Name;
            date.Text          = activity.Date.ToString("dd/MM/yyyy HH:mm");

            description.Text          = activity.Description;
            localization.Text         = activity.Location;
            labelActivityCreator.Text = "Criador da atividade\n" + activity.User.Email;

            description.MaximumSize = new Size(400, 0);
            description.AutoSize    = true;

            if (AccountsManager.GetLoggedUser() is Admin)
            {
                buttonParticipate.Visible = false;
            }

            else if (activity.User.Id != AccountsManager.GetLoggedUser().Id)
            {
                buttonDelete.Visible = false;
                buttonEdit.Visible   = false;
            }

            if (ActivityManager.GetCurrentActivity().Date < DateTime.Now)
            {
                buttonParticipate.Visible = false;
                buttonDelete.Visible      = false;
                buttonEdit.Visible        = false;
            }
        }