Ejemplo n.º 1
0
        /// <summary>
        /// 从页面中查找需填写的参数键值及控件句柄间的对应关系,将其保存到_keyRelation列表中。
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        private IntPtr GetParameters(IntPtr container)
        {
            _keyRelation.Clear();
            IntPtr        afterChild  = IntPtr.Zero;
            IntPtr        finded      = IntPtr.Zero;
            IntPtr        saveButton  = IntPtr.Zero;
            StringBuilder className   = new StringBuilder(256);
            StringBuilder text        = new StringBuilder(256);
            List <IntPtr> controlList = new List <IntPtr>();

            do
            {
                text.Clear();
                className.Clear();
                finded = NativeApi.FindWindowEx(container, afterChild, null, null);
                if (finded != IntPtr.Zero)
                {
                    NativeApi.GetClassName(finded, className, 255);
                    string ClassName = className.ToString();
                    if (ClassName.StartsWith(CCCFillManager.StaticClassName))
                    {
                        NativeApi.GetWindowText(finded, text, 255);
                        string controlText = text.ToString();
                        if (keyMatcher.IsMatch(controlText))
                        {
                            _keyRelation.Add(new KeyValuePair <string, object>(controlText, finded));
                        }
                        else if (UnnumberedParameter.ContainsKey(controlText))
                        {
                            _keyRelation.Add(new KeyValuePair <string, object>(UnnumberedParameter[controlText] as string, finded));
                        }
                    }
                    else if (ClassName.StartsWith(CCCFillManager.ButtonClassName))
                    {
                        text.Clear();
                        NativeApi.GetWindowText(finded, text, 255);
                        if (text.ToString() == "保存" && NativeApi.GetParent(finded) == container)
                        {
                            saveButton = finded;
                        }
                        controlList.Add(finded);
                    }
                    else
                    {
                        controlList.Add(finded);
                    }
                    afterChild = finded;
                }
            } while (finded != IntPtr.Zero);
            ControlSorter.SortKey(_keyRelation);
            this.GetKeyRelation(container, controlList);
            if (saveButton == IntPtr.Zero)
            {
                return(FindSaveButton(container));
            }
            return(saveButton);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取参数名与控件句柄间的对应关系
        /// </summary>
        /// <param name="container">用于查找本页的保存按钮</param>
        /// <param name="controlList">控件句柄列表</param>
        private void GetKeyRelation(IntPtr container, List <IntPtr> controlList)
        {
            IntPtr        finding = IntPtr.Zero;
            RECT          keyRect, findedRect;
            StringBuilder className = new StringBuilder(256);

            for (int keyIndex = 0; keyIndex < _keyRelation.Count; keyIndex++)
            {
                finding = (IntPtr)_keyRelation[keyIndex].Value;
                _keyRelation[keyIndex] = new KeyValuePair <string, object>(_keyRelation[keyIndex].Key, IntPtr.Zero);
                NativeApi.GetWindowRect(finding, out keyRect);
                List <IntPtr> list = null;
                for (int i = 0; i < controlList.Count; i++)
                {
                    NativeApi.GetWindowRect(controlList[i], out findedRect);
                    if (findedRect.Top <= keyRect.Top && findedRect.Bottom >= keyRect.Bottom)
                    {
                        list = _keyRelation[keyIndex].Value as List <IntPtr>;
                        if (list == null)
                        {
                            list = new List <IntPtr>();
                            _keyRelation[keyIndex] = new KeyValuePair <string, object>(_keyRelation[keyIndex].Key, list);
                        }
                        list.Add(controlList[i]);
                        controlList.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        int diffrent = (findedRect.Top + findedRect.Bottom) / 2 - (keyRect.Top + keyRect.Bottom) / 2;
                        if (diffrent <= 8 && diffrent >= -8)
                        {
                            list = _keyRelation[keyIndex].Value as List <IntPtr>;
                            if (list == null)
                            {
                                list = new List <IntPtr>();
                                _keyRelation[keyIndex] = new KeyValuePair <string, object>(_keyRelation[keyIndex].Key, list);
                            }
                            list.Add(controlList[i]);
                            controlList.RemoveAt(i);
                            i--;
                        }
                    }
                    if (list != null)
                    {
                        ControlSorter.SortControlList(list); // 将与指定参数名称在同一行的控件按从左到右的顺序排列
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override bool DoFillWork(object state)
        {
            FillValue3C fillValue = state as FillValue3C;

            if (fillValue == null || fillValue.Value == null || fillValue.Separators == null || fillValue.Separators.Length < 1)
            {
                return(false);
            }
            string[] values = fillValue.Value.Split(fillValue.Separators[0]);
            if (values == null || values.Length == 0)
            {
                return(true);
            }
            List <IntPtr> list = ControlSorter.SortContainer(_container);

            if (list == null)
            {
                return(false);
            }
            StringBuilder className = new StringBuilder(256);

            for (int i = 0; i < values.Length && i < list.Count; i++)
            {
                className.Clear();
                NativeApi.GetClassName(list[i], className, 255);
                string classNameStr = className.ToString();
                if (classNameStr.StartsWith(CCCFillManager.EditClassName))
                {
                    ApiSetter.SetText(list[i], values[i]);
                }
                else if (classNameStr.StartsWith(CCCFillManager.ComboBoxClassName))
                {
                    ApiSetter.SetComboBoxSelected(base.HWnd, list[i], values[i]);
                }
            }
            ApiSetter.ClickButton(_finishButton, base.HWnd, null, null);
            return(true);
        }
Ejemplo n.º 4
0
        public override void InitHandle()
        {
            List <IntPtr> listBoxes = new List <IntPtr>();
            StringBuilder className = new StringBuilder(256);

            NativeApi.EnumChildWindows(base.HWnd, (hwnd, lParam) =>
            {
                className.Clear();
                NativeApi.GetClassName(hwnd, className, 255);
                string classNameStr = className.ToString();
                if (classNameStr.StartsWith(CCCFillManager.LISTBOXClassName))
                {
                    listBoxes.Add(hwnd);
                }
                else if (classNameStr.StartsWith(CCCFillManager.ComboBoxClassName))
                {
                    comboBox = hwnd;
                }
                else if (classNameStr.StartsWith(CCCFillManager.ButtonClassName))
                {
                    StringBuilder text = className.Clear();
                    NativeApi.GetWindowText(hwnd, text, 255);
                    if (text.ToString() == "完成")
                    {
                        finish = hwnd;
                    }
                    else if (text.ToString() == "并装")
                    {
                        multiInstall = hwnd;
                    }
                }
                return(listBoxes.Count == 0 || finish == IntPtr.Zero || multiInstall == IntPtr.Zero || comboBox == IntPtr.Zero);
            }, IntPtr.Zero);
            ControlSorter.SortControlList(listBoxes);
            listBox = listBoxes[0];
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 根据参数键值及控件句柄填写参数。
        /// </summary>
        /// <param name="key"></param>
        /// <param name="fillControl"></param>
        /// <returns></returns>
        private bool FillValue(string key, object fillControl)
        {
            IntPtr        current = IntPtr.Zero;
            List <IntPtr> list    = fillControl as List <IntPtr>;

            if (list != null && list.Count == 0)
            {
                return(true);
            }

            if (string.IsNullOrEmpty(key))
            {
                return(true);
            }
            FillParameter3C fillParameter = _fillParameters[key] as FillParameter3C;

            if (fillParameter == null)
            {
                fillParameter = new FillParameter3C()
                {
                    Key = key, Separators = FillParameter3C.DefaultSeparators
                };
                _fillParameters.Add(key, fillParameter);
            }
            FillValue3C fillValue = _pageData[key] as FillValue3C;

            if (fillValue == null)
            {
                Records.Add(new FillRecord(ElementType.Unknown, RecordType.Failed, "数据文件中未定义此参数", key));
                return(true);
            }
            StringBuilder className = new StringBuilder(256);
            string        name      = "";

            if (list != null)
            {
                current   = list[0];
                className = new StringBuilder(256);
                NativeApi.GetClassName(current, className, 255);
                name = className.ToString();
                // 勾选是否适用复选框
                if (name.StartsWith(CCCFillManager.ButtonClassName))
                {
                    if (fillValue.Value == "N/A")
                    {
                        if (ApiSetter.IsDisabled(current) == false)
                        {
                            ApiSetter.SetCheck(current, this.Hwnd);
                            //ApiSetter.ClickButton(current, this.Hwnd, null, null);
                            return(true);
                        }
                    }
                    current = list.Count > 1 ? list[list.Count - 1] : current;
                }
            }
            else
            {
                current = (IntPtr)fillControl;
            }


            if (fillParameter.Type == "5" || fillParameter.Type == "7")
            {
                return(FillCheckBox(fillParameter, current));
            }


            className.Clear();
            NativeApi.GetClassName(current, className, 255);
            name = className.ToString();
            if (name.StartsWith(CCCFillManager.StaticClassName))
            {
                return(true);
            }
            else if (name.StartsWith(CCCFillManager.EditClassName))
            {
                return(FillValue(CCCFillManager.EditClassName, current, fillValue));
            }
            else if (name.StartsWith(CCCFillManager.ButtonClassName))
            {
                return(FillValue(CCCFillManager.ButtonClassName, current, fillValue));
            }
            else if (name.StartsWith(CCCFillManager.ComboBoxClassName))
            {
#if export
                sheet.WriteNextRow();
                sheet.WriteTextCell(1, writer.AddSharedString(key));
#endif
                return(FillValue(CCCFillManager.ComboBoxClassName, current, fillValue));
            }
            else
            {   // 多值填报
                List <IntPtr> sortedControl = ControlSorter.SortContainer(current);
                if (sortedControl == null)
                {
                    return(false);
                }
                else if (sortedControl.Count == 1)
                {
                    return(FillValue(key, sortedControl[0]));
                }
                int valueIndex = 0;
                for (int i = 0; i < sortedControl.Count; i++, valueIndex++)
                {
                    className.Clear();
                    NativeApi.GetClassName(sortedControl[i], className, 255);
                    if (className.ToString().StartsWith(CCCFillManager.ButtonClassName))
                    {
                        FillValue(CCCFillManager.ButtonClassName, ref valueIndex, sortedControl[i], fillValue);
                    }
                    else if (className.ToString().StartsWith(CCCFillManager.ComboBoxClassName))
                    {
#if export
                        sheet.WriteNextRow();
                        sheet.WriteTextCell(1, writer.AddSharedString(key));
#endif
                        FillValue(CCCFillManager.ComboBoxClassName, ref valueIndex, sortedControl[i], fillValue);
                    }
                    else if (className.ToString().StartsWith(CCCFillManager.EditClassName))
                    {
                        FillValue(CCCFillManager.EditClassName, ref valueIndex, sortedControl[i], fillValue);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
 static ControlSorter()
 {
     _current = new ControlSorter();
 }
Ejemplo n.º 7
0
        public override bool DoFillWork(object state)
        {
            FillValue3C fillValue = state as FillValue3C;

            if (fillValue == null || fillValue.Value == null || fillValue.Separators == null || fillValue.Separators.Length < 2 || inputCount == 0)
            {
                return(false);
            }

            foreach (char c in fillValue.Separators)
            {
                fillValue.Value = fillValue.Value.Replace(c, ',');
            }
            List <string[]> values = new List <string[]>();

            string[] array = fillValue.Value.Split(new char[] { ',' }, StringSplitOptions.None);
            string[] group = null;
            for (int i = 0; i < array.Length; i++)
            {
                int mod = (i % inputCount);
                if (mod == 0)
                {
                    group = new string[inputCount];
                    values.Add(group);
                }
                group[mod] = array[i];
            }
            //List<string[]> values = new List<string[]>();
            //foreach (var item in fillValue.Value.Split(fillValue.Separators[1]))
            //{
            //    values.Add(item.Split(fillValue.Separators[0]));
            //}
            bool          result    = true;
            StringBuilder className = new StringBuilder(256);

            for (int index = 0; index < values.Count && current != IntPtr.Zero; index++)
            {
                List <IntPtr> sorted = ControlSorter.SortContainer(current);
                if (sorted != null)
                {
                    string[] parametrValues = values[index];
                    for (int i = 0; i < sorted.Count && parametrValues.Length > i; i++)
                    {
                        NativeApi.GetClassName(sorted[i], className, 255);
                        string classNameStr = className.ToString();
                        if (classNameStr.StartsWith(CCCFillManager.EditClassName))
                        {
                            ApiSetter.SetText(sorted[i], parametrValues[i]);
                        }
                        else if (classNameStr.StartsWith(CCCFillManager.ComboBoxClassName))
                        {
                            ApiSetter.SetComboBoxSelected(base.HWnd, sorted[i], parametrValues[i]);
                        }
                    }
                }
                if (index < values.Count - 1)
                {
                    ApiSetter.ClickButton(addButton, base.HWnd, null, null);
                }
                current = NativeApi.FindWindowEx(container, current, null, null);
            }
            return(result && ApiSetter.ClickButton(saveButton, base.HWnd, null, null));
        }