Пример #1
0
        private void button_remove_user_Click(object sender, EventArgs e)
        {
            if (cached_users.Count == 0)
            {
                MessageBox.Show("Please refresh the users list.");
                return;
            }
            if (comboBox_users.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a user.");
                return;
            }
            int id = cached_users[comboBox_users.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var users = from u in db.Users
                        where u.id == id
                        select u;

            if (users.Count() != 1)
            {
                MessageBox.Show("Error. User not found.");
                return;
            }
            User the_user    = users.Single <User>();
            var  collections = from c in db.Collections
                               where c.user_id == the_user.id
                               select c;

            if (collections.Count() > 0)
            {
                MessageBox.Show("This user cannot be deleted, because of his/her collections.");
                return;
            }
            var feedbacks = from f in db.Feedbacks
                            where f.user_id == the_user.id
                            select f;

            if (feedbacks.Count() > 0)
            {
                MessageBox.Show("This user cannot be deleted, because of his/her feedbacks.");
                return;
            }
            db.Users.DeleteOnSubmit(the_user);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 3; action.user_id = 0; action.date = DateTime.UtcNow;
            action.object_type = "nature_net.User"; action.object_id = the_user.id;
            db.Actions.InsertOnSubmit(action); action.technical_info = the_user.name;
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
        }
Пример #2
0
        private void button_remove_activity_Click(object sender, EventArgs e)
        {
            if (cached_activities.Count == 0)
            {
                MessageBox.Show("Please refresh the activities list.");
                return;
            }
            if (comboBox_activities.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an activity.");
                return;
            }
            int id = cached_activities[comboBox_activities.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from u in db.Activities
                             where u.id == id
                             select u;

            if (activities.Count() != 1)
            {
                MessageBox.Show("Error. Activity not found.");
                return;
            }
            Activity the_activity = activities.Single <Activity>();
            var      collections  = from c in db.Collections
                                    where c.activity_id == the_activity.id
                                    select c;

            if (collections.Count() > 0)
            {
                MessageBox.Show("This activity cannot be deleted, because of the contributions in the activity.");
                return;
            }
            db.Activities.DeleteOnSubmit(the_activity);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 3; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_activity.id;
            action.object_type = "nature_net.Activity"; action.technical_info = the_activity.technical_info;
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            MessageBox.Show("Removed from the local database. It will be synced once (Local -> Server) is enabled.");
        }
Пример #3
0
        private void button_update_activity_Click(object sender, EventArgs e)
        {
            if (cached_activities.Count == 0)
            {
                MessageBox.Show("Please refresh the activities list.");
                return;
            }
            if (comboBox_activities.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an activity.");
                return;
            }
            if (textBox_activity_name.Text == "" || textBox_activity_description.Text == "")
            {
                MessageBox.Show("Please fill the name and description textboxes.");
                return;
            }
            int id = cached_activities[comboBox_activities.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from u in db.Activities
                             where u.id == id
                             select u;

            if (activities.Count() != 1)
            {
                MessageBox.Show("Error. Activity not found.");
                return;
            }
            Activity the_activity = activities.Single <Activity>();

            the_activity.name        = textBox_activity_name.Text;
            the_activity.description = textBox_activity_description.Text;
            the_activity.avatar      = textBox_activity_icon_url.Text;
            sync.classes.Action action = new classes.Action();
            action.type_id     = 2; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_activity.id;
            action.object_type = "nature_net.Activity"; action.technical_info = "Updating name/desc.";
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            MessageBox.Show("Updated in the local database. It will be synced once (Local -> Server) is enabled.");
        }
Пример #4
0
        private void button_remove_idea_Click(object sender, EventArgs e)
        {
            if (cached_ideas.Count == 0)
            {
                MessageBox.Show("Please refresh the ideas list.");
                return;
            }
            if (comboBox_ideas.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an idea.");
                return;
            }
            int id = cached_ideas[comboBox_ideas.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var ideas = from u in db.Contributions
                        where u.id == id
                        select u;

            if (ideas.Count() != 1)
            {
                MessageBox.Show("Error. Design idea not found.");
                return;
            }
            Contribution the_idea = ideas.Single <Contribution>();
            var          mappings = from m in db.Collection_Contribution_Mappings
                                    where m.contribution_id == the_idea.id
                                    select m;

            db.Collection_Contribution_Mappings.DeleteAllOnSubmit(mappings);
            db.Contributions.DeleteOnSubmit(the_idea);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 3; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_idea.id;
            action.object_type = "nature_net.Contribution"; action.technical_info = the_idea.technical_info;
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
        }
Пример #5
0
        private void button_update_affiliation_Click(object sender, EventArgs e)
        {
            if (cached_users.Count == 0)
            {
                MessageBox.Show("Please refresh the users list.");
                return;
            }
            if (comboBox_users.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a user.");
                return;
            }
            int id = cached_users[comboBox_users.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var users = from u in db.Users
                        where u.id == id
                        select u;

            if (users.Count() != 1)
            {
                MessageBox.Show("Error. User not found.");
                return;
            }
            User the_user = users.Single <User>();

            the_user.affiliation = textBox_affiliation.Text;
            sync.classes.Action action = new classes.Action();
            action.type_id     = 2; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_user.id;
            action.object_type = "nature_net.User"; action.technical_info = "Updating affiliation.";
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
        }
Пример #6
0
        private void button_add_activity_Click(object sender, EventArgs e)
        {
            if (textBox_activity_name.Text == "" || textBox_activity_description.Text == "")
            {
                MessageBox.Show("Please fill the name and description textboxes.");
                return;
            }
            Activity a = new Activity();

            a.name        = textBox_activity_name.Text;
            a.description = textBox_activity_description.Text;
            a.avatar      = textBox_activity_icon_url.Text;
            a.avatar      = ""; a.creation_date = DateTime.UtcNow; a.location_id = 0;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();

            db.Activities.InsertOnSubmit(a);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 1; action.user_id = 0; action.date = DateTime.UtcNow;
            action.object_type = "nature_net.Activity"; action.technical_info = "Adding an activity.";
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            action.object_id = a.id;
            db.Actions.InsertOnSubmit(action);
            db.SubmitChanges();
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            MessageBox.Show("Added to the local database. It will be synced once (Local -> Server) is enabled.");
        }