/// <summary>
        /// 加载账套文件
        /// </summary>
        private void LoadFiles()
        {
            try
            {
                listFile.Clear();

                DirectoryInfo directoryInfo = new DirectoryInfo(Application.StartupPath + @"\SowerTestClient\Paper\Account");
                FileInfo[]    fileInfo      = directoryInfo.GetFiles("*.casf");//只取文本文档
                foreach (FileInfo item in fileInfo)
                {
                    if (item.Extension.ToLower() == ".casf")
                    {
                        M_ExerciseFile file = new M_ExerciseFile();
                        file.FileName    = Path.GetFileName(item.Name);
                        file.FileVersion = item.LastWriteTime.ToString();
                        file.Description = item.Name;
                        file.FilePath    = item.FullName;

                        listFile.Add(file);
                    }
                }

                dgvFiles.AutoGenerateColumns = false;
                dgvFiles.DataSource          = null;
                dgvFiles.DataSource          = listFile;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(frmExercise), ex);
                CommonUtil.WriteLog(ex);
            }
        }
示例#2
0
 /// <summary>
 /// 加载视频文件
 /// </summary>
 private void LoadVideoFiles()
 {
     try
     {
         listVideoFile.Clear();
         DirectoryInfo   directoryInfo = new DirectoryInfo(Application.StartupPath + @"\SowerTestClient\Video\");
         DirectoryInfo[] dirList       = directoryInfo.GetDirectories();
         foreach (DirectoryInfo item in dirList)
         {
             string[] nameList = item.Name.Split('_');
             if (nameList.Length <= 1)
             {
                 continue;
             }
             if (nameList[0] != PublicClass.StudentCode)
             {
                 continue;
             }
             M_ExerciseFile file = new M_ExerciseFile();
             file.FileName    = nameList[1];
             file.FileVersion = item.LastWriteTime.ToString();
             file.Description = item.Name;
             file.FilePath    = item.FullName;
             listVideoFile.Add(file);
         }
         dgvVideoFiles.AutoGenerateColumns = false;
         dgvVideoFiles.DataSource          = listVideoFile;
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(typeof(frmExercise), ex);
         CommonUtil.WriteLog(ex);
     }
 }
        /// <summary>
        /// 删除账套文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDeleteFile_Click(object sender, EventArgs e)
        {
            string casfFile = "";

            if (dgvFiles.SelectedRows.Count == 0)
            {
                return;
            }

            DialogResult dialogResult = PublicClass.ShowMessageOKCancel("您确定要删除吗?");

            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    M_ExerciseFile files = dgvFiles.SelectedRows[0].DataBoundItem as M_ExerciseFile;
                    casfFile = files.FilePath;
                    //删除.sdb文件
                    if (File.Exists(casfFile))
                    {
                        File.Delete(casfFile);
                    }
                }
                catch (IOException)
                {
                    string errorMessage = string.Format("无法删除该文件,文件正在被另一个人或程序使用。\n关闭任何可能使用这个文件的程序,重新试一次。");
                    PublicClass.ShowErrorMessageOk(errorMessage);
                }
                catch (Exception ex)
                {
                    PublicClass.ShowMessageOk(ex.Message);
                }
                finally
                {
                    //刷新列表
                    LoadFiles();
                }
            }
        }
示例#4
0
        /// <summary>
        /// 删除视频资源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelVideoFile_Click(object sender, EventArgs e)
        {
            string videoFile = "";

            if (dgvVideoFiles.SelectedRows.Count == 0)
            {
                return;
            }
            DialogResult dialogResult = PublicClass.ShowMessageOKCancel("您确定要删除吗?");

            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    M_ExerciseFile files = dgvVideoFiles.SelectedRows[0].DataBoundItem as M_ExerciseFile;
                    videoFile = files.FilePath;
                    listFile.Remove(files);
                    //删除视频资源包
                    DirFileHelper.DeleteDirectory(videoFile);
                }
                catch (IOException)
                {
                    string errorMessage = string.Format("无法删除该文件,文件正在被另一个人或程序使用。\n关闭任何可能使用这个文件的程序,重新试一次。");
                    PublicClass.ShowErrorMessageOk(errorMessage);
                }
                catch (Exception ex)
                {
                    PublicClass.ShowMessageOk(ex.Message);
                }
                finally
                {
                    //刷新列表
                    LoadVideoFiles();
                }
            }
        }