Пример #1
0
 /// <summary>
 /// 建構函式。
 /// </summary>
 /// <param name="programDefine">程式定義。</param>
 /// <param name="tableName">資料表名稱。</param>
 /// <param name="selectFields">取回欄位集合字串。</param>
 /// <param name="filterItems">過濾條件項目集合。</param>
 /// <param name="sortFields">排序欄位集合。</param>
 public GTableJoinBuilder(GProgramDefine programDefine, string tableName, string selectFields, GFilterItemCollection filterItems, GSortFieldCollection sortFields)
 {
     ProgramDefine = programDefine;
     TableName     = tableName;
     SelectFields  = selectFields;
     FilterItems   = filterItems;
     SortFields    = sortFields;
 }
Пример #2
0
        /// <summary>
        /// 取得排序欄位集合。
        /// </summary>
        private GSortFieldCollection GetSortFields(GTableDefine tableDefine)
        {
            GSortFieldCollection oSortFields;

            // 取得排序欄位集合複本
            oSortFields = new GSortFieldCollection();
            foreach (GSortField sortField in tableDefine.SortFields)
            {
                oSortFields.Add(sortField.Clone());
            }

            return(oSortFields);
        }
Пример #3
0
        /// <summary>
        /// 建置資料表關連資訊。
        /// </summary>
        /// <param name="programDefine">程式定義。</param>
        /// <param name="tableName">資料表名稱。</param>
        /// <param name="selectFields">取回欄位集合字串。</param>
        /// <param name="filterItems">過濾條件項目集合。</param>
        /// <param name="sortFields">排序欄位集合。</param>
        public void Execute(GProgramDefine programDefine, string tableName, string selectFields, GFilterItemCollection filterItems, GSortFieldCollection sortFields)
        {
            this.ProgramDefine = programDefine;
            this.TableName     = tableName;
            var oBuilder = new GTableJoinBuilder(programDefine, tableName, selectFields, filterItems, sortFields);

            oBuilder.Execute(this);
        }
Пример #4
0
        /// <summary>
        /// 取得排序語法。
        /// </summary>
        /// <param name="helper">資料庫命令輔助類別。</param>
        /// <param name="provider">資料表關連資訊提供者。</param>
        /// <param name="tableDefine">資料表定義。</param>
        /// <param name="sortFields">排序欄位集合。</param>
        private string GetSortCommandText(IDbCommandHelper helper, GTableJoinProvider provider, GTableDefine tableDefine, GSortFieldCollection sortFields)
        {
            StringBuilder oBuilder;
            GFieldDefine  oFieldDefine;
            string        sDbFieldName;
            string        sSortDirection;

            // 無排序欄位則傳回空字串
            if (BaseFunc.IsEmpty(sortFields) || !sortFields.Any())
            {
                return(string.Empty);
            }

            oBuilder = new StringBuilder();
            foreach (GSortField sortField in sortFields)
            {
                // 取得包含資料表別名的欄位名稱
                oFieldDefine = tableDefine.Fields[sortField.FieldName];
                sDbFieldName = provider.GetDbFieldName(helper, oFieldDefine);
                // 排序方式
                sSortDirection = sortField.SortDirection == ESortDirection.Ascending ? "ASC" : "DESC";

                if (oBuilder.Length > 0)
                {
                    oBuilder.Append(", ");
                }
                oBuilder.Append(StrFunc.StrFormat("{0} {1}", sDbFieldName, sSortDirection));
            }
            return(" Order By " + oBuilder.ToString());
        }