国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

投票用戶控件

2019-11-17 01:25:53
字體:
來源:轉載
供稿:網友
投票用戶控件
    //投票    PRotected void btn_Vote_Click(object sender, EventArgs e)    {        string useripAddress = Request.UserHostAddress.ToString();//獲取用戶本地的IP地址        HttpCookie oldCookie=Request.Cookies["UserIP"];//創建Cookie對象        if (oldCookie == null)//該用戶沒有投票記錄        {            int flag = this.rbl_Evaluate.SelectedIndex;//獲取用戶投票的選項            switch (flag)            {                case 0: AddCount(Server.MapPath("Result1.txt")); break;                case 1: AddCount(Server.MapPath("Result2.txt")); break;                case 2: AddCount(Server.MapPath("Result3.txt")); break;                default:                    break;            }            Page.RegisterClientScriptBlock("", "<script>alert('投票成功,謝謝您的參與')<script>");            HttpCookie newCookie = new HttpCookie("UserIP");//創建新的Cookie對象            newCookie.Expires = DateTime.MaxValue;//設置Cookie的有效時間            newCookie.Values.Add("IPAddress", userIpAddress);//添加用戶的IP地址在Cookie中,保存起來            Response.AppendCookie(newCookie);//將變量寫入Cookie文件中        }        else        {            string userOldAddress = oldCookie.Values["IPAddress"].ToString();            if (userIpAddress.Trim() == userOldAddress.Trim())//創建Cookie對象            {                Page.RegisterClientScriptBlock("", "<script>alert('每天只能投票一次,謝謝您的光顧!!')</script>");            }            else            {                HttpCookie newCookie = new HttpCookie("UserIP");//創建新的Cookie對象                newCookie.Values.Add("IpAddress", userIpAddress);                newCookie.Expires = DateTime.MaxValue;                Response.AppendCookie(newCookie);                int flag = this.rbl_Evaluate.SelectedIndex;                switch (flag)                {                    case 0: AddCount(Server.MapPath("Result1.txt")); break;                    case 1: AddCount(Server.MapPath("Result2.txt")); break;                    case 2: AddCount(Server.MapPath("Result3.txt")); break;                    default:                        break;                }                Page.RegisterClientScriptBlock("", "<script>alert('投票成功謝謝您的參與')</script>");            }        }    }    
    /// <summary>    /// 讀取文本文件中的數字    /// </summary>    /// <param name="str_path">文本文件的路徑</param>    /// <returns>返回結果</returns>    protected static int ReadCount(string str_path)    {        int count = 0;//創建整形的變量        System.IO.StreamReader srd;//創建流讀取對象        srd = System.IO.File.OpenText(str_path);//打開指定的文本文件        if (srd.Peek()!=-1)//如果有數據        {            count = int.Parse(srd.ReadLine());//讀取文本文件的數字賦值給count        }        srd.Close();//關閉流對象        return count;      }

    /// <summary>    /// 對現有的投票數進行增加    /// </summary>    /// <param name="str_path">文本文件的路徑</param>    protected static void AddCount(string str_path)    {        int count = ReadCount(str_path);        count += 1;        System.IO.StreamWriter swr = new System.IO.StreamWriter(str_path);//將數據的記錄寫入文件        swr.WriteLine(count);        swr.Close();    }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沐川县| 阿图什市| 公安县| 新密市| 巩留县| 吴旗县| 三亚市| 新昌县| 丰都县| 瑞丽市| 奇台县| 怀仁县| 柏乡县| 卢龙县| 双鸭山市| 区。| 个旧市| 扶沟县| 吉林市| 玛曲县| 偃师市| 噶尔县| 塔河县| 仁怀市| 桦甸市| 禹城市| 巴塘县| 环江| 海兴县| 密山市| 鹤岗市| 泰兴市| 九江县| 嫩江县| 古田县| 沁水县| 沅江市| 乌恰县| 库伦旗| 崇信县| 霍城县|