저장 프로세스 페이지 나누기 간단한 예
저장 프로시저:
- set ANSI_NULLS ON
- set QUOTED_IDENTIFIER ON
- go
-
- /*
- Descript:
- Author:Blue.Dream
- Date:2004-8-18 21:01
- */
- ALTER PROCEDURE [dbo].[ListPage](
- @tblName nvarchar(200), ----
- @fldName nvarchar(200) = '*', ----
- @pageSize int = 10, ----
- @page int = 1, ----
- @pageCount int = 1 output, ----]
- @Counts int = 1 output, ----
- @fldSort nvarchar(100) = null, ----
- @Sort bit = 0, ---- ,0 ,1
- @strCondition nvarchar(200) = null, ---- , where
- @ID nvarchar(50) ----
- )
- AS
- SET NOCOUNT ON
- Declare @sqlTmp nvarchar(1000) ---- SQL
- Declare @strTmp nvarchar(1000) ----
- Declare @strID nvarchar(1000) ---- ID
- Declare @sqlSort nvarchar(200) ----
- Declare @intCounts int ----
- Declare @BeginID int ---- ID
- Declare @EndID int ---- ID
-
-
-
- -------- ---------
- if @Sort=0 --
- begin
- if not(@fldSort is null)
- set @sqlSort = ' Order by ' + @fldSort
- else
- set @sqlSort = ' Order by ' + @ID
- end
- else --
- begin
- if not(@fldSort is null)
- set @sqlSort = ' Order by ' + @fldSort + ' DESC'
- else
- set @sqlSort = ' Order by ' + @ID + ' DESC '
- end
-
-
- -------- --------
- -- @strTmp
- if @strCondition is null --
- begin
- set @sqlTmp = @fldName + ' From ' + @tblName
- set @strTmp = 'select @Counts=Count(' + @ID + ') FROM '+@tblName
- set @strID = ' From ' + @tblName
- end
- else
- begin
- set @sqlTmp = + @fldName + ' From ' + @tblName
- set @strTmp = 'select @Counts=Count(' + @ID + ') FROM '+@tblName + ' where ' + @strCondition
- set @strID = ' From ' + @tblName + ' where ' + @strCondition
- end
-
-
-
- ---- -----
- exec sp_executesql @strTmp,N'@Counts int out ',@Counts out
-
- --
- if @Counts <= @pageSize
- set @pageCount = 1
- else
- set @pageCount = (@Counts / @pageSize) + 1
-
-
- --
- if @page = 1
- set @intCounts = @pageSize
- else
- begin
- set @intCounts = (@page-1) * @pageSize + 1
- end
-
- ----- ID
- set @strID = 'select @BeginID=' + @ID + ' ' + @strID
-
-
-
- set @intCounts = @intCounts - @pageSize + 1
- set rowcount @intCounts
- exec sp_executesql @strID,N'@BeginID int out ',@BeginID out
-
- ----- ID
- set @intCounts = @intCounts + @pageSize - 1
- print @intCounts
- set rowcount @intCounts
- exec sp_executesql @strID,N'@BeginID int out ',@EndID out
-
-
- ------ -----
- set rowcount 0
- SET NOCOUNT OFF
-
- ------ -----
- if @strCondition is null
- set @strTmp = 'select ' + @sqlTmp + ' where ' + @ID + ' between ' + str(@BeginID) + ' and ' + str(@EndID)
- else
- set @strTmp = 'select ' + @sqlTmp + ' where ' + @ID +' between ' + str(@BeginID) + ' and ' + str(@EndID) + ' and ' + @strCondition
-
- if not(@sqlSort is null)
- set @strTmp = @strTmp + @sqlSort
- exec sp_executesql @strTmp
-
dal 레이어 호출:
- public DataTable Select(string LDXX, string ZXBH, string JTBZ, string CLBZ, string KSSJ, string JSSJ, int CurrentPageIndex, string orderPX, out int count, out int totlepage)
- {
-
- StringBuilder strSql = new StringBuilder();
- StringBuilder strtj = new StringBuilder();
- StringBuilder st = new StringBuilder();
-
- if (!string.IsNullOrEmpty(ZXBH))
- {
-
- strtj.Append(" ZXBH = " + int.Parse(ZXBH) + " and ");
-
- }
-
- if (!string.IsNullOrEmpty(JTBZ))
- {
- strtj.Append(" JTBZ = " + JTBZ + " and ");
-
- }
- if (!string.IsNullOrEmpty(CLBZ))
- {
- strtj.Append(" CLBZ = " + CLBZ + " and ");
-
- }
-
- if (!string.IsNullOrEmpty(KSSJ))
- {
-
- strtj.Append(" LDSJ >='" + DateTime.Parse(KSSJ) + "' and ");
-
- }
- if (!string.IsNullOrEmpty(JSSJ))
- {
-
- strtj.Append(" LDSJ >='" + DateTime.Parse(JSSJ) + "' and ");
-
- }
-
- if (!string.IsNullOrEmpty(LDXX))
- {
- strtj.Append(" LDXX like '%" + LDXX + "%' and ");
-
- }
- strtj.Append(" 11=1 ");
-
- string strname = "procPageL";
-
- SqlParameter[] listp = {
- new SqlParameter("@TableName",SqlDbType.VarChar,200),
- new SqlParameter("@ReFieldsStr",SqlDbType.VarChar,200),
- new SqlParameter("@OrderString",SqlDbType.VarChar,200),
- new SqlParameter("@WhereString",SqlDbType.VarChar,200),
- new SqlParameter("@pageSize",SqlDbType.Int,4),
- new SqlParameter("@PageIndex",SqlDbType.Int,4),
- new SqlParameter("@TotalRecord",SqlDbType.Int,4) };
- int perpage = 10;
- listp[0].Value = "HW_HRXX";
- listp[1].Value = "JGBH,HJBH,LDXX,ZXBH,LDSJ,JTSJ,JTBZ,XYSC,CLBZ,ZXYY,CLSJ,THSC,JRFS,ZJSJ,GJSJ ";
- if (!string.IsNullOrEmpty(orderPX))
- {
- listp[2].Value = orderPX;
- }
- else
- {
- listp[2].Value = "HJBH DESC";
- }
-
- listp[3].Value = strtj.ToString();
- listp[4].Value = perpage;
- listp[5].Value = CurrentPageIndex;
- listp[6].Direction = ParameterDirection.Output;
-
- DataTable dt = DbHelperSQL.RunProcedure(strname, listp).Tables[0];
- totlepage = perpage;
- count = int.Parse(listp[6].Value.ToString());
-
- return dt;
-
- }
페이지 나누기 방법
- /// <summary>
- ///
- /// summary>
- /// <param name="count"> param>
- /// <param name="Curpage"> param>
- /// <param name="pageSize"> param>
- /// <param name="url">urlparam>
- /// <param name="pagetag">pageparam>
- /// <returns>returns>
- public static string GetPageCode(int count, int Curpage, int pageSize, string url, string pagetag)
- {
- bool mark = false;
- if (pagetag == "")
- pagetag = "page";
- if (url.Contains("type"))
- {
- urlurl = url.Substring(0, url.LastIndexOf("type"));
- }
- if (url.Contains(pagetag))// page
- {
- mark = true;
- }
-
- if (url.IndexOf('?') > 0)//
- urlurl = url + "&";
- else
- urlurl = url + "?";
- if (mark)// page
- {
- urlurl = url.Substring(0, url.LastIndexOf(pagetag));
- }
- int countPage = (count % pageSize) == 0 ? count / pageSize : count / pageSize + 1;
- int priPage = ((Curpage - 1)) > 0 ? (Curpage - 1) : 1;
- int lastPage = ((Curpage + 1)) < countPage ? (Curpage + 1) : countPage;
-
-
- string link = ";
- string code = link + " onClick=qq(1)> a> " + link + "onClick=qq(" + priPage.ToString() + ")> a> " + link + "onClick=qq(" + lastPage.ToString() + ")> a> " + link + "onClick=qq(" + countPage.ToString() + ")> a> :" + Curpage.ToString() + "/" + countPage + " " + count.ToString() + " ";
-
- code += "<select action='page' onchange=qq(this.value)>";
- for (int i = 1; i <= countPage; i++)
- {
- string selected = "";
- if (Curpage == i)
- selected = "selected='selected'";
- code += string.Format("<option value='{0}' {2}>{0}/{1}option>", i, countPage, selected);
- }
- code += "select>";
-
- return code;
- }
페이지 백그라운드 구현:
- DataTable dt = fwlog.Select(ldxx,zxbh,jtbz,clbz, kssj, jssj, page,orderPX,out count ,out totlepage);
- StringBuilder st = new StringBuilder();
- st.Append(" <table width='98%' align='center' border='1' align='center' cellpadding='3' cellspacing='0' style='border-collapse: collapse' class='TableBorderStyle' >");
- st.Append("<tr class='TableTRBgStyle'>");
-
- st.AppendFormat("<td align='center' > td>");
- st.AppendFormat("<td align='center' > td>");
- st.AppendFormat("<td align='center' > td>");
- st.AppendFormat("<td align='center' > td>");
- st.AppendFormat("<td align='center' > td>");
- st.AppendFormat("<td align='center' > td>");
- st.AppendFormat("<td align='center' > td>");
- st.AppendFormat("<td align='center' > td>");
-
-
- st.Append("tr>");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
-
- st.AppendFormat("<tr>");
- st.AppendFormat("<td width='40%' align='center' >{0}td>", dt.Rows[i]["HJBH"]);
- st.AppendFormat("<td width='40%' align='center' >{0}td>", dt.Rows[i]["LDXX"]);
- st.AppendFormat("<td width='40%' align='center' >{0}td>", dt.Rows[i]["LDSJ"]);
- st.AppendFormat("<td width='40%' align='center' >{0}td>", dt.Rows[i]["ZXBH"]);
- if (dt.Rows[i]["ZXBH"].ToString() == "")
- {
- st.AppendFormat("<td width='10%' align='center' >{0}td>", dt.Rows[i]["ZXBH"]);
- }
- else
- {
- st.AppendFormat("<td width='10%' align='center'>{0}td>", tool.GetCZYMCbyID(int.Parse(dt.Rows[i]["ZXBH"].ToString())));
- }
- st.AppendFormat("<td width='40%' align='center' >{0}td>", tool.GetDMName("CLBZ", dt.Rows[i]["CLBZ"].ToString()));
- if (dt.Rows[i]["CLBZ"].ToString() == "0" || dt.Rows[i]["CLBZ"].ToString() == "2")
- {
-
- st.AppendFormat("<td width='30%' align='center' ><img src='../../../p_w_picpaths/txt.gif' onclick='dd()' id='{0}'>td>", dt.Rows[i]["HJBH"]);
- }
- else
- {
- st.AppendFormat("<td width='30%' align='center' ><img src='../../../p_w_picpaths/txt.gif' onclick='tt({0})' id='{0}'>td>", dt.Rows[i]["HJBH"]);
- }
- //st.AppendFormat("<td width='30%' align='center' ><img src='F:\\haiyan\\kfzx\\p_w_picpaths\\cc.ico' onclick='tt({0},{1})' id='{0}'>td>",dt.Rows[i]["HJBH"],dt.Rows[i]["CLBZ"]);
- st.AppendFormat("<td width='30%' align='center' ><img src='../../../p_w_picpaths/clbtn.gif'>td>");
-
- st.Append("tr>");
- }
- st.Append("<tr class='TableBottom'>");
- st.Append(" <td colspan='8'><center>" + tool.GetPageCode(fwlog.Count(ldxx ,zxbh ,jtbz,clbz, kssj, jssj), page, 10, "", "") + "center>td>");
- st.Append("tr>");
- st.Append("table>");
- pagestr = st.ToString();
페이지 프론트 데스크톱에서 비동기 리셋:
- //========= =====================
- function qq(dat)
- {
- q=dat;
- $.get("ym_zxxt_ywsl_ldjl_selcet.aspx?z="+z,{cur:dat,LDXX:$("#LDXX").val()},function(data){
- $("#select").html(data);
- })
- z++;
- }
비교적 간단한 코드는 해설을 많이 하지 않아서 쉽게 알아볼 수 있어요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
양식 제출 후 제출 버튼 비활성화텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.