[How To]如何使用Wildfish進行ISeries開發—單表操作篇

來源:互聯網
上載者:User
在我們的樣本中Account是一個單表的操作。
前面的隨筆已經有產生了AccountDataSet AccountDataTable AccountEntity AccountRule AccountSystem類了。
所以這裡我就不重複累贅了。
如果不想做,可以直接下載demo的代碼
我們建立一個Winform,取名TestSingleTable.cs
並如下畫好介面。

這裡我偷懶,直接把AccountDataSet拉到螢幕作為螢幕的gridview的資料來源
1.using上添加
using Wildfish.Data.ISeries;
using Wildfish.BusinessFacade.ISeries;
using Wildfish.SystemFrameWork.Base;
using Wildfish.SystemFrameWork.Utility;
2.在Form_Load的時候,我們擷取所有的Account資料ACCOUNTSystem mgrSystem=new ACCOUNTSystem();
            ACCOUNTDataSet ds = mgrSystem.FillDataSetByAll();
            this.gridAccount.DataSource = ds.ACCOUNTTable.DefaultView;

3.Add/Update的代碼如下if (this.txtName.Text.Trim().Length == 0)
            {
                this.txtName.Focus();
                MessageBox.Show("Please input the name!");
                return;
            }
            if (this.txtPassword.Text.Trim().Length == 0)
            {
                this.txtPassword.Focus();
                MessageBox.Show("Please input the password!");
                return;
            }
            if (this.txtNickname.Text.Trim().Length == 0)
            {
                this.txtNickname.Focus();
                MessageBox.Show("Please input the nickname!");
                return;
            }
            ACCOUNTSystem mgrSystem = new ACCOUNTSystem();
            if (opMode == OperationMode.Add)
            {
                //check exist
                if (mgrSystem.CheckExist(this.txtName.Text))
                {
                    this.txtName.Focus();
                    MessageBox.Show("The name is already existed!");
                    return;
                }
                ACCOUNTDataSet ds=new ACCOUNTDataSet();
                ACCOUNTEntity entity = ds.ACCOUNTTable.CreateEntity();
                entity.NAME = this.txtName.Text;
                entity.PASSWORD = SecurityUtility.Enctype(this.txtPassword.Text);
                entity.NICKNAME = this.txtNickname.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.txtName.Text);
                ACCOUNTEntity entity = ds.ACCOUNTTable.GetEntity(0);                
                entity.PASSWORD = SecurityUtility.Enctype(this.txtPassword.Text.Trim());
                entity.NICKNAME = this.txtNickname.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.txtName.Enabled = true;
            this.txtName.Text = "";
            this.txtPassword.Enabled = true;
            this.txtPassword.Text = "";
            this.txtNickname.Enabled = true;
            this.txtNickname.Text = "";
            GetAllTheData();

這裡要講述的是如何使用Wildfish進行新增資料
首先,我們new一個外觀層對象 ACCOUNTSystem mgrSystem = new ACCOUNTSystem();
如果是新增
       if (mgrSystem.CheckExist(this.txtName.Text))
        用這個來判斷MainKey=Name的對應值的資料是否已經存在
        AccountDataSet來產生一個AccountEntity
       用AccountEntity的形式來設定值,會有類型校正,也可以在屬性設定處增加自己的校正代碼
       設定完了之後,用AccountDataSet的執行個體SetEntity把Entity值設定到DataRow
      最後調用外觀層對象的InsertData方法來達到新增。
 如果是修改的話
      ACCOUNTDataSet ds = mgrSystem.FillDataSetByID(this.txtName.Text);
       ACCOUNTEntity entity = ds.ACCOUNTTable.GetEntity(0);       
       先擷取資料,如果剛才的資料儲存了,也可以用剛才的那個資料集
       然後擷取實體
       設定實體的值
       調用ds.AccountDataTable.SetEntity();
       最後調用外觀層對象的UpdateData方法來達到修改。

而Delete一條資料
      擷取資料
      打上刪除標誌,可以用datarow.delete,也可以用entity.delete,然後SetEntity的形式
      然後調用外觀層對象的DeleteData方法來達到刪除。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.