Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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;
            //}
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        private void getUniversity()
        {
            MongoDatabase database = MongoService.getDatabase();

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