Example #1
0
        /// <summary>
        /// 点击发票填开
        /// </summary>
        public static void Step1()
        {
            var mainBar = WinApi.FindWindow(null, "增值税发票税控开票软件(金税盘版) V2.2.34.190427");//需要改动,模糊查询所有窗体
            var bar     = WinApi.FindWindowEx(mainBar, IntPtr.Zero, null, null);

            HxShengQing.ClickBtnByName(bar, "发票管理");//点击发票管理

            //找信息表管理父句柄
            var barInfoList   = WinApi.EnumChildWindowsCallback(mainBar);
            var infoParentBar = IntPtr.Zero;

            barInfoList.ForEach(i => {
                if (i.szWindowName == "发票管理")
                {
                    infoParentBar = i.hWnd;
                }
            });
            infoParentBar = WinApi.FindWindowEx(infoParentBar, IntPtr.Zero, null, null);
            var infoBar = WinApi.FindWindowEx(infoParentBar, IntPtr.Zero, null, null);

            WinApi.LeftClick(infoBar);//点击信息表成功

            //打开红字增值税专用发票信息表信息选择--没有防遮挡
            WinApi.keybd_event(VBKEY.vbKeyDown, 0, 0, 0);
            Thread.Sleep(100);
            WinApi.keybd_event(VBKEY.vbKeyReturn, 0, 0, 0);
        }
Example #2
0
        /// <summary>
        /// 折扣处理,正式环境下折扣行只会有一行。
        /// </summary>
        public static void step4()
        {
            //获取所有桌面窗体句柄
            var alldeskBar = WinApi.FindChildInfo(IntPtr.Zero);

            //获取开票软件句柄
            var kprjBar = alldeskBar.Find(bar => bar.szWindowName != null && bar.szWindowName.Contains("开票软件"));

            //获取开票软件下面的所有子句柄
            var kprjList = WinApi.EnumChildWindowsCallback(kprjBar.hWnd);

            //获取红字信息填开句柄--模糊查询
            var hzxxtkBar = kprjList.Find(bar =>
                                          bar.szWindowName != null && bar.szWindowName.Contains("红字发票信息表填开"));

            //三个--最后一个对应toolBar
            var hzxxtklist = WinApi.FindChildInfo(hzxxtkBar.hWnd);

            //点击差额征税按钮
            HxShengQing.ClickBtnByName(hzxxtklist[hzxxtklist.Count - 1].hWnd, "差额");

            var zhekouWinBar = WinApi.FindWindow(null, "输入扣除额");
            var zhekouBar    = WinApi.FindWindowEx(zhekouWinBar, IntPtr.Zero, null, null);
            var zhekouList   = WinApi.FindChildBar(zhekouBar);

            //这是确定按钮
            var confirmBar = zhekouList[0];
            var amountBar  = zhekouList[zhekouList.Count - 1];

            //输入折扣金额
            WinApi.SendMessage(amountBar, 0X0C, IntPtr.Zero, "10");
            Thread.Sleep(1000);
            //点击确定按钮
            WinApi.LeftClickMsg(confirmBar);
        }
Example #3
0
        //税收分类编码添加
        public static void WriteGoodsTaxNoAdd(IntPtr goodNoAddHw, string goodsTaxNo = "")
        {
            //税收分类编码
            var ssflbmBar = IntPtr.Zero;
            var toolStrip = IntPtr.Zero;

            var flag = HxShengQing.TryRetry(str =>
            {
                var childInfos = WinApi.FindChildInfo(goodNoAddHw);
                if (childInfos == null || childInfos.Count < 30)
                {
                    return(false);
                }

                //获取分类名称
                var flmnBar = childInfos.Find(b => b.szWindowName == "税收分类名称").hWnd;
                var temp1   = WinApi.FindWindowEx(goodNoAddHw, flmnBar, null, null);
                var temp2   = WinApi.FindWindowEx(temp1, IntPtr.Zero, null, null);
                ssflbmBar   = WinApi.FindWindowEx(temp1, temp2, null, null);

                //获取toolStrip
                toolStrip = childInfos.Find(b => b.szWindowName == "toolStrip1").hWnd;


                return(ssflbmBar != IntPtr.Zero && toolStrip != IntPtr.Zero);
            }, "", 40, 500);

            WinApi.SendMessage(ssflbmBar, WinApi.BM_TEXT, IntPtr.Zero, TaxSub(goodsTaxNo));
            Thread.Sleep(500);

            HxShengQing.ClickBtnByName(toolStrip, "保存");
        }
Example #4
0
        /// <summary>
        /// 开票软件前置,detail填写,暂时这样--如果分辨率调整肯定会受到影响的
        /// </summary>
        static void InfoTianKai()
        {
            Thread.Sleep(100);
            WinApi.ShowWindow((IntPtr)1442640, 2);
            Thread.Sleep(100);
            WinApi.ShowWindow((IntPtr)1442640, 3);
            Thread.Sleep(100);
            WinApi.SetFocus((IntPtr)1442640);
            Thread.Sleep(100);
            WinApi.SetForegroundWindow((IntPtr)1442640);


            Thread.Sleep(2000);
            for (var i = 0; i < 5; i++)
            {
                WinApi.ClickLocation((IntPtr)7145062, 10, 25 + 23 * i + 12); //可以点中第一行第一块
                HxShengQing.GetTableFocus();
                Thread.Sleep(100);
                SendKeys.SendWait($"{i}aaaaa");
                WinApi.keybd_event(Keys.Tab, 0, 0, 0);
                HxShengQing.WriteGoodsTaxNoAdd(IntPtr.Zero, null);
                Thread.Sleep(1000);
                HxShengQing.ClickBtnByName((IntPtr)7472786, "增行");
                Thread.Sleep(1000);
            }
        }
Example #5
0
        /// <summary>
        /// 根据信息表流水账号,查询对应的信息表流水账号账单并点击上传按钮
        /// </summary>
        public static void step7()
        {
            //获取所有桌面窗体句柄
            var alldeskBar = WinApi.FindChildInfo(IntPtr.Zero);

            //获取开票软件句柄
            var kprjBar = alldeskBar.Find(bar => bar.szWindowName != null && bar.szWindowName.Contains("开票软件"));

            //获取开票软件下面的所有子句柄
            var kprjList = WinApi.EnumChildWindowsCallback(kprjBar.hWnd);

            //获取toolStrip1句柄
            var toolStripBar = kprjList.Find(bar =>
                                             bar.szWindowName != null && bar.szWindowName == "toolStrip1");


            var inputTextBar = WinApi.FindWindowEx(toolStripBar.hWnd, IntPtr.Zero, null, null);

            WinApi.SendMessage(inputTextBar, 0X0C, IntPtr.Zero, "661735289405190530193705");
            Thread.Sleep(1000);
            WinApi.SendKey(inputTextBar, KeySnap.VK_ENTER);

            var indexClickBar = 0;

            for (var i = 0; i < kprjList.Count; i++)
            {
                if (kprjList[i].szWindowName == "红字发票信息表查询导出")
                {
                    indexClickBar = i + 2;
                }
            }
            //ClickBtnByName(kprjList[indexClickBar].hWnd, "");
            WinApi.ClickLocation(kprjList[indexClickBar].hWnd, 10, 55);
            HxShengQing.ClickBtnByName(toolStripBar.hWnd, "上传");
        }
Example #6
0
        public static void GetDropDown()
        {
            var winBar  = WinApi.FindWindow(null, "开具增值税专用发票");
            var toolBar = WinApi.EnumChilWindowsIntptr(winBar).LastOrDefault();

            HxShengQing.ClickBtnByName(toolBar, "红字");
            Thread.Sleep(500);
            var dropDown = WinApi.FindWindowEx(winBar, IntPtr.Zero, null, null);

            WinApi.SendKey(dropDown, WinApi.VK_UP);
            Thread.Sleep(100);
            WinApi.SendKey(dropDown, WinApi.VK_RETURN);
            Thread.Sleep(100);
        }
Example #7
0
        /// <summary>
        /// 操作红字增值税专用发票信息表信息选择
        /// </summary>
        public static void Step2()
        {
            var zhuanRedBar = IntPtr.Zero;

            zhuanRedBar = HxShengQing.TryRetry <string, IntPtr>(
                str => WinApi.FindWindow(null, str), "红字增值税专用发票信息表信息选择",
                20, 500);
            if (zhuanRedBar == IntPtr.Zero)
            {
                //日志--红字增值税专用发票信息表信息选择查找失败
                return;
            }

            Thread.Sleep(500);

            HxShengQing.TryRetry <IntPtr, bool>(bar =>
            {
                var list = WinApi.EnumChildWindowsCallback(bar);
                var PurchaserApplicationBar = list.Find(b => b.szWindowName == "一、购买方申请");
                var SalesAllicationBar      = list.Find(b => b.szWindowName == "二、销售方申请");
                var DeductedBar             = list.Find(b => b.szWindowName == "1、已抵扣");
                var UnDeductedBar           = list.Find(b => b.szWindowName == "2、未抵扣");
                var FpInputBar = list.Find(b => b.szWindowName == "对应蓝字增值税专用发票信息");
                if (PurchaserApplicationBar.hWnd == IntPtr.Zero || SalesAllicationBar.hWnd == IntPtr.Zero ||
                    DeductedBar.hWnd == IntPtr.Zero || UnDeductedBar.hWnd == IntPtr.Zero || FpInputBar.hWnd == IntPtr.Zero)
                {
                    return(false);
                }

                //这里是判断条件--真实业务的时候添加
                Thread.Sleep(1000);
                WinApi.LeftClick(SalesAllicationBar.hWnd);//点击rediobutton
                Thread.Sleep(1000);

                var FpInputList = WinApi.FindChildBar(FpInputBar.hWnd);
                WinApi.SendMessage(FpInputList[0], 0X0C, IntPtr.Zero, "123456"); //发票号码
                WinApi.SendMessage(FpInputList[1], 0X0C, IntPtr.Zero, "654321"); //发票代码


                //Thread.Sleep(1000);
                //WinApi.LeftClick(PurchaserApplicationBar.hWnd);
                //Thread.Sleep(1000);
                //WinApi.LeftClick(DeductedBar.hWnd);
                //Thread.Sleep(1000);
                //WinApi.LeftClick(UnDeductedBar.hWnd);

                return(true);
            }, zhuanRedBar, 20, 500);
        }
