程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 在c#中實現3層架構(2)

在c#中實現3層架構(2)

編輯:關於C語言
戶接口層

下面是用戶接口成的一段代碼,我只選取了調用商業邏輯層的一部分代碼。

//This function get the details from the user via GUI
//tIEr and calls the Add method of business logic layer.
private void cmdAdd_Click(object sender, System.EventArgs e)
{
   try
   {
      cus = new BOCustomer();
      cus.cusID=txtID.Text.ToString();
      cus.LName = txtLName.Text.ToString();
      cus.FName = txtFName.Text.ToString();
      cus.Tel= txtTel.Text.ToString();
      cus.Address = txtAddress.Text.ToString();
      cus.Add();
   }
   catch(Exception err)
   {
      MessageBox.Show(err.Message.ToString());
   }
}

//This function gets the ID from the user and finds the
//customer details and return the details in the form of
//a dataset via busniss object layer.Then it loops through
//the content of the dataset and fills the controls.

private void cmdFind_Click(object sender, System.EventArgs e)
{
   try
   {
      String cusID = txtID.Text.ToString();
      BOCustomer thisCus = new BOCustomer();
      DataSet ds = thisCus.Find(cusID);

      DataRow row;
      row = ds.Tables[0].Rows[0];

      //via looping
      foreach(DataRow rows in ds.Tables[0].Rows )
      {
        txtFName.Text = rows["CUS_F_NAME"].ToString();
        txtLName.Text = rows["CUS_L_NAME"].ToString();
        txtAddress.Text = rows["CUS_ADDRESS"].ToString();
        txtTel.Text = rows["CUS_TEL"].ToString();
      }
   }
   catch (Exception err)
   {
      MessageBox.Show(err.Message.ToString());
   }

}

//this function used to update the customer details.
private void cmdUpdate_Click(object sender,
                 System.EventArgs e)
{
   try
   {
      cus = new BOCustomer();
      cus.cusID=txtID.Text.ToString();
      cus.LName = txtLName.Text.ToString();
      cus.FName = txtFName.Text.ToString();
      cus.Tel= txtTel.Text.ToString();
      cus.Address = txtAddress.Text.ToString();

      cus.Update();
   }
   catch(Exception err)
   {
      MessageBox.Show(err.Message.ToString());
   }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved