Esempio n. 1
0
        public void UpgradeRate(int id, int cRate, string Username)
        {
            db = new Db();
            course.Business_Layer.productBU productBU = new Business_Layer.productBU();
            Business_Layer.product          p         = productBU.GetProductbyID(id.ToString());

            double rate = Math.Round(p.rate, 2);

            if (p.votes != 0)
            {
                rate = Math.Round(p.rate * p.votes, 2);
            }
            if (ExistVote(id, Username))
            {
                double brate = double.Parse(productBU.Rate_cart(Username, id));
                rate -= brate; p.votes--;
            }
            p.votes++;
            double result = (Math.Round(rate, 2) + cRate) / p.votes;

            p.rate = Math.Round(result, 2);
            string sql = "update [product] set product_Rate='" + p.rate.ToString() + "', product_votes='" + p.votes.ToString() + "'  where Id='" + id.ToString() + "'";

            db.executecommand(sql);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            db            = new DataAccess.Db();
            SqlConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\course\course\App_Data\Library.mdf;Integrated Security=True");
            if (Request.QueryString["id"] == null)
            {
                Response.Redirect("items.aspx");
            }
            else
            {
                id = Convert.ToInt32(Request.QueryString["id"].ToString());

                string         sql = "select * from product where Id='" + id + "'";
                SqlCommand     cmd = db.executecommand(sql);
                DataTable      dt  = new DataTable();
                SqlDataAdapter da  = new SqlDataAdapter(cmd);
                da.Fill(dt);
                d1.DataSource = dt;
                d1.DataBind();
            }

            course.Business_Layer.productBU productBU = new Business_Layer.productBU();
            Business_Layer.product          p         = productBU.GetProductbyID(id.ToString());
            Rating.Text = p.rate.ToString();
        }