Example #8
0
        //关闭window窗体
        public static void CloseWindow()
        {
            //获取开票软件主窗体
            var kprjBar = HxShengQing.GetKprjMainPageBar();

            if (kprjBar == IntPtr.Zero)
            {
                return;
            }
            //前置主窗体
            ShowForm(kprjBar);


            var list = WinApi.EnumChildWindowsCallback(kprjBar);
            var bar  = list.Find(b => b.szWindowName == "红字发票信息表查询导出").hWnd;

            var barMation = AutomationElement.FromHandle(bar);

            barMation.TryGetCurrentPattern(WindowPattern.Pattern, out var obj);
            ((WindowPattern)obj).Close();
        }
Example #9
0
        /// <summary>
        /// 对名称和识别号进行赋值
        /// </summary>
        public static void step3()
        {
            //获取所有桌面窗体句柄
            var alldeskBar = WinApi.FindChildInfo(IntPtr.Zero);

            //获取开票软件句柄
            var kprjBar = alldeskBar.Find(bar => bar.szWindowName != null && bar.szWindowName.Contains("开票软件"));

            //获取开票软件下面的所有子句柄
            var kprjList = WinApi.EnumChildWindowsCallback(kprjBar.hWnd);

            //获取红字信息填开句柄--模糊查询
            var hzxxtkBar = kprjList.Find(bar =>
                                          bar.szWindowName != null && bar.szWindowName.Contains("红字发票信息表填开"));

            //三个--最后一个对应toolBar
            var hzxxtklist = WinApi.FindChildInfo(hzxxtkBar.hWnd);

            var hzxxtkInfoList  = WinApi.FindChildInfo(hzxxtklist[0].hWnd);
            var hzxxtkInfoChild = WinApi.FindChildInfo(hzxxtkInfoList[2].hWnd);
            var sfxxlist        = WinApi.FindChildInfo(hzxxtkInfoChild[1].hWnd);

            //对销方名称进行赋值
            var mclist = WinApi.FindChildBar(sfxxlist[1].hWnd);

            mclist.ForEach(mc => WinApi.SendMessage(mc, 0x0C, IntPtr.Zero, "名称测试"));

            //对纳税人识别号进行赋值
            var bmlist = WinApi.FindChildBar(sfxxlist[0].hWnd);

            bmlist.ForEach(mc => WinApi.SendMessage(mc, 0x0C, IntPtr.Zero, "12345678901234567"));

            //点击价格

            //ClickBtnByName(hzxxtklist[hzxxtklist.Count - 1].hWnd, "价格");//这里貌似不需要点击 默认都是不含税
            HxShengQing.ClickBtnByName(hzxxtklist[hzxxtklist.Count - 1].hWnd, "价格");//这里貌似不需要点击 默认都是不含税
        }
Example #10
0
        public static void WriteGoodsSetting(IntPtr goodNoSettingHw, string taxPer = "", string taxPerCon = "", string taxRate = "")
        {
            if (goodNoSettingHw == IntPtr.Zero)
            {
                return;
            }

            var suilvBar  = IntPtr.Zero;
            var yhBar     = IntPtr.Zero;
            var yhlBar    = IntPtr.Zero;
            var toolStrip = IntPtr.Zero;

            TryRetry(str =>
            {
                var childInfos = WinApi.FindChildInfo(goodNoSettingHw);
                if (childInfos == null || childInfos.Count < 11)
                {
                    return(false);
                }

                //获取toolStrip
                toolStrip = childInfos.Find(b => b.szWindowName == "toolStrip1").hWnd;

                //税率句柄
                suilvBar = childInfos[10].hWnd;

                //享受优惠政策
                yhBar = childInfos[8].hWnd;

                //优惠政策类型
                yhlBar = childInfos[5].hWnd;

                return(toolStrip != IntPtr.Zero && suilvBar != IntPtr.Zero &&
                       yhBar != IntPtr.Zero && yhlBar != IntPtr.Zero);
            }, "", 20, 500);

            if (toolStrip == IntPtr.Zero || suilvBar == IntPtr.Zero || yhBar == IntPtr.Zero || yhlBar == IntPtr.Zero)
            {
                //AmLogger.Error("WriteGoodsSetting", $"税收分类编码设置窗体,控件句柄获取失败");
                //throw new AmExceptionCode("税收分类编码设置窗体,控件句柄获取失败");
            }

            if ("1".Equals(taxPer) && !string.IsNullOrEmpty(taxPerCon))
            {
                UIHelper.SetCombox(yhBar, "是");

                //等待优惠政策enable
                Thread.Sleep(1000);
                UIHelper.SetCombox(yhlBar, taxPerCon.Trim());
            }
            else
            {
                UIHelper.SetCombox(suilvBar, HxShengQing.GetByTaxRate(taxRate));
            }

            HxShengQing.ClickBtnByName(toolStrip, "保存");
            Thread.Sleep(1000);

            HxShengQing.SystemOpera("确认", out var message);
            if (message != "修改成功!")
            {
                throw new Exception(message);
            }
            //AmLogger.Info("WriteGoodsSetting", $"税收分类编码设置窗体,设置成功");
        }
Example #11
0
        /// <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);
            }
        }
