当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 4

codesix / SimpleQuestionnaire
关闭

forked from 冷盖天 / SimpleQuestionnaire
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Default.aspx.cs 2.81 KB
一键复制 编辑 原始数据 按行查看 历史
WDF 提交于 2019-07-06 10:06 . 修改Cookie读取
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page
{
const string SQL_VOTE_SELECT = "SELECT 本轮投票编号,本轮投票标题,CASE WHEN 本轮投票截止时间>GETDATE() THEN '1' ELSE '0' END 是否过期 FROM tbl_vote_conf ORDER BY 本轮投票开始时间 DESC";
//原始跳转
static string FMT_ITEM = "<div class=\"weui-cell\"><div class=\"weui-cell__bd\"> <a href=\"Questionnaire.aspx?voteNo={0}\">{1}</a></div></div>";
protected void Page_Load(object sender, EventArgs e)
{
try
{
MakeClient();
DataTable dtVote = new DataTable();
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["Questionnaire"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(SQL_VOTE_SELECT, conn))
{
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dtVote);
}
}
StringBuilder sbCurrentPeriod = new StringBuilder();
StringBuilder sbPassedPeriod = new StringBuilder();
foreach (DataRow dr in dtVote.Rows)
{
if (dr["是否过期"] != DBNull.Value && dr["是否过期"].ToString() == "1")
{
sbCurrentPeriod.AppendFormat(FMT_ITEM, dr["本轮投票编号"], dr["本轮投票标题"]);
}
else
{
sbPassedPeriod.AppendFormat(FMT_ITEM, dr["本轮投票编号"], dr["本轮投票标题"]);
}
}
currentperiod.Text = sbCurrentPeriod.ToString();
passedperiod.Text = sbPassedPeriod.ToString();
}
catch (Exception err)
{
currentperiod.Text = "出错了," + err.Message;
}
}
//没有集成到微信里面暂时用cookie代替
void MakeClient()
{
HttpCookie cookie = Request.Cookies["openId"];
if (null == cookie)
{
string openId = Guid.NewGuid().ToString("N");
Session["openId"] = openId;
cookie = new HttpCookie("openId");
cookie.Values["openId"] = openId;
cookie.Expires = DateTime.Now.AddYears(100);
Response.Cookies.Add(cookie);
}
else
{
cookie.Expires = DateTime.Now.AddYears(100);
Session["openId"] = cookie.Values["openId"] ;
}
}
}
C#
1
https://gitee.com/qau/SimpleQuestionnaire.git
git@gitee.com:qau/SimpleQuestionnaire.git
qau
SimpleQuestionnaire
SimpleQuestionnaire
origin

搜索帮助