コード例 #1
0
ファイル: GLClassUpdater.cs プロジェクト: samuelyi/PK10Tracer
        string UpdateHQData(JRGCDBClass jgdb, DataRow tdr, DateTime EndT)
        {
            DataTable dt = tdr.Table.Clone();
            //DataTable DBdt = new DataTable();
            //DBdt.Columns.Add("SectorCode");
            //DBdt.Columns.Add("HQDate");
            //DBdt.Columns.Add("POpen");
            //DBdt.Columns.Add("PHigh");
            //DBdt.Columns.Add("PClose");
            //DBdt.Columns.Add("PLow");
            //DBdt.Columns.Add("Zf");
            //DBdt.Columns.Add("Volume");
            string   GLCode    = tdr["SectorCode"].ToString();
            string   GLName    = tdr["SectorName"].ToString();
            DateTime LunchDate = (DateTime)tdr["SectorCreateDate"];
            DateTime HQDate    = LunchDate;

            if (tdr["HQModifyDate"] != null)
            {
                DateTime tDate;
                if (DateTime.TryParse(tdr["HQModifyDate"].ToString(), out tDate))
                {
                    HQDate = tDate;
                }
            }
            GLClassProcess glcp = new GLClassProcess();
            DateTime       BegT = HQDate;
            DataTable      WDtb = glcp.getHQData(GLCode, BegT, EndT);

            if (WDtb == null)
            {
                throw (new Exception("无法从万得获取到数据!"));
            }
            CheckPin = string.Format("概念{0}:{1}获取到行情数据{2}条!", GLCode, GLName, (WDtb == null ? 0 : WDtb.Rows.Count));
            DataRow[] drs    = WDtb.Select("VOLUME is not null", "DateTime");
            DataTable savetb = WDtb.Clone();

            for (int i = 0; i < drs.Length; i++)
            {
                savetb.Rows.Add(drs[i].ItemArray);
            }
            savetb.Columns["WINDCODE"].ColumnName = "SectorCode";
            savetb.Columns["DateTime"].ColumnName = "HQDate";
            savetb.Columns["OPEN"].ColumnName     = "POpen";
            savetb.Columns["HIGH"].ColumnName     = "PHigh";
            savetb.Columns["CLOSE"].ColumnName    = "PClose";
            savetb.Columns["LOW"].ColumnName      = "PLow";
            //savetb.Columns["PCT_CHG"].ColumnName = "Zf";
            savetb.Columns["VOLUME"].ColumnName = "Volume";
            string       sql = string.Format("select * from SectorHQTable where SectorCode='{0}' and HQDate between '{1}' and '{2}'", GLCode, BegT, EndT);
            SaveDataTask sdt = new SaveDataTask();

            this.SaveDataPool.Add(sdt);
            sdt.Sqls = new string[] { "", "" };
            DataSet ds = new DataSet();

            ds.Tables.Add(savetb);
            sdt.Data    = ds;
            sdt.Sqls[0] = sql;
            CheckPin    = string.Format("概念{0}:{1}已提交数据保存程序执行。最后日期{2}!", GLCode, GLName, EndT.ToShortDateString());

            return(null);

            //this.SaveDataPool.Add(sdt);
            sql = string.Format("select * from SectorTable where SectorCode='{0}'", GLCode, BegT, EndT);
            tdr["HQModifyDate"] = EndT;
            if (savetb != null && savetb.Rows.Count > 0)
            {
                tdr["HQStartDate"] = savetb.Rows[0]["HQDate"];
            }
            dt.Rows.Add(tdr.ItemArray);
            if (dt.Rows.Count > 1)
            {
                throw (new Exception("概念信息重复!"));
            }
            ds.Tables.Add(dt);
            sdt.Sqls[1] = sql;

            //update sectortable set hqmodifydate = sectorcreatedate
            CheckPin = string.Format("概念{0}:{1}已提交数据保存程序执行。最后日期{2}!", GLCode, GLName, EndT.ToShortDateString());
            dt       = null;
            return(null);
        }
