SDQ的樣本介紹(2)

來源:互聯網
上載者:User

2.本例將頁面提交(POST)過來的資料繫結給資料表模型進行資料存放區

本例環境:ASP.NET 2.0,VS.NET 2005

//------------------------------------------
使用模型進行資料存放區

private string _PGID;
public string PGID
...{
    get
    ...{
        if(_PGID == null)
            _PGID = Request.QueryString["PUID"];
        
        return _PGID;
    }
    set
    ...{
        _PGID = value;
    }
}

//1.使用資料表模型進行快速的資料繫結與同步,實現有[Save21()]同樣的效果與效能
//
public void Save11()
...{
    //BCF_FBT_Group code part:: declare PGID as key column
    //
    //[QColumn(Name = "PGID", Type = ColType.Text , Iskey = true)]
    //public QColumn PGID;

    BCF_FBT_Group g = new BCF_FBT_Group();

    //1) 將WEB頁面提交過來的表單資料,綁定給Group的執行個體@g
    //
    g.Bind(Request.Form);


    //2) 確定Key列的值
    //
    if(this.PGID == null)
        this.PGID = Guid.NewGuid().ToString("N");

    g.PGID.Value = this.PGID;            

    //3) 綁定後,執行同步,將資料同步到資料庫裡
    //
    g.Synchronize();
}

 

//2.比[Save11()] 效能更優的處理辦法,但是不知道資料庫裡是否真有存有一條記錄
//
public void Save12()
...{
    BCF_FBT_Group g = new BCF_FBT_Group();

    //other bind::
    //    g.bind(opsXml);
    //    g.bind(HashTable);
    //    g.bind(IPSData);
    //    g.bind(......);
    g.Bind(Request.Form);

    if(this.PGID == null)  //沒有對資料庫是存真的存在資料進行判斷
    ...{
        g.PGID.Value = Guid.NewGuid().ToString("N");
        g.Insert();
    }
    else
    ...{
        g.PGID.Value = this.PGID;
        g.Update();
    }            
}

//------------------------------------------------------------------------
以下使用SDQRun實現同等效果

//1.使用SQRun 實現資料儲存(插入或更新)
//
public void Save21()
...{
    SQRun SQ = new SQRun();

    BCF_FBT_Group g = new BCF_FBT_Group();

    g.Bind(Request.Form);

    if(this.PGID == null)
        this.PGID = Guid.NewGuid().ToString("N");

    g.PGID.Value = this.PGID;

    SQ.From(g);
    SQ.Where(g.PGID == g.PGID.Value);
    
    if(SQ.Exists())    //選判斷資料庫裡是否已存有記錄
        SQ.Set(g).Update();//延用了上面的Where條件
    else
        SQ.To(g).Insert();
}

//2.使用SQRun 實現資料儲存(使用UnWhere只插入資料)
//
public void Save21_onlyinsert1()//與[Save21_onlyinsert2()]實現同樣同效能的效果
...{
    SQRun SQ = new SQRun();

    BCF_FBT_Group g = new BCF_FBT_Group();

    g.Bind(Request.Form);

    if(this.PGID == null)
        this.PGID = Guid.NewGuid().ToString("N");

    g.PGID.Value = this.PGID;
    
    SQ.To(g).UnWhere(g.PGID == this.PGID).Insert(); //當不滿足該條件時,才插入資料
    
}

//---------------------------------------------
UnWhere 的實現原理::

//3.使用SQRun (UnWhere) 的實現原理
//
public void Save21_onlyinsert2()
...{
    SQRun SQ = new SQRun();

    BCF_FBT_Group g = new BCF_FBT_Group();

    g.Bind(Request.Form);

    if(this.PGID == null)
        this.PGID = Guid.NewGuid().ToString("N");

    g.PGID.Value = this.PGID;            

    SQ.From(g);//如果使用 UnWhere ,可以壓縮代碼量
    SQ.Where(g.PGID == g.PGID.Value);
    
    if(SQ.Exists() == false)    //選判斷資料庫裡是否已存有記錄    
        SQ.To(g).Insert();
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.