Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.QueryString["id"] == null||Request.QueryString["id"].Length>8 || !Filter.IsNumeric(Request.QueryString["id"]))
     {
         Response.Redirect("error.aspx");
     }
     using(var db=new ITStudioEntities())
     {
         int id = Convert.ToInt32(Request.QueryString["id"]);
         if(db.notices.SingleOrDefault(a => a.id == id)==null)
         {
             Response.Redirect("error.aspx");
         }
     }
     btnSubmit.Enabled = true;
     if (!IsPostBack)
     {
         int id = Convert.ToInt16(Request.QueryString["id"]);
         using (var db = new ITStudioEntities())
         {
             notices not = db.notices.SingleOrDefault(a => a.id == id);
             txtTitle.Text = not.title;
             ueditor.Value = not.content;
         }
     }
 }
Exemple #2
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
     {
     }
 }
Exemple #3
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 = "";
 }
Exemple #4
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>");
 }
Exemple #5
0
 //protected void rptWorks_ItemCommand(object source, RepeaterCommandEventArgs e)
 //{
 //    if(e.CommandName=="imgWork")
 //    {
 //        using (var db = new ITStudioEntities())
 //        {
 //            int id =Convert.ToInt32(e.CommandArgument);
 //            works work = db.works.SingleOrDefault(a => a.id == id);
 //            string site = work.link;
 //            System.Diagnostics.Process.Start(site);
 //        }
 //    }
 //}
 //protected void AspNetPager_PageChanged(object sender, EventArgs e)
 //{
 //    using (var db = new ITStudioEntities())
 //    {
 //        PagedDataSource pd = new PagedDataSource();
 //        pd.DataSource = (from items in db.works
 //                         orderby items.id descending
 //                         select items).ToList();
 //        pd.AllowPaging = true;
 //        if (pd.DataSourceCount > AspNetPager.PageSize)
 //        {
 //            this.AspNetPager.AlwaysShow = true;
 //        }
 //        this.AspNetPager.RecordCount = pd.DataSourceCount;
 //        pd.PageSize = this.AspNetPager.PageSize;
 //        pd.CurrentPageIndex = this.AspNetPager.CurrentPageIndex - 1;
 //        rptWorks.DataSource = pd;
 //        rptWorks.DataBind();
 //    }
 //}
 /// <summary>
 /// 获得作品的总页数
 /// </summary>
 /// <param name="pageSize">每页项目数量</param>
 /// <param name="typeId">项目类型,默认值为0表示所有类型</param>
 /// <returns>总页数</returns>
 int getPageCount(int pageSize, int typeId = 0)
 {
     int pageCount = 1;
     using (var db = new ITStudioEntities())
     {
         var dataSource = from items in db.works
                          where (typeId != 0 ? (items.typeId == typeId) : (1 == 1)) //判断是否有类型限制
                             select new { items };
         int totalAmount = dataSource.Count();
         pageCount = (int)Math.Ceiling((double)totalAmount / (double)pageSize); //总页数,向上取整
     }
     return pageCount;
 }
Exemple #6
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>");
    }
Exemple #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using(var db = new ITStudioEntities())
     {
         var search = from it in db.members
                      where it.grade == 2010
                      orderby it.id
                      select it;
         RptMember1.DataSource = search.Take(3).ToList();
         RptMember1.DataBind();
         RptMember2.DataSource = search.Skip(3).Take(3).ToList();
         RptMember2.DataBind();
         RptMember0.DataSource = search.ToList();
         RptMember0.DataBind();
     }
 }
Exemple #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnSubmit.Enabled = false;
            btnSubmit.Text = "请填写完整";

            using (var db = new ITStudioEntities())
            {
                //作者
                ChklstAuthors.DataSource = db.members.ToList();
                ChklstAuthors.DataValueField = "id";
                ChklstAuthors.DataTextField = "name";
                ChklstAuthors.DataBind();
            }
        }
    }
Exemple #9
0
    int pageSize = 6; //页面项目数

    #endregion Fields

    #region Methods

    protected void Page_Load(object sender, EventArgs e)
    {
        int currentPage = getPageNum();
        int typeId = getWorkTypeId();
        worksBind(currentPage, pageSize, typeId);
        pageNumsBind();

        using (var db = new ITStudioEntities())
        {
            var dataSource = from u in db.works
                             select new
                             {
                                 u.time,
                                 u.id,
                                 u.title,
                                 u.introduction,
                                 u.picture,
                             };
            RptWorkOnMobile.DataSource = dataSource.ToList();
            RptWorkOnMobile.DataBind();
        }
    }
