protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (txtGradeMajor.Value.Length > 0 && txtQQ.Value.Length > 0 && txtName.Value.Length > 0 && txtTel.Value.Length > 0 && Request.Form["txtIntroduction"].Length > 0 && txtDepart.Value.Length > 0)
        {
            string     name         = txtName.Value;
            string     tel          = txtTel.Value;
            string     gradeMajor   = txtGradeMajor.Value;
            string     introduction = Request.Form["txtIntroduction"];
            int        depart       = Convert.ToInt32(txtDepart.Value);
            IPManager  manager      = new IPManager();//查看IP是否用得频繁
            string     IPAddress    = manager.GetClientIPv4Address();
            XmlManager xmanager     = new XmlManager();
            int        ans          = xmanager.Editor(IPAddress);
            if (ans > 0)                     //能否写入IP
            {
                if (ans == 1)                //该IP十秒内无操作
                {
                    xmanager.Add(IPAddress); //如果没有这个IP,就加入记录
                    using (var db = new ITShowEntities())
                    {
                        Application person = new Application();
                        person.Name        = name;
                        person.GradeMajor  = gradeMajor;
                        person.Telephone   = tel;
                        person.Introdution = introduction;
                        person.Time        = Convert.ToDateTime(DateTime.Now.ToString());
                        person.QQ          = txtQQ.Value;
                        switch (depart)
                        {
                        case 1: person.Department = "前端开发"; break;

                        case 2: person.Department = "程序开发"; break;

                        case 3: person.Department = "UI设计"; break;

                        case 4: person.Department = "APP开发"; break;
                        }
                        db.Application.Add(person);

                        if (db.SaveChanges() == 1)
                        {
                            Response.Write("<script>alert('报名成功,欢迎加入爱特交流群,群号:245775349');location='ApplicationFormMobile.aspx'</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('报名失败请重试');location='ApplicationFormMobile.aspx'</script>");
                        }
                    }
                }
                else
                {
                    Response.Write("<script>alert('操作过于频繁请10秒后再操作');location='ApplicationFormMobile.aspx'</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('操作失败请重试');location='ApplicationFormMobile.aspx'</script>");
            }
        }
    }
Beispiel #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        IPManager  manager   = new IPManager();//查看IP是否用得频繁
        string     IPAddress = manager.GetClientIPv4Address();
        XmlManager xmanager  = new XmlManager();
        int        ans       = xmanager.Editor(IPAddress);

        if (ans > 0)
        {
            if (ans == 1)
            {
                xmanager.Add(IPAddress);                             //如果没有这个IP,就加入记录

                BadWordsFilter badwordfilter = new BadWordsFilter(); //在此处对comment进行脏字处理
                //初始化关键字
                badwordfilter.Init();
                //检查是否有存在关键字
                bool a = badwordfilter.HasBadWord(textarea1.Value.Trim());

                if (a == false)
                {
                    string comment = textarea1.Value;

                    if (txtCode.Text == Session["CheckCode1"].ToString())
                    {
                        string time     = DateTime.Now.ToString();
                        string photoUrl = "images/p1.png";
                        //获取的对应图片信息
                        if (photoIndex.Text == "0")
                        {
                            photoUrl = "images/p1.png";
                        }
                        if (photoIndex.Text == "1")
                        {
                            photoUrl = "images/p2.png";
                        }
                        if (photoIndex.Text == "2")
                        {
                            photoUrl = "images/p3.png";
                        }
                        if (photoIndex.Text == "3")
                        {
                            photoUrl = "images/p4.png";
                        }
                        if (photoIndex.Text == "4")
                        {
                            photoUrl = "images/p5.png";
                        }
                        if (photoIndex.Text == "5")
                        {
                            photoUrl = "images/p6.png";
                        }
                        if (photoIndex.Text == "6")
                        {
                            photoUrl = "images/p7.png";
                        }
                        if (photoIndex.Text == "7")
                        {
                            photoUrl = "images/p8.png";
                        }
                        if (photoIndex.Text == "8")
                        {
                            photoUrl = "images/p9.png";
                        }
                        using (var db = new ITShowEntities())
                        {
                            Message message = new Message();

                            message.MessageContent = comment;

                            message.MessageTime = Convert.ToDateTime(time);

                            message.MessagePhoto = photoUrl;

                            db.Message.Add(message);

                            db.SaveChanges();

                            Response.Write("<script>alert('留言成功!');location='Comments.aspx'</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('验证码错误!');location='Comments.aspx'</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('留言中有不合法的内容')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('操作过于频繁,请10秒后再操作')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('操作失败请重试')</script>");
        }
    }