Example #1
0
        /// <summary>
        /// ACCESS高效分页
        /// </summary>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">分页容量</param>
        /// <param name="strKey">主键</param>
        /// <param name="showString">显示的字段</param>
        /// <param name="queryString">查询字符串,支持联合查询</param>
        /// <param name="whereString">查询条件,若有条件限制则必须以where 开头</param>
        /// <param name="orderString">排序规则</param>
        /// <param name="pageCount">传出参数:总页数统计</param>
        /// <param name="recordCount">传出参数:总记录统计</param>
        /// <returns>装载记录的DataTable</returns>
        public static DataTable ExecutePager(int pageIndex, int pageSize, string strKey, string showString, string queryString, string whereString, string orderString, out int pageCount, out int recordCount)
        {
            if (pageIndex < 1)
            {
                pageIndex = 1;
            }
            if (pageSize < 1)
            {
                pageSize = 10;
            }
            if (string.IsNullOrEmpty(showString))
            {
                showString = "*";
            }
            if (string.IsNullOrEmpty(orderString))
            {
                orderString = strKey + " asc ";
            }
            using (
                CDBAccess cn =
                    new CDBAccess(System.Configuration.ConfigurationSettings.AppSettings["OledbStr"]))
            {
                string myVw = string.Format(" ( {0} ) tempVw ", queryString);

                string sql111 = string.Format(" select count(*) as recordCount from {0} {1}", myVw, whereString);

                recordCount = Convert.ToInt32(cn.ExecScalar(sql111));

                if ((recordCount % pageSize) > 0)
                {
                    pageCount = recordCount / pageSize + 1;
                }
                else
                {
                    pageCount = recordCount / pageSize;
                }
                string sql;
                if (pageIndex == 1)//第一页
                {
                    sql = string.Format("select top {0} {1} from {2} {3} order by {4} ", pageSize, showString, myVw, whereString, orderString);
                }
                else if (pageIndex > pageCount)//超出总页数
                {
                    sql = string.Format("select top {0} {1} from {2} {3} order by {4} ", pageSize, showString, myVw, "where 1=2", orderString);
                }
                else
                {
                    int    pageLowerBound = pageSize * pageIndex;
                    int    pageUpperBound = pageLowerBound - pageSize;
                    string recordIDs      = recordID(string.Format("select top {0} {1} from {2} {3} order by {4} ", pageLowerBound, strKey, myVw, whereString, orderString), pageUpperBound);
                    sql = string.Format("select {0} from {1} where {2} in ({3}) order by {4} ", showString, myVw, strKey, recordIDs, orderString);
                }
                using (DataTable dt = cn.ExecQuery(sql))
                {
                    return(dt);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 动漫app由9miao社团研发,如有问题请登陆http://www.9miao.com/官网
        /// </summary>
        ///



        public void ProcessRequest(HttpContext context)
        {
            CallBackJson json   = new CallBackJson();
            jsonClass    jclass = new jsonClass();

            jclass.Status = "Error";
            jclass.Msg    = "服务器异常";
            try
            {
                string _id   = context.Request.Form["id"];          //小分类id
                string _name = context.Request.Form["name"];        //小分类名称
                string _type = context.Request.Form["type"];        //类型 0修改  1添加
                if (string.IsNullOrEmpty(_name.Trim()))
                {
                    throw new Exception("信息参数未空");
                }
                using (
                    CDBAccess cn =
                        new CDBAccess(System.Configuration.ConfigurationSettings.AppSettings["OledbStr"]))
                {
                    if (_type == "0")
                    {
                        cn.ExecSQL(@"UPDATE T0001 SET C00006=? WHERE C00004=?",
                                   new OleDbParameter[] {
                            new OleDbParameter("@C00003", _name),
                            new OleDbParameter("@C00001", _id)
                        });
                        jclass.Msg = "恭喜你!修改分类成功";
                    }
                    else
                    {
                        string systemid = cn.ExecScalar(@"select max(Val(C00004))+1 from T0001 where C00101 <> 6 ").ToString();
                        if (string.IsNullOrEmpty(systemid))
                        {
                            systemid = "1";
                        }
                        cn.ExecSQL(@"INSERT INTO T0001 (C00004,C00005,C00006,C00101) VALUES (?,?,?,?)",
                                   new OleDbParameter[] {
                            new OleDbParameter("@C00004", systemid),
                            new OleDbParameter("@C00005", ""),
                            new OleDbParameter("@C00006", _name),
                            new OleDbParameter("@C00101", _id)
                        });
                        jclass.Msg = "恭喜你!添加分类成功";
                    }
                    jclass.Status = "Success";
                }
            }
            catch (Exception ex)
            {
                jclass.Msg = ex.Message;
            }
            context.Response.Write(json.Serializer(jclass));
        }