/// <summary> /// ���� ��ӣ�ɾ������ /// </summary> /// <param name="mapZone"></param> /// <param name="ua"></param> /// <returns></returns> public bool MapZoneCreateDeleteUpdate(MapZone mapZone, UserAction ua) { bool result = false; string commandText = string.Empty; switch (ua) { case UserAction.Create: commandText = "INSERT INTO MapZone (MapZoneID, MapZoneName, MapZoneVisible,CityID) " + " VALUES (" + mapZone.ID + ",'" + mapZone.Name + "'," + mapZone.IsVisible + ","+mapZone.CityID +")"; break; case UserAction.Delete: commandText = "DELETE FROM MapZone where MapZoneID=" + mapZone.ID.ToString(); break; case UserAction.Update: commandText = "UPDATE MapZone SET MapZoneID = " + mapZone.ID + ", mapZoneName = '" + mapZone.Name + "', mapZoneVisible = " + mapZone.IsVisible +",CityID="+mapZone.CityID +" where MapZoneID="+mapZone.ID ; break; } using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commandText; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); result = true; } catch (Exception ex) { throw new Exception(ex.Message); } } } return result; }
/// <summary> /// ͨ��CityID��������б� /// </summary> /// <param name="cityID"></param> /// <returns></returns> public List<MapZone> GetMapZonesByCityID(int cityID) { List<MapZone> list = new List<MapZone>(); string commText = "select * from MapZone where CityID = "+cityID ; using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commText; conn.Open(); using (SqlDataReader reader = comm.ExecuteReader()) { while (reader.Read()) { MapZone mapz = new MapZone(); mapz.CityID = int.Parse(reader["CityID"].ToString()); mapz.ID = int.Parse(reader["MapZoneID"].ToString()); mapz.IsVisible = bool.Parse(reader["MapZoneVisible"].ToString()); mapz.Name = reader["MapZoneName"].ToString(); list.Add(mapz); } } } } } return list; }