Example #12
0
        //发票确认重构
        public static bool ClickVerifyInvoicePage(ref string invoiceCode, ref string invoiceNo,
                                                  ref string invoiceType, bool isEnter = true)
        {
            var formBar = HxShengQing.TryRetry(str => WinApi.FindWindow(null, "发票号码确认"), "", 40, 500);

            var dmInfo          = new WindowInfo();
            var hmInfo          = new WindowInfo();
            var invoiceTypeInfo = new WindowInfo();
            var confirmBar      = IntPtr.Zero;
            var cancelBar       = IntPtr.Zero;

            var flag = HxShengQing.TryRetry(str =>
            {
                var childs = WinApi.EnumChildWindowsCallback(formBar);
                if (childs.Count < 10)
                {
                    return(false);
                }
                if (childs[7].szWindowName.Length == 10 || childs[7].szWindowName.Length == 12)
                {
                    dmInfo = childs[7];
                }
                else
                {
                    dmInfo = childs.FirstOrDefault(info =>
                                                   info.szWindowName.Length == 10 || info.szWindowName.Length == 12);
                }
                if (childs[5].szWindowName.Length == 8)
                {
                    hmInfo = childs[5];
                }
                else
                {
                    hmInfo = childs.FirstOrDefault(info => info.szWindowName.Length == 8 && int.TryParse(info.szWindowName, out var hm));
                }
                invoiceTypeInfo = childs[4];
                confirmBar      = childs.FirstOrDefault(b => b.szWindowName == "确认").hWnd;
                cancelBar       = childs.FirstOrDefault(b => b.szWindowName == "取消").hWnd;
                return(confirmBar != IntPtr.Zero && cancelBar != IntPtr.Zero && !string.IsNullOrEmpty(invoiceTypeInfo.szWindowName) &&
                       !string.IsNullOrEmpty(dmInfo.szWindowName) && !string.IsNullOrEmpty(hmInfo.szWindowName));
            }, "", 10, 500);

            //赋值
            invoiceNo   = hmInfo.szWindowName;
            invoiceCode = dmInfo.szWindowName;
            invoiceType = invoiceTypeInfo.szWindowName;


            if (isEnter)
            {
                for (var i = 0; i < 10; i++)
                {
                    WinApi.LeftClick(confirmBar);
                    Thread.Sleep(1000);
                    formBar = WinApi.FindWindow(null, "发票号码确认");
                    if (formBar == IntPtr.Zero)
                    {
                        break;
                    }
                }
            }
            else
            {
                WinApi.LeftClick(cancelBar);
            }

            return(true);
        }
