Beispiel #1
0
 public void Application1(object sender, EventArgs e)
 {
     try
     {
         using (var db = new ITStudioEntities())
         {
             applications ap = new applications();
             ap.name = takeMaxChar(HttpUtility.HtmlEncode(TxtName.Text.Trim()));
             ap.major = takeMaxChar(HttpUtility.HtmlEncode(TxtMajor.Text.Trim()));
             ap.time = DateTime.Now;
             ap.gender = Convert.ToBoolean(DdlGender.SelectedValue);
             ap.tel = takeMaxChar(HttpUtility.HtmlEncode(TxtTel.Text.Trim())); //####ToDo:验证格式
             ap.job = takeMaxChar(HttpUtility.HtmlEncode(DdlJob.SelectedItem.Text));
             ap.introduction = HttpUtility.HtmlEncode(TxtIntroduction.Value.Trim());
             db.applications.Add(ap);
             db.SaveChanges();
         }
         Response.Write("<script>alert('恭喜您,报名成功');window.window.location.href='index.aspx';</script> ");
     }
     catch
     {
         Response.Write("<script>alert('报名失败,请重试');window.window.location.href='index.aspx';</script> ");
     }
     finally
     {
     }
 }
Beispiel #2
0
 protected void BtnSubmit_Click(object sender, EventArgs e)
 {
     //避免js失效,后端验证
     string title = txtTitle.Text;
     if (txtTitle.Text == null || txtTitle.Text.Trim() == "")
     {
         LblStatus.Text = "请填写标题";
         LblStatus.Visible = true;
         return;
     }
     string content = ueditor.Value;
     if (content == null || content.Trim() == "")
     {
         LblStatus.Text = "请填写内容";
         LblStatus.Visible = true;
         return;
     }
     using (var db = new ITStudioEntities())
     {
         var not = new notices();
         not.time = DateTime.Now;
         not.title = txtTitle.Text;
         not.content = ueditor.Value;
         db.notices.Add(not);
         db.SaveChanges();
     }
     ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功');</script>");
     txtTitle.Text = "";
     ueditor.Value = "";
 }
Beispiel #3
0
 protected void BtnSubmit_Click(object sender, EventArgs e)
 {
     int id = Convert.ToInt16(Request.QueryString["id"]);
     using (var db = new ITStudioEntities())
     {
         notices not = db.notices.SingleOrDefault(a => a.id == id);
         not.time = DateTime.Now;
         not.title = txtTitle.Text;
         not.content = ueditor.Value;
         db.SaveChanges();
     }
     ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功');</script>");
 }
Beispiel #4
0
    /// <summary>
    /// 增加管理员
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnAddAdmin_Click(object sender, EventArgs e)
    {
        if (TxtNewAdminName.Text == "" || TxtNewAdminPassword.Text == "" || TxtNewAdminPasswordAgain.Text == "")
        {
            Response.Write("<script>alert('管理员名和密码不能为空!')</script>");
            return;
        }
        string newName = TxtNewAdminName.Text;
        if (newName.Length > 16)
        {
            Response.Write("<script>alert('新管理员登录名长度应小于16位')</script>");
            return;
        }
        if (TxtNewAdminPassword.Text != TxtNewAdminPasswordAgain.Text)
        {
            Response.Write("<script>alert('两次密码不一致!')</script>");
            return;
        }
        else if (TxtNewAdminPassword.Text.Length < 6 || TxtNewAdminPassword.Text.Length > 16)
        {
            Response.Write("<script>alert('密码位数应在6到16位!')</script>");
            return;
        }

        using (var db = new ITStudioEntities()) //检验是否已存在此登录名
        {
            admins admin = db.admins.SingleOrDefault(a => a.name == newName);
            if (admin != null)
            {
                Response.Write("<script>alert('此管理员已存在!')</script>");
                return;
            }
        }

        string sha = getHash.getSHA1(TxtNewAdminPassword.Text);
        using (var db = new ITStudioEntities())
        {
            var a = new admins();
            a.name = TxtNewAdminName.Text;
            a.password = sha;
            db.admins.Add(a);
            db.SaveChanges();
        }

        adminsBind();
        TxtNewAdminName.Text = "";
        Response.Write("<script>alert('管理员添加成功!')</script>");
    }
