网上投票系统很多,但是用起来不放心.这样我亲自花了点时间完成了一个微信投票系统.
具体可以看我刚刚上线的案例:www.dukyun.com
开发环境:c#+sqlserver
开发微信投票手机端只需要3个页面:投票首页、排行榜、投票内容页。
效果如图:
首先.我们来读取首页的数据,关键代码如下:
protected override void LoadTemplateFile(string fileName)
{
BindCommData();
//开始加载栏目
string bid = Request.QueryString["bid"];//
if (!StringHelper.isNum(bid))
{
Response.Write("参数格式不正确!");
Response.End();
return;
}
string templatefile = "index.html";
if (!string.IsNullOrEmpty(bid))
{
DataRowView model = BLL.DataBaseHelper.instance.GetModelView("channel", "diyfileurl", "bid=" + bid);
if (model != null)
{
templatefile = model["diyfileurl"].ToString();//模板文件
}
}
string template = "default";
if (hs["template"] == null || hs["template"] == "")
{
throw new Exception("webconfig表缺少template参数");
}
else
{
template = hs["template"].ToString();
}
if (string.IsNullOrEmpty(templatefile))//判断是否设置了模板.
{
Response.Write("你还没有设置该栏目(编号为:" + bid + ",类型:封面模板)下的模板文件!请在后台栏目管理->高级->封面模板中设置.设置示例:index.html");
Response.End();
return;
}
string filename = Common.DataCache.GetCache("home_" + templatefile) as string;
if (filename == null)
{
filename = this.Server.MapPath("~/templets/" + template + "/" + templatefile);
Common.DataCache.SetCache("home_" + templatefile, filename);
}
base.LoadTemplateFile(filename);
}
这里主要是读取数据输出ashx文件模版.
然后读取排行榜:
protected override void LoadTemplateFile(string fileName)
{
BindCommData();
//开始加载栏目
string projectid = Request.QueryString["proid"];//
if (!StringHelper.isNum(projectid))
{
Response.Write("参数格式不正确!");
Response.End();
return;
}
string templatefile = "top.html";
string templatefolder = string.Empty;
if (!string.IsNullOrEmpty(projectid))
{
DataRowView model = BLL.DataBaseHelper.instance.GetModelView("u_voteproject", "*", "id=" + projectid);
if (model != null)
{
if (Convert.ToBoolean(model["islock"]) == true)
{
Response.Write("该活动已过期并被主办方删除,不再显示!");
Response.End();
return;
}
hs.Add("vote", model);
hs.Add("base", BaseWeb.BaseUrl + "/votetemplets/" + model["template_folder"] + "/");
templatefolder = model["template_folder"].ToString();
}
}
if (string.IsNullOrEmpty(templatefile))//判断是否设置了模板.
{
Response.Write("没有找到该项目(编号为:" + projectid + "的模版");
Response.End();
return;
}
string filename = Common.DataCache.GetCache("v_" + templatefile + "_" + projectid) as string;
if (filename == null)
{
filename = this.Server.MapPath("~/votetemplets/" + templatefolder + "/" + templatefile);
Common.DataCache.SetCache("v_" + templatefile + "_" + projectid, filename);
}
base.LoadTemplateFile(filename);
}
最后,我们在简单实现读取投票详细页面.
如需要源码我可以免费提供,在评论区留下你的email地址即可.