Ejemplo n.º 1
0
        /// <summary>
        /// 加载
        /// </summary>
        public void Init(Action success, Action <string> fail)
        {
            Http.Get(ServiceConfig.GetConfig(ServiceConfigType.DriveServiceGetUrl)).OnSuccess(content =>
            {
                Html.HtmlDocument document = new Html.HtmlDocument();
                document.LoadHtml(content);
                Inputs  = document.DocumentNode.SelectNodes("//input[@type='password' or @type='hidden' or @type='text']");
                Selects = document.DocumentNode.SelectNodes("//select");

                if (ServiceError.TestServiceError(document.DocumentNode))
                {
                    fail("服务器出错!");
                }
                else
                {
                    success();
                }
            }).TimeOut(5000).OnFail(new Action <WebException>((exp) =>
            {
                fail(exp.ToString());
            })).Go();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="showCodeImg"></param>
        public void Init(Action <Bitmap> showCodeImg, Action <string> fail)
        {
            Http.Get(ServiceConfig.GetConfig(ServiceConfigType.LoginServiceUrl)).OnSuccess(content =>
            {
                Http.Get(ServiceConfig.GetConfig(ServiceConfigType.LoginServiceRndUrl)).OnSuccess((WebHeaderCollection h, Stream img) =>
                {
                    Bitmap codeImg = (Bitmap)Image.FromStream(img);
                    showCodeImg(codeImg);
                }
                                                                                                  ).Go();
                Html.HtmlDocument document = new Html.HtmlDocument();
                document.LoadHtml(content);
                _inputs = document.DocumentNode.SelectNodes("//input[@type='password' or @type='hidden' or @type='text']");

                //
                if (ServiceError.TestServiceError(document.DocumentNode))
                {
                    fail("服务器出错!");
                }
            }).TimeOut(5000).OnFail(new Action <WebException>((exp) =>
            {
                fail(exp.ToString());
            })).Go();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 查询
        /// </summary>
        public void Query(string type, string date, Action <DataTable, bool> success, Action <string> fail)
        {
            string dateControlName           = "";
            Dictionary <string, string> form = new Dictionary <string, string>();

            if (Inputs != null)
            {
                foreach (Html.HtmlNode node in Inputs)
                {
                    string name = node.Attributes["name"].Value;
                    if (name.IndexOf("txtBookingClassDate") != -1)
                    {
                        form.Add(name, date);
                        dateControlName = name;
                    }
                    else
                    {
                        form.Add(name, node.Attributes["value"].Value);
                    }
                }
            }
            if (Selects != null)
            {
                foreach (Html.HtmlNode node in Selects)
                {
                    string name = node.Attributes["name"].Value;
                    if (name.IndexOf("ddlTrainType") != -1)
                    {
                        form.Add(name, type);
                    }
                }
            }
            form.Add("__EVENTARGUMENT", "");
            form.Add("__EVENTTARGET", dateControlName);

            int  s      = (DateTime.Now - Convert.ToDateTime(date)).Days;
            bool istech = (Math.Abs((DateTime.Now - Convert.ToDateTime(date)).Days) + 1) >= 6 ? true : false;

            Http.Post(ServiceConfig.GetConfig(ServiceConfigType.DriveServiceQueryUrl)).Form(form).OnSuccess(result =>
            {
                try
                {
                    Html.HtmlDocument document = new Html.HtmlDocument();
                    document.LoadHtml(result);
                    if (ServiceError.TestServiceError(document.DocumentNode))
                    {
                        fail("服务器出错!");
                    }
                    else
                    {
                        success(GetDataTable(document, istech), istech);
                    }
                }
                catch (Exception exp)
                {
                    fail(exp.ToString());
                }
            }).TimeOut(5000).OnFail(new Action <WebException>((exp) =>
            {
                fail(exp.ToString());
            })).Go();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 得到班车信息
        /// </summary>
        public void GetRegGoWay(Action subMit, Action <string> fail)
        {
            string ddlineControlName         = "";
            Dictionary <string, string> form = new Dictionary <string, string>();

            if (_inputs != null)
            {
                foreach (Html.HtmlNode node in _inputs)
                {
                    string name = node.Attributes["name"].Value;
                    if (name.IndexOf("time") != -1)
                    {
                        if (!form.ContainsKey(name))
                        {
                            form.Add(name, "radio3");
                        }
                    }
                    else
                    {
                        if (node.Attributes["disabled"] == null)
                        {
                            form.Add(name, node.Attributes["value"].Value);
                        }
                    }
                }
            }
            if (_selects != null)
            {
                foreach (Html.HtmlNode node in _selects)
                {
                    string name = node.Attributes["name"].Value;
                    if (name.IndexOf("ddlLine") != -1)
                    {
                        form.Add(name, "---请选择---");
                        ddlineControlName = name;
                    }
                    else if (name.IndexOf("ddlStationAndTime") != -1)
                    {
                        form.Add(name, "---请选择---");
                    }
                }
            }
            form.Add("__EVENTARGUMENT", "");
            form.Add("__EVENTTARGET", ddlineControlName);
            string url = ServiceConfig.GetConfig(ServiceConfigType.DriveServicePostUrl) + GetUrlGetArgs();

            Http.Post(url).Referer(url).Form(form).OnSuccess(result =>
            {
                Html.HtmlDocument document = new Html.HtmlDocument();
                document.LoadHtml(result);
                _inputs = document.DocumentNode.SelectNodes("//input[@type='password' or @type='hidden' or @type='submit' or @type='text' or @type='radio']");
                //
                if (ServiceError.TestServiceError(document.DocumentNode))
                {
                    fail("服务器出错!");
                }
                else
                {
                    subMit();
                }
            }).TimeOut(5000).OnFail(new Action <WebException>((exp) =>
            {
                fail(exp.ToString());
            })).Go();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 提交
        /// </summary>
        public void Submit(Action success, Action <string> fail)
        {
            this.GetRegGoWay(() =>
            {
                #region success
                Dictionary <string, string> form = new Dictionary <string, string>();
                if (_inputs != null)
                {
                    foreach (Html.HtmlNode node in _inputs)
                    {
                        string name = node.Attributes["name"].Value;
                        if (name.IndexOf("time") != -1)
                        {
                            if (!form.ContainsKey(name))
                            {
                                form.Add(name, "radio3");
                            }
                        }
                        else
                        {
                            if (node.Attributes["disabled"] == null)
                            {
                                form.Add(name, node.Attributes["value"].Value);
                            }
                        }
                    }
                }
                form.Add("__EVENTARGUMENT", "");
                form.Add("__EVENTTARGET", "");

                Http.Post(ServiceConfig.GetConfig(ServiceConfigType.DriveServicePostUrl) + GetUrlGetArgs()).Form(form).OnSuccess(result =>
                {
                    Html.HtmlDocument document = new Html.HtmlDocument();
                    document.LoadHtml(result);
                    if (ServiceError.TestServiceError(document.DocumentNode))
                    {
                        fail("服务器出错!");
                    }
                    else
                    {
                        Html.HtmlNodeCollection trs = document.DocumentNode.SelectNodes("/html[1]/body[1]/table[1]/tr[2]/td[1]/table[1]/tr[1]/td[2]/table[2]/tr[5]/td[1]/div[1]/fieldset[1]/div[1]/table[1]/tr[position()>1]");
                        foreach (Html.HtmlNode tr in trs)
                        {
                            string date   = tr.SelectSingleNode("./td[1]/span").InnerText;
                            string time   = tr.SelectSingleNode("./td[2]/span").InnerText;
                            string techer = tr.SelectSingleNode("./td[3]/span").InnerText;
                            if (_info.TecherName == techer && time.Substring(0, 2) == _info.Time.ToString("D2") && date == _info.Date)
                            {
                                success();
                                return;
                            }
                        }
                        fail("提交失败!");
                    }
                }).TimeOut(5000).OnFail(new Action <WebException>((exp) =>
                {
                    fail(exp.ToString());
                })).Go();
                #endregion
            }, fail);
        }