Exemple #10
0
    public static bool isCookieValidated(string name, string token)
    {
        /*
         * 说明:cookie 中的 token 是 SHA-1(name + SHA-1(password) + ip + ua)
         * 数据库中,password储存为 SHA-1(password)
        */

        // #### 此处可以考虑使用封装的函数etc
        using (var db = new ITStudioEntities())
        {
            admins admin = db.admins.SingleOrDefault(a => a.name == name);
            if (admin == null)
            {
                return false;
            }
            string passwordHash = admin.password;

            string ua = HttpContext.Current.Request.UserAgent;
            if (ua == null)
            {
                ua = String.Empty;
            }
            // 如果用户通过代理服务器访问,获取到的将是代理服务器的ip。此ip不可随意伪造。
            string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            if (ip == null) //我想一般不会有这种情况。
            {
                ip = String.Empty;
            }

            if (token != getHash.getSHA1(name + passwordHash + ip + ua))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int ID = Convert.ToInt32(Request.QueryString["id"]);
        using (var db = new ITStudioEntities())
        {
            var dataSource = from u in db.members
                             where (u.id == ID)
                             select new
                             {
                                 u.name,
                                 u.introduction,
                                 u.photo,
                                 u.grade,
                                 u.direction,
                             };
            RptMenber.DataSource = dataSource.ToList();
            RptMenber.DataBind();
            RptMember2.DataSource = dataSource.ToList();
            RptMember2.DataBind();

            var dataSource1 = from u in db.outWorks
                              where (u.memberId == ID)
                              orderby u.time descending
                              select new
                              {
                                  u.picture,
                                  u.introduction,
                                  u.title,
                                  u.time,
                              };
            RptWorks.DataSource = dataSource1.Take(3).ToList();
            RptWorks.DataBind();
            RptWorks2.DataSource = dataSource1.Take(2).ToList();
            RptWorks3.DataSource = dataSource1.Skip(2).Take(2).ToList();
        }
    }
Exemple #12
0
 /// <summary>
 /// 绑定作品,可指定作品类型(默认为0表示没有所有类型)
 /// </summary>
 /// <param name="CurrentPage">页码</param>
 /// <param name="pageSize">页面项目数</param>
 /// <param name="typeId">作品类型</param>
 void worksBind(int CurrentPage,int pageSize, int typeId=0)
 {
     using (var db = new ITStudioEntities())
     {
         var dataSource = from items in db.works
                          orderby items.time descending
                          where(typeId != 0? (items.typeId == typeId):(1==1)) //判断是否有类型限制
                          select new
                          {
                              items.id,
                              items.typeId,
                              items.title,
                              items.time,
                              items.picture,
                              items.link,
                              items.introduction
                          };
         dataSource = dataSource.Skip(pageSize * (CurrentPage - 1)).Take(pageSize); // 分页
         //if (dataSource.Count() == 0)
         //{
         //    Response.Redirect("error.html");
         //}
         rptWorks.DataSource = dataSource.ToList();
         rptWorks.DataBind();
     }
 }
Exemple #13
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>");
    }
Exemple #14
0
 //获得总页数
 int getPageCount(int pageSize)
 {
     int pageCount = 1;
     if (Session["pageCount"] == null)
     {
         using (var db = new ITStudioEntities())
         {
             var dataSource = from items in db.works
                              orderby items.id
                              select new { items };
             int totalAmount = dataSource.Count();
             pageCount = (int)Math.Ceiling((double)totalAmount / (double)pageSize); //总页数,向上取整
         }
         Session["pageCount"] = pageCount;
     }
     else
     {
         pageCount = Convert.ToInt32(Session["pageCount"]);
     }
     return pageCount;
 }
Exemple #15
0
 /// <summary>
 /// 绑定管理员列表
 /// </summary>
 void adminsBind()
 {
     using (var db = new ITStudioEntities())
     {
         var dataSource = from a in db.admins
                          orderby a.id
                          select new { a.id, a.name };
         RptAdmins.DataSource = dataSource.ToList();
         RptAdmins.DataBind();
     }
 }
Exemple #16
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();
     }
 }
Exemple #17
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>");
        }
    }
Exemple #18
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();
                }
            }
        }
    }
Exemple #19
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 = "程序开发";
    }
Exemple #20
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>");
        }
    }
Exemple #21
0
    /// <summary>
    /// 申请信息列表绑定
    /// </summary>
    /// <param name="CurrentPage">当前页码</param>
    /// <param name="PageSize">页面项目总数</param>
    void ApplicationBind(int CurrentPage, int PageSize)
    {
        using (var db = new ITStudioEntities())
        {
            var dataSource = from items in db.applications
                             orderby items.id descending
                             select new { items.id, items.name, items.gender, items.major, items.job, items.tel, items.time, items.introduction };
            int totalAmount = dataSource.Count();
            Session["pageCount"] = Math.Ceiling((double)totalAmount / (double)PageSize); //总页数,向上取整
            dataSource = dataSource.Skip(PageSize * (CurrentPage - 1)).Take(PageSize); //分页
            RptApplication.DataSource = dataSource.ToList();
            RptApplication.DataBind();

            LtlApplicationsCount.Text = totalAmount.ToString();
        }
    }
Exemple #22
0
    //从DataGrid导出
    private void ExportDataGrid(string Job,string FileType, string FileName)
    {
        System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();

        using (var db = new ITStudioEntities())
        {
            var dt = from it in db.applications
                     where it.job == Job
                     select it;
            dg.DataSource = dt.ToList();
        }
        dg.DataBind();

        //定义文档类型、字符编码
        Response.Clear();
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.Charset = "UTF-8";
        Response.ContentEncoding = Encoding.Default;
        Response.ContentType = FileType;
        dg.EnableViewState = false;
        //定义一个输入流
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        //目标数据绑定到输入流输出
        dg.RenderControl(hw);
        //GvContract 绑定datagrid,或其他支持obj.RenderControl()属性的控件
        //ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "info", tw.ToString(), false);
        Response.Write(tw.ToString());
        Response.End();
        //Response.Flush();
        //Response.Close();
    }
Exemple #23
0
    //文章绑定
    void ArticlesBind(int CurrentPage, int PageSize)
    {
        using (var db = new ITStudioEntities())
        {
            var dataSource = from items in db.works
                             orderby items.id descending
                             select new { items.id, items.title, items.time, items.link };
            int totalAmount = dataSource.Count();
            Session["pageCount"] = Math.Ceiling((double)totalAmount / (double)PageSize); //总页数,向上取整
            dataSource = dataSource.Skip(PageSize * (CurrentPage - 1)).Take(PageSize); //分页
            RptArticles.DataSource = dataSource.ToList();
            RptArticles.DataBind();

            LtlArticlesCount.Text = totalAmount.ToString();
        }
    }
Exemple #24
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>");
        }
    }
Exemple #25
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>");
        }
    }
Exemple #26
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == null || Request.QueryString["id"].Length > 8 || !Filter.IsNumeric(Request.QueryString["id"]))
        {
            Response.Redirect("error.aspx");
        }
        using (var db = new ITStudioEntities())
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            if (db.works.SingleOrDefault(a => a.id == id) == null)
            {
                Response.Redirect("error.aspx");
            }
        }
        btnSubmit.Enabled = true;
        if (!IsPostBack)
        {
            int id = Convert.ToInt16(Request.QueryString["id"]);
            using (var db = new ITStudioEntities())
            {
                works work = db.works.SingleOrDefault(a => a.id == id);
                txtTitle.Text = work.title;
                txtIntroduction.InnerText = work.introduction;
                txtLink.Text = work.link;
                txtTime.Text = work.time;
                ImgCurrentWorkPic.ImageUrl = "/upload/workPicture/" + work.picture;
                ddlType.SelectedValue = work.typeId.ToString();
                //作者
                ChklstAuthors.DataSource = db.members.ToList();
                ChklstAuthors.DataValueField = "id";
                ChklstAuthors.DataTextField = "name";
                ChklstAuthors.DataBind();
                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)
                    {
                        ChklstAuthors.Items[i].Selected = true;
                    }
                }
            }

        }
    }