/// <summary> /// 获取日期到结束 /// </summary> /// <param name="DateStr">日期</param> /// <param name="p_strFileName">股票文件</param> /// <returns></returns> public List <SencondLineInfo> GetAreaLineToNow(DateTime DateStr, string p_strFileName) { List <SencondLineInfo> ldsi = new List <SencondLineInfo>(); int MyDateTime = 0; //获取日期下的偏移地址 int StartPostion = GetDayPostion(DateStr, p_strFileName); int CountValue = 0; FileStream stream = new FileStream(p_strFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader b_reader = new BinaryReader(stream); stream.Position = (long)StartPostion * 40; while (stream.CanRead && stream.Position < stream.Length) { SencondLineInfo dsi = new SencondLineInfo(); dsi.ShiFen = b_reader.ReadInt32(); dsi.ChengJiao = b_reader.ReadInt32(); dsi.ZhangDie = b_reader.ReadInt32(); dsi.FuDu = b_reader.ReadInt32(); dsi.MaiRu = b_reader.ReadInt32(); dsi.MaiChu = b_reader.ReadInt32(); dsi.Liang = b_reader.ReadInt32(); dsi.BiShu = b_reader.ReadInt32(); dsi.Backup = b_reader.ReadInt32(); try { MyDateTime = b_reader.ReadInt32(); } catch (Exception ex) { } DateTime day = new DateTime(); try { int yeari = MyDateTime / 10000; int monthi = (MyDateTime % 10000) / 100; int dayi = MyDateTime % 100; day = new DateTime(yeari, monthi, dayi); } catch (Exception exp) { } dsi.time = day; ldsi.Add(dsi); CountValue++; } return(ldsi); }
/// <summary> /// 创造一个分时线 /// </summary> /// <param name="TXTpath">文件路径</param> /// <param name="dsi">日线信息</param> public void CreateSencond(string TXTpath, SencondLineInfo dsi) { if (!File.Exists(TXTpath)) { FileStream sm = File.Create(TXTpath); sm.Close(); } FileStream stream = new FileStream(TXTpath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); BinaryWriter b_reader = new BinaryWriter(stream); b_reader.Write(dsi.ShiFen.ToString("mmss")); b_reader.Write(dsi.ChengJiao); b_reader.Write(dsi.ZhangDie); b_reader.Write(dsi.FuDu); b_reader.Write(dsi.MaiRu); b_reader.Write(dsi.MaiChu); b_reader.Write(dsi.Liang); b_reader.Write(dsi.BiShu); b_reader.Write(dsi.Backup); b_reader.Write(dsi.time.ToString("HHmmss")); stream.Close(); }