Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- /// <summary>
- /// Summary description for ProductRecommendation
- /// </summary>
- public class ProductRecommendation
- {
- string connStr = ConfigurationManager.ConnectionStrings["ProductContext"].ConnectionString;
- private string _prodID;
- private string _prod_Name;
- private decimal _unit_Price;
- private int _stock_Quantity;
- public string Product_ID
- {
- get { return _prodID; }
- set { _prodID = value; }
- }
- public string Product_Name
- {
- get { return _prod_Name; }
- set { _prod_Name = value; }
- }
- public decimal Unit_Price
- {
- get { return _unit_Price; }
- set { _unit_Price = value; }
- }
- public int QuantityInStock
- {
- get { return _stock_Quantity; }
- set { _stock_Quantity = value; }
- }
- public ProductRecommendation()
- {
- }
- public ProductRecommendation(string prodID, string prod_Name, decimal unit_Price, int stock_Quantity)
- {
- _prodID = prodID;
- _prod_Name = prod_Name;
- _unit_Price = unit_Price;
- _stock_Quantity = stock_Quantity;
- }
- public ProductRecommendation Recommendation(string prodID)
- {
- ProductRecommendation prodDetail = null;
- string prod_Name;
- decimal unit_Price;
- int stock_Quantity;
- string queryStr = "SELECT * FROM Product WHERE Product_ID = @ProdID";
- SqlConnection conn = new SqlConnection(connStr);
- SqlCommand cmd = new SqlCommand(queryStr, conn);
- cmd.Parameters.AddWithValue("@ProdID", prodID);
- conn.Open();
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- prod_Name = dr["Product_Name"].ToString();
- unit_Price = decimal.Parse(dr["Unit_Price"].ToString());
- stock_Quantity = int.Parse(dr["QuantityInStock"].ToString());
- prodDetail = new ProductRecommendation(prodID, prod_Name, unit_Price, stock_Quantity);
- }
- else
- {
- prodDetail = null;
- }
- conn.Close();
- dr.Close();
- dr.Dispose();
- return prodDetail;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement