📄 clientda.cs
字号:
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using HouseBE;
namespace HouseDA
{
/// <summary>
/// ClientDA 的摘要说明。
/// </summary>
public class ClientDA:CommonDA
{
private SqlConnection _con;
private ConDA _cons;
private SqlCommand _cmd;
private SqlDataAdapter _adapter;
private DataSet _ds;
private HouseBE.Client _client;
private ArrayList list;
public HouseBE.Client client
{
set
{
this._client=value;
}
get
{
return this._client;
}
}
public ClientDA()
{
//
// TODO: 在此处添加构造函数逻辑
//
this._cons=new ConDA();
this._con=this._cons._con;
}
#region CommonDA 成员
public DataSet select()
{
// TODO: 添加 ClientDA.select 实现
try
{
this._adapter=new SqlDataAdapter("select * from ClientAdd",this._con);
this._ds=new DataSet();
this._adapter.Fill(this._ds,"Client");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
return this._ds;
}
//根据客户姓名查询
public DataSet getNameSelect(string name)
{
try
{
this._adapter=new SqlDataAdapter("select * from ClientAdd where 客户姓名 like '"+name+"'",this._con);
this._ds=new DataSet();
this._adapter.Fill(this._ds,"ClientName");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
return this._ds;
}
public void insert()
{
// TODO: 添加 ClientDA.insert 实现
this._cmd=this._con.CreateCommand();
this._cmd.CommandType=CommandType.StoredProcedure;
this._cmd.CommandText="proc_AddClinet";
this._cmd.Parameters.Add("@ClientName",this._client.ClientName);
this._cmd.Parameters.Add("@empName",this._client.getEmp);
this._cmd.Parameters.Add("@ClientAdress",this._client.ClientAdress);
this._cmd.Parameters.Add("@ClientTelphone",this._client.ClientTelphone);
this._cmd.Parameters.Add("@ClientEmail",this._client.ClientEmail);
this._cmd.Parameters.Add("@Reamark",this._client.Reamark);
try
{
this._con.Open();
this._cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
}
public void update()
{
// TODO: 添加 ClientDA.update 实现
this._cmd=this._con.CreateCommand();
this._cmd.CommandType=CommandType.StoredProcedure;
this._cmd.CommandText="proc_updateClinet";
this._cmd.Parameters.Add("@ClientName",this._client.ClientName);
this._cmd.Parameters.Add("@empName",this._client.getEmp);
this._cmd.Parameters.Add("@ClientAdress",this._client.ClientAdress);
this._cmd.Parameters.Add("@ClientTelphone",this._client.ClientTelphone);
this._cmd.Parameters.Add("@ClientEmail",this._client.ClientEmail);
this._cmd.Parameters.Add("@Reamark",this._client.Reamark);
this._cmd.Parameters.Add("@ClientID",this._client.ClientID);
try
{
this._con.Open();
this._cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
}
//调用存储过程
public void delete()
{
// TODO: 添加 ClientDA.delete 实现
this._cmd=this._con.CreateCommand();
this._cmd.CommandType=CommandType.StoredProcedure;
this._cmd.CommandText="proc_Client";
this._cmd.Parameters.Add("@ClientID",this._client.ClientID);
try
{
this._con.Open();
this._cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
}
#endregion
//查询ID的方法
public DataSet selectID(string client)
{
this._adapter=new SqlDataAdapter("select ClientID,ClientTelphone from Client where ClientName="+client+"",this._con);
this._ds=new DataSet();
this._adapter.Fill(this._ds,"ClientName");
return this._ds;
}
//查询所有的预约信息
public ArrayList getMessage()
{
this.list=new ArrayList();
try
{
this._con.Open();
string str="select * from View_Destine";
SqlCommand cmd=this._con.CreateCommand();
cmd.CommandText=str;
SqlDataReader reads=cmd.ExecuteReader();
while(reads.Read())
{
this._client=new Client();
this._client.ClientName=reads.GetValue(0).ToString();
this._client.getArea=Convert.ToInt32(reads.GetValue(1).ToString());
this._client.getFloor=Convert.ToInt32(reads.GetValue(2).ToString());
this._client.getFormat=reads.GetValue(3).ToString();
this._client.getXiang=reads.GetValue(4).ToString();
this._client.ClientTelphone=reads.GetValue(5).ToString();
this._client.Getstate=reads.GetValue(6).ToString();
this.list.Add(this._client);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
return this.list;
}
public Client getClient()
{
try
{
this._con.Open();
string str="select * from View_Destine where 客户姓名=@name";
SqlCommand cmd=this._con.CreateCommand();
cmd.CommandText=str;
cmd.Parameters.Add("@name",this._client.ClientName);
SqlDataReader reads=cmd.ExecuteReader();
if(reads.Read())
{
this._client=new Client();
this._client.ClientName=reads.GetValue(0).ToString();
this._client.getArea=Convert.ToInt32(reads.GetValue(1).ToString());
this._client.getFloor=Convert.ToInt32(reads.GetValue(2).ToString());
this._client.getFormat=reads.GetValue(3).ToString();
this._client.getXiang=reads.GetValue(4).ToString();
this._client.ClientTelphone=reads.GetValue(5).ToString();
this._client.Getstate=reads.GetValue(6).ToString();
}
else
this._client=null;
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
finally
{
this._con.Close();
}
return this._client;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -