C#评星功能的实现(转载)

 

一、RettingSetting类

using  System;
using  System.Collections.Generic;
using  System.Text;
///   <summary>
    
///  计算投票评均值
    
///   </summary>
     public   class  RetingSettings
    {
        
        
private   bool  _showHalfImage  =   false ; // 是否显示有小数部分
         private   double  _roundValue; // 平均值的整数部分
         private   int  _imageHalfnum;  // 根据值显示图片
         ///   <summary>
        
///  
        
///   </summary>
        
///   <param name="totalScore"> 总分数 </param>
        
///   <param name="evaluationnum"> 评价人数 </param>
        
///   <param name="num"></param>
         public  RetingSettings( int  totalScore,  int  evaluationnum)
        {
            
double  _average  =  ( double )totalScore  / ( double )evaluationnum; // 平均值
            _roundValue   =  Math.Truncate(_average);
            
int  remainder  =  ( int )((_average  -  _roundValue)  *   10 ); // 平均值的小数部分
           
                
if (remainder > 0   && remainder < 3 )
                {
                    _showHalfImage 
=   true ;
                    _imageHalfnum 
=   1 ;
                }
else   if (  remainder >= 3   &&  remainder < 7 )
                {
                    _showHalfImage 
=   true ;
                    _imageHalfnum 
=   2 ;
                }
else   if (remainder >= 7   &&  remainder <= 9 )
                {    
                    _showHalfImage 
=   true ;
                    _imageHalfnum 
=   3 ;
                }
                
else   if  (remainder  ==   0 )
                {
                    _imageHalfnum 
=   0 ;
                }
            }

        
///   <summary>
        
///  平均值的整数部分
        
///   </summary>
         public   int  RroundValue
        {
            
get  {  return  ( int )_roundValue; }
        }
        
///   <summary>
        
///  是否有小数部分
        
///   </summary>
         public   bool  ShowHalfImage
        {
            
get  {  return  _showHalfImage; }
        }
        
///   <summary>
        
///  根据值显示图片
        
///   </summary>
         public   int  ImageHalfnum
        {
            
get  {  return  _imageHalfnum; }
        }
    }
二、根据评论分数显示图片
using  System;
using  System.Data;
using  System.Configuration;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;
using  System.Collections;
using  System.Text;
using  System.Data.SqlClient;
///   <summary>
///  px 的摘要说明
///   </summary>
public   class  px
{
public  px()
{
  
//
  
//  TODO: 在此处添加构造函数逻辑
  
//
    }
    
#region  属性
    
private   int  _dp_id;
    
private   string  _dp_yj;
    
private   int  _use_id;
    
private   int  _shop_id;
    
private   int  _fw;
    
private   int  _kw;
    
private   int  _hj;
    
private   int  _xjb;
    
private  DateTime _dp_datetime;
    
private   string  _dp_ip;
    
///   <summary>
    
///  
    
///   </summary>
     public   int  dp_id
    {
        
set  { _dp_id  =  value; }
        
get  {  return  _dp_id; }
    }
    
///   <summary>
    
///  点评意见
    
///   </summary>
     public   string  dp_yj
    {
        
set  { _dp_yj  =  value; }
        
get  {  return  _dp_yj; }
    }
    
///   <summary>
    
///  
    
///   </summary>
     public   int  use_id
    {
        
set  { _use_id  =  value; }
        
get  {  return  _use_id; }
    }
    
///   <summary>
    
///  
    
///   </summary>
     public   int  shop_id
    {
        
set  { _shop_id  =  value; }
        
get  {  return  _shop_id; }
    }
    
///   <summary>
    
///  服务
    
///   </summary>
     public   int  fw
    {
        
set  { _fw  =  value; }
        
get  {  return  _fw; }
    }
    
///   <summary>
    
///  口味
    
///   </summary>
     public   int  kw
    {
        
set  { _kw  =  value; }
        
get  {  return  _kw; }
    }
    
///   <summary>
    
///  环境
    
///   </summary>
     public   int  hj
    {
        
set  { _hj  =  value; }
        
get  {  return  _hj; }
    }
    
///   <summary>
    
///  性价比
    
///   </summary>
     public   int  xjb
    {
        
set  { _xjb  =  value; }
        
get  {  return  _xjb; }
    }
    
///   <summary>
    
///  
    
///   </summary>
     public  DateTime dp_datetime
    {
        
set  { _dp_datetime  =  value; }
        
get  {  return  _dp_datetime; }
    }
    
///   <summary>
    
///  
    
///   </summary>
     public   string  dp_ip
    {
        
set  { _dp_ip  =  value; }
        
get  {  return  _dp_ip; }
    }
    
#endregion
    
public   static   int  attachnum  =   0 ; // 表示参与点评的人数
     public   static  ArrayList fimgList  =   null ;
    
public   static  Image image = null ; // 图片档案
     public   static  Image fimage = null ;
    
public   static   int  _starnum  =   5 ; // 默认设置5颗星
     public   static   void  Fimgbuding( string  shop_id, string  columnname)
    {
        
int  starno;
        
int  fullstar  =   0 ;
        
int  halfstarnum  =   0 ;
        
bool  HalfImage  =   false ; // 是否有半星

        attachnum 
=  Convert.ToInt32(DataHelpe.ExecuteScalar( " select dp_count from v_店铺详细统计信息 where shop_id=' "   +  shop_id  +   " ' " ).ToString());
        RetingSettings se 
=   new  RetingSettings(Convert.ToInt32(DataHelpe.ExecuteScalar( " select  "   +  columnname  +   "  from v_店铺详细统计信息 where shop_id=' "   +  shop_id  +   " ' " ).ToString()), attachnum);
        
// if (se.ShowHalfImage) // 是否有半星图片
        
// {
        halfstarnum  =  se.ImageHalfnum;
        fullstar 
=  se.RroundValue;
        HalfImage 
=  se.ShowHalfImage;
        fimgList 
=   new  System.Collections.ArrayList();

        
for  ( int  j  =   1 ; j  <=  fullstar; j ++ )
        {
            fimage 
=   new  Image();
            fimage.ID 
=   " ss_starfull "   +  j.ToString();
            fimage.ImageUrl 
=   " ../px/v2_gx_hxx1.gif " ;
            fimgList.Add(fimage);
        }
        
if  (HalfImage)
        {
            fimage 
=   new  Image();
            fimage.ID 
=   " ss_starhalf " ;
            fimage.ImageUrl 
=   " ../px/v2_gx_hxx3n "   +  halfstarnum.ToString()  +   " .gif " ;
            fimgList.Add(fimage);
        }
        
if  (HalfImage)
            starno 
=  _starnum  -  fullstar  -   1 ;
        
else
            starno 
=  _starnum  -  fullstar;
        
for  ( int  i  =   1 ; i  <=  starno; i ++ )
        {
            fimage 
=   new  Image();
            fimage.ID 
=   " ss_starno "   +  i.ToString();
            fimage.ImageUrl 
=   " ../px/v2_gx_hxx2.gif " ;
            fimgList.Add(fimage);
        }
    }
    
public   static   string  result( string  shop_id, string  column)
    {
        px.Fimgbuding(shop_id,column);
        ArrayList al 
=  px.fimgList;
        
string  img  =   "" ;
        
for  ( int  i  =   0 ; i  <  al.Count; i ++ )
        {
            
// '<%=  ((Image)al).ImageUrl%>' style="width:12px;height:14px;" />
            
//   <%
            Image img1  =  (Image)al;
            img 
+=   " <img src= " + img1.ImageUrl + "  style='width:14px;height:15px;' /> " ;
        }
        
return  img;
    }
    
// 返回商家总的点评数
     public   static   string  dp_count( string  shop_id)
    {
        
return  DataHelpe.ExecuteScalar( " select dp_count from v_店铺详细统计信息 where shop_id=' "   +  shop_id  +   " ' " ).ToString();
    }
    
// 插入评论信息
    
    
public   int  Add(px p)
    {
        StringBuilder strSql 
=   new  StringBuilder();
        strSql.Append(
" insert into 点评表( " );
        strSql.Append(
" dp_yj,use_id,shop_id,fw,kw,hj,xjb,dp_datetime,dp_ip) " );
        strSql.Append(
"  values ( " );
        strSql.Append(
" @dp_yj,@use_id,@shop_id,@fw,@kw,@hj,@xjb,@dp_datetime,@dp_ip) " );       
        SqlParameter[] parameters 
=  {
     
new  SqlParameter( " @dp_yj " , SqlDbType.VarChar, 1000 ),
     
new  SqlParameter( " @use_id " , SqlDbType.Int, 4 ),
     
new  SqlParameter( " @shop_id " , SqlDbType.Int, 4 ),
     
new  SqlParameter( " @fw " , SqlDbType.Int, 4 ),
     
new  SqlParameter( " @kw " , SqlDbType.Int, 4 ),
     
new  SqlParameter( " @hj " , SqlDbType.Int, 4 ),
     
new  SqlParameter( " @xjb " , SqlDbType.Int, 4 ),
     
new  SqlParameter( " @dp_datetime " , SqlDbType.DateTime),
     
new  SqlParameter( " @dp_ip " , SqlDbType.VarChar, 50 )};
        parameters[
0 ].Value  =  p.dp_yj;
        parameters[
1 ].Value  =  p.use_id;
        parameters[
2 ].Value  =  p.shop_id;
        parameters[
3 ].Value  =  p.fw;
        parameters[
4 ].Value  =  p.kw;
        parameters[
5 ].Value  =  p.hj;
        parameters[
6 ].Value  =  p.xjb;
        parameters[
7 ].Value  =  p.dp_datetime;
        parameters[
8 ].Value  =  p.dp_ip;
        
return  DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);    
    }
    
// 返回用户的评论信息
     public   static   void  Fimgbuding_use( string  columnname, string  dp_id)
    {
        
int  starno;
        
int  fullstar  =   0 ;
        
int  halfstarnum  =   0 ;
        
bool  HalfImage  =   false ; // 是否有半星

        attachnum 
=   1 ;
        RetingSettings se 
=   new  RetingSettings(Convert.ToInt32(DataHelpe.ExecuteScalar( " select  "   +  columnname  +   "  from 点评表 where dp_id=' "   +  dp_id  +   " ' " )), attachnum);
        
// if (se.ShowHalfImage) // 是否有半星图片
        
// {
        halfstarnum  =  se.ImageHalfnum;
        fullstar 
=  se.RroundValue;
        HalfImage 
=  se.ShowHalfImage;
        fimgList 
=   new  System.Collections.ArrayList();

        
for  ( int  j  =   1 ; j  <=  fullstar; j ++ )
        {
            fimage 
=   new  Image();
            fimage.ID 
=   " ss_starfull "   +  j.ToString();
            fimage.ImageUrl 
=   " ../px/v2_gx_hxx1.gif " ;
            fimgList.Add(fimage);
        }
        
if  (HalfImage)
        {
            fimage 
=   new  Image();
            fimage.ID 
=   " ss_starhalf " ;
            fimage.ImageUrl 
=   " ../px/v2_gx_hxx3n "   +  halfstarnum.ToString()  +   " .gif " ;
            fimgList.Add(fimage);
        }
        
if  (HalfImage)
            starno 
=  _starnum  -  fullstar  -   1 ;
        
else
            starno 
=  _starnum  -  fullstar;
        
for  ( int  i  =   1 ; i  <=  starno; i ++ )
        {
            fimage 
=   new  Image();
            fimage.ID 
=   " ss_starno "   +  i.ToString();
            fimage.ImageUrl 
=   " ../px/v2_gx_hxx2.gif " ;
            fimgList.Add(fimage);
        }
    }
    
public   static   string  result_use( string  column, string  dp_id)
    {
        px.Fimgbuding_use(column,dp_id);
        ArrayList al 
=  px.fimgList;
        
string  img  =   "" ;
        
for  ( int  i  =   0 ; i  <  al.Count; i ++ )
        {
            
// '<%=  ((Image)al).ImageUrl%>' style="width:12px;height:14px;" />
            
//   <%
            Image img1  =  (Image)al;
            img 
+=   " <img src= "   +  img1.ImageUrl  +   "  style='width:12px;height:14px;'/> " ;
        }
        
return  img;
    }
    
}

转载于:https://www.cnblogs.com/zhjzwl/archive/2009/02/27/1399231.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值