Пример #1
0
        //获取所有交易所的品种、合约
        private List <Exchange> getAllExchanges()
        {
            List <IntPtr> wndHandles = WindowsApiUtils.findWindowHandlesByClassTitleFuzzy(CLASS_DIALOG, FuturesAnalysisPage.FUTURES_ANALYSIS_PAGE_TITLE);

            if (wndHandles.Count == 0)
            {
                PageUtils.frontMessageBox(this, "打开“挑选要分析的股票,合约或品种”界面失败,未找到该界面");
                return(null);
            }
            else if (wndHandles.Count > 1)
            {
                PageUtils.frontMessageBox(this, "找到多个“挑选要分析的股票,合约或品种”界面,请关闭多余界面");
                return(null);
            }
            IntPtr handle = wndHandles[0];

            AutomationElement targetWindow = AutomationElement.FromHandle(handle);

            if (targetWindow != null)
            {
                WindowsApiUtils.clearOtherWindows(mainHandle, new List <IntPtr> {
                    handle
                });
                PropertyCondition condition0       = new PropertyCondition(AutomationElement.AutomationIdProperty, FuturesAnalysisPage.AUTOMATION_ID_TREEVIEW_EXCHANGE);
                PropertyCondition condition1       = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tree);
                AutomationElement treeviewExchange = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition0, condition1));

                if (treeviewExchange != null)
                {
                    List <Exchange> exchanges = new List <Exchange>();

                    Condition condition2 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
                    AutomationElementCollection exchangeElementCollection = treeviewExchange.FindAll(TreeScope.Children, condition2);
                    if (exchangeElementCollection != null && exchangeElementCollection.Count > 0)
                    {
                        foreach (AutomationElement exchangeAE in exchangeElementCollection)
                        {
                            string exchangeName = exchangeAE.Current.Name;
                            if (FuturesAnalysisPage.isDomesticFutures(exchangeName))
                            {
                                if (SimulateOperating.expandTreeItem(exchangeAE))
                                {
                                    Exchange exchange = new Exchange();
                                    exchange.exchangeName = exchangeName;
                                    List <Variety> varieties = new List <Variety>();
                                    exchange.varieties = varieties;
                                    exchanges.Add(exchange);

                                    Condition condition3 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
                                    AutomationElementCollection varietyElementCollection = exchangeAE.FindAll(TreeScope.Children, condition3);
                                    if (varietyElementCollection != null && varietyElementCollection.Count > 0)
                                    {
                                        foreach (AutomationElement varietyAE in varietyElementCollection)
                                        {
                                            Variety variety = new Variety();
                                            variety.varietyName = varietyAE.Current.Name;
                                            varieties.Add(variety);
                                        }
                                    }
                                }
                                else
                                {
                                    PageUtils.frontMessageBox(this, "展开“挑选要分析的股票,合约或品种”界面中的“" + exchangeAE.Current.Name + "”子项失败");
                                    WindowsApiUtils.closeWindow(handle);
                                    return(null);
                                }
                            }
                        }
                        WindowsApiUtils.closeWindow(handle);
                        return(exchanges);
                    }
                    else
                    {
                        PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面中的“品种”树形结构的子项");
                        WindowsApiUtils.closeWindow(handle);
                        return(null);
                    }
                }
                else
                {
                    PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面中的“品种”树形结构");
                    WindowsApiUtils.closeWindow(handle);
                    return(null);
                }
            }
            else
            {
                PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面");
                WindowsApiUtils.closeWindow(handle);
                return(null);
            }
        }