Example #13
0
        /// <summary>
        /// 红冲信息表下载demo,缺少成功验证逻辑
        /// </summary>
        public static void downLoadInfo()
        {
            var infoBar   = WinApi.FindWindow(null, "信息表选择");
            var list      = WinApi.EnumChildWindowsCallback(infoBar);
            var toolStrip = list.Find(bar => bar.szWindowName == "toolStrip1");

            if (toolStrip.hWnd == IntPtr.Zero)
            {
                return;
            }

            ClickBtnByName(toolStrip.hWnd, "下载");
            Thread.Sleep(500);

            var beginDateBar = IntPtr.Zero;
            var endDateBar   = IntPtr.Zero;

            var purTaxNoBar  = IntPtr.Zero;
            var saleTaxNoBar = IntPtr.Zero;
            var infoBhBar    = IntPtr.Zero;

            var confirmBar = IntPtr.Zero;

            HxShengQing.TryRetry(str =>
            {
                var downinfoBar = WinApi.FindWindow(null, str);
                var infoChilds  = WinApi.FindChildInfo(downinfoBar);
                confirmBar      = infoChilds.Find(b => b.szWindowName == "确定").hWnd;

                var infoTableInfoBar = infoChilds.Find(b => b.szWindowName == "信息表信息");
                var infoTableChilds  = WinApi.FindChildBar(infoTableInfoBar.hWnd);
                purTaxNoBar          = infoTableChilds[5];
                saleTaxNoBar         = infoTableChilds[4];
                infoBhBar            = infoTableChilds[1];

                var dateBar    = infoChilds.Find(b => b.szWindowName == "填开日期");
                var dateChilds = WinApi.FindChildBar(dateBar.hWnd);
                beginDateBar   = dateChilds[1];
                endDateBar     = dateChilds[0];

                if (beginDateBar == IntPtr.Zero || endDateBar == IntPtr.Zero ||
                    purTaxNoBar == IntPtr.Zero || saleTaxNoBar == IntPtr.Zero ||
                    infoBhBar == IntPtr.Zero || confirmBar == IntPtr.Zero)
                {
                    return(false);
                }
                return(true);
            }, "红字发票信息表审核结果下载条件设置");

            WinApi.LeftClick(beginDateBar);
            Thread.Sleep(500);
            //修改填开日期起为2018-1-1
            Thread.Sleep(100);
            SendKeys.SendWait("2018");
            Thread.Sleep(100);
            SendKeys.SendWait("{right}");
            Thread.Sleep(100);
            SendKeys.SendWait("01");
            Thread.Sleep(100);
            SendKeys.SendWait("{right}");
            Thread.Sleep(100);
            SendKeys.SendWait("01");

            Thread.Sleep(100);
            WinApi.SendMessage(purTaxNoBar, 0X0C, IntPtr.Zero, "1234567890");
            Thread.Sleep(100);
            WinApi.SendMessage(saleTaxNoBar, 0X0C, IntPtr.Zero, "0987654321");
            Thread.Sleep(100);
            WinApi.SendMessage(infoBhBar, 0X0C, IntPtr.Zero, "12345678901234567");
            Thread.Sleep(500);

            WinApi.LeftClick(confirmBar);

            var infoDownLoadBar = HxShengQing.TryRetry(str => WinApi.FindWindow(null, str), "信息表下载中");

            if (infoDownLoadBar != IntPtr.Zero)
            {
                for (var i = 0; i < 100; i++)
                {
                    infoDownLoadBar = WinApi.FindWindow(null, "信息表下载中");
                    var SysMessageBox = WinApi.FindWindow(null, "SysMessageBox");
                    if (SysMessageBox != IntPtr.Zero)
                    {
                        HxShengQing.SystemOpera("确认");
                        break;
                    }
                    if (infoDownLoadBar == IntPtr.Zero)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
            }
        }
Example #14
0
        public static void JuanPiaoTianKai(Entitys.InvoiceInfo invoiceInfo)
        {
            //有时候会有插件加载
            Thread.Sleep(3000);

            var winJuanBar    = IntPtr.Zero;
            var toolBar       = IntPtr.Zero;
            var dataBar       = IntPtr.Zero;
            var FPtiankai_new = IntPtr.Zero;

            //购方名称
            var gfmcBar = IntPtr.Zero;

            //纳税人识别号
            var nsrsbhBar = IntPtr.Zero;

            //收款员
            var skyBar = IntPtr.Zero;

            //备注
            var remarkBar = IntPtr.Zero;

            var flag = TryRetry(str =>
            {
                winJuanBar = WinApi.FindWindow(null, str);
                if (winJuanBar == IntPtr.Zero)
                {
                    return(false);
                }
                var child  = WinApi.FindWindowEx(winJuanBar, IntPtr.Zero, null, "FPtiankai_new");
                var child1 = WinApi.FindWindowEx(child, IntPtr.Zero, null, null);
                toolBar    = WinApi.FindWindowEx(child, child1, null, null);

                var parentBar = WinApi.FindWindowEx(child1, IntPtr.Zero, null, null);
                var childs    = WinApi.FindChildBar(parentBar);

                skyBar    = childs[18];
                remarkBar = childs[19];
                gfmcBar   = childs[childs.Count - 1];
                nsrsbhBar = childs[childs.Count - 2];
                dataBar   = childs[childs.Count - 5];

                if (toolBar == IntPtr.Zero || skyBar == IntPtr.Zero || remarkBar == IntPtr.Zero ||
                    gfmcBar == IntPtr.Zero || nsrsbhBar == IntPtr.Zero || dataBar == IntPtr.Zero)
                {
                    return(false);
                }
                return(true);
            }, "开具增值税普通发票(卷票)", 20, 500);

            if (flag == false)
            {
                Console.Write("句柄查找错误");
                return;
            }

            //窗体前置
            SetForHead(winJuanBar, false);
            Thread.Sleep(100);

            HxShengQing.ClickBtnByName(toolBar, "减行");

            //填写备注
            if (!string.IsNullOrEmpty(invoiceInfo?.Head.Remark))
            {
                WinApi.SendMessage(remarkBar, WinApi.BM_TEXT, IntPtr.Zero, invoiceInfo?.Head.Remark);
            }

            //收款人
            if (!string.IsNullOrEmpty(invoiceInfo?.Head.CashierName))
            {
                var nsMation = AutomationElement.FromHandle(skyBar);
                var temp     = nsMation.FindFirst(TreeScope.Children,
                                                  new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
                if (temp != null)
                {
                    temp.TryGetCurrentPattern(ValuePattern.Pattern, out var objPattern);
                    ((ValuePattern)objPattern)?.SetValue(invoiceInfo?.Head.CashierName);
                }
                else
                {
                    var list = WinApi.FindChildBar(skyBar);
                    foreach (var b in list)
                    {
                        WinApi.SendMessage(b, WinApi.BM_TEXT, IntPtr.Zero, invoiceInfo?.Head.CashierName);
                    }
                }
            }

            //填写购买方名称
            if (!string.IsNullOrEmpty(invoiceInfo?.Head.PurchaserName))
            {
                var nsMation = AutomationElement.FromHandle(gfmcBar);
                var temp     = nsMation.FindFirst(TreeScope.Children,
                                                  new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
                if (temp != null)
                {
                    temp.TryGetCurrentPattern(ValuePattern.Pattern, out var objPattern);
                    ((ValuePattern)objPattern)?.SetValue(invoiceInfo?.Head.PurchaserName);
                }
                else
                {
                    var list = WinApi.FindChildBar(gfmcBar);
                    foreach (var b in list)
                    {
                        WinApi.SendMessage(b, WinApi.BM_TEXT, IntPtr.Zero, invoiceInfo?.Head.PurchaserName);
                    }
                }
                Thread.Sleep(500);
                WinApi.keybd_event(Keys.Down, 0, 0, 0);
                Thread.Sleep(500);
                WinApi.keybd_event(Keys.Enter, 0, 0, 0);
            }

            //填写纳税人识别号
            if (!string.IsNullOrEmpty(invoiceInfo?.Head.PurchaserTaxNo))
            {
                //var txtbar = WinApi.FindChildInfo(nsrsbhBar);

                var nsMation = AutomationElement.FromHandle(nsrsbhBar);
                var temp     = nsMation.FindFirst(TreeScope.Children,
                                                  new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
                if (temp != null)
                {
                    temp.TryGetCurrentPattern(ValuePattern.Pattern, out var objPattern);
                    if (((ValuePattern)objPattern)?.Current.Value != invoiceInfo?.Head.PurchaserTaxNo)
                    {
                        ((ValuePattern)objPattern)?.SetValue(invoiceInfo?.Head.PurchaserTaxNo);
                    }
                }
                else
                {
                    var list = WinApi.FindChildBar(nsrsbhBar);
                    foreach (var b in list)
                    {
                        WinApi.SendMessage(b, WinApi.BM_TEXT, IntPtr.Zero, invoiceInfo?.Head.PurchaserTaxNo);
                    }
                }
                WinApi.ClickLocation(FPtiankai_new, 100, 100);
            }

            //填写明细
            for (var i = 0; i < invoiceInfo.InvoiceDetails.Count; i++)
            {
                if (invoiceInfo.InvoiceDetails[i].DetailKind == "1")
                {
                    continue;
                }

                HxShengQing.ClickBtnByName(toolBar, "增行");

                Thread.Sleep(500);
                //WinApi.ClickLocation(dataBar, 40, 24 + 30 * i + 15); //可以点中第一行第一块
                //Thread.Sleep(200);
                if (invoiceInfo.InvoiceDetails[i].DetailKind == "2")
                {
                    var next = invoiceInfo.InvoiceDetails.Find(detail => detail.DetailKind == "1" &&
                                                               detail.ItemName ==
                                                               invoiceInfo.InvoiceDetails[i].ItemName);
                    JuanPiaoMingXi(toolBar, invoiceInfo.InvoiceDetails[i], next); //填写卷票明细
                }
                else
                {
                    JuanPiaoMingXi(toolBar, invoiceInfo.InvoiceDetails[i]); //填写卷票明细
                }
            }

            Thread.Sleep(500);
        }
Example #15
0
 /// <summary>
 /// 提示框点击取消按钮
 /// </summary>
 public static void step6()
 {
     HxShengQing.SystemOpera("取消");
 }
Example #16
0
        /// <summary>
        /// 蓝字发票校验页面过度
        /// </summary>
        public static void lanzifapiaoguodu()
        {
            var blueInvoiceInputtHw = HxShengQing.TryRetry(str => WinApi.FindWindow(null, str), "销项正数发票代码号码填写、确认");

            var fapiaodaimaBar1 = IntPtr.Zero;
            var fapiaodaimaBar2 = IntPtr.Zero;
            var fapiaohaomaBar1 = IntPtr.Zero;
            var fapiaohaomaBar2 = IntPtr.Zero;
            var nextStepBar     = IntPtr.Zero;


            var flag = HxShengQing.TryRetry(bar =>
            {
                var list    = WinApi.EnumChildWindowsCallback(bar);
                nextStepBar = list.Find(b => b.szWindowName == "下一步").hWnd;

                var tabPage2 = list.Find(b => b.szWindowName == "tabPage2").hWnd;
                var childs   = WinApi.FindChildBar(tabPage2);

                fapiaodaimaBar1 = childs[6];
                fapiaodaimaBar2 = childs[0];
                fapiaohaomaBar1 = childs[3];
                fapiaohaomaBar2 = childs[1];

                if (fapiaodaimaBar1 == IntPtr.Zero || fapiaodaimaBar2 == IntPtr.Zero ||
                    fapiaohaomaBar1 == IntPtr.Zero ||
                    fapiaohaomaBar2 == IntPtr.Zero || nextStepBar == IntPtr.Zero)
                {
                    return(false);
                }
                return(true);
            }, blueInvoiceInputtHw);

            if (!flag)
            {
                throw new Exception("xxxx:蓝字发票校验页面句柄查找错误");
            }

            WinApi.SendMessage(fapiaodaimaBar1, 0X0C, IntPtr.Zero, "4400154620");
            Thread.Sleep(100);
            WinApi.SendMessage(fapiaodaimaBar2, 0X0C, IntPtr.Zero, "4400154620");
            Thread.Sleep(100);
            WinApi.SendMessage(fapiaohaomaBar1, 0X0C, IntPtr.Zero, "51365035");
            Thread.Sleep(100);
            WinApi.SendMessage(fapiaohaomaBar2, 0X0C, IntPtr.Zero, "51365035");
            WinApi.SendKey(fapiaohaomaBar2, WinApi.VK_RETURN);
            Thread.Sleep(100);

            //点击下一步按钮
            WinApi.LeftClick(nextStepBar);


            var confirmBtn     = IntPtr.Zero;
            var cancelBtn      = IntPtr.Zero;
            var isClickConfirm = IntPtr.Zero;

            var nextFlag = HxShengQing.TryRetry(bar =>
            {
                var list       = WinApi.EnumChildWindowsCallback(bar);
                confirmBtn     = list.Find(b => b.szWindowName == "确  定").hWnd;
                cancelBtn      = list.Find(b => b.szWindowName == "取 消").hWnd;
                isClickConfirm = list.Find(b => b.szWindowName == "本张发票可以开红字发票!").hWnd;
                if (confirmBtn == IntPtr.Zero || cancelBtn == IntPtr.Zero)
                {
                    return(false);
                }
                return(true);
            }, blueInvoiceInputtHw);

            if (!nextFlag)
            {
                throw new Exception("xxxx:蓝字发票校验页面下一步之后,句柄查找错误");
            }

            //点击确定按钮
            if (isClickConfirm != IntPtr.Zero)
            {
                WinApi.LeftClick(confirmBtn);
            }
            else
            {
                throw new Exception("xxxx:本张发票不可以开红字发票!");
            }
        }
Example #17
0
        public static void WriteGoodsSetting(IntPtr goodNoSettingHw, RednotificationDetail detail)
        {
            if (goodNoSettingHw == IntPtr.Zero)
            {
                return;
            }

            if (detail == null)
            {
                detail = new RednotificationDetail()
                {
                    GoodsTaxNo = "101010102",
                    //TaxPer = "1",
                    TaxPerCon = "不征税",
                    TaxRate   = "0.17"
                };
            }

            var suilvBar  = IntPtr.Zero;
            var yhBar     = IntPtr.Zero;
            var yhlBar    = IntPtr.Zero;
            var toolStrip = IntPtr.Zero;

            HxShengQing.TryRetry(str =>
            {
                var childInfos = WinApi.FindChildInfo(goodNoSettingHw);
                if (childInfos == null || childInfos.Count < 11)
                {
                    return(false);
                }

                //获取toolStrip
                toolStrip = childInfos.Find(b => b.szWindowName == "toolStrip1").hWnd;

                //税率句柄
                suilvBar = childInfos[10].hWnd;

                //享受优惠政策
                yhBar = childInfos[8].hWnd;

                //优惠政策类型
                yhlBar = childInfos[5].hWnd;

                return(toolStrip != IntPtr.Zero && suilvBar != IntPtr.Zero &&
                       yhBar != IntPtr.Zero && yhlBar != IntPtr.Zero);
            }, "", 20, 500);

            if ("1".Equals(detail.TaxPer) && !string.IsNullOrEmpty(detail.TaxPerCon))
            {
                UIHelper.SetCombox(yhBar, "是");

                //等待优惠政策enable
                Thread.Sleep(1000);
                UIHelper.SetCombox(yhlBar, detail.TaxPerCon.Trim());
            }
            else
            {
                UIHelper.SetCombox(suilvBar, GetByTaxRate(detail.TaxRate));
            }

            ClickBtnByName(toolStrip, "保存");
            Thread.Sleep(1000);

            HxShengQing.SystemOpera("确认", out var message);
            if (message != "修改成功!")
            {
                throw new Exception(message);
            }
        }
Example #18
0
        /// <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...");
        }
Example #19
0
        public static void WriteGoodsTaxNoAdd(IntPtr goodNoAddHw, RednotificationDetail detail)
        {
            if (detail == null)
            {
                detail = new RednotificationDetail()
                {
                    GoodsTaxNo = "101010102",
                    TaxPer     = "1",
                    TaxPerCon  = "不征税",
                    TaxRate    = "0.17"
                };
            }
            if (goodNoAddHw == IntPtr.Zero)
            {
                return;
            }

            //税收分类编码
            var ssflbmBar = IntPtr.Zero;
            var toolStrip = IntPtr.Zero;
            var suilvBar  = IntPtr.Zero;
            var yhBar     = IntPtr.Zero;
            var yhlBar    = IntPtr.Zero;

            HxShengQing.TryRetry(str =>
            {
                var childInfos = WinApi.FindChildInfo(goodNoAddHw);
                if (childInfos == null || childInfos.Count < 30)
                {
                    return(false);
                }

                //获取分类名称
                var flmnBar = childInfos.Find(b => b.szWindowName == "税收分类名称").hWnd;
                var temp1   = WinApi.FindWindowEx(goodNoAddHw, flmnBar, null, null);
                var temp2   = WinApi.FindWindowEx(temp1, IntPtr.Zero, null, null);
                ssflbmBar   = WinApi.FindWindowEx(temp1, temp2, null, null);

                //获取toolStrip
                toolStrip = childInfos.Find(b => b.szWindowName == "toolStrip1").hWnd;

                //获取税率句柄
                var suilv = childInfos.Find(b => b.szWindowName == "*税率").hWnd;
                suilvBar  = WinApi.FindWindowEx(goodNoAddHw, suilv, null, null);

                //获取享受优惠政策
                var yh = childInfos.Find(b => b.szWindowName == "规格型号").hWnd;
                yhBar  = WinApi.FindWindowEx(goodNoAddHw, yh, null, null);

                //优惠政策类型
                yhlBar = childInfos[8].hWnd;

                return(ssflbmBar != IntPtr.Zero && toolStrip != IntPtr.Zero &&
                       suilvBar != IntPtr.Zero && yhBar != IntPtr.Zero && yhlBar != IntPtr.Zero);
            }, "", 20, 500);

            if (ssflbmBar == IntPtr.Zero || toolStrip == IntPtr.Zero ||
                suilvBar == IntPtr.Zero || yhBar == IntPtr.Zero || yhlBar == IntPtr.Zero)
            {
                throw new Exception("商品编码窗体,句柄获取失败");
            }

            WinApi.SendMessage(ssflbmBar, WinApi.BM_TEXT, IntPtr.Zero, TaxSub(detail.GoodsTaxNo));
            Thread.Sleep(100);
            WinApi.SendKey(ssflbmBar, WinApi.VK_DOWN);
            Thread.Sleep(100);
            WinApi.SendKey(ssflbmBar, WinApi.VK_RETURN);
            Thread.Sleep(100);
            WinApi.ClickLocation(goodNoAddHw, 300, 10);
            Thread.Sleep(500);

            if ("1".Equals(detail.TaxPer) && !string.IsNullOrEmpty(detail.TaxPerCon))
            {
                UIHelper.SetCombox(yhBar, "是");

                //等待优惠政策enable
                Thread.Sleep(1000);
                UIHelper.SetCombox(yhlBar, detail.TaxPerCon.Trim());
            }
            else
            {
                UIHelper.SetCombox(suilvBar, GetByTaxRate(detail.TaxRate));
            }

            ClickBtnByName(toolStrip, "保存");
            Thread.Sleep(500);
        }
Example #20
0
        //普票测试通过
        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);
                    }
                }
            }
        }
