Пример #1
0
        /// <summary>
        /// 根据条件查询表
        /// </summary>
        /// <param name="dbHelper">数据库帮助类</param>
        /// <param name="tableStructure">表结构</param>
        /// <param name="fieldClass">条件筛选的字段</param>
        /// <param name="fieldValue">条件筛选的字段值,可空</param>
        /// <param name="orderByString">排序语句,此值为null时根据UPDATEDATE排序</param>
        /// <returns></returns>
        public static DataTable QueryTable(DbHelper dbHelper, TableStructure tableStructure, FieldClass fieldClass, string fieldValue, string orderByString)
        {
            string whereClause = null;

            if (!string.IsNullOrEmpty(fieldValue))
            {
                if (fieldClass.FieldType == typeof(string))
                {
                    whereClause = $"{fieldClass.Name} like '%{fieldValue}%'";
                }
                else if (fieldClass.FieldType == typeof(DateTime))
                {
                    whereClause = $"{fieldClass.Name} = #{fieldValue}#";
                }
                else
                {
                    whereClause = $"{fieldClass.Name} = {fieldValue}";
                }
            }
            return(QueryTable(dbHelper, tableStructure, whereClause, orderByString));
        }
Пример #2
0
 /// <summary>
 /// 获取指定字段对应字典表的指定名称对应的编码
 /// </summary>
 /// <param name="tableFields"></param>
 /// <param name="fieldName">表中的字段,该字段关联字典表</param>
 /// <param name="name">字典表中的值(即名称)</param>
 /// <returns></returns>
 public static string GetDictionaryCode(this TableStructure tableFields, string fieldName, string name)
 {
     return(tableFields.Fields.First(v => v.Name.Equals(fieldName)).DictionaryTable.CodeNameDict.FirstOrDefault(v => v.Value.Equals(name)).Key);
 }
Пример #3
0
 /// <summary>
 /// 获取指定字段对应字典表的全部值(名称)
 /// </summary>
 /// <param name="tableFields">表</param>
 /// <param name="fieldName">表中的字段,该字段关联字典表</param>
 /// <returns></returns>
 public static string[] GetDictionaryValues(this TableStructure tableFields, string fieldName)
 {
     return(tableFields.Fields.First(v => v.Name.Equals(fieldName)).DictionaryTable.CodeNameDict.Values.ToArray());
 }
Пример #4
0
        /// <summary>
        /// 根据条件查询表
        /// </summary>
        /// <param name="dbHelper">数据库帮助类</param>
        /// <param name="tableStructure">表结构</param>
        /// <param name="fieldName">条件筛选的字段</param>
        /// <param name="fieldValue">条件筛选的字段值,可空</param>
        /// <param name="orderbyString">排序语句,此值为null时根据UPDATEDATE排序</param>
        /// <returns></returns>
        public static DataTable QueryTable(DbHelper dbHelper, TableStructure tableStructure, string fieldName, string fieldValue, string orderbyString)
        {
            FieldClass fieldClass = tableStructure.Fields.FirstOrDefault(v => v.Name == fieldName);

            return(QueryTable(dbHelper, tableStructure, fieldClass, fieldValue, orderbyString));
        }