예제 #1
0
        /// <summary>
        /// contract信息在文件data\cont.dat中
        /// </summary>
        /// <param name="filePathName"></param>
        /// <returns></returns>
        public static List <Level2Info> GetConDatData(string filePathName)
        {
            try
            {
                //byte[] bs = FileToByte(@"D:\wh6上海中期\Data\贵金属\cont.dat");
                byte[] bs = FileToByte(filePathName);
                byte[] tt = bs.Skip(8).Take(bs.Length).ToArray();

                List <Level2Info> listInfo = new List <Level2Info>();

                for (int i = 0; i < tt.Length; i = i + 141)
                {
                    byte[] conCode      = tt.Skip(i + 4).Take(4).ToArray();
                    float  conCodeFloat = BytesToFloat(conCode);

                    byte[] conCodeInfo    = tt.Skip(i + 8).Take(2).ToArray();
                    UInt16 conCodeInfoStr = BytesToInt16(conCodeInfo);//这里相当重要

                    byte[] conIns    = tt.Skip(i + 53).Take(28).ToArray();
                    string conInsStr = BytesToString(conIns);

                    Level2Info info = new Level2Info();
                    info.WenHuaCode = conCodeFloat;
                    info.DatCode    = conCodeInfoStr;
                    info.Instrument = conInsStr;

                    listInfo.Add(info);
                }
                return(listInfo);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Add_Click(object sender, EventArgs e)
        {
            if (this.listBox_Level1.SelectedItem == null ||
                this.listBox_Level1.SelectedItem.ToString() == "" ||
                this.listBox_Level2.SelectedItem == null ||
                this.listBox_Level2.SelectedItem.ToString() == "" ||
                this.listBox_SelfBanKuai.SelectedItem == null ||
                this.listBox_SelfBanKuai.SelectedItem.ToString() == ""
                )
            {
                MessageBox.Show("请选中一级市场板块,二级品种,以及自定义版块,再添加!");
                return;
            }


            if (this.listBox_Level1.SelectedItem != null &&
                this.listBox_Level1.SelectedItem.ToString() != "" &&
                this.listBox_Level2.SelectedItem != null &&
                this.listBox_Level2.SelectedItem.ToString() != "" &&
                this.listBox_SelfBanKuai.SelectedItem != null &&
                this.listBox_SelfBanKuai.SelectedItem.ToString() != ""
                )
            {
                foreach (KeyValuePair <string, Dictionary <string, string> > kv in DatDataManager.Instance.BankuaiGeguPathDic)
                {
                    if (kv.Key != this.listBox_SelfBanKuai.SelectedItem.ToString())
                    {
                        continue;
                    }

                    Level2Info infos = this.listBox_Level2.SelectedItem as Level2Info;

                    Dictionary <string, string> geguNamePathStr = kv.Value;
                    geguNamePathStr.Add(infos.Instrument.Replace("\0", "").Trim(),
                                        this.textBox_path.Text.Replace("\r\n", "") + this.listBox_Level1.SelectedItem.ToString()
                                        + "\\" + "day\\" + infos.DataCodeStr + ".dat");

                    this.listBox_ChengfenData.Items.Add(infos.Instrument + " " +
                                                        this.textBox_path.Text.Replace("\r\n", "") + this.listBox_Level1.SelectedItem.ToString()
                                                        + "\\" + "day\\" + infos.DataCodeStr + ".dat");
                }
            }
        }
        private void Level2_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //选中显示个股
                this.richTextBox_Data.Clear();

                if (this.listBox_Level1.SelectedItem == null ||
                    this.listBox_Level1.SelectedItem.ToString() == "" ||
                    this.listBox_Level2.SelectedItem == null ||
                    this.listBox_Level2.SelectedItem.ToString() == "")
                {
                    return;
                }

                Level2Info infos = this.listBox_Level2.SelectedItem as Level2Info;

                string fileInfos = this.textBox_path.Text.Replace("\r\n", "") + this.listBox_Level1.SelectedItem.ToString()
                                   + "\\" + "day\\" + infos.DataCodeStr + ".dat";

                //获取数据
                if (!File.Exists(fileInfos))
                {
                    MessageBox.Show("该行情文件不存在,请刷新文华相关合约的日线数据!");
                }
                else
                {
                    List <MarketData> wDList = WenHuaDataHandle.GetHQDatData(fileInfos);
                    //因为数据可能很多,所以只展示100条
                    for (int i = wDList.Count - 1; i >= wDList.Count - 50; i--)
                    {
                        this.richTextBox_Data.AppendText(wDList[i].DateTimeNum + "|" + wDList[i].Close + "\n");
                    }
                }
            }
        }