Exemplo n.º 1
0
        private void InitControls()
        {
            uscNewOrderPanel.Init(this);

            uscAllOrder.Init(this);
            uscTransactionQuery.Init(this);
            uscPositionsInquiry.Init(this);
            uscPositionsInquiry.PositionDataMouseLeftButtonDown += new PositionDataMouseLeftButtonDownDelegate(uscPositionsInquiry_PositionDataMouseLeftButtonDown);
            uscPositionsInquiry.PositionDataMouseDoubleClicked  += new PositionDataMouseDoubleClickDelegate(uscPositionsInquiry_PositionDataMouseDoubleClicked);

            capitalQuery.Init(this);
            capitalQuery.btnQuery.Click += new RoutedEventHandler(CapitalDetail_Click);

            uscStatementsInquiry = new StatementsInquiry();

            HQBackgroundRealData = new BackgroundDataServer();
        }
        public void Init(MainWindow parent)
        {
            defaultButton          = null;
            this.DataContext       = parent;
            this._MainWindow       = parent;
            dgRealData.DataContext = parent;



            HQRealData      = new BackgroundDataServer(_MainWindow.RealDataCollection, _BackupCodeDic, _DelCodeList, _CodeArray, _OldCodeArray);
            GroupHQRealData = new BackgroundDataServer(_MainWindow.RealDataArbitrageCollection, _BackupCodeDic, _DelCodeList, _GroupCodeArray, _GroupOldCodeArray);
            InitHQData();

            //DataGridColumnBridgeUtils.LoadColumnsSettingFromFile(dgRealData, MainWindow.SettingDictionaryPath);
            dgRealData.SelectionChanged      += new SelectionChangedEventHandler(grdRealData_SelectionChanged);
            dgGroupRealData.SelectionChanged += new SelectionChangedEventHandler(dgGroupRealData_SelectionChanged);

            LvQuotesPanel.Init(parent);

            ResetBlockButtons();
        }
        private void RequestRealData(BackgroundDataServer hqRealData)
        {
            ObservableCollection <UserCodeSet> lstUserCodeSet = UserCodeSetInstance.GetUserCodeSetList();
            //先删除合约
            bool bChanged = false;

            _DelCodeList.Clear();
            foreach (Contract temp in hqRealData.m_oldCodeArray)
            {
                if (!hqRealData.m_codeArray.Contains(temp))
                {
                    _DelCodeList.Add(temp);
                }
            }
            if (_DelCodeList.Count > 0)
            {
                bChanged = true;
                hqRealData.AddContract(_DelCodeList.ToArray());
                hqRealData.UnRequest();
                try
                {
                    RealData tempData = null;
                    foreach (Contract temp in _DelCodeList)
                    {
                        string tempKey = temp.Code + "_" + temp.ExchCode;
                        if (_BackupCodeDic.ContainsKey(tempKey))
                        {
                            tempData = _BackupCodeDic[tempKey];
                            if (tempData != null)
                            {
                                DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData);
                                if (hqRealData == HQRealData)
                                {
                                    //Util.Log("<<:" + tempData.ToString());
                                    _MainWindow.RealDataCollection.Remove(tempDisplayData);
                                }
                                else if (hqRealData == GroupHQRealData)
                                {
                                    _MainWindow.RealDataArbitrageCollection.Remove(tempDisplayData);
                                }
                                _BackupCodeDic.Remove(tempKey);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Util.Log_Error("exception: " + ex.Message);
                    Util.Log_Error("exception: " + ex.StackTrace);
                }
            }
            //在请求新增的合约
            _AddCodeList.Clear();
            foreach (Contract temp in hqRealData.m_codeArray)
            {
                if (!hqRealData.m_oldCodeArray.Contains(temp))
                {
                    _AddCodeList.Add(temp);
                }
            }

            if (_AddCodeList.Count > 0)
            {
                foreach (Contract temp in _AddCodeList)
                {
                    if (temp == null)
                    {
                        continue;
                    }
                    string tempKey = temp.Code + "_" + temp.ExchCode;
                    if (_BackupCodeDic.ContainsKey(tempKey) == false)
                    {
                        RealData tempData2 = new RealData();
                        //Contract tempContract = CodeSetManager.GetContractInfo(temp.Code);
                        tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode);
                        if (tempData2.CodeInfo == null)
                        {
                            tempData2.CodeInfo = new Contract(temp.Code);
                        }
                        //tempData2.Name = tempContract.Name;
                        //decimal fluct = 0.00M;
                        //CodeSetManager.GetHycsAndFluct(tempData2.codeInfo.Code, out (double)tempData2.m_hycs, out fluct);
                        _BackupCodeDic.Add(tempKey, tempData2);
                    }
                }
                bChanged = true;
                hqRealData.AddContract(_AddCodeList.ToArray());
                hqRealData.GetRealData();
                hqRealData.Request();
            }

            DeepCopyInfo(hqRealData.m_codeArray, hqRealData.m_oldCodeArray);

            if (bChanged == false)
            {
                RealData tempData2 = null;
                _MainWindow.RealDataCollection.Clear();
                _MainWindow.RealDataArbitrageCollection.Clear();
                foreach (Contract temp in hqRealData.m_oldCodeArray)
                {
                    //Util.Log(this.defaultButton.Content + " 添加内容 Old-----");
                    string tempKey = temp.Code + "_" + temp.ExchCode;
                    if (_BackupCodeDic.ContainsKey(tempKey))
                    {
                        tempData2 = _BackupCodeDic[tempKey];
                        if (tempData2 != null)
                        {
                            DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData2);
                            if (hqRealData == HQRealData)
                            {
                                //Util.Log(">>:" + tempData2.ToString());
                                _MainWindow.RealDataCollection.Add(tempDisplayData);
                            }
                            else if (hqRealData == GroupHQRealData)
                            {
                                if (tempData2.CodeInfo.Code.Contains("&"))
                                {
                                    //string[] tempType = tempData2.codeInfo.Code.Split(' ');
                                    //string[] tempGroup = tempType[1].Split('&');
                                    //tempData2.Code = tempGroup[0];
                                    //tempData2.Code2 = tempGroup[1];
                                }
                                _MainWindow.RealDataArbitrageCollection.Add(UpdateDisplayProperties(tempData2));
                            }
                        }
                    }
                }
            }
            else
            {
                RealData tempData2 = null;
                _MainWindow.RealDataCollection.Clear();
                _MainWindow.RealDataArbitrageCollection.Clear();
                if (hqRealData == HQRealData)
                {
                    //Util.Log(this.defaultButton.Content + " 添加内容-----");
                    foreach (Contract temp in _CodeArray)
                    {
                        if (temp != null)
                        {
                            string tempKey = temp.Code + "_" + temp.ExchCode;
                            if (_BackupCodeDic.ContainsKey(tempKey) == false)
                            {
                                tempData2 = new RealData();
                                //Contract tempContract = CodeSetManager.GetContractInfo(temp.Code);
                                tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode);
                                if (tempData2.CodeInfo == null)
                                {
                                    tempData2.CodeInfo = new Contract(temp.Code);
                                }
                                //tempData2.Name = tempContract.Name;
                                //double fluct = 0;
                                //CodeSetManager.GetHycsAndFluct(tempData2.Code, out tempData2.m_hycs, out fluct);
                                _BackupCodeDic.Add(tempKey, tempData2);
                            }
                            else
                            {
                                tempData2 = _BackupCodeDic[tempKey];
                            }
                            DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData2);
                            //Util.Log(">>:"+tempData2.ToString());
                            _MainWindow.RealDataCollection.Add(tempDisplayData);
                            //Util.Log("mainWindow.RealDataCollection.count=" + mainWindow.RealDataCollection.Count);
                        }
                    }
                }

                else if (hqRealData == GroupHQRealData)
                {
                    foreach (Contract temp in _GroupCodeArray)
                    {
                        if (temp != null)
                        {
                            string tempKey = temp.Code + "_" + temp.ExchCode;
                            if (_BackupCodeDic.ContainsKey(tempKey) == false)
                            {
                                tempData2          = new RealData();
                                tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode);
                                if (tempData2.CodeInfo == null)
                                {
                                    tempData2.CodeInfo = new Contract(tempKey);
                                }
                                //decimal fluct = 0;
                                //CodeSetManager.GetHycsAndFluct(temp.Code, out tempData2.m_hycs, out fluct);
                                _BackupCodeDic.Add(tempKey, tempData2);
                            }
                            else
                            {
                                tempData2 = _BackupCodeDic[tempKey];
                            }
                            if (tempData2.CodeInfo.Code.Contains("&"))
                            {
                                //string[] tempType = tempData2.Code.Split(' ');
                                //string[] tempGroup = tempType[1].Split('&');
                                //tempData2.Code1 = tempGroup[0];
                                //tempData2.Code2 = tempGroup[1];
                            }
                            _MainWindow.RealDataArbitrageCollection.Add(UpdateDisplayProperties(tempData2));
                        }
                    }
                }
            }
            hqRealData.UpdateRealDataList();
        }