/// <summary> /// 获取序列 /// </summary> /// <param name="seqName">序列名:如果 序列名=SEQ_实体类名,则可以不传入参数</param> /// <returns></returns> internal int GetSequence(string seqName = "") { string strSeqName = ""; int seq = -1; try { if (seqName == null || seqName.Equals("")) { strSeqName = "SEQ_" + typeof(T).Name; } else { strSeqName = seqName; } string sql = "select " + strSeqName + ".nextval from dual"; var result = dbl.GetSingle(sql); if (result != null) { seq = Convert.ToInt32(result); } } catch (Exception ex) { LogHelper.WriteLog(ex); } return(seq); }
/// <summary> /// 查询显示分页数据.返回json字符串(包含列表数据和总数据量数据,配合easyui使用),根据实体对象生成条件. /// </summary> /// <param name="strTable">表名</param> /// <param name="pageCurrent">当前页</param> /// <param name="pageSize">每页显示的数量</param> /// <param name="order">排序字段:如果不需要排序可不传入数据,也可以传入null或者"";如果需要排序则写入order by之后的内容</param> /// <param name="strCondition">条件,需要填写where</param> /// <param name="columnName">列名,默认为*,查询所有</param> /// <returns></returns> public string SelectPageToJSONBySQL(string strTable, int pageCurrent, int pageSize = 10, string order = "", String strCondition = "", string columnName = "*") { string sql = ""; string countSql = ""; try { string strOrder = InternalBase <T> .AddOrder(order);//获取排序字段. sql = this.GetSelectSql(strTable, pageCurrent, pageSize, strOrder, strCondition, columnName); int number = (pageCurrent - 1) * pageSize; DataTable dt = this.SelectBySQL(sql); countSql = "select count (*) from " + strTable + strCondition; var pageCount = dbl.GetSingle(countSql); return(JSONHelper.ObjectToJson(new { total = pageCount, rows = dt })); } catch (Exception ex) { LogHelper.WriteLog(ex, sql + "\r\n" + countSql); return(""); } }
/// <summary> /// 查询显示分页数据.返回json字符串(包含列表数据和总数据量数据,配合easyui使用).根据字典生成条件,用于时间条件为时间段时. /// </summary> /// <param name="dic">保存条件的字典,key为字段名称,关键字:数据库字段名__q(时间起),数据库字段名__z(时间止),数据库字段名__or(条件为or),数据库字段名__like(查询为like)</param> /// <param name="order">排序字段:如果不需要排序可不传入数据,也可以传入null或者"";如果需要排序则写入order by之后的内容</param> /// <param name="pageCurrent">当前页</param> /// <param name="pageSize">每页显示的数量</param> /// <param name="tableName">表名</param> /// <param name="columnName">列名,默认为*,查询所有</param> /// <returns></returns> public string SelectPageToJSON(Dictionary <string, object> dic, String order, int pageCurrent, int pageSize = 10, string tableName = "", string columnName = "*") { string sql = string.Empty; string countSql = string.Empty; try { string strTable = InternalBase <T> .GetTableName(tableName); string strCondition = InternalBase <T> .GetConditionByDIC(dic); DataTable dt = SelectPage(dic, order, pageCurrent, pageSize, tableName, columnName);// dbl.ExecuteQuery(sql); countSql = "select count (*) from " + strTable + strCondition; var pageCount = dbl.GetSingle(countSql); return(JSONHelper.ObjectToJson(new { total = pageCount, rows = dt })); } catch (Exception ex) { LogHelper.WriteLog(ex, sql + "\r\n" + countSql); return(""); } }