Beispiel #5
0
    protected void RptArticles_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete") //删除文章
        {
            string IDStr = e.CommandArgument.ToString().Trim();

            int id = Convert.ToInt32(IDStr);
            using (var db = new ITStudioEntities())
            {
                works work = db.works.SingleOrDefault(a => a.id == id);
                //删除封面图片
                string coverPicName = work.picture;//相对路径
                if (coverPicName != null)
                {
                    coverPicName = Server.MapPath(coverPicName); //必须经过这一步操作才能变成有效路径
                    if (System.IO.File.Exists(coverPicName))//先判断文件是否存在,再执行操作
                    {
                        System.IO.File.Delete(coverPicName); //删除文件
                    }
                }
                db.works.Remove(work);
                var dataSource =(from items in db.workmap
                                 orderby items.id descending
                                 where items.workId==id
                                 select items).ToList();
                // 对 LINQ 查询而返回的结果集进行处理
                // 要么使用 Single() 取出单条记录
                // 要么就迭代集合进行处理
                foreach (workmap o in dataSource)
                {
                    db.workmap.Remove(o);
                }
                db.SaveChanges();
            }
            ArticlesBind(getPageNum(), getPageSize());
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('文章删除成功');</script>");
        }
    }
Beispiel #6
0
    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        //避免js失效,后端验证
        string name = txtName.Text;
        if (txtName.Text == null || txtName.Text.Trim() == "")
        {
            LblStatus.Text = "请填写姓名";
            LblStatus.Visible = true;
            return;
        }
        string direction = txtDirection.Text;
        if (direction == null || direction == "")
        {
            LblStatus.Text = "请填写方向";
            LblStatus.Visible = true;
            return;
        }

        string content = txtIntroduction.InnerText;
        content = content.Replace("\n", "<br />"); // 尝试替换\n为<br />

        if (content == null || content.Trim() == "")
        {
            LblStatus.Text = "请填写简介";
            LblStatus.Visible = true;
            return;
        }

        string photo = uploadMemPho();
        if (photo == null || photo.Trim() == "")
        {
            LblStatus.Text = "请选择照片";
            LblStatus.Visible = true;
            return;
        }
        string ico = uploadMemIco();
        if (photo == null || photo.Trim() == "")
        {
            LblStatus.Text = "请选择头像";
            LblStatus.Visible = true;
            return;
        }

        //存储成员到members表
        using (var db = new ITStudioEntities())
        {
            var mem = new members();
            mem.grade = Convert.ToInt32(ddlGrade.SelectedValue);
            mem.photo = photo;
            mem.ico = ico;
            mem.name = name;
            mem.introduction = content;
            mem.direction = direction;
            mem.job = ddlDeparement.SelectedValue;
            db.members.Add(mem);
            db.SaveChanges();
        }
        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功');</script>");
        txtName.Text = "";
        txtIntroduction.InnerText = "";
        ddlDeparement.SelectedValue = "程序开发";
    }
Beispiel #7
0
    protected void RptArticles_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete") //删除文章
        {
            string IDStr = e.CommandArgument.ToString().Trim();

            int id = Convert.ToInt32(IDStr);
            using (var db = new ITStudioEntities())
            {
                notices not = db.notices.SingleOrDefault(a => a.id == id);
                db.notices.Remove(not);
                db.SaveChanges();
            }
            ArticlesBind(getPageNum(), getPageSize());
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('文章删除成功');</script>");
        }
    }
Beispiel #8
0
    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnChange_Click(object sender, EventArgs e)
    {
        int ID = 0;
        if (TxtIdToChange.Text != null && TxtIdToChange.Text.Trim() != "" && Filter.IsNumeric(TxtIdToChange.Text))
        {
            ID = Convert.ToInt32(TxtIdToChange.Text.Trim());
        }
        else
        {
            return;
        }

        string oldPassword = TxtOldPassword.Text;
        string newPassword = TxtNewPassword.Text;
        if (newPassword.Length < 6 || newPassword.Length > 16)
        {
            Response.Write("<script>alert('密码位数应在6到16位')</script>");
            return;
        }
        string oldPasswordHash = getHash.getSHA1(oldPassword);
        string newPasswordHash = getHash.getSHA1(newPassword);
        using (var db = new ITStudioEntities())
        {
            admins c2 = db.admins.SingleOrDefault(c => c.id == ID);
            if (c2 == null)
            {
                return;
            }
            if (newPassword != "" && oldPassword != "")
            {
                if (c2.password.ToString() == oldPasswordHash)
                {
                    c2.password = newPasswordHash;
                    db.SaveChanges();
                    adminsBind();
                    Response.Write("<script>alert('密码修改成功!')</script>");
                    TblChangePassword.Visible = false;
                    BtnChange.Visible = false;
                }
                else
                    Response.Write("<script>alert('原密码错误!')</script>");
            }
            else
                Response.Write("<script>alert('请完整输入!')</script>");
        }
    }
Beispiel #9
0
 /// <summary>
 /// Admin 列表操作项目
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 protected void RptAdmins_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     //删除操作
     if (e.CommandName == "delete_admin")
     {
         int ID = Convert.ToInt32(e.CommandArgument.ToString().Trim());
         using (var db = new ITStudioEntities())
         {
             admins c1 = db.admins.SingleOrDefault(a => a.id == ID);
             db.admins.Remove(c1);
             db.SaveChanges();
             adminsBind();
             Response.Write("<script>alert('管理员删除成功!')</script>");
         }
     }
     else //修改操作
     {
         TblChangePassword.Visible = true;
         BtnChange.Visible = true;
         int ID = Convert.ToInt32(e.CommandArgument.ToString().Trim());
         TxtIdToChange.Text = ID.ToString();
     }
 }
Beispiel #10
0
    protected void RptArticles_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete") //删除人员
        {
            string IDStr = e.CommandArgument.ToString().Trim();

            int id = Convert.ToInt32(IDStr);
            using (var db = new ITStudioEntities())
            {
                members mem = db.members.SingleOrDefault(a => a.id == id);
                //删除封面图片
                string photoPath = mem.others;//相对路径
                if (photoPath != null)
                {
                    photoPath = Server.MapPath(photoPath); //必须经过这一步操作才能变成有效路径
                    if (System.IO.File.Exists(photoPath))//先判断文件是否存在,再执行操作
                    {
                        System.IO.File.Delete(photoPath); //删除文件
                    }
                }
                db.members.Remove(mem);
                db.SaveChanges();
            }
            ArticlesBind(getPageNum(), getPageSize());
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('人员删除成功');</script>");
        }
    }
Beispiel #11
0
    /// <summary>
    /// 存储作品到works表;存储作品和多个成员关系
    /// </summary>
    /// <param name="typeId">类型在type表中的id</param>
    /// <param name="title">作品标题</param>
    /// <param name="time">作品完成时间</param>
    /// <param name="introduction">作品简介</param>
    /// <param name="workPicName">作品图片文件名(不含路径)</param>
    /// <param name="link">作品链接</param>
    void submitWork(int typeId,string title,string time, string introduction, string workPicName,string link)
    {
        using (var db = new ITStudioEntities())
        {
            var work = new works(); // 要添加的作品
            work.typeId = typeId;
            work.picture = workPicName;
            work.title = title;
            work.introduction = introduction;
            work.time = time;
            work.link = link;
            db.works.Add(work);
            db.SaveChanges();
            int workId = work.id;
            // works work2 = db.works.SingleOrDefault(a => a.picture == work.picture); //意义不明,可能是为了获取刚添加的作品。

            // 存储多个作者到 workmap 表
            for (int i = 0; i < ChklstAuthors.Items.Count; i++) // 遍历CheckBoxList
            {
                if (ChklstAuthors.Items[i].Selected == true)
                {
                    int memberId = 1;
                    if (Filter.IsNumeric(ChklstAuthors.Items[i].Value))
                    {
                        memberId = Convert.ToInt32(ChklstAuthors.Items[i].Value);
                    }

                    var map = new workmap();
                    map.memberId = memberId;
                    map.workId = workId;
                    db.workmap.Add(map);
                    db.SaveChanges();
                }
            }
        }
    }
