熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

dOOdad提供的數據綁定、特殊函數和事務處理

2013-11-13 10:14:53  來源: .NET編程 

    數據綁定
   ()綁定到DataGrid(WebApp)



if(empsLoadAll())
{
     dvEmps = empsDefaultView;
     dgEmpsDataSource = dvEmps;
     dgEmpsDataBind();
}

  ()綁定到ComboBox(WinApp)



//get data
empsQueryAddResultColumn(EmployeesColumnNamesEmployeeID);
empsQueryAddResultColumn(EmployeesColumnNamesLastName);
empsQueryAddOrderBy(EmployeesColumnNamesLastName
WhereParameterDirASC);
empsQueryLoad();
//bind to combobox
cmbEmployeesDisplayMember = EmployeesColumnNamesLastName;
cmbEmployeesValueMember = EmployeesColumnNamesEmployeeID;
cmbEmployeesDatasource = empsDefaultView;

  ()綁定到DropDownList(WebApp)



 //get data
 empsQueryAddResultColumn(EmployeesColumnNamesEmployeeID);
 empsQueryAddResultColumn(EmployeesColumnNamesLastName);
 empsQueryAddOrderBy(EmployeesColumnNamesLastName
 WhereParameterDirASC);
 empsQueryLoad();
 //bind to dropdown list
 ddlEmployeesDatasource = empsDefaultView;
 ddlEmployeesDataTextField = EmployeesColumnNamesLastName;
 ddlEmployeesDataValueField = EmployeesColumnNamesEmployeeID;
 ddlEmployeesDatabind();

    特殊函數執行自定義存儲過程和SQL語句

  Examples:
)LoadFromSql:(從數據庫中檢索並返回檢索結果集查詢結果保存到DataTable中)



ListDictionary Parms = new ListDictionary();
ParmsAdd(@parameterName value);
ParmsAdd(@parameterName value);
parmsAdd……
if(thisLoadFromSql(proc_GetSpecialEmployee Parms))
{
  
}

  ()LoadFromSqlNoExec:(執行無結果集的存儲過程返回受影響的行數)
        int NbrOfChecks = thisLoadFromSqlNoExec(proc_CalculatePayroll);
        例如刪除一條記錄dOOdad提供的文檔中的方法是先LoadByPrimaryKey再MarkAsDeleted最後再Save進數據庫這個過程要對數據庫進行兩次操作實際上我們可以只操作一次數據庫(直接用dOOdads模板生成的存儲過程)而不用先Load
 ListDictionary Parms = new ListDictionary();
 ParmsAdd(@ID empID);
 int effectLine = thisLoadFromSqlNoExec(proc_EmployeeDeleteParms);

  ()LoadFromSqlReader:(返回SqlDataReader)
 SqlDataReader rdr = thisLoadFromSqlReader(proc_GetSpecialEmployee Parms) as SqlDataReader;

  ()LoadFromSqlScalar:(返回單個值)
 DateTime EarliestHireDate;
 ListDictionary Parms = new ListDictionary();
 ParmsAdd(@Active );
 EarliestHireDate = ConvertToDateTime(thisLoadFromSqlScalar(GetEarliestHireDateParms));

  ()LoadFromRawSql:
 thisLoadFromRawSql(SELECT MIN(EM_HireDate) FROM tEmployees

  WHERE EM_Active = {});

    事務處理:



TransactionMgr tx = TransactionMgrThreadTransactionMgr();
try
{
    Employees emps = new Employees();
    empsAddNew();
    empsFirstName = Jimmy;
    empsLastName = Doe;
    Products prds = new Products();
    prdsAddNew();
    prdsProductName =  Lunch Box ;
    prdsDiscontinued = false;
    txBeginTransaction();
    empsSave();
    prdsSave();
    txCommitTransaction();
}
catch(Exception ex)
{
    txRollbackTransaction();
    TransactionMgrThreadTransactionMgrReset();
}


From:http://tw.wingwit.com/Article/program/net/201311/13033.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.