public override void Export2TradeTable(DbDataReader reader, IExportCallback callback, IExport2TradeTable tradeService)
        {
            if (reader == null)
                return;
            TradeTable tradeTable = new TradeTable();
            if (!tradeTable.Open())
                return;

            OrderRowService_LH lhService = new OrderRowService_LH(this.TheProject);
            if (!lhService.Open())
            {
                tradeTable.Close();
                this.ImportState = EImportStatus.Exception;
                this.TheProject.Output.WriteLine("量化平台数据库打开失败!");
                return;
            }

            ProjectInfoService_LH projInfoService = new ProjectInfoService_LH();
            projInfoService.DB = lhService;
            List<ProjectInfo_LH> projInfos = projInfoService.GetProjectInfos(true);

            bool bufferAll_lh = false;
            List<OrderRow_LH> buffer_lh = null;
            List<OrderRow_LH> lhDataList = null;
            string securityId = string.Empty;

            lhService.SyncImportState2Local();
            if (lhService.TotalCount < this.MaxBufferSize)
            {
                bufferAll_lh = true;
                buffer_lh = lhService.GetTradeItems(EMarketType.ALL);
            }

            while (reader.Read())
            {
                if (this.TheProject.HasStop)
                {
                    tradeService.ImportState = EImportStatus.Interrupt;
                    break;
                }

                TradeInfo_O32 row = this.GetTradeInfo(reader);
                // 过滤掉无效的zmdm
                ProjectInfo_LH projInfo = projInfos.Where(o => o.Zmdm.ToString() == row.VC_COMBI_NO).FirstOrDefault();
                if (projInfo == null)
                {
                    callback.CurrentIndex++;
                    continue;
                }

                string interCode = row.VC_REPORT_CODE;
                if (securityId != interCode)
                {
                    securityId = interCode;
                    if (bufferAll_lh)
                        lhDataList = buffer_lh.Where(o => o.zqdm.Equals(interCode)).ToList();   // 从内存中筛选,速度快
                    else
                        lhDataList = lhService.GetTradeItems(interCode, EMarketType.ALL);  // 直接从数据库查询,比较耗时
                }

                if (lhDataList.Where(o => o.zmdm.ToString() == row.VC_COMBI_NO).FirstOrDefault() == null)
                {
                    TradeRow tradeInfo = this.GetTradeRow(row);
                    tradeInfo.Xmdm = projInfo.Zmdm;
                    tradeTable.Add(tradeInfo);
                    callback.ValidIndex++;
                }

                callback.CurrentIndex++;
            }

            lhService.Close();
            tradeTable.Close();
        }
Example #2
0
        /// <summary>
        /// 将数据导出到成交表(TradeTable)中。
        /// </summary>
        public virtual void Export2TradeTable(DbDataReader reader, IExportCallback callback, IExport2TradeTable tradeService)
        {
            if (reader == null)
                return;
            TradeTable tradeTable = new TradeTable();
            if (!tradeTable.Open())
                return;

            while (reader.Read())
            {
                if (this.TheProject.HasStop)
                {
                    tradeService.ImportState = EImportStatus.Interrupt;
                    break;
                }

                TradeRow data = tradeService.GetTradeRow(reader);
                tradeTable.Add(data);
                callback.CurrentIndex++;
                callback.ValidIndex++;
            }

            tradeTable.Close();
        }
        protected void Export2OrderAndTradeTable(DbDataReader reader, IExportCallback callBack)
        {
            OrderTable orderTable = new OrderTable();
            TradeTable tradeTable = new TradeTable();
            if (!orderTable.Open() || !tradeTable.Open())
            {
                orderTable.Close();
                tradeTable.Close();

                return;
            }

            while (reader.Read())
            {
                if (this.TheProject.HasStop)
                {
                    this.ImportState = EImportStatus.Interrupt;
                    break;
                }

                OrderRow_LH row = this.GetOrderRow_LH(reader as SqlDataReader);
                orderTable.Add(this.GetOrderRow(row));

                // 成交信息
                if (row.CjNum > 0)
                {
                    tradeTable.Add(GetTradeRow(row));
                    callBack.ValidIndex++;
                }

                callBack.CurrentIndex++;
            }

            orderTable.Close();
            tradeTable.Close();
        }