Beispiel #1
0
 protected bool FillSelectElement(IHTMLSelectElement element, FillParameter parameter, string value)
 {
     if (parameter.CanContain && value != null)
     {
         for (int i = 0; i < element.length; i++)
         {
             IHTMLOptionElement option = element.item(i);
             if (option.text != null && option.text.Contains(value))
             {
                 //element.selectedIndex = i;
                 element.options[i].selected = true;
                 this.InvokeOnChange(element as IHTMLElement);
                 return(true);
             }
         }
     }
     else
     {
         for (int i = 0; i < element.length; i++)
         {
             IHTMLOptionElement option = element.item(i);
             if (option.text == value)
             {
                 //element.selectedIndex = i;
                 element.options[i].selected = true;
                 this.InvokeOnChange(element as IHTMLElement);
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #2
0
 protected override void UpdateFormIndex(FillParameter parameter)
 {
     if (base.GetElement(parameter, -1) != null)
     {
         _formIndex++;
     }
 }
Beispiel #3
0
 protected override void FillElement(FillParameter parameter, string value)
 {
     if (parameter == null)
     {
         return;
     }
     if (parameter.ParameterName == null || base.DataTable.Contains(parameter.ParameterName) == false)
     {
         value = DefaultValue;
     }
     if (parameter.Type != Matcher.TYPE_FORM)
     {
         if (parameter.Value == "上传图片")
         {
             if (string.IsNullOrEmpty(value))
             {
                 return;
             }
             string file = System.IO.File.Exists(value) ? value : (string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value));
             if (System.IO.File.Exists(file) == false)
             {
                 base.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", file), parameter.ParameterName));
                 return;
             }
             else
             {
                 DataTable["选择文件"] = value;
             }
         }
     }
     base.FillElement(parameter, value);
 }
Beispiel #4
0
        private void FillListElementUncertain(FillParameter parameter)
        {
            base.Continue     = true;
            base.CurrentIndex = -1;
            FillIndexes.Add(this);
            FillParameter tmp   = null;
            String        value = String.Empty;

            while (base.Continue)
            {
                base.Continue = false;
                base.CurrentIndex++;
                if (string.IsNullOrEmpty(parameter.href))
                {
                    tmp = parameter;
                }
                else
                {
                    tmp = new FillParameter()
                    {
                        href = string.Format(parameter.href, base.CurrentIndex + 1)
                    }
                };
                FillElement(tmp, ref value);
                this.Wait();
            }
            FillIndexes.RemoveAt(FillIndexes.Count - 1);
        }
Beispiel #5
0
        /// <summary>
        /// 填报数据
        /// </summary>
        /// <param name="parameterKey">参数名称。</param>
        /// <param name="elementContainer">用于从网页中查找元素的对象,当value为Hashtable时表示当前是一组Radio或CheckBox。</param>
        /// <param name="parameterValue">用于填报的数据。</param>
        /// <param name="list">用于存储多值数据的列表。</param>
        private void FillElement(FillParameterKey parameterKey, object elementContainer, Hashtable data)
        {
            this.Wait();
            FillParameter fillParameter = elementContainer as FillParameter;

            String parameterValue = data[parameterKey.Key] as String;

            if (fillParameter == null)
            {
                Hashtable table = elementContainer as Hashtable;
                if (table == null)
                {
                    return;
                }
                else if (parameterKey.Type == Matcher.TYPE_RADIO)
                {
                    // 处理radio类型的选择
                    if (parameterValue != null)
                    {
                        fillParameter = table[parameterValue] as FillParameter;
                    }
                }
                else if (parameterKey.Type == Matcher.TYPE_CHECKBOX) // 处理checkBox类型
                {
                    FillCheckBoxGroup(ref parameterValue, table);
                    data.Remove(parameterKey.Key);
                    data.Add(parameterKey.Key, parameterValue);
                    return;
                }
            }
            FillElement(fillParameter, ref parameterValue);
            data.Remove(parameterKey.Key);
            data.Add(parameterKey.Key, parameterValue);
        }
Beispiel #6
0
        protected void FillElement(FillParameterKey parameterKey, object elementContainer, string parameterValue)
        {
            this.Wait();
            FillParameter fillParameter = elementContainer as FillParameter;

            if (fillParameter == null)
            {
                Hashtable table = elementContainer as Hashtable;
                if (table == null)
                {
                    return;
                }
                else if (parameterKey.Type == Matcher.TYPE_RADIO)
                {
                    // 处理radio类型的选择
                    if (parameterValue != null)
                    {
                        if (table.ContainsKey(parameterValue) == false)
                        {
                            this.FillRecords.Add(new FillRecord(ElementType.Radio, RecordType.Failed, string.Format("单选框中不包含项 {0}", parameterValue), parameterKey.Key));
                        }

                        fillParameter = table[parameterValue] as FillParameter;
                    }
                }
                else if (parameterKey.Type == Matcher.TYPE_CHECKBOX) // 处理checkBox类型
                {
                    FillCheckBoxGroup(parameterValue, parameterKey.Key, table);
                    return;
                }
            }
            FillElement(fillParameter, parameterValue);
        }
Beispiel #7
0
 protected override IHTMLElement FindElement(HtmlDocument doc, FillParameter parameter, bool isContain, string elementType, int formIndex)
 {
     if (string.IsNullOrEmpty(parameter.href) == false)
     {
         return(InvokeScriptSync(doc, "findElementByHref", new object[] { parameter.href }) as IHTMLElement);
     }
     return(InvokeScriptSync(doc, "findElement", new object[] { elementType, isContain, parameter.Id, parameter.Name, parameter.Value, parameter.OnClick, parameter.href, formIndex }) as IHTMLElement);
 }
Beispiel #8
0
        private void FillTableValue(Hashtable data)
        {
            if (data == null)
            {
                base.Browser.Invoke((Action)(() =>
                {
                    WebBrowser2.InvokeScript(base.Document.DomDocument as IHTMLDocument, "goBack");
                }));
                return;
            }
            int           count     = 0;
            List <string> valueList = null;
            List <KeyValuePair <FillParameterKey, object> > fillList = new List <KeyValuePair <FillParameterKey, object> >();
            int fillIndex = 0, rowIndex = 0;

            foreach (DictionaryEntry entry in data)
            {
                rowIndex = 0;
                DataTable table = entry.Value as DataTable;
                bool      canAdd;
                while (table.Rows.Count > rowIndex)
                {
                    formIndexes.Clear();
                    valueList = GetValueList(table, fillList, out fillIndex, ref rowIndex, out canAdd);
                    for (int i = 0; i < fillIndex; i++)
                    {
                        if (_parameters[i].Key.Type == Matcher.TYPE_FORM)
                        {
                            FillParameter parameter = _parameters[i].Value as FillParameter;
                            if (parameter != null)
                            {
                                string key = parameter.FrameId;
                                if (string.IsNullOrEmpty(key))
                                {
                                    key = "@";
                                }
                                if (formIndexes.ContainsKey(key))
                                {
                                    formIndexes[key] = formIndexes[key] + 1;
                                }
                                else
                                {
                                    formIndexes[key] = 0;
                                }
                            }
                        }
                    }
                    FillListElement(fillList, valueList, canAdd);
                    count = Math.Max(count, fillIndex);
                    fillList.Clear();
                }
            }

            for (int index = count; index < _parameters.Count; index++)
            {
                this.FillElement(_parameters[index].Key, _parameters[index].Value, null);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 使用指定的填报参数及所在form索引获得页面元素。
        /// </summary>
        /// <param name="ele">填报参数。</param>
        /// <param name="ownerFormIndex">form在当前document中的索引。</param>
        /// <returns></returns>
        public IHTMLElement GetElement(FillParameter ele, int ownerFormIndex)
        {
            HtmlDocument document = null;

            if (string.IsNullOrEmpty(ele.FrameId))
            {
                document = _doc;
            }
            else
            {
                _browser.Invoke((Action)(() =>
                {
                    HtmlElement element = _doc.Window.WindowFrameElement;
                    HtmlWindow window = null;
                    if (element != null && element.Id == ele.FrameId)
                    {
                        window = _doc.Window;
                    }
                    else
                    {
                        window = _doc.Window.Frames[ele.FrameId];
                    }
                    document = window == null ? null : window.Document;
                }));
            }
            if (document == null)
            {
                return(null);
            }
            InstallScript(document);
            string elementType = "";
            bool   isContain   = false;

            switch (ele.Type)
            {
            case Matcher.TYPE_BUTTON:
            case Matcher.TYPE_SUBMIT:
            case "BUTTON/SUBMIT":
                isContain   = true;
                elementType = "input";
                break;

            case Matcher.TYPE_CHECKBOX:
            case Matcher.TYPE_TEXT:
            case Matcher.TYPE_RADIO:
            case Matcher.TYPE_FILE:
            case Matcher.TYPE_PASSWORD:
                elementType = "input";
                break;

            default:
                elementType = ele.Type == null ? "" : ele.Type.ToLower();
                break;
            }
            return(FindElement(document, ele, isContain, elementType, ownerFormIndex));
        }
Beispiel #10
0
        private bool SearchMatch(FillParameter parameter, List <KeyValuePair <FillParameterKey, object> > searchOption, List <string> values)
        {
            this.Wait();
            BHPageSearch search = new BHPageSearch(searchOption, values, base.Browser);

            if (search.SearchAndSelect())
            {
                FillElement(parameter, null);
                return(true);
            }
            WebFillManager.ShowMessageBox("未找到指定维修站!", "消息",
                                          System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop);
            return(false);
        }
Beispiel #11
0
 private void FillListElementUncertain(FillParameter parameter)
 {
     base.Continue     = true;
     base.CurrentIndex = -1;
     FillIndexes.Add(this);
     while (base.Continue)
     {
         base.Continue = false;
         base.CurrentIndex++;
         FillElement(parameter, null);
         this.Wait();
     }
     FillIndexes.RemoveAt(FillIndexes.Count - 1);
 }
Beispiel #12
0
        /// <summary>
        /// 填报checkbox数据。
        /// </summary>
        /// <param name="value"></param>
        /// <param name="checkBoxGroup"></param>
        private void FillCheckBoxGroup(ref string value, Hashtable checkBoxGroup)
        {
            //存储checkbox中的"xxx其他"选项
            FillParameter otherCheckBox = null;

            string[] values = value == null ? null : value.Split(PZHFillManager.regularSeparator, StringSplitOptions.RemoveEmptyEntries);
            if (values == null || values.Length < 1)
            {
                return;
            }
            List <String> listValues = new List <String>(values);

            foreach (String key in checkBoxGroup.Keys)
            {
                FillParameter dElement = checkBoxGroup[key] as FillParameter;
                if (key.Contains("其他"))
                {
                    otherCheckBox = dElement;
                }
                if (listValues.Contains(key))
                {
                    dElement.Value = null;
                    IHTMLElement element = base.GetElement(dElement, _formIndex) as IHTMLElement;
                    if (element == null)
                    {
                        continue;
                    }
                    //element.@checked = true;
                    element.click();
                    if (dElement.CanDelete)
                    {
                        listValues.Remove(key);
                    }
                }
            }

            if (listValues != null && listValues.Count > 0)
            {
                otherCheckBox.Value = null;
                IHTMLElement element = base.GetElement(otherCheckBox, _formIndex) as IHTMLElement;
                if (element != null)
                {
                    //element.@checked = true;
                    //base.InvokeOnChange(element as IHTMLElement);
                    element.click();
                    base.InvokeChange2(element as IHTMLElement);
                }
            }
            value = (listValues == null || listValues.Count == 0) ? "" : String.Join(PZHFillManager.regularJoiner, listValues);
        }
Beispiel #13
0
        private void HandleSpecialPage()
        {
            int  formIndex = -1;
            bool replace   = false;

            for (int i = 0; i < _parameters.Count; i++)
            {
                KeyValuePair <FillParameterKey, object> item = _parameters[i];
                FillParameter parameter = item.Value as FillParameter;
                if (parameter != null)
                {
                    if (item.Key.Key == mainVehicleModel)
                    {
                        // 若当前参数为国五轻型汽油车的主车型型号参数,且网页中的主车型型号不为空,则对其动力系进行编辑操作
                        // 否则,按正常填报规则执行。
                        IHTMLInputElement element = GetElement(parameter, formIndex) as IHTMLInputElement;
                        if (element != null && string.IsNullOrEmpty(element.value) == false)
                        {
                            replace = true;
                        }
                        else
                        {
                            return;
                        }
                    }
                    if (item.Key.Type == Matcher.TYPE_FORM)
                    {
                        formIndex++;
                        if (replace && (parameter.Name == formName || parameter.Id == formName))
                        {
                            if (_parameters.Count <= i + 1)
                            {
                                return;
                            }
                            item      = _parameters[i + 1];
                            parameter = item.Value as FillParameter;
                            if (parameter == null)
                            {
                                return;
                            }
                            parameter.Type = Matcher.TYPE_A;
                            parameter.href = "vehicle15.jsp?part=3&action=update&bh={0}";
                            return;
                        }
                    }
                }
            }
        }
Beispiel #14
0
 protected override int GetFormIndex(FillParameter parameter)
 {
     if (parameter == null)
     {
         return(-1);
     }
     else if (string.IsNullOrEmpty(parameter.FrameId) && formIndexes.ContainsKey("@"))
     {
         return(formIndexes["@"]);
     }
     else if (string.IsNullOrEmpty(parameter.FrameId) == false && formIndexes.ContainsKey(parameter.FrameId))
     {
         return(formIndexes[parameter.FrameId]);
     }
     return(-1);
 }
Beispiel #15
0
        protected override void UpdateFormIndex(FillParameter parameter)
        {
            string key = parameter.FrameId;

            if (string.IsNullOrEmpty(key))
            {
                key = "@";
            }
            if (formIndexes.ContainsKey(key))
            {
                formIndexes[key] = formIndexes[key] + 1;
            }
            else
            {
                formIndexes.Add(key, 0);
            }
        }
Beispiel #16
0
 private bool SearchMatch(FillParameter parameter, List <KeyValuePair <FillParameterKey, object> > searchOption, List <string> values)
 {
     this.Wait();
     try
     {
         GHPageSearch search = new GHPageSearch(values, searchOption, base.Browser);
         if (search.SearchAndSelect())
         {
             FillElement(parameter, null);
             return(true);
         }
     }
     finally
     {
         searchOption.Clear();
         values.Clear();
     }
     return(false);
 }
Beispiel #17
0
 /// <summary>
 /// 填报checkbox数据。
 /// </summary>
 /// <param name="value"></param>
 /// <param name="checkBoxGroup"></param>
 protected void FillCheckBoxGroup(string value, string parameterName, Hashtable checkBoxGroup)
 {
     string[] values = value == null ? null : value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
     if (values == null)
     {
         return;
     }
     for (int i = 0; i < values.Length; i++)
     {
         FillParameter dElement = checkBoxGroup[values[i]] as FillParameter;
         if (dElement == null)
         {
             FillRecords.Add(new FillRecord(ElementType.CheckBox, RecordType.Failed, string.Format("复选框中不包含项 {0}", values[i]), parameterName));
             continue;
         }
         IHTMLInputElement element = GetElement(dElement, this.GetFormIndex(dElement)) as IHTMLInputElement;
         if (element == null)
         {
             FillRecords.Add(new FillRecord(ElementType.CheckBox, RecordType.Failed, string.Format("未找复选框元素 {0}", values[i]), parameterName));
             continue;
         }
         ((IHTMLElement)element).click();
     }
 }
Beispiel #18
0
 protected override int GetFormIndex(FillParameter parameter)
 {
     return(_formIndex);
 }
Beispiel #19
0
        //private void FillElement(FillParameterKey parameterKey, object elementContainer, String parameterValue)
        //{
        //    this.Wait();
        //    FillParameter fillParameter = elementContainer as FillParameter;
        //    if (fillParameter == null)
        //    {
        //        Hashtable table = elementContainer as Hashtable;
        //        if (table == null)
        //            return;
        //        else if (parameterKey.Type == Matcher.TYPE_RADIO)
        //        {
        //            // 处理radio类型的选择
        //            if (parameterValue != null)
        //                fillParameter = table[parameterValue] as FillParameter;
        //        }
        //        else if (parameterKey.Type == Matcher.TYPE_CHECKBOX) // 处理checkBox类型
        //        {
        //            FillCheckBoxGroup(ref parameterValue, table);
        //            return;
        //        }
        //    }
        //    FillElement(fillParameter, ref parameterValue);
        //}

        //下拉框填报:1.如果只有一个选项就选中  2.如果选项有其他而且值没有其他符合项就选中其他
        private bool FillSelectElement(FillParameter parameter, ref string value)
        {
            IHTMLSelectElement element = base.GetElement(parameter, _formIndex) as IHTMLSelectElement;

            if (element == null)
            {
                return(false);
            }
            List <IHTMLOptionElement> listOptions = new List <IHTMLOptionElement>();
            IHTMLOptionElement        otherOption = null;

            //分割参数值,已经填充的参数值从中删掉
            string[] values = value == null ? null : value.Split(PZHFillManager.regularSeparator, StringSplitOptions.RemoveEmptyEntries);
            if (values == null || values.Length < 1)
            {
                return(false);
            }
            List <String> listValues = new List <String>(values);

            for (int i = 0; i < element.length; i++)
            {
                IHTMLOptionElement option = element.item(i);
                if (String.IsNullOrWhiteSpace(option.text))
                {
                    continue;
                }
                listOptions.Add(option);
                if (option.text == "其他")
                {
                    otherOption = option;
                }
                if (parameter.CanContain)
                {
                    String selectedItem = null;
                    foreach (String item in listValues)
                    {
                        if (option.text.Contains(item))
                        {
                            option.selected = true;
                            selectedItem    = item;
                            break;
                        }
                    }
                    if (parameter.CanDelete && !String.IsNullOrEmpty(selectedItem))
                    {
                        listValues.Remove(selectedItem);
                    }
                }
                else
                {
                    if (listValues.Contains(option.text))
                    {
                        option.selected = true;
                        if (parameter.CanDelete)
                        {
                            listValues.Remove(option.text);
                        }
                        value = String.Join(PZHFillManager.regularJoiner, listValues);
                        base.InvokeChange2(element as IHTMLElement);
                        return(true);
                    }
                }
            }
            if (listOptions.Count == 1)
            {
                listOptions[0].selected = true;
                base.InvokeChange2(element as IHTMLElement);
                return(true);
            }
            foreach (IHTMLOptionElement option in listOptions)
            {
                if (option.text == "其他")
                {
                    option.selected = true;
                    base.InvokeChange2(element as IHTMLElement);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #20
0
        /// <summary>
        ///  填充元素(分割元素)
        /// </summary>
        /// <param name="list"></param>
        /// <param name="values"></param>
        private void FillListElement(List <KeyValuePair <FillParameterKey, object> > list, List <string> values)
        {
            //包含分割字符串
            if (list.Count == 1 && (list[0].Key.Type == Matcher.TYPE_SUBMIT || list[0].Key.Type == "BUTTON/SUBMIT" ||
                                    list[0].Key.Type == Matcher.TYPE_BUTTON))
            {
                //仅包含新增按钮的新增列表
                FillListElementUncertain(list[0].Value as FillParameter);
                list.Clear();
                values.Clear();
                return;
            }
            string[]        valueArray     = null;
            int             maxValueLength = 0;
            List <string[]> valueList      = new List <string[]>();

            foreach (var value in values)
            {
                valueArray = value == null ? emptyStringArray : value.Split(base.Converter.SpliterChars[0]);
                valueList.Add(valueArray);
                maxValueLength = Math.Max(maxValueLength, valueArray.Length);
            }
            base.CurrentIndex = 0;
            string name           = ((FillParameter)(list[0].Value)).Name;
            bool   skipLastButton = (string.IsNullOrEmpty(name) == false && name.Contains("[") && name.Contains("]"));

            FillIndexes.Add(this);
            for (int valueIndex = 0; valueIndex < maxValueLength; valueIndex++)
            {
                base.CurrentIndex = valueIndex;  // 更新当前填报索引
                FillParameterKey key = null;
                //具体的某个控件
                object elementContainer = null;
                string parameterValue   = "";
                if (valueIndex > 0)
                {
                    nameNum++;
                }
                for (int i = 0; i < list.Count; i++)
                {
                    key = list[i].Key;
                    elementContainer = list[i].Value;
                    if (list[i].Key.Type == Matcher.TYPE_SUBMIT || list[i].Key.Type == Matcher.TYPE_A || list[i].Key.Type == "BUTTON/SUBMIT" || list[i].Key.Type == Matcher.TYPE_BUTTON)
                    {
                        if (valueIndex == maxValueLength - 1 && skipLastButton)
                        {
                            continue;
                        }
                        parameterValue = null;
                    }
                    else if (valueList[i].Length > valueIndex)
                    {
                        parameterValue = valueList[i][valueIndex];
                    }
                    else
                    {
                        parameterValue = "";
                    }
                    //判断所填写是否为新增元素
                    if (valueIndex > 0)
                    {
                        //修改name
                        FillParameter fp = (FillParameter)elementContainer;
                        name = fp.Name;
                        if (string.IsNullOrEmpty(name) == false && name.Contains("[") && name.Contains("]"))
                        {
                            int index1 = name.IndexOf("["), index2 = name.IndexOf("]", index1 == -1 ? 0 : index1);
                            System.Diagnostics.Trace.Assert(index1 != -1 && index2 != -1);
                            string left  = name.Substring(0, index1);
                            string right = name.Substring(index2 + 1);
                            //拼接name
                            fp.Name     = string.Format("{0}[{1}]{2}", left, nameNum, right);
                            fp.FindCode = "";
                        }
                    }
                    FillElement(key, elementContainer, parameterValue);
                }//end for
                this.Wait();
            }
            FillIndexes.RemoveAt(FillIndexes.Count - 1);
            list.Clear();
            values.Clear();
        }
Beispiel #21
0
        private void FillElement(FillParameter parameter, ref string value)
        {
            //if (parameter.Type != Matcher.TYPE_FORM)
            //{
            //    if (parameter.Value == "上传图片")
            //    {
            //        if (string.IsNullOrEmpty(value))
            //            return;
            //        string file = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value);
            //        if (System.IO.File.Exists(file) == false)
            //        {
            //            base.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", file), parameter.ParameterName));
            //            return;
            //        }
            //    }
            //}
            //base.FillElement(parameter, value);
            if (parameter == null)
            {
                return;
            }
            IHTMLElement element = null;

            if (parameter.ParameterName == null || base.DataTable.Contains(parameter.ParameterName) == false)
            {
                value = DefaultValue;
            }
            if (parameter.Type != Matcher.TYPE_FORM)
            {
                element = base.GetElement(parameter, _formIndex);
                if (element == null)
                {
                    this.FillRecords.Add(new FillRecord(GetElementType(parameter.Type), RecordType.Failed, "未找到此元素", parameter.ParameterName));
                    return;
                }
                else if (parameter.Value == "上传图片")
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        return;
                    }
                    string file = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value);
                    if (System.IO.File.Exists(file) == false)
                    {
                        this.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", value), parameter.ParameterName));
                        return;
                    }
                }
                ((IHTMLElement2)element).focus();
            }
            if (string.IsNullOrEmpty(parameter.SplitExpr) == false && string.IsNullOrEmpty(value) == false)
            {
                Match match = Regex.Match(value, parameter.SplitExpr, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    value = match.Groups["value"].Value;
                }
            }
            _currentFillValue = value;
            switch (parameter.Type)
            {
            case Matcher.TYPE_FORM:
                if (base.GetElement(parameter, -1) != null)
                {
                    _formIndex++;
                }
                break;

            case Matcher.TYPE_RADIO:
                IHTMLInputElement radioElement = element as IHTMLInputElement;
                radioElement.@checked = true;
                this.FillRecords[(int)ElementType.Radio].RecordCount++;
                break;

            case Matcher.TYPE_SELECT:
                if (FillSelectElement(parameter, ref value))
                {
                    this.FillRecords[(int)ElementType.Select].RecordCount++;
                }
                else
                {
                    this.FillRecords.Add(new FillRecord(ElementType.Select, RecordType.Failed, string.Format("下拉框中不包含选项 {0}", value), parameter.ParameterName));
                }
                break;

            case Matcher.TYPE_A:
                element.click();
                break;

            case Matcher.TYPE_FILE:
                value             = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value);
                _currentFillValue = value;
                if (System.IO.File.Exists(value))
                {
                    element.click();
                    this.FillRecords[(int)ElementType.File].RecordCount++;
                }
                break;

            case Matcher.TYPE_SUBMIT:
            case Matcher.TYPE_BUTTON:
            case "BUTTON/SUBMIT":
                IHTMLInputElement fileElement = element as IHTMLInputElement;
                element.click();
                break;

            case Matcher.TYPE_TEXTAREA:
                IHTMLTextAreaElement textAreaElement = element as IHTMLTextAreaElement;
                textAreaElement.value = value;
                this.FillRecords[(int)ElementType.Text].RecordCount++;
                break;

            case Matcher.TYPE_TEXT:
            case Matcher.TYPE_PASSWORD:
                IHTMLInputElement textElement = element as IHTMLInputElement;
                textElement.value = value;
                this.FillRecords[(int)ElementType.Text].RecordCount++;
                break;
            }
        }
Beispiel #22
0
 ///// <summary>
 ///// 填报checkbox数据。
 ///// </summary>
 ///// <param name="value"></param>
 ///// <param name="checkBoxGroup"></param>
 //private void FillCheckBoxGroup(string value, Hashtable checkBoxGroup)
 //{
 //    string[] values = value == null ? null : value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
 //    if (values == null)
 //        return;
 //    for (int i = 0; i < values.Length; i++)
 //    {
 //        FillParameter dElement = checkBoxGroup[values[i]] as FillParameter;
 //        if (dElement == null)
 //            continue;
 //        IHTMLInputElement element = base.GetElement(dElement, _formIndex) as IHTMLInputElement;
 //        if (element == null)
 //            continue;
 //        element.@checked = true;
 //    }
 //}
 protected override IHTMLElement FindElement(System.Windows.Forms.HtmlDocument doc, FillParameter parameter, bool isContain, string elementType, int formIndex)
 {
     if (string.IsNullOrEmpty(parameter.FindCode) == false)
     {
         return(InvokeScriptSync(doc, "findElementByExpr", new object[] { parameter.FindCode }) as IHTMLElement);
     }
     else
     {
         return(InvokeScriptSync(doc, "findElement", new object[] { elementType, parameter.Id, parameter.Name, parameter.Value, parameter.OnClick, formIndex }) as IHTMLElement);
     }
 }
Beispiel #23
0
 protected abstract void UpdateFormIndex(FillParameter parameter);
Beispiel #24
0
 protected abstract int GetFormIndex(FillParameter parameter);
Beispiel #25
0
        //得到参数
        protected void GetParameters()
        {
            Hashtable uniqueTable = new Hashtable();

            _parameters.Clear();
            string    note         = "";
            Hashtable group        = null;
            Hashtable columnHeader = new Hashtable();

            using (Office.Excel.ForwardExcelReader reader = new Office.Excel.ForwardExcelReader(GetParameterFile()))
            {
                reader.Open();
                string sheetName = string.Format("{0}({1})", _urlParameter.LabelName, this.Standard);
                // 同类车型中不同排放标准的填报规则可能不同。
                sheetName = reader.Contains(sheetName) ? sheetName : _urlParameter.LabelName;
                Office.Excel.ForwardReadWorksheet sheet = reader.Activate(sheetName) as Office.Excel.ForwardReadWorksheet;
                if (sheet == null)
                {
                    return;
                }
                object content = null;
                if (sheet.ReadNextRow())
                {
                    while (sheet.ReadNextCell(false))
                    {
                        content = sheet.GetContent();
                        columnHeader.Add(sheet.CurrentCell.ColumnIndex, content == null ? "" : content.ToString());
                    }
                }
                FillParameter    dElement;
                FillParameterKey key;
                while (sheet.ReadNextRow())
                {
                    dElement = new FillParameter();
                    while (sheet.ReadNextCell(false))
                    {
                        content = sheet.GetContent();
                        string value = content == null ? "" : content.ToString();
                        switch (columnHeader[sheet.CurrentCell.ColumnIndex] as string)
                        {
                        case "元素id":
                            dElement.Id = value;
                            break;

                        case "元素name":
                            dElement.Name = value;
                            break;

                        case "元素value":
                            dElement.Value = value;
                            break;

                        case "类别":
                            dElement.Type = value == null ? "" : value.ToUpper();
                            break;

                        case "onclick":
                            dElement.OnClick = value;
                            break;

                        case "参数名称":
                            dElement.ParameterName = value;
                            break;

                        case "备注":
                            note = value;
                            break;

                        case "可新增":
                            dElement.CanAdd = value == "是";
                            break;

                        case "查找":
                            dElement.SearchString = value;
                            break;

                        case "frameId":
                            dElement.FrameId = value;
                            break;

                        case "是否必填":
                            dElement.IsRequired = value == "是";
                            break;

                        case "数据表":
                            dElement.TableName = value;
                            break;

                        case "查找代码":
                            dElement.FindCode = value;
                            break;
                        }
                    }
                    if (string.IsNullOrEmpty(dElement.Type))
                    {
                        continue;
                    }
                    if (dElement.Type == Matcher.TYPE_RADIO || dElement.Type == Matcher.TYPE_CHECKBOX)
                    {   // 若当前参数为radio或checkbox则将其后面出现的所有此类元素作为同一参数
                        if (uniqueTable.ContainsKey(dElement.ParameterName) == false)
                        {
                            group = new Hashtable();
                            key   = new FillParameterKey(dElement.ParameterName, dElement.Type, dElement.CanAdd, dElement.IsRequired, dElement.SearchString);
                            _parameters.Add(new KeyValuePair <FillParameterKey, object>(key, group));
                            uniqueTable.Add(dElement.ParameterName, group);
                        }
                        group.Add(dElement.Value, dElement);
                    }
                    else
                    {
                        group         = null;
                        key           = new FillParameterKey(dElement.ParameterName, dElement.Type, dElement.CanAdd, dElement.IsRequired, dElement.SearchString);
                        key.TableName = dElement.TableName;
                        _parameters.Add(new KeyValuePair <FillParameterKey, object>(key, dElement));
                    }
                }
                uniqueTable.Clear();
            }
        }
Beispiel #26
0
        //填充参数
        protected virtual void FillElement(FillParameter parameter, string value)
        {
            if (parameter == null)
            {
                return;
            }
            IHTMLElement element = null;

            if (parameter.Type != Matcher.TYPE_FORM)
            {
                //查找元素,如果是null就是代表没有此元素
                element = GetElement(parameter, GetFormIndex(parameter));
                if (element == null)
                {
                    this.FillRecords.Add(new FillRecord(GetElementType(parameter.Type), RecordType.Failed, "未找到此元素", parameter.ParameterName));
                    return;
                }
                if (parameter.Type == Matcher.TYPE_FILE)
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        return;
                    }
                    value = File.Exists(value) ? value : (string.IsNullOrEmpty(DataFilePath) ? value : string.Format("{0}\\{1}", DataFilePath, value));
                    if (System.IO.File.Exists(value) == false)
                    {
                        this.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", value), parameter.ParameterName));
                        return;
                    }
                }
                ((IHTMLElement2)element).focus();
            }
            if (string.IsNullOrEmpty(parameter.SplitExpr) == false && string.IsNullOrEmpty(value) == false)
            {
                Match match = Regex.Match(value, parameter.SplitExpr, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    value = match.Groups["value"].Value;
                }
            }
            _currentFillValue = value;
            switch (parameter.Type)
            {
            case Matcher.TYPE_FORM:
                UpdateFormIndex(parameter);
                break;

            case Matcher.TYPE_RADIO:
                IHTMLInputElement radioElement = element as IHTMLInputElement;
                radioElement.@checked = true;
                this.FillRecords[(int)ElementType.Radio].RecordCount++;
                break;

            case Matcher.TYPE_SELECT:
                IHTMLSelectElement selectElement = element as IHTMLSelectElement;
                if (FillSelectElement(selectElement, parameter, value))
                {
                    this.FillRecords[(int)ElementType.Select].RecordCount++;
                }
                else
                {
                    this.FillRecords.Add(new FillRecord(ElementType.Select, RecordType.Failed, string.Format("下拉框中不包含选项 {0}", value), parameter.ParameterName));
                }
                break;

            case Matcher.TYPE_A:
                element.click();
                break;

            case Matcher.TYPE_FILE:
                element.click();
                this.FillRecords[(int)ElementType.File].RecordCount++;
                break;

            case Matcher.TYPE_SUBMIT:
            case Matcher.TYPE_BUTTON:
            case "BUTTON/SUBMIT":
                IHTMLInputElement fileElement = element as IHTMLInputElement;
                element.click();
                break;

            case Matcher.TYPE_TEXTAREA:
            case Matcher.TYPE_TEXT:
            case Matcher.TYPE_PASSWORD:
                FillTextElement(element, value);
                break;
            }
        }
Beispiel #27
0
 protected override mshtml.IHTMLElement FindElement(System.Windows.Forms.HtmlDocument doc, FillParameter parameter, bool isContain, string elementType, int formIndex)
 {
     if (string.IsNullOrEmpty(parameter.SearchType))
     {
         return(InvokeScriptSync(doc, "findElement", new object[] { elementType, parameter.Name, parameter.Value, parameter.OnClick, parameter.ReturnIndex }) as mshtml.IHTMLElement);
     }
     else
     {
         string filter = string.Format(parameter.SearchType, parameter.ParameterName == null ? null : string.Format("\"{0}\"", base.DataTable[parameter.ParameterName]));
         return(InvokeScriptSync(doc, "findElementByFilter", new object[] { filter, parameter.ReturnIndex }) as mshtml.IHTMLElement);
     }
 }
Beispiel #28
0
 protected override void UpdateFormIndex(FillParameter parameter)
 {
 }
Beispiel #29
0
        private void GetParameters()
        {
            Hashtable uniqueTable = new Hashtable();

            _parameters.Clear();
            string    note         = "";
            Hashtable group        = null;
            Hashtable columnHeader = new Hashtable();

            using (Office.Excel.ForwardExcelReader reader = new Office.Excel.ForwardExcelReader(GetParameterFile()))
            {
                reader.Open();
                Office.Excel.ForwardReadWorksheet sheet = reader.Activate(_urlParameter.LabelName) as Office.Excel.ForwardReadWorksheet;
                if (sheet == null)
                {
                    return;
                }
                object content = null;
                if (sheet.ReadNextRow())
                {
                    while (sheet.ReadNextCell(false))
                    {
                        content = sheet.GetContent();
                        columnHeader.Add(sheet.CurrentCell.ColumnIndex, content == null ? "" : content.ToString());
                    }
                }
                FillParameter    dElement;
                FillParameterKey key;
                while (sheet.ReadNextRow())
                {
                    dElement = new FillParameter();
                    while (sheet.ReadNextCell(false))
                    {
                        content = sheet.GetContent();
                        string value = content == null ? "" : content.ToString();
                        switch (columnHeader[sheet.CurrentCell.ColumnIndex] as string)
                        {
                        case "元素id":
                            dElement.Id = value;
                            break;

                        case "元素name":
                            dElement.Name = value;
                            break;

                        case "元素value":
                            dElement.Value = value;
                            break;

                        case "元素href":
                            dElement.href = value;
                            break;

                        case "类别":
                            dElement.Type = value == null ? "" : value.ToUpper();
                            break;

                        case "onclick":
                            dElement.OnClick = value;
                            break;

                        case "参数名称":
                            dElement.ParameterName = value;
                            break;

                        case "备注":
                            note = value;
                            break;

                        case "可新增":
                            dElement.CanAdd = value == "是";
                            break;

                        case "查找":
                            dElement.SearchString = value;
                            break;

                        case "frameId":
                            dElement.FrameId = value;
                            break;

                        case "数据所在工作表":
                            dElement.TableName = value;
                            break;

                        case "拆分规则":
                            dElement.SplitExpr = value;
                            break;

                        case "可删除":
                            dElement.CanDelete = value == "是";
                            break;

                        case "模糊匹配":
                            dElement.CanContain = value == "是";
                            break;

                        case "是否必填":
                            dElement.IsRequired = value == "是";
                            break;
                        }
                    }
                    if (string.IsNullOrEmpty(dElement.Type))
                    {
                        continue;
                    }
                    if (dElement.Type == Matcher.TYPE_RADIO || dElement.Type == Matcher.TYPE_CHECKBOX)
                    {   // 若当前参数为radio或checkbox则将其后面出现的所有此类元素作为同一参数
                        if (string.IsNullOrEmpty(dElement.ParameterName) == false &&
                            uniqueTable.ContainsKey(dElement.ParameterName) == false)
                        {
                            group = new Hashtable();
                            key   = new FillParameterKey(dElement.ParameterName, dElement.Type, dElement.CanAdd, dElement.IsRequired, dElement.CanDelete, dElement.CanContain, dElement.SearchString);
                            _parameters.Add(new KeyValuePair <FillParameterKey, object>(key, group));
                            uniqueTable.Add(dElement.ParameterName, group);
                        }

                        //只保存第一个radio或者checkbox参数,在group里面保存全部的信息
                        group.Add(dElement.Value, dElement);
                    }
                    else
                    {
                        group         = null;
                        key           = new FillParameterKey(dElement.ParameterName, dElement.Type, dElement.CanAdd, dElement.CanDelete, dElement.IsRequired, dElement.CanContain, dElement.SearchString);
                        key.TableName = dElement.TableName;
                        _parameters.Add(new KeyValuePair <FillParameterKey, object>(key, dElement));
                    }
                }
                uniqueTable.Clear();
            }
        }
Beispiel #30
0
        ////填充参数
        //protected void FillElement(FillParameter parameter, string value)
        //{
        //    if (parameter == null)
        //        return;
        //    IHTMLElement element = null;
        //    if (parameter.Type != Matcher.TYPE_FORM)
        //    {
        //        string key = parameter.FrameId;
        //        if (string.IsNullOrEmpty(key))
        //            key = "@";
        //        //查找元素,如果是null就是代表没有此元素
        //        element = base.GetElement(parameter, formIndexes[key]);
        //        if (element == null)
        //        {
        //            base.FillRecords.Add(new FillRecord(GetElementType(parameter.Type), RecordType.Failed, "未找到此元素", parameter.ParameterName));
        //            return;
        //        }
        //        if (parameter.Type == Matcher.TYPE_FILE)
        //        {
        //            if (string.IsNullOrEmpty(value))
        //                return;
        //            value = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value);
        //            if (System.IO.File.Exists(value) == false)
        //            {
        //                base.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", value), parameter.ParameterName));
        //                return;
        //            }
        //        }
        //        ((IHTMLElement2)element).focus();
        //    }
        //    _currentFillValue = value;
        //    switch (parameter.Type)
        //    {
        //    case Matcher.TYPE_FORM:
        //        string key = parameter.FrameId;
        //        if (string.IsNullOrEmpty(key))
        //            key = "@";
        //        if (formIndexes.ContainsKey(key))
        //            formIndexes[key] = formIndexes[key] + 1;
        //        else
        //            formIndexes[key] = 0;
        //        break;
        //    case Matcher.TYPE_RADIO:
        //        IHTMLInputElement radioElement = element as IHTMLInputElement;
        //        radioElement.@checked = true;
        //        base.FillRecords[(int)ElementType.Radio].RecordCount++;
        //        break;
        //    case Matcher.TYPE_SELECT:
        //        IHTMLSelectElement selectElement = element as IHTMLSelectElement;
        //        if (FillSelectElement(selectElement, value))
        //            base.FillRecords[(int)ElementType.Select].RecordCount++;
        //        else
        //            base.FillRecords.Add(new FillRecord(ElementType.Select, RecordType.Failed, string.Format("下拉框中不包含选项 {0}", value), parameter.ParameterName));
        //        break;
        //    case Matcher.TYPE_A:
        //        element.click();
        //        break;
        //    case Matcher.TYPE_FILE:
        //        element.click();
        //        base.FillRecords[(int)ElementType.File].RecordCount++;
        //        break;
        //    case Matcher.TYPE_SUBMIT:
        //    case Matcher.TYPE_BUTTON:
        //    case "BUTTON/SUBMIT":
        //        IHTMLInputElement fileElement = element as IHTMLInputElement;
        //        element.click();
        //        break;
        //    case Matcher.TYPE_TEXTAREA:
        //        IHTMLTextAreaElement textAreaElement = element as IHTMLTextAreaElement;
        //        textAreaElement.value = value;
        //        base.FillRecords[(int)ElementType.Text].RecordCount++;
        //        break;
        //    case Matcher.TYPE_TEXT:
        //    case Matcher.TYPE_PASSWORD:
        //        IHTMLInputElement textElement = element as IHTMLInputElement;
        //        textElement.value = value;
        //        base.FillRecords[(int)ElementType.Text].RecordCount++;
        //        break;
        //    }
        //}

        //private void FillElement(FillParameterKey parameterKey, object elementContainer, string parameterValue)
        //{
        //    this.Wait();
        //    FillParameter fillParameter = elementContainer as FillParameter;
        //    if (fillParameter == null)
        //    {
        //        Hashtable table = elementContainer as Hashtable;
        //        if (table == null)
        //            return;
        //        else if (parameterKey.Type == Matcher.TYPE_RADIO)
        //        {
        //            // 处理radio类型的选择
        //            if (parameterValue != null)
        //            {
        //                if (table.ContainsKey(parameterValue) == false)
        //                    base.FillRecords.Add(new FillRecord(ElementType.Radio, RecordType.Failed, string.Format("单选框中不包含项 {0}", parameterValue), parameterKey.Key));

        //                fillParameter = table[parameterValue] as FillParameter;
        //            }
        //        }
        //        else if (parameterKey.Type == Matcher.TYPE_CHECKBOX) // 处理checkBox类型
        //        {
        //            FillCheckBoxGroup(parameterValue, parameterKey.Key, table);
        //            return;
        //        }
        //    }
        //    FillElement(fillParameter, parameterValue);
        //}

        protected override IHTMLElement FindElement(System.Windows.Forms.HtmlDocument doc, FillParameter parameter, bool isContain, string elementType, int formIndex)
        {
            return(InvokeScriptSync(doc, "findElement", new object[] { elementType, parameter.Id, parameter.Name, parameter.Value, parameter.OnClick, formIndex }) as IHTMLElement);
        }