Example #1
0
        /// <summary>
        /// 添加账套文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddFile_Click(object sender, EventArgs e)
        {
            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\Paper\Account\{1}", Application.StartupPath, fileName);
                try
                {
                    if (fileExt != ".casf")
                    {
                        PublicClass.ShowMessageOk("该文件不是有效的账套文件,请重新添加!");
                        return;
                    }
                    if (File.Exists(copyPath))
                    {
                        DialogResult dialogResult = PublicClass.ShowMessageOKCancel("该账套文件已经存在,确定要覆盖吗?");
                        if (dialogResult == DialogResult.Cancel)
                        {
                            return;
                        }
                    }
                    CommonUtil.ShowProcessing("正在处理中,请稍候...", this, (obj) =>
                    {
                        DirFileHelper.CopyFile(filePath, copyPath);
                    }, null);
                }
                catch (Exception ex)
                {
                    PublicClass.ShowMessageOk(ex.Message);
                }
                finally
                {
                    LoadFiles();
                }
            }
        }
Example #2
0
        /// <summary>根据UploadConfig的单一缩放</summary>
        /// <param name="picImg">图片地址(没有任何扩展后缀,比如后台没有:"b","m","s","b")</param>
        /// <param name="mC">根据vid查得的 UploadConfig配置</param>
        public static void OneMakeThumbImage(string picImg, UploadConfig mC)
        {
            string bigImg = DirFileHelper.GetFilePathPostfix(picImg, "b");
            string midImg = DirFileHelper.GetFilePathPostfix(picImg, "m");
            string minImg = DirFileHelper.GetFilePathPostfix(picImg, "s");
            string hotImg = DirFileHelper.GetFilePathPostfix(picImg, "h");
            string orgImg = DirFileHelper.GetFilePathPostfix(picImg, "o");

            //--------------------------------------------------
            //big
            DirFileHelper.DeleteFile(bigImg);
            if (mC.IsBigPic == 1)
            {
                if (mC.BigWidth > 0 && mC.BigHeight > 0)
                {
                    Uploader.MakeThumbImage(orgImg, bigImg,
                                            ConvertHelper.Cint0(mC.BigWidth),
                                            ConvertHelper.Cint0(mC.BigHeight),
                                            ConvertHelper.Cint0(mC.BigQuality),
                                            ConvertHelper.Cint0(mC.CutType));
                }
                else//因为不限制宽高,所以直接复制出来就行了
                {
                    DirFileHelper.CopyFile(orgImg, bigImg);
                }

                //添加水印
                if (mC.IsWaterPic == 1)
                {
                    Uploader.MakeWaterPic(bigImg);
                }
            }


            //--------------------------------------------------
            //mid
            DirFileHelper.DeleteFile(midImg);
            if (mC.IsMidPic == 1)
            {
                if (mC.MidWidth > 0 && mC.MidHeight > 0)
                {
                    Uploader.MakeThumbImage(orgImg, midImg,
                                            ConvertHelper.Cint0(mC.MidWidth),
                                            ConvertHelper.Cint0(mC.MidHeight),
                                            ConvertHelper.Cint0(mC.MidQuality),
                                            ConvertHelper.Cint0(mC.CutType));
                }
                else//因为不限制宽高,所以直接复制出来就行了
                {
                    DirFileHelper.CopyFile(orgImg, midImg);
                }

                //添加水印
                if (mC.IsWaterPic == 1)
                {
                    Uploader.MakeWaterPic(midImg);
                }
            }

            //--------------------------------------------------
            //hot
            DirFileHelper.DeleteFile(hotImg);
            if (mC.IsHotPic == 1)
            {
                if (mC.HotWidth > 0 && mC.HotHeight > 0)
                {
                    Uploader.MakeThumbImage(orgImg, hotImg,
                                            ConvertHelper.Cint0(mC.HotWidth),
                                            ConvertHelper.Cint0(mC.HotHeight),
                                            ConvertHelper.Cint0(mC.HotQuality),
                                            ConvertHelper.Cint0(mC.CutType));
                }
                else//因为不限制宽高,所以直接复制出来就行了
                {
                    DirFileHelper.CopyFile(orgImg, hotImg);
                }

                //添加水印
                if (mC.IsWaterPic == 1)
                {
                    Uploader.MakeWaterPic(hotImg);
                }
            }

            //--------------------------------------------------
            //min
            DirFileHelper.DeleteFile(minImg);
            if (mC.IsMinPic == 1)
            {
                if (mC.IsMinPic > 0 && mC.MinHeight > 0)
                {
                    Uploader.MakeThumbImage(orgImg, minImg,
                                            ConvertHelper.Cint0(mC.MinWidth),
                                            ConvertHelper.Cint0(mC.MinHeight),
                                            ConvertHelper.Cint0(mC.MinQuality),
                                            ConvertHelper.Cint0(mC.CutType));
                }
                else//因为不限制宽高,所以直接复制出来就行了
                {
                    DirFileHelper.CopyFile(orgImg, minImg);
                }

                //微型图不用加水印
            }


            //--------------------------------------------------
            //pic
            DirFileHelper.DeleteFile(picImg);
            if (mC.IsFixPic == 1)
            {
                if (mC.PicWidth > 0 && mC.PicHeight > 0)
                {
                    Uploader.MakeThumbImage(orgImg, picImg,
                                            ConvertHelper.Cint0(mC.PicWidth),
                                            ConvertHelper.Cint0(mC.PicHeight),
                                            ConvertHelper.Cint0(mC.PicQuality),
                                            ConvertHelper.Cint0(mC.CutType));
                }
                else//因为不限制宽高,所以直接复制出来就行了
                {
                    DirFileHelper.CopyFile(orgImg, picImg);
                }

                //添加水印
                if (mC.IsWaterPic == 1)
                {
                    Uploader.MakeWaterPic(picImg);
                }
            }
        }
