string sql2 = "select adddate,LimitYear from users where code='" + Number + "'";
 DataSet ds2 = bc.getDataSet(sql2);
DateTime addTime = Convert.ToDateTime(ds2.Tables[0].Rows[0][0]);
int liyear = Convert.ToInt32(ds2.Tables[0].Rows[0][1]);
if (DateTime.Now > addTime.AddYears(+liyear))
{
   bc.MessageBox("对不起,您的账户已过期,将不能登录,感谢你的使用!", "/index.aspx");
 }明明断点DateTime.Now的值(2013-9-10 15:02:02) 大于 断点addTime.AddYears(+liyear)的值(2013-8-09 11:02:02)
可是这句---- bc.MessageBox("对不起,您的账户已过期,将不能登录,感谢你的使用!", "/index.aspx");--一直未见执行!请各位大师指教!万分感谢!

解决方案 »

  1.   

    在bc.MessageBox("对不起,您的账户已过期,将不能登录,感谢你的使用!", "/index.aspx");这里设置断点,单步调试进入方法体,看究竟哪里有问题。
      

  2.   

    我是楼主。直接跳过了{
       bc.MessageBox("对不起,您的账户已过期,将不能登录,感谢你的使用!", "/index.aspx");
     }
    而且就算把大于号改成小于号,也会跳过去。请帮我看看。
      

  3.   

    if (DateTime.Now > addTime.AddYears(+liyear))你这个貌似写的有问题吧,多了个加号?是不是这样if (DateTime.Now > addTime.AddYears(liyear))
      

  4.   

    addTime.AddYears(+liyear)的值(2013-8-09 11:02:02)   确定是这个值 先弹出来看看
    messagebox.show()?
      

  5.   

    很奇怪,我把
     bc.MessageBox("对不起,您的账户已过期,将不能登录,感谢你的使用!", "/index.aspx");放在第一行(所有代码的最上一行),不设任何条件,居然也不执行!
      

  6.   

    DateTime.Now > addTime.AddYears(+liyear)  建议你把这两个都弹出来看看 不要相信自己的感觉
      

  7.   

    问题是我把
     bc.MessageBox("对不起,您的账户已过期,将不能登录,感谢你的使用!", "/index.aspx");放在第一行(所有代码的最上一行),不设任何条件,居然也不执行!
      

  8.   


    你这个加号没必要吧  如果你这个liyear值是负的那你前面的加号可能会导致错误
      

  9.   

    我清理了一下,把所有页面代码拷贝过来,请注意bc.MessageBox("我要测试!", "login.aspx");---这一句就是不弹出来。public partial class web_login : System.Web.UI.Page
    {
        BaseClass bc = new BaseClass();
        usersManager bll = new usersManager();
        users model = new users();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (Session["userid"] != null)
                //{
                //    Response.Redirect("usercenter.aspx");
                //}
            }
        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {        string Number = bc.NoHTML(this.txtNumber.Text.ToString().Trim());
            string password = bc.NoHTML(this.txtPassword.Text.ToString().Trim());        if (this.txtCode.Text.ToString() == Request.Cookies["CheckCode"].Value.ToString())
            {
                if (bll.CheckLogin(Number, password))
                {
                    if (bc.userLimit(Number))
                    {
                        //将用户ID保存到session
                        string sql = "select userid,LimitYear,LimitDate,loginnum from users where code='" + Number + "'";
                        DataSet ds = bc.getDataSet(sql);
                        Session["userid"] = ds.Tables[0].Rows[0][0].ToString();
                       string yhm = this.txtNumber.Text.ToString();
                        Session.Add("yonghuming",yhm);
                        
                        Session.Timeout = 600;
                        bc.MessageBox("我要测试!", "login.aspx");
                        //如果用户是第一次登录则产生用户的到期时间
                        if (ds.Tables[0].Rows[0][1].ToString() != "0" && ds.Tables[0].Rows[0][3].ToString() == "0")
                        {
                            string sqln = "update users set loginDate='" + DateTime.Now.ToString() + "', LimitDate='" + DateTime.Now.AddYears(+Convert.ToInt32(ds.Tables[0].Rows[0][1])) + "' where userid=" + Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                            bc.executesql(sqln);
                        }                    //将登录次数+1
                        string sqlc = "update users set loginnum=loginnum+1 where userid=" + Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                        bc.executesql(sqlc);
                        Response.Redirect("usercenter.aspx");
                    }
                    else
                    {
                        bc.MessageBox("对不起,您的账户已过期,将不能登录,感谢你的使用!", "/index.aspx");
                    }            }
                else
                {
                    bc.MessageBox("用户名、密码出错,请确认正确后重试!", "login.aspx");
                }
            }
            else
            {
                bc.MessageBox("验证码输入错误!", "login.aspx");
            }    }
    }
      

  10.   

    帮我写一下response的语句好吗?
      

  11.   

    用response可行,但我想知道为什么bc.MessageBox就不行呢?谁能解释一下吗?
      

  12.   

    而且Response.Write("我要测试")也不行。
     Response.Redirect("index.aspx");这个可以。
    天哪,怎么回事?
      

  13.   

    你要知道 bc.MessageBox 这个 封装的函数怎么写的!把 这个 BaseClass bc = new BaseClass();
    贴的给我们看下啊!
      

  14.   

    这是 BaseClass的定义,其中包括MessageBox方法,请帮助分析一下
    public class BaseClass
    {   
    .......
     public void MessageBox(string Message, string page)
        {
            HttpContext.Current.Response.Write("<script>alert('" + Message + "');location.href='" + page + "'</script>");
        }
    }
      

  15.   

    http://blog.csdn.net/thebesttome/article/details/6848310 
      

  16.   

     public void MessageBox(string Message, string page)
    {
    const string js = "<Script language='JavaScript'>alert('{0}');window.location.replace('{1}')</script>";
                HttpContext.Current.Response.Write(string.Format(js, Message, page));
    }
      

  17.   

    修改为下面这样:public void MessageBox(string Message, string page)
    {
    const string js = "<Script language='JavaScript'>alert('{0}');window.location.replace('{1}')</script>";
                HttpContext.Current.Response.Write(string.Format(js, Message, page));
    }