/// <summary>
        /// 解包详细文件
        /// 0.通过文件名【140619\222158.DAT】检查是否解包过,如果已经解包过那么跳过不处理。
        /// 1.检查文件格式是否正确,不正确跳过不处理。
        /// 2.检查Sn是否一致,不是该设备的跳过不处理。
        /// 3.解析详细文件的文件头
        /// 4.解析详细内容
        /// 5.检查详细文件是否跨越中午12点,半夜12点,如果跨越则将文件拆分成多个详细文件,
        /// 5.将处理后的【ProductRuningSummaryData】和【ProductRuningDetailedData】存入数据库(1-n条)
        /// 单水平(CPAP、APAP)和双水品(BPAP)数据部分不一样,都在此处做内部处理和区分。
        /// </summary>
        /// <returns></returns>
        public IEnumerable<NeedUpDateTherapyMode> StartUnpackAndSaveToDataBase()
        {
            // 文件不存在,直接返回
            if (!File.Exists(detailedFileFullName))
            {
                //LogHelper.Info("FileNotFound:" + detailedFileFullName);
                return null;
            }
            IList<SummaryAndDetailed> listSummaryAndDetailed = new List<SummaryAndDetailed>();

            using (var fileStream = new FileStream(detailedFileFullName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                #region 0.通过文件名【140619\222158.DAT】检查是否解包过,如果已经解包过那么跳过不处理。

                var detailedFilePath = detailedFileFullName.Substring(detailedFileFullName.Length - 17, 17);
                var productWorkingSummaryDataBLL = new ProductWorkingSummaryDataBLL();
                //Expression<Func<ProductWorkingSummaryData, bool>> condition =
                //    t => t.ProductId == indexFileField.ProductId && t.FileName == detailedFilePath;
                //var listProductRuningSummaryDatas = productWorkingSummaryDataBLL.GetByCondition(condition);
                var listProductRuningSummaryDatas = productWorkingSummaryDataBLL.SelectByProductIdFileName(indexFileField.ProductId, detailedFilePath);
                productWorkingSummaryDataBLL.Dispose();
                productWorkingSummaryDataBLL = null;
                if (listProductRuningSummaryDatas != null && listProductRuningSummaryDatas.Count() > 0)
                {
                    //解包过
                    listProductRuningSummaryDatas = null;
                    //LogHelper.Info("Allread Unpacked:" + detailedFileFullName);
                    return null;
                }

                #endregion

                #region  1.检查文件格式是否正确,不正确跳过不处理。 检验文件是否合法(文件大小、文件头)

                //检验文件是否合法,(头512字节 第一组数据20字节)位置是第一组数据结尾,如果没有数据那么不处理
                if (fileStream.Length < 532)
                {
                    //LogHelper.Info("File Length too short:" + detailedFileFullName);
                    return null;
                }
                readBytes = null;
                readBytes = new byte[6]; //Sy_RMS同步字
                fileStream.Read(readBytes, 0, 6);
                if (Encoding.ASCII.GetString(readBytes) != "Sy_RMS")
                {
                    //LogHelper.Info("File Header Sy_RMS Missed:" + detailedFileFullName);
                    return null;
                }

                #endregion

                #region 2.检查Sn是否一致,不是该设备的跳过不处理。

                //fileStream.Seek(6, SeekOrigin.Begin);//读取开始位置跳过同步字0-5
                readBytes = null;
                readBytes = new byte[9];
                fileStream.Read(readBytes, 0, 9);
                var Sn = readBytes.ToHexString();
                if (Sn != indexFileField.SerialNumber)
                {
                    //不是此设备的数据,不处理
                    Sn = null;
                    //LogHelper.Info("File Sn Different:" + detailedFileFullName);
                    return null;
                }
                Sn = null;

                #endregion

                #region 3.解析详细文件的文件头

                productWorkingSummaryData = new ProductWorkingSummaryData();
                productWorkingSummaryData.Id = DateTime.Now.ToGuid();
                productWorkingSummaryData.ProductId = indexFileField.ProductId;
                productWorkingSummaryData.FileName = detailedFilePath;
                detailedFilePath = null;

                #region 型号 模式

                //------------------------------------------------------------
                fileStream.Seek(15, SeekOrigin.Begin); //读取开始位置 产品型号
                readBytes = null;
                readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                indexFileField.ProductModel = readBytes[0]; //TODO设置产品型号,还没有更新到数据库
                productWorkingSummaryData.ProductModel = readBytes[0];
                productWorkingSummaryData.ProductVersion = indexFileField.ProductVersion; //产品版本

                //------------------------------------------------------------

                //当前时间	0x20,0x11,0x12,0x05,0x13,0x25,0x45	2011-12-5 13:25:45 BCD码:年月日时分秒
                //保存年月日到timeBytes,在解析详细包的时候只有时分秒
                fileStream.Seek(16, SeekOrigin.Begin); //读取开始位置跳
                readBytes = null;
                readBytes = new byte[7];
                fileStream.Read(readBytes, 0, 7);
                productWorkingSummaryData.CurrentTime = DateTime.ParseExact(readBytes.ToHexString(), "yyyyMMddHHmmss",
                    CultureInfo.CurrentCulture);

                fileStream.Seek(16, SeekOrigin.Begin); //读取开始位置跳
                fileStream.Read(timeBytes, 0, 4);

                //------------------------------------------------------------
                fileStream.Seek(23, SeekOrigin.Begin); //读取开始位置跳
                readBytes = null;
                readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);

                productWorkingSummaryData.TherapyMode = readBytes[0];
                //== 0 ? "S/T" : ((DrivicesMode)readBytes[0]).ToString();
                //下面需要根据治疗模式解析详细
                var CurrentMode = readBytes[0];

                #endregion

                #region 报警 通用

                //------------------------------------------------------------
                fileStream.Seek(38, SeekOrigin.Begin); //读取开始位置  报警总开关
                //readBytes = null;
                //readBytes = new byte[1];

                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Alert = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(38, SeekOrigin.Begin);//读取开始位置  报警--面罩
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Alert_Tube = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(38, SeekOrigin.Begin);//读取开始位置  报警--窒息
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Alert_Apnea = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(38, SeekOrigin.Begin);//读取开始位置  报警--分钟通气量报警
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Alert_MinuteVentilation = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(38, SeekOrigin.Begin);//读取开始位置  报警--高呼吸频率报警
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Alert_HRate = readBytes[0];
                //------------------------------------------------------------
                //fs.Seek(38, SeekOrigin.Begin);//读取开始位置  报警--低呼吸频率报警
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Alert_LRate = readBytes[0];

                #endregion

                #region 配置 通用

                //------------------------------------------------------------
                fileStream.Seek(48, SeekOrigin.Begin); //读取开始位置  配置--湿化器档位
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_HumidifierLevel = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(48, SeekOrigin.Begin);//读取开始位置  配置--数据保存
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_DataStore = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(48, SeekOrigin.Begin);//读取开始位置  配置--智能启动
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_SmartStart = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(48, SeekOrigin.Begin);//读取开始位置  配置--压力单位
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_PressureUnit = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(48, SeekOrigin.Begin);//读取开始位置  配置--界面语言
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_Language = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(48, SeekOrigin.Begin);//读取开始位置  配置--背光模式
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_Backlight = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(48, SeekOrigin.Begin);//读取开始位置  配置--面罩压力
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_MaskPressure = readBytes[0];

                //------------------------------------------------------------
                //fs.Seek(48, SeekOrigin.Begin);//读取开始位置  配置--临床设置
                //readBytes = null;
                //readBytes = new byte[1];
                fileStream.Read(readBytes, 0, 1);
                productWorkingSummaryData.Config_ClinicalSet = readBytes[0];

                #endregion

                #region 模式不同,数据不同 需要单独解析和统计 扩展点

                #region 24-37字节的数据不一样

                // 0x00:S/T
                // 0x01:T
                // 0x02:S
                // 0x03:CPAP
                // 0x04:APAP
                // 0x05:PCV
                // 0x06:AutoS
                switch (CurrentMode)
                {
                    case 0x00: //S/T
                    case 0x05: //PCV

                        #region 24-37字节的数据不一样

                        //24-37字节的数据不一样------------------------------------------------------------
                        fileStream.Seek(24, SeekOrigin.Begin); //读取开始位置 IPAP(2)
                        readBytes = null;
                        readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.IPAP = readBytes.BytesToInt16(0) * 0.1f; //Kpa0.01 cmH2O 0.1

                        //------------------------------------------------------------
                        ////读取开始位置 EPAP(2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.EPAP = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        //------------------------------------------------------------
                        //读取开始位置 上升时间(1)
                        readBytes = null;
                        readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.RiseTime = readBytes[0]; //分钟

                        //------------------------------------------------------------
                        //读取开始位置 呼吸频率(1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.RespiratoryRate = readBytes[0]; //breaths/min

                        //------------------------------------------------------------
                        //读取开始位置 吸气时间((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.InspireTime = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 吸气灵敏度((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.ITrigger = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 呼气灵敏度((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.ETrigger = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 延时升压(1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.Ramp = readBytes[0];

                        #endregion

                        break;
                    case 0x01: //T

                        #region 24-37字节的数据不一样

                        //24-37字节的数据不一样------------------------------------------------------------
                        fileStream.Seek(24, SeekOrigin.Begin); //读取开始位置 IPAP(2)
                        readBytes = null;
                        readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.IPAP = readBytes.BytesToInt16(0) * 0.1f; //Kpa0.01 cmH2O 0.1

                        //------------------------------------------------------------
                        ////读取开始位置 EPAP(2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.EPAP = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        //------------------------------------------------------------
                        //读取开始位置 上升时间(1)
                        readBytes = null;
                        readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.RiseTime = readBytes[0]; //分钟

                        //------------------------------------------------------------
                        //读取开始位置 呼吸频率(1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.RespiratoryRate = readBytes[0]; //breaths/min

                        //------------------------------------------------------------
                        //读取开始位置 吸气时间((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.InspireTime = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 呼气时间((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.ExhaleTime = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 延时升压Ramp((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.Ramp = readBytes[0];

                        #endregion

                        break;
                    case 0x02: //S

                        #region 24-37字节的数据不一样

                        //24-37字节的数据不一样------------------------------------------------------------
                        fileStream.Seek(24, SeekOrigin.Begin); //读取开始位置 IPAP(2)
                        readBytes = null;
                        readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.IPAP = readBytes.BytesToInt16(0) * 0.1f; //Kpa0.01 cmH2O 0.1

                        //------------------------------------------------------------
                        ////读取开始位置 EPAP(2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.EPAP = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        //------------------------------------------------------------
                        //读取开始位置 上升时间(1)
                        readBytes = null;
                        readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.RiseTime = readBytes[0]; //分钟

                        //------------------------------------------------------------
                        //读取开始位置 吸气灵敏度((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.ITrigger = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 呼气灵敏度((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.ETrigger = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 延时升压Ramp((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.Ramp = readBytes[0];

                        #endregion

                        break;
                    case 0x03: //CPAP APAP 详细部分相同

                        #region 24-37字节的数据不一样

                        //24-37字节的数据不一样------------------------------------------------------------
                        fileStream.Seek(24, SeekOrigin.Begin); //读取开始位置 CPAP(2)
                        readBytes = null;
                        readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.CPAP = readBytes.BytesToInt16(0) * 0.1f; //Kpa0.01 cmH2O 0.1

                        //------------------------------------------------------------
                        //f读取开始位置 压力延迟(1)
                        readBytes = null;
                        readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.Ramp = readBytes[0]; //分钟

                        //------------------------------------------------------------
                        //读取开始位置  舒适程度(1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.CFlex = readBytes[0];

                        #endregion

                        break;
                    case 0x04: //APAP

                        #region 24-37字节的数据不一样

                        //24-37字节的数据不一样------------------------------------------------------------
                        fileStream.Seek(24, SeekOrigin.Begin); //读取开始位置 APAPStart(2)
                        readBytes = null;
                        readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.CPAPStart = readBytes.BytesToInt16(0) * 0.1f; //Kpa0.01 cmH2O 0.1

                        ////读取开始位置 APAPMax (2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.CPAPMax = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        ////读取开始位置 APAPMax (2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.CPAPMin = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        //------------------------------------------------------------
                        //fs.Seek(24, SeekOrigin.Begin);//读取开始位置 压力延迟(1)
                        readBytes = null;
                        readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.Ramp = readBytes[0]; //分钟

                        //------------------------------------------------------------
                        //fs.Seek(24, SeekOrigin.Begin);//读取开始位置  舒适程度(1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.CFlex = readBytes[0];

                        #endregion

                        break;
                    case 0x06: //AutoS

                        #region 24-37字节的数据不一样

                        //24-37字节的数据不一样------------------------------------------------------------
                        fileStream.Seek(24, SeekOrigin.Begin); //读取开始位置 IPAPMax(2)
                        readBytes = null;
                        readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.IPAPMax = readBytes.BytesToInt16(0) * 0.1f; //Kpa0.01 cmH2O 0.1

                        //------------------------------------------------------------
                        ////读取开始位置 EPAPMin(2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.EPAPMin = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        //------------------------------------------------------------
                        //读取开始位置 PS Max(2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.PSMax = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        //------------------------------------------------------------
                        //读取开始位置 PS Min (2)
                        //readBytes = null;
                        //readBytes = new byte[2];
                        fileStream.Read(readBytes, 0, 2);
                        productWorkingSummaryData.PSMin = readBytes.BytesToInt16(0) * 0.1f; //Kpa

                        //------------------------------------------------------------
                        //读取开始位置 RiseTime((1)
                        readBytes = null;
                        readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.RiseTime = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 吸气灵敏度((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.ITrigger = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 呼气灵敏度((1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.ETrigger = readBytes[0];

                        //------------------------------------------------------------
                        //读取开始位置 延时升压(1)
                        //readBytes = null;
                        //readBytes = new byte[1];
                        fileStream.Read(readBytes, 0, 1);
                        productWorkingSummaryData.Ramp = readBytes[0];

                        #endregion

                        break;
                }

                #endregion

                #region 处理详细 详细数据 512之后的数据验证和存入数据库

                //处理详细
                //var tmpDetailedBytes = GetDetailedBytesArrayData(fileStream, 0x3B);
                var tmpDetailedBytes = GetDetailedBytesArrayData(fileStream);
                if (tmpDetailedBytes == null || tmpDetailedBytes.Count < 1)
                {
                    return null;
                }

                IList<ICollection<byte[]>> listSplit = new Collection<ICollection<byte[]>>();

                #region 数据分割 分割12点和0点的数据

                //分一下几种情况
                //1.正常数据不包含 0点和12点的数据 不需要分割
                //2.跨越中午12点的数据-年月日不变-开始位置不是12点,中间有12点
                //3.中午12点开始的数据-年月日不变-开始位置是12点,中间不含0点
                //4.跨午夜0点的数据-年月日变化-开始位置不是0点,中间有0点
                //5.午夜0点开始的数据-年月日不变-开始位置是0点,中间不含12点

                #endregion

                var doWhile = true;
                //分割12点和0点的数据,TODO
                while (doWhile)
                {
                    var hourIndex12 = tmpDetailedBytes.FindIndex(t => t[0] == 12);
                    var hourIndex24 = tmpDetailedBytes.FindIndex(t => t[0] == 0);
                    if (hourIndex12 > 0)
                    {
                        //有分割,得到 分割位置 年月日不变
                        var currentList = tmpDetailedBytes.GetRange(0, hourIndex12);
                        listSplit.Add(currentList);
                        tmpDetailedBytes = tmpDetailedBytes.GetRange(hourIndex12, tmpDetailedBytes.Count - hourIndex12);
                        doWhile = true;
                    }
                    else if (hourIndex24 > 0)
                    {
                        //有分割,得到 分割位置 年月日变化
                        var currentList = tmpDetailedBytes.GetRange(0, hourIndex24);
                        listSplit.Add(currentList);
                        tmpDetailedBytes = tmpDetailedBytes.GetRange(hourIndex24, tmpDetailedBytes.Count - hourIndex24);
                        isChangeDate = true;
                        doWhile = true;
                    }
                    else //正常年月日时间不变
                    {
                        listSplit.Add(tmpDetailedBytes);
                        doWhile = false;
                    }
                }

                //如果大于2段则无法确定后面的时间,所以出错
                if (listSplit.Count > 2)
                {
                    //LogHelper.Info("File Split Over Ranger " + listSplit.Count + ":" + detailedFileFullName);
                    return null;
                }

                //分割之后 将 summary 和各段的对应起来
                for (var i = 0; i < listSplit.Count; i++)
                {
                    var newProductWorkingSummaryData = (ProductWorkingSummaryData)productWorkingSummaryData.Clone();
                    newProductWorkingSummaryData.Id = DateTime.Now.ToGuid();
                    listSummaryAndDetailed.Add(new SummaryAndDetailed(newProductWorkingSummaryData,
                        listSplit[i].ToList()));
                }
                //处理分段之后的内容
                for (var i = 0; i < listSummaryAndDetailed.Count(); i++)
                {
                    var listDetailed = getDetailedData(listSummaryAndDetailed[i].ProductWorkingSummaryData,
                        listSummaryAndDetailed[i].DetailedList);
                    SaveToBD(listSummaryAndDetailed[i].ProductWorkingSummaryData, listDetailed);
                }

                #endregion

                #endregion

                #endregion
            } //endusing

            //得到数据的日期
            var result = from a in listSummaryAndDetailed
                         select new NeedUpDateTherapyMode
                             (a.ProductWorkingSummaryData.StartTime, a.ProductWorkingSummaryData.TherapyMode);
            return result;
        }
 /// <summary>
 /// 通用方法,将概要数据和详细数据保存到数据库
 /// </summary>
 /// <param name="productWorkingSummaryData"></param>
 /// <param name="detailedList"></param>
 private void SaveToBD(ProductWorkingSummaryData productWorkingSummaryData,
     IEnumerable<DetailedField> detailedList)
 {
     //using (var transactionScope = new TransactionScope())
     //{
     using (var productWorkingSummaryDataBLL = new ProductWorkingSummaryDataBLL())
     {
         productWorkingSummaryDataBLL.Insert(productWorkingSummaryData);
         using (var memoryStream = new MemoryStream())
         {
             Serializer.Serialize(memoryStream, detailedList);
             using (var productWorkingDetailedDataBLL = new ProductWorkingDetailedDataBLL())
             {
                 var productWorkingDetailedData = new ProductWorkingDetailedData();
                 productWorkingDetailedData.Id = DateTime.Now.ToGuid();
                 productWorkingDetailedData.ProductWorkingSummaryDataId = productWorkingSummaryData.Id;
                 productWorkingDetailedData.Content = memoryStream.ToArray();
                 productWorkingDetailedDataBLL.Insert(productWorkingDetailedData);
             }
             memoryStream.Close();
         }
     }
     //transactionScope.Complete();
     //}
 }