ASP. Aries Advanced Development Tutorial: Excel Import Code writing (external)

Source: Internet
Author: User

Objective:

The import configuration feature provided by the framework has been able to solve more than 95% of the import situation, but in some cases, the code should be solved.

This article describes the code associated with importing.

1, the front-end append the input post parameters:
var Grid = new AR. DataGrid (' v_test ', ' Demo_testa '),//.../* Append some Post parameters */grid before import.    ToolBar.BtnImport.onBeforeExecute = function (para)    {        alert ("Imported parameter:" + JSON.STRINGIFY (para));        Para. Name = "Append a name, the format of Excel import configuration can be configured @name";        Para. Para2 = "Casual ...";    }
2. Back-end code intercepts import events:

If you don't know where to write the code, see: ASP. Aries Open Source Development framework: Development Guide (i) understand the final framework of the request process.

  Public OverrideImportResult Beforeimport (mdatatable DT, Mdatarow Excelinfo, out stringmsg) {            if(dt. TableName = ="v_userlist")//processing only specific (view object) tables            {                //parameter Description://DT Data sheet from Excel, column header or Chinese//Excelinfo Advanced Excel configuration (null if configuration is not configured)msg="error message, only available if False is returned"; if(msg = ="Handle the logic yourself")                {                    //add your own logic                    BOOLresult = Formatexcel (dt, excelinfo);//call the System method, translate the column in Chinese into English and translate the drop-down item into a value                    if(Result) {//Write your own method of inserting the database. //result = excelconfig.acceptchanges (dt, Excelinfo, objname);//dt. AcceptChanges (Acceptop.auto);                    }                    returnimportresult.true; }                Else if(msg = ="handle logic yourself, abort execution, return processing failure")                {                    returnimportresult.true; }                Else                {                    //The data of the DT is processed only by itself.                     returnImportresult.continue;//Keep the framework going .                }            }            return Base. Beforeimport (Dt,excelinfo, outmsg); }

There are two core approaches to providing a framework:

Formatexcel:

Internal processing process: 1. Translate the Chinese header into English. 2, the key value pairs of Chinese converted to a value. 3. Handle some default value setting issues. 4. Complete the basic data validation (required, null, length, data type)

Excelconfig.acceptchanges (DT, Excelinfo, objname);

The system handles complex processing based on the contents of the advanced Excel configuration items, and decides whether to update or insert according to the configuration.

For Excelconfig. The AcceptChanges method also has a high-level extension that allows you to handle things before and after each data occurrence.

Specific look: Aries.logic project under the ExcelConfigExtend.cs file.

Summary description:

If you want to increase the data validation, or to make up the data, then rewrite: Beforeimport event, it is necessary.

If there is something that needs to be done before and after each row of data, then a bit of code can be Aries.Logic.ExcelConfigExtend.

ASP. Aries Advanced Development Tutorial: Excel Import Code writing (external)

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.