using System; using System.Data; using System.Text; using System.Data.SqlClient; namespace Mtxfw.DAL { /// /// 数据访问类:county /// public partial class county : Mtxfw.Utility.Myabstract { public county() : base("county") { } /// /// 增加一条数据 /// public int Add(Mtxfw.Model.county model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into county("); strSql.Append("CountyID,CountyName,CityID,center)"); strSql.Append(" values ("); strSql.Append("@CountyID,@CountyName,@CityID,@center)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@CountyID", SqlDbType.NVarChar,50), new SqlParameter("@CountyName", SqlDbType.NVarChar,60), new SqlParameter("@CityID", SqlDbType.NVarChar,50), new SqlParameter("@center", SqlDbType.NVarChar,50)}; parameters[0].Value = model.CountyID; parameters[1].Value = model.CountyName; parameters[2].Value = model.CityID; parameters[3].Value = model.center; object obj = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public bool Update(Mtxfw.Model.county model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update county set "); strSql.Append("CountyName=@CountyName,"); strSql.Append("CountyID=@CountyID,"); strSql.Append("CityID=@CityID"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@CountyName", SqlDbType.NVarChar,60), new SqlParameter("@CityID", SqlDbType.NVarChar,50), new SqlParameter("@id", SqlDbType.Int,4), new SqlParameter("@CountyID", SqlDbType.NVarChar,50)}; parameters[0].Value = model.CountyName; parameters[1].Value = model.CityID; parameters[2].Value = model.id; parameters[3].Value = model.CountyID; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 更新一条数据 /// public bool Updatecenter(string center, int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("update county set "); strSql.Append("center=@center"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@center", SqlDbType.NVarChar,50), new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = center; parameters[1].Value = id; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from county "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete(string CountyID) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from county "); strSql.Append(" where CountyID=@CountyID "); SqlParameter[] parameters = { new SqlParameter("@CountyID", SqlDbType.NVarChar,50)}; parameters[0].Value = CountyID; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool DeleteList(string idlist) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from county "); strSql.Append(" where id in (" + idlist + ") "); int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString()); if (rows > 0) { return true; } else { return false; } } /// /// 获取县城名称 /// public String GetCounty(string CountyID) { string sql = "select top 1 * from county where CountyID='" + CountyID + "'"; DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { return ds.Tables[0].Rows[0]["CountyName"].ToString(); } else { return String.Empty; } } /// /// 获取县城CountyID /// public String GetCountyID(string CountyName) { string sql = "select top 1 * from county where CountyName like '%" + CountyName + "%'"; DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { return ds.Tables[0].Rows[0]["CountyID"].ToString(); } else { return String.Empty; } } /// /// 得到一个对象实体 /// public Mtxfw.Model.county GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,CountyID,CountyName,CityID from county "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Mtxfw.Model.county model = new Mtxfw.Model.county(); DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.CountyID = ds.Tables[0].Rows[0]["CountyID"].ToString(); model.CountyName = ds.Tables[0].Rows[0]["CountyName"].ToString(); model.CityID = ds.Tables[0].Rows[0]["CityID"].ToString(); return model; } else { return null; } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,CountyID,CountyName,CityID "); strSql.Append(" FROM county "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" id,CountyID,CountyName,CityID "); strSql.Append(" FROM county "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } } }