예제 #1
0
        public ActionResult AddBikeInfo(BikeInfo bikeInfo)
        {
            //计算总价
            var price = bikeInfo.Price;
            var count = bikeInfo.Counts;
            var total = price * count;

            if (Session["loginUser"] != null)
            {
                UserInfo user = Session["loginUser"] as UserInfo;
                //调用生成UID的方法
                bikeInfo.UID        = CommonWeb.AutoNumber();
                bikeInfo.AdminUser  = user == null?"未登录": user.Name;
                bikeInfo.DelFlag    = noDel;
                bikeInfo.SubTime    = DateTime.Now;
                bikeInfo.ModifyOn   = DateTime.Now;
                bikeInfo.TotalPrice = total;
                if (ModelState.IsValid)
                {
                    bikeInfoService.Add(bikeInfo);
                    return(Content("ok"));
                }
            }
            return(Content("error"));
        }
예제 #2
0
        public async Task <Result <BikeInfo> > ScrapeShareAsync(LoginInfo loginInfo, ScrapeCondition scrapeCondition)
        {
            Console.WriteLine(loginInfo.Password);
            var context       = BrowsingContext.New(Configuration.Default.WithDefaultLoader());
            var queryDocument = await context.OpenAsync("https://tcc.docomo-cycle.jp/cycle/TYO/cs_web_main.php");

            var bikeInfos = new List <BikeInfo>();

            //ログイン
            var loginForm      = queryDocument.QuerySelector("form") as IHtmlFormElement;
            var resultDocument = await loginForm.SubmitAsync(new { MemberID = loginInfo.UserID, Password = loginInfo.Password });

            {
                var userinfo = resultDocument.GetElementsByClassName("user_inf pc_view").FirstOrDefault();
                if (userinfo == null)
                {
                    var loginError = resultDocument.GetElementsByClassName("err_text").FirstOrDefault();
                    return(new Result <BikeInfo>()
                    {
                        HasError = true,
                        Message = loginError?.TextContent ?? "ログインに失敗しました。",
                        ResultObject = null,
                    });
                }
            }

            //Wait
            System.Threading.Thread.Sleep(ScrapeSpan);

            //駐輪場から選ぶへ
            var selectByPlaceForm = resultDocument.GetElementsByName("from_port_tab").FirstOrDefault() as IHtmlFormElement;
            var portDocument      = await selectByPlaceForm.SubmitAsync();

            var portTitle = portDocument.GetElementsByClassName("tittle_h1").FirstOrDefault();

            //Wait
            System.Threading.Thread.Sleep(ScrapeSpan);

            //地域を選ぶ
            var searchAreaResult = await SearchCyclePage("sel_area", "AreaID", scrapeCondition.Area, portDocument);

            if (searchAreaResult.HasError)
            {
                return(new Result <BikeInfo>()
                {
                    HasError = true,
                    Message = searchAreaResult.Message,
                    ResultObject = null,
                });
            }

            //Wait
            System.Threading.Thread.Sleep(ScrapeSpan);

            //場所を選ぶ
            var searchPlaceResult = await SearchCyclePage("sel_location", "Location", scrapeCondition.Place, searchAreaResult.ResultObject);

            if (searchPlaceResult.HasError)
            {
                return(new Result <BikeInfo>()
                {
                    HasError = true,
                    Message = searchPlaceResult.Message,
                    ResultObject = null,
                });
            }

            //駐輪一覧取得
            var           searchDocument = searchPlaceResult.ResultObject;
            CyclePortInfo cyclePortInfo  = null;

            {
                var searchFinished = false;
                while (searchFinished == false)
                {
                    var portMain = searchDocument.GetElementsByClassName("main_inner_wide").FirstOrDefault();
                    var portList = portMain.GetElementsByClassName("sp_view").FirstOrDefault().QuerySelectorAll("form");
                    foreach (var p in portList)
                    {
                        var portAtag    = p.GetElementsByTagName("a").FirstOrDefault();
                        var splitedPort = portAtag.InnerHtml.Split(new string[] { "< br >", "<br>", "<br/>", "<br />", "< br>", "<br >" }, StringSplitOptions.None);

                        //ポート名で検索
                        if (splitedPort[0].Contains(scrapeCondition.Port))
                        {
                            cyclePortInfo = new CyclePortInfo()
                            {
                                PortName = splitedPort[0], PortNameEnglish = splitedPort[1], PortQuantity = splitedPort[2], Element = p as IHtmlFormElement
                            };
                            searchFinished = true;
                            break;
                        }
                    }

                    if (searchFinished == false)
                    {
                        var nextPageArea = searchDocument.GetElementsByClassName("mt20").FirstOrDefault()?.GetElementsByClassName("main_inner_wide_right").FirstOrDefault();
                        if (nextPageArea == null)
                        {
                            searchFinished = true;
                            break;
                        }
                        else
                        {//次のページを探す
                            var nextPageForm = nextPageArea.QuerySelector("form") as IHtmlFormElement;
                            searchDocument = await nextPageForm.SubmitAsync();

                            System.Threading.Thread.Sleep(ScrapeSpan);
                        }
                    }
                }
            }
            if (cyclePortInfo == null)
            {
                return(new Result <BikeInfo>()
                {
                    HasError = true,
                    Message = "駐輪場の取得に失敗しました",
                    ResultObject = null,
                });
            }

            //Wait
            System.Threading.Thread.Sleep(ScrapeSpan);

            //バイク一覧取得
            var bikePageDocument = await cyclePortInfo.Element.SubmitAsync();

            var bikeForms = bikePageDocument.GetElementsByClassName("main_inner_wide_left_list").FirstOrDefault().GetElementsByTagName("form");

            //Wait
            System.Threading.Thread.Sleep(ScrapeSpan);

            //バイクレンタル main_inner_wide
            var bikeForm = bikeForms.FirstOrDefault() as IHtmlFormElement;
            var bikeInfo = new BikeInfo()
            {
                BikeName = bikeForm.TextContent, Element = bikeForm
            };
            var bikeResultDocument = await bikeForm.SubmitAsync();

            return(new Result <BikeInfo>()
            {
                Message = bikeResultDocument.TextContent,
                ResultObject = bikeInfo,
            });
        }
예제 #3
0
 public Request(int userId, BikeInfo bikeInfo)
 {
     UserId   = userId;
     BikeInfo = bikeInfo;
 }
예제 #4
0
 public ActionResult Edit(BikeInfo bikeInfo)
 {
     bikeInfoService.Update(bikeInfo);
     return(Content("ok"));
 }