Exemple #1
0
        public FileManagerPageViewMode()
        {
            //EA = ea;
            FileInfo    = new FileInfo();
            ProjectDal  = new ProjectDal();
            FileInfoDal = new FileInfoDal();
            // 初始化树
            InitTreeView();

            FileUpLoadCommand = new DelegateCommand(FileUpLoad);

            SelectNodeCommand = new DelegateCommand(SelectNode);

            DelFileCommand = new DelegateCommand <object>(DelFile);
        }
        /// <summary>
        /// 初始化登记业务项目
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public Project InitialRegistrationProject(Project project)
        {
            if (project == null)
            {
                return(null);
            }

            if ("2".Equals(project.Type))
            {
                ApplicantDal applicantDal = new ApplicantDal();
                TransferDal  transferDal  = new TransferDal();
                FileInfoDal  fileInfoDal  = new FileInfoDal();
                project.Applicants = applicantDal.GetListBy(a => a.ProjectID == project.ID);
                project.Transfer   = transferDal.GetModel(t => t.ProjectID == project.ID);
                project.FileInfos  = fileInfoDal.GetListBy(f => f.ProjectID == project.ID);
            }
            return(project);
        }
Exemple #3
0
        public static void DelFile(BusinessData.FileInfo fileInfo)
        {
            try
            {
                // 删除文件
                string   path = ReadConfigInfo();
                FileInfo file = new FileInfo(path + "\\" + fileInfo.Path + "\\" + fileInfo.ID + fileInfo.Extension);
                if (file.Exists)
                {
                    file.Delete();
                }

                // 删除数据
                FileInfoDal fileInfoDal = new FileInfoDal();
                fileInfoDal.Del(fileInfo);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #4
0
        public static void DelDir(BusinessData.Project project)
        {
            try
            {
                // 删除目录
                string        basePath = ReadConfigInfo();
                string        path     = basePath + "\\" + project.ID + "\\";
                DirectoryInfo di       = new DirectoryInfo(path);
                if (di.Exists)
                {
                    Directory.Delete(path, true);
                }

                // 删除数据
                FileInfoDal fileInfoDal = new FileInfoDal();
                fileInfoDal.DelBy(t => t.ProjectID == project.ID);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #5
0
        /// <summary>
        /// 附件上传
        /// </summary>
        private void FileUpLoad()
        {
            //TreeNode = selectedTreeNode as TreeNode;
            if (TreeNode == null || TreeNode.ID.Length != 6)
            {
                MessageBox.Show("请选择叶节点", "提示");
                return;
            }

            // 项目路径
            string projectPath = FileHelper.ReadConfigInfo();

            if (string.IsNullOrWhiteSpace(projectPath))
            {
                MessageBox.Show("请设置项目路径", "提示");
                return;
            }

            // 选择附件
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Title           = "选择文件",
                Filter          = "(*.jpg,*.png,*.jpeg,*.bmp)|*.jpg;*.png;*.jpeg;*.bmp",
                FileName        = "选择文件",
                FilterIndex     = 1,
                ValidateNames   = false,
                CheckFileExists = false,
                CheckPathExists = true,
                Multiselect     = true
            };
            var result = openFileDialog.ShowDialog();

            if (result == true)
            {
                String[] SelectedFilePaths = openFileDialog.FileNames;
                //bool isShow = false;
                foreach (String baseAddress in SelectedFilePaths)
                {
                    // 判断图片大小,不能超过2m(1024*2)kb
                    System.IO.FileInfo selectedFileInfo = new System.IO.FileInfo(baseAddress);
                    //if (selectedFileInfo.Length > 1024 * 1024 * 2)
                    //{
                    //    isShow = true;
                    //    continue;
                    //}
                    String   filename   = System.IO.Path.GetFileNameWithoutExtension(baseAddress); // 文件原名称
                    String   extension  = System.IO.Path.GetExtension(baseAddress);                // 文件扩展名
                    String   path       = Project.ID + "\\" + GetTreeFullPath(TreeNode);           // 相对路径
                    FileInfo uploadFile = new FileInfo
                    {
                        ID         = Guid.NewGuid(),
                        ProjectID  = Project.ID,
                        Name       = filename,
                        Extension  = extension,
                        Path       = path,
                        Type       = TreeNode.Name,
                        UpdateTime = DateTime.Now
                    };
                    StringBuilder savePath = new StringBuilder(); // 文件保存路径
                    savePath.Append(projectPath).Append("\\").Append(path);
                    //address.Append(Project.ID).Append("\\").Append(TreeNode.Name);
                    if (!System.IO.Directory.Exists(savePath.ToString()))
                    {
                        System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(savePath.ToString());
                        directoryInfo.Create();
                    }
                    savePath.Append(uploadFile.ID).Append(uploadFile.Extension);
                    System.IO.FileStream fsRead  = new System.IO.FileStream(baseAddress, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    System.IO.FileStream fsWrite = new System.IO.FileStream(savePath.ToString(), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                    byte[] arr = new byte[200];
                    //记录到底读取了多少字节的数据
                    int count = 0;
                    while (fsRead.Position < fsRead.Length)
                    {
                        //每一次读取,返回真正读取到的字节数,用count记录(最后一次读取后可能count可能会小于200)
                        count = fsRead.Read(arr, 0, arr.Length);
                        //将数组中的数据写入到指定的文件
                        fsWrite.Write(arr, 0, count);
                    }

                    fsWrite.Close();
                    fsRead.Close();


                    FileInfoDal fileInfoDal = new FileInfoDal();
                    fileInfoDal.Add(uploadFile);
                    FileInfoList.Add(uploadFile);
                }
                //if (isShow)
                //{
                //    MessageBox.Show("上传的每张图片大小不能超过2M", "提示");
                //}
            }
        }