Example #3
0
        /// <summary>生成一条配置记录的图片</summary>
        /// <param name="vid"></param>
        /// <returns></returns>
        public string fix_PicSize(int vid)
        {
            //---------------------------------------------------
            UploadConfig mC = new UploadConfig(x => x.Id == vid);

            if (mC.Id != vid)
            {
                return("缺少参数:Id!");
            }

            StringBuilder sb = new StringBuilder();
            //只修改关联的图片
            //string sql = "select Path from UploadFile where Id=" + vid + " and JoinId>0 order by Id";

            //修改全部图片(包含非关联)
            //string sql = "select Path from UploadFile where UploadConfig_Id=" + vid + " order by Id";

            //定义要查询出来的列
            var list = new List <string>();

            list.Add(UploadFileTable.Path);
            //定义查询条件
            var wheres = new List <ConditionHelper.SqlqueryCondition>();

            wheres.Add(new ConditionHelper.SqlqueryCondition(ConstraintType.And, UploadFileTable.UploadConfig_Id, Comparison.Equals, vid));
            //定义排序
            var sort = new List <string>();

            sort.Add(UploadFileTable.Id);

            string[] rs1 = DataTableHelper.GetArrayString(GetDataTable(false, 0, list, 0, 0, wheres, sort), UploadFileTable.Path);
            if (rs1 != null && rs1.Length > 0)
            {
                int ti = rs1.Length;
                for (int i = 0; i < ti; i++)
                {
                    string picImg = rs1[i];
                    string sExt   = DirFileHelper.GetFileExtension(picImg).ToLower();
                    if (picImg.Length > 4 && (sExt == "jpg" || sExt == "png" || sExt == "gif"))
                    {
                        string orgImg = DirFileHelper.GetFilePathPostfix(picImg, "o");

                        if (!DirFileHelper.IsExistFile(orgImg))
                        {
                            DirFileHelper.CopyFile(picImg, orgImg);
                        }

                        //原始图存在的情况下,才能生成其它size
                        if (DirFileHelper.IsExistFile(orgImg))
                        {
                            OneMakeThumbImage(picImg, mC);
                        }
                        else
                        {
                            sb.AppendFormat("原始文件不存在={0}<br />", picImg);
                        }
                    }
                }
            }
            return(sb.ToString());
        }
Example #4
0
        /// <returns>上传成功返回"",并填充 Model.UploadFile</returns>
        /// <param name="vid">上传配置模块id,即UploadConfig_Id</param>
        /// <param name="key">随机key</param>
        /// <param name="userId">上传者id</param>
        /// <param name="userName">上传者UserName</param>
        /// <param name="remotePicUrl">远程图片的url地址</param>
        /// <param name="m_r">Model.UploadFile</param>
        /// <returns>上传成功返回"",并填充 Model.UploadFile</returns>
        public string Upload_RemotePic(int vid, string key, int userId, string userName, string remotePicUrl, UploadFile m_r)
        {
            #region 检查参数
            //---------------------------------------------------
            if (vid < 1 || key.Length < 10)
            {
                return("缺少参数:key或sid");
            }
            //---------------------------------------------------

            #region 检查登陆
            m_r.UserId   = userId;
            m_r.UserName = userName;

            if (m_r.UserId == 0)
            {
                return("您的权限不足!");
            }
            #endregion

            //---------------------------------------------------
            UploadConfig mC = Read_UploadConfig(vid);
            if (mC.Id != vid)
            {
                return("缺少参数:UploadConfig_Id!");
            }

            if (mC.IsPost != 1)
            {
                return("系统暂时禁止上传文件2!");
            }

            if (mC.IsEditor != 1)
            {
                return("非编辑器类别!");
            }

            mC.UploadType_TypeKey = "image";
            #endregion


            //----------------------------------------------
            #region 生成暂时目录
            string sCfgSavePath = new Uploader().SavePath;
            string sSavePath    = DirFileHelper.FixDirPath(sCfgSavePath + mC.SaveDir) + DateTime.Now.ToString("yyMM") + "/";
            if (!DirFileHelper.CheckSaveDir(sSavePath))
            {
                return("SavePath设置不当:" + sSavePath + ", 或权限不足!");
            }

            string sServerDir = sCfgSavePath + "remote/";
            if (!DirFileHelper.CheckSaveDir(sServerDir))
            {
                return("ServerDir设置不当:" + sServerDir + ", 或权限不足!");
            }
            //----------------------------------------------
            string sSrcName = StringHelper.Left(DirFileHelper.GetFileName(remotePicUrl), 90);
            string sFileExt = DirFileHelper.GetFileExtension(sSrcName);

            //因部部分网站不是标准的jpg、gif扩展名,所以修改下面代码
            if (sFileExt.Length > 0)
            {
                string sAllowed = ",jpg,gif,png,bmp,";
                string sExt     = "," + sFileExt.ToLower() + ",";
                if (sAllowed.IndexOf(sExt) == -1)
                {
                    sFileExt = "jpg";
                }
            }
            else
            {
                sFileExt = "jpg";
            }
            //----------------------------------------------

            string sNewFile = DirFileHelper.GetRndFileName("." + sFileExt);

            if (sServerDir.IndexOf(":") < 0)
            {
                sServerDir = DirFileHelper.FixDirPath(DirFileHelper.GetMapPath(sServerDir));
            }
            string sNewRoot = System.IO.Path.Combine(sServerDir, sNewFile);
            #endregion

            //----------------------------------------------
            #region   到暂时目录
            try
            {
                var wc = new System.Net.WebClient();
                wc.DownloadFile(remotePicUrl, sNewRoot);
            }
            catch (Exception ex)
            {
                //throw ex;
                return(ex.Message.ToLower());
            }

            if (!DirFileHelper.IsExistFile(sNewRoot))
            {
                return("上传失败");
            }
            #endregion

            //----------------------------------------------
            #region 判断是否真实图片格式,并取得图片宽高
            int ww = 0, hh = 0;
            if (!Uploader.Get_Pic_WW_HH(sNewRoot, out ww, out hh))
            {
                DirFileHelper.DeleteFile(sNewRoot);
                return("非法格式!不是图片文件。");
            }

            int  iMaxSize  = mC.PicSize;
            long iFileSize = DirFileHelper.GetFileSize(sNewRoot);

            /*
             * if (iFileSize > iMaxSize)
             * {
             *  return "上传文件大小超过了限制.最多上传(" + DirFileHelper.FmtFileSize2(iMaxSize) + ").";
             * }
             */
            #endregion


            #region 把上传的暂时文件复制到相关模块目录中
            string sNewPath = sSavePath + sNewFile;
            string orgImg   = DirFileHelper.GetFilePathPostfix(sNewPath, "o");

            //复制到原始图
            DirFileHelper.CopyFile(sNewRoot, orgImg);

            //删除暂时上传的图片
            DirFileHelper.DeleteFile(sNewRoot);

            //生成相关缩略图
            OneMakeThumbImage(sNewPath, mC);

            #endregion


            //----------------------------------------------
            #region 保存入数据库
            m_r.UploadConfig_Id = mC.Id;
            m_r.JoinName        = mC.JoinName;
            m_r.JoinId          = 0;

            m_r.UserType = mC.UserType;
            m_r.UserIp   = IpHelper.GetUserIp();
            m_r.AddDate  = DateTime.Now;
            m_r.InfoText = "";
            m_r.RndKey   = key;

            m_r.Name = sNewFile;
            m_r.Path = sNewPath;
            m_r.Src  = sSrcName;
            m_r.Ext  = sFileExt;

            m_r.Size      = ConvertHelper.Cint0(iFileSize);
            m_r.PicWidth  = ww;
            m_r.PicHeight = hh;

            //保存入数据库
            Add_UploadFile(m_r);
            #endregion

            //------------------------------------
            //上传成功,输出结果
            return("");
        }
