/// <summary> /// 成功操作红字申请测试通过 /// </summary> public static void Method7() { var tableBar = (IntPtr)6227812; var childs = UiaHelper.GetUIAutomation().ElementFromHandle(tableBar). FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); for (var i = 1; i < childs.Length; i++) { var subChilds = childs.GetElement(i).FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); //对名称进行赋值 var pt3 = (IUIAutomationLegacyIAccessiblePattern)subChilds.GetElement(0) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt3.DoDefaultAction(); Thread.Sleep(500); var childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, $"AAA"); try { pt3.DoDefaultAction(); } catch (Exception e) { var noaddBar = WinApi.FindWindow(null, "商品编码添加"); Bug.WriteGoodsTaxNoAdd(noaddBar, "101010104"); Console.WriteLine(e); } //改变税率 var pt2 = (IUIAutomationLegacyIAccessiblePattern)subChilds.GetElement(6) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt2.DoDefaultAction(); childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, "17%"); Thread.Sleep(500); for (var j = 1; j < 8; j++) { var pt1 = (IUIAutomationLegacyIAccessiblePattern)subChilds.GetElement(j) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt1.Select(j); if (j == 0) { pt1.DoDefaultAction(); Thread.Sleep(500); var childinfos = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, $"{i}-{j}AAA"); try { pt1.DoDefaultAction(); } catch (Exception e) { var noaddBar = WinApi.FindWindow(null, "商品编码添加"); Bug.WriteGoodsTaxNoAdd(noaddBar, "101010104"); Console.WriteLine(e); } } else if (j == 1) { pt1.DoDefaultAction(); //pt1.SetValue("小"); var childinfos = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "小"); Thread.Sleep(100); } else if (j == 2) { pt1.DoDefaultAction(); var childinfos = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "kg"); Thread.Sleep(100); } else if (j == 3) { pt1.DoDefaultAction(); //pt1.SetValue("小"); var childinfos = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "-1"); Thread.Sleep(100); } else if (j == 4) { pt1.DoDefaultAction(); //pt1.SetValue("小"); var childinfos = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "100"); Thread.Sleep(100); pt1.DoDefaultAction(); Thread.Sleep(1000); } } } }
//普票测试通过 public static void Method8() { var winBar = WinApi.FindWindow(null, "开具增值税普通发票"); var winBarUia = UiaHelper.GetUIAutomation().ElementFromHandle(winBar); var toolBar = winBarUia.FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "toolStrip3")); for (var i = 0; i < 4; i++) { HxShengQing.ClickBtnByName(toolBar.CurrentNativeWindowHandle, "减行"); Thread.Sleep(100); } for (var i = 0; i < 4; i++) { ClickBtnUia(toolBar.CurrentNativeWindowHandle, "增行"); Thread.Sleep(100); } var dataGridUia = winBarUia.FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "DataGrid1")); var rectdatatable = dataGridUia.CurrentBoundingRectangle; var childs = dataGridUia.FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); for (var i = 2; i < childs.Length; i++) { var comElement = childs.GetElement(i); var rect = comElement.CurrentBoundingRectangle; var subChilds = childs.GetElement(i).FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); //对名称进行赋值 var pt3 = (IUIAutomationLegacyIAccessiblePattern)subChilds.GetElement(1) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); //pt3.DoDefaultAction(); Thread.Sleep(500); var childinfos1 = WinApi.EnumChildWindowsCallback(dataGridUia.CurrentNativeWindowHandle); WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, $"AAA"); try { //pt3.DoDefaultAction(); } catch (Exception e) { var noaddBar = WinApi.FindWindow(null, "商品编码添加"); Bug.WriteGoodsTaxNoAdd(noaddBar, "101010104"); Console.WriteLine(e); } //改变税率 var subElement = subChilds.GetElement(7); var retcsub = subElement.CurrentBoundingRectangle; var pt2 = (IUIAutomationLegacyIAccessiblePattern)subChilds.GetElement(7) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt2.DoDefaultAction(); childinfos1 = WinApi.EnumChildWindowsCallback(dataGridUia.CurrentNativeWindowHandle); UIHelper.SetCombox(childinfos1[1].hWnd, "17%"); //WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, "17%"); Thread.Sleep(500); for (var j = 2; j < 6; j++) { var pt1 = (IUIAutomationLegacyIAccessiblePattern)subChilds.GetElement(j) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); if (j == 2) { pt1.DoDefaultAction(); var childinfos = WinApi.EnumChildWindowsCallback(dataGridUia.CurrentNativeWindowHandle); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "小"); Thread.Sleep(100); } else if (j == 3) { pt1.DoDefaultAction(); var childinfos = WinApi.EnumChildWindowsCallback(dataGridUia.CurrentNativeWindowHandle); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "kg"); Thread.Sleep(100); } else if (j == 4) { pt1.DoDefaultAction(); var childinfos = WinApi.EnumChildWindowsCallback(dataGridUia.CurrentNativeWindowHandle); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "3"); Thread.Sleep(100); } else if (j == 5) { pt1.DoDefaultAction(); var childinfos = WinApi.EnumChildWindowsCallback(dataGridUia.CurrentNativeWindowHandle); WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "100"); Thread.Sleep(100); pt1.DoDefaultAction(); Thread.Sleep(1000); } } } }
/// <summary> /// 卷票测试--通过--有点小问题需要调整--调整完毕,大于5的话从4开始,其他从3开始--默认五条数据 /// </summary> public static void Method10() { var winBar = WinApi.FindWindow(null, "开具增值税普通发票(卷票)"); var winBarUia = UiaHelper.GetUIAutomation().ElementFromHandle(winBar); var toolBarUia = winBarUia.FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "toolStrip3")); var dataGridUia = winBarUia.FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "DataGrid1")); var tableBar = (IntPtr)dataGridUia.CurrentNativeWindowHandle; var shouhangRetc = dataGridUia.FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_NamePropertyId, "首行")).CurrentBoundingRectangle; for (var i = 0; i < 2; i++) { HxShengQing.ClickBtnByName(toolBarUia.CurrentNativeWindowHandle, "减行"); Thread.Sleep(100); } for (var i = 0; i < 3; i++) { ClickBtnUia(toolBarUia.CurrentNativeWindowHandle, "增行"); Thread.Sleep(500); //对名称进行赋值 var childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, $"uuyy{i}"); var element = dataGridUia.FindFirst(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation() .CreatePropertyCondition( UIA_PropertyIds.UIA_NamePropertyId, $"行 {i}")); var elementChilds = element.FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); var pt2 = (IUIAutomationLegacyIAccessiblePattern)elementChilds.GetElement(2) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); var rectcol2 = elementChilds.GetElement(2).CurrentBoundingRectangle; //触发商品编码添加窗体 pt2.DoDefaultAction(); Thread.Sleep(2000); var noaddBar = WinApi.FindWindow(null, "商品编码添加"); if (noaddBar != IntPtr.Zero) { Bug.WriteGoodsTaxNoAdd(noaddBar, "101010104"); Thread.Sleep(500); WinApi.ClickLocation(tableBar, rectcol2.left - shouhangRetc.left + 10, rectcol2.top - shouhangRetc.top + 10); Thread.Sleep(500); } childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, "2.00"); var pt3 = (IUIAutomationLegacyIAccessiblePattern)elementChilds.GetElement(3) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt3.DoDefaultAction(); Thread.Sleep(500); childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, "200.00"); pt3.DoDefaultAction(); Thread.Sleep(500); var rect = elementChilds.GetElement(5).CurrentBoundingRectangle; WinApi.ClickLocation(tableBar, rect.left - shouhangRetc.left + 10, rect.top - shouhangRetc.top + 10); Thread.Sleep(500); childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); //修改税率 UIHelper.SetCombox(childinfos1.Find(b => b.szClassName.Contains("COMBOBOX")).hWnd, "17%"); } Console.WriteLine("success..."); }
/// <summary> /// 红字申请测试 /// </summary> public static void Method14() { Thread.Sleep(10000); var winBar = WinApi.FindWindow(null, "增值税发票税控开票软件(金税盘版) V2.2.34.190628 - [红字发票信息表填开]"); var tkUia = UiaHelper.GetUIAutomation().ElementFromHandle(winBar).FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "SqdTianKai")); var toolBarUia = tkUia.FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation() .CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "toolStrip2")); for (var i = 0; i < 7; i++) { HxShengQing.ClickBtnByName(toolBarUia.CurrentNativeWindowHandle, "增行"); Thread.Sleep(100); } var tableUia = tkUia.FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_NamePropertyId, "DataGridView")); var tableBar = tableUia.CurrentNativeWindowHandle; var shUia = tableUia.FindFirst(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation() .CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "首行")); var shRect = shUia.CurrentBoundingRectangle; for (var i = 0; i < 8; i++) { var row = tableUia.FindFirst(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation() .CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, $"行 {i}")); var cols = row.FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); Console.WriteLine($"{i}:col0:{cols.GetElement(0).CurrentName},col1:{cols.GetElement(1).CurrentName}"); var nameRect = cols.GetElement(0).CurrentBoundingRectangle; WinApi.ClickLocation(tableBar, nameRect.left - shRect.left + 50, nameRect.top - shRect.top + 10); Thread.Sleep(100); WinApi.ClickLocation(tableBar, nameRect.left - shRect.left + 50, nameRect.top - shRect.top + 10); Thread.Sleep(500); var childs = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childs[childs.Count - 1].hWnd, 12, IntPtr.Zero, $"BBB{i}"); WinApi.SendKey(tableBar, 9);//发送tab按键 //var guigeRect = cols.GetElement(1).CurrentBoundingRectangle; //WinApi.ClickLocation(tableBar, guigeRect.left - shRect.left + 10, guigeRect.top - shRect.top + 10); Thread.Sleep(2000); var noaddBar = WinApi.FindWindow(null, "商品编码添加"); if (noaddBar != IntPtr.Zero) { Bug.WriteGoodsTaxNoAdd(noaddBar, "101010104"); Thread.Sleep(500); } var pt1 = (IUIAutomationLegacyIAccessiblePattern)cols.GetElement(1) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt1.DoDefaultAction(); Thread.Sleep(500); childs = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childs[childs.Count - 1].hWnd, 12, IntPtr.Zero, "大"); pt1.DoDefaultAction(); Thread.Sleep(200); var pt6 = (IUIAutomationLegacyIAccessiblePattern)cols.GetElement(6) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt6.DoDefaultAction(); Thread.Sleep(500); childs = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childs[childs.Count - 1].hWnd, 12, IntPtr.Zero, "10%"); Thread.Sleep(500); pt6.DoDefaultAction(); Thread.Sleep(500); //var danweiRect = cols.GetElement(2).CurrentBoundingRectangle; //WinApi.ClickLocation(tableBar, danweiRect.left - shRect.left + 10, danweiRect.top - shRect.top + 10); var pt2 = (IUIAutomationLegacyIAccessiblePattern)cols.GetElement(2) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt2.DoDefaultAction(); Thread.Sleep(500); childs = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childs[childs.Count - 1].hWnd, 12, IntPtr.Zero, "kg"); //var numRect = cols.GetElement(3).CurrentBoundingRectangle; //WinApi.ClickLocation(tableBar, numRect.left - shRect.left + 10, numRect.top - shRect.top + 10); var pt3 = (IUIAutomationLegacyIAccessiblePattern)cols.GetElement(3) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt3.DoDefaultAction(); Thread.Sleep(500); childs = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childs[childs.Count - 1].hWnd, 12, IntPtr.Zero, "-3"); //var priceRect = cols.GetElement(4).CurrentBoundingRectangle; //WinApi.ClickLocation(tableBar, priceRect.left - shRect.left + 10, priceRect.top - shRect.top + 10); var pt4 = (IUIAutomationLegacyIAccessiblePattern)cols.GetElement(4) .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt4.DoDefaultAction(); Thread.Sleep(500); childs = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childs[childs.Count - 1].hWnd, 12, IntPtr.Zero, "100.00"); Thread.Sleep(100); pt4.DoDefaultAction(); Thread.Sleep(500); } }
//卷票调整 public static void Method13() { var winBar = WinApi.FindWindow(null, "开具增值税普通发票(卷票)"); var winBarUia = UiaHelper.GetUIAutomation().ElementFromHandle(winBar); var dataGridUia = winBarUia.FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation() .CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "DataGrid1")); var tableBar = (IntPtr)dataGridUia.CurrentNativeWindowHandle; var childs = dataGridUia.FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); var count = childs.Length; for (var i = 0; i < count; i++) { dataGridUia = winBarUia.FindFirst(TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation() .CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "DataGrid1")); childs = dataGridUia.FindAll(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); var uiarow = dataGridUia.FindFirst(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_NamePropertyId, $"行 {i}")); Console.WriteLine($"uiarow.CurrentName:{uiarow.CurrentName}"); var uiaxiangmu = uiarow.FindFirst(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_NamePropertyId, $"项目 行 {i}")); Console.WriteLine($"uiaxiangmu.CurrentName:{uiaxiangmu.CurrentName}"); var uiashuilv = uiarow.FindFirst(TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_NamePropertyId, $"税率 行 {i}")); Console.WriteLine($"uiashuilv.CurrentName:{uiashuilv.CurrentName}"); //var subChilds = childs.GetElement(i).FindAll(TreeScope.TreeScope_Children, // UiaHelper.GetUIAutomation().CreateTrueCondition()); //对名称进行赋值 var pt3 = (IUIAutomationLegacyIAccessiblePattern)uiaxiangmu .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt3.DoDefaultAction(); Thread.Sleep(500); var childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); WinApi.SendMessage(childinfos1[childinfos1.Count - 1].hWnd, 12, IntPtr.Zero, "Hello world"); try { pt3.DoDefaultAction(); } catch (Exception e) { var noaddBar = WinApi.FindWindow(null, "商品编码添加"); Bug.WriteGoodsTaxNoAdd(noaddBar, "101010104"); Console.WriteLine(e); } //改变税率 var pt2 = (IUIAutomationLegacyIAccessiblePattern)uiashuilv .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); pt2.DoDefaultAction(); Thread.Sleep(100); pt2.DoDefaultAction(); childinfos1 = WinApi.EnumChildWindowsCallback(tableBar); UIHelper.SetCombox(childinfos1.Find(b => b.szClassName.Contains("COMBOBOX")).hWnd, "17%"); Thread.Sleep(500); //for (var j = 2; j < 5; j++) //{ // var pt1 = (IUIAutomationLegacyIAccessiblePattern) subChilds.GetElement(j) // .GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId); // if (j == 2) // { // pt1.DoDefaultAction(); // var childinfos = WinApi.EnumChildWindowsCallback(tableBar); // WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "2"); // Thread.Sleep(100); // } // else if (j == 3) // { // pt1.DoDefaultAction(); // var childinfos = WinApi.EnumChildWindowsCallback(tableBar); // WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "25"); // Thread.Sleep(100); // } // else if (j == 4) // { // pt1.DoDefaultAction(); // var childinfos = WinApi.EnumChildWindowsCallback(tableBar); // WinApi.SendMessage(childinfos[childinfos.Count - 1].hWnd, 12, IntPtr.Zero, "50"); // Thread.Sleep(100); // } //} } }