[How to] How to Use wildfish for iseries development-single table operations

Source: Internet
Author: User
In our example, account is a single table operation.
The preceding essays have generated the accountdataset accountdatatable accountentity accountrule accountsystem class.
So I will not repeat it here.
If you do not want to do this, you can download the Demo code directly.
Create a new winform named testsingletable. CS.
And draw the interface as follows.

Here I am lazy and pull accountdataset to the screen as the data source of the screen's gridview.
1. Add on using
Using wildfish. Data. iseries;
Using wildfish. businessfacade. iseries;
Using wildfish. systemframework. base;
Using wildfish. systemframework. utility;
2. When form_load, we get all the account data accountsystem mgrsystem = new accountsystem ();
Accountdataset DS = mgrsystem. filldatasetbyall ();
This. gridaccount. datasource = Ds. accounttable. defaultview;

3. The Add/update code is as follows: if (this.txt name. Text. Trim (). Length = 0)
{
This.txt name. Focus ();
MessageBox. Show ("Please input the name! ");
Return;
}
If (this.txt password. Text. Trim (). Length = 0)
{
This.txt password. Focus ();
MessageBox. Show ("Please input the password! ");
Return;
}
If (this.txt nickname. Text. Trim (). Length = 0)
{
This.txt nickname. Focus ();
MessageBox. Show ("Please input the nickname! ");
Return;
}
Accountsystem mgrsystem = new accountsystem ();
If (opmode = operationmode. Add)
{
// Check exist
If (mgrsystem.checkexist(this.txt name. Text ))
{
This.txt name. Focus ();
MessageBox. Show ("the name is already existed! ");
Return;
}
Accountdataset DS = new accountdataset ();
Accountentity entity = Ds. accounttable. createentity ();
Entity. Name = this.txt name. text;
Entity. Password = securityutility.enctype(this.txt password. Text );
Entity. Nickname = this.txt nickname. text;
// Ds. setentity (entity); or
// Ds. accounttable. setentity (entity );
DS. accounttable. setentity (entity );
If (! Mgrsystem. insertdata (DS ))
{
MessageBox. Show ("error occur at Insert the data to database! Please check the wildfish.log.txt for detail! ");
}
}
Else
{
Accountdataset DS = mgrsystem.filldatasetbyid(this.txt name. Text );
Accountentity entity = Ds. accounttable. getentity (0 );
Entity. Password = securityutility.enctype(this.txt password. Text. Trim ());
Entity. Nickname = this.txt nickname. text;
// Ds. setentity (entity); or
// Ds. accounttable. setentity (entity );
DS. accounttable. setentity (entity );
If (! Mgrsystem. updatedata (DS ))
{
MessageBox. Show ("error occur at update the data to database! Please check the wildfish.log.txt for detail! ");
}
}
This. opmode = operationmode. Add;
This.txt name. Enabled = true;
This.txt name. Text = "";
This.txt password. Enabled = true;
This.txt password. Text = "";
This.txt nickname. Enabled = true;
This.txt nickname. Text = "";
Getallthedata ();

How to Use wildfish to add data
First, we create a new appearance layer object accountsystem mgrsystem = new accountsystem ();
If you are adding
If (mgrsystem.checkexist(this.txt name. Text ))
Use this to determine whether the data of the corresponding value of mainkey = name already exists.
Accountdataset to generate an accountentity
Set the value in the form of accountentity, there will be type verification, you can also add your own validation code in the attribute settings
After setting, use the instance setentity of accountdataset to set the entity value to datarow.
Finally, call the insertdata method of the appearance layer object to add a new object.
If it is modified
Accountdataset DS = mgrsystem.filldatasetbyid(this.txt name. Text );
Accountentity entity = Ds. accounttable. getentity (0 );
Obtain the data first. If the data is saved, you can use the dataset you just saved.
Then obtain the object
Set object values
Call Ds. accountdatatable. setentity ();
Finally, the updatedata method of the appearance layer object is called for modification.

Delete a piece of data
Get Data
Marked with the delete mark. You can use datarow. Delete, entity. delete, and setentity.
Call the deletedata method of the appearance layer object to delete the object.

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.