/// <summary> /// ���������Ʒ�Ƽ� /// </summary> /// <param name="count">0 ȫ��</param> /// <returns></returns> public List<ProductRecommand> GetProductRecommands(int count) { List<ProductRecommand> list = new List<ProductRecommand>(); string commText = ""; switch (count) { case 0: commText = "select * from ProductRecommand pr left join Product p on pr.ProductRawID = p.ProductID order by pr.ProductRecommandID desc"; break; default: commText = "select top "+count.ToString()+" * from ProductRecommand pr left join Product p on pr.ProductRawID = p.ProductID order by pr.ProductRecommandID desc"; break; } using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commText; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { ProductRecommand productRecommand = new ProductRecommand(); productRecommand.ProductRecommandID = int.Parse(sdr["ProductRecommandID"].ToString()); productRecommand.ProductRawID = int.Parse(sdr["ProductRawID"].ToString()); productRecommand.ProductName = sdr["ProductName"].ToString(); productRecommand.ProductCompany = sdr["ProductCompany"].ToString(); productRecommand.ProductCompanyDescription = sdr["ProductCompanyDescription"].ToString(); productRecommand.ProductPictureStoreIDs = sdr["ProductPictureStoreIDs"].ToString(); productRecommand.ProductHits = int.Parse(sdr["ProductHits"].ToString()); productRecommand.ProductDescription = sdr["ProductDescription"].ToString(); productRecommand.HairShopIDs = sdr["HairShopIDs"].ToString(); productRecommand.ProductRawPrice = sdr["ProductRawPrice"].ToString(); productRecommand.ProductPrice = sdr["ProductPrice"].ToString(); productRecommand.ProductDiscount = sdr["ProductDiscount"].ToString(); productRecommand.ProductTagIDs = sdr["ProductTagIDs"].ToString(); productRecommand.ProductRecommandEx = sdr["ProductRecommandEx"].ToString(); productRecommand.ProductRecommandInfo = sdr["ProductRecommandInfo"].ToString(); list.Add(productRecommand); } } } } } return list; }
/// <summary> /// ������Ʒ�Ƽ� ��ӣ�ɾ������ /// </summary> /// <param name="productRecommand"></param> /// <param name="ua"></param> /// <returns></returns> public bool ProductRecommandCreateDeleteUpdate(ProductRecommand productRecommand, UserAction ua) { bool result = false; string commandText = string.Empty; switch (ua) { case UserAction.Create: commandText = "insert into ProductRecommand(ProductRawID,ProductName,ProductCompany,ProductCompanyDescription,ProductPictureStoreIDs,ProductDescription,HairShopIDs,ProductRawPrice,ProductPrice,ProductDiscount,ProductTagIDs,ProductRecommandEx,ProductRecommandInfo) values(" + productRecommand.ProductRawID.ToString() + ",'" + productRecommand.ProductName + "','" + productRecommand.ProductCompany + "','" + productRecommand.ProductCompanyDescription + "','" + productRecommand.ProductPictureStoreIDs + "','" + productRecommand.ProductDescription + "','" + productRecommand.HairShopIDs + "','" + productRecommand.ProductRawPrice + "','" + productRecommand.ProductPrice + "','" + productRecommand.ProductDiscount + "','" + productRecommand.ProductTagIDs + "','"+productRecommand.ProductRecommandEx+"','"+productRecommand.ProductRecommandInfo+"')"; break; case UserAction.Delete: commandText = "delete from ProductRecommand where ProductRecommandID=" + productRecommand.ProductRecommandID.ToString(); break; case UserAction.Update: commandText = "update ProductRecommand set ProductRawID=" + productRecommand.ProductRawID.ToString() + ",ProductName='" + productRecommand.ProductName + "',ProductCompany='" + productRecommand.ProductCompany + "',ProductCompanyDescription='" + productRecommand.ProductCompanyDescription + "',ProductPictureStoreIDs='" + productRecommand.ProductPictureStoreIDs + "',ProductDescription='" + productRecommand.ProductDescription + "',HairShopIDs='" + productRecommand.HairShopIDs + "',ProductRawPrice='" + productRecommand.ProductRawPrice + "',ProductPrice='" + productRecommand.ProductPrice + "',ProductDiscount='" + productRecommand.ProductDiscount + "',ProductTagIDs='" + productRecommand.ProductTagIDs + "',ProductRecommandEx='"+productRecommand.ProductRecommandEx+"',ProductRecommandInfo='"+productRecommand.ProductRecommandInfo+"' where ProductRecommandID = " + productRecommand.ProductRecommandID.ToString(); 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="productID"></param> /// <returns></returns> public ProductRecommand GetProductRecommandByProductRecommandID(int productRecommandID) { ProductRecommand productRecommand = new ProductRecommand(); using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { string commText = "select * from ProductRecommand pr left join Product p on pr.ProductRawID = p.ProductID where pr.ProductRecommandID=" + productRecommandID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commText; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { if (sdr.Read()) { productRecommand.ProductRecommandID = int.Parse(sdr["ProductRecommandID"].ToString()); productRecommand.ProductRawID = int.Parse(sdr["ProductRawID"].ToString()); productRecommand.ProductName = sdr["ProductName"].ToString(); productRecommand.ProductCompany = sdr["ProductCompany"].ToString(); productRecommand.ProductCompanyDescription = sdr["ProductCompanyDescription"].ToString(); productRecommand.ProductPictureStoreIDs = sdr["ProductPictureStoreIDs"].ToString(); productRecommand.ProductHits = int.Parse(sdr["ProductHits"].ToString()); productRecommand.ProductDescription = sdr["ProductDescription"].ToString(); productRecommand.HairShopIDs = sdr["HairShopIDs"].ToString(); productRecommand.ProductRawPrice = sdr["ProductRawPrice"].ToString(); productRecommand.ProductPrice = sdr["ProductPrice"].ToString(); productRecommand.ProductDiscount = sdr["ProductDiscount"].ToString(); productRecommand.ProductTagIDs = sdr["ProductTagIDs"].ToString(); productRecommand.ProductRecommandEx = sdr["ProductRecommandEx"].ToString(); productRecommand.ProductRecommandInfo = sdr["ProductRecommandInfo"].ToString(); } } } } return productRecommand; }