僅展示呼叫 BLL 的事件處理,省略介面設計細節。
private void cmdAdd_Click(object sender, EventArgs e)
{
try
{
BOCustomer cus = new BOCustomer();
cus.cusID = txtID.Text;
cus.LName = txtLName.Text;
cus.FName = txtFName.Text;
cus.Tel = txtTel.Text;
cus.Address = txtAddress.Text;
cus.Add(); // 呼叫 BLL 新增
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void cmdFind_Click(object sender, EventArgs e)
{
try
{
string id = txtID.Text;
BOCustomer cus = new BOCustomer();
DataSet ds = cus.Find(id); // BLL 回傳 DataSet
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
DataRow row = ds.Tables[0].Rows[0];
txtFName.Text = row["CUS_F_NAME"].ToString();
txtLName.Text = row["CUS_L_NAME"].ToString();
txtAddress.Text = row["CUS_ADDRESS"].ToString();
txtTel.Text = row["CUS_TEL"].ToString();
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
private void cmdUpdate_Click(object sender, EventArgs e)
{
try
{
BOCustomer cus = new BOCustomer();
cus.cusID = txtID.Text;
cus.LName = txtLName.Text;
cus.FName = txtFName.Text;
cus.Tel = txtTel.Text;
cus.Address = txtAddress.Text;
cus.Update(); // 呼叫 BLL 修改
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}