Beispiel #1
0
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdOK_Click(object sender, EventArgs e)
        {
            MongoCollection mongoCol = SystemManager.GetCurrentCollection();
            IMongoQuery     query    = MongoDBHelper.GetQuery(GroupConditionList);
            GroupByDocument groupdoc = new GroupByDocument();

            foreach (CheckBox item in panColumn.Controls)
            {
                if (item.Checked)
                {
                    groupdoc.Add(item.Name, true);
                }
            }
            BsonDocument Initial = new BsonDocument();

            for (int i = 0; i < _conditionCount; i++)
            {
                ctlAddBsonEl ctl = (ctlAddBsonEl)Controls.Find("BsonEl" + (i + 1).ToString(), true)[0];
                if (ctl.IsSetted)
                {
                    Initial.Add(ctl.getElement());
                }
            }

            BsonJavaScript      reduce    = new BsonJavaScript(txtReduceJs.Text);
            BsonJavaScript      finalize  = new BsonJavaScript(txtfinalizeJs.Text);
            List <BsonDocument> resultlst = new List <BsonDocument>();

            try
            {
                ///SkipCnt Reset
                var Result = mongoCol.Group(query, groupdoc, Initial, reduce, finalize);
                //防止错误的条件造成的海量数据
                int Count = 0;
                foreach (var item in Result)
                {
                    if (Count == 1000)
                    {
                        break;
                    }
                    resultlst.Add(item);
                    Count++;
                }
                ;
                MongoDBHelper.FillJSONDataToTextBox(this.txtResult, resultlst, 0);
                if (Count == 1001)
                {
                    this.txtResult.Text = "Too many result,Display first 1000 records" + System.Environment.NewLine + this.txtResult.Text;
                }
                this.txtResult.Select(0, 0);
                tabGroup.SelectedIndex = 4;
            }
            catch (Exception ex)
            {
                MyMessageBox.ShowMessage("Exception", "Exception is Happened", ex.ToString(), true);
            }
        }
        public void TestGroupByDocumentConstructor()
        {
            var document1 = new GroupByDocument(_dictionary);
            var document2 = new GroupByDocument(_hashtable);
            var document3 = new GroupByDocument(_idictionaryNonGeneric);
            var document4 = new GroupByDocument(_idictionary);

            Assert.AreEqual("Dictionary<string, object>", document1["type"].AsString);
            Assert.AreEqual("Hashtable", document2["type"].AsString);
            Assert.AreEqual("IDictionary", document3["type"].AsString);
            Assert.AreEqual("IDictionary<string, object>", document4["type"].AsString);
        }
Beispiel #3
0
        /// <summary>
        /// GroupByCount
        /// </summary>
        /// <param name="collectionName"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        public static Dictionary <string, int> GroupCount(string collectionName, string FieldName, IMongoQuery query = null)
        {
            MongoCollection col      = GetDatabaseByType(_defaultDatabaseName).GetCollection(collectionName);
            GroupArgs       g        = new GroupArgs();
            var             groupdoc = new GroupByDocument();

            groupdoc.Add(FieldName, true);
            g.KeyFields      = groupdoc;
            g.ReduceFunction = new BsonJavaScript("function(obj,prev){ prev.count++;}");
            g.Initial        = new BsonDocument().Add("count", 0);
            if (query != null)
            {
                g.Query = query;
            }
            var GroupResult = col.Group(g);
            var result      = new Dictionary <string, int>();

            foreach (BsonDocument item in GroupResult)
            {
                result.Add(item.GetElement(FieldName).Value.ToString(), (int)item.GetElement("count").Value.AsDouble);
            }
            return(result);
        }
