Ejemplo n.º 1
0
        /// <summary>
        /// 压缩一个数据集到文件
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="destFileName"></param>
        /// <param name="cry"></param>
        /// <param name="cryKey"></param>
        /// <returns></returns>
        public I3MsgInfo CompressADataSet(DataSet dataSet, string destFileName, bool cry, string cryKey)
        {
            #region 初始化临时文件变量
            string tmpDir         = I3DirectoryUtil.GetAppTmpTmpDir();
            string tmpDataSetFile = Path.Combine(tmpDir, "DataSet.tmp");
            string tmpRarFile     = Path.Combine(tmpDir, I3DateTimeUtil.ConvertDateTimeToLongString(DateTime.Now) + ".tmp");
            if ((!I3DirectoryUtil.CreateDirctory(tmpDir).State) || (!I3FileUtil.CheckFileNotExists(tmpDataSetFile)) || (!I3FileUtil.CheckFileNotExists(tmpRarFile)))
            {
                return(new I3MsgInfo(false, ""));
            }
            #endregion

            try
            {
                #region 数据集保存到临时文件
                try
                {
                    //保存时要写入架构信息,否则字段类型有可能会更改,如Int32更改为String
                    dataSet.WriteXml(tmpDataSetFile, XmlWriteMode.WriteSchema);
                }
                catch (Exception ex)
                {
                    return(new I3MsgInfo(false, "数据集保存到临时文件失败!文件名:" + tmpDataSetFile + "错误信息:" + ex.Message));
                }
                if (!File.Exists(tmpDataSetFile))
                {
                    return(new I3MsgInfo(false, "数据集保存到临时文件失败!文件名:" + tmpDataSetFile));
                }
                #endregion

                #region 数据集临时文件压缩到临时压缩包
                I3MsgInfo msg = this.CompressASingleFile(tmpDataSetFile, tmpRarFile);
                if (!msg.State)
                {
                    return(msg);
                }
                if (!File.Exists(tmpRarFile))
                {
                    return(new I3MsgInfo(false, "数据集临时文件压缩失败!文件名:" + tmpDataSetFile));
                }
                #endregion

                #region 临时压缩包加密到目标文件
                if (cry)
                {
                    return(I3RijnDaelCry.CryFile(tmpRarFile, destFileName, cryKey));
                }
                else
                {
                    return(I3FileUtil.MoveFile(tmpRarFile, destFileName, true));
                }
                #endregion
            }
            finally
            {
                #region  除临时文件
                I3DirectoryUtil.DeleteDirctory(tmpDir);
                #endregion
            }
        }
Ejemplo n.º 2
0
        public DateTime GetTime(string Big, string Small, DateTime Default)
        {
            string s = GetString(Big, Small, I3DateTimeUtil.ConvertDateTimeToDateTimeString(Default));

            try
            {
                return(I3DateTimeUtil.ConvertStringToDateTime(s));
            }
            catch (Exception)
            {
                return(Default);
            }
        }
Ejemplo n.º 3
0
        public static DateTime GetDateTime(string key)
        {
            string   tmp = GetString(key);
            DateTime result;

            try
            {
                result = I3DateTimeUtil.ConvertStringToDateTime(tmp);
            }
            catch
            {
                throw new InvalidCastException(string.Format("读取配置{0}时出错错误,值{1}不是一个DateTime。\r\n其格式必须类似于 2001-01-01 12:00:00", key, tmp));
            }
            return(result);
        }
Ejemplo n.º 4
0
 public static void Set(string key, object value)
 {
     if (value == null)
     {
         throw new ArgumentNullException(string.Format("设置配置{0}的值时出现错误,值不能为null", key));
     }
     if (value is DateTime)
     {
         Set(key, I3DateTimeUtil.ConvertDateTimeToDateTimeString((DateTime)value));
     }
     else
     {
         Set(key, value.ToString());
     }
 }
Ejemplo n.º 5
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Mode.ToString());
            sb.Append("\r\n");
            sb.Append(BeginChecked.ToString());
            sb.Append("\r\n");
            sb.Append(EndChecked.ToString());
            sb.Append("\r\n");
            sb.Append(I3DateTimeUtil.ConvertDateTimeToDateString(Begin));
            sb.Append("\r\n");
            sb.Append(I3DateTimeUtil.ConvertDateTimeToDateString(End));

            return(sb.ToString());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据设置刷新结果
        /// </summary>
        public void RefreshResult()
        {
            switch (fieldType)
            {
            case I3SearchItemType.sitString:
                switch (searchType)
                {
                case I3SearchType.stNone:
                    lookString   = "";
                    searchString = "";
                    break;

                case I3SearchType.stEqual:
                    lookString   = fieldCaption + " 等于 " + String1;
                    searchString = fieldName + " = " + I3DBUtil.QuotedStr(string1);
                    break;

                case I3SearchType.stDim:
                    lookString   = fieldCaption + " 包含 " + String1;
                    searchString = fieldName + " like " + I3DBUtil.QuotedStr("%" + string1 + "%");
                    break;

                case I3SearchType.stInterval:
                    lookString   = "";
                    searchString = "";
                    break;

                default:
                    lookString   = "";
                    searchString = "";
                    break;
                }
                break;

            case I3SearchItemType.sitNum:
                switch (SearchType)
                {
                case I3SearchType.stNone:
                    lookString   = "";
                    searchString = "";
                    break;

                case I3SearchType.stEqual:
                    lookString   = fieldCaption + " 等于 " + num1.ToString();
                    searchString = fieldName + " = " + num1.ToString();
                    break;

                case I3SearchType.stDim:
                    lookString   = "";
                    searchString = "";
                    break;

                case I3SearchType.stInterval:
                    lookString   = fieldCaption + "在" + num1.ToString() + "和" + num2.ToString() + "之间";
                    searchString = "(" + fieldName + " >= " + num1.ToString()
                                   + " and " + fieldName + " <= " + num2.ToString() + ")";
                    break;

                default:
                    lookString   = "";
                    searchString = "";
                    break;
                }
                break;

            case I3SearchItemType.sitDate:
                switch (SearchType)
                {
                case I3SearchType.stNone:
                    lookString   = "";
                    searchString = "";
                    break;

                case I3SearchType.stEqual:
                    lookString   = fieldCaption + " 等于 " + I3DateTimeUtil.ConvertDateTimeToDateString(date1);
                    searchString = " Convert(char(10)," + fieldName + ",126) = "
                                   + I3DBUtil.QuotedStr(I3DateTimeUtil.ConvertDateTimeToDateString(date1));
                    break;

                case I3SearchType.stDim:
                    lookString   = "";
                    searchString = "";
                    break;

                case I3SearchType.stInterval:
                    lookString = fieldCaption + "在" + I3DateTimeUtil.ConvertDateTimeToDateString(date1)
                                 + "和" + I3DateTimeUtil.ConvertDateTimeToDateString(date2) + "之间";
                    searchString = " Convert(char(10)," + fieldName + ",126) between "
                                   + I3DBUtil.QuotedStr(I3DateTimeUtil.ConvertDateTimeToDateString(date1))
                                   + " and "
                                   + I3DBUtil.QuotedStr(I3DateTimeUtil.ConvertDateTimeToDateString(date2));
                    break;

                default:
                    lookString   = "";
                    searchString = "";
                    break;
                }
                break;

            default:
                lookString   = "";
                searchString = "";
                break;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 根据fileInfoList的设置,生成新的压缩包文件
        ///
        /// 错误处理:IEFS_Error.LastErrorMessage
        ///
        /// </summary>
        /// <returns></returns>
        public I3MsgInfo Flush()
        {
            #region 定义变量
            string          message;
            ZipOutputStream outputStream     = null;
            int             addFileCount     = GetAddFileCount() + GetNormalFileCount();
            long            totalAddFileSize = GetTotalAddFileSize() + GetTotalNormalFileSize(); //所有需要压缩的文件的字节数
            long            passFileSize     = 0;                                                //已经压缩的文件的字节数
            long            totalPosition    = 0;                                                //总共压缩到的字节数
            #endregion

            #region 检查临时文件与临时目录
            string tmpFile = fileName + ".tmpsharpzip";
            if (!I3FileUtil.CheckFileNotExists(tmpFile))
            {
                return(new I3MsgInfo(false, ""));
            }
            string    tmpDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, I3DateTimeUtil.ConvertDateTimeToLongString(DateTime.Now));
            I3MsgInfo msg    = I3DirectoryUtil.CheckAndClearDirctory(tmpDir);
            if (!msg.State)
            {
                return(msg);
            }
            #endregion

            try
            {
                #region 解压所有不需要替换或者删除的文件到临时目录
                msg = UnCompressAllFile(tmpDir, true);
                if (!msg.State)
                {
                    return(msg);
                }
                #endregion

                #region 开始压缩状态为normal、New、Change三种状态的文件到临时文件中
                try
                {
                    #region 压缩
                    outputStream = new ZipOutputStream(File.Create(tmpFile));
                    outputStream.SetLevel(zipLevel);
                    if (!string.IsNullOrEmpty(passWord))
                    {
                        outputStream.Password = passWord;
                    }

                    int fileindex = 0;
                    foreach (I3SharpZipFileInfo info in fileInfoList)
                    {
                        #region 判断文件是否要参与压缩
                        if (info.Mode == I3SZFileInfoMode.szimDelete)
                        {
                            continue;
                        }
                        #endregion

                        #region 发送文件个数进度信息
                        message = "正在压缩文件\"" + info.FileName + "\"";
                        fileindex++;
                        OnMutiFileProcessReport(addFileCount, fileindex, message);
                        #endregion

                        #region 写入ZipEntry
                        //outputStream.PutNextEntry(GetEntry(info.FileName, info.FullName));
                        //自己在ZipEntry中写入CRC信息,读取时会报Eof of Header的错误
                        //在网上查找资料后发现,新版SharpZip.dll已经更改,不再需要自己写入CRC等信息
                        outputStream.PutNextEntry(new ZipEntry(info.FileName));
                        info.Mode = I3SZFileInfoMode.szimNormal;
                        if (info.FileSize == 0)
                        {
                            continue;
                        }
                        #endregion

                        FileStream sourceFileStream = null;
                        try
                        {
                            #region 将文件写入压缩流
                            sourceFileStream          = File.OpenRead(info.FullName);
                            sourceFileStream.Position = 0;
                            //IEFS_Stream.WriteStreamToStream(null, sourceFileStream, outputStream, blockSize, null);
                            byte[] data     = new byte[blockSize];
                            long   longsize = 0;
                            while (true)
                            {
                                int size = sourceFileStream.Read(data, 0, data.Length);
                                if (size > 0)
                                {
                                    outputStream.Write(data, 0, size);
                                    longsize += size;
                                    OnSingleFileProcessReport(info.FileSize, longsize, message);
                                    totalPosition = passFileSize + longsize;
                                    OnTotalBytesProcessReport(totalAddFileSize, totalPosition, message);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            passFileSize += longsize;
                            #endregion
                        }
                        finally
                        {
                            #region 释放单个文件的文件流
                            if (sourceFileStream != null)
                            {
                                sourceFileStream.Close();
                            }
                            #endregion
                        }
                    }
                    #endregion
                }
                #region 错误处理
                catch (Exception ex)
                {
                    return(new I3MsgInfo(false, ex.Message, ex));
                }
                #endregion
                #region 释放变量  删除临时目录
                finally
                {
                    if (outputStream != null)
                    {
                        outputStream.Finish();
                        outputStream.Close();
                    }
                    I3DirectoryUtil.DeleteDirctory(tmpDir);
                }
                #endregion
                #endregion

                #region 替换原始文件
                if (!I3FileUtil.CheckFileNotExists(fileName))
                {
                    return(new I3MsgInfo(false, ""));
                }
                return(I3FileUtil.MoveFile(tmpFile, fileName, true));

                #endregion
            }
            finally
            {
                I3DirectoryUtil.DeleteDirctory(tmpDir);
                I3FileUtil.CheckFileNotExists(tmpFile);
            }
        }
Ejemplo n.º 8
0
        public static DateTime ReadDateTimeFromStream(Stream aStream)
        {
            string aStr = I3Stream.ReadStringFromStream(aStream);

            return(I3DateTimeUtil.ConvertStringToDateTime(aStr));
        }
Ejemplo n.º 9
0
        public static void WriteDateTimeToStream(DateTime aDateTime, Stream aStream)
        {
            string aStr = I3DateTimeUtil.ConvertDateTimeToDateTimeString(aDateTime);

            I3Stream.WriteStringToStream(aStr, aStream);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 从一个被压缩的数据集文件中加载数据集
        /// </summary>
        /// <param name="sourceFileName"></param>
        /// <param name="dataSet"></param>
        /// <param name="unCry"></param>
        /// <param name="unCryKey"></param>
        /// <returns></returns>
        public I3MsgInfo UnCompressADataSet(string sourceFileName, DataSet dataSet, bool unCry, string unCryKey)
        {
            #region 初始化临时文件变量
            string tmpDir         = I3DirectoryUtil.GetAppTmpTmpDir();
            string tmpDataSetFile = Path.Combine(tmpDir, "DataSet.tmp");
            string tmpRarFile     = Path.Combine(tmpDir, I3DateTimeUtil.ConvertDateTimeToLongString(DateTime.Now) + ".tmp");
            if ((!I3DirectoryUtil.CreateDirctory(tmpDir).State) || (!I3FileUtil.CheckFileNotExists(tmpDataSetFile)) || (!I3FileUtil.CheckFileNotExists(tmpRarFile)))
            {
                return(new I3MsgInfo(false, ""));
            }
            #endregion

            I3MsgInfo msg;
            try
            {
                #region 解密到临时压缩文件
                if (unCry)
                {
                    msg = I3RijnDaelCry.UnCryFile(sourceFileName, tmpRarFile, unCryKey);
                    if (!msg.State)
                    {
                        return(msg);
                    }
                }
                else
                {
                    msg = I3FileUtil.MoveFile(sourceFileName, tmpRarFile, false);
                    if (!msg.State)
                    {
                        return(msg);
                    }
                }
                if (!File.Exists(tmpRarFile))
                {
                    return(new I3MsgInfo(false, "文件解密到临时压缩文件失败!文件名:" + tmpRarFile));
                }
                #endregion

                #region 解压缩到临时数据集文件
                msg = this.UnCompressASingleFile(tmpRarFile, "DataSet.tmp", tmpDataSetFile);
                if (!msg.State)
                {
                    return(msg);
                }
                if (!File.Exists(tmpDataSetFile))
                {
                    return(new I3MsgInfo(false, "临时压缩文件解压到临时数据集文件失败!文件名:" + tmpDataSetFile));
                }
                #endregion

                #region 从临时数据集文件加载
                try
                {
                    dataSet.ReadXml(tmpDataSetFile);
                    return(I3MsgInfo.Default);
                }
                catch (Exception ex)
                {
                    return(new I3MsgInfo(false, "从临时数据集文件加载数据集失败!错误信息:" + ex.Message, ex));
                }
                #endregion
            }
            finally
            {
                #region  除临时文件
                I3DirectoryUtil.DeleteDirctory(tmpDir);
                #endregion
            }
        }
Ejemplo n.º 11
0
 public void SetTime(string Big, string Small, DateTime Value)
 {
     SetString(Big, Small, I3DateTimeUtil.ConvertDateTimeToDateTimeString(Value));
 }