Exemplo n.º 1
0
        //清理“提醒补充数据界面”,这个界面的关闭按钮无效,需要特殊处理
        private static void closeSupplyDataHintPage(IntPtr handle)
        {
            AutomationElement supplyDataHintPageWindow = AutomationElement.FromHandle(handle);

            if (supplyDataHintPageWindow == null)
            {
                return;
            }
            PropertyCondition condition0 = new PropertyCondition(AutomationElement.AutomationIdProperty, SupplyDataHintPage.AUTOMATION_ID_BUTTON_NO);
            PropertyCondition condition1 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
            AutomationElement buttonNo   = supplyDataHintPageWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition0, condition1));

            if (buttonNo != null)
            {
                SimulateOperating.clickButton(buttonNo);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
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);
            }
        }
        //打开“挑选要分析的股票,合约或品种”界面
        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);
            }
        }
Exemplo n.º 5
0
        //跳转到模型对应的tab,步骤:点击“行情首页”按钮->到数据tab,遍历找到“期货”,并找到其第一个子项->双击子项->点击“K线”按钮
        private bool getModelFromWH8MainPage()
        {
            AutomationElement targetWindow = AutomationElement.FromHandle(mainHandle);

            if (targetWindow == null)
            {
                MessageBox.Show("未找到“赢智程序化”主界面");
                return(false);
            }

            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)
            {
                frontMessageBox("未找到主界面“行情首页”按钮");
                return(false);
            }
            SimulateOperating.clickButton(buttonHangqing);
            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)
            {
                frontMessageBox("未找到主界面“数据”对应的树形结构");
                return(false);
            }
            Condition condition4 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
            AutomationElementCollection categoryElementCollection = treeViewShuju.FindAll(TreeScope.Children, condition4);

            if (categoryElementCollection == null || categoryElementCollection.Count == 0)
            {
                frontMessageBox("未找到主界面“数据”对应的树形结构的子项");
                return(false);
            }
            bool foundFutures = false;

            foreach (AutomationElement categoryAE in categoryElementCollection)
            {
                if ("期货".Equals(categoryAE.Current.Name))
                {
                    foundFutures = true;
                    SimulateOperating.expandTreeItem(categoryAE);
                    Condition condition5 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
                    AutomationElementCollection exchangeElementCollection = categoryAE.FindAll(TreeScope.Children, condition5);
                    if (exchangeElementCollection == null || exchangeElementCollection.Count == 0)
                    {
                        frontMessageBox("未找到主界面“数据”树形结构中的子项“期货”的子项");
                        return(false);
                    }
                    SimulateOperating.doubleClick(exchangeElementCollection[0]);
                    PropertyCondition condition6  = new PropertyCondition(AutomationElement.AutomationIdProperty, WH8MainPage.AUTOMATION_ID_BUTTON_KXIAN);
                    PropertyCondition condition7  = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
                    AutomationElement buttonKXIAN = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition6, condition7));
                    if (buttonKXIAN == null)
                    {
                        frontMessageBox("未找到主界面“K线”按钮");
                        return(false);
                    }
                    if (!SimulateOperating.clickButton(buttonKXIAN))
                    {
                        frontMessageBox("点击主界面“K线”按钮失败");
                    }
                    Thread.Sleep(500);

                    PropertyCondition condition8    = new PropertyCondition(AutomationElement.AutomationIdProperty, WH8MainPage.AUTOMATION_ID_TREEVIEW_SHUJU);
                    PropertyCondition condition9    = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tree);
                    AutomationElement treeViewModel = targetWindow.FindFirst(TreeScope.Descendants, new AndCondition(condition8, condition9));
                    //这里不需要判断,是同一个treeview,上面能够拿到下面也可以拿到
                    Condition condition10 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
                    AutomationElementCollection modelCategoryElementCollection = treeViewModel.FindAll(TreeScope.Children, condition10);
                    if (modelCategoryElementCollection == null || modelCategoryElementCollection.Count == 0)
                    {
                        frontMessageBox("未找到主界面“模型”树形结构的子项");
                        return(false);
                    }
                    List <ModelCategory> modelCategories = new List <ModelCategory>();
                    bool foundModelCategory = false;
                    foreach (AutomationElement modelCategoryAE in modelCategoryElementCollection)
                    {
                        string modelCategoryName = modelCategoryAE.Current.Name;
                        if (string.IsNullOrEmpty(modelCategoryName))
                        {
                            continue;
                        }
                        if (modelCategoryName.StartsWith("回测"))
                        {
                            foundModelCategory = true;
                            if (!SimulateOperating.expandTreeItem(modelCategoryAE))
                            {
                                //展开失败
                                continue;
                            }
                            Condition condition11 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem);
                            AutomationElementCollection modelElementCollection = modelCategoryAE.FindAll(TreeScope.Children, condition11);
                            if (modelElementCollection == null && modelElementCollection.Count == 0)
                            {
                                //未找到自编下的子项
                                continue;
                            }
                            ModelCategory modelCategory = new ModelCategory();
                            modelCategory.modelCategoryName = modelCategoryName;
                            List <string> models = new List <string>();
                            foreach (AutomationElement modelAE in modelElementCollection)
                            {
                                models.Add(modelAE.Current.Name);
                            }
                            modelCategory.models = models;
                            modelCategories.Add(modelCategory);
                        }
                    }
                    if (!foundModelCategory)
                    {
                        frontMessageBox("未找到主界面“模型”树形结构中的“回测”子项");
                        return(false);
                    }
                    if (modelCategories == null || modelCategories.Count == 0)
                    {
                        frontMessageBox("未找到主界面“模型”树形结构中的回测模型,请补充!");
                        return(false);
                    }
                    fillTreeView(modelCategories);
                    return(true);
                }
            }

            if (!foundFutures)
            {
                frontMessageBox("未找到主界面“数据”树形结构中的“期货”子项");
                return(false);
            }
            return(false);
        }