Example #5
0
        /// <summary>
        /// 执行创建文件
        /// </summary>
        /// <param name="baseConfigModel">基本信息</param>
        /// <param name="strCode">生成代码内容</param>
        public static void CreateExecution(BaseConfigModel baseConfigModel, string strCode)
        {
            var strParam = strCode.ToJObject();

            #region 实体类

            string entityCode = strParam["entityCode"].ToString();
            string entityPath = baseConfigModel.OutputEntity + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.EntityClassName + ".cs";
            if (!System.IO.File.Exists(entityPath))
            {
                DirFileHelper.CreateFileContent(entityPath, entityCode);
            }

            #endregion

            #region  射类

            string entitymapCode = strParam["entitymapCode"].ToString();
            string entitymapPath = baseConfigModel.OutputMap + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.MapClassName + ".cs";
            if (!System.IO.File.Exists(entitymapPath))
            {
                DirFileHelper.CreateFileContent(entitymapPath, entitymapCode);
            }

            #endregion

            #region  务类

            string serviceCode = strParam["serviceCode"].ToString();
            string servicePath = baseConfigModel.OutputService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.ServiceClassName + ".cs";
            if (!System.IO.File.Exists(servicePath))
            {
                DirFileHelper.CreateFileContent(servicePath, serviceCode);
            }

            #endregion

            #region 接口类

            string iserviceCode = strParam["iserviceCode"].ToString();
            string iservicePath = baseConfigModel.OutputIService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.IServiceClassName + ".cs";
            if (!System.IO.File.Exists(iservicePath))
            {
                DirFileHelper.CreateFileContent(iservicePath, iserviceCode);
            }

            #endregion

            #region 业务类

            string businesCode = strParam["businesCode"].ToString();
            string businesPath = baseConfigModel.OutputBusines + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.BusinesClassName + ".cs";
            if (!System.IO.File.Exists(businesPath))
            {
                DirFileHelper.CreateFileContent(businesPath, businesCode);
            }

            #endregion

            #region 控制器

            string controllerCode = strParam["controllerCode"].ToString();
            string controllerPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Controllers\\" + baseConfigModel.ControllerName + ".cs";
            if (!System.IO.File.Exists(controllerPath))
            {
                DirFileHelper.CreateFileContent(controllerPath, controllerCode);
            }

            #endregion

            #region 列表页

            string indexCode = strParam["indexCode"].ToString();
            string indexPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.IndexPageName + ".cshtml";
            if (!System.IO.File.Exists(indexPath))
            {
                DirFileHelper.CreateFileContent(indexPath, indexCode.Replace("★", "&nbsp;"));
            }

            #endregion

            #region 表单页

            string formCode = strParam["formCode"].ToString();
            string formPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.FormPageName + ".cshtml";
            if (!System.IO.File.Exists(formPath))
            {
                DirFileHelper.CreateFileContent(formPath, formCode.Replace("★", "&nbsp;"));
            }

            #endregion

            #region web.config ,Registration.cs 文件 2017-4-1 lijun

            string configPath = "Areas\\" + baseConfigModel.OutputAreas + "\\Views\\Web.config";
            if (!System.IO.File.Exists(baseConfigModel.OutputController + "\\" + configPath))
            {
                // 读取 SystemManager 的配置文件,复制到新文件中
                string systemconfigPath = "Areas\\SystemManage\\Views\\Web.config";

                DirFileHelper.CopyFile(systemconfigPath, configPath);
            }

            string registrationPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.OutputAreas + "AreaRegistration.cs";
            if (!System.IO.File.Exists(registrationPath))
            {
                // 读取 SystemManager 的Registration文件,修改后复制到新文件中
                string sysRegistrationPath = baseConfigModel.OutputController + "\\Areas\\SystemManage\\SystemManageAreaRegistration.cs";
                string text = DirFileHelper.ReadFile(sysRegistrationPath);
                if (!string.IsNullOrEmpty(text))
                {
                    DirFileHelper.CreateFileContent(registrationPath, text.Replace("SystemManage", baseConfigModel.OutputAreas));
                }
            }

            #endregion
        }
