C#和sql设计的 车辆管理系统 课程设计报告,附带代码(2)

2020-06-23 12:20

1. namespace DA模块

public DataTable CarInfoSelectAll()

{ using (SqlConnection conn = DABase.CreateConnection()) { if (ConnectionState.Closed == conn.State) { conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand())

{ cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \ try

{ SqlDataAdapter Adapter = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); Adapter.Fill(ds); conn.Close();

return ds.Tables[0]; }

catch (SqlException sqlEx) { throw sqlEx; } } } }

public CarInfoModule CarInfoSelectOne(String CarID)

{ using (SqlConnection conn = DABase.CreateConnection()) { if (ConnectionState.Closed == conn.State) { conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \ #region 添加存储过程参数

cmd.Parameters.AddWithValue(\车辆标号 #endregion try

{ SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows == false) { dr.Close(); return null; }

CarInfoModule CarMod = new CarInfoModule(); dr.Read();

#region 读取字段值

CarMod.CarID = CommonSqlValue.GetString(0, dr); CarMod.CarType = CommonSqlValue.GetString(1, dr); CarMod.CarDriver = CommonSqlValue.GetString(2, dr);

5

CarMod.CarColor = CommonSqlValue.GetString(3, dr); CarMod.Carbuytime = CommonSqlValue.GetDateTime(4, dr); CarMod.CarLoad = CommonSqlValue.GetInt32(5, dr); #endregion dr.Close(); conn.Close(); return CarMod; }

catch (SqlException sqlEx) { throw sqlEx; } } } }

public void CarInfoDeleteOne(String CarID)

{ using (SqlConnection conn = DABase.CreateConnection()) { if (ConnectionState.Closed == conn.State) { conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand()) {

cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \ #region 添加存储过程参数

cmd.Parameters.AddWithValue(\记录序列号 #endregion try

{ cmd.ExecuteNonQuery(); conn.Close(); }

catch (SqlException sqlEx) { throw sqlEx; } } } }

public void CarInfoUpdateOne(CarInfoModule CarMod)

{ using (SqlConnection conn = DABase.CreateConnection()) { if (ConnectionState.Closed == conn.State) { conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand())

{ cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \

6

#region 添加存储过程参数

cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ #endregion try

{ cmd.ExecuteNonQuery(); conn.Close(); }

catch (SqlException sqlEx) {

switch (sqlEx.Number) { case 2601: case 2627:

throw new Exception(\修改记录失败!插入的键值已经存在,请确认后重试。如果仍有错误,请与管理员联系。\

case 8152: throw new Exception(\修改记录失败!字符串长度超出范围,请确认后重试。如果仍有错误,请与管理员联系。\

case 8115: throw new Exception(\修改记录失败!数值超出范围,请确认后重试。如果仍有错误,请与管理员联系。\default: throw sqlEx;

} } } } }

public void CarInfoInsertOne(CarInfoModule CarMod)

{ using (SqlConnection conn = DABase.CreateConnection()) { if (ConnectionState.Closed == conn.State) { conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand())

{ cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \ #region 添加存储过程参数

cmd.Parameters.AddWithValue(\cmd.Parameters.AddWithValue(\

cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ #endregion try { cmd.ExecuteNonQuery(); conn.Close(); }

catch (SqlException sqlEx)

7

{

switch (sqlEx.Number) {

case 2601: case 2627: throw new Exception(\添加记录失败!插入的键值已经存在,请确认后重试。如果仍有错误,请与管理员联系。\

case 8152: throw new Exception(\添加记录失败!字符串长度超出范围,请确认后重试。如果仍有错误,请与管理员联系。\

case 8115: throw new Exception(\添加记录失败!数值超出范围,请确认后重试。如果仍有错误,请与管理员联系。\ default: throw sqlEx;

} } } } } }} namespace DA

{ public partial class CarOutDA {

public DataTable CarOutSelectAll()

{ using (SqlConnection conn = DABase.CreateConnection()) {

if (ConnectionState.Closed == conn.State) { conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand()) {

cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \ try {

SqlDataAdapter Adapter = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); Adapter.Fill(ds); conn.Close();

return ds.Tables[0]; }

catch (SqlException sqlEx) { throw sqlEx; } } } }

public CarOutModule CarOutSelectOne1(DateTime date1,DateTime date2) { using (SqlConnection conn = DABase.CreateConnection()) { if (ConnectionState.Closed == conn.State) { conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand()) {

8

cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \ #region 添加存储过程参数

cmd.Parameters.AddWithValue(\ cmd.Parameters.AddWithValue(\ #endregion try

{ SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows == false) { dr.Close(); return null; }

CarOutModule CarOutMod = new CarOutModule(); dr.Read();

#region 读取字段值

CarOutMod.OutID = CommonSqlValue.GetString(0, dr); CarOutMod.OutCarID = CommonSqlValue.GetString(1, dr); CarOutMod.CarOutTime = CommonSqlValue.GetDateTime(2, dr); CarOutMod.CarInTime = CommonSqlValue.GetDateTime(3, dr); CarOutMod.OutFee = CommonSqlValue.GetDecimal(4, dr); #endregion dr.Close(); conn.Close(); return CarOutMod; }

catch (SqlException sqlEx) { throw sqlEx; } } } }

public void CarOutDeleteOne(String OutID)

{ using (SqlConnection conn = DABase.CreateConnection()) { if (ConnectionState.Closed == conn.State) {

conn.Open(); }

using (SqlCommand cmd = conn.CreateCommand())

{ cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = \ #region 添加存储过程参数

cmd.Parameters.AddWithValue(\用户编号 #endregion try

{ cmd.ExecuteNonQuery(); conn.Close(); }

9


C#和sql设计的 车辆管理系统 课程设计报告,附带代码(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017河南专监复习资料

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: