Пример #1
0
        private void showData()
        {
            MongoDatabase database = MongoService.getDatabase();

            var collection           = database.GetCollection <Animal>("Animals");
            var universityCollection = database.GetCollection <University>("University");

            var query1 = from University in universityCollection.AsQueryable <University>()
                         where University.Name == university
                         select University;

            u = query1.First();



            list.Items.Clear();

            foreach (MongoDBRef tmpRef in u.generatedData)
            {
                Animal tmp = database.FetchDBRefAs <Animal>(tmpRef);
                Topic  t   = database.FetchDBRefAs <Topic>(tmp.topic);
                list.Items.Add((list.Items.Count + 1) + ". " + tmp.name + ", date: " + tmp.date +
                               "  -  topic:" + t.name);
            }
        }
Пример #2
0
        private void btnDeleteTopic_Click(object sender, EventArgs e)
        {
            if (comboTopic.SelectedItem == null)
            {
                MessageBox.Show("Pick a topic");
                return;
            }

            MongoDatabase database = MongoService.getDatabase();

            var collection      = database.GetCollection <Animal>("Animals");
            var topicCollection = database.GetCollection <Topic>("Topics");


            var query1 = from Topics in topicCollection.AsQueryable <Topic>()
                         where Topics.name == comboTopic.SelectedItem.ToString()
                         select Topics;

            Topic t = query1.First();

            //foreach (MongoDBRef animalRef in university.generatedData)
            //{
            //    Animal tmp = database.FetchDBRefAs<Animal>(animalRef);
            //    //MessageBox.Show(tmp.name);
            //    collection.Remove(Query.EQ("_id", tmp.Id));
            //}

            topicCollection.Remove(Query.EQ("_id", t.Id));
        }
Пример #3
0
        private void comboProp_SelectedIndexChanged(object sender, EventArgs e)
        {
            MongoDatabase database = MongoService.getDatabase();

            Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]);

            lblName.Text = animal.name;
            lblDate.Text = animal.date.ToShortDateString();

            textPropName.Text  = animal.properties[comboProp.SelectedIndex].Name;
            textPropValue.Text = animal.properties[comboProp.SelectedIndex].Value;
        }
Пример #4
0
        public void getTopics()
        {
            MongoDatabase database       = MongoService.getDatabase();
            var           topicCollecion = database.GetCollection <Topic>("Topics");


            comboTopic.Items.Clear();
            foreach (Topic t in topicCollecion.FindAll())
            {
                comboTopic.Items.Add(t.name);
            }
        }
Пример #5
0
        public void getUniversities()
        {
            MongoDatabase database = MongoService.getDatabase();

            var collecion = database.GetCollection <University>("University");


            comboUniversity.Items.Clear();
            foreach (University u in collecion.FindAll())
            {
                comboUniversity.Items.Add(u.Name);
            }
        }
Пример #6
0
        private void list_MouseClick(object sender, MouseEventArgs e)
        {
            if (list.SelectedItem == null)
            {
                return;
            }

            MongoDatabase database = MongoService.getDatabase();

            Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]);

            lblName.Text = animal.name;
            lblDate.Text = animal.date.ToShortDateString();

            addComboData(animal);
        }
Пример #7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            MongoDatabase database = MongoService.getDatabase();

            var collection           = database.GetCollection <Animal>("Animals");
            var UniversityCollection = database.GetCollection <University>("University");

            MongoDBRef animalRef = u.generatedData[list.SelectedIndex];
            Animal     animal    = database.FetchDBRefAs <Animal>(animalRef);


            u.generatedData.RemoveAt(list.SelectedIndex);
            UniversityCollection.Save(u);
            collection.Remove(Query.EQ("_id", animal.Id));
            showData();
        }
Пример #8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (comboTopic.SelectedItem == null)
            {
                MessageBox.Show("Pick a topic");
                return;
            }

            if (textName.TextLength < 1)
            {
                MessageBox.Show("Enter name");
                return;
            }

            MongoDatabase database = MongoService.getDatabase();

            var collection           = database.GetCollection <Animal>("Animals");
            var topicCollecion       = database.GetCollection <Topic>("Topics");
            var universityCollection = database.GetCollection <University>("University");

            var query1 = from Topics in topicCollecion.AsQueryable <Topic>()
                         where Topics.name == comboTopic.SelectedItem.ToString()
                         select Topics;

            Topic t = query1.First();


            Animal a = new Animal
            {
                name       = this.textName.Text,
                date       = this.dateTime.Value,
                properties = tmpProps,
                topic      = new MongoDBRef("Topics", t.Id),
                //university = new MongoDBRef("University", university.Id)
            };

            collection.Insert <Animal>(a);

            university.generatedData.Add(new MongoDBRef("Animals", a.Id));

            //topicCollecion.Save(t);
            universityCollection.Save(university);

            tmpProps.Clear();
            listProp.Items.Clear();
            textName.Clear();
        }
Пример #9
0
        private void btnAddProp_Click(object sender, EventArgs e)
        {
            if (textPropName.TextLength < 1 || textPropValue.TextLength < 1)
            {
                MessageBox.Show("Enter property");
                return;
            }
            MongoDatabase database   = MongoService.getDatabase();
            var           collection = database.GetCollection <Animal>("Animals");

            Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]);

            animal.properties.Add(new Property {
                Name = textPropName.Text, Value = textPropValue.Text
            });
            collection.Save(animal);
            addComboData(animal);
        }
Пример #10
0
        private void showData()
        {
            MongoDatabase database = MongoService.getDatabase();

            var collection      = database.GetCollection <Animal>("Animals");
            var topicCollection = database.GetCollection <Topic>("Topics");

            var query1 = from Topics in topicCollection.AsQueryable <Topic>()
                         where Topics.name == topic
                         select Topics;

            t = query1.First();

            //var query = from Animals in collection.AsQueryable<Animal>()
            //             where Animals.properties
            //             select Animals;

            //foreach(Animal a in query)
            //{
            //    MessageBox.Show(a.name);
            //}



            //list.Items.Clear();

            List <Animal> lista = new List <Animal>();

            List <IMongoQuery> queries = new List <IMongoQuery>();

            queries.Add(Query.EQ("topic.$id", t.Id));

            foreach (Animal tmp in collection.Find(Query.And(queries)))
            {
                Topic t = database.FetchDBRefAs <Topic>(tmp.topic);
                lista.Add(tmp);
            }

            list.DataSource    = lista;
            list.DisplayMember = "name";
            list.ValueMember   = "Id";
        }
Пример #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textTopicName.Text.Length < 1)
            {
                MessageBox.Show("Enter topic name");
                return;
            }

            MongoDatabase database = MongoService.getDatabase();

            var topicCollecion = database.GetCollection <Topic>("Topics");

            Topic t = new Topic {
                name = textTopicName.Text
            };

            topicCollecion.Insert <Topic>(t);

            parent.getTopics();
            this.Close();
        }
Пример #12
0
        private void list_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (list.SelectedItem == null)
            {
                return;
            }

            MongoDatabase database = MongoService.getDatabase();

            var    collection = database.GetCollection <Animal>("Animals");
            Animal animal     = collection.FindOne(Query.EQ("_id", ObjectId.Parse(list.SelectedValue.ToString())));

            String props  = "";
            int    brojac = 1;

            foreach (Property tmp in animal.properties)
            {
                props += " " + brojac + ". " + tmp.Name + ":  " + tmp.Value + "   \n";
                brojac++;
            }

            //MessageBox.Show(list.SelectedItem.ToString());
            MessageBox.Show(props, animal.name + " properties", MessageBoxButtons.OK);
        }
Пример #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            MongoDatabase database   = MongoService.getDatabase();
            var           collection = database.GetCollection <Animal>("Animals");

            Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]);

            if (textName.TextLength > 0)
            {
                animal.name = textName.Text;
            }
            animal.date = dateTime.Value;

            if (textPropName.TextLength > 0 && textPropValue.TextLength > 0)
            {
                animal.properties[comboProp.SelectedIndex].Name  = textPropName.Text;
                animal.properties[comboProp.SelectedIndex].Value = textPropValue.Text;
            }

            collection.Save(animal);

            clearAll();
            showData();
        }
Пример #14
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            MongoDatabase database = MongoService.getDatabase();

            var collection      = database.GetCollection <Animal>("Animals");
            var topicCollection = database.GetCollection <Topic>("Topics");

            int dataCount = 9999999;

            List <IMongoQuery> queries = new List <IMongoQuery>();

            queries.Add(Query.EQ("topic.$id", t.Id));

            if (textCount.TextLength > 0)
            {
                dataCount = Int32.Parse(textCount.Text);
            }

            if (textNoPops.TextLength > 0)
            {
                queries.Add(Query.Size("properties", Int32.Parse(textNoPops.Text)));
            }

            if (textName.TextLength > 0)
            {
                queries.Add(Query.EQ("name", textName.Text));
            }

            if (rbProp.Checked && textPropName.TextLength > 0 && textPropValue.TextLength > 0)
            {
                //db.collection.find( { {properties : {Name: }} : { $exists: true } } );
                var jsonQuery = "{ properties : {\"Name\" : \"" + textPropName.Text + "\", \"Value\" : \"" +
                                textPropValue.Text + "\" }}";


                BsonDocument doc = MongoDB.Bson.Serialization
                                   .BsonSerializer.Deserialize <BsonDocument>(jsonQuery);

                queries.Add(new QueryDocument(doc));

                //queries.Add(Query.Find()};
            }

            String text = "";
            int    i    = 1;

            foreach (Animal a in collection.Find(Query.And(queries)).SetLimit(dataCount))
            {
                if (text == "")
                {
                    text += "Topic: " + t.name + System.Environment.NewLine + System.Environment.NewLine;
                }

                text += i + ". Name: " + a.name + ", date: " + a.date + "; \n \t Properties: \n";
                foreach (Property p in a.properties)
                {
                    text += "\t \t Name:" + p.Name + ",  Value: " + p.Value + System.Environment.NewLine;
                }
                text += System.Environment.NewLine;
                i++;
            }

            dataView f = new dataView(text);

            f.Show();
        }
Пример #15
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (textUsername.TextLength < 1)
            {
                MessageBox.Show("Enter username");
                return;
            }
            if (textPass1.TextLength < 1 || textPass2.TextLength < 1)
            {
                MessageBox.Show("Enter password");
                return;
            }
            else
            {
                if (textPass1.Text != textPass2.Text)
                {
                    MessageBox.Show("Passwords does not match");
                    return;
                }
            }
            if (!cbScietist.Checked && !cbUser.Checked)
            {
                MessageBox.Show("Pick a role");
                return;
            }


            MongoDatabase database = MongoService.getDatabase();

            var topicCollecion       = database.GetCollection <User>("User");
            var universityCollection = database.GetCollection <University>("University");

            var queryUser = from User in topicCollecion.AsQueryable()
                            where User.username == textUsername.Text
                            select User;

            if (queryUser.Count() > 0)
            {
                MessageBox.Show("That username already exists");
                textUsername.Text = "";
                return;
            }

            User u;

            if (cbScietist.Checked)
            {
                var query = from University in universityCollection.AsQueryable <University>()
                            where University.Name == comboUniversity.SelectedItem.ToString()
                            select University;

                University uni = query.First();



                u = new Scientist
                {
                    username = textUsername.Text,
                    password = textPass1.Text,
                    //type = "scientist",
                    university = new MongoDBRef("University", uni.Id)
                };
            }
            else
            {
                u = new User
                {
                    username = textUsername.Text,
                    password = textPass1.Text,
                    //type = "user",
                };
            }

            topicCollecion.Insert(u);

            //University u1 = new University { Name = "Univerzitet u Nisu" };
            //University u2 = new University { Name = "Univerzitet u Beogradu" };
            //University u3 = new University { Name = "Univerzitet u Novom Sadu" };

            //universityCollection.Insert<University>(u1);
            //universityCollection.Insert<University>(u2);
            //universityCollection.Insert<University>(u3);

            parent.enableBtn();
            this.Close();
        }
Пример #16
0
        private void logIn_Click(object sender, EventArgs e)
        {
            if (textPassword.TextLength < 1 || TextUsername.TextLength < 1)
            {
                MessageBox.Show("Invalid username/password combination");
                return;
            }

            MongoDatabase database = MongoService.getDatabase();

            var userCollecion = database.GetCollection <Scientist>("User");

            var query = from User in userCollecion.AsQueryable()
                        where User.username == TextUsername.Text
                        select User;

            //var u=userCollecion.FindOne<>(Query.EQ("username", TextUsername.Text));
            //MessageBox.Show(query.GetType().ToString());

            if (query.Count() == 0)
            {
                MessageBox.Show("Invalid username/password combination");
                return;
            }

            //var u=query.First();
            //if(query.GetType()==typeof(Scientist))
            //    var u = query.Cast<>();


            if (query.First().GetType() == typeof(Scientist) && query.First().university != null)
            {
                var u = query.First();

                if (u.password == textPassword.Text)
                {
                    Form1 f = new Form1(this, (Scientist)u);
                    f.Show();
                    clearText();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Invalid username/password combination");
                    return;
                }
            }
            else
            {
                var u = query.First();
                if (u.password == textPassword.Text)
                {
                    devTopic.BackColor = Color.FromArgb(150, 255, 255, 255);
                    lblTopic.Visible   = true;
                    btnTopic.Visible   = true;
                    comboTopic.Visible = true;
                    getTopics();

                    logIn.Enabled        = false;
                    Register.Enabled     = false;
                    textPassword.Enabled = false;
                    TextUsername.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Invalid username/password combination");
                    return;
                }
            }



            //if (u.password==textPassword.Text)
            //{

            //    if (query.GetType() == typeof(User))
            //    {

            //        devTopic.BackColor=Color.FromArgb(150, 255, 255, 255);
            //        lblTopic.Visible = true;
            //        btnTopic.Visible = true;
            //        comboTopic.Visible=true;
            //        getTopics();

            //        logIn.Enabled = false;
            //        Register.Enabled = false;
            //        textPassword.Enabled = false;
            //        TextUsername.Enabled = false;
            //    }
            //    else
            //    {
            //        Form1 f = new Form1(this,(Scientist)u);
            //        f.Show();
            //        clearText();
            //        this.Hide();

            //    }
            //    //Form1 f = new Form1(this);
            //    //f.Show();
            //    //clearText();
            //    //this.Hide();

            //}
            //else
            //{
            //    MessageBox.Show("Invalid username/password combination");
            //    return;
            //}
        }
Пример #17
0
        private void getUniversity()
        {
            MongoDatabase database = MongoService.getDatabase();

            university = database.FetchDBRefAs <University>(logedUser.university);
        }