Section II: ExtJS call WCF Series-----paging sorted list implementation

Source: Internet
Author: User

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;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.