コード例 #1
0
    protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            //获得文件正确的地址
            string fullPath = this.lblFilePath.Text.ToString().Trim().Replace("/", Path.AltDirectorySeparatorChar.ToString()) + this.txtFileName.Text;

            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }
            string filePath = fullPath.Replace(IniFile.IniReadValue(((User)Session["Login"]).UserId), "");
            MyOffice.Models.FileInfo file = new MyOffice.Models.FileInfo();
            file.FileName            = this.txtFileName.Text;
            file.IfDelete            = 0;
            file.FileType.FileTypeId = 1;
            file.FileOwner           = ((User)Session["Login"]);
            file.Remark     = this.txtRemark.Text;
            file.CreateDate = DateTime.Now;
            file.ParentId   = Convert.ToInt32(Request.QueryString["parentId"]);
            file.FilePath   = filePath;

            FileInfoManager.AddFile(file);

            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功!');location='FileMain.aspx?fileId=" + Request.QueryString["parentId"] + "';</script>");
        }
        catch (Exception ex)
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!');location='FileMain.aspx?fileId=" + Request.QueryString["parentId"] + "';</script>");
        }
    }
コード例 #2
0
    protected void btnExit_Click1(object sender, ImageClickEventArgs e)
    {
        try
        {
            int fileId = Convert.ToInt32(Request.QueryString["fileId"]);
            MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId);
            if (Directory.Exists(this.lblFilePath.Text))
            {
                Directory.Delete(this.lblFilePath.Text, true);
            }
            IList <int> childFileLists = new List <int>();
            FileInfoManager.GetAllChildByFileId(childFileLists, Convert.ToInt32(Request.QueryString["fileId"]));
            foreach (int delfileId in childFileLists)
            {
                FileInfoManager.DelFileById(delfileId);
            }
            FileInfoManager.DelFileById(Convert.ToInt32(Request.QueryString["fileId"]));

            Response.Redirect("FileMain.aspx?fileId=" + file.ParentId + "&fileTypeId=1");
        }
        catch (Exception ex)
        {
            throw;
        }
    }
コード例 #3
0
ファイル: FileMain.aspx.cs プロジェクト: Gaushee/MyOffice
    protected void gvFile_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int a = this.gvFile.SelectedIndex;

        if (e.CommandName == "details")
        {
            int fileId = Convert.ToInt32(e.CommandArgument.ToString());
            MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId);
            //判断是链接到文件详细还是文件夹详细
            if (file.FileType.FileTypeId == 1)
            {
                Response.Redirect("FolderDetails.aspx?fileId=" + file.FileId);
            }
            else
            {
                Response.Redirect("FileDetails.aspx?fileId=" + file.FileId);
            }
        }
        else if (e.CommandName == "del")
        {
            int fileId = Convert.ToInt32(e.CommandArgument.ToString());
            FileInfoManager.update_IfDelete_ByFileId(fileId);
            this.gvFile.DataBind();
        }
    }
コード例 #4
0
    /// <summary>
    /// 显示文件详细信息时绑定页面的空间
    /// </summary>
    /// <param name="fileIdStr"></param>
    private void BindPage(string fileIdStr)
    {
        int fileId = Convert.ToInt32(fileIdStr);

        MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId);
        this.txtFileName.Text   = file.FileName;
        this.txtRemark.Text     = file.Remark;
        this.lblCreateTime.Text = file.CreateDate.ToString();
        this.lblFileOwer.Text   = file.FileOwner.UserName;
        this.lblFilePath.Text   = IniFile.IniReadValue(((User)Session["Login"]).UserId) + file.FilePath;
        //显示修改按钮隐藏添加按钮
        this.imgbtnSave.Visible   = false;
        this.imgbtnSave.Enabled   = false;
        this.imgbtnUpdate.Visible = true;
        this.imgbtnUpdate.Enabled = true;
        //不启用验证文件上传控件的控件
        RequiredFieldValidator4.Enabled = false;

        foreach (ListItem rdo in this.rboFileIcoList.Items)
        {
            if (file.FileType.FileTypeId.ToString() == rdo.Value)
            {
                rdo.Selected = true;
            }
        }
    }
コード例 #5
0
ファイル: FileMain.aspx.cs プロジェクト: Gaushee/MyOffice
    protected void imgbtnMove_ServerClick(object sender, ImageClickEventArgs e)
    {
        HtmlInputImage imgbtnMove = sender as HtmlInputImage;

        ViewState["Move_FileId"] =
            this.gvFile.DataKeys[Convert.ToInt32(imgbtnMove.Value) - 1].Value.ToString();

        MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(Convert.ToInt32(this.gvFile.DataKeys[Convert.ToInt32(imgbtnMove.Value) - 1].Value));
        this.txtMoveFileName.Text = file.FileName;
    }
コード例 #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindRL();
            try
            {
                string fileIdStr = Request.QueryString["fileId"];
                //当前页面功能为显示文件信息
                if (fileIdStr != "" && fileIdStr != null)
                {
                    this.FileType.Style.Add("display", "none");
                    MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(Convert.ToInt32(fileIdStr));
                    this.imgbtnUp.PostBackUrl = "FileMain.aspx?fileId=" + file.ParentId + "&fileTypeId=1";
                    BindPage(fileIdStr);
                }
                //当前页面功能为新增文件
                else
                {
                    this.imgbtnUp.PostBackUrl = "FileMain.aspx?fileId=" + Request.QueryString["parentId"] + "&fileTypeId=1";
                    this.btnExit.PostBackUrl  = "FileMain.aspx?fileId=" + Request.QueryString["parentId"] + "&fileTypeId=1";
                    //获得当前文件的上级目录(文件夹)ID
                    int parentId = Convert.ToInt32(Request.QueryString["parentId"]);
                    //上级目录不是根目录  可以从数据库中查找
                    if (parentId != 0)
                    {
                        MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(parentId);
                        this.lblFilePath.Text = IniFile.IniReadValue(((User)Session["Login"]).UserId) + file.FilePath + "\\";
                    }
                    //上级目录是根目录   数据库中没有根目录的数据记录
                    else
                    {
                        this.lblFilePath.Text = IniFile.IniReadValue(((User)Session["Login"]).UserId);
                    }

                    this.lblFileOwer.Text   = ((User)Session["Login"]).UserName;
                    this.lblCreateTime.Text = DateTime.Now.ToString();
                    //显示添加按钮隐藏修改按钮
                    this.imgbtnSave.Visible   = true;
                    this.imgbtnSave.Enabled   = true;
                    this.imgbtnUpdate.Visible = false;
                    this.imgbtnUpdate.Enabled = false;
                    //启用验证文件上传控件的控件
                    RequiredFieldValidator4.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("~/index.aspx");
            }
        }
    }
コード例 #7
0
ファイル: FileMain.aspx.cs プロジェクト: Gaushee/MyOffice
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string fileIdStr = Convert.ToString(Request.QueryString["fileId"]);

            Page_FileId = fileIdStr;

            int fileId = int.Parse(fileIdStr);
            if (fileId == 0)
            {
                this.txtFolderPath.Text = "文件管理" + "\\";
                this.imgbtnUp.Enabled   = false;
            }
            else
            {
                this.imgbtnUp.Enabled = true;
                //找到页面所对应的上级文件夹对象  得到本页面的上一级文件夹ID  并为界面中“上一级”按钮赋URL
                MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId);
                this.imgbtnUp.PostBackUrl = "FileMain.aspx?fileId=" + file.ParentId + "&fileTypeId=1";


                if (file == null)
                {
                    this.txtFolderPath.Text = "文件管理" + "\\";
                }
                else
                {
                    this.txtFolderPath.Text = file.FilePath + "\\";
                }
            }
            //没有修改当前文件路径的情况下 禁用转到按钮
            this.imgbtnGoto.Enabled = false;
        }
        catch (Exception ex)
        {
            if (!IsPostBack)
            {
                Response.Redirect("FileMain.aspx?fileId=0&fileTypeId=1");
            }
        }

        //给更改当前所在界面所需的树绑定事件
        (this.FolderTree1.FindControl("tvFolder") as TreeView).SelectedNodeChanged += new EventHandler(ChangeFileTree);

        if (!IsPostBack)
        {
            BindTV();
        }
    }
コード例 #8
0
    private void BindPage()
    {
        string fileIdStr = Request.QueryString["fileId"];

        MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(Convert.ToInt32(fileIdStr));
        this.txtFileName.Text   = file.FileName;
        this.txtRemark.Text     = file.Remark;
        this.lblCreateTime.Text = file.CreateDate.ToString();
        this.lblFileOwer.Text   = file.FileOwner.UserName;
        this.lblFilePath.Text   = IniFile.IniReadValue(((User)Session["Login"]).UserId) + file.FilePath;
        //显示修改按钮隐藏添加按钮
        this.imgbtnSave.Visible   = false;
        this.imgbtnSave.Enabled   = false;
        this.imgbtnUpdate.Visible = true;
        this.imgbtnUpdate.Enabled = true;
    }
コード例 #9
0
    protected void imgbtnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(Convert.ToInt32(Request.QueryString["fileId"]));
        try
        {
            file.FileName            = this.txtFileName.Text;
            file.FileType.FileTypeId = 1;
            file.Remark = this.txtRemark.Text;

            FileInfoManager.UpdateFile(file);
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');location='FolderDetails.aspx?fileId=" + file.FileId + "';</script>");
        }
        catch (Exception ex)
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');location='FolderDetails.aspx?fileId=" + file.FileId + "';</script>");
        }
    }
コード例 #10
0
ファイル: FileMain.aspx.cs プロジェクト: Gaushee/MyOffice
    protected void tvMove_SelectedNodeChanged(object sender, EventArgs e)
    {
        int fileId = Convert.ToInt32(this.tvMove.SelectedValue);

        MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId);

        if (file == null)
        {
            this.txtMove.Text = "文件管理" + "\\";
        }
        else
        {
            this.txtMove.Text = file.FilePath + "\\";
        }
        this.btnMove.Enabled       = true;
        ViewState["moveTo_FileId"] = fileId;
    }
コード例 #11
0
 protected void btnExit_Click(object sender, ImageClickEventArgs e)
 {
     try
     {
         int fileId = Convert.ToInt32(Request.QueryString["fileId"]);
         MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId);
         if (File.Exists(this.lblFilePath.Text))
         {
             File.Delete(this.lblFilePath.Text);
         }
         FileInfoManager.DelFileById(fileId);
         Response.Redirect("FileMain.aspx?fileId=" + file.ParentId + "&fileTypeId=1");
     }
     catch (Exception ex)
     {
         throw;
     }
 }
コード例 #12
0
ファイル: FileMain.aspx.cs プロジェクト: Gaushee/MyOffice
    void ChangeFileTree(object sender, EventArgs e)
    {
        TreeView tv     = (this.FolderTree1.FindControl("tvFolder") as TreeView);
        int      fileId = Convert.ToInt32(tv.SelectedValue);

        //获得选中文件夹对象
        MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId);
        if (file == null)
        {
            this.txtFolderPath.Text = "文件管理" + "\\";
        }
        else
        {
            this.txtFolderPath.Text = file.FilePath + "\\";
        }
        //启用转到按钮
        this.imgbtnGoto.Enabled     = true;
        this.imgbtnGoto.PostBackUrl = "FileMain.aspx?fileId=" + file.FileId;
    }
コード例 #13
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void imgbtnUpdate_Click(object sender, ImageClickEventArgs e)
 {
     MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(Convert.ToInt32(Request.QueryString["fileId"]));
     try
     {
         file.FileName = this.txtFileName.Text;
         file.FileType = FileTypeManager.GetFileTypeById(Convert.ToInt32(this.rboFileIcoList.SelectedValue));
         file.Remark   = this.txtRemark.Text;
         if (fuFile.FileName != null && !"".Equals(fuFile.FileName))
         {
             File.Delete(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + file.FilePath);
             //获得此文件的上级文件夹   为了得到上级文件夹的路径,来保存新的文件
             MyOffice.Models.FileInfo parentFile = FileInfoManager.GetFileByFileId(file.ParentId);
             //新文件的路径  (判断上级是否为空)
             if (parentFile == null)
             {
                 file.FilePath = this.fuFile.FileName;
             }
             else
             {
                 file.FilePath = parentFile.FilePath + "\\" + this.fuFile.FileName;
             }
             fuFile.SaveAs(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + file.FilePath);
             FileInfoManager.UpdateFileAndFilePath(file);
         }
         else
         {
             FileInfoManager.UpdateFile(file);
         }
         this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');location='FileDetails.aspx?fileId=" + file.FileId + "';</script>");
     }
     catch (Exception ex)
     {
         this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');location='FileDetails.aspx?fileId=" + file.FileId + "';</script>");
     }
 }
コード例 #14
0
ファイル: FileMain.aspx.cs プロジェクト: Gaushee/MyOffice
    //移动
    protected void btnMove_Click(object sender, EventArgs e)
    {
        try
        {
            //被移动的文件夹
            MyOffice.Models.FileInfo move_File = FileInfoManager.GetFileByFileId(Convert.ToInt32(ViewState["Move_FileId"]));
            if (!ViewState["Move_FileId"].ToString().Equals(ViewState["moveTo_FileId"].ToString()))
            {
                IList <int> childFileLists = new List <int>();
                FileInfoManager.GetAllChildByFileId(childFileLists, move_File.FileId);
                if (!childFileLists.Contains(Convert.ToInt32(ViewState["moveTo_FileId"])))
                {
                    //移动到的文件夹
                    MyOffice.Models.FileInfo moveTo_File = FileInfoManager.GetFileByFileId(Convert.ToInt32(ViewState["moveTo_FileId"]));

                    //移动磁盘中的文件或文件夹
                    if (move_File.FileType.FileTypeId == 1)
                    {
                        MoveFolder(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + move_File.FilePath, IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + moveTo_File.FilePath);
                    }
                    else
                    {
                        MoveFile(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + move_File.FilePath, IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + moveTo_File.FilePath);
                    }

                    //判断是否是根目录
                    string fileName = move_File.FilePath.Substring(move_File.FilePath.LastIndexOf("\\") + 1);
                    if (moveTo_File == null)
                    {
                        move_File.ParentId = 0;
                        move_File.FilePath = fileName;
                    }
                    else
                    {
                        move_File.ParentId = moveTo_File.FileId;
                        move_File.FilePath = moveTo_File.FilePath + "\\" + fileName;
                    }

                    //移动文件 即修改文件的父ID 和FilePath
                    FileInfoManager.MoveFile(move_File);
                    ViewState["Move_FileId"]   = null;
                    ViewState["moveTo_FileId"] = null;
                    this.txtMove.Text          = "";
                    this.txtMoveFileName.Text  = "";
                    this.btnMove.Enabled       = false;
                    this.gvFile.DataBind();
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动成功!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>");
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动失败:目标文件是源文件夹的子文件夹!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>");
                }
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动失败:目标文件和源文件夹相同!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>");
            }
        }
        catch (Exception ex)
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动失败!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>");
        }
    }