コード例 #2
0
ファイル: GLClassUpdater.cs プロジェクト: samuelyi/PK10Tracer
        /// <summary>
        /// 更新概念指数的历史成分股变动日数据
        /// </summary>
        /// <param name="jgdb"></param>
        /// <param name="tdr"></param>
        /// <param name="EndT"></param>
        /// <returns></returns>
        string UpdateMember(JRGCDBClass jgdb, DataRow tdr, DateTime EndT)
        {
            DataTable dt   = tdr.Table;
            DataTable DBdt = new DataTable();

            DBdt.Columns.Add("SectorCode");
            DBdt.Columns.Add("ChangeDate");
            DBdt.Columns.Add("MumberList");
            DBdt.Columns.Add("MumberCnt");
            string         GLCode    = tdr["SectorCode"].ToString();
            string         GLName    = tdr["SectorName"].ToString();
            DateTime       LunchDate = (DateTime)tdr["SectorCreateDate"];
            GLClassProcess glcp      = new GLClassProcess();

            DateTime BegT              = (DateTime)tdr["LastModifyDate"];
            Int64    iMemCnt           = 0;
            bool     bMemCnt           = Int64.TryParse(tdr["CurrMumberCount"].ToString(), out iMemCnt);
            DateTime LoopT             = BegT;
            string   strLastMemberList = null;
            DateTime lastDate          = BegT;

            while (LoopT <= EndT)//从最后更新日开始,每一个月检查一次成员数量是否不一样,忽略只调整成员内容,不调整数量的情况
            {
                Int64 MemCnt = glcp.getRecordCount(GLCode, LoopT);
                if (MemCnt != iMemCnt) //如果该日成分股数量与上一日期的不同
                {
                    bool    isFirstDay = (LunchDate == LoopT);
                    DataRow dr         = DBdt.NewRow();
                    dr["SectorCode"] = GLCode;

                    for (int j = 31; j >= 0; j--)//往前一个月每日检查
                    {
                        DateTime dd    = LoopT;
                        Int64    ddcnt = MemCnt;
                        if (!isFirstDay)
                        {
                            dd = LoopT.AddDays(-1 * j);
                            if (dd <= lastDate)
                            {
                                continue;                //一个月内有多个价格
                            }
                            CheckPin = string.Format("概念{0}:{1}已计算到日期{2}", GLCode, GLName, dd.ToShortDateString());
                            ddcnt    = glcp.getRecordCount(GLCode, dd);
                        }
                        else
                        {
                            CheckPin = string.Format("概念{0}:{1}建立日期{2}", GLCode, GLName, dd.ToShortDateString());
                        }
                        if (ddcnt != iMemCnt)                   //如果当日数量不等于前值,标志为改变日期
                        {
                            dr["ChangeDate"] = dd;              //更新日期
                            DataTable memdt = glcp.getRecords(GLCode, dd);
                            dr["MumberCnt"] = memdt.Rows.Count; //股票数量
                            List <string> memberList = new List <string>();
                            foreach (DataRow wdr in memdt.Rows)
                            {
                                string   secid = wdr["wind_code"].ToString();
                                string[] arr   = secid.Split('.');
                                secid = string.Format("{0}.{1}", arr[1], arr[0]);
                                memberList.Add(secid);
                            }
                            string strChange = string.Join(",", memberList.ToArray());
                            dr["MumberList"]  = strChange;
                            strLastMemberList = strChange;
                            if (dd < LoopT)
                            {
                                LoopT = dd;
                            }
                            lastDate = LoopT;
                            iMemCnt  = memberList.Count;
                            break;
                        }
                    }
                    DBdt.Rows.Add(dr);
                }
                LoopT    = LoopT.AddMonths(1);
                CheckPin = string.Format("概念{0}:{1}已计算到日期{2}", GLCode, GLName, LoopT.ToShortDateString());
            }
            if (strLastMemberList != null)
            {
                tdr["CurrMumberCount"] = iMemCnt;
                tdr["CurrMumberList"]  = strLastMemberList;
                if (LoopT > EndT)
                {
                    LoopT = EndT;
                }
                tdr["LastModifyDate"] = LoopT;
            }
            string sql = string.Format("select * from SectorMemberTable where SectorCode='{0}'", GLCode);

            for (int i = DBdt.Rows.Count - 1; i >= 0; i--)
            {
                DataRow dr = DBdt.Rows[i];
                if (dr["SectorCode"].ToString() == "884221.WI")
                {
                    int itest = 32;
                }
                if (dr["ChangeDate"].ToString() == "")
                {
                    DBdt.Rows.Remove(dr);
                }
            }
            jgdb.Save(DBdt, sql);
            sql = string.Format("select * from SectorTable where SectorCode='{0}'", GLCode);
            jgdb.Save(dt, sql);

            CheckPin = string.Format("概念{0}:{1}已保存完毕。最后日期{2}!", GLCode, GLName, LoopT.ToShortDateString());
            return(null);
        }