"He said, you are too tired to do that, and if the field changes, maintenance is required"

Source: Internet
Author: User

(to csdn) developed a system that uses the UI (presentation layer)-WebService (business logic layer)-sqlserver (data layer) architecture,
I have made many webmethods In the WebService layer to add/delete data and obtain record sets. For a representative webmethod, the function definition is
Boolean addorg (string org_name, string org_address, string org_tel)
{
/*....................... */
}< br> as the system has just begun implementation, the user's requirements are not very clear and new fields need to be added to a data table. If so, I need to add an input parameter to the WebService layer, add a textbox for user input in the presentation layer, modify the WebService method called, and send the value in the textbox to the end, this is very troublesome, I would like to ask if there is a way to better adapt to user needs? Can someone tell me?
my solution:
first, on the UI side, I wrote:
private void button#click (Object sender, system. eventargs e)
{< br> system. data. dataset siteset = f_sitemanagement.remote_logical.getsitestru ();
system. data. datarow siterow = siteset. tables ["u_site_info"]. newrow ();
system. data. datatable sitetable = siteset. tables ["u_site_info"];
siterow ["sitename"] = textbox1.text. tostring ();
siterow ["sitetypeid"] = "3";
siterow ["siteaddress"] = textbox2.text. tostring ();

/* As the table structure increases or decreases, do not change other Code */
siterow ["Newfield"] = "newvalue"
siterow ["Newfield"] = "newvalue"
siterow ["Newfield"] = "newvalue"
siterow ["Newfield"] = "newvalue"
siterow ["Newfield"] = "newvalue"
siterow ["Newfield"] = "newvalue"
/* increases or decreases with the table structure, no need to change other code */

Sitetable. Rows. Add (siterow );

If (f_sitemanagement.remote_logical.addsite (siteset. getchanges () = 1)
{
MessageBox. Show ("added successfully! ");
}
}
The WebService end is written as follows:
Public int addsite (Dataset siteset)
{
Sqldataadapter siteadap = new sqldataadapter ();
Sqlcommand sitecommand = new sqlcommand ("select * From u_site_info", c_service_scout.dbconn );

Siteadap. selectcommand = sitecommand;
Sqlcommandbuilder sitebuilder = new sqlcommandbuilder (siteadap );
C_service_scout.dbconn.open ();
Siteadap. Update (siteset, "u_site_info ");
C_service_scout.dbconn.close ();
Return 1;
}
Public dataset getsitestru ()
{
C_service_scout.dbconn.open ();
Dataset sitelist = new dataset ("sitelist ");
Sqlcommand sitecomm = new sqlcommand ("select top 1 * From u_site_info", c_service_scout.dbconn );
Sqldataadapter siteadap = new sqldataadapter ();
Siteadap. selectcommand = sitecomm;
Siteadap. Fill (sitelist, "u_site_info ");
C_service_scout.dbconn.close ();
Sitecomm. Dispose ();
Siteadap. Dispose ();
Return sitelist;
}
The principle is as follows: I use two interfaces on the WebService side: getsitestru and addsite,
To avoid changing other code, I first obtain the table structure of the current site_info table from the WebService layer and call getsitestru to the local dataset, then declare a datarow with the same structure for the local dataset on the UI Layer. All the operations for adding records are completed here, then, the local dataset is uniformly sent to the addsite structure of WebService and updated using the adapter.
In this way, each time I add a new field, I only need to assign a value to the field directly in the siterow on the UI side. Some Newfield and newvalue have been written in the code.

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.