Example #21
0
        /// <summary>
        /// 卷票明细
        /// </summary>
        /// <param name="detail"></param>
        /// <param name="next"></param>
        /// <param name="toolBar"></param>
        public static void JuanPiaoMingXi(IntPtr toolBar, Entitys.InvoiceDetail detail, Entitys.InvoiceDetail next = null)
        {
            try
            {
                GetTableFocus();
                //填写货物名称
                SendKeys.SendWait(detail.ItemName);
                Thread.Sleep(500);
                WinApi.keybd_event(Keys.Tab, 0, 0, 0);

                var ssbmszBar = IntPtr.Zero;
                var ssbmtjBar = IntPtr.Zero;
                TryRetry(str =>
                {
                    ssbmszBar = WinApi.FindWindow(null, "税收分类编码设置");
                    ssbmtjBar = WinApi.FindWindow(null, "商品编码添加");
                    return(ssbmszBar != IntPtr.Zero || ssbmtjBar != IntPtr.Zero);
                }, "", 4, 500);

                if (ssbmszBar != IntPtr.Zero)
                {
                    WriteGoodsSetting(ssbmszBar,
                                      detail.TaxPer, detail.TaxperCon, detail.TaxRate);
                }
                if (ssbmtjBar != IntPtr.Zero)
                {
                    WriteGoodsTaxNoAdd(ssbmtjBar, detail.GoodsTaxNo,
                                       detail.TaxPer, detail.TaxperCon, detail.TaxRate);
                }

                if (!string.IsNullOrWhiteSpace(detail.Quantity))
                {
                    GetTableFocus();
                    //填写数量
                    SendKeys.SendWait(detail.Quantity);
                }

                Thread.Sleep(500);
                WinApi.keybd_event(Keys.Tab, 0, 0, 0);
                if (!string.IsNullOrWhiteSpace(detail.UnitPrice))
                {
                    GetTableFocus();
                    //填写单价
                    if (detail.PriceMethod != "1")
                    {
                        detail.UnitPrice = ((1 + Convert.ToDouble(detail.TaxRate))
                                            * Convert.ToDouble(detail.UnitPrice)).ToString();
                    }
                    SendKeys.SendWait(detail.UnitPrice);
                }

                Thread.Sleep(500);
                WinApi.keybd_event(Keys.Tab, 0, 0, 0);
                Thread.Sleep(500);
                //AmLogger.Info("JuanPiaoMingXi", "一行明细填写成功");

                //添加折扣逻辑
                if (detail.DetailKind != "2" || next == null)
                {
                    return;
                }

                //点击折扣按钮
                HxShengQing.ClickBtnByName(toolBar, "折扣");
                Thread.Sleep(500);

                var jbar = IntPtr.Zero;
                for (var i = 0; i < 10; i++)
                {
                    jbar = WinApi.FindWindow(null, "添加折扣行");
                    if (jbar != IntPtr.Zero)
                    {
                        break;
                    }

                    Thread.Sleep(500);
                }

                var list = WinApi.EnumChilWindowsIntptr(jbar);
                if (list == null || list.Count < 8)
                {
                    return;
                }

                //发送折扣金额
                WinApi.SendMessage((IntPtr)list[6], WinApi.BM_TEXT, IntPtr.Zero, next.AmountWithTax.Substring(1, next.AmountWithTax.Length - 1));

                //点击确定按钮
                Thread.Sleep(500);
                WinApi.LeftClickMsg(list[4]);
            }
            catch (Exception e)
            {
                //CaptureScreen.TakeScreenShot("添加明细", $"{e.Message}");
                //AmLogger.Error("JuanPiaoMingXi", e);
            }
        }