protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BOLItemRates ItemRatesBOL = new BOLItemRates(); ItemRates CurRate = ItemRatesBOL.GetDetail(_itemCode, _hCEntityCode); if (CurRate != null) { _starCount = Convert.ToInt32(CurRate.RateVal); } BindStars(); } }
protected void HandleRepeaterCommand(object source, RepeaterCommandEventArgs e) { string NewSavedRates = ""; if (Request.Cookies["Khabardaan"] != null) { string SavedRates = Request.Cookies["Khabardaan"]["Rate"]; if (SavedRates != "" && SavedRates != null) { string[] SavedRatesArray = SavedRates.Split(','); if (((IList)SavedRatesArray).Contains(_itemCode + "|" + _hCEntityCode)) { msgMessage.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error; msgMessage.Text = "شما قبلا به این مطلب رای داده اید."; return; } else { if (SavedRates == "") { NewSavedRates = _itemCode + "|" + _hCEntityCode; } else { NewSavedRates = SavedRates + "," + _itemCode + "|" + _hCEntityCode; } } } else { if (SavedRates == "") { NewSavedRates = _itemCode + "|" + _hCEntityCode; } else { NewSavedRates = SavedRates + "," + _itemCode + "|" + _hCEntityCode; } } } Response.Cookies["Khabardaan"].Expires = DateTime.Now.AddDays(365); Response.Cookies["Khabardaan"]["Rate"] = NewSavedRates; decimal NewRateVal = 0; ImageButton btnStar = (ImageButton)e.Item.FindControl("btnStar"); decimal RateVal = Convert.ToDecimal(btnStar.Attributes["Val"]); BOLItemRates ItemRatesBOL = new BOLItemRates(); ItemRates CurRate = ItemRatesBOL.GetDetail(_itemCode, _hCEntityCode); decimal CurrentAvg = 0; int CurrentCount = 0; if (CurRate != null) { CurrentAvg = (decimal)CurRate.RateVal; CurrentCount = (int)CurRate.RateCount; } //if (e.CommandName == "HalfStar") //{ // RateVal = RateVal + rptStars.Items.Count; //} NewRateVal = (RateVal + (CurrentAvg * CurrentCount)) / (CurrentCount + 1); ItemRatesBOL.UpdateVal(_itemCode, _hCEntityCode, NewRateVal, CurrentCount + 1); string JSCommand = ""; msgMessage.Text = "رای شما با موفقیت ثبت شد."; //JSCommand += " $(\"#" + msgMessage.ClientID + "\").fadeTo(\"slow\",0.9);"; //ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(string), "SelectMediaRow", JSCommand, true); _starCount = Convert.ToInt32(NewRateVal); BindStars(); }