Beispiel #12
0
    /// <summary>
    /// 提交修改键
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        //避免js失效,后端验证
        string title = txtTitle.Text;
        if (txtTitle.Text == null || txtTitle.Text.Trim() == "")
        {
            LblStatus.Text = "请填写标题";
            LblStatus.Visible = true;
            return;
        }
        string content = txtIntroduction.InnerText;
        if (content == null || content.Trim() == "")
        {
            LblStatus.Text = "请填写内容";
            LblStatus.Visible = true;
            return;
        }

        string workPicName = uploadWorkPic();
        //if (workPicName == null || workPicName.Trim() == "") // 可以不修改作品图片
        //{
        //    LblStatus.Text = "请选择作品图片";
        //    LblStatus.Visible = true;
        //    return;
        //}
        string time = txtTime.Text;
        if (time == null || time.Trim() == "")
        {
            LblStatus.Text = "请填写时间";
            LblStatus.Visible = true;
            return;
        }

        int id = Convert.ToInt32(Request.QueryString["id"]);

        //删除旧封面图片
        if (workPicName != null) //此时:已上传新封面图片,文件名未写入数据库
        {
            string oldCoverPic = "";
            using (var db = new ITStudioEntities())
            {
                works w = db.works.SingleOrDefault(a => a.id == id);
                if (w == null)
                {
                    return;
                }
                oldCoverPic = w.picture;
                string oldCoverPicPath = "/upload/workPicture/" + oldCoverPic; //相对路径
                oldCoverPicPath = Server.MapPath(oldCoverPicPath); //必须经过这一步操作才能变成有效路径
                if (System.IO.File.Exists(oldCoverPicPath))//先判断文件是否存在,再执行操作
                {
                    System.IO.File.Delete(oldCoverPicPath); //删除文件
                }
            }
        }

        // 写入数据库
        using (var db = new ITStudioEntities())
        {
            //修改works表
            works work = db.works.SingleOrDefault(a => a.id == id);
            work.typeId = Convert.ToInt32(ddlType.SelectedValue);
            if (workPicName != null)
            {
                work.picture = workPicName; // 修改了图片的情况
                ImgCurrentWorkPic.ImageUrl = "/upload/workPicture/" + workPicName;
            }
            work.title = title;
            work.introduction = content;
            work.time = txtTime.Text;
            work.link = ITStudioHelper.addProtocol(txtLink.Text);
            //修改workmap表
            for (int i = 0; i < ChklstAuthors.Items.Count; i++) // 遍历CheckBoxList
            {
                int memberId = Convert.ToInt32(ChklstAuthors.Items[i].Value);
                workmap map = db.workmap.SingleOrDefault(a => a.workId == id && a.memberId == memberId);
                if (map != null)
                {
                    db.workmap.Remove(map);
                }
            }
            for (int i = 0; i < ChklstAuthors.Items.Count; i++) // 遍历CheckBoxList
            {
                if (ChklstAuthors.Items[i].Selected == true)
                {
                    int memberId = 1;
                    if (Filter.IsNumeric(ChklstAuthors.Items[i].Value))
                    {
                        memberId = Convert.ToInt32(ChklstAuthors.Items[i].Value);
                    }

                    var map = new workmap();
                    map.memberId = memberId;
                    map.workId = id;
                    db.workmap.Add(map);
                }
            }
            db.SaveChanges();
        }
        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功');</script>");
    }