Example #6
0
        private void DownLoadTopicDB(string fileFullName)
        {
            string filePath    = fileFullName;
            string fileTPath   = fileFullName + "t";
            string fileName    = Path.GetFileName(filePath);
            string fileExt     = Path.GetExtension(filePath).ToLower();
            string copyPath    = string.Format(@"{0}\data\{1}", Application.StartupPath, fileName.Replace(".srk", ".sdb"));
            string copyTPath   = string.Format(@"{0}\data\{1}t", Application.StartupPath, fileName.Replace(".srk", ".sdb"));
            string connection  = string.Format(@"data source={0};password={1};polling=false;failifmissing=true", filePath, PublicClass.PasswordTopicDB);
            string connectionT = string.Format(@"data source={0};polling=false;failifmissing=true", fileTPath);

            try
            {
                if (fileExt != ".sdb" && fileExt != ".srk")
                {
                    PublicClass.ShowMessageOk("该文件不是有效的题库文件,请重新添加!");
                    return;
                }
                if (File.Exists(copyPath) && File.Exists(copyTPath))
                {
                    DialogResult dialogResult = PublicClass.ShowMessageOKCancel("该题库文件已经存在,确定要覆盖吗?");
                    if (dialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                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);
                            conn.Close();
                        }
                        conn.Dispose();
                        conn = null;
                    }
                    else
                    {
                        PublicClass.ShowMessageOk("无法打开题库文件,该题库不是有效的题库文件!");
                    }
                    key3.Dispose();
                }, null);
            }
            catch (SQLiteException)
            {
                PublicClass.ShowMessageOk("无法打开题库文件,该题库不是有效的题库文件!");
            }
            catch (AggregateException)
            {
                PublicClass.ShowMessageOk("无法打开题库文件,该题库不是有效的题库文件!");
            }
            catch (Exception ex)
            {
                PublicClass.ShowMessageOk(ex.Message);
            }
        }
Example #7
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;
     }
 }
Example #8
0
        /// <summary>上传文件,并按设置生成缩略图,水印</summary>
        /// <returns></returns>
        public bool UploadFile(HttpPostedFile oFile = null)
        {
            #region 检查设置
            if (!this.IsEnabled)
            {
                SendResponse(500, "");
                return(false);
            }

            if (this.IsChkSrcPost)
            {
                if (!RequestHelper.ChkSrcPost())
                {
                    SendResponse(501, "");
                    return(false);
                }
            }

            if (this._savePath.Length < 1)
            {
                SendResponse(101, "SavePath未设置");
                return(false);
            }

            if (oFile == null)
            {
                if (this.FilePostName.Length < 1)
                {
                    SendResponse(101, "filePostName未设置");
                    return(false);
                }
            }

            this._savePath = DirFileHelper.FixDirPath(_savePath) + DateTime.Now.ToString("yyMM") + "/";
            bool isOk = DirFileHelper.CheckSaveDir(this._savePath);

            if (!isOk)
            {
                SendResponse(101, "SavePath设置不当:" + this._savePath + ", 或权限不足!");
                return(false);
            }
            #endregion

            //------------------------------------------------
            #region 获取文件对象
            //获取文件对象
            if (oFile == null)
            {
                oFile = HttpContext.Current.Request.Files[FilePostName];
            }
            if (oFile == null)
            {
                SendResponse(201, "");
                return(false);
            }
            //------------------------------------------------
            //原始文件名;
            this.SrcName = Path.GetFileName(oFile.FileName);
            #endregion

            //------------------------------------------------
            #region 检查文件大小
            this._fileSize = oFile.ContentLength;

            //不能上传小于10字节的内容
            if (this.SrcName.Length < 3 || this._fileSize < 10)
            {
                SendResponse(201, "");
                return(false);
            }

            //检测文件大小是否超过限制
            if (this._fileSize > (this._maxSize * 1024))
            {
                SendResponse(301, "");
                return(false);
            }

            #endregion

            //------------------------------------------------
            #region 检查文件类型
            this.FileExt = Path.GetExtension(this.SrcName).ToLower().TrimStart('.');

            if (!checkAllowedExt(this.FileExt))
            {
                SendResponse(202, "");
                return(false);
            }
            #endregion


            #region   文件
            //上传
            string sServerDir = _savePath;
            if (sServerDir.IndexOf(":") < 0)
            {
                sServerDir = DirFileHelper.FixDirPath(DirFileHelper.GetMapPath(sServerDir));
            }

            string sNewFile = "";   //新文件名(系统生成)
            string sNewRoot = "";   //新文件路径(绝对路径)

            while (true)
            {
                sNewFile = DirFileHelper.GetRndFileName("." + this.FileExt);
                sNewRoot = System.IO.Path.Combine(sServerDir, sNewFile);

                if (!DirFileHelper.IsExistFile(sNewRoot))
                {
                    try
                    {
                        oFile.SaveAs(sNewRoot);
                    }
                    catch
                    {
                        SendResponse(204, "");
                        return(false);
                    }
                    break;
                }
            }

            this.NewFile = sNewFile;
            this.NewPath = _savePath + sNewFile;
            #endregion

            //------------------------------------------------
            #region 生成缩略图 + 水印
            if (this.FileExt == "jpg" || this.FileExt == "png" || this.FileExt == "gif" || this.FileExt == "jpeg" || this.FileExt == "bmp")
            {
                #region 取得原始尺寸
                try//能取得图片宽高,是真实的图片
                {
                    System.Drawing.Image testImage1 = System.Drawing.Image.FromFile(sNewRoot);
                    this.SrcWidth  = testImage1.Width;
                    this.SrcHeight = testImage1.Height;
                    testImage1.Dispose();

                    this.NewWidth  = this.SrcWidth;
                    this.NewHeight = this.SrcHeight;
                }
                catch
                {
                    //非法格式,不是真正的图片
                    DirFileHelper.DeleteFile(sNewRoot);
                    SendResponse(202, "");
                    return(false);
                }

                //------------------------------------------------
                //先备份原始图
                var tmpPath = "";
                tmpPath = System.IO.Path.Combine(sServerDir, DirFileHelper.GetFileNamePostfix(sNewFile, "o"));
                DirFileHelper.CopyFile(sNewRoot, tmpPath);
                #endregion


                if (this._isFixPic || this._isBigPic || this._isMidPic || this._isMinPic)
                {
                    #region 创建大图
                    if (this._isBigPic)
                    {
                        tmpPath = System.IO.Path.Combine(sServerDir, DirFileHelper.GetFileNamePostfix(sNewFile, "b"));

                        if (this._bigWidth > 0 && this._bigHeight > 0)
                        {
                            //缩略
                            MakeThumbImage(sNewRoot, tmpPath, this._bigWidth, this._bigHeight, this._bigQuality, this.CutType);
                        }
                        else//因为不限制宽高,所以直接复制出来就行了
                        {
                            DirFileHelper.CopyFile(sNewRoot, tmpPath);
                        }

                        //添加水印
                        if (this.IsWaterPic)
                        {
                            MakeWaterPic(tmpPath);
                        }
                    }
                    #endregion

                    //------------------------------------------------
                    #region 创建中图
                    if (this._isMidPic)
                    {
                        tmpPath = System.IO.Path.Combine(sServerDir, DirFileHelper.GetFileNamePostfix(sNewFile, "m"));

                        if (this._midWidth > 0 && this._midHeight > 0)
                        {
                            //缩略图
                            MakeThumbImage(sNewRoot, tmpPath, this._midWidth, this._midHeight, this._midQuality, this.CutType);
                        }
                        else//因为不限制宽高,所以直接复制出来就行了
                        {
                            DirFileHelper.CopyFile(sNewRoot, tmpPath);
                        }

                        //添加水印
                        if (this.IsWaterPic)
                        {
                            MakeWaterPic(tmpPath);
                        }
                    }
                    #endregion

                    //------------------------------------------------
                    #region 创建小图
                    if (this._isMinPic)
                    {
                        tmpPath = System.IO.Path.Combine(sServerDir, DirFileHelper.GetFileNamePostfix(sNewFile, "s"));

                        if (this._minWidth > 0 && this._minHeight > 0)
                        {
                            //缩略图
                            MakeThumbImage(sNewRoot, tmpPath, this._minWidth, this._minHeight, this._minQuality, this.CutType);
                        }
                        else//因为不限制宽高,所以直接复制出来就行了
                        {
                            DirFileHelper.CopyFile(sNewRoot, tmpPath);
                        }

                        //微型图不用加水印
                    }
                    #endregion

                    //------------------------------------------------
                    #region 创建推荐图
                    if (this._isHotPic)
                    {
                        tmpPath = System.IO.Path.Combine(sServerDir, DirFileHelper.GetFileNamePostfix(sNewFile, "h"));

                        if (this._hotWidth > 0 && this._hotHeight > 0)
                        {
                            //缩略图
                            MakeThumbImage(sNewRoot, tmpPath, this._hotWidth, this._hotHeight, this._hotQuality, this.CutType);
                        }
                        else//因为不限制宽高,所以直接复制出来就行了
                        {
                            DirFileHelper.CopyFile(sNewRoot, tmpPath);
                        }


                        //添加水印
                        if (this.IsWaterPic)
                        {
                            MakeWaterPic(tmpPath);
                        }
                    }
                    #endregion

                    //------------------------------------------------
                    #region 限制列表图
                    if (this._isFixPic && this._picWidth > 0 && this._picHeight > 0)
                    {
                        MakeThumbImage(sNewRoot, sNewRoot, this._picWidth, this._picHeight, this._picQuality, this.CutType);
                    }
                    #endregion


                    #region 取得缩放后的图片宽高
                    try
                    {
                        System.Drawing.Image testImage2 = System.Drawing.Image.FromFile(sNewRoot);
                        this.NewWidth  = testImage2.Width;
                        this.NewHeight = testImage2.Height;
                        testImage2.Dispose();
                    }
                    catch
                    {
                        DirFileHelper.DelPicFile(this.NewPath);
                        SendResponse(202, "");
                        return(false);
                    }
                    #endregion
                }

                //列表图是否加水印
                if (DirFileHelper.IsExistFile(sNewRoot) && this.IsWaterPic)
                {
                    MakeWaterPic(sNewRoot);
                }
            }
            #endregion

            //上传成功!!
            return(true);
        }
Example #9
0
        /// <summary>
        /// 添加题库文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddTopicDB_Click(object sender, EventArgs e)
        {
            DialogResult result = ofdOpenTopicDB.ShowDialog();

            if (result == DialogResult.OK)
            {
                string        existsResult = string.Empty;
                string        filePath     = ofdOpenTopicDB.FileName;
                string        fileTPath    = ofdOpenTopicDB.FileName + "t";
                string        fileName     = Path.GetFileName(filePath);
                string        fileExt      = Path.GetExtension(filePath).ToLower();
                string        copyPath     = string.Format(@"{0}\data\{1}_{2}", Application.StartupPath, PublicClass.StudentCode, fileName.Replace(".srk", ".sdb"));
                string        copyTPath    = string.Format(@"{0}\data\{1}_{2}t", Application.StartupPath, PublicClass.StudentCode, fileName.Replace(".srk", ".sdb"));
                string        connection   = string.Format(@"data source={0};password={1};polling=false;failifmissing=true", filePath, PublicClass.PasswordTopicDB);
                string        connectionT  = string.Format(@"data source={0};polling=false;failifmissing=true", fileTPath);
                M_SubjectProp mSubjectProp = new M_SubjectProp();
                try
                {
                    if (fileExt != ".sdb" && fileExt != ".srk")
                    {
                        PublicClass.ShowMessageOk("该文件不是有效的题库文件,请重新添加!");
                        return;
                    }
                    if (File.Exists(copyPath) && File.Exists(copyTPath))
                    {
                        DialogResult dialogResult = PublicClass.ShowMessageOKCancel("该题库文件已经存在,确定要覆盖吗?");
                        if (dialogResult == DialogResult.Cancel)
                        {
                            return;
                        }
                    }
                    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);
                                conn.Close();
                                DirFileHelper.CopyFile(filePath, copyPath);
                                DirFileHelper.CopyFile(fileTPath, copyTPath);
                                mSubjectProp = bSubjectProp.GetSubjectProp(Path.GetFileName(copyTPath));
                                existsResult = bService.ExistsTopicDB(mSubjectProp.TopicDBCode, mSubjectProp.TopicDBVersion);
                                if (existsResult == "-1")
                                {
                                    DirFileHelper.DeleteFile(copyPath);
                                    DirFileHelper.DeleteFile(copyTPath);
                                }
                            }
                            conn.Dispose();
                            conn = null;
                            DirFileHelper.DeleteFile(fileTPath);
                        }
                        else
                        {
                            PublicClass.ShowMessageOk("无法打开题库文件,该题库不是有效的题库文件!");
                        }
                        key3.Dispose();
                    }, null);
                    if (existsResult == "-1")
                    {
                        Msg.ShowInformation("在作业中心->练习题库列表中没有添加该文件,请联系授课老师进行添加。");
                    }
                }
                catch (SQLiteException)
                {
                    PublicClass.ShowMessageOk("无法打开题库文件,该题库不是有效的题库文件!");
                    DirFileHelper.DeleteFile(copyPath);
                    DirFileHelper.DeleteFile(copyTPath);
                }
                catch (AggregateException)
                {
                    PublicClass.ShowMessageOk("无法打开题库文件,该题库不是有效的题库文件!");
                    DirFileHelper.DeleteFile(copyPath);
                    DirFileHelper.DeleteFile(copyTPath);
                }
                catch (Exception ex)
                {
                    PublicClass.ShowMessageOk(ex.Message);
                    DirFileHelper.DeleteFile(copyPath);
                    DirFileHelper.DeleteFile(copyTPath);
                }
                finally
                {
                    LoadTopicDB();
                }
            }
        }