Beispiel #4
0
        /// <summary>
        ///     确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdOK_Click(object sender, EventArgs e)
        {
            var mongoCol  = RuntimeMongoDbContext.GetCurrentCollection();
            var query     = QueryHelper.GetQuery(GroupConditionList);
            var groupdoc  = new GroupByDocument();
            var chartTite = string.Empty;

            foreach (CheckBox item in panColumn.Controls)
            {
                if (!item.Checked)
                {
                    continue;
                }
                groupdoc.Add(item.Name, true);
                chartTite += item.Name + ",";
            }
            chartTite = chartTite.TrimEnd(",".ToCharArray());
            var initial = new BsonDocument();

            for (var i = 0; i < _conditionCount; i++)
            {
                var ctl = (ctlBsonValueTypeName)Controls.Find("BsonEl" + (i + 1), true)[0];
                if (ctl.IsSetted)
                {
                    initial.Add(ctl.GetElement());
                }
            }

            var reduce    = new BsonJavaScript(ctlReduce.Context);
            var finalize  = new BsonJavaScript(ctlFinalize.Context);
            var resultlst = new List <BsonDocument>();

            try
            {
                //SkipCnt Reset
                var result = mongoCol.Group(query, groupdoc, initial, reduce, finalize);
                //图形化初始化
                chartResult.Series.Clear();
                chartResult.Titles.Clear();
                var seriesResult = new Series("Result");

                //防止错误的条件造成的海量数据
                var count = 0;
                foreach (var item in result)
                {
                    if (count == 1000)
                    {
                        break;
                    }
                    resultlst.Add(item);
                    //必须带有Count元素
                    var dPoint = new DataPoint(0, (double)item.GetElement("count").Value);
                    seriesResult.Points.Add(dPoint);
                    count++;
                }
                ViewHelper.FillJsonDataToTextBox(txtResult, resultlst, 0);
                if (count == 1001)
                {
                    txtResult.Text = "Too many result,Display first 1000 records" + Environment.NewLine + txtResult.Text;
                }
                txtResult.Select(0, 0);
                //图形化加载
                chartResult.Series.Add(seriesResult);
                chartResult.Titles.Add(new Title(chartTite));
                tabGroup.SelectedIndex = 4;
            }
            catch (Exception ex)
            {
                Utility.ExceptionDeal(ex, "Exception", "Exception is Happened");
            }
        }
Beispiel #5
0
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdOK_Click(object sender, EventArgs e)
        {
            MongoCollection mongoCol  = SystemManager.GetCurrentCollection();
            IMongoQuery     query     = MongoDBHelper.GetQuery(GroupConditionList);
            GroupByDocument groupdoc  = new GroupByDocument();
            String          ChartTite = string.Empty;

            foreach (CheckBox item in panColumn.Controls)
            {
                if (item.Checked)
                {
                    groupdoc.Add(item.Name, true);
                    ChartTite += item.Name + ",";
                }
            }
            ChartTite = ChartTite.TrimEnd(",".ToCharArray());
            BsonDocument Initial = new BsonDocument();

            for (int i = 0; i < _conditionCount; i++)
            {
                ctlAddBsonEl ctl = (ctlAddBsonEl)Controls.Find("BsonEl" + (i + 1).ToString(), true)[0];
                if (ctl.IsSetted)
                {
                    Initial.Add(ctl.getElement());
                }
            }

            BsonJavaScript      reduce    = new BsonJavaScript(ctlReduce.Context);
            BsonJavaScript      finalize  = new BsonJavaScript(ctlFinalize.Context);
            List <BsonDocument> resultlst = new List <BsonDocument>();

            try
            {
                ///SkipCnt Reset
                var Result = mongoCol.Group(query, groupdoc, Initial, reduce, finalize);
                //图形化初始化
                chartResult.Series.Clear();
                chartResult.Titles.Clear();
                Series SeriesResult = new Series("Result");

                //防止错误的条件造成的海量数据
                int Count = 0;
                foreach (BsonDocument item in Result)
                {
                    if (Count == 1000)
                    {
                        break;
                    }
                    resultlst.Add(item);
                    //必须带有Count元素
                    DataPoint dPoint = new DataPoint(0, (double)item.GetElement("count").Value);
                    SeriesResult.Points.Add(dPoint);
                    Count++;
                }
                ;
                MongoDBHelper.FillJSONDataToTextBox(this.txtResult, resultlst, 0);
                if (Count == 1001)
                {
                    this.txtResult.Text = "Too many result,Display first 1000 records" + System.Environment.NewLine + this.txtResult.Text;
                }
                this.txtResult.Select(0, 0);
                //图形化加载
                chartResult.Series.Add(SeriesResult);
                chartResult.Titles.Add(ChartTite);
                tabGroup.SelectedIndex = 4;
            }
            catch (Exception ex)
            {
                SystemManager.ExceptionDeal(ex, "Exception", "Exception is Happened");
            }
        }