Пример #1
0
    public IOutFile CreateNewObj(OutFileType type)
    {
        IOutFile _result = null;

        switch (type)
        {
        case OutFileType.TXT:
            _result = new OutFile_Text();
            break;

        case OutFileType.TXT2:
            _result = new OutFile_Text2();
            break;

        case OutFileType.MDB:
            _result = new OutFile_Mdb();
            break;

        case OutFileType.XLSX:
            _result = new OutFile_Xlsx();
            break;

        case OutFileType.XLSX2:
            _result = new OutFile_Xlsx2();
            break;

        default:
            break;
        }

        return(_result);
    }
Пример #2
0
    public void ExportFileByZip(int apployInfoId)
    {
        YHFramework.DAL.ApployInfoDal        apployInfoDal = new ApployInfoDal();
        YHFramework.SysModel.ApployInfoModel model         = apployInfoDal.GetModel(apployInfoId);
        OutFileFactory FileFactory  = new OutFileFactory();
        IOutFile       outfile      = FileFactory.CreateNewObj(GetOutFileType(apployInfoId));
        FileInfo       fileinfo     = new FileInfo(model.FileName);
        string         fileanme     = fileinfo.Name.Replace(fileinfo.Extension, "");
        string         tempfilename = fileanme + outfile.ExtName;
        string         zipfilename  = fileanme + ".zip";
        string         tempfilepath = System.AppDomain.CurrentDomain.BaseDirectory + "tempfile\\";
        string         zipfilepath  = System.AppDomain.CurrentDomain.BaseDirectory + "down\\";

        if (Directory.Exists(tempfilepath) == false)
        {
            Directory.CreateDirectory(tempfilepath);
        }

        #region 清理文件

        if (File.Exists(tempfilepath + tempfilename))
        {
            File.Delete(tempfilepath + tempfilename);
        }

        if (File.Exists(zipfilepath + zipfilename))
        {
            File.Delete(zipfilepath + zipfilename);
        }

        #endregion

        #region 写入临时文件

        int pagezise  = 20000;
        int pagecount = 0;
        int datacount = 0;


        YHFramework.DAL.CodeDataDal codedatadal = new CodeDataDal();
        string sqlwhere = " and ApployInfoId=" + apployInfoId + " ";
        datacount = codedatadal.GetCount(sqlwhere, "");
        if (datacount % pagezise == 0)
        {
            pagecount = datacount / pagezise;
        }
        else
        {
            pagecount = datacount / pagezise + 1;
        }

        for (int i = 1; i <= pagecount; i++)
        {
            DataTable dt = codedatadal.GetPageList(" a.* ", "", sqlwhere, i, pagezise);
            outfile.OutFilePath = tempfilepath;
            outfile.FileName    = tempfilename;
            outfile.OutFile(dt);
        }


        #endregion

        #region 压缩
        bool result = ZipCommon.ZipFile(tempfilepath + tempfilename, zipfilepath, fileanme, 5, 2048, model.Secret);
        if (result)
        {
            this.txtMsg.Text = "压缩成功";
        }
        else
        {
            this.txtMsg.Text = "压缩失败";
        }
        #endregion

        #region 更新任务

        #endregion
    }