📄 branchda.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using HouseBE;
namespace HouseDA
{
/// <summary>
/// BranchDA 部门的数据库访问层。
/// </summary>
public class BranchDA:CommonDA
{
private SqlConnection _con;
private SqlDataAdapter _adapter;
private SqlCommand _cmd;
private DataSet _ds;
private ConDA _cons;
private HouseBE.Branch _branch;
public HouseBE.Branch branch
{
set
{
this._branch=value;
}
get
{
return this._branch;
}
}
public BranchDA()
{
this._cons=new ConDA();
this._con=this._cons._con;
}
#region CommonDA 成员
public DataSet select()
{
try
{
this._adapter=new SqlDataAdapter("select * from VIEW_Branch",this._con);
this._ds=new DataSet();
this._adapter.Fill(this._ds,"Branch");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
return this._ds;
// TODO: 添加 BranchDA.select 实现
}
public void insert()
{
// TODO: 添加 BranchDA.insert 实现
this._cmd=this._con.CreateCommand();
this._cmd.CommandText="insert into Branch values(@BranchName,@Remark)";
this._cmd.Parameters.Add("@BranchName",this._branch.BranchName);
this._cmd.Parameters.Add("@Remark",this._branch.Remark);
try
{
this._con.Open();
this._cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
}
public void update()
{
// TODO: 添加 BranchDA.update 实现
this._cmd=this._con.CreateCommand();
this._cmd.CommandText="update Branch set BranchName=@BranchName,Remark=@Remark where BranchID=@BranchID";
this._cmd.Parameters.Add("@BranchName",this._branch.BranchName);
this._cmd.Parameters.Add("@Remark",this._branch.Remark);
this._cmd.Parameters.Add("@BranchID",this._branch.BranchID);
try
{
this._con.Open();
this._cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
}
//未实现的方法 需要调用存储过程
public void delete()
{
// TODO: 添加 BranchDA.delete 实现
this._cmd=this._con.CreateCommand();
this._cmd.CommandType=CommandType.StoredProcedure;
this._cmd.CommandText="proc_Branch";
this._cmd.Parameters.Add("@BranchID",this._branch.BranchID);
try
{
this._con.Open();
this._cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
}
#endregion
public DataSet Selects(HouseBE.Branch branch)
{
this._ds=new DataSet();
try
{
this._adapter=new SqlDataAdapter("select * from VIEW_Branch where BranchName="+this._branch.BranchName+"",this._con);
this._adapter.Fill(this._ds,"BranchName");
}
catch(Exception ex)
{
throw ex;
}
return this._ds;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -