/// <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>(); ///SkipCnt的备份 int mSkipCnt = MongoDBHelper.SkipCnt; try { ///SkipCnt Reset MongoDBHelper.SkipCnt = 0; 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.FillDataToTextBox(this.txtResult, resultlst); 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); } ///SkipCnt的还原 MongoDBHelper.SkipCnt = mSkipCnt; }
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); }
/// <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 = (CtlAddBsonEl) 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(chartTite); tabGroup.SelectedIndex = 4; } catch (Exception ex) { Utility.ExceptionDeal(ex, "Exception", "Exception is Happened"); } }
/// <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(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); //图形化初始化 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) { MyMessageBox.ShowMessage("Exception", "Exception is Happened", ex.ToString(), true); } }