//实例类 public class CityModel { int _id; string _cityname; string _citycode; public int ID { set { _id = value; } get { return _id; } } public string CityName { set { _cityname = value; } get { return _cityname; } } public string CityCode { set { _citycode = value; } get { return _citycode; } } } //DAL层,返回DataTable,使用通用SqlHelper public DataTable CityList(string pcode) { string SQL = "SELECT * FROM city WHERE 1=1"; if (!string.IsNullOrEmpty(pcode)) { if (pcode.Substring(2, 2) != "00") { SQL = SQL + " AND RIGHT(citycode,2)'00' AND LEFT(citycode,4)=LEFT(@pcode,4)"; } else { SQL = SQL + " AND RIGHT(citycode,2)='00' AND LEFT(RIGHT(citycode,4),2)'00' AND LEFT(citycode,2)=LEFT(@pcode,2)"; } } else { SQL = SQL + " AND LEFT(citycode,2)'00' AND RIGHT(citycode,4)='0000'"; } SQL = SQL + " ORDER BY sorts ASC"; SqlParameter[] Param ={ new SqlParameter("@pcode",pcode) }; using (SqlConnection conn = new SqlConnection(DBUtility.SqlHelper.ConnectionStringLocalTransaction)) { DataSet ds = DBUtility.SqlHelper.ExecuteDataSet(conn, CommandType.Text, SQL, Param); return ds.Tables[0]; } } //BLL层,返回City的泛型列表 public List CityList(string code) { List list = new List(); DAL. CityDAL cd = new DAL.CityDAL(); DataTable dt = cd.CityList(code); if (dt.Rows.Count > 0) { for (int i = 0; i { CityModel cm = new CityModel(); cm.ID = int.Parse(dt.Rows[i]["id"].ToString()); cm.CityName = dt.Rows[i]["cityname"].ToString(); cm.CityCode = dt.Rows[i]["citycode"].ToString(); list.Add(cm); } } return list; }
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn