Data center Charging System Reconstruction (6)-generic set

Source: Internet
Author: User

Restructuring of the data room charging system is still in progress, but during the process, data type conversion may never be avoided. Today I will talk about the data type conversion problem!

In the charging system of the personal data center, if you add, delete, modify, or delete data in the Dal layer, no parameters are required. The return value is Boolean, but a return value is required in the query, the returned data is of the dateset type, so the problem arises here.

If the table type is always returned during the return value process, it may not be so much troublesome. However, the dateset makes the system highly coupled, but what if the returned object class is used! I also checked the information about this. Why does table use lead to strong coupling?

For example, if the user information changes, we need to modify the table data, but we need to modify the data at the Dal layer, which makes the system difficult to maintain, however, if the object class is returned, we can modify user information directly in the object class!

Next let's take a look at the data center fee record for top-up students! (Only part of the code is pasted)

Obtain basic data information in the Dal Layer

Imports system. data. sqlclientimports system. dataimports idalpublic class da_querychargerec: Implements idal. iquerychargerec ''' <summary> ''' Dal layer function block. You need to call the datesettolist method to convert the data. ''' </Summary> ''' <Param name = "chargerec"> object class name </param> ''' <returns> </returns> ''' <remarks> </remarks> Public Function querycharge (chargerec as model. mo_querychargerec) as List (of model. mo_querychargerec) implements idal. iquerychargerec. querycharge dim sqlparamas as sqlparameter () = {New sqlparameter ("@ cardno", chargerec. cardno )} dim plain text as string = "select * From t_rechargeinfo where [email protected]" 'query database dim datesetlist as new da_datesettolist' instantiate data conversion function class dim helper as new sqlhelper 'instantiate sqlhelper dim primitive type commandtype = new commandtype () struct type = commandtype. text dim table as new able instantiate a table = helper. executequery (plain text, plain type, sqlparamas) 'returns the table data if table. rows. count <> 0 then': determines whether the table is empty. Return datesetlist. datesettolist (table) 'calls the datesettolist method and returns the generic Entity else return nothing end if end functionend class
Let's take a look at the code for calling the datesettolist method above:

Public class da_datesettolist: Implements idal. idatesettolist public function datesettolist (byval dT as datatable) as ilist (of model. mo_querychargerec) implements idal. idatesettolist. datesettolist' defines the generic set dim list as new list (of model. mo_querychargerec) dim type as type = GetType (model. mo_querychargerec) 'defines the Temporary Variable dim tempname as string' to traverse each row in the data table for each Dr as datarow in DT. rows 'create recharge Basic Information Entity class dim morechargeinfo as new model. mo_querychargerec dim propertys () as system. reflection. propertyinfo = morechargeinfo. getType (). getproperties () 'obtains all the attributes of the entity class enrechargeinfo and puts them in the array.' All attributes of this object are traversed for each PI as system. reflection. propertyinfo in propertys tempname = pi. name' assign the attribute name to the Temporary Variable 'and check whether the datatable contains this column (column name = Object attribute name) If DT. columns. contains (tempname) then' if this column contains if not Pi. canwrite then' if this attribute cannot be written, directly jump out of continue for end if 'if this attribute can be written to dim value as object = DR (tempname)' if not empty, if not isnothing (value. tostring () then dim A as string = value. tostring (). trim () Pi. setvalue (morechargeinfo, A, nothing) end if next list. add (morechargeinfo) 'add the recharge information entity to the next return List' in the set to return the end functionend class of the generic set.
The above method may be the same as sqlhelper. It is a template. If you want to use it, you will use it. More research is required on generic set code.

Finally, The bll layer returns a generic set, and displays the UI Layer!


I am not very familiar with this part. I just made a snapshot for myself to record my problems. If you have any questions or opinions, I am eager to take a picture!

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.