예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            FormLogin fLogin = new FormLogin();
            if (fLogin.ShowDialog(this) == DialogResult.Cancel)
            {
                this.Close();
                return;
            }

            _t = fLogin.trade;
            _q = fLogin.quote;
            _t.OnRtnCancel += trade_OnRtnCancel;
            _t.OnRtnError += trade_OnRtnError;
            _t.OnRtnExchangeStatus += trade_OnRtnExchangeStatus;
            _t.OnRtnNotice += trade_OnRtnNotice;
            _t.OnRtnOrder += trade_OnRtnOrder;
            _t.OnRtnTrade += trade_OnRtnTrade;
            if (_q != null)
                _q.OnRtnTick += quote_OnRtnTick;

            SetConfig("server", fLogin.Server);
            SetConfig("investor", fLogin.trade.Investor);

            fLogin.Close();

            this.Text += string.Format("({0}@{1})", GetConfig("investor"), GetConfig("server"));

            //初始化表格
            InitView(this.kryptonDataGridViewTick, this.kryptonDataGridViewOrder, this.kryptonDataGridViewTrade, this.kryptonDataGridViewPosition);
            this.kryptonDataGridViewOrder.CellDoubleClick += kryptonDataGridViewOrder_CellDoubleClick;
            this.kryptonDataGridViewPosition.CellDoubleClick += kryptonDataGridViewPosition_CellDoubleClick;
            this.kryptonDataGridViewOrder.CellFormatting += kryptonDataGridView_CellFormatting;
            this.kryptonDataGridViewTrade.CellFormatting += kryptonDataGridView_CellFormatting;
            this.kryptonDataGridViewPosition.CellFormatting += kryptonDataGridView_CellFormatting;
            this.kryptonComboBoxInstrument.SelectedIndexChanged += kryptonComboBox1_SelectedIndexChanged;
            this.kryptonComboBoxInstrument.Enter += kryptonComboBoxInstrument_Enter;
            this.kryptonComboBoxInstrument.DropDown += kryptonComboBoxInstrument_Enter;
            this.kryptonLabel5.Click += kryptonLabel5_Click;
            this.kryptonButtonCancel.Click += kryptonButtonCancel_Click;
            this.kryptonButtonFAK.Click += kryptonButtonOrder_Click;
            this.kryptonButtonFOK.Click += kryptonButtonOrder_Click;
            this.kryptonButtonLimit.Click += kryptonButtonOrder_Click;
            this.kryptonButtonMarket.Click += kryptonButtonOrder_Click;

            //样式
            foreach (var v in Enum.GetNames(typeof(PaletteModeManager)))
            {
                var item = this.ToolStripMenuItemStyle.DropDownItems.Add(v);
                item.Click += (obj, arg) =>
                {
                    RecalcNonClient();
                    this.kryptonManager1.GlobalPaletteMode = (PaletteModeManager)Enum.Parse(typeof(PaletteModeManager), ((ToolStripDropDownItem)obj).Text);
                };
            }

            //创建确认选项
            for (int i = 0; i < _confirmNames.Length; ++i)
            {
                ToolStripMenuItem item = new ToolStripMenuItem
                {
                    Name = _confirmNames[i],
                    Text = _confirmTexts[i],
                    Checked = true,
                    CheckOnClick = true,
                };
                this.ToolStripMenuItemOption.DropDownItems.Add(item);
            }
            this.ToolStripMenuItemOption.DropDownItems.Add("-");//增加隔断

            //过滤显示
            _dtPosition.DefaultView.RowFilter = "Position > 0";

            //加载插件
            if (Directory.Exists(Application.StartupPath + "\\plugin"))
                foreach (var file in new DirectoryInfo(Application.StartupPath + "\\plugin").GetFiles("*.dll"))
                {
                    Assembly ass = Assembly.LoadFile(file.FullName);
                    //加载hf_plat报错:增加对hf_plat_core的引用
                    var t = ass.GetTypes().FirstOrDefault(n => n.BaseType == typeof(UserControl));
                    if (t != null && !t.FullName.StartsWith("Telerik."))
                    {
                        this.tabControl1.TabPages.Add(t.FullName, t.Name);
                        TabPage tp = this.tabControl1.TabPages[t.FullName];
                        var uc = (UserControl)Activator.CreateInstance(t, _t, _q);
                        uc.Dock = DockStyle.Fill;
                        tp.Controls.Add(uc);
                    }
                }
            if (File.Exists(Application.StartupPath + "\\hf_plat_terminal.dll"))
                //foreach (var file in new DirectoryInfo(Application.StartupPath + "\\strategy").GetFiles("*.dll"))
                {
                    Assembly ass = Assembly.LoadFile(Application.StartupPath + "\\hf_plat_terminal.dll");
                    //加载hf_plat报错:增加对hf_plat_core的引用
                    var t = ass.GetTypes().FirstOrDefault(n => n.BaseType == typeof(UserControl));
                    if (t != null)
                    {
                        this.tabControl1.TabPages.Add(t.FullName, t.Name);
                        TabPage tp = this.tabControl1.TabPages[t.FullName];
                        var uc = (UserControl)Activator.CreateInstance(t, _t, _q);
                        uc.Dock = DockStyle.Fill;
                        tp.Controls.Add(uc);
                    }
                }
            //if (File.Exists(Application.StartupPath + "\\strategy\\hf_plat_core.dll"))
            //{
            //	Assembly ass = Assembly.LoadFile(Application.StartupPath + "\\strategy\\hf_plat_core.dll");
            //	var t = ass.GetType("hf_plat_core.Plat");
            //	var uc = (UserControl)Activator.CreateInstance(t, _t, _q);
            //	this.tabControl1.TabPages.Add(t.FullName, t.Name);
            //	TabPage tp = this.tabControl1.TabPages[t.FullName];
            //	uc.Dock = DockStyle.Fill;
            //	tp.Controls.Add(uc);
            //}

            _timer.Tick += _timer_Tick;
            _timer.Start();

            //恢复配置
            if (!string.IsNullOrEmpty(GetConfig("WindowState")))
                this.WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), GetConfig("WindowState"));
            if (this.WindowState != FormWindowState.Maximized)
            {
                if (!string.IsNullOrEmpty(GetConfig("Left")))
                    this.Left = int.Parse(GetConfig("Left"));
                if (!string.IsNullOrEmpty(GetConfig("Top")))
                    this.Top = int.Parse(GetConfig("Top"));
                if (!string.IsNullOrEmpty(GetConfig("Height")))
                    this.Height = int.Parse(GetConfig("Height"));
                if (!string.IsNullOrEmpty(GetConfig("Width")))
                    this.Width = int.Parse(GetConfig("Width"));
            }
            if (!string.IsNullOrEmpty(GetConfig("GlobalPaletteMode")))
                this.kryptonManager1.GlobalPaletteMode = (PaletteModeManager)Enum.Parse(typeof(PaletteModeManager), GetConfig("GlobalPaletteMode"));	//更新样式

            //选项
            foreach (var v in _confirmNames)
            {
                ((ToolStripMenuItem)this.ToolStripMenuItemOption.DropDownItems[v]).Checked = string.IsNullOrEmpty(GetConfig(v)) || bool.Parse(GetConfig(v));
            }
        }
