private void buttonLoadPobo_Click(object sender, EventArgs e) { openFileDialog1.FileName = "*.da1"; openFileDialog1.Filter = "Pobo Day Files|*.da1"; if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; } int start = openFileDialog1.FileName.LastIndexOf('\\'); int upIndex = openFileDialog1.FileName.Substring(0, start).LastIndexOf('\\'); CommodityInfomation commodity = CommodityInfomation.CommodityOf(openFileDialog1.FileName.Substring(start)); if (quoteGroup == null) { throw new Exception("Please import records from text files first."); } if (commodity == null) { textBoxDescription.Text = "Failed to get Commodity Information from " + openFileDialog1.FileName; return; } else if (commodity != quoteGroup.Commodity) { textBoxDescription.Text = "Different commodity: " + openFileDialog1.FileName; return; } else { textBoxDescription.Text = string.Format("{0}\r\n", commodity); } foreach (string filename in openFileDialog1.FileNames) { ContractInfomation theContract = commodity.ContractOf(filename.Substring(start)); if (theContract.Month == 0 && (openFileDialog1.FileNames.Length > 1)) { continue; } List <Quote> items = PoboDataImporter.Import(filename, RecordType.DayRecord); if (items == null) { continue; } QuoteCollection quotes = new QuoteCollection(theContract, filename, RecordType.DayRecord, items); quoteGroup.Group.Add(theContract, quotes); } }
private void appendGoodsSummary() { if (tabControlMarkets.SelectedTab.Controls.Count != 0) { return; } DataGridView allGoodsView = new DataGridView(); BindingSource summaryBindings = new BindingSource(); allGoodsView.Dock = DockStyle.Fill; allGoodsView.ScrollBars = ScrollBars.Both; allGoodsView.MultiSelect = false; allGoodsView.AutoGenerateColumns = true; allGoodsView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; tabControlMarkets.SelectedTab.Controls.Add(allGoodsView); Dictionary <string, string> allGoods = PoboDataImporter.AllGoodsOf(tabControlMarkets.SelectedTab.Tag as string); allGoodsView.Tag = allGoods; List <PoboDayFileSummary> summaries = new List <PoboDayFileSummary>(); foreach (KeyValuePair <string, string> kvp in allGoods) { PoboDayFileSummary newSummary = new PoboDayFileSummary(kvp.Key, kvp.Value); if (newSummary == null || newSummary.ItemsCount <= 1) { continue; } summaries.Add(newSummary); } summaryBindings.DataSource = summaries; allGoodsView.DataSource = summaryBindings; allGoodsView.SelectionChanged += new EventHandler(allGoodsView_SelectionChanged); allGoodsView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); //allGoodsView.Invalidate(); }
private static void readTr2Test() { string tickFileName = @"C:\Program Files\南华期货博易大师客户端\pobo3\Data\cnfut\Tick\010512.tr2"; if (!File.Exists(tickFileName)) { Console.WriteLine("Failed to locate the file!"); return; } FileInfo fileInfo = new FileInfo(tickFileName); if ((fileInfo.Length - 16) % PoboTr2Structure.Size != 0) { Console.WriteLine("File length is not expected: " + fileInfo.Length.ToString()); return; } using (FileStream fs = new FileStream(tickFileName, FileMode.Open, FileAccess.Read)) { byte[] temp = new byte[16]; int readed = 0; readed = fs.Read(temp, 0, temp.Length); if (readed != 16) { throw new IOException("Failed to read all data!"); } UInt32[] uArray = PoboDataImporter.BytesToStructures <UInt32>(temp); Int32 sellVolume = PoboDataImporter.ToVolume(uArray[0]); Int32 buyVolume = PoboDataImporter.ToVolume(uArray[1]); double lastPrice = (double)(uArray[2]) / 1000; int lastPosition = PoboDataImporter.ToVolume(uArray[3]); byte[] buffer = new byte[fs.Length - 16]; readed = fs.Read(buffer, 0, buffer.Length); fs.Close(); if (readed != buffer.Length) { throw new IOException("Failed to read all data!"); } PoboTr2Structure[] rawRecords = PoboDataImporter.BytesToStructures <PoboTr2Structure>(buffer); foreach (PoboTr2Structure raw in rawRecords) { Console.WriteLine("P={0}, U2={2:x}, U1={1:x}", raw.Position, raw.Unknown1, raw.Unknown2); //Console.WriteLine("P={0}, U1={1:x}, U2={2:x}, {3}{4}", raw.Position, raw.Unknown1, raw.Unknown2, // Convert.ToString(raw.Unknown2, 2), Convert.ToString(raw.Unknown1, 2)); //Console.WriteLine(raw.ToString()); } } }