Пример #1
0
        private void btnAddVideoFile_Click(object sender, EventArgs e)
        {
            if (dgvResult.SelectedRows.Count == 0) return;
            M_MyJob myJob = dgvResult.SelectedRows[0].DataBoundItem as M_MyJob;
            ofdOpenFile.Title = "视频资源";
            ofdOpenFile.FileName = "视频资源";
            ofdOpenFile.Filter = "视频资源|*.zip*";
            ofdOpenFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            DialogResult result = ofdOpenFile.ShowDialog();

            if (result == DialogResult.OK)
            {
                string filePath = ofdOpenFile.FileName;
                string fileName = Path.GetFileName(filePath);
                string fileExt = Path.GetExtension(filePath).ToLower();
                string copyPath = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}\",
                    Application.StartupPath, PublicClass.StudentCode, DirFileHelper.GetFileNameNoExtension(filePath));
                string videoFileName = string.IsNullOrEmpty(myJob.VideoFileName) == true ? "" : myJob.VideoFileName.ToLower();
                if (string.IsNullOrEmpty(videoFileName))
                {
                    Msg.ShowInformation(string.Format("作业“{0}”没有添加视频资源,请联系授课教师到作业中心->作业维护发布列表进行添加。", myJob.HWName));
                    return;
                }
                if (fileName.ToLower() != videoFileName)
                {
                    Msg.ShowInformation(string.Format("您添加的视频资源无效,请添加名字为【{0}】的视频资源。", videoFileName));
                    return;
                }
                try
                {
                    if (fileExt != ".zip")
                    {
                        PublicClass.ShowMessageOk("该文件不是有效的视频资源,请重新添加!");
                        return;
                    }
                    if (Directory.Exists(copyPath))
                    {
                        DialogResult dialogResult = PublicClass.ShowMessageOKCancel("该视频资源包已经存在,确定要覆盖吗?");
                        if (dialogResult == DialogResult.Cancel) return;
                    }
                    CommonUtil.ShowProcessing("正在处理中,请稍候...", this, (obj) =>
                    {
                        ZipFileTools.UnZipSZL(filePath, copyPath);
                        dgvResult.SelectedRows[0].Cells["VideoDownLoadState"].Value = "已下载";
                    }, null);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(typeof(frmHomeWork), ex);
                    CommonUtil.WriteLog(ex);
                }
            }
        }
Пример #2
0
        private void FtpDownload(M_MyJob myJob)
        {
            //文件路径
            string filePath = Path.GetDirectoryName(myJob.FilePath).Replace("\\", "//");
            //文件名
            string fileName = Path.GetFileName(myJob.FilePath);
            //复制文件到系统路径
            string copyPath = string.Format(@"{0}\SowerTestClient\Paper\Download\{1}_{2}", Application.StartupPath, PublicClass.StudentCode, fileName);
            //下载文件保存路径
            string savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName);

            FtpWeb ftpWeb = CommonUtil.GetFtpWeb();

            if (ftpWeb != null)
            {
                ftpWeb.Download(Globals.DownLoadDir, fileName, filePath, tsbBar, tsbMessage, "作业下载进度:");
            }

            //复制作业到系统目录
            File.Copy(savePath, copyPath, true);
            //删除下载文件
            File.Delete(savePath);
            //设置已下载状态
            dgvResult.SelectedRows[0].Cells["JobDownLoadState"].Value = "已下载";
            tsbMessage.Text = "作业下载进度:";
            tsbBar.Value    = 0;
            //下载账套文件
            if (ftpWeb != null && myJob.RequireEnvFile.ToLower() == "true" && myJob.IsUpload.ToLower() == "true" && cbIsDownAccount.Checked == true)
            {
                filePath = Path.GetDirectoryName(myJob.EnvFilePath).Replace("\\", "//");
                fileName = myJob.EnvFileName;
                copyPath = string.Format(@"{0}\SowerTestClient\Paper\Account\{1}", Application.StartupPath, fileName);
                savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName);
                ftpWeb.Download(Globals.DownLoadDir, fileName, filePath, tsbBar, tsbMessage, "帐套下载进度:");
                //复制作业到系统目录
                DirFileHelper.Copy(savePath, copyPath);
                //删除临时下载文件
                DirFileHelper.DeleteFile(savePath);
                tsbMessage.Text = "帐套下载进度:";
                tsbBar.Value    = 0;
                dgvResult.SelectedRows[0].Cells["AccountDownLoadState"].Value = "已下载";
            }
            //下载视频文件
            if (ftpWeb != null && myJob.IsUploadVideoFile == true && string.IsNullOrEmpty(myJob.VideoFilePath) == false && cbIsDownVideo.Checked == true)
            {
                filePath = Path.GetDirectoryName(myJob.VideoFilePath).Replace("\\", "//");
                fileName = myJob.VideoFileName;
                copyPath = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}\", Application.StartupPath, PublicClass.StudentCode, DirFileHelper.GetFileNameNoExtension(myJob.VideoFilePath));
                savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName);
                ftpWeb.Download(Globals.DownLoadDir, fileName, filePath, tsbBar, tsbMessage, "视频下载进度:");
                //复制作业到系统目录
                ZipFileTools.UnZipSZL(savePath, copyPath);
                //删除临时下载文件
                DirFileHelper.DeleteFile(savePath);
                tsbMessage.Text = "视频下载进度:";
                tsbBar.Value    = 0;
                dgvResult.SelectedRows[0].Cells["VideoDownLoadState"].Value = "已下载";
            }
        }
Пример #3
0
 /// <summary>
 /// 下载题库
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDown_Click(object sender, EventArgs e)
 {
     #region 局部变量
     string topicFileName      = string.Empty;
     string topicFilePath      = string.Empty;
     string topicEnvFilePath   = string.Empty;
     string topicVideoFilePath = string.Empty;
     string requireEnvFile     = string.Empty;
     string envFileName        = string.Empty;
     string envFilePath        = string.Empty;
     string videoFileName      = string.Empty;
     string videoFilePath      = string.Empty;
     string envFileExt         = string.Empty;
     string copyEnvPath        = string.Empty;
     string copyVideoPath      = string.Empty;
     string filePath           = string.Empty;
     string fileTPath          = string.Empty;
     string fileExt            = string.Empty;
     string fileName           = string.Empty;
     string copyPath           = string.Empty;
     string copyTPath          = string.Empty;
     string connection         = string.Empty;
     string connectionT        = string.Empty;
     string errorMessage       = string.Empty;
     FtpWeb ftpWeb             = null;
     #endregion
     try
     {
         btnDown.Enabled = false;
         if (dgvDownTopicDB.SelectedRows.Count == 0)
         {
             return;
         }
         M_TopicDB topicDB = dgvDownTopicDB.SelectedRows[0].DataBoundItem as M_TopicDB;
         #region 检测本地是否存在题库文件
         string path = string.Format(@"{0}\data\{1}_{2}.sdbt", Application.StartupPath, PublicClass.StudentCode, topicDB.TopicDBName);
         if (File.Exists(path))
         {
             M_SubjectProp subject = bSubjectProp.GetSubjectProp(string.Format("{0}_{1}.sdbt", PublicClass.StudentCode, topicDB.TopicDBName));
             if (subject.TopicDBVersion == topicDB.TopicDBVersion && subject.TopicDBCode == topicDB.TopicDBCode)
             {
                 PublicClass.ShowErrorMessageOk("您已经下载过这个题库文件,不能重复下载。");
                 return;
             }
         }
         #endregion
         #region 初始化变量
         topicFileName  = Path.GetFileName(topicDB.TopicDBPath);
         topicFilePath  = Path.GetDirectoryName(topicDB.TopicDBPath).Replace("\\", "//");
         requireEnvFile = string.IsNullOrEmpty(topicDB.RequireEnvFile) == true ? "false" : topicDB.RequireEnvFile.ToLower();
         filePath       = string.Format("{0}\\{1}", Globals.DownLoadDir, topicFileName);
         fileTPath      = string.Format("{0}\\{1}t", Globals.DownLoadDir, topicFileName);
         fileExt        = string.IsNullOrEmpty(topicDB.TopicDBPath) == true ? "" : Path.GetExtension(topicDB.TopicDBPath).ToLower();
         fileName       = string.Format("{0}{1}", topicDB.TopicDBName, fileExt);
         copyPath       = string.Format(@"{0}\data\{1}_{2}", Application.StartupPath, PublicClass.StudentCode, fileName.Replace(".srk", ".sdb"));
         copyTPath      = string.Format(@"{0}\data\{1}_{2}t", Application.StartupPath, PublicClass.StudentCode, fileName.Replace(".srk", ".sdb"));
         connection     = string.Format(@"data source={0};password={1};polling=false;failifmissing=true", filePath, PublicClass.PasswordTopicDB);
         connectionT    = string.Format(@"data source={0};polling=false;failifmissing=true", fileTPath);
         #endregion
         //下载题库文件
         ftpWeb = CommonUtil.GetFtpWeb();
         if (ftpWeb != null)
         {
             ftpWeb.Download(Globals.DownLoadDir, topicFileName, topicFilePath, proDown, lblDown, "题库下载进度:");
         }
         else
         {
             Msg.ShowInformation("FTP地址不可用,请返回登陆界面进行配置。");
             return;
         }
         //下载账套文件
         if (ftpWeb != null && requireEnvFile == "true" && topicDB.IsUploadEnvFile == true && !string.IsNullOrEmpty(topicDB.EnvFilePath))
         {
             envFileName      = Path.GetFileName(topicDB.EnvFilePath);
             envFilePath      = string.Format("{0}\\{1}", Globals.DownLoadDir, envFileName);
             copyEnvPath      = string.Format(@"{0}\SowerTestClient\Paper\Account\{1}", Application.StartupPath, envFileName);
             topicEnvFilePath = Path.GetDirectoryName(topicDB.EnvFilePath).Replace("\\", "//");
             ftpWeb.Download(Globals.DownLoadDir, envFileName, topicEnvFilePath, proDown, lblDown, "账套下载进度:");
         }
         //下载视频文件
         if (ftpWeb != null && topicDB.IsUploadVideoFile == true && !string.IsNullOrEmpty(topicDB.VideoFilePath))
         {
             videoFileName      = Path.GetFileName(topicDB.VideoFilePath);
             videoFilePath      = string.Format("{0}\\{1}", Globals.DownLoadDir, videoFileName);
             copyVideoPath      = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}\", Application.StartupPath, PublicClass.StudentCode, DirFileHelper.GetFileNameNoExtension(videoFileName));
             topicVideoFilePath = Path.GetDirectoryName(topicDB.VideoFilePath).Replace("\\", "//");
             ftpWeb.Download(Globals.DownLoadDir, videoFileName, topicVideoFilePath, proDown, lblDown, "视频下载进度:");
         }
         #region 验证题库文件
         if (fileExt != ".sdb" && fileExt != ".srk")
         {
             Msg.ShowError("该文件不是有效的题库文件,请重新添加!");
             return;
         }
         if (File.Exists(copyTPath) && File.Exists(copyPath))
         {
             if (!Msg.AskQuestion("该题库文件已经存在,确定要覆盖吗?"))
             {
                 return;
             }
         }
         if (File.Exists(filePath))
         {
             CommonUtil.ShowProcessing("正在验证题库,请稍候...", this, (obj) =>
             {
                 //复制一个.sdbt文件
                 DirFileHelper.CopyFile(filePath, fileTPath);
                 //修改.sdbt文件密码
                 bool updateResult = key3.ChangePassWordByGB2312(fileTPath, PublicClass.PassWordTopicDB_SDB, "");
                 if (updateResult)
                 {
                     SQLiteConnection conn = new SQLiteConnection(connectionT);
                     conn.Open();
                     if (ConnectionState.Open == conn.State)
                     {
                         //更改题库密码
                         conn.ChangePassword(PublicClass.PasswordTopicDB);
                         //复制题库到系统目录
                         DirFileHelper.CopyFile(filePath, copyPath);
                         DirFileHelper.CopyFile(fileTPath, copyTPath);
                         //复制账套到系统目录
                         if (requireEnvFile == "true" && topicDB.IsUploadEnvFile == true && !string.IsNullOrEmpty(topicDB.EnvFilePath))
                         {
                             DirFileHelper.CopyFile(envFilePath, copyEnvPath);
                         }
                         //复制视频到系统目录
                         if (topicDB.IsUploadVideoFile == true && !string.IsNullOrEmpty(topicDB.VideoFilePath))
                         {
                             ZipFileTools.UnZipSZL(videoFilePath, copyVideoPath);
                         }
                         conn.Close();
                     }
                     conn.Dispose();
                     conn = null;
                     DirFileHelper.DeleteFile(filePath);
                     DirFileHelper.DeleteFile(fileTPath);
                     DirFileHelper.DeleteFile(envFilePath);
                     DirFileHelper.DeleteFile(videoFilePath);
                 }
                 else
                 {
                     Msg.ShowError("该题库不是有效的题库文件!");
                 }
                 key3.Dispose();
             }, null);
         }
         #endregion
     }
     catch (SQLiteException se)
     {
         Msg.ShowError("无法打开题库文件,该题库不是有效的题库文件!");
         LogHelper.WriteLog(typeof(frmDownTopicDB), se);
         CommonUtil.WriteLog(se);
     }
     catch (WebException we)
     {
         Msg.ShowError("该题库文件不存在,请联系管理员重新上传。");
         LogHelper.WriteLog(typeof(frmDownTopicDB), we);
         CommonUtil.WriteLog(we);
     }
     catch (AggregateException ae)
     {
         Msg.ShowError("无法打开题库文件,该题库不是有效的题库文件!");
         LogHelper.WriteLog(typeof(frmDownTopicDB), ae);
         CommonUtil.WriteLog(ae);
     }
     catch (Exception ex)
     {
         PublicClass.ShowErrorMessageOk(ex.Message);
         LogHelper.WriteLog(typeof(frmDownTopicDB), ex);
         CommonUtil.WriteLog(ex);
     }
     finally
     {
         btnDown.Enabled = true;
     }
 }
Пример #4
0
        private void btnZuJuan_Click(object sender, EventArgs e)
        {
            string existsResult = string.Empty;

            try
            {
                if (cboSubject.SelectedIndex == 0)
                {
                    PublicClass.ShowMessageOk("请选择一门考试科目,在进行后续操作。");
                    return;
                }
                PublicClass.SubjectName = cboSubject.SelectedValue.ToString();
                PublicClass.JobType     = JobType.TiKu;
                InitialStudentDir();
                InitialSubjectProp();
                InitialKaoShiFangShi();
                PublicClass.oSubjectProp.PresetPaperID = Convert.ToInt32(lbTaoJuan.SelectedValue);
                PublicClass.VideoFilePath = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}\", Application.StartupPath, PublicClass.StudentCode, DirFileHelper.GetFileNameNoExtension(PublicClass.oSubjectProp.MediaPackageFileName));
                frmBusicWorkMain busicWorkMain = this.ParentForm as frmBusicWorkMain;
                existsResult = bService.ExistsTopicDB(PublicClass.oSubjectProp.TopicDBCode, PublicClass.oSubjectProp.TopicDBVersion);
                if (existsResult == "-1")
                {
                    Msg.ShowInformation("在作业中心->练习题库列表中没有添加该文件,请联系授课老师进行添加。");
                    return;
                }
                //模拟练习
                if (rdoExercise.Checked)
                {
                    PublicClass.oSubjectProp.ExamMode = "1";
                    PublicClass.SowerExamPlugn.SetParaValue(PublicClass.StudentDir, "题库信息", "考试模式", "1");

                    frmExamInfo examInfo = new frmExamInfo();
                    examInfo.Show();
                    busicWorkMain.Hide();
                }
                //正式考试
                if (rdoExam.Checked)
                {
                    PublicClass.oSubjectProp.ExamMode = "2";
                    PublicClass.SowerExamPlugn.SetParaValue(PublicClass.StudentDir, "题库信息", "考试模式", "2");

                    frmExamSubject examSubject = new frmExamSubject();
                    CommonUtil.subjectIndex = cboSubject.SelectedIndex;
                    examSubject.Show();
                    busicWorkMain.Hide();
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(frmExercise), ex);
                CommonUtil.WriteLog(ex);
                PublicClass.ShowErrorMessageOk(ex.Message);
            }
        }
Пример #5
0
        private void btnDoJob_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvResult.SelectedRows.Count == 0) return;
                M_MyJob myJob = dgvResult.SelectedRows[0].DataBoundItem as M_MyJob;
                PublicClass.oMyJob = myJob;
                PublicClass.JobType = JobType.ShiJuan;
                PublicClass.VideoFilePath = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}\",
                    Application.StartupPath, PublicClass.StudentCode, DirFileHelper.GetFileNameNoExtension(myJob.VideoFilePath));

                //作业限定时间&&当前时间小于作业发布开始时间
                if (myJob.HWSubmitTimeType.ToLower() == "true" &&       //true:限时,false:不限时
                    Globals.ServerTime < DateTime.Parse(myJob.ExamStartDateTime))
                {
                    PublicClass.ShowMessageOk("还没有到做作业的时间,先休息休息吧!");
                    return;
                }

                //作业限定时间&&不允许补交作业&&当前时间大于作业提交截止时间
                if (myJob.HWSubmitTimeType.ToLower() == "true" &&       //true:限时,false:不限时
                    myJob.IsPay.ToLower() == "false" &&           //true:允许补交作业,false:不允许补交作业
                    Globals.ServerTime > DateTime.Parse(myJob.ExamEndDateTime))
                {
                    PublicClass.ShowMessageOk("对不起,您已经过了交作业时间。\n请联系老师允许您补交作业!");
                    return;
                }

                //不允许重复提交&&作业已经提交
                if (myJob.IsAllowReSubmitScore.ToLower() == "false" &&
                    myJob.ScoreSubmitted == "1")
                {
                    PublicClass.ShowMessageOk("对不起,您已经提交过作业,不能重复提交!");
                    return;
                }

                //允许重复提交&&大于重复提交次数
                if (myJob.IsAllowReSubmitScore.ToLower() == "true" &&
                    myJob.AllowReSubmitScoreCount <= myJob.SubmittedCount &&
                    myJob.AllowReSubmitScoreCount != -1)
                {
                    PublicClass.ShowMessageOk(string.Format("对不起,您只能提交{0}次成绩!", myJob.AllowReSubmitScoreCount));
                    return;
                }

                string envFilePath = string.Format(@"{0}\SowerTestClient\Paper\Account\{1}", Application.StartupPath, myJob.EnvFileName);
                string requireEnvFile = string.IsNullOrEmpty(myJob.RequireEnvFile) == true ? "false" : myJob.RequireEnvFile.ToLower();
                if (requireEnvFile == "true" && !File.Exists(envFilePath))
                {
                    PublicClass.ShowMessageOk(string.Format("对不起,没有检测到账套文件{0}。\n请您进行手动添加!", myJob.EnvFileName));
                    return;
                }

                InitialStudentDir();

                InitialSubjectProp();

                InitialKaoShiFangShi();

                frmExamInfo examInfo = new frmExamInfo();
                examInfo.Show();

                frmBusicWorkMain busicWorkMain = this.ParentForm as frmBusicWorkMain;
                busicWorkMain.Hide();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(frmDownWork), ex);
                CommonUtil.WriteLog(ex);
            }
        }