예제 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            FormLogin fLogin = new FormLogin();

            if (fLogin.ShowDialog(this) == DialogResult.Cancel)
            {
                this.Close();
                return;
            }

            _t                      = fLogin.trade;
            _q                      = fLogin.quote;
            _t.OnRtnCancel         += trade_OnRtnCancel;
            _t.OnRtnError          += trade_OnRtnError;
            _t.OnRtnExchangeStatus += trade_OnRtnExchangeStatus;
            _t.OnRtnNotice         += trade_OnRtnNotice;
            _t.OnRtnOrder          += trade_OnRtnOrder;
            _t.OnRtnTrade          += trade_OnRtnTrade;
            if (_q != null)
            {
                _q.OnRtnTick += quote_OnRtnTick;
            }

            SetConfig("server", fLogin.Server);
            SetConfig("investor", fLogin.trade.Investor);

            fLogin.Close();

            this.Text += string.Format("({0}@{1})", GetConfig("investor"), GetConfig("server"));

            //初始化表格
            InitView(this.kryptonDataGridViewTick, this.kryptonDataGridViewOrder, this.kryptonDataGridViewTrade, this.kryptonDataGridViewPosition);
            this.kryptonDataGridViewOrder.CellDoubleClick       += kryptonDataGridViewOrder_CellDoubleClick;
            this.kryptonDataGridViewPosition.CellDoubleClick    += kryptonDataGridViewPosition_CellDoubleClick;
            this.kryptonDataGridViewOrder.CellFormatting        += kryptonDataGridView_CellFormatting;
            this.kryptonDataGridViewTrade.CellFormatting        += kryptonDataGridView_CellFormatting;
            this.kryptonDataGridViewPosition.CellFormatting     += kryptonDataGridView_CellFormatting;
            this.kryptonComboBoxInstrument.SelectedIndexChanged += kryptonComboBox1_SelectedIndexChanged;
            this.kryptonComboBoxInstrument.Enter += kryptonComboBoxInstrument_Enter;
            this.kryptonLabel5.Click             += kryptonLabel5_Click;
            this.kryptonButtonCancel.Click       += kryptonButtonCancel_Click;
            this.kryptonButtonFAK.Click          += kryptonButtonOrder_Click;
            this.kryptonButtonFOK.Click          += kryptonButtonOrder_Click;
            this.kryptonButtonLimit.Click        += kryptonButtonOrder_Click;
            this.kryptonButtonMarket.Click       += kryptonButtonOrder_Click;

            //样式
            foreach (var v in Enum.GetNames(typeof(PaletteModeManager)))
            {
                var item = this.ToolStripMenuItemStyle.DropDownItems.Add(v);
                item.Click += (obj, arg) =>
                {
                    RecalcNonClient();
                    this.kryptonManager1.GlobalPaletteMode = (PaletteModeManager)Enum.Parse(typeof(PaletteModeManager), ((ToolStripDropDownItem)obj).Text);
                };
            }

            //创建确认选项
            for (int i = 0; i < _confirmNames.Length; ++i)
            {
                ToolStripMenuItem item = new ToolStripMenuItem
                {
                    Name         = _confirmNames[i],
                    Text         = _confirmTexts[i],
                    Checked      = true,
                    CheckOnClick = true,
                };
                this.ToolStripMenuItemOption.DropDownItems.Add(item);
            }
            this.ToolStripMenuItemOption.DropDownItems.Add("-");            //增加隔断

            //过滤显示
            _dtPosition.DefaultView.RowFilter = "Position > 0";

            //加载合约列表
            this.kryptonComboBoxInstrument.Items.AddRange(_t.DicInstrumentField.Keys.ToArray());

            //加载插件
            if (Directory.Exists(Application.StartupPath + "\\plugin"))
            {
                foreach (var file in new DirectoryInfo(Application.StartupPath + "\\plugin").GetFiles("*.dll"))
                {
                    Assembly ass = Assembly.LoadFile(file.FullName);
                    var      t   = ass.GetTypes().FirstOrDefault(n => n.BaseType == typeof(UserControl));
                    if (t != null && !t.FullName.StartsWith("Telerik."))
                    {
                        this.tabControl1.TabPages.Add(t.FullName, t.Name);
                        TabPage tp = this.tabControl1.TabPages[t.FullName];
                        var     uc = (UserControl)Activator.CreateInstance(t, _t, _q);
                        uc.Dock = DockStyle.Fill;
                        tp.Controls.Add(uc);
                    }
                }
            }

            _timer.Tick += _timer_Tick;
            _timer.Start();


            //恢复配置
            if (!string.IsNullOrEmpty(GetConfig("WindowState")))
            {
                this.WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), GetConfig("WindowState"));
            }
            if (this.WindowState != FormWindowState.Maximized)
            {
                if (!string.IsNullOrEmpty(GetConfig("Left")))
                {
                    this.Left = int.Parse(GetConfig("Left"));
                }
                if (!string.IsNullOrEmpty(GetConfig("Top")))
                {
                    this.Top = int.Parse(GetConfig("Top"));
                }
                if (!string.IsNullOrEmpty(GetConfig("Height")))
                {
                    this.Height = int.Parse(GetConfig("Height"));
                }
                if (!string.IsNullOrEmpty(GetConfig("Width")))
                {
                    this.Width = int.Parse(GetConfig("Width"));
                }
            }
            if (!string.IsNullOrEmpty(GetConfig("GlobalPaletteMode")))
            {
                this.kryptonManager1.GlobalPaletteMode = (PaletteModeManager)Enum.Parse(typeof(PaletteModeManager), GetConfig("GlobalPaletteMode"));                    //更新样式
            }
            //选项
            foreach (var v in _confirmNames)
            {
                ((ToolStripMenuItem)this.ToolStripMenuItemOption.DropDownItems[v]).Checked = string.IsNullOrEmpty(GetConfig(v)) || bool.Parse(GetConfig(v));
            }
        }