Пример #1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (this.FormCheck())
            {
                try
                {
                    tb_File file = new tb_File();
                    file.fileName = txtFileName.Text;
                    file.fileURL  = txtUrl.Text;


                    file.fileFullName = txtUrl.Text.Trim().Substring(txtUrl.Text.LastIndexOf('.') + 1);;


                    file.createPer  = base.Session["LoginName"].ToString();
                    file.createTime = DateTime.Now;

                    file.id = Convert.ToInt32(base.Request["Id"]);
                    if (this.fileSer.Update(file))
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('修改成功!');</script>");
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('修改失败!');</script>");
                    }
                }
                catch (Exception ex)
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('" + ex.Message + "!');</script>");
                }
            }
        }
        public ActionResult SetFile(tb_File model, HttpPostedFileWrapper file)
        {
            if (file != null && file.ContentLength > 0)
            {
                string path = $"/Files/{Guid.NewGuid()}_{file.FileName}";
                file.SaveAs(Server.MapPath("~" + path));
                model.Path = path;
            }

            if (model.Id == 0)
            {
                entities.tb_File.Add(model);
            }
            else
            {
                entities.Entry(model).State = System.Data.Entity.EntityState.Modified;
                if (model.Path == null)
                {
                    entities.Entry(model).Property(x => x.Path).IsModified = false;
                }
            }

            entities.SaveChanges();

            return(RedirectToAction("List"));
        }
Пример #3
0
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            if (this.txtName.Text.Trim() != "")
            {
                ExploreFile    ef    = new ExploreFile();
                List <tb_File> files = ef.MAIN();

                tb_File file = new tb_File();
                file.fileName = txtName.Text.Trim();

                files                  = files.FindAll(new Predicate <tb_File>(file.ifCon));
                ViewState["file"]      = files;
                this.gvList.DataSource = files;
                this.gvList.DataBind();



                //  List<tb_File> files = this.fileSer.GetListArray(string.Format(" and fileName like '%{0}%'", this.txtName.Text.Trim()));
                //this.gvList.DataSource = files;
                //this.gvList.DataBind();
            }
            else
            {
                ExploreFile    ef    = new ExploreFile();
                List <tb_File> files = ef.MAIN();

                //tb_File file = new tb_File();
                //file.fileName = txtName.Text.Trim();

                //files = files.FindAll(new Predicate<tb_File>(file.ifCon));
                ViewState["file"]      = files;
                this.gvList.DataSource = files;
                this.gvList.DataBind();
            }
        }
Пример #4
0
        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.gvList.PageIndex = e.NewPageIndex;

            ExploreFile    ef    = new ExploreFile();
            List <tb_File> files = ef.MAIN();

            tb_File file = new tb_File();

            file.fileName = txtName.Text.Trim();

            files                  = files.FindAll(new Predicate <tb_File>(file.ifCon));
            ViewState["file"]      = files;
            this.gvList.DataSource = files;
            this.gvList.DataBind();
        }
Пример #5
0
 protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "Down")
         {
             int     id   = Convert.ToInt32(e.CommandArgument);
             tb_File file = fileSer.GetModel(id);
             down1(file.fileName + "." + file.fileFullName, file.fileURL);
         }
     }
     catch (Exception)
     {
         base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('下载失败!');</script>");
     }
 }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                if (base.Request["Id"] != null)
                {
                    this.btnAdd.Visible = false;
                    tb_File file = fileSer.GetModel(Convert.ToInt32(base.Request["Id"]));

                    this.txtFileName.Text = file.fileName;
                    this.txtUrl.Text      = file.fileURL;
                }
                else
                {
                    this.btnUpdate.Visible = false;
                }
            }
        }
Пример #7
0
 protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "Down")
         {
             int            id    = Convert.ToInt32(e.CommandArgument);
             List <tb_File> files = ViewState["file"] as List <tb_File>;
             tb_File        fi    = new tb_File();
             fi.id = id;
             tb_File file = files.Find(new Predicate <tb_File>(fi.show));
             //tb_File file = fileSer.GetModel(id);
             // downLoad(file.fileName , file.fileURL);
             down1(file.fileName, file.fileURL);
         }
     }
     catch (Exception)
     {
         base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('下载失败!');</script>");
     }
 }
Пример #8
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.FormCheck())
            {
                try
                {
                    tb_File file = new tb_File();
                    file.fileName = txtFileName.Text;
                    file.fileURL  = txtUrl.Text;



                    file.fileFullName = txtUrl.Text.Trim().Substring(txtUrl.Text.LastIndexOf('.') + 1);;
                    file.createPer    = base.Session["LoginName"].ToString();
                    file.createTime   = DateTime.Now;

                    if (this.fileSer.Add(file) > 0)
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('添加成功!');</script>");

                        this.txtUrl.Text = "";

                        this.txtFileName.Text = "";
                        this.txtFileName.Focus();
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('添加失败!');</script>");
                    }
                }
                catch (Exception ex)
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('" + ex.Message + "!');</script>");
                }
            }
        }