Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5.  
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9.  
  10.  
  11. /// <summary>
  12. /// Summary description for ProductRecommendation
  13. /// </summary>
  14. public class ProductRecommendation
  15. {
  16. string connStr = ConfigurationManager.ConnectionStrings["ProductContext"].ConnectionString;
  17. private string _prodID;
  18. private string _prod_Name;
  19. private decimal _unit_Price;
  20. private int _stock_Quantity;
  21.  
  22. public string Product_ID
  23. {
  24. get { return _prodID; }
  25. set { _prodID = value; }
  26. }
  27. public string Product_Name
  28. {
  29. get { return _prod_Name; }
  30. set { _prod_Name = value; }
  31. }
  32. public decimal Unit_Price
  33. {
  34. get { return _unit_Price; }
  35. set { _unit_Price = value; }
  36. }
  37. public int QuantityInStock
  38. {
  39. get { return _stock_Quantity; }
  40. set { _stock_Quantity = value; }
  41. }
  42.  
  43. public ProductRecommendation()
  44. {
  45.  
  46. }
  47.  
  48. public ProductRecommendation(string prodID, string prod_Name, decimal unit_Price, int stock_Quantity)
  49. {
  50. _prodID = prodID;
  51. _prod_Name = prod_Name;
  52. _unit_Price = unit_Price;
  53. _stock_Quantity = stock_Quantity;
  54. }
  55.  
  56. public ProductRecommendation Recommendation(string prodID)
  57. {
  58. ProductRecommendation prodDetail = null;
  59.  
  60. string prod_Name;
  61. decimal unit_Price;
  62. int stock_Quantity;
  63.  
  64. string queryStr = "SELECT * FROM Product WHERE Product_ID = @ProdID";
  65. SqlConnection conn = new SqlConnection(connStr);
  66. SqlCommand cmd = new SqlCommand(queryStr, conn);
  67. cmd.Parameters.AddWithValue("@ProdID", prodID);
  68. conn.Open();
  69. SqlDataReader dr = cmd.ExecuteReader();
  70.  
  71. if (dr.Read())
  72. {
  73. prod_Name = dr["Product_Name"].ToString();
  74. unit_Price = decimal.Parse(dr["Unit_Price"].ToString());
  75. stock_Quantity = int.Parse(dr["QuantityInStock"].ToString());
  76.  
  77. prodDetail = new ProductRecommendation(prodID, prod_Name, unit_Price, stock_Quantity);
  78. }
  79. else
  80. {
  81. prodDetail = null;
  82. }
  83.  
  84. conn.Close();
  85. dr.Close();
  86. dr.Dispose();
  87. return prodDetail;
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement