Project Experience-retrieval and update operations of EasyUI

Source: Internet
Author: User

What can't be tolerated "?!

For example, the EasyUI framework used in the project is obviously a headache. The EasyUI framework used by the project has encapsulated styles so that developers do not need to consider the specific div and css styles, but they are tossing us over the project. Who said that, the life is endless, and there is no more to go about. Today, we will also take a look at EasyUI's simple operations-add, delete, modify, and query EasyUI.

Business Analysis:

  

1. When the page is loaded, the corresponding records retrieved from the corresponding table or view of the database are displayed on the page;
2. Set the time or pass the failed condition to display the specific data according to the set condition.
3. Click "authenticate" to change the review status and whether to authenticate to "Yes". If you cancel the authentication, change the two to "No;


Function implementation: Query operation: Html code:

<% -- Table display area -- %>
 
 
  
  
<% -- Table title -- %>
  
  
User Name Log title Time Review status Notification Authenticated?
<% -- Toolbar-including searching by time, checking by code, and searching button -- %> time from:To:Machine review: Pass Failed Search authentication cancels authentication // query and transmits data to the background. Array function getQueryParams (queryParams) {var StartTime = $ ("# StartTime "). datebox ("getValue"); var EndTime = $ ("# EndTime "). datebox ("getValue"); // var KeyWord = document. getElementById ("KeyWord "). value; var Category = $ ("# Category "). combobox ("getValue"); queryParams. startTime = StartTime; queryParams. endTime = EndTime; // queryParams. keyWord = KeyWord; queryParams. category = Category; return queryParams;} // Add query parameters and reload table function reloadgrid () {// Add the query parameters directly to the queryParams var queryParams =$ ('# tt '). datagrid ('options '). queryParams; getQueryParams (queryParams); $ ('# tt '). datagrid ('options '). queryParams = queryParams; // transfer value // alert (queryParams. category); $ ("# tt "). datagrid ('reload'); // reload table}


Here are the data display areas and search functional areas encapsulated by EasyUI. Note: 1. the url in the table is 'examineverifylog. ashx/processrequest', which is the general processing program to be referenced.
2. pageSize: 5, pageList: [5, 10, 15, 20] indicates the number of entries displayed on each page.
3. "field: 'Data to bin' is used to bind the fields corresponding to your database. You can set the style center.
4. query the transfer parameter. It must be consistent with the Control ID in the toolbar.

 

General Handler:

// Declare userLogBLL userlog = new userLogBLL (); public void ProcessRequest (HttpContext context) {string command = context. request. queryString ["test"]; if (command = null) {Query (context) ;}if (command = "modify") {Modify (context );} else {Query (context) ;}// the Query displays the public void Query (HttpContext context) {context. response. contentType = "text/plain "; // ======================================== ============================================/// Obtain query conditions: [user ID, start time, end time, Keyword: string category, startTime, endTime; category = startTime = endTime = ""; if (null! = Context. Request. QueryString ["Category"]) {category = context. Request. QueryString ["Category"]. ToString (). Trim ();} if (null! = Context. Request. QueryString ["StartTime"]) {startTime = context. Request. QueryString ["StartTime"]. ToString (). Trim ();} if (null! = Context. request. queryString ["EndTime"]) {endTime = context. request. queryString ["EndTime"]. toString (). trim ();} // ================================================ ============================================/// retrieve paging and sorting information: page size, page number, sorting method, sorting field int pageRows, page; pageRows = 10; page = 1; string order, sort, oderby; order = sort = oderby = ""; if (null! = Context. request. queryString ["rows"]) {pageRows = int. parse (context. request. queryString ["rows"]. toString (). trim ();} if (null! = Context. request. queryString ["page"]) {page = int. parse (context. request. queryString ["page"]. toString (). trim ();} if (null! = Context. Request. QueryString ["sort"]) {order = context. Request. QueryString ["sort"]. ToString (). Trim ();} if (null! = Context. request. queryString ["order"]) {sort = context. request. queryString ["order"]. toString (). trim ();} // ================================================ ==========================================/// combined query statement: condition + sort StringBuilder strWhere = new StringBuilder (); if (category! = "") {StrWhere. AppendFormat ("ExamineSign = '{0}' and", category);} if (startTime! = "") {StrWhere. AppendFormat ("PublishDate >=' {0} 'and", startTime);} if (endTime! = "") {StrWhere. appendFormat ("PublishDate <= '{0}' and", endTime);} // Delete unnecessary and int startindex = strWhere. toString (). lastIndexOf ("and"); // obtain the last and position if (startindex> = 0) {strWhere. remove (startindex, 3); // Delete unnecessary and keywords} if (sort! = "" & Order! = "") {// StrWhere. appendFormat ("order by {0} {1}", sort, order); // Add sort oderby = order + "" + sort;} // DataSet ds = Bnotice. getList (strWhere. toString (); // call getlist without pagination // call the GetList method of pagination DataSet ds = userlog. getListByPage (strWhere. toString (), oderby, (page-1) * pageRows + 1, page * pageRows); int count = userlog. getRecordCount (strWhere. toString (); string strJson = ToJson. dataset2Json (ds, count); context. response. write (strJson); context. response. end ();}


