关于信息删除修改的示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;
using System.Data.SqlClient;
namespace BLL
{
public class chuche
{
public chuche()
{
}
private int chuche_id;
private string chuche_chepai;
private string chuche_people;
private string chuche_dirver;
private string chuche_lichen;
private string chuche_reason;
private string chuche_beizhu;
private string chuche_mudd;
private DateTime chuche_back;
#region 单件
private static chuche chuche_instance = null;
public static chuche instance()
{
if (chuche_instance == null)
{
chuche_instance = new chuche();
}
return chuche_instance;
}
#endregion 单件
public int getchuche_id()
{ return this.chuche_id; }
public void setchuche_id(int chuche_id)
{ this.chuche_id = chuche_id; }
public string getchuche_chepai()
{ return this.chuche_chepai; }
public void setchuche_chepai(string chuche_chepai)
{ this.chuche_chepai = chuche_chepai; }
public string getchuche_people()
{ return this.chuche_people; }
public void setchuche_people(string chuche_people)
{ this.chuche_people = chuche_people; }
public string getchuche_dirver()
{ return this.chuche_dirver; }
public void setchuche_dirver(string chuche_dirver)
{ this.chuche_dirver = chuche_dirver; }
public string getchuche_lichen()
{ return this.chuche_lichen; }
public void setchuche_lichen(string chuche_lichen)
{ this.chuche_lichen = chuche_lichen; }
public string getchuche_reason()
{ return this.chuche_reason; }
public void setchuche_reason(string chuche_reason)
{ this.chuche_reason = chuche_reason; }
public string getchuche_beizhu()
{ return this.chuche_beizhu; }
public void setchuche_beizhu(string chuche_beizhu)
{ this.chuche_beizhu = chuche_beizhu; }
public string getchuche_mudd()
{ return this.chuche_mudd; }
public void setchuche_mudd(string chuche_mudd)
{ this.chuche_mudd = chuche_mudd; }
public DateTime getchuche_back()
{ return this.chuche_back; }
public void setchuche_back(DateTime chuche_back)
{ this.chuche_back = chuche_back; }
public static DataSet show()
{
string strsql = "select * from tb_chuche";
DataSet ds = DBlHelper.GetDataSet(strsql, null);
return ds;
}
public DataSet show(string index,string cc)
{
string strsql = "select * from tb_chuche where 车牌号=@车牌号 or
用车人=@用车人 ";
//含参SQL示例
SqlParameter[] param ={
new SqlParameter("@车牌号", SqlDbType.Char,10),
new SqlParameter("@用车人", SqlDbType.Char,10)
};
param[0].Value = index;
param[1].Value = cc;
DataSet ds = DBlHelper.GetDataSet(strsql, param);
return ds;
}
public static int delete(int bianhao)
{
string str_sql = "delete from tb_chuche where 车辆编号=@车辆编号";
SqlParameter[] parameters = {
new SqlParameter("@车辆编号", SqlDbType.Int,50)
};
parameters[0].Value = bianhao;
int i = DBlHelper.ExecCommand(str_sql, parameters);
return i;
}
public static int add(int int_id, string str_chepai, string str_people,string str_dirver, string str_licheng, string str_reason, string str_mudd, DateTime str_back, string str_beizhu)
{
string str_sql = "insert into tb_chuche(车辆编号, 车牌号,用车人,驾驶员,出车里程,出车原因, 目的地,预计回车,出车备注) values(@车辆编号, @车牌号,@用车人,@驾驶员,@出车里程,@出车原因, @目的地,@预计回车,@出车备注)";
SqlParameter[] parameters = {
new SqlParameter("@车辆编号", SqlDbType.Int),
new SqlParameter("@车牌号",SqlDbType.Char ,10),
new SqlParameter("@用车人",SqlDbType.Char ,10),
new SqlParameter("@驾驶员",SqlDbType.Char ,10),
new SqlParameter("@出车里程", SqlDbType.NChar,50),
new SqlParameter("@出车原因",SqlDbType.NText ,50),
new SqlParameter("@目的地",SqlDbType.Char ,50),
new SqlParameter("@预计回车", SqlDbType.DateTime,50),
new SqlParameter("@出车备注",SqlDbType.NText ,50),
};
parameters[0].Value = int_id;
parameters[1].Value = str_chepai;
parameters[2].Value = str_people;
parameters[3].Value = str_dirver;
parameters[4].Value = str_licheng;
parameters[5].Value = str_reason;
parameters[6].Value = str_mudd;
parameters[7].Value = str_back;
parameters[8].Value = str_beizhu;
int i = DBlHelper.ExecCommand(str_sql, parameters);
return i;
}
public static int update(int int_id, string str_chepai,string str_people, string str_dirver, string str_licheng, string str_reason, string str_mudd, DateTime str_back, string str_beizhu)
{
string str_sql = "update tb_chuche set 车牌号=@车牌号,用车人=@用车人,驾驶员=@驾驶员,出车里程=@出车里程,出车原因=@出车原因,目的地=@目的地,预计回车=@预计回车,出车备注=@出车备注 whe
re 车辆编号=@车辆编号";
SqlParameter[] parameters = {
new SqlParameter("@车辆编号", SqlDbType.Int,50),
new SqlParameter("@车牌号",SqlDbType.Char ,50),
new SqlParameter("@用车人",SqlDbType.Char ,50),
new SqlParameter("@驾驶员",SqlDbType.Char ,50),
new SqlParameter("@出车里程", SqlDbType.NChar,50),
new SqlParameter("@出车原因",SqlDbType.NText ,50),
new SqlParameter("@目的地",SqlDbType.Char ,50),
new SqlParameter("@预计回车", SqlDbType.DateTime,50),
new SqlParameter("@出车备注",SqlDbType.NText ,50),
};
parameters[0].Value = int_id;
parameters[1].Value = str_chepai;
parameters[2].Value = str_people;
parameters[3].Value = str_dirver;
parameters[4].Value = str_licheng;
parameters[5].Value = str_reason;
parameters[6].Value = str_mudd;
parameters[7].Value = str_back;
parameters[8].Value = str_beizhu;
int i = DBlHelper.ExecCommand(str_sql, parameters);
return i;
}
public static chuche read(int int_id)
{
chuche cc = new chuche();
string strRead = "select * from tb_chuche where 车辆编号=@车辆编号";
SqlParameter[] parameters = {
new SqlParameter("@车辆编号", SqlDbType.Int,50)
};
parameters[0].Value = int_id;
SqlDataReader reader = DBlHelper.ExecSqlDataReader(strRead,parameters);
if (reader.Read())//读一条记录
{
cc.chuche_id = int_id;
cc.chuche_chepai = reader["车牌号"].ToString();
cc.chuche_people = reader["用车人"].ToString();
cc.chuche_dirver = reader["驾驶员"].ToString();
cc.chuche_lichen = reader["出车里程"].ToString();
cc.chuche_reason = reader["出车原因"].ToString();
cc.chuche_mudd = reader["目的地"].ToString();
if (reader["预计回车"].ToString() == "")
{
cc.chuche_back = Convert.ToDateTime("2000-1-1 00:00:00");
}
else
{
cc.chuche_back=(DateTime)reader["预计回车"];
}
cc.chuche_beizhu = reader["出车备注"].ToString();
}
return cc;
}
}
}