279 lines
9.1 KiB
C#
279 lines
9.1 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace Mtxfw.DAL
|
|
{
|
|
/// <summary>
|
|
/// 数据访问类:city
|
|
/// </summary>
|
|
public partial class city : Mtxfw.Utility.Myabstract
|
|
{
|
|
public city()
|
|
: base("city")
|
|
{ }
|
|
|
|
/// <summary>
|
|
/// 增加一条数据
|
|
/// </summary>
|
|
public int Add(Mtxfw.Model.city model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("insert into city(");
|
|
strSql.Append("CityID,CityName,ProvinceID,pinyin,pinyinjx,citycode,center)");
|
|
strSql.Append(" values (");
|
|
strSql.Append("@CityID,@CityName,@ProvinceID,@pinyin,@pinyinjx,@citycode,@center)");
|
|
strSql.Append(";select SCOPE_IDENTITY()");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@CityID", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@CityName", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@ProvinceID", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@pinyin", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@pinyinjx", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@citycode", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@center", SqlDbType.NVarChar,50)
|
|
};
|
|
parameters[0].Value = model.CityID;
|
|
parameters[1].Value = model.CityName;
|
|
parameters[2].Value = model.ProvinceID;
|
|
parameters[3].Value = model.pinyin;
|
|
parameters[4].Value = model.pinyinjx;
|
|
parameters[5].Value = model.citycode;
|
|
parameters[6].Value = model.center;
|
|
object obj = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
if (obj == null)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return Convert.ToInt32(obj);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 更新一条数据
|
|
/// </summary>
|
|
public bool Update(Mtxfw.Model.city model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("update city set ");
|
|
strSql.Append("CityName=@CityName,");
|
|
strSql.Append("ProvinceID=@ProvinceID");
|
|
strSql.Append(" where id=@id");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@CityName", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@ProvinceID", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@id", SqlDbType.Int,4),
|
|
new SqlParameter("@CityID", SqlDbType.NVarChar,50)};
|
|
parameters[0].Value = model.CityName;
|
|
parameters[1].Value = model.ProvinceID;
|
|
parameters[2].Value = model.id;
|
|
parameters[3].Value = model.CityID;
|
|
|
|
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
if (rows > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 更新一条数据
|
|
/// </summary>
|
|
public bool Updatecenter(string center, int id)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("update city 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;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 删除一条数据
|
|
/// </summary>
|
|
public bool Delete(int id)
|
|
{
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("delete from city ");
|
|
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;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 删除一条数据
|
|
/// </summary>
|
|
public bool Delete(string CityID)
|
|
{
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("delete from city ");
|
|
strSql.Append(" where CityID=@CityID ");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@CityID", SqlDbType.NVarChar,50)};
|
|
parameters[0].Value = CityID;
|
|
|
|
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
|
|
if (rows > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 删除一条数据
|
|
/// </summary>
|
|
public bool DeleteList(string idlist)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("delete from city ");
|
|
strSql.Append(" where id in (" + idlist + ") ");
|
|
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString());
|
|
if (rows > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取城市名称
|
|
/// </summary>
|
|
public String GetCity(string CityID)
|
|
{
|
|
string sql = "select top 1 * from city where cityID='" + CityID + "'";
|
|
DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(sql);
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
return ds.Tables[0].Rows[0]["CityName"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return String.Empty;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取城市ID
|
|
/// </summary>
|
|
public String GetCityID(string CityName)
|
|
{
|
|
string sql = "select top 1 * from city where CityName like '%" + CityName + "%'";
|
|
DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(sql);
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
return ds.Tables[0].Rows[0]["CityID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return String.Empty;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 得到一个对象实体
|
|
/// </summary>
|
|
public Mtxfw.Model.city GetModel(int id)
|
|
{
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select top 1 id,CityID,CityName,ProvinceID from city ");
|
|
strSql.Append(" where id=@id");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@id", SqlDbType.Int,4)
|
|
};
|
|
parameters[0].Value = id;
|
|
|
|
Mtxfw.Model.city model = new Mtxfw.Model.city();
|
|
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.CityID = ds.Tables[0].Rows[0]["CityID"].ToString();
|
|
model.CityName = ds.Tables[0].Rows[0]["CityName"].ToString();
|
|
model.ProvinceID = ds.Tables[0].Rows[0]["ProvinceID"].ToString();
|
|
return model;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得数据列表
|
|
/// </summary>
|
|
public DataSet GetList(string strWhere)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select id,CityID,CityName,ProvinceID ");
|
|
strSql.Append(" FROM city ");
|
|
if (strWhere.Trim() != "")
|
|
{
|
|
strSql.Append(" where " + strWhere);
|
|
}
|
|
return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得前几行数据
|
|
/// </summary>
|
|
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,CityID,CityName,ProvinceID ");
|
|
strSql.Append(" FROM city ");
|
|
if (strWhere.Trim() != "")
|
|
{
|
|
strSql.Append(" where " + strWhere);
|
|
}
|
|
strSql.Append(" order by " + filedOrder);
|
|
return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString());
|
|
}
|
|
}
|
|
}
|
|
|