Modify update authentication: Html code:
// Modify the Administrator function modify (flag) {$ ('# FM '). form ('clear'); var row = $ ('# tt '). datagrid ('getselected'); // obtain the parameters required for updating the selected row // define the parameters, that is, the database fields, and obtain them from the table on the page. Var userid = row. userID; var content = row. content; var examinemessage = row. examineMessage; var publishdate = row. publishDate; var realname = row. realName; var title = row. title; var userlogid = row. userLogID; var examineSign = flag; var xmlHttp = null; // create the core Ajax object. indicates that the current browser is not ie if (window. XMLHttpRequest) {xmlHttp = new XMLHttpRequest ();} else if (window. activeXObject) {// iebrowser xmlHttp = new Activ EXObject ("Microsoft. XMLHTTP");} var url = "ExamineVerifyLog. ashx? Test = modify & UserID = "+ userid +" & Content = "+ content +" & ExamineSign = "+ examineSign +" & ExamineMessage = "+ examinemessage +" & PublishDate = "+ publishdate + "& RealName =" + realname + "& Title =" + title + "& UserLogID =" + userlogid; // set the request method to GET and url. Submit xmlHttp asynchronously. open ("GET", url, true); xmlHttp. onreadystatechange = function () {// alert (xmlHttp. readyState); // determine whether the execution is complete if (4 = xmlHttp. readyState ){// If the execution is successful, if (200 = xmlHttp. status) {// call reload $ ('# tt '). datagrid ('reload');} else {alert ("request failed! Error Code: "+ xmlHttp. status) ;}}; // enable asynchronous request xmlHttp. send (null );}


General handler code:

////// Modify the record //////Public void Modify (HttpContext context) {// declare Entity class Entity. userLogEntity entityuserlog = new Entity. userLogEntity (); entityuserlog. userID = context. server. urlDecode (context. request. queryString ["UserID"]); entityuserlog. content = context. server. urlDecode (context. request. queryString ["Content"]); entityuserlog. examineMessage = context. server. urlDecode (context. request. queryString ["ExamineMessage"]); entityuserlog. publishDate = context. server. urlDecode (context. request. queryString ["PublishDate"]); entityuserlog. title = context. server. urlDecode (context. request. queryString ["Title"]); entityuserlog. userLogID = context. server. urlDecode (context. request. queryString ["UserLogID"]); entityuserlog. examineSign = context. server. urlDecode (context. request. queryString ["ExamineSign"]); try {if (userlog. update (entityuserlog) // checks whether the Update is successful {context. response. write ("T");} else {context. response. write ("F") ;}} catch (Exception ex ){}}

Of course, the method of layer D is not written here. layer D is generated by dynamic soft code rather than by ourselves. After the method is generated, the method generated by Neusoft code is called directly ~~~


Your own feeling:

For EasyUI, I feel that all kinds of encapsulated frameworks need to implement corresponding functions and call the encapsulated methods. However, this sentence is simple and true, but it makes people feel a little bit of pain ~~~ Thanks to Jackie Chan's help, ^ _~......

To add a gossip: Speaking is one thing, and communication is another thing!




Related Article

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.