/// <summary> /// ����Ƶ���ؼ��ַ��� ��ӣ�ɾ������ /// </summary> /// <param name="hairNetTagGroup"></param> /// <param name="ua"></param> /// <returns></returns> public bool HairNetTagGroupCreateDeleteUpdate(HairNetTagGroup hairNetTagGroup, UserAction ua) { bool result = false; string commandText = string.Empty; switch (ua) { case UserAction.Create: commandText = "INSERT INTO HairNetTagGroup (HairNetTagGroupID, HairNetTagGroupName) VALUES (" + hairNetTagGroup.ID + ", '" + hairNetTagGroup.Name + "')"; break; case UserAction.Delete: commandText = "DELETE FROM HairNetTagGroup WHERE (HairNetTagGroupID = " + hairNetTagGroup.ID + ")"; break; case UserAction.Update: commandText = "UPDATE HairNetTagGroup SET HairNetTagGroupName ='" + hairNetTagGroup.Name + "' WHERE (HairNetTagGroupID = " + hairNetTagGroup.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> /// �������Ƶ���ؼ��ַ����б� /// </summary> /// <param name="count"></param> /// <returns></returns> public List<HairNetTagGroup> GetHairNetTagGroups(int count) { List<HairNetTagGroup> list = new List<HairNetTagGroup>(); string commText = string.Empty; switch (count) { case 0: commText = "SELECT * FROM HairNetTagGroup ORDER BY HairNetTagGroupID DESC"; break; default: commText = "select top " + count.ToString() + " * FROM HairNetTagGroup ORDER BY HairNetTagGroupID DESC"; break; } 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()) { HairNetTagGroup tag = new HairNetTagGroup(); tag.ID = int.Parse(reader["HairNetTagGroupID"].ToString()); tag.Name = reader["HairNetTagGroupName"].ToString(); list.Add(tag); } } } } } return list; }