Пример #2
0
        //获取所有交易所的品种、合约
        private List <StockExchange> getAllStockExchanges()
        {
            List <IntPtr> wndHandles = WindowsApiUtils.findWindowHandlesByClassTitleFuzzy(CLASS_DIALOG, FuturesAnalysisPage.FUTURES_ANALYSIS_PAGE_TITLE);

            if (wndHandles.Count == 0)
            {
                PageUtils.frontMessageBox(this, "打开“挑选要分析的股票,合约或品种”界面失败,未找到该界面");
                return(null);
            }
            else if (wndHandles.Count > 1)
            {
                PageUtils.frontMessageBox(this, "找到多个“挑选要分析的股票,合约或品种”界面,请关闭多余界面");
                return(null);
            }
            IntPtr handle = wndHandles[0];

            AutomationElement targetWindow = AutomationElement.FromHandle(handle);

            if (targetWindow != null)
            {
                WindowsApiUtils.clearOtherWindows(mainHandle, new List <IntPtr> {
                    handle
                });
                PropertyCondition condition0       = new PropertyCondition(AutomationElement.AutomationIdProperty, FuturesAnalysisPage.AUTOMATION_ID_TREEVIEW_EXCHANGE);
                PropertyCondition condition1       = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tree);
                AutomationElement treeviewExchange = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition0, condition1));
                if (treeviewExchange != null)
                {
                    List <StockExchange> stockExchanges = new List <StockExchange>();

                    Condition condition2 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
                    AutomationElementCollection exchangeElementCollection = treeviewExchange.FindAll(TreeScope.Children, condition2);
                    if (exchangeElementCollection != null && exchangeElementCollection.Count > 0)
                    {
                        foreach (AutomationElement exchangeAE in exchangeElementCollection)
                        {
                            string exchangeName = exchangeAE.Current.Name;
                            if (FuturesAnalysisPage.isDomesticStock(exchangeName))
                            {
                                StockExchange stockExchange = new StockExchange();
                                stockExchange.stockExchangeName = exchangeName;
                                List <string> stocks = new List <string>();
                                stockExchange.stocks = stocks;
                                if (SimulateOperating.selectTreeItem(exchangeAE))
                                {
                                    PropertyCondition condition3   = new PropertyCondition(AutomationElement.AutomationIdProperty, FuturesAnalysisPage.AUTOMATION_ID_LISTBOX_VARIETY);
                                    PropertyCondition condition4   = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List);
                                    AutomationElement listBoxStock = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition3, condition4));
                                    if (listBoxStock != null)
                                    {
                                        Condition condition5 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem);
                                        AutomationElementCollection stockElementCollection = listBoxStock.FindAll(TreeScope.Children, condition5);
                                        if (stockElementCollection != null && stockElementCollection.Count > 0)
                                        {
                                            foreach (AutomationElement stockAE in stockElementCollection)
                                            {
                                                stocks.Add(stockAE.Current.Name);
                                            }
                                            stockExchanges.Add(stockExchange);
                                        }
                                        else
                                        {
                                            PageUtils.frontMessageBox(this, "在“挑选要分析的股票,合约或品种”界面,股票为空");
                                            return(null);
                                        }
                                    }
                                    else
                                    {
                                        PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面中的股票列表");
                                        return(null);
                                    }
                                }
                                else
                                {
                                    PageUtils.frontMessageBox(this, "选择“挑选要分析的股票,合约或品种”界面中的“" + exchangeAE.Current.Name + "”子项失败");
                                    WindowsApiUtils.closeWindow(handle);
                                    return(null);
                                }
                            }
                        }
                        WindowsApiUtils.closeWindow(handle);
                        return(stockExchanges);
                    }
                    else
                    {
                        PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面中的“品种”树形结构的子项");
                        WindowsApiUtils.closeWindow(handle);
                        return(null);
                    }
                }
                else
                {
                    PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面中的“品种”树形结构");
                    WindowsApiUtils.closeWindow(handle);
                    return(null);
                }
            }
            else
            {
                PageUtils.frontMessageBox(this, "未找到“挑选要分析的股票,合约或品种”界面");
                WindowsApiUtils.closeWindow(handle);
                return(null);
            }
        }
        //打开“挑选要分析的股票,合约或品种”界面
        public static bool toFuturesAnalysisPage(Form from, IntPtr mainHandle)
        {
            AutomationElement targetWindow = AutomationElement.FromHandle(mainHandle);

            if (targetWindow != null)
            {
                WindowsApiUtils.clearOtherWindows(mainHandle, null);
                PropertyCondition condition0     = new PropertyCondition(AutomationElement.AutomationIdProperty, WH8MainPage.AUTOMATION_ID_BUTTON_HANGQINGSHOUYE);
                PropertyCondition condition1     = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
                AutomationElement buttonHangqing = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition0, condition1));
                if (buttonHangqing != null)
                {
                    //这里突然一天就不行了11.29,愁人
                    //SimulateOperating.clickButton(buttonHangqing);
                    targetWindow.SetFocus();
                    SimulateOperating.leftClickAutomationElement(buttonHangqing);

                    Thread.Sleep(500);

                    PropertyCondition condition2    = new PropertyCondition(AutomationElement.AutomationIdProperty, WH8MainPage.AUTOMATION_ID_TREEVIEW_SHUJU);
                    PropertyCondition condition3    = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tree);
                    AutomationElement treeViewShuju = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition2, condition3));
                    if (treeViewShuju != null)
                    {
                        Condition condition4 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
                        AutomationElementCollection automationElementCollection = treeViewShuju.FindAll(TreeScope.Children, condition4);
                        if (automationElementCollection != null && automationElementCollection.Count > 0)
                        {
                            if ("我的篮子".Equals(automationElementCollection[0].Current.Name))
                            {
                                SimulateOperating.doubleClick(automationElementCollection[0]);

                                PropertyCondition condition5  = new PropertyCondition(AutomationElement.AutomationIdProperty, WH8MainPage.AUTOMATION_ID_BUTTON_KXIAN);
                                PropertyCondition condition6  = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
                                AutomationElement buttonKXIAN = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition5, condition6));
                                if (buttonKXIAN != null)
                                {
                                    SimulateOperating.clickButton(buttonKXIAN);
                                    return(true);
                                }
                                else
                                {
                                    frontMessageBox(from, "未找到主界面“K线”按钮");
                                    return(false);
                                }
                            }
                            else
                            {
                                frontMessageBox(from, "未找到主界面“数据”树形结构中的“我的篮子”子项");
                                return(false);
                            }
                        }
                        else
                        {
                            frontMessageBox(from, "未找到主界面“数据”树形结构的子项");
                            return(false);
                        }
                    }
                    else
                    {
                        frontMessageBox(from, "未找到主界面“数据”对应的树形结构");
                        return(false);
                    }
                }
                else
                {
                    frontMessageBox(from, "未找到主界面“行情首页”按钮");
                    return(false);
                }
            }
            else
            {
                frontMessageBox(from, "未找到“赢智程序化”主界面");
                return(false);
            }
        }