Exemplo n.º 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            DALnew    dal  = new DALnew();
            newEntity news = new newEntity();

            news.Author = Session["adminID"].ToString();
            //news.Author = "admin";
            news.Content     = content.Value;
            news.ReleaseTime = DateTime.Parse(txtReleaseTime.Text);
            news.Title       = txtTitle.Text;
            if (FileUpload1.HasFile)
            {
                int    startPosition = FileUpload1.FileName.LastIndexOf(".");                   //获取后缀名的起始位置
                string extName       = FileUpload1.FileName.Substring(startPosition).ToLower(); //获取后缀名
                string path          = Server.MapPath("./File/");
                string fileName      = DateTime.Now.ToString("yyyyMMddHHmmss") + extName;

                string saveFile = path + fileName;      //实现上传的
                string showFile = "./File/" + fileName; //后期页面上显示的

                FileUpload1.SaveAs(saveFile);
                news.RelateFile = showFile;
            }
            dal.Addnews(news);
            this.Page.RegisterClientScriptBlock("", "<script>新闻发布成功!</script>");
            Response.Redirect("NewsManage.aspx");
        }
Exemplo n.º 2
0
        protected void submit_Click(object sender, EventArgs e)
        {
            DALnew    dal  = new DALnew();
            newEntity news = new newEntity();

            news.Title       = desc1.Value;
            news.Content     = content.Value;
            news.Author      = Session["name"].ToString();
            news.ReleaseTime = System.DateTime.Now;
            if (FileUpload1.HasFile)
            {
                int    startPosition = FileUpload1.FileName.LastIndexOf(".");
                string extName       = FileUpload1.FileName.Substring(startPosition).ToLower();
                string path          = Server.MapPath("./File/");
                string fileName      = DateTime.Now.ToString("yyyyMMddHHmmss") + extName;

                string saveFile = path + fileName;
                string showFile = "./File/" + fileName;

                FileUpload1.SaveAs(saveFile);
                news.RelateFile = showFile;
            }
            dal.Addnews(news);
            ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('新闻发布成功!');</script>");
        }
Exemplo n.º 3
0
        protected void submit_Click(object sender, EventArgs e)
        {
            DALnew    dal  = new DALnew();
            newEntity news = (newEntity)ViewState["news"];

            news.Title   = desc1.Value;
            news.Content = desc.Value;
            dal.Modnews(news);
            ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('编辑成功!');</script>");
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取数据并展示
        /// </summary>
        /// <param name="id"></param>
        public void GetData(int id)
        {
            DALnew    dal  = new DALnew();
            newEntity news = dal.Getnews(id);

            ViewState["news"]   = news;//在当前页缓存数据。
            txtTitle.Text       = news.Title;
            txtReleaseTime.Text = news.ReleaseTime.ToString();
            content.Value       = news.Content;
        }
Exemplo n.º 5
0
        public void GetData(int id)
        {
            //将取回的数据在页面进行展示,可以修改的数据使用TextBox来展示,并提供修改。
            //通过按钮触发,实现将数据编辑保存的功能

            DALnew    dal  = new DALnew();
            newEntity news = dal.Getnews(id);

            ViewState["news"] = news;
            desc.Value        = news.Content;
        }
Exemplo n.º 6
0
        protected void submit_Click(object sender, EventArgs e)
        {
            DALnew    dal  = new DALnew();
            newEntity news = new newEntity();

            news.Title       = desc1.Value;
            news.Content     = desc.Value;
            news.Author      = Session["uName"].ToString();
            news.ReleaseTime = System.DateTime.Now;
            dal.Addnews(news);
            ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('新闻编辑成功');</script>");
        }
Exemplo n.º 7
0
        protected void grdnews_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    rowindex = int.Parse(e.CommandArgument.ToString());     //获取操作行的行号
            string Id       = grdnews.DataKeys[rowindex].Value.ToString(); //获取操作行数据的主键Id
            DALnew dal      = new DALnew();

            switch (e.CommandName) //获取操作对象的命令
            {
            case "see":            //调转到编辑页面
                Response.Redirect("NewsShow.aspx?id=" + Id);
                break;
            }
        }
Exemplo n.º 8
0
        public void Bind(int id)
        {
            DALnew    dal  = new DALnew();
            newEntity news = dal.Getnews(id);

            lt1.Text = news.Title;
            lb1.Text = news.ReleaseTime.ToString();
            lt2.Text = news.Content;
            if (!string.IsNullOrEmpty(news.RelateFile))
            {
                lt3.Text = "附件:<a href='" + news.RelateFile + "'>单击下载附件</a>";
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 加载数据信息
        /// </summary>
        public void LoadData()
        {
            string conditon = string.Empty;

            conditon = "(Title is not null and Title<>' ')";
            if (!string.IsNullOrEmpty(newsTitle.Value))
            {
                conditon += " and Title like'%" + newsTitle.Value + "%'";
            }
            DALnew            dal  = new DALnew();
            IList <newEntity> news = dal.GetnewsbyCondition(conditon);//按照条件来查询数据

            Repeater1.DataSource = news;
            Repeater1.DataBind();
        }
Exemplo n.º 10
0
        protected void grdnews_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    rowindex = int.Parse(e.CommandArgument.ToString());     //获取操作行的行号
            string Id       = grdnews.DataKeys[rowindex].Value.ToString(); //获取操作行数据的主键Id
            DALnew dal      = new DALnew();

            switch (e.CommandName) //获取操作对象的命令
            {
            case "edit":           //调转到编辑页面
                Response.Redirect("NewsEdit.aspx?id=" + Id);
                break;

            case "del":    //删除用户
                dal.Delnews(int.Parse(Id));
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('数据删除成功!');location.href='NewsManage.aspx';</script>");
                break;
            }
        }