/// <summary> /// �ض� ��ӣ�ɾ������ /// </summary> /// <param name="hotZone"></param> /// <param name="ua"></param> /// <returns></returns> public bool HotZoneCreateDeleteUpdate(HotZone hotZone, UserAction ua) { bool result = false; string commandText = string.Empty; switch (ua) { case UserAction.Create: commandText = "INSERT INTO HotZone (HotZoneID, HotZoneName, HotZoneVisible,CityID) " + " VALUES (" + hotZone.ID + ",'" + hotZone.Name + "'," + hotZone.IsVisible + "," + hotZone.ID + ")"; break; case UserAction.Delete: commandText = "DELETE FROM HotZone where HotZoneID=" + hotZone.ID.ToString(); break; case UserAction.Update: commandText = "UPDATE HotZone SET HotZoneID = " + hotZone.ID + ", HotZoneName = '" +hotZone.Name + "', HotZoneVisible = " + hotZone.IsVisible + ",MapZoneID=" + hotZone.MapZoneID +" where HotZoneID = "+hotZone.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> /// ͨ������ID���ߵض� /// </summary> /// <param name="MapZoneID"></param> /// <returns></returns> public List<HotZone> GetHotZonesByMapZoneID(int MapZoneID) { List<HotZone> list = new List<HotZone>(); string commText = "select * from HotZone"; 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()) { HotZone hotz = new HotZone(); hotz.MapZoneID = int.Parse(reader["MapZoneID"].ToString()); hotz.ID = int.Parse(reader["HotZoneID"].ToString()); hotz.IsVisible = bool.Parse(reader["HotZoneVisible"].ToString()); hotz.Name = reader["HotZoneName"].ToString(); list.Add(hotz); } } } } } return list; }