예제 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetNoStore();
        bool reviewIsCheck = false;
        B_Review bll = new B_Review();
        B_SiteInfo SiteBll = new B_SiteInfo();
        B_User bllUser = new B_User();
        M_Review model = new M_Review();
        M_User userModel = null;
        if (Request.Form["txtIsLogin"] == "False")
        {
            if (Request.Form["btnSubmit"] == "登录")
            {
                bool flaglogin = true;
                string msgBox = string.Empty;
                if (Request.Form["UserName"].ToString().Trim() == "")
                {
                    flaglogin = false;
                    msgBox = "<script>alert('用户名必须填写');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                }
                else if (Request.Form["userPwd"].ToString().Trim() == "")
                {
                    flaglogin = false;
                    msgBox = "<script>alert('密码必须填写');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                }
                if (flaglogin)
                {

                    ltMsg.Text = "";
                    string logName = "";
                    string pwd = "";
                    string cookieType = "";

                    logName = Function.UrlDecode(Request.Form["UserName"].ToString());
                    pwd = Function.MD5Encrypt(Request.Form["userPwd"].ToString());
                    cookieType = "No";

                    if ((!string.IsNullOrEmpty(logName)) && (!string.IsNullOrEmpty(pwd)))
                    {
                        B_SiteInfo siteInfo = new B_SiteInfo();
                        M_Site siteModel = siteInfo.GetSiteModel();
                        M_User modelLogin = bllUser.GetUser(logName);
                        if (modelLogin != null && siteModel != null)
                        {

                                //用户登录
                                bool flag = bllUser.Login(logName, pwd);
                                if (flag && (!string.IsNullOrEmpty(cookieType)))
                                {
                                    HttpCookie cookie = new HttpCookie("User");
                                    cookie["uId"] = modelLogin.UserID.ToString();
                                    cookie["logN"] = modelLogin.LogName;
                                    cookie["pd"] = modelLogin.UserPwd;
                                    switch (cookieType)
                                    {
                                        case "onehour":
                                            cookie.Expires = DateTime.Now.AddHours(1);
                                            break;
                                        case "oneday":
                                            cookie.Expires = DateTime.Now.AddDays(1);
                                            break;
                                        case "oneweek":
                                            cookie.Expires = DateTime.Now.AddDays(7);
                                            break;
                                        case "onemounth":
                                            cookie.Expires = DateTime.Now.AddMonths(1);
                                            break;
                                        case "oneyear":
                                            cookie.Expires = DateTime.Now.AddYears(1);
                                            break;
                                        case "No":
                                        default:
                                            break;
                                    }
                                    Response.Cookies.Add(cookie);

                                    string lastLoginIP = string.Empty;
                                    if (Request.UserHostAddress != null)
                                    {
                                        lastLoginIP = Request.UserHostAddress;
                                    }
                                    DateTime currLoginTime = DateTime.Now;
                                    DateTime oldLoginTime = modelLogin.LastLoginTime;
                                    bllUser.LoginSuccess(modelLogin.UserID, lastLoginIP, currLoginTime);
                                    if (oldLoginTime.Date != currLoginTime.Date)
                                    {
                                        B_Money moneyBll = new B_Money();
                                        moneyBll.Integral(siteModel.LoginScore, modelLogin.UserID);
                                    }

                                    msgBox = "<script>alert('登录成功');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                                }
                                else
                                {
                                    msgBox = "<script>alert('登录失败');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                                }
                        }
                        else
                        {
                            msgBox = "<script>alert('登录失败');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                        }
                    }
                }
                    ltMsg.Text = msgBox;
            }
            else
            {
                if (Request.Form["hidNoName"].ToString() == "False")
                {
                    ltMsg.Text = "<script>alert('本系统设置了不允许匿名评论,请先登录');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                }
                else
                {
                    //根据栏目的设置,对论评论审核进行初始化
                    if (Request.Form["hidColCommentSet"].ToString() == "True")
                        reviewIsCheck = false;
                    else
                        reviewIsCheck = true;

                    string validateCode = string.Empty;
                    string flag = Request.Form["hidValidate"];
                    if (flag == "True")
                    {
                        if (Session["ValidateCode"] == null)
                        {
                            Response.Write("<script language='javascript'>alert('你在登陆页面停留的时间过长,验证码已经失效');window.history.back();</script>");
                            Response.End();
                        }
                        //验证码错误
                        validateCode = Session["ValidateCode"].ToString().ToLower();
                        if (validateCode.ToLower() != Request.Form["txtValidate"].ToString().Trim().ToLower())
                        {
                            Response.Write("<script language='javascript'>alert('验证码错误');window.history.back();</script>");
                            Response.End();
                        }
                    }

                    if (bllUser.IsLogin())
                    {
                        M_User loginUserModel = bllUser.GetCookie();
                        userModel = bllUser.GetUser(loginUserModel.LogName);
                    }

                    model.ModelType = int.Parse(Request.Form["hidModeType"].ToString());
                    model.InfoId = Request.Form["hidNewsId"].ToString();

                    if (Request.Form["hidUserGroupViewIsCheck"] == "True" && bllUser.IsLogin())
                        reviewIsCheck = true;
                    model.IsCheck = reviewIsCheck;

                    model.ReviewTitle = "";                                    //评论标题

                    model.IsArgue = false;
                    model.IsSquare = 3;

                    model.BrarNum = 0;
                    model.FightNum = 0;

                    model.IsElite = false;
                    model.ReviewContent = SiteBll.GetFiltering(Request.Form["txtContent"].ToString());           //评论内容
                    model.ReviewTime = DateTime.Now;                                                       //评论时间
                    if (bllUser.IsLogin())                                             //是否是登录用户
                        model.UserNum = userModel.UserID.ToString();
                    else
                        model.UserNum = "0";
                    model.ReviewIP = Request.UserHostAddress;     //评论用户的IP

                    if (bll.Add(model))
                    {
                        if (!reviewIsCheck)
                            ltMsg.Text = "<script>alert('评论成功,将在审核后显示出来');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                        else
                            ltMsg.Text = "<script>window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                    }
                }
            }
        }
        else
        {
            if (Request.Form["hidNoName"].ToString() == "False")
            {
                ltMsg.Text = "<script>alert('本系统设置了不允许匿名评论,请先登录');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
            }
            else
            {
                //根据栏目的设置,对论评论审核进行初始化
                if (Request.Form["hidColCommentSet"].ToString() == "True")
                    reviewIsCheck = false;
                else
                    reviewIsCheck = true;

                string validateCode = string.Empty;
                string flag = Request.Form["hidValidate"];
                if (flag == "True")
                {
                    if (Session["ValidateCode"] == null)
                    {
                        Response.Write("<script language='javascript'>alert('你在登陆页面停留的时间过长,验证码已经失效');window.history.back();</script>");
                        Response.End();
                    }
                    //验证码错误
                    validateCode = Session["ValidateCode"].ToString().ToLower();
                    if (validateCode.ToLower() != Request.Form["txtValidate"].ToString().Trim().ToLower())
                    {
                        Response.Write("<script language='javascript'>alert('验证码错误');window.history.back();</script>");
                        Response.End();
                    }
                }

                if (bllUser.IsLogin())
                {
                    M_User loginUserModel = bllUser.GetCookie();
                    userModel = bllUser.GetUser(loginUserModel.LogName);
                }

                model.ModelType = int.Parse(Request.Form["hidModeType"].ToString());
                model.InfoId = Request.Form["hidNewsId"].ToString();
                if (Request.Form["hidUserGroupViewIsCheck"] == "True" && bllUser.IsLogin())
                    reviewIsCheck = true;
                model.IsCheck = reviewIsCheck;

                model.ReviewTitle = "";                                    //评论标题

                model.IsArgue = false;
                model.IsSquare = 3;

                model.BrarNum = 0;
                model.FightNum = 0;

                model.IsElite = false;
                model.ReviewContent = SiteBll.GetFiltering(Request.Form["txtContent"].ToString());           //评论内容
                model.ReviewTime = DateTime.Now;                                                       //评论时间
                if (bllUser.IsLogin())                                             //是否是登录用户
                    model.UserNum = userModel.UserID.ToString();
                else
                    model.UserNum = "0";
                model.ReviewIP = Request.UserHostAddress;     //评论用户的IP

                if (bll.Add(model))
                {
                    if (!reviewIsCheck)
                        ltMsg.Text = "<script>alert('评论成功,将在审核后显示出来');window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                    else
                        ltMsg.Text = "<script>window.location.href('" + Request.UrlReferrer.ToString() + "');</script>";
                }
            }
        }
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["subjectflagl"] != null)
        {
            string subjectId = Request.Form["subjectflagl"].ToString();
            if (Request.Cookies[subjectId] != null)
            {
                Response.Write("<script>alert('你已经投过票了');window.history.back();</script>");
            }
            else
            {
                int ItemNum1 = 0;
                int ItemNum2 = 0;
                int ItemNum3 = 0;
                int ItemNum4 = 0;
                int ItemNum5 = 0;
                int ItemNum6 = 0;
                string[] voteIdArr = Request.Form["hidvoteIdAll"].ToString().Substring(0, Request.Form["hidvoteIdAll"].ToString().Length - 1).Split(',');
                foreach (string voteId in voteIdArr)
                {
                    B_Vote bllVote = new B_Vote();
                    B_User userBll = new B_User();
                    M_Vote mUpdateVote = new M_Vote();
                    M_Vote mVote = bllVote.GetVoteIdbyInfo(int.Parse(voteId.ToString()));

                    DataTable dt = bllVote.GetSubject((int)mVote.SubjectId);
                    if (dt != null && dt.Rows.Count != 0)
                    {
                        if ((DateTime)dt.Rows[0]["EndDate"] < DateTime.Now.Date)
                        {
                            Response.Write("<script>alert('此投票主题已过期');window.history.back();</script>");
                            return;
                        }
                        if (dt.Rows[0]["RequireLogin"].ToString() == "True" && !userBll.IsLogin())
                        {
                            Response.Write("<script>alert('请登录后再投票');window.history.back();</script>");
                            return;
                        }
                    }
                    HttpCookie ipCookie = new HttpCookie(subjectId);
                    ipCookie.Value = Request.UserHostAddress;
                    ipCookie.Expires = DateTime.Now.AddHours(2);
                    Response.Cookies.Add(ipCookie);

                    ItemNum1 = mVote.ItemNum1;
                    ItemNum2 = mVote.ItemNum2;
                    ItemNum3 = mVote.ItemNum3;
                    ItemNum4 = mVote.ItemNum4;
                    ItemNum5 = mVote.ItemNum5;
                    ItemNum6 = mVote.ItemNum6;
                    string[] voteItem = null;
                    if (Request.Form[voteId + "vote"] != null)
                    {
                        voteItem = Request.Form[voteId + "vote"].ToString().Split(',');
                        foreach (string ItemValue in voteItem)
                        {
                            if (ItemValue == "ItemNum1")
                                ItemNum1 = ItemNum1 + 1;
                            if (ItemValue == "ItemNum2")
                                ItemNum2 = ItemNum2 + 1;
                            if (ItemValue == "ItemNum3")
                                ItemNum3 = ItemNum3 + 1;
                            if (ItemValue == "ItemNum4")
                                ItemNum4 = ItemNum4 + 1;
                            if (ItemValue == "ItemNum5")
                                ItemNum5 = ItemNum5 + 1;
                            if (ItemValue == "ItemNum6")
                                ItemNum6 = ItemNum6 + 1;

                            mUpdateVote.ItemNum1 = ItemNum1;
                            mUpdateVote.ItemNum2 = ItemNum2;
                            mUpdateVote.ItemNum3 = ItemNum3;
                            mUpdateVote.ItemNum4 = ItemNum4;
                            mUpdateVote.ItemNum5 = ItemNum5;
                            mUpdateVote.ItemNum6 = ItemNum6;
                            mUpdateVote.VoteId = int.Parse(voteId.ToString());
                            mUpdateVote.VoteTitle = mVote.VoteTitle;
                            mUpdateVote.IsMore = mVote.IsMore;
                            mUpdateVote.ItemTitle1 = mVote.ItemTitle1;
                            mUpdateVote.ItemTitle2 = mVote.ItemTitle2;
                            mUpdateVote.ItemTitle3 = mVote.ItemTitle3;
                            mUpdateVote.ItemTitle4 = mVote.ItemTitle4;
                            mUpdateVote.ItemTitle5 = mVote.ItemTitle5;
                            mUpdateVote.ItemTitle6 = mVote.ItemTitle6;
                            bllVote.UpdateVote(mUpdateVote);
                        }
                    }
                }
                Response.Write("<script>alert('投票成功');window.history.back();</script>");
            }
        }
    }