Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        public string UpdateAllGLList(DateTime EndT)
        {
            JRGCDBClass jgdb = new JRGCDBClass();
            DataTable   dt   = getRecords(null, EndT);
            string      sql  = "select * from SectorTable";
            DataSet     ds   = jgdb.GetDataSet(sql);

            if (ds == null)
            {
                jgdb.Close();
                return("无法从本地数据库中获取到概念数据!");
            }
            DataTable dbdt = ds.Tables[0];

            string[] seccodes = new string[dbdt.Rows.Count];
            for (int i = 0; i < dbdt.Rows.Count; i++)
            {
                seccodes[i] = dbdt.Rows[i]["SectorCode"].ToString();
            }
            string strSecCodes = string.Join("','", seccodes);
            string Filtersql   = string.Format("wind_code not in ('{0}')", strSecCodes);

            DataRow[] drs;
            if (strSecCodes.Length == 0)
            {
                drs = dt.Select();
            }
            else
            {
                drs = dt.Select(Filtersql);
            }
            if (drs.Length == 0)
            {
                return(null);
            }
            List <string> sectorList = new List <string>();

            for (int i = 0; i < drs.Length; i++)
            {
                sectorList.Add(drs[i]["wind_code"].ToString());
            }
            strSecCodes = string.Join(",", sectorList.ToArray());
            WSSProcess wss = new WSSProcess();

            dt = wss.getRecods(strSecCodes, "windcode,sec_name,launchdate");
            if (dt == null || dt.Rows.Count == 0)
            {
                jgdb.Close();
                return("无法从万得数据库中获取到概念其它信息!");
            }
            DataTable InsertTable = dbdt.Copy();

            InsertTable.Rows.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = InsertTable.NewRow();
                dr["SectorCode"]       = dt.Rows[i]["WINDCODE"];
                dr["SectorName"]       = dt.Rows[i]["SEC_NAME"];
                dr["SectorCreateDate"] = dt.Rows[i]["LAUNCHDATE"];
                dr["LastModifyDate"]   = dt.Rows[i]["LAUNCHDATE"];
                dr["HQModifyDate"]     = dt.Rows[i]["LAUNCHDATE"];
                InsertTable.Rows.Add(dr);
            }

            Int64 ret = jgdb.Save(InsertTable, sql);

            jgdb.Close();
            //if (InsertTable.Rows.Count != ret) return string.Format("计划保存{0}条数据,实际保存{1}条数据!", InsertTable.Rows.Count , ret);
            return(null);
        }