Open the item in the first section and create a new paging.aspx page to implement the pagination list.
This time we use a test database Companyinfodb, which has two tables, departments and employees, and a foreign key association, the database Call takes the LINQ SQLMetal command, and the following command is entered in the Visual Studio 2008 Command prompt: D:\ Program Files\Microsoft Visual Studio 9.0\vc>sqlmetal/conn:server=172.16.1.52;database=companyinfodb;uid=sa;pwd =sa123456/map:c:\linqtemp\companyinfodb.map
/code:c:\linqtemp\companyinfodb.cs/serialization:unidirectional
The generated compayinfo.map files and CompanyInfo.cs files are then added to the project, and System.Data.Linq references are modified, and the web.config Add the location of the database link string and Xmlmappingsource file.
<connectionStrings>
<add name="CompanyInfoDBConnectionString" connectionString="Data Source=172.16.1.52;Initial Catalog=CompanyInfoDB;Persist Security Info=True;User ID=sa;Password=sa123456" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="CompanyInfoDBXmlMappingSource" value="E:\ExtJS\ExtJS调用WCF系列博客源文件\ExtJSAndWCFChapter1\ExtJSAndWCFChapter1\DataBase\CompanyInfoDB.map"/>
</appSettings>
As shown in figure:
For a clearer level, we created a EmployeeBL.cs class file to handle employee business logic, EmpployeeBL.cs's file code is as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
Using System.Data.Linq.Mapping;
Using System.IO;
Using System.Linq.Dynamic;
Using System.Runtime.Serialization;
Namespace ExtJSAndWCFChapter1
{
public class Employeebl
{
Companyinfodb CTX;
Constructors
Public Employeebl ()
{
Xmlmappingsource XMS = Xmlmappingsource.fromxml (File.readalltext (configurationmanager.appsettings[) Companyinfodbxmlmappingsource "]));
CTX = new Companyinfodb (configurationmanager.connectionstrings["companyinfodbconnectionstring"). ConnectionString, XMS);
CTx. Log = Console.Out;
}
public string getemployeepaging (int start, int limit, string sort, string dir)
{
String strjsonsource = "";
var query = from emp in CTX. Employee
Select New
{
EmployeeID = emp. EmployeeID,
Cnname = emp. Cnname,
Sex = emp. Sex,
Age = emp. Age,
Email = emp. Email,
Onworkdate = emp. Onworkdate,
Deptname = emp. Department.cnname
};
query = query. By (sort + "" + dir);
int totalcount = query. Count (); Total number of records
int pagenum = Start/limit; Total pages
int PageSize = limit; Number of records per page
query = query. Skip (PageSize * pagenum). Take (PageSize);
String jsonsource = query. Tojson (); Current page record into JSON format
Strjsonsource = @ "{" "TotalCount" ":" "" + TotalCount + "";
Strjsonsource = Strjsonsource + @ "" "," "EmployeeList" ":" + Jsonsource + "}";
return strjsonsource;
}
}
}