ASP. NET Web development framework-4 Query

Source: Internet
Author: User

Enterprise Solution supports user-defined query and lookup, and defines query as a standard function. lookup is used to return the query value to the data input form.

First, configure the database connection string and use the company registration to register a new database connection. In the query designer, select the corresponding object and design the association. The Web framework can parse the query and turn it into a page function.

Add a TriggerBox on the customer page. A small icon is displayed at the end of it to search for data.

 
 
  1.  <ext:TriggerBox ID="tbxCustomerNo" ShowLabel="true" Readonly="false" TriggerIcon="Search" 
  2.                             OnTriggerClick="tbxCustomerNo_TriggerClick" OnTextChanged="tbxCustomerNo_TextChanged" 
  3.                             AutoPostBack="true" Label="Customer No." runat="server" Lookup="CustomerEntryLookup" 
  4.                             DataBindingString="CustomerEntity:CustomerNo">  
  5. </ext:TriggerBox> 

Let's look at the background code processing mode.

 
 
  1. string lookup = tbxCustomerNo.Lookup;  
  2.              tbxCustomerNo.OnClientTriggerClick = Window1.GetSaveStateReference(tbxCustomerNo.ClientID, HiddenField1.ClientID, HiddenField2.ClientID)  
  3.                + Window1.GetShowReference(string.Format("lookup.aspx?id={0}", lookup), "Look-up:Customer"); 

From the preceding Web page, the Lookup attribute is mermerentrylookup. This statement associates Lookup with Window1 of the page for the pop-up window. At the same time, it specifies the HiddenField1 of the page to accept the return value of Lookup. Finally, it calls the re-sending and refresh process of the window, page refresh. The Code is as follows:

 
 
  1. protected void Window1_Close(object sender, EventArgs e)  
  2. {  
  3.             string customerNo = tbxCustomerNo.Text;  
  4.             if (!string.IsNullOrWhiteSpace(customerNo))  
  5.             {  
  6.                 ReloadEntity(customerNo);              
  7.             }  
  8. }     

In this way, the selection value is displayed on the query page, the return value is returned to the main form, and the main form is refreshed.

Let's take a look at lookup. how is the aspx page designed? It accepts a query id as the parameter, which is the CustomerEntryLookup we specify. In the query designer, it is designed in this way.

The lookup. aspx page accepts input parameters. Its initial trial page is designed in this way.

 
 
  1. protected void Page_Init(object sender, EventArgs e)  
  2. {  
  3.             LookupName = Request.QueryString["id"];  
  4.            
  5.             ILookupDialogManager _lookupDialogManager = ClientProxyFactory.CreateProxyInstance<ILookupDialogManager>();  
  6.             string companycode = "TS";  
  7.             DataTable table = _lookupDialogManager.GetLookupDialogData(LookupName, null, null, 0, 0, companycode);  
  8.             Grid1.RecordCount = table.Rows.Count;  
  9.  
  10.               BindGrid();  
  11.              

Query by PAGE based on the total number of records. The code here is the paging code of the Grid. It is not complicated to see the definition of the BindGrid method.

 
 
  1. private void BindGrid()  
  2. {  
  3.             DataSet ds = LoadData(Grid1.PageIndex+1);  
  4.  
  5.             while (Grid1.Columns.Count > 0)  
  6.                 Grid1.Columns.RemoveAt(0);  
  7.  
  8.             foreach (DataColumn colu in ds.Tables[0].Columns)  
  9.             {  
  10.                 ExtAspNet.BoundField field = new ExtAspNet.BoundField();  
  11.                 field.ColumnID = colu.ColumnName;  
  12.                 field.DataField = colu.ColumnName;  
  13.                 field.HeaderText = GetTranslation(colu.ColumnName);  
  14.                 Grid1.Columns.Add(field);  
  15.             }  
  16.  
  17.             Grid1.PageSize = PageSize;  
  18.             
  19.             Grid1.DataSource = ds.Tables[0];  
  20.             Grid1.DataBind();  
  21.  } 

It first deletes the original columns in the grid, generates new columns Based on the results, and applies multilingual translation to the column names. Pay attention to the Creation Time of the dynamic control. You should select it in Page_Init instead of Page_Load. When debugging, the page code is displayed as database pages, and only the set number of lines is returned each time.

The Grid paging event sample code is as follows, which is exactly the same as that of the GridView.

 
 
  1. protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)  
  2. {  
  3.          Grid1.PageIndex = e.NewPageIndex;  
  4.          BindGrid();  

Next let's take a look at the code of the two button methods on the lookup. aspx page. The simplest is to Close the form directly without returning any value to the main form. Its code is the easiest, as shown below:

 
 
  1. btnClose.OnClientClick = ActiveWindow.GetHideReference(); 

The Code is as follows:

 
 
  1. protected void btnSaveClose_Click(object sender, EventArgs e)  
  2. {  
  3.             int rowIndex = Grid1.SelectedRowIndex;  
  4.             GridRow row = Grid1.Rows[rowIndex];  
  5.  
  6.             ILookupDialogManager lookupManager=ClientProxyFactory.CreateProxyInstance<ILookupDialogManager>();  
  7.             LookupDialogEntity lookup = lookupManager.GetLookupDialog(LookupName);  
  8.             List<string> keyFields = new List<string>();  
  9.         
  10.             keyFields.Add(lookup.KeyField1);  
  11.             keyFields.Add(lookup.KeyField2);  
  12.             keyFields.Add(lookup.KeyField3);  
  13.  
  14.             List<string> values = new List<string>();  
  15.             foreach (string keyField in keyFields)  
  16.             {  
  17.                 string value = string.Empty;  
  18.                 if (!string.IsNullOrWhiteSpace(keyField))  
  19.                 {  
  20.                     ExtAspNet.BoundField field = (ExtAspNet.BoundField)Grid1.FindColumn(keyField);  
  21.                     string f1 = field.DataField;  
  22.                     object f2 = Grid1.Rows[rowIndex].States[field.ColumnIndex];  
  23.                     value = Convert.ToString(((DataRowView)(Grid1.Rows[rowIndex].DataItem))[keyField]);                
  24.                 }  
  25.                 values.Add(value);  
  26.             }  
  27.             PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(values[0], values[1], values[2]) + ActiveWindow.GetHidePostBackReference());  
  28.  } 

This part of the Code has two intentions: Take the value in the Grid and return it to the main form. Because you need to refresh the main form, add GetHidePostBackReference () to make the main form send back, the windowdid close, designed at the beginning of the article, ReloadEntity completes the re-binding of objects.

The principle of query and lookup is the same. They are all used for custom data searches. Query is used for relatively independent functions and is executable. lookup is used for searching and Returning Field Values to facilitate data input in the form. In the query designer, you can enter SQL statements or call stored procedures not only for Object Design queries.

This makes it easy for you to expand the system query function without secondary development.

Link: http://www.cnblogs.com/JamesLi2015/archive/2012/09/25/2700992.html

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.