Esempio n. 1
0
        /// <summary>
        /// 添加新模型
        /// </summary>
        public virtual KeyValuePair <bool, string> AddNew()
        {
            Dictionary <string, object> paramList = new Dictionary <string, object>();
            //return new KeyValuePair<bool, string>(false, this.SQLInsert(paramList));
            bool   b_exec;
            string sql = this.SQLInsert(paramList);

            #region 自增属性赋值处理
            Type ttp = this.GetType();
            if (GLB_CACHE_MODELPROPERTYS.ContainsKey(ttp))
            {
                var idfprop = GLB_CACHE_MODELPROPERTYS[ttp].IdentityProperty;
                if (idfprop != null)
                {
                    sql += " SELECT SCOPE_IDENTITY() c";
                    int idfval = Dbop.GetSingleInt(sql, paramList);
                    if (idfval > 0)
                    {
                        PropertySetValue(this, idfprop, idfval);
                        b_exec = true;
                    }
                    else
                    {
                        b_exec = false;
                    }
                    return(new KeyValuePair <bool, string>(b_exec, null));
                }
            }
            #endregion

            b_exec = Dbop.ExecuteSqlSuc(sql, paramList);
            return(new KeyValuePair <bool, string>(b_exec, null));
        }
Esempio n. 2
0
        public DataTable PagingTable(IDbHandle.IDbop dbop, string sql, string sqlOrder, int pagingsize, int pagingnumber, out int rowcount)
        {
            rowcount = dbop.GetSingleInt(string.Format("SELECT COUNT(*) FROM({0}) tmp_tb_pagingt", sql));
            if (rowcount == 0)
            {
                return(new DataTable());
            }
            string pagingSql;

            if (rowcount <= pagingsize)
            {
                // 不接受 PagingNumber 参数 直接查询
                pagingSql = string.Format("{0} {1}", sql, sqlOrder);
            }
            else
            {
                // sql 异常处理
                if (!string.IsNullOrEmpty(sqlOrder) && sqlOrder.IndexOf('.') >= 0)
                {
                    // 剔除字段前缀
                    sqlOrder = Regex.Replace(sqlOrder, "\\s+\\w+[.]", " ");
                    sqlOrder = Regex.Replace(sqlOrder, "[,]\\w+[.]", ",");
                }
                pagingSql =
                    @"WITH tmp_tb_paging AS
 (SELECT *, ROW_NUMBER() OVER ({0})as t_rownumber FROM ({1}) t) 
 SELECT * FROM tmp_tb_paging WHERE t_rownumber between {2} and {3}";
                pagingSql = string.Format(pagingSql,
                                          sqlOrder,
                                          sql,
                                          (pagingnumber - 1) * pagingsize + 1,
                                          pagingnumber * pagingsize);
            }
            return(dbop.GetDataTable(pagingSql));
        }