Exemplo n.º 1
0
 public static long GetCurrentCollectionCount(DataFilter query)
 {
     if (query == null)
     {
         return RuntimeMongoDbContext.GetCurrentCollection().Count();
     }
     var mQuery = GetQuery(query.QueryConditionList);
     return RuntimeMongoDbContext.GetCurrentCollection().Count(mQuery);
 }
Exemplo n.º 2
0
 public FrmGroup(DataFilter mDataFilter, bool isUseFilter)
 {
     InitializeComponent();
     if (mDataFilter.QueryConditionList.Count <= 0 || !isUseFilter) return;
     Text += "[With DataView Filter]";
     foreach (var item in mDataFilter.QueryConditionList)
     {
         GroupConditionList.Add(item);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        ///     将条件转成UI
        /// </summary>
        /// <param name="newDataFilter"></param>
        public void PutQueryToUi(DataFilter newDataFilter)
        {
            var strErrMsg = string.Empty;
            var showColumnList = new List<string>();
            foreach (var item in ColumnList)
            {
                showColumnList.Add(item);
            }
            //清除所有的控件
            var fieldList = newDataFilter.QueryFieldList;
            foreach (var queryFieldItem in newDataFilter.QueryFieldList)
            {
                //动态加载控件
                if (!ColumnList.Contains(queryFieldItem.ColName))
                {
                    strErrMsg += "Display Field [" + queryFieldItem.ColName +
                                 "] is not exist in current collection any more" + Environment.NewLine;
                }
                else
                {
                    showColumnList.Remove(queryFieldItem.ColName);
                }
            }
            foreach (var item in showColumnList)
            {
                strErrMsg += "New Field" + item + "Is Append" + Environment.NewLine;
                //输出配置的初始化
                fieldList.Add(new DataFilter.QueryFieldItem(item));
            }
            Controls.Clear();
            _conditionPos = new Point(5, 0);
            _conditionCount = 0;
            foreach (var queryConditionItem in newDataFilter.QueryConditionList)
            {
                var newCondition = new CtlQueryCondition();
                newCondition.Init(ColumnList);
                _conditionPos.Y += newCondition.Height;
                newCondition.Location = _conditionPos;
                newCondition.ConditionItem = queryConditionItem;
                _conditionCount++;
                newCondition.Name = "Condition" + _conditionCount;
                Controls.Add(newCondition);

                if (!ColumnList.Contains(queryConditionItem.ColName))
                {
                    strErrMsg += queryConditionItem.ColName +
                                 "Query Condition Field is not exist in collection any more" + Environment.NewLine;
                }
            }

            if (strErrMsg != string.Empty)
            {
                MyMessageBox.ShowMessage("Load Exception", "A Exception is happened when loading", strErrMsg, true);
            }
        }
Exemplo n.º 4
0
 public FrmDistinct(DataFilter mDataFilter, bool isUseFilter)
 {
     InitializeComponent();
     if (mDataFilter.QueryConditionList.Count <= 0 || !isUseFilter) return;
     Text += "[With DataView Filter]";
     //直接使用 DistinctConditionList = mDataFilter.QueryConditionList
     //DistinctConditionList是引用类型,在LoadQuery的时候,会改变mDataFilter.QueryConditionList的值
     //进而改变DataViewInfo在TabView上的值
     foreach (var item in mDataFilter.QueryConditionList)
     {
         DistinctConditionList.Add(item);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 private static IMongoQuery GetQuery(DataFilter.QueryConditionInputItem item)
 {
     IMongoQuery query;
     var queryvalue = item.Value.GetBsonValue();
     switch (item.Compare)
     {
         case DataFilter.CompareEnum.Eq:
             query = Query.EQ(item.ColName, queryvalue);
             break;
         case DataFilter.CompareEnum.Gt:
             query = Query.GT(item.ColName, queryvalue);
             break;
         case DataFilter.CompareEnum.Gte:
             query = Query.GTE(item.ColName, queryvalue);
             break;
         case DataFilter.CompareEnum.Lt:
             query = Query.LT(item.ColName, queryvalue);
             break;
         case DataFilter.CompareEnum.Lte:
             query = Query.LTE(item.ColName, queryvalue);
             break;
         case DataFilter.CompareEnum.Ne:
             query = Query.NE(item.ColName, queryvalue);
             break;
         default:
             query = Query.EQ(item.ColName, queryvalue);
             break;
     }
     return query;
 }
Exemplo n.º 6
0
        //http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart(旧网址)
        //http://docs.mongodb.org/manual/reference/sql-comparison/

        /// <summary>
        ///     Convert Query SqlHelper To DataFilter
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="mongoCol"></param>
        /// <returns></returns>
        public static DataFilter ConvertQuerySql(string sql, MongoCollection mongoCol)
        {
            var rtnQuery = new DataFilter();
            sql = sql.Trim();
            //引号中的空格用&nbsp;代替,引号以外的东西小写
            sql = Regular(sql);
            //先将字符串里面的空格统一成单个空格
            //Select    A,B  From   C ->
            //Select A,B From C
            while (sql.Contains("  "))
            {
                sql = sql.Replace("  ", " ");
            }
            //找出Select ,From , Group 
            var sqlToken = sql.Split(" ".ToCharArray());

            var selectStartIndex = -1;
            var fromStartIndex = -1;
            var whereStartIndex = -1;
            var groupByStartIndex = -1;
            var orderByStartIndex = -1;

            for (var i = 0; i < sqlToken.Length; i++)
            {
                switch (sqlToken[i].ToLower())
                {
                    case "select":
                        selectStartIndex = i;
                        break;
                    case "from":
                        fromStartIndex = i;
                        break;
                    case "where":
                        whereStartIndex = i;
                        break;
                    case "group":
                        groupByStartIndex = i;
                        break;
                    case "order":
                        orderByStartIndex = i;
                        break;
                }
            }

            string[] keyWords = {"select", "from", "where", "group", "order"};

            //From - > CollectionName
            GetKeyContent(fromStartIndex, sqlToken, keyWords);

            //Select 设定 必须项
            //Select - > FieldList
            var strSelect = GetKeyContent(selectStartIndex, sqlToken, keyWords);
            if (strSelect == string.Empty)
            {
                return null;
            }
            var columnNameLst = MongoHelper.GetCollectionSchame(mongoCol);
            if (strSelect == "*")
            {
                //Select * 
                foreach (var item in columnNameLst)
                {
                    var field = new DataFilter.QueryFieldItem
                    {
                        ColName = item,
                        IsShow = true,
                        SortType = DataFilter.SortType.NoSort
                    };
                    rtnQuery.QueryFieldList.Add(field);
                }
            }
            else
            {
                //Select A,B,C 
                foreach (var item in strSelect.Split(",".ToCharArray()))
                {
                    var field = new DataFilter.QueryFieldItem
                    {
                        ColName = item,
                        IsShow = true,
                        SortType = DataFilter.SortType.NoSort
                    };
                    rtnQuery.QueryFieldList.Add(field);
                }
            }

            //Where 设定,可选项
            var strWhere = GetKeyContent(whereStartIndex, sqlToken, keyWords);
            if (strWhere != string.Empty)
            {
                rtnQuery.QueryConditionList = SetQueryCondition(strWhere, columnNameLst);
            }

            //Order 设定,可选项
            var strOrder = GetKeyContent(orderByStartIndex, sqlToken, keyWords);
            if (strOrder != string.Empty)
            {
                SetQueryOrder(rtnQuery, strOrder);
            }


            //Group 设定,可选项
            var strGroup = GetKeyContent(groupByStartIndex, sqlToken, keyWords);
            if (strGroup != string.Empty)
            {
                //TODO:Group
            }

            return rtnQuery;
        }
Exemplo n.º 7
0
 /// <summary>
 ///     Order 的设置
 /// </summary>
 /// <param name="currentDataFilter"></param>
 /// <param name="sqlContent"></param>
 private static void SetQueryOrder(DataFilter currentDataFilter, string sqlContent)
 {
     //如果获得了内容,应该是这个样子的 By A ASC,B DES
     //1.删除By By A ASC,B DES -> A Asc,B Des
     sqlContent = sqlContent.Substring(3);
     //2.通过逗号分隔列表
     //A Asc , B Des ->  A Asc
     //                  B Des
     var sortFieldLst = sqlContent.Split(",".ToCharArray());
     //3.分出 Field 和 Order
     foreach (var sortField in sortFieldLst)
     {
         var sortfld = sortField.Trim().Split(" ".ToCharArray());
         for (var i = 0; i < currentDataFilter.QueryFieldList.Count; i++)
         {
             if (currentDataFilter.QueryFieldList[i].ColName.ToLower() == sortfld[0].ToLower())
             {
                 //无参数时候,默认是升序[Can't Modify]QueryFieldList是一个结构体
                 var queryfld = currentDataFilter.QueryFieldList[i];
                 if (sortfld.Length == 1)
                 {
                     queryfld.SortType = DataFilter.SortType.Ascending;
                 }
                 else
                 {
                     queryfld.SortType = sortfld[1].ToLower().StartsWith("d")
                         ? DataFilter.SortType.Descending
                         : DataFilter.SortType.Ascending;
                 }
                 currentDataFilter.QueryFieldList[i] = queryfld;
                 break;
             }
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 ///     Group
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void groupToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var query = new DataFilter();
     Utility.OpenForm(new FrmGroup(query, false), true, true);
 }